:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --ink: #141413;
  --muted: #6f6e69;
  --line: #e7e5df;
  --line-strong: #cfccc4;
  --green: #1f8f55;
  --green-soft: #e6f4ec;
  --red: #b3372f;
  --red-soft: #fbeceb;
  --amber: #9a6a00;
  --radius: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.brand { font-weight: 650; letter-spacing: 0.22em; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2c2c2a; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.tiny { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }

.field {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 12px;
}
.field:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(20, 20, 19, 0.08); }

/* ---------- centered screens (gate, done, messages) ---------- */
.center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 40px 36px;
}
.card h1 { font-size: 24px; line-height: 1.25; margin: 18px 0 6px; font-weight: 600; letter-spacing: -0.01em; }
.card .meta { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.card .instructions { white-space: pre-wrap; font-size: 14.5px; border-top: 1px solid var(--line); padding-top: 16px; margin: 0 0 22px; }
.card label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.card .code-input { text-transform: uppercase; letter-spacing: 0.14em; font-size: 18px; text-align: center; padding: 13px; }
.card .btn { width: 100%; margin-top: 14px; padding: 12px; }
.card .error { font-size: 14px; margin: 12px 0 0; min-height: 1.4em; }

/* ---------- exam ---------- */
.exam-mode, .exam-mode * { user-select: none; -webkit-user-select: none; }
.exam-mode textarea { user-select: text; -webkit-user-select: text; }

.exam { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .title { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.topbar .save { font-size: 13px; color: var(--muted); }
.topbar .save.bad { color: var(--red); font-weight: 500; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; }
.timer.low { color: var(--red); border-color: var(--red); background: var(--red-soft); }

.sidebar { border-right: 1px solid var(--line); background: var(--surface); padding: 20px 18px; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar h2 { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.nav-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.nav-item {
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.nav-item:hover { border-color: var(--ink); }
.nav-item.answered { background: var(--green); border-color: var(--green); color: #fff; }
.nav-item.current { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
.sidebar .progress { font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.sidebar .legend { font-size: 12px; color: var(--muted); display: flex; gap: 14px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; border: 1px solid var(--line-strong); margin-right: 5px; vertical-align: -1px; }
.legend i.g { background: var(--green); border-color: var(--green); }
.sidebar .spacer { flex: 1; min-height: 20px; }
.sidebar .btn { width: 100%; }

.stage { overflow-y: auto; padding: 48px 32px 64px; }
.item { max-width: 720px; margin: 0 auto; }
.item .kicker-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.item .kicker-row .kicker { margin: 0; }
.item .kicker {font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0 0 14px; }
.item .prompt { font-size: 21px; line-height: 1.45; font-weight: 500; margin: 0 0 8px; white-space: pre-wrap; letter-spacing: -0.005em; }
.item .prompt:focus { outline: none; }
.item .hint { font-size: 14px; color: var(--muted); margin: 0 0 26px; }

.letters { display: flex; flex-wrap: wrap; gap: 12px; }
.letter {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-weight: 600;
  font-size: 17px;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
}
.letter:hover, .letter:focus-visible { border-color: var(--ink); transform: translateY(-1px); }
.letter.selected { background: var(--ink); border-color: var(--ink); color: #fff; }
.letter .rank {
  position: absolute; top: -8px; right: -8px;
  min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px; background: var(--green); color: #fff;
  font-size: 12px; line-height: 22px; font-weight: 600;
}
.reveal {
  margin-top: 20px;
  min-height: 132px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px 20px;
  font-size: 17px;
  white-space: pre-wrap;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.reveal.empty { color: var(--muted); font-size: 14px; align-items: center; justify-content: center; }
.reveal.empty::before { content: "Hover over a letter to read that option"; }
.reveal .tag { font-weight: 700; flex: none; }
.reveal.live { border-style: solid; border-color: var(--ink); background: var(--surface); }
.choice-line { margin-top: 14px; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 12px; min-height: 30px; }
.choice-line strong { color: var(--ink); font-weight: 600; }

/* screen-reader mode: ordinary, always-visible controls */
.plain-options { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.plain-options legend { position: absolute; left: -9999px; }
.plain-option {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); padding: 12px 14px; text-align: left; width: 100%;
}
.plain-option input { margin-top: 5px; width: 16px; height: 16px; accent-color: var(--ink); }
.plain-option.selected { border-color: var(--ink); }
.plain-option .rank-label { margin-left: auto; color: var(--green); font-weight: 600; font-size: 14px; white-space: nowrap; }

.answer-box { min-height: 240px; resize: vertical; line-height: 1.6; }
.count { font-size: 13px; color: var(--muted); margin-top: 8px; text-align: right; }

.pager { display: flex; justify-content: space-between; margin-top: 40px; }

.confirm { max-width: 520px; margin: 40px auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px; }
.confirm h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.confirm .warn { color: var(--amber); font-weight: 500; }
.confirm .row { display: flex; gap: 10px; margin-top: 24px; }

#blackout {
  position: fixed; inset: 0; z-index: 9999; background: #000; color: #8a8a8a;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  font-size: 15px; text-align: center; padding: 24px;
}
#blackout button { background: transparent; color: #d0d0d0; border: 1px solid #555; border-radius: 8px; padding: 10px 18px; }
#blackout button:hover { border-color: #d0d0d0; }

@media (max-width: 760px) {
  .exam { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-grid { grid-template-columns: repeat(10, 1fr); }
  .stage { padding: 28px 16px 48px; }
}
@media print { body { display: none !important; } }

/* ---------- instructor ---------- */
.admin { max-width: 1080px; margin: 0 auto; padding: 28px 24px 80px; }
.admin header { display: flex; align-items: center; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.admin header .grow { flex: 1; }
.admin h1 { font-size: 26px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.admin h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; margin-bottom: 20px; }
.panel > p.muted { margin: 0 0 16px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.grid2 label, .stack label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.stack { margin-top: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; align-items: center; }
.linkbox { display: flex; gap: 10px; }
.linkbox input { font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .field { padding: 5px 8px; width: 92px; font-size: 14px; }
td code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #efeee9; color: var(--muted); white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: #fbf1d9; color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.notice { border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-top: 12px; background: #efeee9; }
.notice.bad { background: var(--red-soft); color: var(--red); }
.notice.good { background: var(--green-soft); color: var(--green); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
details summary { cursor: pointer; font-size: 14px; font-weight: 500; }
ol.items { font-size: 14px; padding-left: 22px; }
ol.items li { margin-bottom: 8px; }
a.plain { color: inherit; }
.exam-row { cursor: pointer; }
.exam-row:hover td { background: #f6f5f1; }
