:root {
  --bg: #F4F5F0;
  --surface: #FFFFFF;
  --surface-sunken: #E9EBE4;
  --ink: #1C2321;
  --ink-soft: #5B655F;
  --ink-faint: #8B948C;
  --rule: #D9DCD2;
  --accent: #2F6F6B;
  --accent-ink: #245552;
  --accent-soft: #E3EFED;
  --tag: #9A6B2E;
  --tag-soft: #F3E7D5;
  --good: #1F8A57;
  --good-soft: #DEF3E7;
  --bad: #B5484A;
  --bad-soft: #FBE6E5;
  --shadow: 0 1px 3px rgba(28,35,33,0.06), 0 8px 24px rgba(28,35,33,0.06);
  --accent-glow: rgba(47,111,107,0.32);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171A;
    --surface: #1B2124;
    --surface-sunken: #10151A;
    --ink: #E8ECE7;
    --ink-soft: #A2ACA5;
    --ink-faint: #6C756E;
    --rule: #2B3332;
    --accent: #74C9BF;
    --accent-ink: #9EDBD3;
    --accent-soft: #1E3634;
    --tag: #E0AD63;
    --tag-soft: #33291A;
    --good: #59C98A;
    --good-soft: #163326;
    --bad: #E98587;
    --bad-soft: #3A1E20;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 12px 30px rgba(0,0,0,0.35);
    --accent-glow: rgba(116,201,191,0.38);
  }
  .btn-next { background: var(--accent); color: #0E1213; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.serif {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
}

.app {
  max-width: 66rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  display: grid;
  grid-template-columns: 1fr 19rem;
  gap: 2.5rem;
  align-items: start;
}

@media (max-width: 54rem) {
  .app { grid-template-columns: 1fr; }
}

/* ---------- main column ---------- */

.main-col { display: flex; flex-direction: column; min-width: 0; }

.hud { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.1rem; }

.hud-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.82rem; color: var(--ink-soft); }

.hud-title { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-ink); font-weight: 600; }

.hud-score { font-variant-numeric: tabular-nums; }

.progress-track { height: 5px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }

.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0%; transition: width 0.4s ease; }

@media (prefers-reduced-motion: reduce) { .progress-fill { transition: none; } }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.filter-pill {
  font-size: 0.76rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.filter-pill:not(.active):hover { border-color: var(--ink-faint); color: var(--ink); }

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 700;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-pill.active::before { content: "✓ "; }

@media (prefers-reduced-motion: reduce) { .filter-pill { transition: none; } }

.card-wrap { width: 100%; min-height: 22rem; display: flex; }

.card {
  position: relative; width: 100%; min-height: 21rem;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: var(--shadow); padding: 2rem 1.85rem; display: flex; flex-direction: column;
  transition: border-color 0.3s ease;
}

.card.state-good { border-color: var(--good); }
.card.state-bad { border-color: var(--tag); }

.card.shake { animation: shake 0.4s ease; }

@media (prefers-reduced-motion: reduce) { .card.shake { animation: none; } }

@media (prefers-reduced-motion: reduce) {
  .cat-bar-fill, .ring-fill { transition: none; }
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.card-top-row { display: flex; align-items: center; margin-bottom: 1.1rem; }

.eyebrow {
  font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--tag);
  background: var(--tag-soft); display: inline-block; width: fit-content; padding: 0.15rem 0.55rem;
  border-radius: 3px;
}

.pos-tag { font-size: 0.78rem; font-style: italic; color: var(--ink-faint); margin-left: 0.6rem; }

.definition { font-size: 1.18rem; color: var(--ink); margin: 0 0 0.3rem; text-wrap: balance; }

.translation-line { font-size: 0.92rem; color: var(--ink-soft); margin: 0 0 1rem; }
.translation-line .translation-label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 4px; padding: 0.1rem 0.4rem; margin-right: 0.5rem;
}

.blank-example {
  font-size: 1rem; font-style: italic; color: var(--ink-soft); border-left: 2px solid var(--accent-soft);
  padding-left: 0.85rem; margin: 0;
}

.blank-mark { font-style: normal; color: var(--accent-ink); font-weight: 600; letter-spacing: 0.02em; }

form.guess-form { margin-top: auto; padding-top: 1.25rem; display: flex; flex-direction: column; gap: 0.65rem; }

.guess-input {
  font: inherit; font-size: 1.05rem; padding: 0.65rem 0.85rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--surface-sunken); color: var(--ink); width: 100%;
}

.guess-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.options-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.65rem; }

.option-pill {
  background: var(--surface-sunken); border: 1px solid var(--rule); color: var(--ink);
  font-weight: 600; padding: 0.55rem 0.7rem; border-radius: 8px; text-align: center;
}
.option-pill:hover:not(:disabled) { border-color: var(--accent); }
.option-pill.wrong { border-color: var(--bad); color: var(--bad); opacity: 0.65; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 0.6rem 1rem; font-size: 0.92rem;
  font-weight: 600; border: 1px solid transparent; transition: filter 0.15s ease, transform 0.1s ease;
}

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--bg); flex: 1; }
.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--rule); }
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-faint); }

