:root {
  --ink: #0b1f3a;
  --ink-2: #33415c;
  --muted: #64748b;
  --paper: #f3f1ec;
  --card: #ffffff;
  --line: #e2ddd3;
  --line-2: #d1cabd;
  --red: #d52b1e;
  --red-soft: #fde8e6;
  --ok: #0f8a5f;
  --ok-soft: #e3f5ec;
  --ko: #c8261b;
  --ko-soft: #fdeae8;
  --warn: #b45309;
  --accent: #0b1f3a;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(11, 31, 58, .06), 0 6px 18px rgba(11, 31, 58, .06);
  --r: 14px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eef2f8; --ink-2: #c3cddc; --muted: #8b98ab; --paper: #0a1424; --card: #111e33; --line: #1f2f4a; --line-2: #2a3d5c;
    --red-soft: #3a1714; --ok: #34c08a; --ok-soft: #10301f; --ko: #ff6b5e; --ko-soft: #3a1714; --accent: #eef2f8;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #eef2f8; --ink-2: #c3cddc; --muted: #8b98ab; --paper: #0a1424; --card: #111e33; --line: #1f2f4a; --line-2: #2a3d5c;
  --red-soft: #3a1714; --ok: #34c08a; --ok-soft: #10301f; --ko: #ff6b5e; --ko-soft: #3a1714; --accent: #eef2f8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.5; color: var(--ink); background: var(--paper); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.hidden { display: none !important; }

/* ---- header ---- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: #0b1f3a; color: #fff; border-bottom: 3px solid var(--red); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; color: var(--red); flex: none; }
.brand-text { font-family: var(--display); font-size: 24px; letter-spacing: .02em; font-weight: 700; text-transform: uppercase; }
.brand-text b { color: #fff; font-weight: 800; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a { text-decoration: none; padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 15px; color: #c9d4e6; }
.topnav a.on { color: #fff; background: rgba(255,255,255,.1); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: rgba(127,127,127,.14); }
.icon-btn svg { width: 22px; height: 22px; }
.foot { text-align: center; padding: 18px 16px 28px; color: var(--muted); font-size: 13px; }
.foot p { max-width: 640px; margin: 0 auto; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1.5px solid var(--line-2); background: var(--card); font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none; transition: transform .08s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #b92318; }
.btn.dark { background: #0b1f3a; border-color: #0b1f3a; color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

/* ---- home ---- */
.hero { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 22px; }
.hero h1 { font-family: var(--display); font-weight: 800; font-size: clamp(34px, 7vw, 52px); line-height: .95; margin: 6px 0 8px; text-transform: uppercase; letter-spacing: .01em; }
.hero h1 em { font-style: normal; color: var(--red); }
.hero p { margin: 0; color: var(--ink-2); max-width: 560px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .v { font-family: var(--mono); font-size: 24px; font-weight: 600; line-height: 1.1; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .v.ok { color: var(--ok); } .kpi .v.ko { color: var(--ko); }

.section-title { font-family: var(--display); text-transform: uppercase; letter-spacing: .06em; font-size: 15px; font-weight: 700; color: var(--muted); margin: 26px 0 10px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.modules { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.mod { position: relative; display: flex; flex-direction: column; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 16px 14px; box-shadow: var(--shadow); text-decoration: none; overflow: hidden; }
.mod::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--c); }
.mod-link { text-decoration: none; display: grid; gap: 10px; align-content: start; flex: 1; }
.mod-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mod-code { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--c); }
.mod h3 { margin: 0; font-family: var(--display); font-size: 25px; line-height: 1.05; font-weight: 700; text-transform: uppercase; }
.mod p { margin: 0; color: var(--ink-2); font-size: 15px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .ok { background: var(--ok); } .bar .ko { background: var(--ko); opacity: .75; }
.mod-foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 500; }
.mod-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.mod-actions .btn { min-height: 42px; font-size: 15px; }

.quick { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.quick a { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; text-decoration: none; box-shadow: var(--shadow); }
.quick a .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--red-soft); color: var(--red); flex: none; font-size: 20px; }
.quick a b { display: block; font-size: 16px; }
.quick a span { font-size: 13px; color: var(--muted); }
.quick a[aria-disabled="true"] { opacity: .55; pointer-events: none; }

/* ---- module page ---- */
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.page-title { font-family: var(--display); font-size: clamp(30px, 6vw, 44px); text-transform: uppercase; line-height: 1; margin: 4px 0 6px; }
.modes { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin: 18px 0; }
.mode { text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: 16px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.mode b { font-family: var(--display); font-size: 24px; text-transform: uppercase; }
.mode span { color: var(--ink-2); font-size: 15px; }
.mode.sel { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line-2); background: var(--card); border-radius: 99px; padding: 7px 13px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: #0b1f3a; color: #fff; border-color: #0b1f3a; }
:root[data-theme="dark"] .chip[aria-pressed="true"] { background: #eef2f8; color: #0b1f3a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip[aria-pressed="true"] { background: #eef2f8; color: #0b1f3a; border-color: #eef2f8; } }
.chip small { font-family: var(--mono); opacity: .7; margin-left: 4px; }
.opts { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.opts h4 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.topics { width: 100%; border-collapse: collapse; font-size: 15px; }
.topics td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.topics td:last-child { text-align: right; font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.topics .bar { width: 90px; display: inline-flex; vertical-align: middle; margin-right: 8px; height: 6px; }

/* ---- question view ---- */
.qbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.qbar .where { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tag { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 4px 8px; border-radius: 6px; background: var(--c, #0b1f3a); color: #fff; white-space: nowrap; }
.counter { display: flex; gap: 6px; font-family: var(--mono); font-weight: 600; font-size: 15px; }
.counter span { padding: 4px 10px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
.counter .ok { color: var(--ok); } .counter .ko { color: var(--ko); }
.timer { font-family: var(--mono); font-weight: 600; font-size: 18px; padding: 4px 10px; border-radius: 8px; background: #0b1f3a; color: #fff; }
.timer.low { background: var(--ko); }
.progress { height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.progress i { display: block; height: 100%; background: var(--red); transition: width .25s; }

.qcard { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.qmeta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.qmeta .num { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 600; }
.qmeta .tools { display: flex; gap: 4px; }
.qmeta .icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--paper); }
.qmeta .icon-btn[aria-pressed="true"] { color: var(--red); border-color: var(--red); }
.qmeta .icon-btn.speaking { color: #fff; background: var(--red); border-color: var(--red); }
.qtext { font-size: 21px; font-weight: 600; line-height: 1.4; margin: 0 0 18px; }
.answers { display: grid; gap: 10px; }
.ans { display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line-2); background: var(--card); cursor: pointer; font-size: 17px; line-height: 1.4; transition: border-color .12s, background .12s; }
.ans:hover:not([disabled]) { border-color: var(--ink-2); }
.ans .k { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--paper); border: 1px solid var(--line); font-family: var(--mono); font-weight: 600; font-size: 14px; }
.ans.picked { border-color: #0b1f3a; background: rgba(11,31,58,.05); box-shadow: inset 0 0 0 1px #0b1f3a; }
.ans.picked .k { background: #0b1f3a; color: #fff; border-color: #0b1f3a; }
.ans.right { border-color: var(--ok); background: var(--ok-soft); }
.ans.right .k { background: var(--ok); color: #fff; border-color: var(--ok); }
.ans.wrong { border-color: var(--ko); background: var(--ko-soft); }
.ans.wrong .k { background: var(--ko); color: #fff; border-color: var(--ko); }
.ans[disabled] { cursor: default; }
.explain { margin-top: 16px; border-radius: 12px; padding: 14px 16px; border-left: 5px solid var(--ok); background: var(--ok-soft); }
.explain.bad { border-left-color: var(--ko); background: var(--ko-soft); }
.explain h4 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.explain p { margin: 0; color: var(--ink-2); }
.explain .ref { margin-top: 6px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.qnav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; }
.qnav .btn { flex: 1; }
.qnav .btn.flag { flex: 0 0 58px; padding: 0; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }
.hint kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--card); }
@media (hover: none) { .hint { display: none; } }

.grid-nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin-top: 18px; }
.grid-nav button { height: 40px; border-radius: 8px; border: 1.5px solid var(--line-2); background: var(--card); font-family: var(--mono); font-weight: 600; font-size: 13px; cursor: pointer; position: relative; }
.grid-nav button.done { background: #0b1f3a; color: #fff; border-color: #0b1f3a; }
.grid-nav button.cur { box-shadow: 0 0 0 3px var(--red); }
.grid-nav button.flag::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }

/* ---- results ---- */
.result-head { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.ring { width: 128px; height: 128px; }
.ring text { font-family: var(--mono); font-weight: 600; fill: var(--ink); }
.verdict { font-family: var(--display); font-size: 34px; text-transform: uppercase; font-weight: 800; line-height: 1; margin: 0 0 6px; }
.verdict.pass { color: var(--ok); } .verdict.fail { color: var(--ko); }
.review { display: grid; gap: 10px; margin-top: 10px; }
.rv { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--ok); border-radius: 12px; padding: 14px 16px; }
.rv.bad { border-left-color: var(--ko); }
.rv .q { font-weight: 600; margin: 0 0 6px; }
.rv .a { font-size: 15px; margin: 2px 0; }
.rv .a.y { color: var(--ko); } .rv .a.c { color: var(--ok); font-weight: 600; }
.rv .e { font-size: 14px; color: var(--ink-2); margin: 6px 0 0; }
.filters { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

/* ---- stats ---- */
.stat-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.stat-table th, .stat-table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 15px; }
.stat-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--paper); }
.stat-table td.n { font-family: var(--mono); text-align: right; white-space: nowrap; }
.stat-table th.n { text-align: right; }
.pass-pill { font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.pass-pill.pass { background: var(--ok-soft); color: var(--ok); } .pass-pill.fail { background: var(--ko-soft); color: var(--ko); }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); background: var(--card); border: 1px dashed var(--line-2); border-radius: var(--r); }

/* ---- dialog ---- */
.sheet { border: 0; border-radius: 18px; padding: 0; width: min(460px, calc(100% - 24px)); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.sheet::backdrop { background: rgba(5, 12, 24, .55); }
.sheet form { padding: 20px; display: grid; gap: 14px; }
.sheet h2 { margin: 0; font-family: var(--display); text-transform: uppercase; font-size: 26px; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }
.field select, .field input[type=text], .field input[type=password], .field textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line-2); background: var(--paper); font-weight: 500; }
.field input[type=range] { width: 100%; accent-color: var(--red); }
.switch { display: flex; gap: 10px; align-items: center; font-size: 15px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--red); flex: none; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0b1f3a; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

@media (max-width: 640px) {
  body { font-size: 16px; }
  main { padding: 14px 16px 32px; }
  .brand-text { font-size: 21px; }
  .topnav a { padding: 8px 8px; font-size: 14px; }
  .modes { grid-template-columns: 1fr; }
  .qcard { padding: 16px; border-radius: 16px; }
  .qtext { font-size: 19px; }
  .ans { font-size: 16px; padding: 12px; }
  .result-head { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .kpi .v { font-size: 20px; }
  .qnav { position: sticky; bottom: 0; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 30%); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
