:root {
  --bg: #fbf6ef;
  --surface: #ffffff;
  --surface-2: #f4ebe0;
  --text: #2b2118;
  --muted: #7a6a5b;
  --line: #eadccb;
  --accent: #c2410c;
  --accent-soft: #fde7d6;
  --accent-text: #ffffff;
  --gold: #e9a23b;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(60, 35, 15, .06), 0 6px 20px rgba(60, 35, 15, .06);
  --radius: 16px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Bricolage Grotesque", "Nunito", system-ui, sans-serif;
  --font-ar: "Noto Naskh Arabic", "Geeza Pro", "Segoe UI", Tahoma, sans-serif;
  --font-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", sans-serif;
  color-scheme: light dark;
}
:root[data-lang="zh"] { --accent: #0f766e; --accent-soft: #d5f2ee; }
:root[data-lang="ru"] { --accent: #1d4ed8; --accent-soft: #dde7fd; }
:root[data-lang="de"] { --accent: #a16207; --accent-soft: #fbefcf; }
:root[data-lang="ar"] { --accent: #15803d; --accent-soft: #d9f5e3; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17120e;
    --surface: #221a14;
    --surface-2: #2c221a;
    --text: #f3eae0;
    --muted: #b3a291;
    --line: #3a2e24;
    --accent: #f0874a;
    --accent-soft: #3d2416;
    --accent-text: #1b120c;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
  :root:not([data-theme="light"])[data-lang="zh"] { --accent: #2dd4bf; --accent-soft: #10302c; }
  :root:not([data-theme="light"])[data-lang="ru"] { --accent: #7aa2ff; --accent-soft: #172447; }
  :root:not([data-theme="light"])[data-lang="de"] { --accent: #f2c14e; --accent-soft: #3a2c0c; }
  :root:not([data-theme="light"])[data-lang="ar"] { --accent: #4ade80; --accent-soft: #10301c; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 640px;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font: 800 1.45rem/1 var(--font-display); margin: 0; letter-spacing: -.02em; }
.logo {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: .8rem;
}
.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}

.langs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.langs::-webkit-scrollbar { display: none; }
.lang {
  flex: none; display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; white-space: nowrap;
}
.lang[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.lang .due { font-size: .75rem; padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.lang[aria-pressed="true"] .due { background: rgba(255,255,255,.25); color: inherit; }

.progress { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (max-width: 420px) { .progress { grid-template-columns: 1fr; } }
.meter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.meter-head { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; color: var(--muted); }
.meter-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.meter small { color: var(--muted); font-size: .8rem; }
.bar { position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; display: flex; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.bar i.sub { background: var(--gold); opacity: .55; }
.bar i.rev { background: var(--gold); }

.offline-note {
  margin-top: 10px; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft);
  font-size: .88rem; display: flex; justify-content: space-between; gap: 10px; align-items: center;
}

.tabs {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  margin: 14px -16px 0; padding: 8px 16px; background: var(--bg);
}
.tabs button {
  padding: 10px 4px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 700;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

main { padding-top: 8px; min-height: 50vh; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 22px 18px;
  box-shadow: var(--shadow); text-align: center;
}
.instr { margin: 6px 0 0; color: var(--muted); font-size: .9rem; font-weight: 600; }
.cat { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.prompt { font: 700 1.65rem/1.2 var(--font-display); margin: 4px 0 0; letter-spacing: -.01em; overflow-wrap: anywhere; }
.target { font-weight: 800; font-size: 1.9rem; line-height: 1.2; margin: 8px 0 2px; overflow-wrap: anywhere; }
.target.zh, .zh { font-family: var(--font-zh), var(--font); }
.target.zh { font-size: 2.6rem; font-weight: 600; }
.target.ar, .ar { font-family: var(--font-ar); }
.target.ar { font-size: 2.3rem; font-weight: 600; line-height: 1.5; }
.ex-t.ar { font-size: 1.15rem; line-height: 1.8; }
.opt.ar { font-size: 1.3rem; font-family: var(--font-ar); }
.word .t.ar { font-size: 1.25rem; font-weight: 600; }
[dir="rtl"] { unicode-bidi: isolate; }
.example p[dir="rtl"], .opt[dir="rtl"] { text-align: right; }
.pron { color: var(--muted); font-size: 1.05rem; letter-spacing: .02em; }
.meta { color: var(--muted); font-size: .85rem; }
.example { margin: 16px 0 0; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); text-align: left; }
.example p { margin: 0; }
.example .ex-t { font-weight: 700; }
.example .ex-p { color: var(--muted); font-size: .88rem; }
.example .ex-u { color: var(--muted); font-size: .92rem; margin-top: 4px; }
.row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.spacer { height: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 800;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.warn { background: var(--surface-2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.speak {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent-soft); color: var(--accent); flex: none;
}
.speak.small { width: 36px; height: 36px; }
.speak.playing { background: var(--accent); color: var(--accent-text); }

.options { display: grid; gap: 10px; margin-top: 18px; }
.opt {
  padding: 14px 16px; min-height: 54px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); text-align: left; font-weight: 700; font-size: 1.05rem;
}
.opt.zh { font-size: 1.35rem; font-weight: 600; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 14px; font-weight: 700; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.no { background: var(--bad-soft); color: var(--bad); }
.feedback .fix { display: block; font-weight: 600; color: var(--text); margin-top: 4px; }

.type-in {
  width: 100%; margin-top: 18px; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); font-size: 1.2rem; text-align: center;
}
.type-in:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint-box { margin-top: 14px; text-align: left; }
.hint-box label { font-size: .82rem; color: var(--muted); font-weight: 700; }
.hint-box textarea {
  width: 100%; min-height: 54px; margin-top: 4px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); resize: vertical; font-size: .95rem;
}
.hint-show { margin-top: 12px; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--accent); text-align: left; font-size: .92rem; }

.session-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 2px 10px; color: var(--muted); font-size: .9rem; }
.pill { padding: 3px 10px; border-radius: 99px; background: var(--surface-2); font-weight: 700; font-size: .8rem; }
.done-card h2 { font: 800 1.55rem/1.2 var(--font-display); margin: 12px 0 6px; letter-spacing: -.01em; }
.done-card p { color: var(--muted); margin: 0 0 16px; }
.done-icon { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); }

/* list */
.filters { display: grid; gap: 8px; margin-bottom: 12px; }
.filters input[type="search"], .filters select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.filters .row { justify-content: space-between; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: .92rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.count { color: var(--muted); font-size: .85rem; }
.words { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.word {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.word.learned { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.word .txt { min-width: 0; }
.word .t { font-weight: 800; overflow-wrap: anywhere; }
.word .t.zh { font-size: 1.2rem; font-weight: 600; }
.word .u { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.word .p { color: var(--muted); font-size: .8rem; }
.word .more { grid-column: 1 / -1; }
.word .open-btn { background: none; border: 0; padding: 0; text-align: left; width: 100%; }
.tick {
  width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  display: grid; place-items: center; color: transparent;
}
.tick[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.tick.partial { border-color: var(--gold); color: var(--gold); }
.status { font-size: .72rem; font-weight: 800; color: var(--gold); }
.status.ok { color: var(--ok); }

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: .85rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.score { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; }
.score b { font-variant-numeric: tabular-nums; }

/* tips */
.tips { margin-top: 32px; padding: 18px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); }
.tips h2 { font: 800 1.25rem var(--font-display); margin: 0 0 4px; letter-spacing: -.01em; }
.tips > p { color: var(--muted); margin: 0 0 12px; font-size: .9rem; }
.tip { display: grid; grid-template-columns: 52px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.tip .k { display: grid; place-items: center; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 1.1rem; }
.tip p { margin: 0; font-size: .93rem; }
.tip .eg { color: var(--muted); font-size: .86rem; }
.tip .eg b { color: var(--text); }

/* settings */
.sheet {
  border: 0; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 88vh; border-radius: 22px;
  background: var(--bg); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.sheet::backdrop { background: rgba(20, 12, 6, .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; position: sticky; top: 0; background: var(--bg); }
.sheet-head h2 { margin: 0; font: 800 1.35rem var(--font-display); letter-spacing: -.01em; }
#settingsBody { padding: 4px 18px 22px; display: grid; gap: 14px; }
.set-group { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.set-group h3 { margin: 0 0 4px; font-size: 1rem; }
.set-group p { margin: 0 0 10px; color: var(--muted); font-size: .88rem; }
.lang-toggle { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.lang-toggle:first-of-type { border-top: 0; }
.lang-toggle .soon { color: var(--muted); font-size: .82rem; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }


/* browser surfaces, themed */
::selection { background: var(--accent); color: var(--accent-text); }
input, textarea { caret-color: var(--accent); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .opt:focus-visible, .chip:focus-visible, .lang:focus-visible, .tabs button:focus-visible { outline-offset: 3px; }
html { scrollbar-color: color-mix(in srgb, var(--accent) 45%, var(--line)) transparent; }
.btn:not(:disabled):active, .opt:not(:disabled):active { transform: translateY(1px); }
.btn.primary:not(:disabled):hover { filter: brightness(1.06); }
.opt:not(:disabled):hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }

.logo svg { display: block; }
.session-head .kind { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.session-head .kind::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.session-head .kind.review::before { background: var(--gold); }
.hint-show b { color: var(--accent); }

/* first-run welcome */
.welcome { text-align: left; padding: 26px 20px; }
.welcome h2 { font: 800 1.9rem/1.1 var(--font-display); letter-spacing: -.02em; margin: 0 0 8px; }
.welcome .lead { color: var(--muted); margin: 0 0 20px; }
.steps { list-style: none; margin: 0 0 22px; padding: 0; display: grid; gap: 14px; }
.steps li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; }
.steps .n { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.steps b { display: block; }
.steps span { color: var(--muted); font-size: .92rem; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 6px; }
.pick label { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.pick input { accent-color: var(--accent); width: 18px; height: 18px; }
.pick label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.welcome .note { color: var(--muted); font-size: .85rem; margin: 0 0 18px; }

.first-run .langs, .first-run .progress, .first-run .tabs, .first-run .tips, .first-run .offline-note { display: none; }
.first-run main { padding-top: 6px; }
.welcome ol { counter-reset: none; }

/* the brand mark keeps the app-icon colours in every language and theme */
.logo { background: linear-gradient(135deg, #5b21b6, #2e1065); color: #fff8f0; box-shadow: 0 2px 6px rgba(46, 16, 101, .3); }