.btn-next { background: var(--ink); color: var(--bg); width: 100%; }

.filled-word { font-style: normal; font-weight: 700; }
.filled-word.good { color: var(--good); }
.filled-word.bad { color: var(--tag); }

.back-status { font-size: 0.85rem; font-weight: 600; margin: 0.9rem 0 0; }
.back-status.good { color: var(--good); }
.back-status.bad { color: var(--tag); }

.resolved-actions { margin-top: auto; padding-top: 1.25rem; display: flex; flex-direction: column; gap: 0.65rem; }

.btn-listen {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  width: 100%;
}
.btn-listen:hover { color: var(--accent-ink); border-color: var(--accent); }
.btn-listen:disabled { opacity: 0.5; cursor: default; }

.btn-danger {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-faint);
  width: 100%;
  font-size: 0.82rem;
}
.btn-danger:hover { color: var(--bad); border-color: var(--bad); }

.summary { width: 100%; margin: 1rem auto; text-align: center; }
.summary h1 { font-size: 2rem; margin-bottom: 0.3rem; }
.summary .tally { font-size: 1.05rem; color: var(--ink-soft); margin-bottom: 1.75rem; }
.summary .tally strong { color: var(--good); font-variant-numeric: tabular-nums; }

.review-list { text-align: left; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 0.4rem 1.25rem; margin-bottom: 1.75rem; }
.review-item { padding: 0.9rem 0; border-bottom: 1px solid var(--rule); }
.review-item:last-child { border-bottom: none; }
.review-item .word { font-weight: 700; margin-right: 0.4rem; }
.review-item .def { color: var(--ink-soft); font-size: 0.92rem; }
.review-item .def-nl { color: var(--ink-faint); font-style: italic; }
.empty-review { color: var(--ink-soft); padding: 1.4rem 0; text-align: center; }

[hidden] { display: none !important; }

/* ---------- sidebar ---------- */

aside.stats {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.4rem 1.3rem 1.6rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 2rem;
}

@media (max-width: 54rem) { aside.stats { position: static; } }

.stats-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }

.stats-title { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-ink); font-weight: 600; }

.reset-btn {
  background: transparent; border: 1px solid var(--rule); color: var(--ink-faint);
  font-size: 0.72rem; padding: 0.3rem 0.6rem; border-radius: 6px;
}
.reset-btn:hover { color: var(--bad); border-color: var(--bad); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-bottom: 2rem; }

.stat-tile { background: var(--surface-sunken); border-radius: 10px; padding: 0.7rem 0.8rem; position: relative; transition: box-shadow 0.4s ease; }

.stat-tile-icon { display: block; width: 17px; height: 17px; color: var(--ink-faint); margin-bottom: 0.4rem; }

.stat-tile .num { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }

.stat-tile .label { font-size: 0.7rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.15rem; }

.stat-tile--pr { box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-glow); }

.stat-tile--pr .stat-tile-icon { color: var(--accent-ink); }

.accuracy-ring-wrap { position: relative; width: 44px; height: 44px; margin: 0.05rem 0 0.15rem; }

.accuracy-ring { transform: rotate(-90deg); }

.ring-track { fill: none; stroke: var(--rule); stroke-width: 4; }

.ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 113.1; stroke-dashoffset: 113.1;
  transition: stroke-dashoffset 1s cubic-bezier(0.16,1,0.3,1), stroke 0.3s ease;
}

.ring-fill.empty { stroke: var(--ink-faint); }

.accuracy-ring-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.74rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums;
}

.stats-section-title {
  font-size: 0.7rem; font-weight: 600; color: var(--ink-soft); margin: 0 0 0.8rem;
  text-transform: uppercase; letter-spacing: 0.08em;
}

details.stats-section summary.stats-section-title {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

details.stats-section summary.stats-section-title::-webkit-details-marker { display: none; }

details.stats-section summary.stats-section-title::before {
  content: "▸";
  font-size: 0.6rem;
  color: var(--ink-faint);
  transition: transform 0.15s ease;
}

details.stats-section[open] summary.stats-section-title::before { transform: rotate(90deg); }

details.stats-section summary.stats-section-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

details.stats-section .hard-list { margin-top: 0.7rem; }

@media (prefers-reduced-motion: reduce) {
  details.stats-section summary.stats-section-title::before { transition: none; }
}

.cat-row { margin-bottom: 0.75rem; }

.cat-row-head { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 0.3rem; }

.cat-bar-track { height: 6px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }

.cat-bar-fill {
  height: 100%; border-radius: 999px; background: var(--accent); width: 0%;
  transition: width 0.9s cubic-bezier(0.16,1,0.3,1), background-color 0.4s ease;
}

.cat-bar-fill--zero { background: var(--ink-faint); }
.cat-bar-fill--mid { background: var(--tag); }
.cat-bar-fill--high { background: var(--accent); }

.hard-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.9rem; }

