/* Finnish Inflection Drill — dark theme, modern UI refresh.
 *
 * Design notes:
 *   - Palette is layered grays with a subtle blue tint + soft accent glow.
 *   - Typography uses a system stack that prefers Inter when installed, so
 *     everything still works offline (no web-font fetch).
 *   - Radius scale: sm (6) for controls, md (10) for inputs, lg (14) for
 *     panels — keeps the rhythm consistent.
 *   - Motion is 150ms / custom ease; respects prefers-reduced-motion.
 */

:root {
  /* Surfaces */
  --bg:            #0f1115;
  --bg-soft:       #14171d;
  --panel:         #1b1f27;
  --panel-2:       #242933;
  --panel-hover:   #2a303c;

  /* Text */
  --text:          #e6e8ec;
  --text-dim:      #c4c7cf;
  --muted:         #8b909a;
  --muted-soft:    #6b7280;

  /* Accent + semantic */
  --accent:        #7aa7ff;
  --accent-soft:   #4f78c8;
  --accent-glow:   rgba(122, 167, 255, 0.32);
  --accent-wash:   rgba(122, 167, 255, 0.10);
  --on-accent:     #0a0c10;
  --danger:        #f87171;
  --danger-soft:   rgba(248, 113, 113, 0.12);
  --ok:            #4ade80;
  --ok-soft:       rgba(74, 222, 128, 0.12);

  /* Lines + shadows */
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md:     0 6px 20px rgba(0, 0, 0, 0.28);
  --shadow-lg:     0 14px 44px rgba(0, 0, 0, 0.36);

  /* Geometry + motion */
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     14px;
  --ease:          cubic-bezier(0.2, 0.7, 0.1, 1);
  --dur:           150ms;
}

/* Light theme overrides — applied when the user (or system) picks light.
 * We keep the same semantic variable names so every rule below still works;
 * only the palette flips. Accent goes darker/saturated to stay legible on
 * near-white surfaces. */
:root[data-theme="light"] {
  --bg:            #f6f7fa;
  --bg-soft:       #eef1f6;
  --panel:         #ffffff;
  --panel-2:       #f1f4f8;
  --panel-hover:   #e8ecf2;

  --text:          #161a22;
  --text-dim:      #3a4150;
  --muted:         #6b7280;
  --muted-soft:    #9aa0ac;

  --accent:        #2f5bd1;
  --accent-soft:   #4f78c8;
  --accent-glow:   rgba(47, 91, 209, 0.22);
  --accent-wash:   rgba(47, 91, 209, 0.07);
  --on-accent:     #ffffff;
  --danger:        #c2362f;
  --danger-soft:   rgba(194, 54, 47, 0.10);
  --ok:            #1f8f3c;
  --ok-soft:       rgba(31, 143, 60, 0.10);

  --border:        rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.18);
  --shadow-sm:     0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md:     0 6px 20px rgba(17, 24, 39, 0.08);
  --shadow-lg:     0 14px 44px rgba(17, 24, 39, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, var(--accent-wash), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", "Segoe UI Variable", "Segoe UI", system-ui,
               -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}
@media (max-width: 520px) {
  main { padding: 1.25rem 0.9rem 3rem; }
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
h1 {
  color: var(--text);
  margin: 0;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
}
/* Little accent diamond before the title — cheap brand mark. */
h1::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  transform: translateY(-1px) rotate(45deg);
  box-shadow: 0 0 14px var(--accent-glow);
  flex-shrink: 0;
}
.version {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0;
  margin-left: 0.2rem;
  padding: 0.12rem 0.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  vertical-align: middle;
}
.about-version {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  margin-top: 1rem !important;
}

