:root {
  --navy: #0c2340;
  --navy-soft: #e8eef6;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-bright: #14b8a6;
  --teal-soft: #f0fdfa;
  --ink: #142033;
  --muted: #44566a;
  --line: #d5e0ea;
  --bg: #f4f7fb;
  --card: #ffffff;
  --danger: #9f1239;
  --danger-soft: #fff1f2;
  --warn: #9a3412;
  --warn-soft: #fff7ed;
  --shadow: 0 12px 40px rgba(12, 35, 64, 0.07);
  --radius: 16px;
  --max: 1080px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
}

html.has-session #welcome-screen {
  display: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3.5rem;
  z-index: 50;
  background: #ffffff;
  color: var(--navy);
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  font-weight: 700;
}

.skip-link:focus {
  top: 0.75rem;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--teal-bright);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--navy);
  color: #ffffff;
  box-shadow: 0 1px 0 rgba(20, 184, 166, 0.85);
}

.topbar-inner,
main,
.site-footer {
  width: min(var(--max), calc(100% - 1.5rem));
  margin-left: auto;
  margin-right: auto;
}

.topbar-inner {
  min-height: 4.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.mark {
  width: 2.6rem;
  height: 2.6rem;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--teal-bright);
  color: #042f2e;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.brand-kicker,
.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-kicker {
  color: #99f6e4;
}

.brand-title {
  margin: 0;
  color: #ffffff;
  font-weight: 700;
}

.exam-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.student-chip {
  margin: 0;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d7e4f2;
  font-size: 0.95rem;
}

.timer {
  margin: 0;
  min-width: 5.6rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
}

.timer.is-warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.timer.is-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

main {
  padding: 1.5rem 0 2.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2vw, 1.6rem);
}

.welcome {
  max-width: 760px;
  margin: 0 auto;
  border-top: 4px solid var(--teal);
}

.welcome h1,
.results-hero h1,
.question-card h1 {
  margin: 0.3rem 0 0.75rem;
  color: var(--navy);
  font-size: clamp(1.45rem, 2.7vw, 1.9rem);
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}

.stat {
  padding: 0.9rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7fafc;
  text-align: center;
}

.stat strong {
  display: block;
  color: var(--navy);
  font-size: 1.45rem;
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

.instructions {
  margin: 0 0 1.25rem;
  padding-left: 1.25rem;
}

.instructions li {
  margin: 0.4rem 0;
  padding-left: 0.2rem;
}

.instructions li::marker {
  color: var(--teal);
  font-weight: 700;
}

.field label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--navy);
  font-weight: 700;
}

.req {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

input[type="text"][aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  min-height: 1.3rem;
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-size: 0.92rem;
}

button {
  min-height: 44px;
  padding: 0.65rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--navy);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: #9fb0c3;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

button.primary:hover {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

button.submit {
  background: var(--navy);
  border-color: var(--navy);
  color: #ffffff;
}

button.submit:hover {
  background: #16365c;
}

#start-btn {
  width: 100%;
  margin-top: 0.35rem;
}

.exam-layout {
  display: grid;
  gap: 1rem;
}

.progress-labels,
.legend {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.progress-labels {
  margin-bottom: 0.4rem;
  color: var(--navy);
  font-weight: 700;
}

.progress-track {
  height: 0.55rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e6eef3;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--teal-bright));
  transition: width 0.2s ease;
}

.question-card {
  scroll-margin-top: 5.5rem;
}

.topic {
  margin: 1rem 0 0.25rem;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.answer-set {
  margin: 0;
  padding: 0;
  border: 0;
}

.options {
  display: grid;
  gap: 0.65rem;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.85rem 0.95rem;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.option:hover {
  border-color: #8ecfc8;
}

.option:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.option:has(input:focus-visible) {
  outline: 3px solid var(--teal-bright);
  outline-offset: 2px;
}

.option input {
  margin-top: 0.3rem;
  accent-color: var(--teal-dark);
}

.letter {
  flex: 0 0 auto;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--navy-soft);
  color: var(--navy);
  font-size: 0.85rem;
  font-weight: 800;
}

.option:has(input:checked) .letter {
  background: var(--teal);
  color: #ffffff;
}

.option-text {
  padding-top: 0.12rem;
}

.exam-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.1rem;
}

#submit-btn {
  grid-column: 1 / -1;
}

.key-hint,
.scoring-note,
.print-note,
.nav-summary,
.site-footer p {
  color: var(--muted);
  font-size: 0.88rem;
}

.key-hint {
  margin: 0.9rem 0 0.2rem;
}

.scoring-note {
  margin: 0.2rem 0 0;
}

.navigator-card h2,
.review h2 {
  margin: 0 0 0.8rem;
  color: var(--navy);
  font-size: 1.15rem;
}

.navigator {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.4rem;
}

.nav-btn {
  min-height: 40px;
  padding: 0.2rem;
  font-variant-numeric: tabular-nums;
}

