/* ---------- tokens ---------- */
:root {
  --main: #7c5cfc;
  --main-dark: #6347e0;
  --main-soft: #ece5ff;
  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --blue-soft: #ddf4ff;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-soft: #ffdfe0;
  --green: #58cc02;
  --green-dark: #46a302;
  --green-soft: #d7ffb8;
  --gold: #ffc800;

  --bg: #ffffff;
  --panel: #ffffff;
  --raised: #f7f7f7;
  --ink: #3c3c3c;
  --ink-soft: #777777;
  --line: #e5e5e5;
  --line-strong: #d4d4d4;

  --kb-white: #fffdf8;
  --kb-black: #23222b;

  --radius: 16px;
  --tab-h: 60px;
  --top-h: 56px;
  --wrap: 620px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16131f;
    --panel: #1f1b2b;
    --raised: #292338;
    --ink: #f3f1fa;
    --ink-soft: #a89fc2;
    --line: #383050;
    --line-strong: #463c64;
    --main-soft: #2c2350;
    --blue-soft: #10323f;
    --red-soft: #3d1618;
    --green-soft: #1f3d12;
    --kb-white: #efeaf6;
    --kb-black: #0d0c12;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body { padding-top: var(--top-h); padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); }
body.in-session { padding-top: 0; padding-bottom: 0; }
body.in-session .topbar, body.in-session .tabbar { display: none; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h);
  background: var(--panel); border-bottom: 2px solid var(--line); z-index: 20;
}
.topbar-inner {
  max-width: var(--wrap); margin: 0 auto; height: 100%;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px; gap: 12px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 19px; color: var(--ink); text-decoration: none; letter-spacing: -0.02em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px; background: var(--main); color: #fff;
  display: grid; place-items: center; font-size: 16px; font-weight: 900;
}
.stats-chips { display: flex; gap: 8px; }
.chip {
  font-weight: 800; font-size: 14px; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.chip b { color: var(--ink); }
.chip-streak b { color: #ff9600; }
.chip-xp b { color: var(--gold); }
.chip-due b { color: var(--blue); }
.chip-due.none { opacity: 0.45; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; inset: auto 0 0 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--panel); border-top: 2px solid var(--line);
  display: flex; z-index: 20;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--ink-soft); text-decoration: none;
}
.tabbar a span { font-size: 21px; line-height: 1; }
.tabbar a.active { color: var(--main); }

/* ---------- layout ---------- */
.view { max-width: var(--wrap); margin: 0 auto; padding: 18px 16px 32px; }
h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -0.02em; }
h2 { font-size: 19px; margin: 22px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 6px; }
p  { line-height: 1.55; margin: 6px 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 14px; padding: 13px 20px;
  font: inherit; font-weight: 800; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em;
  color: #fff; background: var(--main); box-shadow: 0 4px 0 var(--main-dark);
  cursor: pointer; text-decoration: none; transition: transform .06s, box-shadow .06s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(4px); box-shadow: none; }
.btn.blue { background: var(--blue); box-shadow: 0 4px 0 var(--blue-dark); }
.btn.red  { background: var(--red);  box-shadow: 0 4px 0 var(--red-dark); }
.btn.ghost {
  background: transparent; color: var(--ink-soft);
  border: 2px solid var(--line-strong); box-shadow: 0 4px 0 var(--line);
}
.btn[disabled] { background: var(--line); color: var(--ink-soft); box-shadow: none; cursor: default; transform: none; }
.btn.wide { width: 100%; }
.btn.sm { padding: 9px 14px; font-size: 13px; border-radius: 11px; }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.card.flat { border-color: transparent; background: var(--raised); }

/* ---------- section / unit list ---------- */
.section-card {
  border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel); margin-bottom: 14px;
}
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; cursor: pointer; background: var(--raised);
}
.section-head h3 { font-size: 17px; margin: 0; }
.section-head .sub { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.pill {
  font-size: 12px; font-weight: 800; color: var(--ink-soft);
  background: var(--panel); border: 2px solid var(--line); border-radius: 999px; padding: 3px 10px;
  white-space: nowrap;
}
.bar { height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--main); border-radius: 999px; transition: width .4s; }
.bar.thin { height: 9px; }
.section-body { padding: 6px 12px 12px; display: none; }
.section-card.open .section-body { display: block; }
.section-progress { padding: 0 16px 14px; }