/* ---------- Mode switch (segmented control) ---------- */
.mode-switch {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.mode-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.mode-btn:hover { color: var(--text); }
.mode-btn[aria-selected="true"] {
  background: linear-gradient(180deg, var(--accent), var(--accent-soft));
  color: var(--on-accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}
@media (max-width: 420px) {
  .mode-btn { padding: 0.4rem 0.75rem; font-size: 0.88rem; }
}

/* ---------- Panel base ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
  margin: 0.9rem 0;
  box-shadow: var(--shadow-sm);
}
.hidden { display: none !important; }

/* Description text used under panel headers. */
.panel-description {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.9rem;
  line-height: 1.55;
}

/* ---------- Challenge (hero) ---------- */
.challenge {
  text-align: center;
  padding: 2.2rem 1.4rem;
  background:
    radial-gradient(circle at 50% 0%, var(--accent-wash), transparent 65%),
    var(--panel);
}
.word-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.headword {
  font-size: 2.4rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.translation {
  color: var(--muted);
  font-style: italic;
  font-size: 1rem;
}
.target-form {
  margin-top: 0.75rem;
  font-size: 1.05rem;
  color: var(--text-dim);
  letter-spacing: 0.01em;
  font-weight: 500;
}

/* Speaker button — inline with the headword. */
.speak-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 2.1rem;
  height: 2.1rem;
  line-height: 1;
  cursor: pointer;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.speak-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--panel-2);
}
.speak-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Example sentences */
.examples {
  list-style: none;
  padding: 0;
  margin: 1.1rem auto 0;
  text-align: left;
  max-width: 55ch;
}
.examples li {
  color: var(--text-dim);
  font-size: 0.92rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
}
.examples li:first-child { border-top: none; }
.examples .ex-highlight { color: var(--accent); font-weight: 600; }
.examples .ex-fi { color: var(--text); }
.examples .ex-en { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; display: block; }

/* TTS warning banner */
.tts-warning {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
  padding: 0.55rem 0.8rem;
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.22);
  border-radius: var(--radius-sm);
}

/* ---------- Answer area ---------- */
.answer-row { display: flex; flex-direction: column; gap: 0.75rem; }

input[type="text"] {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 1.1rem;
  font-family: inherit;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
input[type="text"]::placeholder { color: var(--muted-soft); }
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.feedback {
  min-height: 1.5em;
  font-size: 0.95rem;
  font-weight: 500;
}
.feedback.ok  { color: var(--ok); }
.feedback.bad { color: var(--danger); }

/* Hint row */
.hint-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.hint-btn {
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease), transform 80ms var(--ease);
}
.hint-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--panel-hover);
}
.hint-btn:active { transform: translateY(1px); }
.hint-btn:disabled { opacity: 0.45; cursor: not-allowed; }

kbd {
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0.05em 0.4em;
  font-size: 0.78em;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  color: var(--muted);
}

/* ---------- Filters ---------- */
.filters { display: flex; flex-direction: column; gap: 1.25rem; }
.filter-section-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.filter-section-head h2 {
  font-size: 0.78rem;
  margin: 0;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.mini-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }

/* Case grid */
.case-grid {
  border-collapse: collapse;
  width: 100%;
}
.case-grid th,
.case-grid td {
  padding: 0.4rem 0.5rem;
  text-align: left;
}
.case-grid thead th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.55rem;
}
.case-grid thead th label { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.35rem; }
.case-grid .case-name  { color: var(--text-dim); }
.case-grid .case-cell  { width: 80px; text-align: center; }
.case-grid .case-cell.disabled { opacity: 0.15; }
.case-grid tbody tr { transition: background 120ms var(--ease); }
.case-grid tbody tr:hover { background: var(--accent-wash); }
.case-grid input[type="checkbox"] {
  cursor: pointer;
  transform: scale(1.1);
  accent-color: var(--accent);
}

/* Group list (noun groups, verb groups) */
.group-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.3rem 1rem;
}
.inline-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.5rem;
}
.group-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms var(--ease);
}
.group-row:hover { background: var(--accent-wash); }
.group-row input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.group-label   { color: var(--text); }
.group-example { color: var(--muted); font-size: 0.85em; font-style: italic; }

