:root {
  --bg: #eef6f8;
  --surface: #ffffff;
  --surface-2: #f4f9fb;
  --text: #102a35;
  --muted: #5b7380;
  --line: #d6e4ea;
  --accent: #0b7fa3;
  --accent-ink: #ffffff;
  --accent-soft: #d9f0f7;
  --good: #1f9d63;
  --good-soft: #e1f6ec;
  --bad: #d4543a;
  --bad-soft: #fdebe6;
  --learned: #1f9d63;
  --known: #0b7fa3;
  --learning: #f0a020;
  --new: #c3d2d9;
  --book: #e0453a;
  --shadow: 0 1px 2px rgb(16 42 53 / 6%), 0 4px 16px rgb(16 42 53 / 6%);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d26;
    --surface: #12303d;
    --surface-2: #163847;
    --text: #e8f3f7;
    --muted: #93adb8;
    --line: #23495a;
    --accent: #3cb8dc;
    --accent-ink: #062330;
    --accent-soft: #19455a;
    --good: #45c98c;
    --good-soft: #143d2e;
    --bad: #f07a60;
    --bad-soft: #43231c;
    --learned: #45c98c;
    --known: #3cb8dc;
    --learning: #f3b23e;
    --new: #3a5a68;
    --book: #c8463c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 17px/1.45 Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100dvh;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

button, input, select { font: inherit; color: inherit; }

.loading { text-align: center; color: var(--muted); margin-top: 30vh; }

/* header */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 12px;
}
.top h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.logo { font-size: 26px; }
.streak, .score { font-weight: 800; white-space: nowrap; }
.icon {
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  font-size: 20px; cursor: pointer;
}
.progress { flex: 1; height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }

