:root {
  --ink: #101817;
  --paper: #f2f0e8;
  --panel: #fffef9;
  --lime: #c6ff36;
  --cyan: #43dbdf;
  --orange: #ff794a;
  --muted: #66716d;
  --line: #c9cec8;
  --shadow: 8px 8px 0 var(--ink);
  --sans: "Segoe UI", "Sylfaen", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: radial-gradient(#101817 0.55px, transparent 0.55px);
  background-size: 7px 7px;
  mask-image: linear-gradient(to bottom, #000, transparent 75%);
}

.topbar {
  height: 76px;
  border-bottom: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 5vw, 72px);
  position: relative;
  z-index: 2;
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.1rem; }
.brand-mark { background: var(--ink); color: var(--lime); padding: 8px 9px; font: 600 .85rem var(--mono); }
.header-actions { display: flex; align-items: center; gap: 18px; }
.header-meta { display: flex; align-items: center; gap: 10px; font: 500 .75rem var(--mono); letter-spacing: .05em; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #30cc6d; box-shadow: 0 0 0 4px rgba(48,204,109,.16); }
.divider { color: #9aa29f; }
.lab17-link {
  border: 2px solid var(--ink);
  background: var(--lime);
  color: var(--ink);
  padding: 8px 11px;
  text-decoration: none;
  font: 700 .72rem var(--mono);
  letter-spacing: .04em;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.lab17-link:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.lab17-link:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

main { position: relative; z-index: 1; }
.screen { width: min(1180px, calc(100% - 40px)); min-height: calc(100vh - 138px); margin: 0 auto; }
.hidden { display: none !important; }

.setup-screen { display: grid; grid-template-columns: 1.2fr .8fr; gap: clamp(48px, 8vw, 110px); align-items: center; padding: 70px 0; }
.eyebrow { color: #32676a; margin: 0 0 20px; font: 600 .78rem var(--mono); letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(3.1rem, 7vw, 6.8rem); line-height: .96; letter-spacing: -.07em; }
h1 span { -webkit-text-stroke: 2px var(--ink); color: transparent; }
.lede { max-width: 680px; color: #46534f; font-size: 1.05rem; line-height: 1.8; margin: 28px 0 34px; }
.blueprint-strip { border: 2px solid var(--ink); display: flex; max-width: 650px; background: var(--panel); box-shadow: 5px 5px 0 var(--ink); }
.blueprint-strip span { flex: var(--w); min-width: 0; padding: 12px 7px; text-align: center; border-right: 1px solid var(--ink); font: 600 .66rem var(--mono); }
.blueprint-strip span:last-child { border: 0; }
.blueprint-strip b { display: block; margin-top: 3px; font-size: .6rem; color: var(--muted); }

.setup-card, .breakdown-card { background: var(--panel); border: 2px solid var(--ink); box-shadow: var(--shadow); padding: 26px; }
.card-head { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 26px; font: 600 .75rem var(--mono); letter-spacing: .08em; }
.code { font: 600 .72rem var(--mono); color: var(--muted); }
.profile-strip { display: grid; grid-template-columns: repeat(4, 1fr); max-width: 650px; margin-top: 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.profile-strip div { padding: 12px 9px; border-right: 1px solid var(--line); }
.profile-strip div:last-child { border: 0; }
.profile-strip span { display: block; color: var(--muted); font: 600 .58rem var(--mono); }
.profile-strip strong { font: 600 1rem var(--mono); }
label, legend { display: block; font-size: .8rem; font-weight: 700; margin-bottom: 10px; }
.select-wrap { position: relative; }
.select-wrap::after { content: "⌄"; position: absolute; right: 15px; top: 12px; pointer-events: none; font-size: 1.2rem; }
select { appearance: none; width: 100%; border: 1.5px solid var(--ink); background: white; color: var(--ink); padding: 14px 40px 14px 14px; font: 600 .82rem var(--sans); }
fieldset { border: 0; padding: 0; margin: 24px 0; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-option { margin: 0; }
.mode-option input { position: absolute; opacity: 0; }
.mode-option span { display: flex; min-height: 92px; flex-direction: column; gap: 7px; border: 1.5px solid var(--ink); padding: 13px; cursor: pointer; background: white; }
.mode-option b { font: 600 .72rem var(--mono); }
.mode-option small { color: var(--muted); font-size: .65rem; line-height: 1.45; }
.mode-option input:checked + span { background: var(--lime); box-shadow: 3px 3px 0 var(--ink); }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); border: 1.5px solid var(--ink); }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 12px; text-align: center; border-right: 1px solid var(--ink); cursor: pointer; font: 600 .85rem var(--mono); }
.segmented label:last-child span { border: 0; }
.segmented input:checked + span { background: var(--lime); }
.primary-btn, .ghost-btn { min-height: 50px; border: 2px solid var(--ink); padding: 12px 18px; font: 700 .85rem var(--sans); cursor: pointer; transition: transform .15s, box-shadow .15s; }
.primary-btn { width: 100%; color: var(--ink); background: var(--lime); box-shadow: 4px 4px 0 var(--ink); display: flex; align-items: center; justify-content: space-between; }
.primary-btn:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ink); }
.primary-btn:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.primary-btn span { font-size: 1.2rem; }
.fine-print { color: var(--muted); font-size: .69rem; line-height: 1.6; margin: 18px 0 0; }

.quiz-screen { padding: 48px 0 70px; }
.quiz-header { display: flex; justify-content: space-between; align-items: end; }
.quiz-header .eyebrow { margin-bottom: 9px; }
.question-counter { margin: 0; font: 500 .8rem var(--mono); }
.question-counter strong { font-size: 1.8rem; }
.quiz-stats { display: flex; gap: clamp(14px, 3vw, 40px); text-align: right; }
.quiz-stats div { display: flex; flex-direction: column; }
.quiz-stats span { color: var(--muted); font-size: .68rem; font-weight: 700; }
.quiz-stats strong { font: 600 1.2rem var(--mono); }
.exam-mode .quiz-stats > div:not(:last-child) { display: none; }
.exit-btn { display: block; margin: 10px 0 0 auto; border: 0; background: transparent; color: var(--muted); text-decoration: underline; font: 600 .68rem var(--sans); cursor: pointer; }
.progress-track { height: 8px; background: #d4d8d2; border: 1px solid var(--ink); margin: 22px 0 34px; }
.progress-bar { height: 100%; width: 0; background: var(--cyan); border-right: 1px solid var(--ink); transition: width .35s ease; }
.question-card { width: min(880px, 100%); margin: auto; background: var(--panel); border: 2px solid var(--ink); box-shadow: var(--shadow); padding: clamp(24px, 4vw, 46px); }
.question-meta { display: flex; align-items: center; justify-content: space-between; }
.badge { border: 1px solid var(--ink); padding: 5px 9px; font: 600 .65rem var(--mono); text-transform: uppercase; background: #e8ebe6; }
.badge-row { display: flex; gap: 7px; }
.type-badge { background: var(--cyan); }
.badge.medium { background: #fff3a1; }
.badge.hard { background: #ffb7a2; }
.question-card h2 { font-size: clamp(1.25rem, 2.5vw, 1.8rem); line-height: 1.5; margin: 24px 0 28px; letter-spacing: -.025em; }
.options { display: grid; gap: 12px; }
.option { width: 100%; display: grid; grid-template-columns: 38px 1fr; align-items: center; text-align: left; border: 1.5px solid var(--ink); background: white; padding: 0; font: 500 .91rem var(--sans); cursor: pointer; }
.option-key { align-self: stretch; display: grid; place-items: center; border-right: 1.5px solid var(--ink); background: #e9ebe7; font: 600 .8rem var(--mono); }
.option-text { padding: 13px 15px; }
.option:hover:not(:disabled) { background: #f3ffce; }
.option.selected { background: #ddf9fa; box-shadow: 3px 3px 0 var(--ink); transform: translate(-2px,-2px); }
.option.correct { background: #d8ffae; border-color: #207642; }
.option.correct .option-key { background: #5ed47e; }
.option.wrong { background: #ffe0d7; border-color: #b53d2a; }
.option.wrong .option-key { background: #ff9274; }
.option:disabled { color: var(--ink); cursor: default; }
.exam-notice { margin: -12px 0 18px; color: #6c5941; font-size: .72rem; }
.feedback { margin-top: 20px; border-left: 5px solid var(--cyan); background: #e6f9f7; padding: 15px 18px; }
.feedback.incorrect { border-color: var(--orange); background: #fff0ea; }
.feedback-title { font-weight: 800; margin: 0 0 5px; }
.feedback p:last-child { margin: 0; color: #3f4d49; font-size: .86rem; line-height: 1.6; }
.check-btn { margin-top: 18px; background: var(--cyan); }
.question-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 26px; }
.shortcut { color: var(--muted); font-size: .69rem; }
kbd { border: 1px solid #9aa39f; border-bottom-width: 2px; background: white; padding: 2px 5px; font: 500 .65rem var(--mono); }
.compact { width: auto; min-width: 160px; }

.result-screen { display: grid; grid-template-columns: 1fr .85fr; gap: 80px; align-items: center; padding: 65px 0; }
.result-hero { text-align: center; }
.score-ring { --score: 0deg; width: 220px; height: 220px; border-radius: 50%; margin: 0 auto 28px; background: conic-gradient(var(--lime) var(--score), #d7dbd4 0); display: grid; place-items: center; border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); }
.score-ring::before { content: ""; width: 166px; height: 166px; position: absolute; background: var(--panel); border-radius: 50%; border: 2px solid var(--ink); }
.score-ring div { z-index: 1; display: flex; flex-direction: column; }
.score-ring strong { font: 600 2.5rem var(--mono); }
.score-ring span { color: var(--muted); font-size: .72rem; }
.result-hero h2 { font-size: 2rem; margin: 0 0 8px; }
.result-hero > p:not(.eyebrow) { color: var(--muted); margin: 0 auto 26px; }
.result-hero .xp-summary { display: inline-block; color: var(--ink); background: var(--lime); border: 1px solid var(--ink); padding: 7px 12px; font: 600 .75rem var(--mono); margin-top: -12px; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 540px; margin: auto; }
.ghost-btn { background: transparent; }
.breakdown-row { margin: 0 0 19px; }
.breakdown-label { display: flex; justify-content: space-between; font-size: .72rem; margin-bottom: 7px; }
.breakdown-label strong { font: 600 .7rem var(--mono); }
.mini-track { height: 7px; border: 1px solid var(--ink); background: #e3e6e0; }
.mini-bar { height: 100%; background: var(--cyan); }
.history-line { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 26px; padding-top: 18px; font-size: .75rem; }
.history-line strong { font: 600 1rem var(--mono); }
.review-section { grid-column: 1 / -1; border-top: 2px solid var(--ink); padding-top: 42px; }
.review-head { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 24px; }
.review-head .eyebrow { margin-bottom: 8px; }
.review-head h2 { margin: 0; font-size: clamp(1.5rem, 3vw, 2.3rem); }
.review-filters { display: flex; border: 1px solid var(--ink); }
.review-filter { border: 0; border-right: 1px solid var(--ink); padding: 10px 14px; background: var(--panel); font: 700 .72rem var(--sans); cursor: pointer; }
.review-filter:last-child { border: 0; }
.review-filter.active { background: var(--lime); }
.review-list { display: grid; gap: 14px; }
.review-item { background: var(--panel); border: 1.5px solid var(--ink); padding: 20px; }
.review-item.is-correct { border-left: 6px solid #45b966; }
.review-item.is-wrong { border-left: 6px solid var(--orange); }
.review-item-head { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font: 600 .65rem var(--mono); }
.review-question { margin: 12px 0; font-weight: 700; line-height: 1.55; }
.review-answer { margin: 5px 0; font-size: .8rem; }
.review-answer strong { color: var(--muted); }
.review-explanation { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: #40504b; font-size: .8rem; line-height: 1.55; }
.empty-review { color: var(--muted); text-align: center; border: 1px dashed var(--line); padding: 30px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(16,24,23,.7); }
.modal-card { width: min(460px, 100%); background: var(--panel); border: 2px solid var(--ink); box-shadow: 8px 8px 0 var(--lime); padding: 28px; }
.modal-card .eyebrow { margin-bottom: 8px; }
.modal-card h2 { margin: 0 0 8px; }
.modal-card > p:last-of-type { color: var(--muted); line-height: 1.6; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.danger-btn { min-height: 50px; border: 2px solid var(--ink); background: var(--orange); font: 700 .82rem var(--sans); cursor: pointer; }

button:focus-visible, select:focus-visible, input:focus-visible + span { outline: 3px solid var(--cyan); outline-offset: 3px; }

footer { min-height: 62px; border-top: 1px solid var(--line); padding: 0 clamp(20px, 5vw, 72px); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .65rem; position: relative; z-index: 1; }

@media (max-width: 820px) {
  .setup-screen, .result-screen { grid-template-columns: 1fr; gap: 50px; }
  .setup-screen { padding: 50px 0 70px; }
  h1 { font-size: clamp(3rem, 14vw, 5rem); }
  .setup-card { max-width: 580px; }
  .result-screen { padding: 50px 0 70px; }
  .review-section { grid-column: 1; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .brand { gap: 8px; font-size: .95rem; }
  .brand-mark { padding: 7px; }
  .header-actions { gap: 10px; }
  .header-meta { display: none; }
  .lab17-link { padding: 7px 8px; font-size: .64rem; box-shadow: 2px 2px 0 var(--ink); }
  .screen { width: min(100% - 28px, 1180px); }
  .blueprint-strip { display: grid; grid-template-columns: repeat(3, 1fr); }
  .blueprint-strip span { border-bottom: 1px solid var(--ink); }
  .quiz-header { align-items: start; display: grid; gap: 14px; }
  .quiz-stats { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; text-align: left; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .quiz-stats div { padding: 8px 5px; border-right: 1px solid var(--line); }
  .quiz-stats div:last-child { border: 0; }
  .quiz-stats div:nth-child(4) { display: none; }
  .quiz-stats strong { font-size: .95rem; }
  .question-card { padding: 22px 16px; box-shadow: 5px 5px 0 var(--ink); }
  .shortcut { display: none; }
  .question-actions { justify-content: flex-end; }
  .compact { width: 100%; }
  .result-actions { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .profile-strip { grid-template-columns: 1fr 1fr; }
  .profile-strip div:nth-child(2) { border-right: 0; }
  .profile-strip div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  #startBtn { position: fixed; left: 14px; right: 14px; bottom: 12px; z-index: 4; width: auto; }
  .setup-screen { padding-bottom: 110px; }
  .review-head { align-items: stretch; flex-direction: column; }
  .review-filters { width: 100%; }
  .review-filter { flex: 1; }
  .modal-actions { grid-template-columns: 1fr; }
  footer { flex-direction: column; justify-content: center; gap: 5px; text-align: center; }
}
