/* Theme tokens: dark "security ops" navy by default; light via [data-theme="light"]. */
:root {
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #18233b;
  --text: #e6edf6;
  --muted: #9fb0c6;
  --border: #26344f;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-contrast: #04211d;
  --accent-soft: #0f2f35;
  --good: #4ade80;
  --good-soft: #0f2a1c;
  --bad: #f87171;
  --bad-soft: #341719;
  --warn: #fbbf24;
  --warn-soft: #33270c;
  --radius: 12px;
  --shadow: none;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eaf0f6;
  --text: #0f1b2d;
  --muted: #4d5d73;
  --border: #d3dce8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-contrast: #ffffff;
  --accent-soft: #dff5f2;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #92400e;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 1px 3px rgba(15, 27, 45, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 1rem/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
main { flex: 1; padding: 28px 0 48px; }
main:focus { outline: none; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { line-height: 1.25; }
h1, h2, .brand, .eyebrow, .stat-value, .score-big, .tag, kbd, code, pre { font-family: var(--mono); }
h1 { letter-spacing: -.02em; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-x: auto; font-size: .85rem; line-height: 1.5; }
pre code { background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 800px; margin: 0 auto; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 50; background: var(--accent); color: var(--accent-contrast); padding: 8px 14px; border-radius: 8px; font-weight: 700; }
.skip-link:focus { top: 8px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-inner { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; order: 1; }
.brand svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.site-nav { display: flex; gap: 2px; order: 2; margin-left: auto; }
.site-nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .95rem; white-space: nowrap; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.header-actions { display: flex; gap: 6px; order: 3; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 24px 0; font-size: .85rem; color: var(--muted); }
.footer-inner { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; align-items: center; }
.footer-inner p { margin: 0; max-width: 680px; }
.footer-inner nav { display: flex; gap: 14px; flex-wrap: wrap; }
.footer-inner nav a { color: var(--muted); }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; line-height: 1.3;
  text-decoration: none; cursor: pointer; min-height: 44px;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; font-size: .9rem; cursor: pointer; text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label, legend { font-weight: 650; padding: 0; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
fieldset:disabled { opacity: .55; }
select, input[type="range"] { max-width: 100%; }
select { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; min-height: 44px; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }
.checkbox { display: flex; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; flex: none; }
.check-group legend { margin-bottom: 4px; }
.check-group.inline { display: flex; flex-wrap: wrap; gap: 0 20px; }
.check-group.inline legend { width: 100%; }
.check-actions { display: flex; gap: 14px; margin-bottom: 2px; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 6px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 14px; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--surface); }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 5px; }
.radio-card strong { display: block; }
.radio-card span span { display: block; font-size: .875rem; color: var(--muted); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-error { color: var(--bad); font-weight: 600; min-height: 1.2em; margin: 0 0 10px; }
.form-error:empty { display: none; }
.form-status { color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }
.hint { margin: -4px 0 10px 28px; }

/* Layout pieces */
.hero { padding: 12px 0 4px; }
.eyebrow { color: var(--accent); margin: 0 0 8px; font-size: .9rem; }
.hero h1 { font-size: clamp(1.7rem, 4.5vw, 2.5rem); margin: 0 0 12px; }
.hero p { color: var(--muted); font-size: 1.08rem; max-width: 680px; margin: 0 0 20px; }
.hero-actions, .card-actions, .result-actions, .quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-actions { margin: 16px 0; }
.section-title { font-size: 1.3rem; margin: 36px 0 14px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.section-sub { font-size: 1rem; margin: 22px 0 8px; }
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: clamp(1.5rem, 4vw, 2rem); }
.page-head p { margin: 6px 0 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid > .card, .steps > .card { margin-bottom: 0; }
.card-title { font-size: 1.1rem; margin: 0 0 14px; }
.card-link { text-decoration: none; color: inherit; }
.card-link:hover { border-color: var(--accent); color: inherit; }
.exam-card { display: flex; flex-direction: column; gap: 10px; }
.exam-card h3 { margin: 0; font-size: 1.35rem; font-family: var(--mono); }
.exam-card-head { display: flex; justify-content: space-between; align-items: center; }
.card-sub { margin: 0; }
.card-actions { margin-top: auto; padding-top: 6px; }
.card-actions .btn { padding: 8px 12px; }
.mini-progress { display: grid; gap: 4px; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; text-transform: none; }
.exam-card-head .tag, .card-link .tag { margin-left: 0; align-self: flex-start; }
.diff-easy { background: var(--good-soft); color: var(--good); }
.diff-medium { background: var(--warn-soft); color: var(--warn); }
.diff-hard { background: var(--bad-soft); color: var(--bad); }
.meta-row { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .9rem; color: var(--muted); }
.steps { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.steps h3 { margin: 0 0 6px; font-size: 1.02rem; }
.steps p { margin: 0; color: var(--muted); }
.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.recent-list li:first-child { border-top: 0; }
.notice { padding: 12px 16px; border-radius: 10px; background: var(--warn-soft); border: 1px solid var(--warn); margin: 0 0 16px; }

/* Ads */
.ad-slot { margin: 24px 0; }
.ad-slot ins { display: block; width: 100%; }
.ad-placeholder { min-height: 90px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: .75rem; display: flex; align-items: center; justify-content: center; letter-spacing: .08em; text-transform: uppercase; }

/* Bars & charts */
.domain-bars { display: grid; gap: 12px; list-style: none; margin: 0; padding: 0; }
.bar-label { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 12px; font-size: .9rem; margin-bottom: 4px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .6s ease; }
.bar-row.weak .bar > span { background: var(--warn); }
.bar-row.weak .bar-label > :first-child { color: var(--warn); font-weight: 650; }
.line-chart { width: 100%; height: auto; display: block; }
.line-chart .grid { stroke: var(--border); stroke-width: 1; }
.line-chart .axis { fill: var(--muted); font-size: 12px; font-family: var(--mono); }
.line-chart .pass { stroke: var(--warn); stroke-dasharray: 6 5; stroke-width: 1.5; }
.line-chart .trend { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.line-chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.stat-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 2px; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.exam-progress summary { cursor: pointer; margin-bottom: 4px; }
.exam-progress[open] summary { margin-bottom: 14px; }

/* Quiz */
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px; font-size: .9rem; color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.question-text { font-family: inherit; font-size: 1.15rem; line-height: 1.55; margin: 0 0 18px; font-weight: 600; }
.question-text:focus { outline: none; }
.multi-hint { margin: -8px 0 14px; color: var(--accent); font-weight: 650; font-size: .92rem; }
.options { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.option {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 13px 16px;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  font: inherit; line-height: 1.45; cursor: pointer; min-height: 48px;
  transition: border-color .15s ease, background-color .15s ease;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: .85rem; background: var(--surface-2); color: var(--muted);
}
.option .letter.square { border-radius: 6px; }
.option > span:last-child { padding-top: 2px; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .letter { background: var(--accent); color: var(--accent-contrast); }
.option.correct { border-color: var(--good); background: var(--good-soft); animation: pop .3s ease; }
.option.correct .letter { background: var(--good); color: var(--bg); }
.option.incorrect { border-color: var(--bad); background: var(--bad-soft); animation: shake .3s ease; }
.option.incorrect .letter { background: var(--bad); color: var(--bg); }
.option:disabled { cursor: default; opacity: 1; }
@keyframes pop { 50% { transform: scale(1.015); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.explanation { margin-top: 18px; padding: 14px 16px; border-radius: 10px; background: var(--surface-2); border-left: 4px solid var(--accent); }
.explanation:focus { outline: none; }
.explanation.good { border-left-color: var(--good); }
.explanation.bad { border-left-color: var(--bad); }
.explanation > strong { display: block; margin-bottom: 4px; }
.explanation p { margin: 0 0 6px; }
.rationales { margin: 8px 0 0; padding-left: 18px; }
.rationales li { margin: 6px 0; }
.refs { font-size: .85rem; color: var(--muted); margin-top: 8px !important; }
.quiz-nav { display: flex; align-items: center; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.quiz-nav .spacer { flex: 1; }
.flag-btn[aria-pressed="true"], .bookmark-btn[aria-pressed="true"] { border-color: var(--warn); background: var(--warn-soft); }
.navigator { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; margin-top: 18px; }
.navigator button { height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; position: relative; }
.navigator .answered { background: var(--accent-soft); border-color: var(--accent); }
.navigator .current { outline: 2px solid var(--accent); outline-offset: 1px; }
.navigator .flagged::after { content: ""; position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.timer { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.timer.low { color: var(--bad); }
.kbd-hint { margin: 16px 0 0; font-size: .8rem; color: var(--muted); }
kbd { font-size: .75rem; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* Results */
.score-head { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.score-big { font-size: 3.2rem; font-weight: 800; line-height: 1; }
.score-big.pass { color: var(--good); }
.score-big.fail { color: var(--bad); }
.score-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.score-head h2:focus { outline: none; }
.score-head p { margin: 0; }
.next-steps { margin: 0 0 16px; padding-left: 20px; }
.next-steps li { margin: 6px 0; }
.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.filter-tabs button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .875rem; cursor: pointer; min-height: 36px; }
.filter-tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.review-item { border-top: 1px solid var(--border); padding: 18px 0; }
.review-item h3 { font-size: 1rem; margin: 0 0 10px; font-weight: 600; }
.q-num { color: var(--muted); font-weight: 700; margin-right: 6px; }
.review-opt { padding: 6px 10px; border-radius: 6px; margin: 4px 0; font-size: .95rem; display: flex; gap: 8px; }
.review-opt .mark { flex: none; width: 1.2em; font-weight: 700; }
.review-opt.correct { background: var(--good-soft); }
.review-opt.wrong { background: var(--bad-soft); }
.review-item .explanation { margin-top: 10px; font-size: .95rem; }
.status-pill { font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.status-pill.ok { background: var(--good-soft); color: var(--good); }
.status-pill.no { background: var(--bad-soft); color: var(--bad); }
.status-pill.skip { background: var(--surface-2); color: var(--muted); }

/* Flashcards */
.fc-stage { display: grid; gap: 14px; }
.flashcard {
  position: relative; display: block; width: 100%; min-height: 260px; padding: 0; border: 0; background: none;
  cursor: pointer; perspective: 1200px; font: inherit; color: inherit; text-align: center;
}
.fc-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  backface-visibility: hidden; transition: transform .45s ease;
}
.fc-back { transform: rotateY(180deg); background: var(--surface-2); border-color: var(--accent); }
.flashcard.flipped .fc-front { transform: rotateY(-180deg); }
.flashcard.flipped .fc-back { transform: rotateY(0); }
.flashcard:focus-visible .fc-face { outline: 2px solid var(--accent); outline-offset: 2px; }
.fc-domain { font-size: .8rem; color: var(--muted); font-family: var(--mono); }
.fc-term { font-size: clamp(1.3rem, 4vw, 1.8rem); font-weight: 700; font-family: var(--mono); color: var(--accent); }
.fc-def { font-size: 1.08rem; line-height: 1.55; max-width: 560px; }
.fc-hint { font-size: .8rem; color: var(--muted); }
.fc-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Articles */
.prose h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 0 0 12px; }
.prose h2 { font-size: 1.3rem; margin: 30px 0 10px; }
.prose h3 { font-size: 1.08rem; margin: 22px 0 8px; }
.prose .lede { font-size: 1.08rem; color: var(--muted); }
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
tr:last-child td, tr:last-child th { border-bottom: 0; }
th { background: var(--surface-2); font-weight: 650; }
.cta-box { margin: 30px 0; padding: 20px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent); display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.cta-box p { margin: 0; font-weight: 600; }
.settings-form .field { max-width: 360px; }

@media (max-width: 640px) {
  .site-nav { order: 4; width: 100%; margin: 0 -10px; overflow-x: auto; padding-bottom: 6px; }
  .header-actions { margin-left: auto; }
  .card { padding: 16px; }
  .question-text { font-size: 1.05rem; }
  .quiz-nav .btn { flex: 1 1 auto; }
  .quiz-nav .spacer { display: none; }
  .score-big { font-size: 2.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
