:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1d2330;
  --text-2: #4a5263;
  --muted: #6b7385;
  --border: #d9dde4;
  --primary: #1f4e79;
  --primary-hover: #183e61;
  --primary-text: #ffffff;
  --accent: #f2c14e;
  --ok: #1f7a4a;
  --ok-bg: #e5f4ec;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --focus: #2b7de9;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --scale: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1b1f27; --surface-2: #232834; --text: #e8eaef; --text-2: #c2c7d2;
    --muted: #9aa1b0; --border: #333a48; --primary: #6aa7e0; --primary-hover: #8bbbe8; --primary-text: #0d1724;
    --ok: #5cc98d; --ok-bg: #173325; --bad: #f2867d; --bad-bg: #3a1c1a; --warn: #f2c14e; --warn-bg: #352a10;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1b1f27; --surface-2: #232834; --text: #e8eaef; --text-2: #c2c7d2;
  --muted: #9aa1b0; --border: #333a48; --primary: #6aa7e0; --primary-hover: #8bbbe8; --primary-text: #0d1724;
  --ok: #5cc98d; --ok-bg: #173325; --bad: #f2867d; --bad-bg: #3a1c1a; --warn: #f2c14e; --warn-bg: #352a10;
  color-scheme: dark;
}
/* High contrast mode (toggle) */
:root[data-contrast="high"] {
  --bg: #000; --surface: #000; --surface-2: #000; --text: #fff; --text-2: #fff; --muted: #fff;
  --border: #fff; --primary: #ffff00; --primary-hover: #ffff66; --primary-text: #000; --accent: #ffff00;
  --ok: #00ff7f; --ok-bg: #000; --bad: #ff6b6b; --bad-bg: #000; --warn: #ffff00; --warn-bg: #000; --focus: #00ffff;
  --shadow: none; color-scheme: dark;
}
:root[data-fontscale="large"] { --scale: 1.5; }

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--scale)); }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer; padding: 4px; border-radius: 6px; color: var(--primary); }
.brand-text { font-weight: 650; font-size: 1.05rem; color: var(--text); }
@media (max-width: 480px) { .brand-text { font-size: .95rem; text-align: left; } .badge { white-space: nowrap; } }
.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; outline: none; }
.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .8rem; }
.site-footer p { max-width: 1180px; margin: 0 auto; padding: 14px 16px; }

/* ---------- Generic ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
ul { margin: 0 0 12px; padding-left: 22px; }
li { margin: 4px 0; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 18px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: .875rem; }
.icon-btn { min-width: 40px; padding: 8px; }

.notice { border-radius: 6px; padding: 12px 14px; border: 1px solid; }
.notice-info { background: var(--surface-2); border-color: var(--border); }
.notice-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--text); }
.notice-ok { background: var(--ok-bg); border-color: var(--ok); }
.notice-bad { background: var(--bad-bg); border-color: var(--bad); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 600px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface-2); border-radius: 6px; padding: 12px; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .8rem; color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--primary); }
.part-progress { display: grid; grid-template-columns: 1fr; gap: 10px; }
.part-progress .lbl { display: flex; justify-content: space-between; font-size: .875rem; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.num { font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.table-wrap { overflow-x: auto; }

/* ---------- Test layout (side nav + question panel) ---------- */
.test-shell { display: grid; grid-template-columns: 210px 1fr; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.qnav { border-right: 1px solid var(--border); background: var(--surface-2); padding: 8px; max-height: 70vh; overflow-y: auto; }
.qnav-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; }
.qnav-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; cursor: pointer; text-align: left; position: relative; font-size: .95rem;
}
.qnav-item:hover { background: var(--surface); }
.qnav-item[aria-current="true"] { background: var(--surface); font-weight: 700; }
.qnav-item[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--primary); }
.qnav-icon { width: 18px; height: 18px; flex: none; display: inline-flex; color: var(--muted); }
.qnav-item.answered .qnav-icon { color: var(--ok); }
.qnav-item.marked .qnav-icon { color: var(--warn); }

.qpanel { padding: 16px 24px 20px; display: flex; flex-direction: column; min-height: 480px; }
.toolbar { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.toolbar .btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.question-area { flex: 1; padding: 20px 0; font-size: 1.35rem; }
.question-category { font-size: .8em; color: var(--muted); margin-bottom: 6px; }
.question-text { display: block; font-weight: 650; margin-bottom: 18px; line-height: 1.35; }
.options { display: flex; flex-direction: column; gap: 10px; border: 0; padding: 0; margin: 0; }
.option {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 1.05rem; background: var(--surface);
}
.option:hover { border-color: var(--primary); }
.option input { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--primary); flex: none; cursor: pointer; }
.option.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.locked { cursor: default; }
.key-hint { margin-left: auto; font-size: .75rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; align-self: center; }

.qactions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.qactions .spacer { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--warn); }
.statusbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 12px; font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); font-weight: 700; }

