:root {
  color-scheme: dark;
  --bg: #090d18;
  --panel: #111827;
  --panel2: #172033;
  --line: #2b3852;
  --text: #f4f7fb;
  --muted: #9ba8bc;
  --accent: #7dd3fc;
  --accentStrong: #38bdf8;
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(56,189,248,.12), transparent 28rem),
    radial-gradient(circle at 92% 92%, rgba(52,211,153,.08), transparent 30rem),
    var(--bg);
}
button, input { font: inherit; }
button {
  border: 0;
  border-radius: 12px;
  padding: .8rem 1.05rem;
  font-weight: 760;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, border-color .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .42; transform: none; }
.primary { background: var(--accentStrong); color: #03111a; }
.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.danger { background: #be123c; color: white; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.ghost.active { color: #111827; background: var(--warn); border-color: var(--warn); }
.large { width: 100%; padding: 1rem 1.2rem; font-size: 1.05rem; }
.screen { display: none; }
.screen.active { display: block; }
#start-screen { min-height: 100vh; padding: 1.2rem; place-items: center; }
#start-screen.active { display: grid; }
.start-card, .score-card {
  width: min(760px, 100%);
  padding: clamp(1.5rem, 4vw, 3rem);
  background: rgba(17,24,39,.95);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.36);
}
.eyebrow {
  color: var(--accent);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .78rem;
  font-weight: 850;
}
h1 { margin: .4rem 0 1.1rem; font-size: clamp(2rem, 6vw, 3.5rem); line-height: 1; }
h2 { line-height: 1.38; }
p { color: var(--muted); line-height: 1.65; }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .8rem;
  margin: 1.5rem 0;
}
.meta-grid div {
  padding: 1rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.meta-grid span { display: block; color: var(--muted); font-size: .8rem; margin-bottom: .25rem; }
.meta-grid strong { font-size: 1.05rem; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .9rem clamp(1rem,3vw,2.2rem);
  background: rgba(9,13,24,.93);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.progress-label { color: var(--muted); margin-top: .2rem; font-size: .92rem; }
.timer {
  min-width: 126px;
  text-align: center;
  padding: .68rem .9rem;
  font-size: 1.28rem;
  font-weight: 880;
  font-variant-numeric: tabular-nums;
  border-radius: 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
}
.timer.warning { color: #111827; background: var(--warn); border-color: var(--warn); }
.timer.critical { color: white; background: #be123c; border-color: #be123c; }
.progress-track { height: 5px; background: #111827; }
#progress-fill { height: 100%; width: 1%; background: var(--accentStrong); transition: width .2s ease; }
.quiz-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 930px);
  gap: 1.2rem;
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.2rem;
}
.sidebar, .question-panel {
  background: rgba(17,24,39,.95);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.sidebar {
  align-self: start;
  position: sticky;
  top: 92px;
  padding: 1rem;
}
.sidebar-heading {
  display: flex;
  justify-content: space-between;
  gap: .7rem;
  color: var(--muted);
  font-size: .8rem;
  margin-bottom: .85rem;
}
.sidebar-heading strong { color: var(--text); }
.palette-wrap { max-height: 60vh; overflow: auto; padding: 3px; }
.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .42rem;
}
.palette button {
  aspect-ratio: 1;
  padding: 0;
  background: var(--panel2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: .76rem;
}
.palette button.answered { color: #052e24; background: var(--good); border-color: var(--good); }
.palette button.flagged { box-shadow: inset 0 -4px 0 var(--warn); }
.palette button.current { outline: 3px solid var(--accent); outline-offset: 2px; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: .73rem;
}
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dot.current { background: var(--accent); }
.dot.answered { background: var(--good); }
.dot.flagged { background: var(--warn); }
.question-panel {
  min-height: 680px;
  padding: clamp(1.15rem,3.6vw,2.3rem);
  display: flex;
  flex-direction: column;
}
.question-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.question-number { color: var(--accent); font-weight: 850; }
#question-text { margin: 1.15rem 0 1.35rem; font-size: clamp(1.18rem,2.3vw,1.62rem); }
.options { display: grid; gap: .8rem; }
.option {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: .8rem;
  align-items: center;
  padding: 1rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  line-height: 1.5;
  transition: border-color .12s ease, background .12s ease, transform .12s ease;
}
.option:hover { border-color: #4d668d; transform: translateY(-1px); }
.option.selected { border-color: var(--accentStrong); background: rgba(56,189,248,.11); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option-letter {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-weight: 850;
  color: var(--muted);
}
.option.selected .option-letter { background: var(--accentStrong); color: #03111a; border-color: var(--accentStrong); }
.actions { display: flex; gap: .7rem; margin-top: auto; padding-top: 2rem; }
.actions #submit-btn { margin-left: auto; }
.results-wrap { max-width: 1040px; margin: 0 auto; padding: 1.3rem; }
.score-card { margin: 1rem auto 2rem; text-align: center; }
.score-value { font-size: clamp(3rem,12vw,6.5rem); font-weight: 900; line-height: 1; color: var(--accent); }
.score-details { color: var(--muted); margin: 1rem 0 1.4rem; }
.review-list { display: grid; gap: 1rem; padding-bottom: 3rem; }
.review-item {
  padding: 1.15rem;
  background: rgba(17,24,39,.95);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.review-item.correct { border-left: 5px solid var(--good); }
.review-item.incorrect { border-left: 5px solid var(--bad); }
.review-item h3 { margin: 0 0 .9rem; font-size: 1rem; line-height: 1.5; }
.review-line { margin: .38rem 0; color: var(--muted); line-height: 1.45; }
.review-line strong { color: var(--text); }
.answer-good { color: var(--good); }
.answer-bad { color: var(--bad); }
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  place-items: center;
  padding: 1rem;
  background: rgba(0,0,0,.72);
}
.modal.open { display: grid; }
.modal-card {
  width: min(440px,100%);
  padding: 1.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1.2rem; }
@media (max-width: 840px) {
  .meta-grid { grid-template-columns: 1fr; }
  .quiz-layout { display: block; padding: .8rem; }
  .sidebar { position: static; margin-bottom: .8rem; }
  .palette-wrap { max-height: 240px; }
  .palette { grid-template-columns: repeat(10,1fr); }
  .question-panel { min-height: calc(100vh - 390px); }
}
@media (max-width: 560px) {
  .palette { grid-template-columns: repeat(6,1fr); }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions #submit-btn { margin-left: 0; grid-column: 1 / -1; }
  .topbar { padding: .75rem .8rem; }
}

/* Full post-submission review */
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin: 1rem 0 1.35rem;
}

.result-stat {
  padding: .9rem;
  text-align: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.result-stat strong {
  display: block;
  font-size: 1.45rem;
  margin-bottom: .15rem;
}

.result-stat span {
  color: var(--muted);
  font-size: .8rem;
}

.review-toolbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  align-items: center;
  margin: 0 0 1rem;
  padding: .8rem;
  background: rgba(9, 13, 24, .95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.review-filter {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: .55rem .75rem;
}

.review-filter.active {
  background: var(--accent-strong);
  color: #03111a;
  border-color: var(--accent-strong);
}

#review-visible-count {
  margin-left: auto;
  color: var(--muted);
  font-size: .82rem;
}

.review-item {
  overflow: visible;
}

.review-item.was-flagged {
  box-shadow: inset 0 0 0 2px rgba(251, 191, 36, .55);
}

.review-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .9rem;
}

.review-question {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  line-height: 1.55;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: normal;
}

.flag-badge {
  flex: 0 0 auto;
  padding: .32rem .55rem;
  border-radius: 999px;
  background: var(--warn);
  color: #181207;
  font-size: .72rem;
  font-weight: 850;
}

.review-options {
  display: grid;
  gap: .55rem;
}

.review-option {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: start;
  gap: .65rem;
  padding: .72rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
}

.review-option.correct-option {
  border-color: var(--good);
  background: rgba(52, 211, 153, .09);
}

.review-option.wrong-option {
  border-color: var(--bad);
  background: rgba(251, 113, 133, .09);
}

.review-option-letter {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-weight: 850;
}

.review-option-text {
  min-width: 0;
  line-height: 1.45;
  white-space: normal;
  overflow: visible;
  word-break: normal;
}

.review-option-labels {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .35rem;
}

.correct-label,
.selected-correct-label,
.selected-wrong-label {
  padding: .25rem .42rem;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 850;
  white-space: nowrap;
}

.correct-label,
.selected-correct-label {
  color: #052e24;
  background: var(--good);
}

.selected-wrong-label {
  color: white;
  background: #be123c;
}

.review-status {
  margin-top: .8rem;
  color: var(--muted);
}

@media (max-width: 680px) {
  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .review-toolbar {
    position: static;
  }

  #review-visible-count {
    width: 100%;
    margin-left: 0;
  }

  .review-option {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .review-option-labels {
    grid-column: 2;
    justify-content: flex-start;
  }
}