.unit-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 8px;
  border-radius: 12px; text-decoration: none; color: inherit; cursor: pointer;
}
.unit-row:hover { background: var(--raised); }
.unit-row.locked { opacity: 0.45; cursor: not-allowed; }
.unit-icon {
  width: 44px; height: 44px; flex: none; border-radius: 14px; background: var(--raised);
  display: grid; place-items: center; font-size: 22px; border: 2px solid var(--line);
}
.unit-row.done .unit-icon { background: var(--main); border-color: var(--main-dark); color: #fff; }
.unit-main { flex: 1; min-width: 0; }
.unit-main .t { font-weight: 800; font-size: 15px; }
.unit-main .s { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.unit-dots { display: flex; gap: 4px; margin-top: 6px; }
.unit-dots i { width: 22px; height: 6px; border-radius: 999px; background: var(--line); }
.unit-dots i.on { background: var(--main); }

/* ---------- hero / continue ---------- */
.hero {
  border-radius: var(--radius); padding: 18px; color: #fff;
  background: linear-gradient(135deg, var(--main), #5a3ee8);
}
.hero h2 { margin: 0 0 4px; font-size: 20px; color: #fff; }
.hero p { margin: 0 0 14px; opacity: .92; font-size: 14px; }
.hero .btn { background: #fff; color: var(--main-dark); box-shadow: 0 4px 0 rgba(0,0,0,.18); }

/* ---------- session ---------- */
.session { min-height: 100dvh; display: flex; flex-direction: column; }
.session-top {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  max-width: var(--wrap); margin: 0 auto; width: 100%;
}
.session-top .quit {
  border: none; background: none; font-size: 26px; line-height: 1; color: var(--ink-soft);
  cursor: pointer; padding: 0 4px;
}
.score { font-size: 15px; font-weight: 800; color: var(--ink-soft); white-space: nowrap; }
.session-body {
  flex: 1; max-width: var(--wrap); margin: 0 auto; width: 100%; padding: 8px 16px 24px;
}
.q-tag {
  font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-soft); margin-bottom: 6px;
}
.q-sub { font-size: 15px; font-weight: 800; color: var(--ink-soft); margin-bottom: 16px; }
.q-prompt {
  font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.25; margin-bottom: 18px;
}
.q-prompt.small { font-size: 22px; }

.speaker {
  border: 2px solid var(--blue-dark); background: var(--blue); color: #fff;
  width: 62px; height: 62px; border-radius: 16px; font-size: 26px;
  box-shadow: 0 4px 0 var(--blue-dark); cursor: pointer; display: grid; place-items: center;
}
.speaker:active { transform: translateY(4px); box-shadow: none; }
.speaker.sm { width: 38px; height: 38px; font-size: 16px; border-radius: 11px; box-shadow: 0 3px 0 var(--blue-dark); }
.speaker.slow { background: var(--panel); color: var(--blue); border-color: var(--line-strong); box-shadow: 0 4px 0 var(--line); }

.options { display: grid; gap: 10px; }
.opt {
  text-align: left; font: inherit; font-weight: 700; font-size: 16px; color: var(--ink);
  background: var(--panel); border: 2px solid var(--line); border-bottom-width: 4px;
  border-radius: 14px; padding: 15px 16px; cursor: pointer;
}
.opt:hover { background: var(--raised); }
.opt.sel { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }
.opt.right { border-color: var(--green-dark); background: var(--green-soft); }
.opt.wrong { border-color: var(--red-dark); background: var(--red-soft); }
.opt[disabled] { cursor: default; }
.options.two { grid-template-columns: 1fr 1fr; }

.answer-input {
  width: 100%; font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  background: var(--raised); border: 2px solid var(--line); border-radius: 14px;
  padding: 15px 16px; outline: none;
}
.answer-input:focus { border-color: var(--main); }
.answer-input[readonly] { opacity: .8; }

.accent-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.accent-row button {
  font: inherit; font-weight: 800; font-size: 15px; min-width: 40px;
  background: var(--raised); color: var(--ink); border: 2px solid var(--line);
  border-radius: 10px; padding: 7px 0; cursor: pointer;
}

/* ---------- the piano ---------- */
.kbd { margin: 10px 0 4px; }
.kbd-inner {
  position: relative; display: flex; height: 148px;
  border-radius: 10px; overflow: hidden;
  border: 2px solid var(--line-strong); border-bottom-width: 4px;
  background: var(--kb-black);
  touch-action: manipulation;
}
.kb {
  padding: 0; margin: 0; cursor: pointer; border: none; font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.kb-w {
  flex: 1; position: relative; z-index: 1;
  background: var(--kb-white);
  border-left: 1px solid rgba(0,0,0,.22);
  border-radius: 0 0 5px 5px;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
}
.kb-w:first-child { border-left: none; }
.kb-b {
  position: absolute; top: 0; height: 60%; z-index: 2;
  background: var(--kb-black);
  border-radius: 0 0 4px 4px;
  box-shadow: inset 0 -5px 0 rgba(255,255,255,.09);
}
.kb-label {
  font-size: 10px; font-weight: 800; color: rgba(0,0,0,.42);
  pointer-events: none;
}
.kb-w:active { background: #e7e2ee; }
.kb-b:active { background: #3a3846; }
.kb-w.on { background: var(--main-soft); box-shadow: inset 0 -4px 0 var(--main); }
.kb-b.on { background: var(--main); box-shadow: inset 0 -4px 0 var(--main-dark); }
.kb-w.root { background: var(--main); }
.kb-w.root .kb-label { color: rgba(255,255,255,.85); }
.kb-b.root { background: var(--main-dark); }
.kb-w.right { background: var(--green-soft); box-shadow: inset 0 -4px 0 var(--green); }
.kb-b.right { background: var(--green-dark); box-shadow: inset 0 -4px 0 var(--green); }
.kb-w.wrong { background: var(--red-soft); box-shadow: inset 0 -4px 0 var(--red); }
.kb-b.wrong { background: var(--red-dark); box-shadow: inset 0 -4px 0 var(--red); }
.kb-w.miss { box-shadow: inset 0 0 0 3px var(--green); }
.kb-b.miss { box-shadow: inset 0 0 0 3px var(--green); }
.kbd.locked .kb { cursor: default; }
@media (max-width: 480px) { .kbd-inner { height: 118px; } .kb-label { display: none; } }

/* ---------- feedback ---------- */
.feedback {
  position: sticky; bottom: 0; margin-top: auto;
  border-top: 2px solid var(--line); background: var(--panel);
}
.feedback.ok   { background: var(--green-soft); border-color: transparent; }
.feedback.bad  { background: var(--red-soft);   border-color: transparent; }
.feedback-inner {
  max-width: var(--wrap); margin: 0 auto; padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.feedback-text { flex: 1; min-width: 200px; font-weight: 800; }
.feedback.ok  .feedback-text { color: var(--green-dark); }
.feedback.bad .feedback-text { color: var(--red-dark); }
.feedback-text .sol { display: block; font-weight: 800; font-size: 15px; margin-top: 3px; }
.feedback-text .note { display: block; font-weight: 700; font-size: 13px; opacity: .85; margin-top: 3px; }

/* ---------- tables ---------- */
.gtable { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.gtable th, .gtable td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; }
.gtable th { background: var(--raised); font-weight: 800; }
.table-wrap { overflow-x: auto; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 800; color: var(--ink-soft); margin-bottom: 5px; }
select, input[type="text"], input[type="search"], textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--raised); border: 2px solid var(--line); border-radius: 12px; padding: 11px 12px;
}
textarea { min-height: 120px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.checkline { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-weight: 700; }
.checkline input { width: 20px; height: 20px; accent-color: var(--main); }
.chipset { display: flex; flex-wrap: wrap; gap: 8px; }
.chipset button {
  font: inherit; font-weight: 800; font-size: 13px; color: var(--ink-soft);
  background: var(--panel); border: 2px solid var(--line); border-radius: 999px;
  padding: 7px 13px; cursor: pointer;
}
.chipset button.on { background: var(--main-soft); border-color: var(--main); color: var(--main-dark); }
@media (prefers-color-scheme: dark) { .chipset button.on { color: #cabffb; } }

/* ---------- lists ---------- */
.wordlist { border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.wordrow {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-top: 1px solid var(--line);
}
.wordrow:first-child { border-top: none; }
.wordrow.col { flex-direction: column; align-items: flex-start; gap: 6px; }
.wordrow .es { font-weight: 800; }
.wordrow .en { color: var(--ink-soft); font-size: 14px; }
.wordrow .grow { flex: 1; min-width: 0; }
.badge {
  font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 7px; border-radius: 6px; background: var(--raised); color: var(--ink-soft);
}
.badge.learned { background: var(--green-soft); color: var(--green-dark); }

/* ---------- stats ---------- */
.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--raised); border-radius: var(--radius); padding: 14px; }
.stat .n { font-size: 26px; font-weight: 900; letter-spacing: -0.02em; }
.stat .l { font-size: 12px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 92px; margin-top: 10px; }
.spark div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.spark i { display: block; width: 100%; background: var(--main); border-radius: 5px 5px 0 0; min-height: 3px; }
.spark span { font-size: 10px; font-weight: 800; color: var(--ink-soft); }

/* ---------- misc ---------- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-soft); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 18px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-weight: 800; font-size: 14px; z-index: 50; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.finish { text-align: center; padding: 40px 0; }
.finish .big { font-size: 62px; }
.finish h1 { margin-top: 8px; }
