:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2fb;
  --text: #172033;
  --muted: #5b6478;
  --line: #dde3ee;
  --brand: #1f3a8a;
  --brand-2: #2f55c9;
  --brand-soft: #e6ecfb;
  --good: #137a3d;
  --good-soft: #e3f5ea;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --warn: #9a6200;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d;
    --surface: #171e2b;
    --surface-2: #1e2738;
    --text: #e8ecf4;
    --muted: #9aa5ba;
    --line: #2a3447;
    --brand: #8fa8ff;
    --brand-2: #a9bcff;
    --brand-soft: #232f4d;
    --good: #5fd08f;
    --good-soft: #15301f;
    --bad: #ff8a80;
    --bad-soft: #3a1c1c;
    --warn: #f0b44c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
}
.wrap { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
b, strong { font-weight: 650; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; cursor: pointer; color: inherit; text-align: left; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .logo { color: #0f141d; } }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); font-size: .78rem; }
.quiz-meta { display: flex; align-items: center; gap: 10px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 650; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); }
.timer.low { color: var(--bad); background: var(--bad-soft); }

/* Buttons */
.btn { font: inherit; font-weight: 600; border-radius: 10px; padding: 11px 18px; border: 1px solid transparent; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f141d; } }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--brand); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Home */
.screen { padding: 20px 0 32px; }
.hero { margin: 8px 0 18px; }
.hero p { color: var(--muted); }
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.mode { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; box-shadow: var(--shadow); color: inherit; font: inherit; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, transform .1s; }
.mode:hover { border-color: var(--brand); transform: translateY(-1px); }
.mode .m-title { font-weight: 700; font-size: 1.05rem; }
.mode .m-desc { color: var(--muted); font-size: .9rem; }
.mode .m-meta { margin-top: 6px; font-size: .82rem; color: var(--brand); font-weight: 600; }
.mode.featured { background: var(--brand-soft); border-color: var(--brand); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.switch { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.switch input { flex: 0 0 18px; width: 18px; height: 18px; accent-color: var(--brand); }
.switch.compact { padding: 0; font-size: .9rem; }
.row-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
select { font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.section-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .s-name { font-size: .82rem; color: var(--muted); }
.stat .s-val { font-size: 1.25rem; font-weight: 700; }
.stat .s-sub { font-size: .75rem; color: var(--muted); }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.history-list li:first-child { border-top: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: .92rem; }
.bank-info { color: var(--muted); font-size: .85rem; text-align: center; }
.link-btn { background: none; border: 0; color: var(--brand); font: inherit; font-size: .85rem; cursor: pointer; padding: 0; text-decoration: underline; }

/* Quiz */
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress-bar { height: 100%; width: 0; background: var(--brand); transition: width .25s; }
.q-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; font-weight: 600; }
.chip { font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.chip.muted { background: var(--surface-2); color: var(--muted); }
.passage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; max-height: 46vh; overflow: auto; box-shadow: var(--shadow); }
.passage h3 { font-size: 1rem; }
.passage p { font-size: .96rem; }
.passage .pn { color: var(--muted); font-weight: 600; margin-right: 4px; }
.q-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.q-prompt { font-size: 1.08rem; margin-bottom: 14px; }
.q-instr { color: var(--muted); font-size: .88rem; margin-bottom: 8px; }
.options { display: grid; gap: 8px; }
.opt { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 14px; cursor: pointer; transition: border-color .12s, background .12s; }
.opt:hover:not(:disabled) { border-color: var(--brand); }
.opt .letter { flex: 0 0 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: .85rem; }
.opt.selected { border-color: var(--brand); background: var(--brand-soft); }
.opt.selected .letter { background: var(--brand); color: #fff; }
.opt.correct { border: 2px solid var(--good); background: var(--good-soft); }
.opt.correct .letter { background: var(--good); color: #fff; }
.opt.wrong { border: 2px solid var(--bad); background: var(--bad-soft); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt.locked { cursor: default; }
.opt.locked:not(.correct):not(.wrong):hover { border-color: var(--line); }
.opt.locked.correct:hover { border-color: var(--good); }
.opt.locked.wrong:hover { border-color: var(--bad); }
.we-sentence { font-size: 1.1rem; line-height: 2.1; margin-bottom: 14px; }
.we-part { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; font-weight: 600; }
.we-part sub { font-size: .7rem; color: var(--brand); font-weight: 700; margin-left: 1px; }
.audio-box { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.audio-box .hint { font-size: .85rem; color: var(--muted); }
.transcript { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin: 10px 0 0; font-size: .95rem; }
.transcript .spk { font-weight: 700; color: var(--brand); margin-right: 6px; }
.feedback { margin-top: 12px; border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); }
.feedback.ok { border-color: var(--good); background: var(--good-soft); }
.feedback.no { border-color: var(--bad); background: var(--bad-soft); }
.feedback .fb-title { font-weight: 700; margin-bottom: 4px; }
.q-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.q-actions .btn { flex: 1; }
.q-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin-top: 16px; }
.q-grid button { font: inherit; font-size: .85rem; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.q-grid button.answered { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }
.q-grid button.current { outline: 2px solid var(--brand); outline-offset: 1px; }
.submit-row { margin-top: 14px; text-align: center; }

/* Result */
.score-card { text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.score-big { font-size: 3rem; font-weight: 800; line-height: 1; margin: 8px 0; }
.score-sub { color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 150px 1fr 60px; align-items: center; gap: 10px; padding: 6px 0; font-size: .92rem; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar-row .pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.result-actions { display: flex; gap: 10px; margin-bottom: 14px; }
.result-actions .btn { flex: 1; }
.review-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.review-item { border-top: 1px solid var(--line); padding: 12px 0; }
.review-item:first-child { border-top: 0; }
.review-item .ri-q { font-weight: 600; margin-bottom: 4px; }
.review-item .ri-a { font-size: .92rem; }
.review-item .ri-a .ok { color: var(--good); font-weight: 600; }
.review-item .ri-a .no { color: var(--bad); font-weight: 600; }
.review-item .ri-x { font-size: .92rem; color: var(--muted); margin-top: 4px; }
.topic-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10, 15, 25, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 20px; max-width: 380px; width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.footer { color: var(--muted); font-size: .8rem; text-align: center; padding-bottom: 28px; }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .bar-row { grid-template-columns: 110px 1fr 48px; }
  .q-card { padding: 14px; }
  .score-big { font-size: 2.4rem; }
}