/* Update banner — fixed strip at the top of the viewport. Intentionally
 * narrow on z-index budget (z: 50) so modal-style dialogs (confirm, prompt)
 * still appear above it. */
.update-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  background: linear-gradient(180deg, var(--accent), var(--accent-soft));
  color: var(--on-accent);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.update-banner .mini-btn {
  background: rgba(255, 255, 255, 0.18);
  color: var(--on-accent);
  border-color: rgba(255, 255, 255, 0.35);
  font-weight: 600;
}
.update-banner .mini-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}
.update-banner-close {
  background: transparent;
  color: var(--on-accent);
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  opacity: 0.75;
}
.update-banner-close:hover { opacity: 1; }

/* Presets panel: list of saved filter configurations, per mode. Each row
 * has a name button (click = apply) and a small trash button on the right.
 * The whole row is a button, so the layout hugs tightly to the edges. */
.preset-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.preset-empty {
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
  padding: 0.3rem 0.1rem;
}
.preset-row {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}
.preset-apply {
  flex: 1;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.preset-apply:hover {
  background: var(--panel-hover);
  border-color: var(--border-strong);
}
.preset-delete {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 0.6rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.preset-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Variant for rows whose control isn't a simple checkbox+label (e.g. the
 * priority-mode radiogroup with its explanatory footer). Stacks vertically
 * and drops the row-level hover/pointer so it doesn't look clickable as a
 * whole. */
.group-row-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  cursor: default;
}
.group-row-stack:hover { background: transparent; }

/* ---------- Settings ---------- */
.inline-number {
  width: 4.5em;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.45rem;
  font-size: 0.9rem;
  font-family: inherit;
  margin: 0 0.2rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.inline-number:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.inline-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.45rem;
  font-size: 0.9rem;
  font-family: inherit;
  margin: 0 0.2rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.inline-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- Options panel ---------- */
#options-panel h2 {
  color: var(--accent);
  font-size: 1.2rem;
  margin: 0 0 0.6rem;
  letter-spacing: -0.01em;
  font-weight: 600;
}
.options-group {
  margin-top: 1.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}
.options-group:first-of-type {
  margin-top: 0.8rem;
  padding-top: 0;
  border-top: none;
}
.options-group h3 {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0 0 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.options-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.4rem;
}
.import-feedback {
  min-height: 1.2em;
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.import-feedback.ok  { color: var(--ok); }
.import-feedback.bad { color: var(--danger); }

/* Segmented switch (theme picker). Same silhouette as the mode-switch at the
 * top but scaled for inline use inside Options. */
.seg-switch {
  display: inline-flex;
  gap: 0.15rem;
  padding: 0.2rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: linear-gradient(180deg, var(--accent), var(--accent-soft));
  color: var(--on-accent);
  box-shadow: 0 1px 6px var(--accent-glow);
}

/* Daily streak badge — lives inside the h1 next to the version tag. */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0;
  color: #f0a64a;
  padding: 0.12rem 0.55rem;
  background: rgba(240, 166, 74, 0.12);
  border: 1px solid rgba(240, 166, 74, 0.28);
  border-radius: 999px;
  vertical-align: middle;
  white-space: nowrap;
}
:root[data-theme="light"] .streak-badge {
  color: #b8761f;
  background: rgba(240, 166, 74, 0.16);
  border-color: rgba(240, 166, 74, 0.45);
}