@media (max-width: 760px) {
  .test-shell { grid-template-columns: 1fr; }
  .qnav { border-right: 0; border-bottom: 1px solid var(--border); max-height: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .qnav-title { grid-column: 1 / -1; }
  .qnav-item { justify-content: center; padding: 8px 4px; font-size: .85rem; flex-direction: column; gap: 2px; }
  .qnav-item .qnav-label-long { display: none; }
  .qnav-item[aria-current="true"]::before { left: 8px; right: 8px; top: auto; bottom: 0; width: auto; height: 3px; }
  .qpanel { padding: 12px 16px 16px; min-height: 0; }
  .question-area { font-size: 1.15rem; }
}
@media (min-width: 761px) { .qnav-item .qnav-label-short { display: none; } }

/* ---------- Results ---------- */
.result-hero { text-align: center; padding: 28px 24px; }
.result-hero .big { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.result-hero.pass { border-top: 6px solid var(--ok); }
.result-hero.fail { border-top: 6px solid var(--bad); }
.verdict { font-size: 1.4rem; font-weight: 750; margin: 6px 0 12px; }
.verdict.pass { color: var(--ok); }
.verdict.fail { color: var(--bad); }
.criteria { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; margin-top: 16px; }
@media (max-width: 600px) { .criteria { grid-template-columns: 1fr; } }
.criterion { border: 1px solid var(--border); border-radius: 6px; padding: 12px; display: flex; gap: 10px; align-items: flex-start; }
.criterion .mark { font-weight: 800; font-size: 1.1rem; }
.criterion.ok .mark { color: var(--ok); }
.criterion.bad .mark { color: var(--bad); }

.review-item { border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; background: var(--surface); }
.review-item.is-correct { border-left: 5px solid var(--ok); }
.review-item.is-wrong { border-left: 5px solid var(--bad); }
.review-q { font-weight: 650; margin-bottom: 8px; }
.review-ans { font-size: .95rem; margin: 2px 0; }
.review-exp { font-size: .9rem; color: var(--text-2); background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin-top: 8px; }
.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-tabs .btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* ---------- Practice ---------- */
.feedback { margin-top: 16px; font-size: 1rem; }
.practice-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.choice { text-align: left; padding: 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--primary); }
.choice strong { display: block; margin-bottom: 2px; }
.choice small { color: var(--muted); }

/* ---------- Study, readiness, language ---------- */
.small { font-size: .82rem; }
.site-footer p + p { padding-top: 0; }
.page-link { font-size: .82rem; white-space: nowrap; }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin: 12px 0; }
.meter > span { display: block; height: 100%; }
.meter .lvl-ok { background: var(--ok); } .meter .lvl-warn { background: var(--warn); } .meter .lvl-bad { background: var(--bad); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 8px; color: var(--muted); font-size: .92rem; }
.checklist li.ok { color: var(--text); }
.checklist li.ok span { color: var(--ok); font-weight: 700; }
.select, .input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; min-height: 40px; width: 100%; }
.input { max-width: 320px; }
.translation { margin-top: 10px; padding: 10px 12px; border-radius: 6px; background: var(--surface-2); border: 1px dashed var(--border); font-size: .95rem; }
.translation p { margin: 0 0 6px; }
.translate-btn { min-height: 30px; padding: 2px 10px; font-weight: 600; }
.choice:disabled { opacity: .5; cursor: not-allowed; }
.study-card ul { margin-bottom: 8px; }
.study-card li { margin: 6px 0; }
.glossary { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
.glossary > div { padding: 10px 0; border-bottom: 1px solid var(--border); }
.glossary dt { font-weight: 700; }
.glossary dd { margin: 2px 0 0; color: var(--text-2); }
.flashcard {
  width: 100%; min-height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface-2); cursor: pointer; text-align: center;
}
.flashcard.flipped { border-color: var(--primary); }
.fc-front { font-size: 1.3rem; font-weight: 700; }
.fc-back { font-size: 1.1rem; color: var(--text); background: var(--surface); padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); }

/* ---------- Dialog ---------- */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.dialog { background: var(--surface); color: var(--text); border-radius: var(--radius); max-width: 460px; width: 100%; padding: 22px; border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.dialog .row { justify-content: flex-end; margin-top: 16px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: .9rem; z-index: 60; box-shadow: var(--shadow); }

@media (prefers-reduced-motion: no-preference) {
  .option, .btn, .qnav-item { transition: background-color .12s, border-color .12s; }
}
@media print {
  .topbar, .site-footer, .toolbar, .qnav, .qactions, .no-print { display: none !important; }
}

/* New version available */
.update-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 1100px; margin: 12px auto 0; padding: 10px 16px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface, var(--bg)); color: var(--text); width: calc(100% - 32px); box-sizing: border-box; }
.update-banner .btn { flex: none; }

/* ---------- Static SEO pages (questions, study guide, FAQ) ---------- */
.page { max-width: 820px; margin: 0 auto; }
.page h1 { font-size: 1.75rem; }
.page h2 { margin-top: 28px; }
.page .lead { font-size: 1.05rem; color: var(--text-2); }
.crumbs { font-size: .85rem; color: var(--muted); margin: 0 0 12px; }
.crumbs a { color: var(--muted); }
.cta { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 20px 0; }
.cta p { margin: 0 0 10px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.link-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 16px 0; }
.link-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.link-card:hover { border-color: var(--primary); }
.link-card strong { display: block; color: var(--primary); margin-bottom: 4px; }
.link-card span { font-size: .9rem; color: var(--muted); }
.qa-list { list-style: none; padding: 0; margin: 16px 0; counter-reset: qa; }
.qa { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; counter-increment: qa; }
.qa h3 { font-size: 1rem; margin: 0 0 8px; }
.qa h3::before { content: counter(qa) ". "; color: var(--muted); }
.qa ol { list-style: upper-alpha; margin: 0 0 8px; }
.qa details summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .9rem; }
.qa details p { margin: 8px 0 0; }
.qa .correct { color: var(--ok); font-weight: 600; }
.study-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin: 0 0 12px; }
.study-section h2 { margin: 0 0 8px; font-size: 1.15rem; }
.glossary dt { font-weight: 650; margin-top: 12px; }
.glossary dd { margin: 2px 0 0; color: var(--text-2); }
.faq-item { margin: 0 0 18px; }
.faq-item h2 { font-size: 1.1rem; margin: 0 0 6px; }
.site-footer .footer-nav { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.footer-nav a { white-space: nowrap; }
