:root {
  --bg: #f7f6f2;
  --card: #ffffff;
  --line: #e6e3da;
  --text: #22252b;
  --muted: #777b85;
  --aux: #2563c9;
  --verb: #c2500f;
  --present: #1f9d6b;
  --past: #7a5cd6;
  --future: #d98a16;
  --c0: #5d7f8f;
  --c1: #1f9d6b;
  --c2: #d98a16;
  --c3: #cf4d4d;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1e2126;
    --line: #2e323a;
    --text: #e8e9ec;
    --muted: #9296a0;
    --aux: #7aa9f5;
    --verb: #f0935a;
    --present: #4cc494;
    --past: #a48cf0;
    --future: #eeb04e;
    --c0: #8fb0bf;
    --c1: #4cc494;
    --c2: #eeb04e;
    --c3: #ef7b7b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px clamp(16px, 4vw, 40px) 56px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.top, .controls, main { max-width: 1040px; margin-inline: auto; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.top h1 { font-size: 20px; letter-spacing: -0.01em; }

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--line);
}
.seg button {
  min-width: 40px;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.aux { color: var(--aux); }
.verb { color: var(--verb); }

/* Tenses */
.row { margin-top: 28px; }
.row-present { --accent: var(--present); }
.row-past { --accent: var(--past); }
.row-future { --accent: var(--future); }

.row h2 {
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 4px solid var(--accent);
  font-size: 17px;
  line-height: 1.2;
}
.row h2 small { color: var(--muted); font-size: 13px; font-weight: 400; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.tile, .cond, dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
}
.tile {
  padding: 12px 14px;
  font: inherit;
  text-align: left;
}
button.tile { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
button.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile h3 { color: var(--muted); font-size: 13px; font-weight: 600; }
.tile-off { background: none; border-style: dashed; }
.off { margin-top: 12px; color: var(--muted); font-size: 13px; }

.tl { display: block; width: 100%; max-width: 220px; margin: 6px 0 4px; }
.tl-axis { stroke: var(--line); stroke-width: 1.5; stroke-linecap: round; }
.tl-now { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 2; }
.tl-label { fill: var(--muted); font-size: 6px; }
.tl-fill { fill: var(--accent); }
.tl-ring { fill: var(--card); stroke: var(--accent); stroke-width: 1.6; }
.tl-arc { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: 3 2; }

.formula {
  font: 600 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.example { margin-top: 6px; }
.use { margin-top: 8px; color: var(--muted); font-size: 13px; }
.markers { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.markers span {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}

/* Conditionals */
.src-0 { --src: var(--c0); }
.src-1 { --src: var(--c1); }
.src-2 { --src: var(--c2); }
.src-3 { --src: var(--c3); }

.conds {
  display: grid;
  gap: 10px;
  max-width: 720px;
  margin: 12px auto 0;
}
.cond { padding: 12px 14px; }
.cond summary {
  display: grid;
  grid-template-columns: 52px 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}
.cond summary::-webkit-details-marker { display: none; }
.cond[open] summary { margin-bottom: 12px; }
.badge {
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--src);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.clause {
  padding: 8px 10px;
  border-radius: 10px;
  border-left: 4px solid var(--src);
  background: color-mix(in srgb, var(--src) 9%, transparent);
}
.arrow { color: var(--muted); font-size: 18px; }
.in-cond, .in-res { color: var(--src); }

.notes {
  max-width: 720px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 14px;
}
.notes summary { cursor: pointer; }
.notes ul { margin: 8px 0 0; padding-left: 20px; }
.notes li + li { margin-top: 4px; }
.notes b { color: var(--text); }

/* Focus */
dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 20px 22px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.focus header, .focus footer { display: flex; align-items: center; justify-content: space-between; }
.focus h2 { font-size: 20px; }
.focus h2 small { color: var(--muted); font-size: 14px; font-weight: 400; }
.focus .tl { max-width: 340px; margin: 14px auto; }
.focus .tl-ring { fill: var(--card); }
.form {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 0 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.form .sign { grid-row: span 2; color: var(--muted); font-weight: 700; }
.form .example { margin-top: 2px; }
.focus footer { margin-top: 14px; }
.icon {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

@media (max-width: 860px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .legend { margin-left: 0; }
  .cond summary { grid-template-columns: 52px 1fr; }
  .cond summary .arrow { display: none; }
  .cond summary .clause:last-child { grid-column: 2; }
}

.formula b { white-space: nowrap; }
.tile .formula { font-size: 13px; }

/* Tips */
.tips {
  margin-top: 18px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--future) 10%, transparent);
  font-size: 14px;
}
.tips:has(+ .conds) { max-width: 720px; margin-inline: auto; }
.tips summary { font-weight: 600; cursor: pointer; }
.tips ul { margin: 8px 0 2px; padding-left: 20px; }
.tips li + li { margin-top: 6px; }
.tip {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--future) 10%, transparent);
  font-size: 13px;
}
.tip::before { content: '💡 '; }

/* Linkers */
.link-group { display: grid; gap: 10px; }
.link-group + .link-group { margin-top: 14px; }
.link-group h2 {
  padding-left: 10px;
  border-left: 4px solid var(--src);
  font-size: 16px;
  line-height: 1.2;
}
.link-group h2 small { color: var(--muted); font-size: 13px; font-weight: 400; }
.cond.link summary { grid-template-columns: 170px 1fr; }
.word { color: var(--src); font-size: 15px; }
.after { font-weight: inherit; border-bottom: 2px dotted var(--src); }
.formula .after { font-weight: 600; }

/* Linking words */
.phrase-list { padding: 4px 16px; }
.phrases {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 6px 16px;
  padding: 12px 0;
}
.phrases + .phrases { border-top: 1px solid var(--line); }
.phrases h3 {
  align-self: start;
  margin-top: 5px;
  padding-left: 8px;
  border-left: 3px solid var(--src);
  font-size: 13px;
  line-height: 1.3;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: color-mix(in srgb, var(--src) 10%, transparent);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.chip:hover, .chip.on { border-color: var(--src); }
.chip.on { background: var(--src); color: #fff; }
.phrase {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
}
.phrase .use { margin-top: 0; }
.phrase .example { margin-top: 2px; }
.phrase .tip { background: none; padding: 0; margin-top: 6px; color: var(--muted); }

.top .seg { max-width: 100%; overflow-x: auto; }
.seg button { white-space: nowrap; }

@media (max-width: 520px) {
  .phrases { grid-template-columns: 1fr; }
  .cond.link summary { grid-template-columns: 1fr; gap: 4px; }
}

/* Shell: home, search, stars */
.brand { color: inherit; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
#search {
  flex: 1 1 220px;
  max-width: 420px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
}
#search:focus { outline: 2px solid var(--aux); outline-offset: -1px; }
.back { color: var(--muted); font-weight: 600; text-decoration: none; }
.back:hover { color: var(--text); }
.topic-title { font-size: 18px; }
body:not([data-tab='tenses'], [data-tab='home'], [data-tab='plan']) :is(.controls, .tips) { max-width: 720px; margin-inline: auto; }
body:not([data-tab='tenses'], [data-tab='home'], [data-tab='plan']) .controls { margin-top: 18px; }

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
  gap: 10px;
  margin-top: 24px;
}
.topic {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--src);
  border-radius: 14px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s;
}
.topic:hover { transform: translateY(-2px); }
.topic h3 { font-size: 16px; }
.topic p { margin-top: 2px; color: var(--muted); font-size: 13px; }
.home-title { max-width: 720px; margin: 32px auto 0; font-size: 16px; }

.results { display: grid; gap: 6px; max-width: 720px; margin: 18px auto 0; }
.home-title + .results { margin-top: 10px; }
.result {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 2px 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.result:hover { border-color: var(--muted); }
.r-topic { grid-row: span 2; align-self: center; color: var(--muted); font-size: 12px; }
.result .formula { font-size: 13px; font-weight: 500; }
.empty { margin-top: 32px; color: var(--muted); text-align: center; }

.star {
  display: block;
  margin-top: 8px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.star.on { color: var(--future); }
.focus footer .star, .vs header .star { margin-top: 0; }

/* X vs Y */
.vs header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.vs h3 { font-size: 15px; }
.sides {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.side {
  padding: 10px 12px;
  border-top: 3px solid var(--src);
  border-radius: 10px;
  background: color-mix(in srgb, var(--src) 8%, transparent);
}
.side h4 { margin: 0 0 4px; color: var(--src); font-size: 14px; }
.side .use { margin-top: 4px; }

@media (max-width: 520px) {
  .result { grid-template-columns: 1fr; }
  .r-topic { grid-row: auto; }
}

/* Practice */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { border-color: var(--text); background: var(--text); color: var(--bg); }
.btn.small { margin-left: auto; padding: 4px 12px; font-size: 13px; }
.legend + .btn.small { margin-left: 0; }
.practice-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.practice-bar + .topic-grid { margin-top: 14px; }

.progress { max-width: 720px; height: 4px; margin: 14px auto 0; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--present); transition: width 0.2s; }
.q { padding: 22px; }
.q-text { font-size: 20px; line-height: 1.5; }
.gap { display: inline-block; width: 80px; border-bottom: 2px solid var(--muted); }
.ok { color: var(--present); }
.q-opts { display: grid; gap: 8px; margin-top: 18px; }
.opt {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.opt:not(:disabled):hover { border-color: var(--muted); }
.opt:disabled { cursor: default; }
.opt kbd { margin-right: 12px; color: var(--muted); font: inherit; font-size: 12px; }
.opt.right { border-color: var(--present); background: color-mix(in srgb, var(--present) 14%, transparent); }
.opt.wrong { border-color: var(--c3); background: color-mix(in srgb, var(--c3) 14%, transparent); }
.q-rule { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.q-rule .use { margin: 0 0 2px; }
.q-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 16px; }
.score { font-size: 44px; font-weight: 700; text-align: center; }
.center { text-align: center; }
.q .results { margin-top: 12px; }

.seg.small button { padding: 3px 10px; font-size: 13px; }
.q-base { margin-top: 4px; color: var(--muted); }
.q-type { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.q-type input {
  flex: 1 1 220px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.q-type input:focus { outline: 2px solid var(--aux); outline-offset: -1px; }
.verdict { margin-top: 10px; font-weight: 600; }
.verdict.bad { color: var(--c3); }
.verdict b { font-weight: 700; }

/* Progress and rewrite */
.topic { position: relative; }
.pct { position: absolute; top: 12px; right: 14px; font-size: 13px; font-weight: 700; }
.pct.good { color: var(--present); }
.pct.mid { color: var(--future); }
.pct.low { color: var(--c3); }
.home-note { max-width: 720px; margin: 2px auto 0; color: var(--muted); font-size: 13px; }
.q-from { margin-bottom: 8px; color: var(--muted); font-size: 17px; }
.q-from + .q-text::before { content: '→ '; color: var(--muted); }

/* Plan */
.plan-card header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-card h3 { font-size: 17px; }
.badge-status { padding: 2px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; }
.badge-status.сьогодні { background: var(--text); color: var(--bg); }
.plan-part { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.plan-part h4 { margin: 0; font-size: 15px; }
.plan-part .results { margin: 10px 0 0; }
.plan-part .btn { margin-top: 12px; }
.plan-part .use { margin-top: 2px; }
.plan-list { display: grid; gap: 4px; margin-top: 10px; }
.plan-row {
  display: grid;
  grid-template-columns: 110px 1fr 20px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.plan-row:hover, .plan-row.on { border-color: var(--line); background: var(--card); }
.plan-date { color: var(--muted); font-size: 13px; }
.plan-what small { color: var(--muted); }
.plan-row.done .plan-what b { color: var(--muted); font-weight: 500; }
.plan-row.done .plan-mark { color: var(--present); }
.plan-row.today .plan-date { color: var(--text); font-weight: 700; }
.plan-row.missed .plan-date { color: var(--c3); }
.conds > .home-title { margin: 18px 0 0; }
.conds > .home-note { margin: -6px 0 0; }

/* Plan calendar */
.plan { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 24px; margin-top: 14px; }
.plan-cal { grid-column: 1; grid-row: 1; display: grid; gap: 22px; }
.plan-side { position: sticky; top: 16px; display: grid; gap: 10px; }
.plan-side .home-note { margin: 0; }
.plan-side .plan-card .result { grid-template-columns: 1fr; }
.plan-card .r-topic { grid-row: auto; }
.cal-month summary { margin-bottom: 8px; font-size: 16px; font-weight: 700; cursor: pointer; }
.cal-month summary::first-letter { text-transform: uppercase; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-week { padding: 2px 6px; color: var(--muted); font-size: 12px; }
.cal-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 78px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  overflow: hidden;
}
button.cal-cell { cursor: pointer; }
button.cal-cell:hover { border-color: var(--muted); }
.cal-cell.blank { border: 0; background: none; }
.cal-cell.out { border-style: dashed; background: none; color: var(--muted); }
.cal-num { color: var(--muted); font-size: 12px; font-weight: 600; }
.cal-title { font-size: 11.5px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.cal-rev { color: var(--muted); font-size: 10.5px; }
.cal-cell.today { border-color: var(--text); border-width: 2px; padding: 5px 6px; }
.cal-cell.today .cal-num { color: var(--text); }
.cal-cell.on { outline: 2px solid var(--aux); outline-offset: 1px; }

@media (max-width: 900px) {
  .plan { grid-template-columns: minmax(0, 1fr); }
  .plan-cal { grid-row: auto; }
  .plan-side { position: static; }
}
}
.plan-part .btn.small { margin-left: 0; }
.plan-part .chips { margin-top: 8px; }
.cal-cell.past { background: none; }
.cal-cell.past .cal-title { color: var(--muted); font-weight: 500; }

/* На телефоні замість сітки — список днів, де все видно одразу */
.cal-list { display: none; gap: 4px; }
.cal-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.cal-date { color: var(--muted); font-size: 13px; }
.cal-what { display: grid; gap: 2px; }
.cal-what small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.cal-row.past { background: none; }
.cal-row.past b { color: var(--muted); font-weight: 500; }
.cal-row.today { border-color: var(--text); border-width: 2px; }
.cal-row.today .cal-date { color: var(--text); font-weight: 700; }
.cal-row.on { outline: 2px solid var(--aux); outline-offset: 1px; }
.cal-rev { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; line-height: 1.25; }
.cal-title + .cal-rev { margin-top: auto; }
.cal-cell > .cal-rev:nth-child(2) { margin-top: 0; }

@media (max-width: 640px) {
  .cal-grid { display: none; }
  .cal-list { display: grid; }
}
.plan-copy { width: 100%; margin-top: 0 !important; }
.plan-prompt { margin-top: 10px; color: var(--muted); font-size: 13px; }
.plan-prompt summary { cursor: pointer; }
.plan-prompt pre {
  max-height: 320px;
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow: auto;
}
.cond .plan-prompt summary { display: list-item; list-style: disclosure-closed inside; }
.cond .plan-prompt[open] summary { list-style-type: disclosure-open; }
