:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #1d2321;
  --muted: #66706c;
  --border: #dedbd2;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --good: #2e7d4f;
  --good-soft: #dff1e5;
  --bad: #b3412f;
  --bad-soft: #f8e1dc;
  --warn: #9a6a00;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121514;
    --surface: #1b201e;
    --surface-2: #252b29;
    --text: #e9ece9;
    --muted: #9aa49f;
    --border: #323a37;
    --accent: #5fb39a;
    --accent-ink: #0d1412;
    --accent-soft: #1f3a32;
    --good: #6cc890;
    --good-soft: #1d3426;
    --bad: #ef8b78;
    --bad-soft: #3d2420;
    --warn: #e0b04a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121514; --surface: #1b201e; --surface-2: #252b29; --text: #e9ece9; --muted: #9aa49f;
  --border: #323a37; --accent: #5fb39a; --accent-ink: #0d1412; --accent-soft: #1f3a32;
  --good: #6cc890; --good-soft: #1d3426; --bad: #ef8b78; --bad-soft: #3d2420; --warn: #e0b04a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; }
.spacer { flex: 1; }
.icon-btn {
  background: none; border: 0; font-size: 28px; line-height: 1; padding: 0 8px 2px 0;
  color: var(--accent); cursor: pointer;
}

main { max-width: 680px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  font-size: 11px; color: var(--muted); gap: 2px; padding: 4px 0; cursor: pointer;
}
.tabbar button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }
body.in-session .tabbar { display: none; }
body.in-session { padding-bottom: env(safe-area-inset-bottom); }

/* generic */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: none; }
.btn:disabled { opacity: .5; }
.btn.danger { color: var(--bad); }

.hero { text-align: center; padding: 22px 16px; }
.hero .big { font-size: 40px; font-weight: 700; line-height: 1.1; }
.hero .btn { margin-top: 14px; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode {
  text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; box-shadow: var(--shadow); min-height: 92px;
}
.mode .e { font-size: 22px; }
.mode b { display: block; margin-top: 4px; font-size: 15px; }
.mode .tiny { color: var(--muted); }
.mode:disabled { opacity: .45; }

/* session */
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s; }
.qtype { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.prompt { font-size: 22px; font-weight: 600; margin: 4px 0 6px; }
.prompt.sentence { font-size: 20px; font-weight: 500; line-height: 1.5; }
.gap { display: inline-block; min-width: 64px; border-bottom: 2px solid var(--accent); text-align: center; color: var(--accent); font-weight: 650; padding: 0 4px; }
.sub { color: var(--muted); font-size: 15px; margin-bottom: 4px; }
.ipa { color: var(--muted); font-size: 15px; }
.speak { background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 17px; flex: none; }

.options { display: grid; gap: 10px; margin-top: 14px; }
.opt {
  min-height: 52px; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 17px;
}
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }

.input {
  width: 100%; font-size: 19px; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); margin-top: 14px;
}
.input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.match .col { display: grid; gap: 8px; align-content: start; }
.tile {
  min-height: 52px; padding: 8px 10px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 15px; text-align: center;
}
.tile.sel { border-color: var(--accent); background: var(--accent-soft); }
.tile.done { opacity: .35; border-color: var(--good); cursor: default; }
.tile.miss { border-color: var(--bad); background: var(--bad-soft); }

.answer-line { min-height: 56px; border-bottom: 2px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0; margin-top: 12px; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 17px;
}
.chip.used { visibility: hidden; }

.feedback { margin-top: 16px; border-radius: var(--radius); padding: 14px; border: 1px solid; }
.feedback.ok { background: var(--good-soft); border-color: var(--good); }
.feedback.ko { background: var(--bad-soft); border-color: var(--bad); }
.feedback .verdict { font-weight: 700; margin-bottom: 4px; }
.feedback .ans { font-weight: 600; }
.feedback p { margin: 6px 0 0; }

.flash { text-align: center; padding: 26px 12px; }
.flash .front { font-size: 26px; font-weight: 650; }
.flash .back { margin-top: 14px; font-size: 19px; }

.session-footer { position: sticky; bottom: 0; padding: 12px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.session-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.session-top .progress { flex: 1; margin: 0; }
.x { background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; padding: 4px 8px; }

/* words */
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 17px; }
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0; padding-bottom: 2px; }
.filters button { flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; cursor: pointer; }
.filters button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.li { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.li:last-child { border-bottom: 0; }
.li .t { font-weight: 600; }
.li .c { color: var(--muted); font-size: 14px; }
.dots { display: flex; gap: 3px; flex: none; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 4px; vertical-align: 2px; }
.tag.ex { background: var(--accent-soft); color: var(--accent); }

.example { padding: 10px 0; border-top: 1px solid var(--border); }
.example:first-of-type { border-top: 0; }
.example .cz { color: var(--muted); font-size: 15px; }

/* stats */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.kpi b { display: block; font-size: 26px; }
.kpi span { font-size: 12px; color: var(--muted); }
.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); margin: 8px 0 6px; }
.bar > div { height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart svg { width: 100%; height: auto; display: block; }
.acc-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 14px; }
.acc-row .name { width: 42%; }
.acc-row .track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.acc-row .track div { height: 100%; background: var(--accent); }
.acc-row .val { width: 44px; text-align: right; color: var(--muted); }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; font-size: 15px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); cursor: pointer;
}
.center { text-align: center; }
@media (min-width: 700px) {
  .modes { grid-template-columns: repeat(3, 1fr); }
  .options.two { grid-template-columns: 1fr 1fr; }
}