.nav-btn.is-answered:not(.is-current) {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.nav-btn.is-current {
  border-color: var(--navy);
  background: var(--navy);
  color: #ffffff;
}

.legend {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.7rem 1rem;
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 0.85rem;
  height: 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
}

.swatch.is-current {
  border-color: var(--navy);
  background: var(--navy);
}

.swatch.is-answered {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.nav-summary {
  margin: 0.7rem 0 0;
}

.results-hero h1 {
  margin-bottom: 0.4rem;
}

.banner {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 700;
}

.results-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1.25rem;
  align-items: center;
}

.score-ring {
  --score: 0;
  --ring: var(--teal);
  width: 9.5rem;
  height: 9.5rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--ring) calc(var(--score) * 1%), #e6eef3 0);
}

.ring-inner {
  width: 7.15rem;
  height: 7.15rem;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background: #ffffff;
  text-align: center;
}

.ring-inner strong {
  color: var(--navy);
  font-size: 1.45rem;
}

.ring-inner span {
  color: var(--muted);
  font-size: 0.78rem;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
  margin: 0;
}

.result-stats div {
  min-width: 0;
}

.result-stats dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.result-stats dd {
  margin: 0.15rem 0 0;
  color: var(--navy);
  font-size: 1.05rem;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.95rem;
}

.badge.pass {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.badge.fail {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.open {
  background: #eef2f6;
  color: var(--muted);
}

.tallies {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1.2rem 0 0;
  padding: 0;
  list-style: none;
}

.tally {
  padding: 0.8rem;
  border-radius: 12px;
  background: #f7fafc;
  text-align: center;
}

.tally strong {
  display: block;
  color: var(--navy);
  font-size: 1.4rem;
}

.tally span {
  color: var(--muted);
  font-size: 0.85rem;
}

.tally.is-correct {
  background: var(--teal-soft);
}

.tally.is-incorrect {
  background: var(--danger-soft);
}

.results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.print-note {
  margin: 0.7rem 0 0;
}

.review {
  margin-top: 1rem;
}

.review-item {
  margin-top: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 12px;
  background: #ffffff;
}

.review-item.is-correct {
  border-left-color: var(--teal);
}

.review-item.is-incorrect {
  border-left-color: var(--danger);
}

.review-item.is-unanswered {
  border-left-color: #94a3b8;
}

.review-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.7rem;
  margin-bottom: 0.35rem;
}

.review-head .topic {
  margin: 0;
}

.your-answer,
.correct-line {
  margin: 0.15rem 0;
}

.correct-line {
  color: var(--teal-dark);
  font-weight: 700;
}

.q-num {
  color: var(--navy);
  font-weight: 800;
}

.review-item h3 {
  margin: 0 0 0.75rem;
  color: var(--navy);
  font-size: 1.05rem;
}

.review-options {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.review-option {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 0.7rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.review-option.is-correct {
  border-color: #99f6e4;
  background: var(--teal-soft);
}

.review-option.is-wrong {
  border-color: #fecdd3;
  background: var(--danger-soft);
}

.tag {
  margin-left: auto;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #ffffff;
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 800;
}

.explanation {
  margin: 0.75rem 0 0;
  color: var(--ink);
}

.explanation strong {
  color: var(--teal-dark);
}

.site-footer {
  padding-bottom: 2rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 40;
  max-width: calc(100% - 2rem);
  transform: translateX(-50%);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: var(--navy);
  color: #ffffff;
  box-shadow: var(--shadow);
}

dialog {
  width: min(32rem, calc(100vw - 2rem));
  padding: 1.35rem;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 35, 64, 0.55);
}

dialog h2 {
  margin: 0 0 0.5rem;
  color: var(--navy);
}

dialog p {
  margin: 0;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.2rem;
}

.noscript-card {
  max-width: 760px;
  margin: 0 auto 1rem;
}

@media (min-width: 720px) {
  .exam-actions {
    display: flex;
  }

  #submit-btn {
    margin-left: auto;
  }
}

@media (min-width: 900px) {
  .exam-layout {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }

  .navigator-card {
    position: sticky;
    top: 5.4rem;
    max-height: calc(100vh - 6.6rem);
    overflow: auto;
  }
}

@media (max-width: 720px) {
  .topbar-inner {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 0.8rem 0;
  }

  .student-chip {
    max-width: 9rem;
  }

  .stats,
  .tallies,
  .results-grid,
  .result-stats {
    grid-template-columns: 1fr;
  }

  .navigator {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .score-ring {
    margin-inline: auto;
  }
}

@media (max-width: 420px) {
  .navigator {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar {
    transition: none;
  }

  html {
    scroll-behavior: auto;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #ffffff;
  }

  .topbar,
  .no-print,
  .toast,
  dialog {
    display: none !important;
  }

  main,
  .site-footer {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .card,
  .review-item {
    box-shadow: none;
  }

  .review-item,
  .results-hero {
    break-inside: avoid;
  }

  .review-item {
    break-inside: auto;
    page-break-inside: auto;
  }

  .review-option,
  .result-stats div,
  .tally {
    break-inside: avoid;
  }
}
