:root {
  --accent: #C8102E;
  --ink: #16191d;
  --muted: #5d6670;
  --line: #d9dde2;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ok: #1f7a4d;
  --warn: #b26a00;
  --bad: #b3261e;
  --sel: #eef3fb;
  --sel-line: #2457a6;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
body.candidate { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.candidate input, body.candidate select { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; font-weight: 500; }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem;
  padding: calc(env(safe-area-inset-top) + .75rem) 1.25rem .75rem; background: var(--card);
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; }
.brand img { height: 32px; }
.exam-title { flex: 1; color: var(--muted); font-size: .95rem; }
.timer { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.timer .lbl { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.timer #clock { font-size: 1.5rem; font-weight: 700; }
.timer.warn #clock { color: var(--warn); }
.timer.crit #clock { color: var(--bad); }

main { max-width: 900px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.narrow { max-width: 640px; margin: 0 auto; }
.row { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }

.field { margin-bottom: 1rem; }
.field label, .pin-box label { display: block; font-weight: 600; margin-bottom: .35rem; }
input, select {
  width: 100%; font: inherit; font-size: 1.1rem; padding: .8rem .9rem; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.consent { display: flex; gap: .75rem; align-items: flex-start; margin: 1.25rem 0 .5rem; line-height: 1.4; }
.consent input { width: 26px; height: 26px; flex: none; margin-top: 2px; }
.rules { line-height: 1.55; padding-left: 1.2rem; }
.rules li { margin-bottom: .4rem; }
.pin-box { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--line); max-width: 260px; }

.btn {
  font: inherit; font-size: 1rem; font-weight: 600; padding: .8rem 1.2rem; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; min-height: 48px;
}
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big { padding: .9rem 1.6rem; font-size: 1.1rem; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--sel-line); }
.btn.flag.on { background: #fff4e0; border-color: var(--warn); color: var(--warn); }

.qhead { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.qnum { font-size: 1.05rem; white-space: nowrap; }
.progress { flex: 1; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.qcard { padding: 1.75rem; }
.stem { font-size: 1.25rem; line-height: 1.5; margin: 0 0 1.5rem; white-space: pre-line; }
.options { display: flex; flex-direction: column; gap: .75rem; }
.opt {
  display: flex; align-items: center; gap: 1rem; text-align: left; font: inherit; font-size: 1.1rem; line-height: 1.4;
  padding: 1rem 1.1rem; min-height: 64px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--ink); cursor: pointer;
}
.opt .letter {
  flex: none; width: 2.1rem; height: 2.1rem; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 700;
}
.opt.sel { border-color: var(--sel-line); background: var(--sel); }
.opt.sel .letter { background: var(--sel-line); border-color: var(--sel-line); color: #fff; }
.qfoot { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; }
.qfoot .btn { flex: 1; }
.savestate { color: var(--muted); font-size: .85rem; text-align: center; margin-top: .75rem; min-height: 1.2em; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: .5rem; margin: 1rem 0; }
.cell {
  font: inherit; font-weight: 600; height: 52px; border-radius: 10px; border: 2px solid var(--line);
  background: #fff; position: relative; cursor: pointer;
}
.cell.answered { background: var(--sel); border-color: var(--sel-line); }
.cell.flagged::after { content: "⚑"; position: absolute; top: 1px; right: 4px; font-size: .75rem; color: var(--warn); }
.cell.current { outline: 3px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; gap: 1rem; align-items: center; color: var(--muted); font-size: .9rem; margin-top: .75rem; flex-wrap: wrap; }
.sw { display: inline-block; width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--line); vertical-align: -3px; margin-right: -.6rem; }
.sw.answered { background: var(--sel); border-color: var(--sel-line); }
.sw.flagged { border-color: var(--warn); }

.overlay { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 20; display: grid; place-items: center; padding: 1rem; }
.sheet { width: min(760px, 100%); max-height: 90vh; overflow: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.5rem); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .9rem 1.4rem; border-radius: 10px; font-weight: 600; z-index: 30;
}
.tick { width: 72px; height: 72px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 2.4rem; display: grid; place-items: center; margin: .5rem auto 1rem; }

@media (max-width: 640px) {
  .exam-title { display: none; }
  .qfoot { flex-wrap: wrap; }
  .qfoot .flag { order: 3; flex-basis: 100%; }
}

/* ---------------- admin ---------------- */
body.admin main { max-width: 1280px; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: .75rem 1rem; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.tile .v { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .k { color: var(--muted); font-size: .85rem; }
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: .9rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f8f9fa; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fb; }
tr.void td { color: var(--muted); text-decoration: line-through; }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: 70vh; }
.pill { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eceff3; }
.pill.easy { background: #e5f4ec; color: var(--ok); }
.pill.medium { background: #fff4e0; color: var(--warn); }
.pill.difficult { background: #fbe9e7; color: var(--bad); }
.pill.approved { background: #e5f4ec; color: var(--ok); }
.pill.reviewed { background: #e8effa; color: var(--sel-line); }
.pill.retired { background: #eee; color: #777; }
.flags { color: var(--bad); font-size: .8rem; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar input, .toolbar select { width: auto; font-size: .95rem; padding: .5rem .7rem; }
.bar { display: inline-block; height: 10px; background: var(--sel-line); border-radius: 2px; vertical-align: middle; }
.bar.key { background: var(--ok); }
.detail { margin-top: 1rem; }
.detail .opt-line { padding: .2rem 0; }
.detail .opt-line.key { color: var(--ok); font-weight: 600; }
.detail .opt-line.wrong { color: var(--bad); }
.cov td { text-align: center; }
textarea { width: 100%; font: inherit; padding: .6rem; border: 1px solid var(--line); border-radius: 8px; min-height: 70px; }
.login { max-width: 380px; margin: 10vh auto; }
.userbar { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; justify-content: flex-end; }
.userbar a.btn { text-decoration: none; display: inline-flex; align-items: center; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef0f3; padding: .1rem .4rem; border-radius: 4px; }
.signed-in { background: #f6faf7; border: 1px solid var(--ok); border-radius: 10px; padding: .75rem 1rem; margin-top: 1.25rem; }
