:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #111a2e;
  --ink-soft: #475467;
  --muted: #7a8699;
  --line: #e2e7f0;
  --line-strong: #cdd5e3;
  --brand: #2b59e0;
  --brand-dark: #1e40c0;
  --brand-tint: #eef3ff;
  --ok: #15884a;
  --ok-tint: #e9faf0;
  --warn: #b5580a;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* wins over the display rules below */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.55rem; letter-spacing: -0.02em; margin: 0 0 .3em; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.lead { color: var(--ink-soft); font-size: 1.02rem; }
.error { color: var(--danger); font-weight: 500; }

/* ---------- Centered panels (gate / code / instructions / done) ---------- */
#screen-gate, #screen-code, #screen-instructions, #screen-done {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 620px;
  padding: 34px 38px;
}
.panel.narrow { max-width: 460px; }
.panel.center { text-align: center; }

.brand-mark {
  width: 52px; height: 52px;
  margin: 0 auto 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), #5b7bf0);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .05em;
  box-shadow: 0 6px 16px rgba(43,89,224,.35);
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600;
  padding: 11px 22px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .02s;
}
.btn:hover { background: #f6f8fc; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; }
.btn-lg { padding: 13px 28px; font-size: 1.02rem; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Code entry ---------- */
#code-form { margin-top: 22px; }
#code-input {
  font-size: 1.35rem; font-weight: 600;
  letter-spacing: 4px; text-transform: uppercase; text-align: center;
  padding: 13px 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  width: 100%;
  display: block;
  margin: 0 auto 14px;
  background: #fbfcfe;
}
#code-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-tint); }

/* ---------- Instructions ---------- */
.greeting { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.avatar {
  width: 48px; height: 48px; flex: none;
  border-radius: 50%;
  background: var(--brand-tint); color: var(--brand);
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.2rem;
}
.exam-info-box {
  background: var(--brand-tint);
  border: 1px solid #d7e2ff;
  border-radius: 12px;
  padding: 14px 18px;
  margin: 18px 0;
}
.exam-info-box p { margin: 0; }
.instructions { list-style: none; padding: 0; margin: 10px 0 22px; }
.instructions li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
}
.instructions li:first-child { border-top: none; }
.instructions .ico { flex: none; font-size: 1.05rem; line-height: 1.5; }
.instructions strong { color: var(--ink); }

/* ---------- Exam header ---------- */
#screen-exam { min-height: 100%; }
#exam-header {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  background: #0e1626;
  color: #fff;
  padding: 12px 26px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.hdr-left { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.hdr-left #exam-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-dot { width: 9px; height: 9px; border-radius: 50%; background: #34d17e; flex: none; box-shadow: 0 0 0 3px rgba(52,209,126,.25); }
.hdr-center { justify-self: center; text-align: center; min-width: 220px; }
#progress-text { font-size: .82rem; color: #aeb8cc; margin-bottom: 5px; }
#progress-text #answered-count { color: #fff; font-weight: 700; }
#progress-bar { height: 6px; border-radius: 99px; background: rgba(255,255,255,.14); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #34d17e, #67e39a); border-radius: 99px; transition: width .25s ease; }
.hdr-right { justify-self: end; display: flex; align-items: center; gap: 16px; }
#save-status { color: #8b98b0; font-size: .82rem; white-space: nowrap; }
#timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.3rem; font-weight: 700; letter-spacing: .02em;
  padding: 4px 12px; border-radius: 9px;
  background: rgba(255,255,255,.08);
}
#timer.low { color: #ffd27a; background: rgba(255,171,0,.14); }
#timer.critical { color: #ff9a8f; background: rgba(240,68,56,.18); }

/* ---------- Exam body: questions + sidebar ---------- */
#exam-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 26px 60px;
  align-items: start;
}
@media (max-width: 1040px) {
  #exam-body { grid-template-columns: 1fr; }
  #exam-sidebar { order: -1; position: static !important; }
  #nav-palette { max-height: 120px; overflow: auto; }
}

/* ---------- Question cards ---------- */
.question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 16px;
  scroll-margin-top: 84px;
}
.question.is-answered { border-color: #bfe7cf; }
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.qnum {
  flex: none;
  font-size: .8rem; font-weight: 700;
  color: var(--brand);
  background: var(--brand-tint);
  padding: 3px 10px; border-radius: 99px;
}
.qcheck { margin-left: auto; color: var(--ok); font-weight: 700; font-size: .82rem; display: flex; align-items: center; gap: 4px; }
.qtext { font-size: 1.05rem; font-weight: 600; line-height: 1.5; }

/* MCQ options */
.option {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  margin-top: 10px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.option:hover { border-color: var(--line-strong); background: #f8fafd; }
.option:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
.option input { accent-color: var(--brand); width: 18px; height: 18px; flex: none; margin: 0; }
.opt-letter { font-weight: 700; color: var(--ink-soft); flex: none; }
.option:has(input:checked) .opt-letter { color: var(--brand); }

/* text / prompt answers */
textarea, input.short-answer {
  width: 100%; font: inherit; margin-top: 8px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fbfcfe;
}
textarea:focus, input.short-answer:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-tint); background: #fff; }
textarea { min-height: 190px; resize: vertical; line-height: 1.55; }
.char-count { text-align: right; margin-top: 6px; font-size: .82rem; }

/* ---------- Sidebar ---------- */
#exam-sidebar { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px; }
.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.sidebar-card h3 { margin: 0 0 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; font-size: .72rem; }
#nav-palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.nav-btn {
  aspect-ratio: 1; padding: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: #fff; color: var(--ink-soft);
  font: inherit; font-weight: 600; font-size: .82rem;
  cursor: pointer;
  transition: border-color .1s, background .1s;
}
.nav-btn:hover { border-color: var(--brand); }
.nav-btn.answered { background: var(--ok); border-color: var(--ok); color: #fff; }
.nav-btn.current { box-shadow: 0 0 0 3px var(--brand-tint); border-color: var(--brand); }
.palette-legend { display: flex; gap: 16px; margin-top: 14px; font-size: .78rem; color: var(--muted); }
.palette-legend span { display: flex; align-items: center; gap: 6px; }
.lg { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.lg-answered { background: var(--ok); }
.lg-unanswered { background: #fff; border: 1.5px solid var(--line-strong); }
#submit-summary { margin: 0 0 12px; font-size: .88rem; }

/* ---------- Done / warning ---------- */
.done-check {
  width: 64px; height: 64px; margin: 0 auto 18px;
  border-radius: 50%; background: var(--ok-tint); color: var(--ok);
  display: grid; place-items: center; font-size: 2rem; font-weight: 700;
}
.warn-icon {
  width: 60px; height: 60px; margin: 0 auto 18px;
  border-radius: 50%; background: rgba(240,68,56,.12); color: var(--danger);
  display: grid; place-items: center; font-size: 2rem; font-weight: 800;
}
#focus-warning {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(14,22,38,.94);
  display: grid; place-items: center; padding: 20px;
}
#focus-warning[hidden] { display: none; }