/* ---------- Test mode ---------- */
.test-controls { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.test-controls label {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.test-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  background: var(--accent-wash);
  border: 1px solid var(--accent-glow);
  border-radius: var(--radius);
}
.test-results { color: var(--text); }
.test-results h3 {
  color: var(--accent);
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
  font-weight: 600;
}
.test-results .summary {
  font-size: 1rem;
  margin: 0 0 0.9rem;
  color: var(--text-dim);
}
.test-results .wrong-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
  display: grid;
  gap: 0.3rem;
}
.test-results .wrong-list li {
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}
.test-results .wrong-list .expected {
  color: var(--ok);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.test-results .wrong-list .yours {
  color: var(--danger);
  text-decoration: line-through;
  opacity: 0.85;
}
.test-results .wrong-list .outcome {
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ---------- About panel ---------- */
.about h2 {
  color: var(--accent);
  font-size: 1.2rem;
  margin: 0 0 0.6rem;
  letter-spacing: -0.01em;
  font-weight: 600;
}
.about h3 {
  color: var(--text);
  font-size: 0.98rem;
  margin: 1.5rem 0 0.45rem;
  letter-spacing: -0.005em;
  font-weight: 600;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}
.about h3:first-of-type { border-top: none; padding-top: 0; }
.about p {
  color: var(--text-dim);
  line-height: 1.65;
  margin: 0.5rem 0;
}
.about ul {
  color: var(--text-dim);
  line-height: 1.6;
  margin: 0.4rem 0 0.8rem;
  padding-left: 1.2rem;
}
.about ul li { margin: 0.3rem 0; }
.about ul li::marker { color: var(--muted-soft); }
.about strong { color: var(--text); font-weight: 600; }
.about a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-glow);
  transition: border-color var(--dur) var(--ease);
}
.about a:hover { border-bottom-color: var(--accent); }

/* Keyboard-shortcut list reads better as a compact two-column grid. */
.about .shortcuts {
  list-style: none;
  padding-left: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.25rem 1rem;
}
.about .shortcuts li {
  margin: 0;
  padding: 0.2rem 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

/* ---------- Stats panel ---------- */
.stats-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stats-panel summary::-webkit-details-marker { display: none; }
.stats-panel summary::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 0.4em;
  font-size: 0.7em;
  transition: transform var(--dur) var(--ease);
}
.stats-panel[open] summary::before { transform: rotate(90deg); }
.stats-panel summary > span:first-child { flex: 1; }

.stats-overall {
  color: var(--text);
  font-size: 1rem;
  margin: 0.95rem 0 0.25rem;
}
.stats-overall-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}
.stats-group { margin-top: 1.2rem; }
.stats-group h2 {
  color: var(--accent);
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
  letter-spacing: -0.01em;
  font-weight: 600;
}
.stats-section { margin: 0.75rem 0 1.2rem; overflow-x: auto; }
.stats-section h3 {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0 0 0.4rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stats-empty {
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
  margin: 0.2rem 0 0.6rem;
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.stats-table th,
.stats-table td {
  padding: 0.38rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.stats-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.stats-table td.num,
.stats-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tbody tr { transition: background 120ms var(--ease); }
.stats-table tbody tr:hover { background: var(--accent-wash); }

/* Per-word section — controls above a Word/Forms/Attempts/Wrong/%/Weakest table.
 * Controls are sticky in layout terms: the <head> div stays put across
 * filter keystrokes (only the body re-renders) so focus stays on the input. */
.stats-words .stats-word-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.stats-words .stats-word-head h3 { margin: 0; }
.stats-word-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.stats-word-controls .stats-ctl {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.stats-word-search {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.22rem 0.55rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 11rem;
  max-width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stats-word-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.stats-word-table td.word {
  color: var(--text);
  font-weight: 500;
}
.stats-word-table td .muted { color: var(--muted); font-size: 0.85em; }
.stats-word-foot {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
}
.stats-word-foot .muted { color: var(--muted); }

@media (max-width: 600px) {
  .stats-table { font-size: 0.82rem; }
  .stats-table th,
  .stats-table td { padding: 0.25rem 0.4rem; }
  .stats-overall { font-size: 0.95rem; }
  .headword     { font-size: 2rem; }
  .challenge    { padding: 1.6rem 1rem; }
}

/* ---------- Status line ---------- */
.status-line {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 1.2rem;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ---------- Accessibility ---------- */
button:focus-visible,
.mode-btn:focus-visible,
.hint-btn:focus-visible,
.mini-btn:focus-visible,
.speak-btn:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition: none !important; animation: none !important; }
}
