:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1b19;
  --muted: #6b6962;
  --line: #e2dfd8;
  --accent: #b4441f;
  --accent-text: #ffffff;
  --accent-weak: #f7e7e0;
  --ok: #1f7a4d;
  --ok-weak: #e2f1e8;
  --bad: #b42318;
  --bad-weak: #fbe8e6;
  --warn: #8a5a00;
  --warn-weak: #fbf0d4;
  --irr: #b4441f;
  --end: #2457a6;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 1px 1px rgb(0 0 0 / 0.03);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #1f1e1b;
    --surface-2: #2a2825;
    --text: #eceae4;
    --muted: #a19e95;
    --line: #34322d;
    --accent: #e8744d;
    --accent-text: #1a0c06;
    --accent-weak: #3b2219;
    --ok: #5ccf96;
    --ok-weak: #17301f;
    --bad: #f97a70;
    --bad-weak: #3a1816;
    --warn: #f2c35b;
    --warn-weak: #332a12;
    --irr: #f0885f;
    --end: #86b2f5;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* Top bar */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; font-size: 1.05rem; letter-spacing: -0.01em; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  text-decoration: none; color: var(--muted); font-size: 0.92rem; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav .icon { display: inline-flex; }
.nav a.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); font-weight: 550; }
body.quiz-mode .top { display: none; }

.main { max-width: 760px; margin: 0 auto; padding: 24px 16px 96px; }

