/* VTNE Prep — mobile-first. Tokens on :root, dark overrides via prefers-color-scheme (and data-theme). */
:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef2f5; --text: #14212b; --muted: #5a6b79; --border: #dde4ea;
  --primary: #0d7f82; --primary-2: #0a6567; --on-primary: #ffffff; --accent: #e07a2f;
  --good: #1b8a4b; --good-bg: #e6f5ec; --bad: #c43b3b; --bad-bg: #fbeaea; --warn: #a96a12; --warn-bg: #fdf3e2;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  --radius: 14px; --tap: 52px; --tabbar: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1418; --surface: #152026; --surface-2: #1c2a32; --text: #e5edf2; --muted: #93a5b3; --border: #26363f;
    --primary: #2fb4b6; --primary-2: #4cc7c9; --on-primary: #04282a; --accent: #f29a52;
    --good: #43c97d; --good-bg: #12301f; --bad: #ff7676; --bad-bg: #3a1a1c; --warn: #f0b84a; --warn-bg: #3a2c12;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1418; --surface: #152026; --surface-2: #1c2a32; --text: #e5edf2; --muted: #93a5b3; --border: #26363f;
  --primary: #2fb4b6; --primary-2: #4cc7c9; --on-primary: #04282a; --accent: #f29a52;
  --good: #43c97d; --good-bg: #12301f; --bad: #ff7676; --bad-bg: #3a1a1c; --warn: #f0b84a; --warn-bg: #3a2c12;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .tiny { font-size: .78rem; }
.center { text-align: center; } .row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .75rem; } .hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* shell */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); padding: calc(env(safe-area-inset-top) + .6rem) 16px .6rem; }
.topbar-inner { max-width: 680px; margin: 0 auto; display: flex; align-items: center; gap: .75rem; min-height: 32px; }
.topbar .title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { border: 0; background: none; padding: .25rem .4rem; margin-left: -.4rem; font-size: 1.4rem; line-height: 1; color: var(--primary); cursor: pointer; }
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem; border-radius: 999px; background: var(--surface-2); font-size: .82rem; font-weight: 600; white-space: nowrap; }
main { max-width: 680px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; }
.tabbar-inner { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 680px; }
.tab { height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; font-weight: 600;
  color: var(--muted); text-decoration: none; border: 0; background: none; cursor: pointer; }
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--primary); }
body.focus-mode .tabbar { display: none; } body.focus-mode main { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); }

