/* Answer-sheet UI. Light only: used on breaks, often in bright rooms. */
:root {
  color-scheme: light;
  --desk: #eceff3;
  --sheet: #ffffff;
  --ink: #1d222c;
  --ink-2: #4a5160;
  --rule: #d6dbe2;
  --rule-strong: #8a919d;
  --red: #bf1429;
  --red-press: #9a0f20;
  --red-tint: #fdeced;
  --pencil: #2c323d;
  --ok: #18683f;
  --ok-tint: #e5f3ea;
  --info-tint: #eaeef4;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --bar-h: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
  accent-color: var(--red);
  caret-color: var(--red);
  scrollbar-color: var(--rule-strong) transparent;
}
::selection { background: #f6c3c9; color: var(--ink); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; border-radius: 6px; }
[tabindex="-1"]:focus { outline: none; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.bar {
  height: var(--bar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--sheet);
  border-bottom: 1px solid var(--rule);
}
.brand { font-weight: 650; letter-spacing: -0.01em; }
.bar-link, .bar-btn {
  color: var(--ink-2); font: inherit; font-size: 0.9375rem; font-weight: 550;
  text-decoration: none; background: none; border: 0; cursor: pointer;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 8px; margin-right: -8px;
  border-radius: 8px;
}
.bar-link:hover, .bar-btn:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.bar-left { display: flex; align-items: center; gap: 12px; }

/* Sheet */
.wrap { padding: 0; }
.sheet {
  background: var(--sheet);
  max-width: 640px; margin: 0 auto;
  min-height: calc(100dvh - var(--bar-h));
}
@media (min-width: 680px) {
  .wrap { padding: 32px 16px 64px; }
  .sheet {
    min-height: 0;
    border: 1px solid var(--rule); border-radius: 12px;
    box-shadow: 0 1px 2px rgb(20 25 35 / 0.05), 0 12px 32px rgb(20 25 35 / 0.06);
  }
}
.pad { padding: 24px 20px; }
@media (min-width: 680px) { .pad { padding: 32px 36px; } }

h1 { font-size: 1.625rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 6px; font-weight: 700; text-wrap: balance; }
h2 { font-size: 1.125rem; line-height: 1.3; letter-spacing: -0.01em; margin: 0; font-weight: 650; }
p { margin: 0; }
.lede { color: var(--ink-2); max-width: 52ch; }
.stack > * + * { margin-top: 20px; }

/* Fields */
label.field, .field-label { display: block; font-size: 0.875rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  font: inherit; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule-strong); border-radius: 8px;
}
select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a5160' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 20px;
  padding-right: 40px;
}
.input::placeholder { color: #6b7280; }
.input:hover { border-color: var(--ink-2); }
.input:focus-visible { outline: 3px solid var(--red); outline-offset: 1px; border-color: var(--ink); }
.input[aria-invalid="true"] { border-color: var(--red); background: var(--red-tint); }
.field-hint { font-size: 0.875rem; color: var(--ink-2); margin-top: 6px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px;
  font: inherit; font-weight: 650; letter-spacing: -0.005em;
  color: #fff; background: var(--red);
  border: 1px solid var(--red); border-radius: 8px; cursor: pointer;
  transition: background-color 120ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--red-press); border-color: var(--red-press); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { cursor: default; }
.btn.busy { background: var(--red-press); border-color: var(--red-press); }
.btn.block { width: 100%; }
.btn.secondary { color: var(--ink); background: var(--sheet); border-color: var(--rule-strong); }
.btn.secondary:hover { background: #f3f5f8; border-color: var(--ink-2); }
.btn.sm { min-height: 44px; padding: 0 16px; font-size: 0.9375rem; }
.btn.quiet { color: var(--ink-2); background: transparent; border-color: transparent; font-weight: 600; padding: 0 12px; }
.btn.quiet:hover { background: #f3f5f8; color: var(--ink); }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgb(255 255 255 / 0.4); border-top-color: #fff;
  animation: spin 700ms linear infinite;
}
.btn.secondary .spinner { border-color: rgb(29 34 44 / 0.2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Quiz header + progress */
.quiz-head { padding: 24px 20px 8px; }
@media (min-width: 680px) { .quiz-head { padding: 32px 36px 8px; } }
.quiz-head .field-block { margin-top: 20px; }

.questions { padding: 8px 20px 0; }
@media (min-width: 680px) { .questions { padding: 8px 36px 0; } }
div.q { margin: 0; padding: 24px 0; min-width: 0; border-top: 1px solid var(--rule); }
div.q:first-child { margin-top: 12px; }
.sheet { border-top: 2px solid var(--pencil); }
@media (min-width: 680px) { .sheet { border-top-width: 1px; } }
.q:focus { outline: none; }
.q-legend { display: grid; grid-template-columns: 28px 1fr; column-gap: 12px; padding: 0; margin-bottom: 14px; font-size: 1.125rem; line-height: 1.4; font-weight: 600; width: 100%; }
.q-num { font-weight: 700; color: var(--ink-2); font-size: 1rem; line-height: 1.55; }
.q-miss {
  display: none; align-items: center; gap: 8px;
  margin: 0 0 12px 40px; padding: 8px 12px;
  font-size: 0.9375rem; font-weight: 600; color: var(--red-press);
  background: var(--red-tint); border-radius: 8px;
}
.q.missed .q-miss { display: flex; }

.choices { display: grid; gap: 8px; padding-left: 40px; }
@media (max-width: 420px) { .choices { padding-left: 0; } .q-miss { margin-left: 0; } }
.choice {
  position: relative;
  display: grid; grid-template-columns: 32px 1fr; align-items: center; column-gap: 14px;
  min-height: 52px; padding: 10px 14px;
  border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--sheet);
  cursor: pointer;
  transition: border-color 120ms var(--ease), background-color 120ms var(--ease);
}
.choice:hover { border-color: var(--ink-2); background: #f7f8fa; }
.choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choice:has(input:focus-visible) { outline: 3px solid var(--red); outline-offset: 2px; }
.choice:has(input:checked) { border-color: var(--pencil); background: #f3f5f8; }
.bubble {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.5px solid var(--ink-2); color: var(--ink-2);
  font-size: 0.875rem; font-weight: 700;
  transition: background-color 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
}
.choice:has(input:checked) .bubble { background: var(--pencil); border-color: var(--pencil); color: #fff; }
.choice-text { line-height: 1.4; overflow-wrap: anywhere; }
.bubble.erased { animation: erase 520ms var(--ease) both; }
@keyframes erase {
  from { background: var(--pencil); border-color: var(--pencil); color: #fff; }
  to { background: transparent; border-color: var(--ink-2); color: var(--ink-2); }
}
.q.missed .choice { border-color: #e7a3ab; }

/* Sticky submit bar */
.dock {
  position: sticky; bottom: 0; z-index: 5;
  margin-top: 24px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--sheet); border-top: 1px solid var(--rule);
}
@media (min-width: 680px) { .dock { padding-left: 36px; padding-right: 36px; border-radius: 0 0 12px 12px; } }
.progress { min-width: 0; }
.progress-text { font-size: 0.875rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; white-space: nowrap; }
.ticks { display: flex; gap: 4px; }
.tick { height: 6px; width: 28px; border-radius: 3px; background: var(--rule); transition: background-color 160ms var(--ease); }
.tick.on { background: var(--pencil); }

/* States: done, empty, error */
.state { text-align: center; padding: 56px 24px; }
@media (min-width: 680px) { .state { padding: 72px 48px; } }
.state .lede { margin: 6px auto 0; }
.state .btn { margin-top: 24px; }
.badge-circle {
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 20px;
  display: grid; place-items: center;
  background: var(--ok-tint); color: var(--ok);
}
.badge-circle .icon { width: 30px; height: 30px; stroke-width: 2; }
.badge-circle.neutral { background: var(--info-tint); color: var(--ink-2); }
.badge-circle.warn { background: var(--red-tint); color: var(--red-press); }
.badge-circle.pop { animation: pop 420ms var(--ease) both; }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Skeleton */
.skel { border-radius: 8px; background: linear-gradient(90deg, #edf0f4 25%, #f6f8fa 50%, #edf0f4 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-line { height: 16px; margin-bottom: 12px; }
.skel-box { height: 52px; margin-bottom: 8px; }

/* Toasts */
.toasts {
  position: fixed; z-index: 50; top: calc(var(--bar-h) + 12px); left: 50%; transform: translateX(-50%);
  width: min(calc(100vw - 24px), 440px);
  display: grid; gap: 8px; pointer-events: none;
}
@media (max-width: 679px) {
  .toasts { top: auto; bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { animation-name: toast-up; }
}
@keyframes toast-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 8px 12px 14px;
  background: var(--sheet); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 2px 6px rgb(20 25 35 / 0.08), 0 12px 28px rgb(20 25 35 / 0.12);
  animation: toast-in 220ms var(--ease) both;
}
.toast.leaving { opacity: 0; transform: translateY(-6px); transition: opacity 180ms, transform 180ms; }
.toast .icon { margin-top: 2px; }
.toast-success .icon { color: var(--ok); }
.toast-error .icon { color: var(--red); }
.toast-info .icon { color: var(--ink-2); }
.toast-text { flex: 1; padding-top: 1px; font-weight: 550; }
.toast-x { flex: none; width: 36px; height: 36px; margin-top: -6px; display: grid; place-items: center; background: none; border: 0; color: var(--ink-2); border-radius: 8px; cursor: pointer; }
.toast-x:hover { background: #f3f5f8; color: var(--ink); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* Admin */
.section { --gutter: 20px; padding: 28px var(--gutter); border-top: 1px solid var(--rule); }
.section:first-of-type { border-top: 0; }
@media (min-width: 680px) { .section { --gutter: 36px; padding: 32px var(--gutter); } }
.section .dock { margin: 24px calc(-1 * var(--gutter)) -28px; }
@media (min-width: 680px) { .section .dock { margin-bottom: -32px; } }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.qrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-top: 1px solid var(--rule); min-height: 64px; }
.qrow:first-child { border-top: 0; }
.qrow-title { font-weight: 600; overflow-wrap: anywhere; }
.qrow-meta { font-size: 0.875rem; color: var(--ink-2); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 0.875rem; font-weight: 650; background: var(--ok-tint); color: var(--ok); white-space: nowrap; }
.pill .icon { width: 16px; height: 16px; stroke-width: 2.25; }
.empty-note { color: var(--ink-2); padding: 8px 0; }

.qb { border: 0; border-top: 1px solid var(--rule); padding: 20px 0 8px; margin: 0; min-width: 0; }
.qb-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.qb-title { font-weight: 650; }
.cb { display: grid; grid-template-columns: 32px 1fr; align-items: center; gap: 12px; margin-top: 8px; }
.cb-pick { position: relative; width: 44px; height: 44px; margin: -6px; display: grid; place-items: center; cursor: pointer; }
.cb-pick input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.cb-pick:has(input:focus-visible) { outline: 3px solid var(--red); border-radius: 50%; }
.cb-pick input:checked + .bubble { background: var(--pencil); border-color: var(--pencil); color: #fff; }
.cb-pick:hover .bubble { border-color: var(--ink); }

.add-row { display: flex; gap: 12px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