/* Page head */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.head-meta { color: var(--muted); font-variant-numeric: tabular-nums; }
.eyebrow { display: inline-block; color: var(--muted); font-size: 0.85rem; margin-bottom: 4px; text-decoration: none; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: 0.92rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { margin-bottom: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 20px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.disabled { opacity: 0.45; pointer-events: none; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions.sticky {
  position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.actions.sticky .btn { flex: 1; max-width: 320px; }
button.plain { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 0.88rem; border: 1px solid transparent; text-decoration: none;
}
button.chip { cursor: pointer; text-align: left; }
.chip.muted { color: var(--muted); }
.chip.link:hover, button.chip:hover { border-color: var(--line); }
.chip.toggle.on { background: var(--accent-weak); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); font-weight: 550; }
.chip.removable span { color: var(--muted); }
.list-chip .x { color: var(--muted); margin-left: 4px; }
.tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--warn-weak); color: var(--warn); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: 0.75rem; font-weight: 600;
}

/* Tense names */
.tn-en { color: var(--muted); font-weight: 400; }
.chip.toggle.on .tn-en { color: color-mix(in srgb, var(--accent) 70%, var(--muted)); }
h2 .tn-en { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* Levels */
.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.level-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  text-decoration: none;
}
.level-row:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.num {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.level-row.complete .num { background: var(--ok-weak); color: var(--ok); }
.level-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.level-title { font-weight: 550; }
.level-tenses { color: var(--text); font-size: 0.85rem; }
.level-score { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.due-card { display: flex; align-items: center; justify-content: space-between; text-decoration: none; font-weight: 550; padding: 14px 16px; }

/* Lesson */
.lesson { margin: 20px 0 8px; }
.lesson h2 { margin: 28px 0 12px; }
.lesson p, .lesson li { max-width: 62ch; }
.lesson ul { padding-left: 20px; }
.lesson li { margin: 4px 0; }
.lesson em { font-style: normal; color: var(--accent); font-weight: 500; }
.lesson strong { font-weight: 650; }
.quiz-verbs { margin-top: 28px; }
.quiz-verbs h2 { margin-bottom: 10px; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 0.9rem; }
.pager a { color: var(--muted); text-decoration: none; }
.pager a:hover { color: var(--text); }

/* Verb tables */
.vt { margin: 16px 0; }
.vt figcaption { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.vt-es { font-weight: 600; }
.vt-en { color: var(--muted); font-size: 0.85rem; }
.vt-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.vt table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.vt th, .vt td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.vt tr:last-child th, .vt tr:last-child td { border-bottom: 0; }
.vt thead th { font-weight: 600; font-size: 0.85rem; background: var(--surface-2); }
.vt thead a { text-decoration: none; }
.vt th.person { color: var(--muted); font-weight: 400; font-size: 0.85rem; width: 1%; }
.vt td .en { color: var(--muted); font-size: 0.82rem; white-space: normal; margin-top: 1px; }
.form .irr { color: var(--irr); font-weight: 650; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.form .end { color: var(--end); font-weight: 600; }
.mood { margin-top: 28px; }
.mood h2 { margin-bottom: 4px; }

/* Verb list */
.search { position: relative; margin-bottom: 12px; }
.sticky-top { position: sticky; top: 57px; z-index: 5; background: var(--bg); padding: 4px 0 8px; }
.input {
  width: 100%; min-height: 44px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
.verb-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.verb-list li + li { border-top: 1px solid var(--line); }
.verb-list a { display: flex; align-items: center; gap: 12px; padding: 10px 16px; text-decoration: none; }
.verb-list a:hover { background: var(--surface-2); }
.verb-list .inf { font-weight: 550; min-width: 8em; }
.verb-list .muted { flex: 1; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results { display: grid; gap: 2px; margin-top: 4px; }
.search-results .result {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 12px; border-radius: 8px; border: 0; background: var(--surface-2);
  font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.search-results .result:hover { background: var(--accent-weak); }

/* Practice form */
.form h2 { margin: 22px 0 10px; }
.form h2:first-child { margin-top: 0; }
.group { margin-bottom: 10px; }
.group-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.presets { margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row .input { flex: 1; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: none; font: inherit; font-size: 0.9rem; color: var(--muted);
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 550; }

/* Quiz */
.quiz { max-width: 560px; margin: 0 auto; }
.quiz-head { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 8px; margin-bottom: 10px; }
.close { font-size: 1.6rem; line-height: 1; text-decoration: none; color: var(--muted); width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.close:hover { background: var(--surface-2); color: var(--text); }
.quiz-title { font-weight: 600; text-align: center; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.bar { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 20px; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width 0.25s ease; }
.quiz-card { padding: 28px 20px 20px; }
.prompt { text-align: center; margin-bottom: 22px; }
.prompt-main { font-size: 2.2rem; font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; }
.prompt-main.en { font-size: 1.5rem; font-weight: 600; }
.prompt-meta { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.pronoun { font-size: 1.1rem; font-weight: 550; color: var(--accent); }
.answer {
  width: 100%; min-height: 56px; padding: 0 16px;
  font: inherit; font-size: 1.35rem; text-align: center;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--text);
}
.answer:focus { outline: none; border-color: var(--accent); }
.answer.locked.correct { border-color: var(--ok); background: var(--ok-weak); }
.answer.locked.accent { border-color: var(--warn); background: var(--warn-weak); }
.answer.locked.wrong { border-color: var(--bad); background: var(--bad-weak); }
.accent-keys { display: flex; gap: 6px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.key {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 1.05rem; cursor: pointer;
}
.key:hover { background: var(--surface-2); }
.feedback { min-height: 92px; text-align: center; margin-top: 16px; }
.feedback:empty { min-height: 0; }
.status { display: inline-block; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 10px; border-radius: 999px; }
.status.correct { background: var(--ok-weak); color: var(--ok); }
.status.accent { background: var(--warn-weak); color: var(--warn); }
.status.wrong { background: var(--bad-weak); color: var(--bad); }
.answer-line { font-size: 1.5rem; font-weight: 600; margin: 8px 0 2px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: baseline; }
.typed { color: var(--muted); font-weight: 400; font-size: 1.1rem; }
.quiz-card .actions { justify-content: center; }
.quiz-card .actions .btn { min-width: 180px; }

/* Results */
.result { text-align: center; }
.score { font-size: 3rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.result .status { margin-top: 12px; }
.misses { list-style: none; padding: 0; margin: 20px 0 0; text-align: left; border-top: 1px solid var(--line); }
.misses li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.misses .muted { font-size: 0.9rem; }
.result .actions { justify-content: center; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat-num { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.82rem; }
.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.box { text-align: center; }
.box-bar { height: 80px; display: flex; align-items: flex-end; justify-content: center; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.box-bar span { display: block; width: 100%; background: var(--accent); min-height: 3px; }
.box-num { font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.box-label { color: var(--muted); font-size: 0.78rem; }
.acc { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.acc th, .acc td { padding: 8px 0; border-bottom: 1px solid var(--line); text-align: left; }
.acc th { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
.acc .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter { display: inline-block; width: 60px; height: 6px; border-radius: 999px; background: var(--surface-2); vertical-align: middle; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); }

/* Settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.setting:first-child { padding-top: 0; }
.setting:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-label { font-weight: 550; }

.error { color: var(--bad); }

@media (max-width: 560px) {
  .top { flex-direction: column; align-items: stretch; gap: 6px; padding-top: 8px; padding-bottom: 6px; }
  .brand { padding: 0 4px; }
  .nav { margin-left: 0; justify-content: space-between; }
  .nav { gap: 0; }
  .nav a { padding: 6px 6px; font-size: 0.88rem; }
  .sticky-top { top: 84px; }
  .main { padding-top: 18px; }
  h1 { font-size: 1.5rem; }
  .prompt-main { font-size: 1.9rem; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .stat { padding: 10px; }
  .stat-num { font-size: 1.2rem; }
  .verb-list .inf { min-width: 6.5em; }
}

@media (max-width: 380px) {
  .nav a { padding: 6px 4px; font-size: 0.84rem; }
}