.hard-item { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; padding: 0.4rem 0.55rem; background: var(--surface-sunken); border-radius: 8px; }

.hard-item .w { font-weight: 600; }

.hard-item-right { display: flex; align-items: center; gap: 0.5rem; }

.hard-item .frac { color: var(--ink-faint); font-variant-numeric: tabular-nums; font-size: 0.78rem; }

.hard-remove-btn {
  background: transparent;
  border: none;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
  line-height: 1;
  color: var(--ink-faint);
  border-radius: 5px;
}

.hard-remove-btn:hover { color: var(--bad); background: var(--bad-soft); }

.no-data { color: var(--ink-faint); font-size: 0.85rem; padding: 0.4rem 0; }

hr.stats-divider { border: none; border-top: 1px solid var(--rule); margin: 1.3rem 0; }

/* ---------- practice mode toggle ---------- */

.mode-toggle {
  display: inline-flex; gap: 0.2rem; padding: 0.2rem;
  background: var(--surface-sunken); border: 1px solid var(--rule); border-radius: 10px;
}

.mode-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.9rem; }

.mode-btn {
  background: transparent; color: var(--ink-soft); font-size: 0.82rem;
  padding: 0.4rem 0.9rem; border-radius: 7px;
}
.mode-btn:hover:not(.active) { color: var(--ink); }
.mode-btn.active { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }

/* ---------- flashcard mode ---------- */

.flash-word-row { display: flex; align-items: center; gap: 0.6rem; margin: 0.6rem 0 1rem; }
.flash-word { font-size: 2.2rem; font-weight: 700; margin: 0; line-height: 1.15; color: var(--ink); }
.card.flash-front .flash-word-row { flex: 1; justify-content: center; margin: 1.5rem 0; }

.btn-speak {
  background: transparent; border: 1px solid var(--rule); color: var(--ink-soft);
  padding: 0.3rem 0.5rem; font-size: 0.9rem; border-radius: 999px;
}
.btn-speak:hover { border-color: var(--accent); }

.flash-actions { margin-top: auto; padding-top: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash-hint { font-size: 0.74rem; color: var(--ink-faint); text-align: center; margin: 0; }

.btn-grade { flex: 1; border: 1px solid var(--rule); background: var(--surface-sunken); color: var(--ink); }
.btn-grade.miss:hover { border-color: var(--tag); color: var(--tag); background: var(--tag-soft); }
.btn-grade.knew:hover { border-color: var(--good); color: var(--good); background: var(--good-soft); }

.filled-word.flash { color: var(--accent-ink); }

.flash-word.nl { font-size: 1.55rem; font-weight: 600; text-align: center; text-wrap: balance; }

/* ---------- quiz hint + option shortcuts ---------- */

.hint-line {
  margin: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1rem;
  letter-spacing: 0.25em; color: var(--accent-ink);
}

.option-key {
  display: inline-block; min-width: 1.2rem; margin-right: 0.45rem; padding: 0 0.3rem;
  font-size: 0.7rem; font-weight: 600; color: var(--ink-faint);
  border: 1px solid var(--rule); border-radius: 4px; vertical-align: 1px;
}

.summary-actions { display: flex; flex-direction: column; gap: 0.6rem; }
.summary-actions button { width: 100%; padding: 0.8rem; }
#practiceMissedBtn + #restartBtn { background: transparent; color: var(--ink-soft); border-color: var(--rule); }

/* ---------- person switch ---------- */

.profile-toggle .mode-btn::before { content: "👤 "; font-size: 0.75rem; }
.profile-toggle .mode-btn.active { color: var(--tag); }

/* ---------- sub-category group label ---------- */

.filter-group {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--tag); background: transparent; border: none; padding: 0.32rem 0.2rem 0.32rem 0;
}
.filter-group:hover { text-decoration: underline; }
.filter-group-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; width: 100%; }
.filter-group { min-width: 3.6rem; text-align: left; }

/* ---------- unselect all + empty state ---------- */

.filter-toggle-all {
  font-size: 0.76rem; padding: 0.32rem 0.7rem; border-radius: 999px;
  background: transparent; border: 1px dashed var(--rule); color: var(--ink-faint);
}
.filter-toggle-all:hover { color: var(--ink); border-color: var(--ink-faint); }

.no-categories {
  width: 100%; min-height: 21rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.4rem; text-align: center; color: var(--ink-soft);
  border: 1px dashed var(--rule); border-radius: 14px; padding: 2rem;
}
.no-categories p { font-size: 1.4rem; color: var(--ink); margin: 0; }