/* cards & buttons */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.tight { padding: 12px 14px; }
.section-title { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-block { width: 100%; min-height: var(--tap); font-size: 1.02rem; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .88rem; border-radius: 10px; }
.list-btn { display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left; padding: 14px; min-height: var(--tap); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.list-btn + .list-btn { margin-top: 8px; }
.list-btn .chev { color: var(--muted); font-size: 1.2rem; }
.icon-circle { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 1.25rem; flex: none; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: .45rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: .88rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* forms */
label.field { display: block; font-weight: 600; font-size: .92rem; }
label.field input, label.field select, label.field textarea { display: block; width: 100%; margin-top: .35rem; padding: .7rem .8rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; }
textarea { resize: vertical; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 6px; }
.seg button { min-height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* question */
.q-meta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-bottom: .5rem; }
.q-stem { font-size: 1.08rem; font-weight: 600; line-height: 1.45; margin-bottom: 14px; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: .7rem; align-items: flex-start; width: 100%; min-height: 56px; padding: 12px 14px; text-align: left; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer; line-height: 1.4; }
.opt .letter { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; background: var(--surface-2); }
.opt.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 9%, var(--surface)); }
.opt.sel .letter { background: var(--primary); color: var(--on-primary); }
.opt.correct { border-color: var(--good); background: var(--good-bg); } .opt.correct .letter { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); } .opt.wrong .letter { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; color: var(--text); opacity: 1; }
.feedback { margin-top: 14px; border-radius: 12px; padding: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.feedback.good { border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.feedback.bad { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.verdict { font-weight: 800; margin-bottom: .4rem; } .verdict.good { color: var(--good); } .verdict.bad { color: var(--bad); }
.notes { margin: .5rem 0 0; padding-left: 0; list-style: none; font-size: .92rem; }
.notes li { margin: .35rem 0; padding-left: 1.6rem; position: relative; }
.notes li b { position: absolute; left: 0; }
.cite { font-size: .8rem; color: var(--muted); margin-top: .6rem; border-top: 1px dashed var(--border); padding-top: .5rem; }
.ai-box { margin-top: 12px; border-radius: 12px; padding: 12px; border: 1px dashed var(--primary); background: color-mix(in srgb, var(--primary) 6%, var(--surface)); font-size: .95rem; white-space: pre-wrap; }
.ai-label { font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--primary); margin-bottom: .3rem; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px); background: var(--surface); border-top: 1px solid var(--border); }
.actionbar-inner { max-width: 680px; margin: 0 auto; display: flex; gap: 8px; }
/* Book figures */
.figs { display: grid; gap: 10px; margin-top: 12px; }
.figbox { margin: 0; border-radius: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); }
.figbox img { display: block; width: 100%; max-height: 42vh; object-fit: contain; background: #fff; cursor: zoom-in; }
.figbox.zoom img { max-height: none; cursor: zoom-out; }
.figbox.big img { max-height: 48vh; }
.figbox .figph { padding: 28px 12px; text-align: center; }
.figbox figcaption { padding: 8px 10px; }
.wrap-chips { flex-wrap: wrap; overflow: visible; }
/* "Why is it wrong?" */
.why { display: grid; gap: 6px; margin-top: 12px; }
.why-row { display: flex; gap: .6rem; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .92rem; border: 1px solid transparent; }
.why-row b { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; background: var(--surface); }
.why-row.now { border-color: var(--primary); } .why-row.good { background: var(--good-bg); } .why-row.bad { background: var(--bad-bg); }
.why-ask { margin-top: 14px; }
.why-input { width: 100%; padding: .6rem .7rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; resize: vertical; }
.progressbar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progressbar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.steps { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; background: var(--surface); border-radius: 10px; padding: 10px; border: 1px solid var(--border); overflow-x: auto; }

/* dashboard */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.big-num { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.dom-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.dom-row:last-child { border-bottom: 0; }
.dom-name { font-weight: 600; font-size: .95rem; }
.dom-pct { font-weight: 800; font-size: .95rem; }
.dom-track { grid-column: 1 / -1; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; position: relative; }
.dom-track > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; }
.lvl-low { background: var(--bad); } .lvl-mid { background: var(--warn); } .lvl-ok { background: var(--good); } .lvl-none { background: var(--border); }
.plan-item { display: flex; gap: 12px; align-items: center; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge-tile { text-align: center; padding: 12px 6px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.badge-tile .ico { font-size: 1.8rem; } .badge-tile .nm { font-weight: 700; font-size: .78rem; line-height: 1.2; margin-top: 4px; }
.badge-tile.locked { opacity: .45; filter: grayscale(1); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; }

/* exam */
.timer { font-variant-numeric: tabular-nums; font-weight: 800; }
.timer.low { color: var(--bad); }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.qgrid button { height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; font-size: .85rem; cursor: pointer; position: relative; }
.qgrid button.ans { background: color-mix(in srgb, var(--primary) 16%, var(--surface)); border-color: var(--primary); }
.qgrid button.cur { outline: 3px solid var(--accent); }
.qgrid button.mark::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.score-ring { width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto; }
.score-ring .inner { width: 104px; height: 104px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.tag { display: inline-block; font-size: .72rem; font-weight: 800; padding: .1rem .45rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.good { background: var(--good-bg); color: var(--good); } .tag.bad { background: var(--bad-bg); color: var(--bad); } .tag.warn { background: var(--warn-bg); color: var(--warn); }
details.rev { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 0; }
details.rev + details.rev { margin-top: 8px; }
details.rev summary { cursor: pointer; padding: 12px 14px; list-style: none; font-weight: 600; }
details.rev summary::-webkit-details-marker { display: none; }
details.rev .body { padding: 0 14px 14px; }

/* flashcards */
.flash { min-height: 260px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 22px; }
.flash .front { font-size: 1.15rem; font-weight: 700; }
.flash .back { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); text-align: left; }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade-row .btn { flex-direction: column; gap: 0; min-height: 56px; font-size: .92rem; }
.grade-row .btn small { font-weight: 500; font-size: .72rem; opacity: .8; }

/* sheet & toast */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(5, 12, 16, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 680px; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); }
.sheet .grabber { width: 40px; height: 5px; border-radius: 99px; background: var(--border); margin: -6px auto 12px; }
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 12px); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; max-width: 520px; background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .92rem; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: tin .2s ease-out; }
.toast.badge { background: linear-gradient(135deg, var(--accent), #d9502f); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; }
.logo { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 12px; background: var(--primary); color: var(--on-primary); font-size: 2rem; }
.banner { border-radius: 12px; padding: 10px 12px; font-size: .9rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.bad { background: var(--bad-bg); color: var(--bad); } .banner.info { background: var(--surface-2); }
.install { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 10px); z-index: 50; padding: 0 12px; }
.install .card { max-width: 520px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.scroll-x { overflow-x: auto; }
@media (min-width: 720px) { h1 { font-size: 1.7rem; } .q-stem { font-size: 1.15rem; } }
body.focus-mode .install { display: none; }                 /* never cover answers/action bar while studying */
body.has-install main { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 110px); }
