:root {
  --bg: #F1F5F6;
  --surface: #FFFFFF;
  --surface-2: #E7EEF0;
  --ink: #10232A;
  --muted: #5B6D73;
  --line: #D3DDE0;
  --accent: #0E7C7B;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEFEE;
  --good: #1B7F4D;
  --good-soft: #E1F3E9;
  --bad: #B8411F;
  --bad-soft: #FBE8E2;
  --flag: #B7791F;
  --flag-soft: #FBF0DA;
  --shadow: 0 1px 2px rgba(16, 35, 42, 0.06), 0 8px 24px -16px rgba(16, 35, 42, 0.25);
  --radius: 10px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E181B;
    --surface: #152327;
    --surface-2: #1D2F34;
    --ink: #E6EEF0;
    --muted: #94A7AC;
    --line: #2A3D43;
    --accent: #3FB8B1;
    --accent-ink: #06201F;
    --accent-soft: #163A3A;
    --good: #4CC585;
    --good-soft: #163626;
    --bad: #F0875F;
    --bad-soft: #3D1F15;
    --flag: #E0A84A;
    --flag-soft: #3A2C13;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -16px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #0E181B; --surface: #152327; --surface-2: #1D2F34; --ink: #E6EEF0; --muted: #94A7AC; --line: #2A3D43;
  --accent: #3FB8B1; --accent-ink: #06201F; --accent-soft: #163A3A; --good: #4CC585; --good-soft: #163626;
  --bad: #F0875F; --bad-soft: #3D1F15; --flag: #E0A84A; --flag-soft: #3A2C13;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.0625rem; }
p { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 820px; margin: 0 auto; padding: 24px 16px 80px; }
.loading { padding: 80px 0; color: var(--muted); text-align: center; }
.stack > * + * { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.9375rem; }

/* time strip: the one loud element — a bar across the very top that drains as time runs out */
.timestrip { position: fixed; inset: 0 0 auto 0; height: 6px; background: var(--surface-2); z-index: 20; }
.timestrip-fill { height: 100%; width: 100%; background: var(--accent); transition: width 1s linear, background-color 0.4s; }
.timestrip.low .timestrip-fill { background: var(--bad); }
.timestrip.paused .timestrip-fill { background: var(--flag); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 500; min-height: 44px;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.lg { padding: 14px 24px; font-size: 1.0625rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-row.end { justify-content: flex-end; }
.btn-row.between { justify-content: space-between; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.app > .card + .card, .review-item + .review-item { margin-top: 16px; }

/* home */
.masthead { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.masthead .sub { color: var(--muted); margin-top: 6px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .modes { grid-template-columns: 1fr; } }
.mode { display: flex; flex-direction: column; gap: 12px; }
.mode h2 { font-size: 1.5rem; }
.mode p { color: var(--muted); flex: 1; }
.mode ul { margin: 0; padding-left: 18px; color: var(--muted); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 14px; padding: 16px 20px; margin-bottom: 16px; }

.stats { display: flex; gap: 28px; flex-wrap: wrap; }
.stat b { display: block; font-size: 1.75rem; font-weight: 600; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 0.9375rem; }

table.history { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
table.history th, table.history td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.history th { color: var(--muted); font-weight: 500; }
table.history td.num, table.history th.num { text-align: right; }
table.history tr:last-child td { border-bottom: none; }

/* bars */
.bars { display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: minmax(120px, 180px) 1fr 70px; gap: 12px; align-items: center; font-size: 0.9375rem; }
.bar .track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.bar .fill.good { background: var(--good); }
.bar .fill.bad { background: var(--bad); }
.bar .val { text-align: right; color: var(--muted); }

/* setup form */
.field { display: grid; gap: 8px; }
.field > label, .field > .label { font-weight: 500; }
.field .hint { color: var(--muted); font-size: 0.9375rem; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; min-height: 40px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: 10px; }
.check input { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--accent); }
.check .hint { display: block; color: var(--muted); font-size: 0.9375rem; }
select, input[type="number"] { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); min-height: 44px; }
.pool-note { padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius); font-size: 0.9375rem; }

/* exam */
.exam-top { position: sticky; top: 6px; z-index: 10; background: var(--bg); padding: 12px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.exam-top .where { font-weight: 500; }
.exam-top .where span { color: var(--muted); font-weight: 400; }
.clock { font-size: 1.5rem; font-weight: 600; letter-spacing: 0.02em; min-width: 5.2ch; text-align: right; }
.clock.low { color: var(--bad); }
.clock.paused { color: var(--flag); }
.exam-tools { display: flex; gap: 6px; align-items: center; }

.question { padding: 28px 26px; }
.question .qtext { font-size: 1.25rem; line-height: 1.45; font-weight: 500; max-width: 68ch; }
.question .qmeta { color: var(--muted); font-size: 0.875rem; margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); font-size: 0.8125rem; }
.tag.warn { background: var(--flag-soft); color: var(--flag); }

.options { list-style: none; margin: 22px 0 0; padding: 0; display: grid; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; align-items: center; width: 100%; text-align: left;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); min-height: 56px;
  transition: border-color 0.15s, background-color 0.15s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .key { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-weight: 600; }
.opt .otext { line-height: 1.4; }
.opt .mark { font-size: 0.875rem; font-weight: 600; }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.opt[aria-checked="true"] .key { background: var(--accent); color: var(--accent-ink); }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .key { background: var(--good); color: #fff; }
.opt.correct .mark { color: var(--good); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt.wrong .mark { color: var(--bad); }
.opt:disabled { cursor: default; }

.verdict { margin-top: 20px; padding: 14px 16px; border-radius: 12px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.verdict.good { background: var(--good-soft); color: var(--good); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.neutral { background: var(--surface-2); color: var(--ink); }

.explain { margin-top: 18px; display: grid; gap: 14px; }
.explain h3 { font-size: 0.9375rem; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.explain ul { margin: 0; padding-left: 20px; }
.explain li + li { margin-top: 4px; }
.explain .answer { font-size: 1.125rem; font-weight: 500; }
.rtl { direction: rtl; unicode-bidi: plaintext; }
details.source summary { cursor: pointer; color: var(--accent); font-weight: 500; list-style: none; display: inline-flex; gap: 6px; align-items: center; }
details.source summary::-webkit-details-marker { display: none; }
details.source summary::before { content: "▸"; }
details.source[open] summary::before { content: "▾"; }
details.source img { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
details.source .note { margin-top: 6px; font-size: 0.875rem; color: var(--muted); }

.exam-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font-size: 0.8125rem; background: var(--surface); color: var(--muted); }

/* palette */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin-top: 12px; }
.pbtn { height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 0.875rem; }
.pbtn.answered { background: var(--accent-soft); border-color: var(--accent); }
.pbtn.flagged { box-shadow: inset 0 0 0 2px var(--flag); }
.pbtn.current { outline: 3px solid var(--accent); outline-offset: 1px; }
.pbtn.right { background: var(--good-soft); border-color: var(--good); }
.pbtn.wrongp { background: var(--bad-soft); border-color: var(--bad); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 0.875rem; margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; border: 1px solid var(--line); }

/* overlay (pause, confirm) */
.overlay { position: fixed; inset: 0; background: rgba(8, 20, 24, 0.55); display: grid; place-items: center; z-index: 30; padding: 16px; backdrop-filter: blur(3px); }
.overlay .card { max-width: 460px; width: 100%; }
.overlay h2 { margin-bottom: 8px; }

/* break */
.break { text-align: center; padding: 60px 24px; }
.break .bigclock { font-size: clamp(3rem, 12vw, 5.5rem); font-weight: 600; letter-spacing: 0.02em; margin: 18px 0 8px; }

/* results */
.score { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.score b { font-size: 3.5rem; font-weight: 600; line-height: 1; }
.score span { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.review-item { padding: 18px 20px; }
.review-item .head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.review-item .n { color: var(--muted); font-size: 0.875rem; white-space: nowrap; }
.review-item .qtext { margin-top: 4px; font-weight: 500; }
.review-item .pill { font-size: 0.8125rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.skip { background: var(--surface-2); color: var(--muted); }
.review-opts { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; font-size: 0.9375rem; }
.review-opts li { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); display: flex; gap: 10px; }
.review-opts li.correct { border-color: var(--good); background: var(--good-soft); }
.review-opts li.chosen.wrong { border-color: var(--bad); background: var(--bad-soft); }
.review-opts .k { font-weight: 600; min-width: 1.4em; }

footer.about { margin-top: 40px; color: var(--muted); font-size: 0.875rem; line-height: 1.55; }
footer.about p + p { margin-top: 8px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .question { padding: 20px 16px; }
  .question .qtext { font-size: 1.125rem; }
  .opt { grid-template-columns: 34px 1fr auto; gap: 10px; padding: 10px 12px; }
  .opt .key { width: 34px; height: 34px; }
  .bar { grid-template-columns: 1fr 60px; }
  .bar .track { grid-column: 1 / -1; order: 3; }
  h1 { font-size: 1.625rem; }
  .score b { font-size: 2.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (max-width: 640px) {
  .exam-nav > span { display: none; }
}

/* ---- practice gamification ---- */
.scorebox { position: relative; display: inline-flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 0.9375rem; }
.scorebox .pts b { font-size: 1.125rem; font-weight: 600; }
.scorebox .streak { color: var(--flag); font-weight: 600; }
.scorebox .float { position: absolute; left: 50%; top: -4px; transform: translateX(-50%); color: var(--good); font-weight: 700; pointer-events: none; animation: floatUp 1.1s ease-out forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 6px) scale(0.8); } 20% { opacity: 1; transform: translate(-50%, -4px) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -34px) scale(1); } }
.gain { font-weight: 500; font-size: 0.9375rem; margin-left: auto; opacity: 0.95; }
.verdict { flex-wrap: wrap; }

.opt { position: relative; }
.opt.anim-right { animation: popRight 0.55s cubic-bezier(.2,.9,.3,1.3); }
@keyframes popRight { 0% { transform: scale(1); } 35% { transform: scale(1.035); box-shadow: 0 0 0 6px color-mix(in srgb, var(--good) 35%, transparent); } 100% { transform: scale(1); box-shadow: none; } }
.opt.anim-wrong, .scorebox.anim-wrong { animation: shake 0.45s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
.opt .spark { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--good)); pointer-events: none; opacity: 0; animation: burst 0.8s ease-out forwards; }
.opt .spark:nth-child(odd) { width: 6px; height: 6px; border-radius: 2px; }
@keyframes burst { 0% { opacity: 1; transform: translate(-50%, -50%) scale(0.6); } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1); } }

.toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 22px; border-radius: 999px; font-weight: 600; font-size: 1.125rem; z-index: 40; box-shadow: var(--shadow); animation: toastIn 1.8s ease forwards; pointer-events: none; }
@keyframes toastIn { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.9); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.04); } 20% { transform: translate(-50%, 0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -12px); } }

@media (prefers-reduced-motion: reduce) {
  .opt.anim-right, .opt.anim-wrong, .scorebox.anim-wrong, .scorebox .float, .toast, .opt .spark { animation: none; }
  .scorebox .float, .opt .spark { display: none; }
}
.mode h2 .emoji { display: inline-block; margin-right: 6px; font-size: 1.35em; vertical-align: -0.1em; }
.exam-tools { flex-wrap: wrap; justify-content: flex-end; }
.xs-only { display: none; }
@media (max-width: 480px) {
  .exam-top .btn { padding: 8px 10px; min-height: 40px; }
  .xs-hide { display: none; }
  .xs-only { display: inline; }
  .clock { font-size: 1.25rem; }
}

/* ---- blueprint sections & assessment ---- */
.chip .chip-w { opacity: 0.75; font-size: 0.8125rem; margin-left: 2px; }
.chip .chip-n { display: inline-block; min-width: 1.6em; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: rgba(127,127,127,0.18); font-size: 0.75rem; text-align: center; }
details.advanced summary { cursor: pointer; color: var(--muted); font-size: 0.9375rem; }
.bar .bar-name { line-height: 1.25; }
.bar .val b.strong { color: var(--good); }
.bar .val b.weak { color: var(--bad); }
.bar .val b.okay { color: var(--flag); }
.pill.mid { background: var(--flag-soft); color: var(--flag); }
.focus { margin-top: 20px; padding: 16px 18px; border-radius: 12px; background: var(--accent-soft); }
.focus.good { background: var(--good-soft); }
.focus h3 { margin-bottom: 8px; }
.focus ol { margin: 0; padding-left: 20px; }
.focus li + li { margin-top: 6px; }
details.topics { border-top: 1px solid var(--line); padding: 10px 0; }
details.topics summary { cursor: pointer; list-style: none; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details.topics summary::-webkit-details-marker { display: none; }
details.topics summary::before { content: "▸"; color: var(--muted); }
details.topics[open] summary::before { content: "▾"; }
.topic-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.9375rem; }
.topic-table td { padding: 6px 8px; border-bottom: 1px dashed var(--line); }
.topic-table td.num { text-align: right; white-space: nowrap; }
.topic-table b.strong { color: var(--good); } .topic-table b.weak { color: var(--bad); } .topic-table b.okay { color: var(--flag); }
.options.readonly .opt { cursor: default; opacity: 0.9; }
