:root {
  --bg: #14100d;
  --surface: #1f1a16;
  --surface-2: #2a231d;
  --line: #3a2f27;
  --ink: #f3ece4;
  --ink-dim: #b8a998;
  --ink-faint: #8a7a68;
  --accent: #e8913c;
  --accent-soft: #3a2a18;
  --good: #6bbf7b;
  --bad: #e2684f;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6f1;
    --surface: #fff;
    --surface-2: #f3ece3;
    --line: #e4d8ca;
    --ink: #241c15;
    --ink-dim: #6b5c4c;
    --ink-faint: #9c8b78;
    --accent: #b7651a;
    --accent-soft: #fbeeda;
    --good: #2f7d45;
    --bad: #b93f28;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; cursor: pointer; }

#app { max-width: 640px; margin: 0 auto; padding: 0 16px 96px; }

/* ---------- header ---------- */
header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 0 14px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 72%, transparent);
}
header.top h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.01em; flex: 1; }
header.top .sub { font-size: 12.5px; color: var(--ink-faint); font-weight: 450; }

.back {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  width: 36px; height: 36px; display: grid; place-items: center; font-size: 17px; flex: none;
}
.back:active { transform: scale(0.94); }

.streak {
  font-size: 13px; color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--line); padding: 5px 11px; border-radius: 999px; font-variant-numeric: tabular-nums;
}

/* ---------- generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
}

.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 14px 18px; font-weight: 600; font-size: 15.5px; width: 100%;
}
@media (prefers-color-scheme: light) { .btn { color: #fff; } }
.btn:active { transform: scale(0.985); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.slim { padding: 10px 14px; font-size: 14px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: 13px; }

/* ---------- unit list ---------- */
.unit {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 9px;
}
.unit:active { background: var(--surface-2); }
.unit .kn-tag {
  font-size: 15px; color: var(--accent); min-width: 74px; flex: none;
  font-feature-settings: "kern";
}
.unit .meta { flex: 1; min-width: 0; }
.unit .meta b { font-weight: 600; font-size: 15.5px; display: block; }
.unit .meta span { font-size: 12.5px; color: var(--ink-faint); }
.pill {
  font-size: 11.5px; padding: 3px 8px; border-radius: 999px; flex: none;
  background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums;
}
.pill.done { background: transparent; color: var(--good); border: 1px solid var(--line); }

.bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 7px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }

/* ---------- flashcard ---------- */
.stage { padding-top: 6px; }

.phrase {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px 22px; text-align: center; margin-bottom: 14px;
}
.phrase .ro {
  font-size: 30px; font-weight: 620; letter-spacing: -0.015em; line-height: 1.25;
  word-break: break-word;
}
.phrase .ro.small { font-size: 23px; }
.phrase .en { font-size: 16.5px; color: var(--ink-dim); margin-top: 12px; }
.phrase .en.big { font-size: 25px; font-weight: 600; color: var(--ink); }
.phrase .script { font-size: 19px; color: var(--ink-faint); margin-top: 10px; }
/* The Devanagari spelling sits directly under the romanisation: same word,
   second script, so the eye reads them as one thing rather than two. */
.phrase .dev { display: block; font-size: 22px; color: var(--accent); margin-top: 6px; }
.phrase .dev:empty { display: none; }
.phrase .hi {
  font-size: 14px; color: var(--accent); margin-top: 12px;
  background: var(--accent-soft); display: inline-block; padding: 5px 12px; border-radius: 999px;
}
.phrase .lit { font-size: 13px; color: var(--ink-faint); margin-top: 10px; font-style: italic; }

.speaker {
  width: 62px; height: 62px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--accent-soft); color: var(--accent); font-size: 25px;
  display: grid; place-items: center; margin: 0 auto 6px;
}
/* The slow take sits beside the normal one rather than under it, and smaller:
   it is the second thing you reach for, not an equal choice. */