/* buttons */
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn small { font-weight: 500; font-size: 13px; color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary small { color: inherit; opacity: .85; }
.btn.big { min-height: 64px; font-size: 20px; margin: 16px 0; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; box-shadow: none; margin-top: 24px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .opt:focus-visible, .icon:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 10px; margin-top: 10px; }
.row > * { flex: 1; }

/* home */
.unit {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.unit-id { font-size: 24px; font-weight: 800; }
.unit-sub { color: var(--muted); margin-bottom: 14px; }
.bar { display: flex; height: 14px; border-radius: 99px; background: var(--new); overflow: hidden; }
.seg { display: block; height: 100%; }
.seg.learned, .dot.learned { background: var(--learned); }
.seg.known, .dot.known { background: var(--known); }
.seg.learning, .dot.learning { background: var(--learning); }
.dot.new { background: var(--new); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; list-style: none; padding: 0; margin: 12px 0 0; font-size: 15px; color: var(--muted); }
.legend b { color: var(--text); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; flex: none; }
.today { margin-top: 10px; font-size: 15px; color: var(--muted); }
.allclear {
  margin: 16px 0;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--good-soft);
  color: var(--text);
  text-align: center;
  font-weight: 700;
}

/* session */
.mode { color: var(--muted); font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  text-align: center;
}
.tag { color: var(--accent); font-weight: 800; font-size: 15px; margin-bottom: 10px; }
.word { font-size: 30px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.ipa {
  font-family: 'Charis SIL', 'Doulos SIL', 'Lucida Grande', 'Segoe UI', system-ui, sans-serif;
  color: var(--muted);
  font-weight: 400;
}
.card .ipa { font-size: 18px; margin-top: 4px; }
.ua { font-size: 20px; font-weight: 700; margin-top: 10px; }
.ua.big { font-size: 26px; margin: 6px 0; }
.example, .sentence { font-size: 18px; margin: 14px 0 0; text-align: left; }
.sentence { font-size: 21px; text-align: center; }
.example { color: var(--muted); }
.example .fill { color: var(--text); }
.blank { color: var(--accent); font-weight: 800; letter-spacing: .05em; }
.hint { color: var(--muted); margin-top: 10px; font-size: 16px; }

.options { display: grid; gap: 10px; margin-top: 16px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 12px 16px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface);
  font-weight: 700; font-size: 18px; text-align: left; cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt kbd {
  font: 700 13px/1 system-ui, sans-serif; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px;
}
@media (hover: none) { .opt kbd { display: none; } }

.typed { margin-top: 16px; }
.pattern {
  white-space: pre; overflow-x: auto;
  text-align: center; font: 700 20px/1.4 ui-monospace, Menlo, monospace;
  color: var(--muted); margin-bottom: 10px;
}
.typed input {
  width: 100%; min-height: 58px; padding: 12px 16px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface); font-size: 22px; font-weight: 700; text-align: center;
}
.typed input:focus { outline: none; border-color: var(--accent); }
.note { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 15px; }

.reveal.good { background: var(--good-soft); }
.reveal.badc { background: var(--bad-soft); }
.verdict { font-size: 22px; font-weight: 800; margin-bottom: 10px; }
.reveal.good .verdict { color: var(--good); }
.reveal.badc .verdict { color: var(--bad); }
.mine { color: var(--muted); margin-bottom: 8px; }

.family { width: 100%; border-collapse: separate; border-spacing: 6px; margin-top: 14px; table-layout: fixed; }
.family th { font-size: 13px; color: var(--muted); font-weight: 700; }
.family td {
  background: var(--surface-2); border-radius: 10px; padding: 10px 4px;
  font-weight: 800; font-size: 17px; overflow-wrap: anywhere;
}
.family td.me { background: var(--accent-soft); }
.family td.blank-cell { background: var(--accent); color: var(--accent-ink); }

/* done */
.done .card { padding: 28px 18px; }
.mark { font-size: 64px; font-weight: 800; line-height: 1; }
.mark small { font-size: 24px; color: var(--muted); }
.sub { color: var(--muted); margin-top: 10px; }
h2 { font-size: 18px; margin: 24px 0 8px; }

/* word list */
.wordlist { list-style: none; padding: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.w { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.w:first-child { border-top: 0; }
.w-main { flex: 1; min-width: 0; }
.w .ipa { font-size: 14px; }
.w-ua { color: var(--muted); font-size: 15px; }
.muted { color: var(--muted); }

/* textbook table */
.vocab { margin-top: 28px; }
.vocab-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.vocab-title {
  background: var(--book); color: #fff;
  font-weight: 800; font-size: 18px;
  padding: 4px 12px; border-radius: 6px;
}
.vocab-tools {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 10px;
  background: var(--line); border-radius: 12px;
}
.vocab-tools button {
  flex: 1; min-height: 38px; padding: 4px 6px;
  border: 0; border-radius: 9px; background: transparent;
  font-weight: 700; font-size: 13px; line-height: 1.15; color: var(--muted); cursor: pointer;
}
.vocab-tools button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.vtable { list-style: none; padding: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.vrow {
  display: grid; grid-template-columns: 8px minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 10px; align-items: baseline;
  padding: 9px 12px; border-top: 1px solid var(--line);
  -webkit-tap-highlight-color: transparent;
}
.vrow:first-child { border-top: 0; }
.vtable[class*="hide-"] .vrow { cursor: pointer; }
.vrow .dot { width: 8px; height: 8px; margin: 0; align-self: center; }
.v-en { overflow-wrap: anywhere; }
.v-en b { font-weight: 800; }
.v-en .ipa { font-size: 14px; }
.v-ua { font-size: 15px; color: var(--muted); overflow-wrap: anywhere; }
.vtable.hide-ua .vrow:not(.peek) .v-ua,
.vtable.hide-en .vrow:not(.peek) .v-en {
  border-radius: 6px; background: var(--line); user-select: none;
}
.vtable.hide-ua .vrow:not(.peek) .v-ua,
.vtable.hide-en .vrow:not(.peek) .v-en,
.vtable.hide-en .vrow:not(.peek) .v-en * { color: transparent; }
.vocab-note { font-size: 14px; text-align: center; margin: 10px 0 0; }

/* settings */
.settings .field { display: block; margin: 0 0 18px; font-weight: 700; }
.settings .field small { display: block; color: var(--muted); font-weight: 500; margin-top: 6px; }
.settings input[type=number], .settings input[type=text] {
  display: block; width: 100%; margin-top: 6px; min-height: 48px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
}

@media (max-width: 380px) {
  .word { font-size: 26px; }
  .row { flex-direction: column; }
}
