:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #17192b;
  --muted: #646778;
  --line: #e2ded4;
  --accent: #3a3fa0;
  --accent-ink: #ffffff;
  --gold: #e08a12;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --bad: #c2372f;
  --bad-bg: #fbe7e5;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20,20,40,.06), 0 6px 20px rgba(20,20,40,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1222; --surface: #181c33; --surface-2: #222745; --text: #f1f0ec; --muted: #a2a5bd;
    --line: #2c3152; --accent: #8f95ff; --accent-ink: #0f1222; --gold: #ffb347;
    --ok: #4cd18a; --ok-bg: #143326; --bad: #ff7b72; --bad-bg: #3a1a1d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1222; --surface: #181c33; --surface-2: #222745; --text: #f1f0ec; --muted: #a2a5bd;
  --line: #2c3152; --accent: #8f95ff; --accent-ink: #0f1222; --gold: #ffb347;
  --ok: #4cd18a; --ok-bg: #143326; --bad: #ff7b72; --bad-bg: #3a1a1d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  min-height: 100dvh; overflow-x: hidden;
}
main {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 120px);
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.mt { margin-top: 20px; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 52px; padding: 12px 18px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 17px;
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .4; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 20px; flex: none;
}

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }

/* Header / stats */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.brand { font-weight: 800; font-size: 22px; }
.brand span { color: var(--gold); }
.chips { display: flex; gap: 8px; }
.chip { background: var(--surface); box-shadow: var(--shadow); border-radius: 999px; padding: 6px 12px; font-weight: 650; font-size: 15px; white-space: nowrap; }

.goal { display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: center; }
.ring { width: 76px; height: 76px; }
.ring circle { fill: none; stroke-width: 9; }
.ring .bgc { stroke: var(--surface-2); }
.ring .fgc { stroke: var(--gold); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }

.week { display: flex; justify-content: space-between; margin-top: 14px; }
.day { display: grid; justify-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.dot { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; }
.dot.on { background: var(--gold); color: #1b1300; }
.dot.today { outline: 2px solid var(--accent); outline-offset: 2px; }

.units { display: grid; gap: 10px; }
.unit { display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center; text-align: left; width: 100%; }
.unit .emo { width: 48px; height: 48px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-size: 24px; }
.unit h3 { font-size: 17px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s ease; }
.pct { font-weight: 700; font-size: 14px; color: var(--muted); }

.banner { background: var(--surface-2); border-radius: 14px; padding: 14px; font-size: 14px; }

/* Session */
.sessiontop { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; margin-bottom: 22px; }
.sessiontop .bar { margin: 0; height: 10px; }
.kind { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.prompt { font-size: 22px; font-weight: 650; line-height: 1.35; }
.en { font-size: 20px; }
.options { display: grid; gap: 10px; margin-top: 18px; }
.opt {
  text-align: left; padding: 14px 16px; border-radius: 14px; background: var(--surface);
  box-shadow: var(--shadow); border: 2px solid transparent; font-size: 17px; min-height: 52px;
}
.opt.sel { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }

input.answer, textarea {
  width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--text); outline: none;
}
input.answer:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; font-size: 14px; font-family: ui-monospace, Menlo, monospace; }

.flash { text-align: center; padding: 28px 18px; }
.flash .front { font-size: 26px; font-weight: 700; }
.flash .back { margin-top: 18px; font-size: 18px; }
.flash .ex { margin-top: 12px; font-style: italic; color: var(--muted); }

.tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 56px; }
.built { padding: 12px; border-radius: 14px; border: 2px dashed var(--line); margin-top: 16px; }
.pool { margin-top: 16px; }
.tile { padding: 10px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); font-size: 17px; font-weight: 550; }
.tile.used { visibility: hidden; }

.speak { display: flex; gap: 12px; justify-content: center; margin: 10px 0 18px; }
.speak .iconbtn { width: 72px; height: 72px; border-radius: 20px; font-size: 30px; background: var(--accent); color: var(--accent-ink); }
.speak .iconbtn.slow { background: var(--surface-2); color: var(--text); font-size: 24px; }

.footer {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.footer > div { max-width: 528px; margin: 0 auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
  border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  animation: up .22s ease;
}
.sheet.ok { background: var(--ok-bg); }
.sheet.bad { background: var(--bad-bg); }
.sheet > div { max-width: 528px; margin: 0 auto; }
.sheet h3 { font-size: 20px; margin-bottom: 6px; }
.sheet.ok h3 { color: var(--ok); }
.sheet.bad h3 { color: var(--bad); }
.sheet p { margin-bottom: 8px; }
.sheet .btn { margin-top: 10px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.big { font-size: 56px; text-align: center; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { text-align: center; padding: 16px 10px; }
.stat b { display: block; font-size: 26px; }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 16px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 20;
  max-width: calc(100% - 32px);
}
