:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efe9dc;
  --text: #1d2424;
  --muted: #5d6868;
  --accent: #0f5c5d;
  --accent-ink: #ffffff;
  --accent-soft: #d7ebea;
  --good: #1f7a3d;
  --bad: #b03a2e;
  --line: #ddd5c4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --radius: 16px;
  --script-font: "Amiri Quran", "Amiri", "Scheherazade New", "Geeza Pro", "Noto Naskh Arabic", serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1515;
    --surface: #162121;
    --surface-2: #1d2b2b;
    --text: #e9efee;
    --muted: #9fb0af;
    --accent: #4fb3b0;
    --accent-ink: #062020;
    --accent-soft: #1c3a3a;
    --good: #5fcf85;
    --bad: #ff8a7a;
    --line: #2a3a3a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: var(--accent-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; letter-spacing: .2px; }
.pack-picker select {
  max-width: 60vw; background: rgba(255,255,255,.15); color: inherit;
  border: 1px solid rgba(255,255,255,.35); border-radius: 10px; padding: 6px 8px;
}
.pack-picker select option { color: #000; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); }

/* Home */
.stats-card {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: var(--surface); border-radius: var(--radius); padding: 14px 8px; box-shadow: var(--shadow);
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat .num { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: .8rem; color: var(--muted); }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.mode-btn {
  display: flex; flex-direction: column; gap: 4px; min-height: 96px; padding: 14px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: var(--text); border: 1px solid var(--line);
}
.mode-btn .t { font-weight: 700; font-size: 1.05rem; }
.mode-btn .d { font-size: .85rem; color: var(--muted); }
.mode-btn.primary { grid-column: 1 / -1; background: var(--accent); color: var(--accent-ink); border-color: transparent; min-height: 110px; }
.mode-btn.primary .d { color: inherit; opacity: .85; }
.notice { background: var(--accent-soft); padding: 10px 12px; border-radius: 12px; font-size: .9rem; }
.offline { color: var(--muted); font-size: .85rem; }

/* Session */
.session-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.session-head h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.back { text-decoration: none; white-space: nowrap; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; }
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.options:empty { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip[disabled] { opacity: .45; cursor: not-allowed; }
.options .label { width: 100%; font-size: .85rem; color: var(--muted); }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 16px; text-align: center; min-height: 200px;
}
.card-hint { margin: 0 0 6px; color: var(--muted); font-size: .9rem; min-height: 1.3em; }
.script {
  font-family: var(--script-font); font-size: clamp(3rem, 16vw, 5.5rem); line-height: 1.6;
  direction: rtl; min-height: 1.6em; word-break: break-word;
}
.script.small { font-size: clamp(1.8rem, 9vw, 3rem); }
.script.hidden-word { color: transparent; text-shadow: 0 0 22px var(--muted); user-select: none; }
.translit { font-size: 1.25rem; color: var(--muted); font-style: italic; min-height: 1.4em; }
.reveal { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.meanings { font-size: 1.35rem; font-weight: 600; }
.note { color: var(--muted); font-size: .95rem; margin: 8px 0; }
.example { background: var(--surface-2); border-radius: 12px; padding: 10px; margin-top: 8px; }
.example .ex-script { font-family: var(--script-font); font-size: 1.6rem; direction: rtl; line-height: 1.9; }
.example .ex-tr { font-style: italic; color: var(--muted); }
.example .ex-ref { font-size: .8rem; color: var(--muted); }

.heard { min-height: 1.5em; text-align: center; margin: 12px 0 0; font-size: 1.05rem; }
.heard.ok { color: var(--good); }
.heard.miss { color: var(--bad); }
.status { text-align: center; color: var(--muted); min-height: 1.5em; margin: 4px 0 12px; }
.status.listening::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--bad); margin-right: 8px; animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.controls { display: flex; flex-direction: column; gap: 10px; }
.big-btn {
  width: 100%; min-height: 72px; border-radius: 18px; border: 0; cursor: pointer;
  font-size: 1.4rem; font-weight: 700; background: var(--accent); color: var(--accent-ink);
}
.big-btn.stop { background: var(--bad); color: #fff; }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row button, .progress button {
  min-height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.voice-help { font-size: .8rem; color: var(--muted); text-align: center; }

/* Driving: fewer things, bigger */
body.driving { --bg: #050909; --surface: #0d1616; --text: #f2f7f6; --muted: #9fb0af; --line: #223030; }
body.driving .topbar { display: none; }
body.driving .card { min-height: 38vh; display: flex; flex-direction: column; justify-content: center; }
body.driving .reveal .note, body.driving .reveal .example { display: none; }
body.driving .big-btn { min-height: 120px; font-size: 2rem; }
body.driving .status { font-size: 1.4rem; }

/* Word list */
.search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px;
}
.word-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.word-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  background: var(--surface); border-radius: 12px; padding: 10px 12px; cursor: pointer; border: 1px solid var(--line);
}
.word-list .w { font-family: var(--script-font); font-size: 1.8rem; direction: rtl; text-align: right; grid-column: 2; grid-row: 1 / span 2; }
.word-list .m { font-weight: 600; }
.word-list .x { color: var(--muted); font-size: .85rem; }
.box-badge { display: inline-block; min-width: 1.6em; text-align: center; border-radius: 6px; font-size: .75rem; padding: 1px 4px; background: var(--surface-2); color: var(--muted); margin-right: 6px; }
.box-badge.known { background: var(--accent-soft); color: var(--accent); }

/* Progress */
.big-line { font-size: 1.3rem; font-weight: 600; }
.boxes { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 8px 0; }
.boxes .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: .8rem; color: var(--muted); }
.boxes .fill { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; }
.small { font-size: .88rem; color: var(--muted); }
.progress h2 { font-size: 1.05rem; margin-top: 24px; }
.progress button { padding: 0 16px; }
.danger { color: var(--bad); }

.diag { white-space: pre-wrap; font-size: .75rem; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px; }
.diag:empty { display: none; }