.play-pair { display: flex; justify-content: center; align-items: center; gap: 12px; margin-bottom: 6px; }
.play-pair .speaker { margin: 0; }
.speaker.slow {
  width: 46px; height: 46px; font-size: 20px;
  background: transparent; color: var(--ink-dim);
}
.speaker:active { transform: scale(0.92); }
.speaker.playing { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 14%, transparent); } }

.counter {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; color: var(--ink-faint); margin-bottom: 10px; font-variant-numeric: tabular-nums;
}

/* ---------- choices ---------- */
.choice {
  display: block; width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 15px 16px;
  margin-bottom: 8px; font-size: 16px; transition: background .12s, border-color .12s;
}
.choice:active { background: var(--surface-2); }
.choice .sub { display: block; font-size: 13px; color: var(--ink-faint); margin-top: 3px; }
.choice.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.choice.reveal { border-color: var(--good); }
.choice[disabled] { pointer-events: none; }
/* An option you can hear: the speaker and the word are separate tap targets,
   so hearing one never risks answering with it. */
.choice-wrap { display: flex; align-items: stretch; gap: 8px; margin-bottom: 8px; }
.choice-wrap .choice { margin-bottom: 0; flex: 1; min-width: 0; }
.hear {
  flex: none; width: 56px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 19px; color: var(--accent); cursor: pointer;
}
.hear:active { background: var(--surface-2); }
.hear[disabled] { opacity: .45; pointer-events: none; }

/* ---------- grading ---------- */
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.grades button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 4px; font-size: 13px; font-weight: 560;
}
.grades button small { display: block; font-size: 10.5px; color: var(--ink-faint); font-weight: 400; margin-top: 2px; }
.grades button.g0 { color: var(--bad); }
.grades button.g3 { color: var(--good); }

/* ---------- patterns ---------- */
.pat { border-left: 2px solid var(--accent); padding-left: 14px; margin: 16px 0; }
.pat b { font-size: 16px; color: var(--accent); }
.pat p { margin: 5px 0 8px; font-size: 14.5px; color: var(--ink-dim); }
.pat li { font-size: 14px; margin-bottom: 5px; color: var(--ink); }
.pat ul { margin: 0; padding-left: 17px; }

/* ---------- phrasebook ---------- */
.search {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 15px; font-size: 16px; color: var(--ink); margin-bottom: 12px;
}
.search::placeholder { color: var(--ink-faint); }
.pb-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--line); padding: 13px 2px;
}
.pb-item .ico { color: var(--accent); font-size: 17px; flex: none; }
.pb-item .t { flex: 1; min-width: 0; }
.pb-item .t b { display: block; font-size: 15.5px; font-weight: 580; }
.pb-item .t span { font-size: 13px; color: var(--ink-dim); }

/* ---------- misc ---------- */
.banner {
  background: var(--accent-soft); border: 1px solid var(--line); color: var(--ink-dim);
  border-radius: 12px; padding: 13px 15px; font-size: 13.5px; margin-bottom: 12px;
}
.banner b { color: var(--accent); }

.done-screen { text-align: center; padding: 40px 0; }
.done-screen .big { font-size: 46px; }
.done-screen h2 { margin: 12px 0 6px; font-size: 21px; }

.setting {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line);
}
.setting:last-child { border-bottom: none; }
.setting label { font-size: 15px; }
.setting .hint { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
select, input[type=range] { accent-color: var(--accent); }
select {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; font-size: 14px; max-width: 190px;
}
.switch { width: 50px; height: 30px; border-radius: 999px; background: var(--line); border: none; position: relative; flex: none; }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.switch[aria-checked=true] { background: var(--accent); }
.switch[aria-checked=true]::after { transform: translateX(20px); }

.heard { font-size: 15px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 10px; }
.heard .lbl { font-size: 11.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; }

nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  flex: 1; text-align: center; padding: 10px 0 12px; font-size: 10.5px;
  color: var(--ink-faint); text-decoration: none;
}
nav.tabs a .i { display: block; font-size: 19px; margin-bottom: 1px; }
nav.tabs a.on { color: var(--accent); }
