/* Mobile-first styles. System fonts only (no network). */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #17202e;
  --muted: #5b6577;
  --border: #d6dbe4;
  --primary: #1d4ed8;
  --primary-text: #ffffff;
  --primary-press: #1e40af;
  --good: #116b3a;
  --good-bg: #e6f4ec;
  --almost: #8a5a00;
  --almost-bg: #fdf3dc;
  --retry: #9b2c2c;
  --retry-bg: #fbeaea;
  --mark: #b45309;
  --focus: #f59e0b;
  --radius: 14px;
  --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1724;
    --surface: #182233;
    --surface-2: #213049;
    --text: #e8edf5;
    --muted: #a3afc2;
    --border: #2e3d57;
    --primary: #5b8def;
    --primary-text: #0b1220;
    --primary-press: #7aa3f3;
    --good: #6fd39b;
    --good-bg: #13321f;
    --almost: #f3c25a;
    --almost-bg: #3a2c0c;
    --retry: #f19b9b;
    --retry-bg: #3b1a1a;
    --mark: #f6ad55;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

.app { min-height: 100dvh; display: flex; justify-content: center; }
.screen {
  width: 100%;
  max-width: 34rem;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.loading { justify-content: center; align-items: center; min-height: 100dvh; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
[hidden] { display: none !important; }

a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.topbar h1 { flex: 1; }

button, .btn {
  font: inherit;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.primary:active { background: var(--primary-press); }
.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.link { background: none; border-color: transparent; color: var(--primary); padding: 10px 8px; }
.icon-btn { min-width: var(--tap); padding: 0; font-size: 1.3rem; background: none; border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { color: var(--good); background: var(--good-bg); border-color: transparent; }
.badge.warn { color: var(--almost); background: var(--almost-bg); border-color: transparent; }
.badge.test { color: var(--retry); background: var(--retry-bg); border-color: transparent; font-weight: 600; }

.banner { border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.banner.info { background: var(--surface-2); }
.banner.warn { background: var(--almost-bg); color: var(--text); }
.banner.test { background: var(--retry-bg); }

.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > div { height: 100%; background: var(--primary); width: 0; border-radius: 999px; transition: width 0.3s; }

.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu .btn { min-height: 64px; flex-direction: column; gap: 2px; font-weight: 600; }
.menu .btn small { font-weight: 400; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.kpi strong { display: block; font-size: 1.35rem; }
.kpi span { font-size: 0.8rem; color: var(--muted); }

/* ---------- Session ---------- */
.session-screen {
  height: 100dvh;
  padding-bottom: 0;
  gap: 0;
}
.session-screen .topbar { flex: none; }
.progress { flex: 1; }
.count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; min-width: 3.5em; text-align: right; }
.session-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 0 12px;
}
.instruction { font-size: 0.9rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.situation { color: var(--muted); font-style: italic; }
.sentence { font-size: 1.35rem; line-height: 1.45; font-weight: 500; }
.gap {
  display: inline-block; min-width: 3.5em; border-bottom: 3px solid var(--primary);
  color: transparent; line-height: 1; user-select: none;
}
.focus-word { background: var(--almost-bg); border-radius: 4px; padding: 0 3px; font-weight: 700; }
.prompt-nl { font-size: 1.4rem; font-weight: 600; }
.cue { font-size: 1rem; }
.cue strong { font-weight: 700; }
.translation { color: var(--muted); }
.base-form { color: var(--muted); }
.hints { margin: 0; padding-left: 1.2em; color: var(--almost); }

.dock {
  flex: none;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}
.answer {
  width: 100%;
  font: inherit;
  font-size: 1.25rem;
  min-height: 54px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.answer:focus { border-color: var(--primary); outline: none; }
.answer[aria-readonly="true"] { background: var(--surface-2); }
.answer.good { border-color: var(--good); }
.answer.almost { border-color: var(--almost); }
.answer.retry { border-color: var(--retry); }
.umlauts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.umlauts button { min-height: 44px; font-size: 1.15rem; padding: 0; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions .grow { flex: 1; }
.actions button { white-space: nowrap; padding: 10px 12px; }
.actions .link { padding: 10px 6px; }
.actions .primary { flex: 1 1 auto; min-width: 0; margin-left: auto; }
h1[tabindex="-1"]:focus { outline: none; }

.options { display: flex; flex-direction: column; gap: 10px; }
.options button { justify-content: flex-start; text-align: left; min-height: 56px; }
.options button.correct { border-color: var(--good); background: var(--good-bg); }
.options button.chosen-wrong { border-color: var(--retry); background: var(--retry-bg); }

.feedback { border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.feedback.good { background: var(--good-bg); }
.feedback.almost { background: var(--almost-bg); }
.feedback.retry { background: var(--retry-bg); }
.feedback h2 { font-size: 1.2rem; }
.feedback.good h2 { color: var(--good); }
.feedback.almost h2 { color: var(--almost); }
.feedback.retry h2 { color: var(--retry); }
.answer-line strong { font-size: 1.15rem; }
.seg-ok { color: var(--good); font-weight: 600; }
.seg-bad { color: var(--retry); font-weight: 600; text-decoration: underline wavy; }
.seg-mid { color: var(--almost); font-weight: 600; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 40px; padding: 6px 12px; border-radius: 999px; font-size: 0.95rem; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

details.explain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px; }
details.explain summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 600; cursor: pointer; }
details.explain[open] { padding-bottom: 14px; }
.explain .block { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.explain .label { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.explain ul { margin: 0; padding-left: 1.1em; }
.tokens { display: flex; flex-wrap: wrap; gap: 4px 2px; font-size: 1.15rem; }
.token-btn {
  min-height: 36px; padding: 2px 6px; border-radius: 8px; border: 1px dashed var(--border); background: transparent; font-size: inherit;
}
.token-btn[aria-pressed="true"] { border: 1px solid var(--mark); color: var(--mark); font-weight: 700; }
.token-plain { padding: 6px 2px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list a {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-decoration: none; min-height: 56px;
}
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 0.9rem; }
.search { width: 100%; font: inherit; min-height: var(--tap); padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.history { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.history td, .history th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
pre.raw { font-size: 0.75rem; overflow-x: auto; background: var(--surface-2); padding: 8px; border-radius: 8px; }

/* ---------- Forms & dialogs ---------- */
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; padding: 0 6px; }
label.radio, label.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
input[type="radio"], input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); }
input[type="number"] { font: inherit; width: 6em; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
dialog { border: none; border-radius: var(--radius); padding: 18px; max-width: min(30rem, 92vw); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog .actions { flex-wrap: wrap; justify-content: flex-end; margin-top: 12px; }
.danger { color: var(--retry); border-color: var(--retry); }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 0.95rem; opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

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

@media (min-width: 40rem) {
  .screen { padding-top: 24px; }
}
