/* ------------------------------------------------------------------
   Design language: the OMR answer sheet. Numbered bubbles, pencil-ink
   fills, registration-mark squares, a depleting timer rail.
   ------------------------------------------------------------------ */

:root {
  --ink:        #15161b;
  --paper:      #ffffff;
  --sheet:      #eceef3;
  --line:       #d9dce4;
  --muted:      #6a7080;

  --pen:        #3a2bd6;
  --pen-dark:   #2a1eab;
  --pen-soft:   #edebff;

  --right:      #157f4a;
  --right-soft: #e3f4ea;
  --wrong:      #c92a3c;
  --wrong-soft: #fce9eb;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --shadow: 0 1px 2px rgba(21, 22, 27, .06), 0 6px 16px -10px rgba(21, 22, 27, .28);
  --bar-h: 68px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--sheet);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior-y: none; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.0625rem; }
p  { margin: 0 0 .75rem; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

:focus-visible {
  outline: 2px solid var(--pen);
  outline-offset: 2px;
  border-radius: 4px;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--sheet);
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------- top bar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: .625rem 1rem .5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 56px;
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar .eyebrow { font-size: .75rem; color: var(--muted); }
.topbar h1 {
  font-size: 1.0625rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: .01em;
}
.clock.low { color: var(--wrong); }

.rail {
  position: sticky;
  top: 56px;
  z-index: 20;
  height: 3px;
  background: var(--line);
}
.rail span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--pen);
  transform-origin: left;
  transition: transform 1s linear;
}
.rail span.low { background: var(--wrong); }

/* ------------------------------------------------------------- bits --- */
.wrap { padding: 1rem; }
.stack > * + * { margin-top: .75rem; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 46px;
  padding: 0 1.125rem;
  border-radius: var(--r-md);
  background: var(--pen);
  color: #fff;
  font-weight: 600;
  transition: background .15s ease;
}
.btn:active { background: var(--pen-dark); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.wide { width: 100%; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.ghost:active { background: var(--sheet); }
.btn.quiet { background: var(--pen-soft); color: var(--pen-dark); }
.btn.sm { min-height: 38px; padding: 0 .875rem; font-size: .875rem; }

.link { color: var(--pen-dark); font-weight: 600; text-decoration: none; }

.muted { color: var(--muted); }
.tiny  { font-size: .8125rem; }
.nums  { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

.field { display: block; margin-bottom: .875rem; }
.field span { display: block; font-size: .8125rem; color: var(--muted); margin-bottom: .3125rem; }
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 0 .875rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--pen);
  box-shadow: 0 0 0 3px var(--pen-soft);
}

.notice {
  padding: .75rem .875rem;
  border-radius: var(--r-md);
  background: var(--wrong-soft);
  color: var(--wrong);
  font-size: .875rem;
}
.notice.ok { background: var(--right-soft); color: var(--right); }

.empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
}

/* ------------------------------------------------------- quiz cards --- */
.quiz-card { padding: 1rem; }
.quiz-card .cat {
  display: inline-block;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--pen-dark);
  background: var(--pen-soft);
  padding: .1875rem .5rem;
  border-radius: 999px;
  margin-bottom: .5rem;
}
.quiz-card h2 { margin-bottom: .5rem; }
.quiz-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  font-size: .8125rem;
  color: var(--muted);
  margin-bottom: .875rem;
}
.quiz-card .meta b { color: var(--ink); font-weight: 600; }
.quiz-card .foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

/* -------------------------------------------------------- questions --- */
.qhead {
  display: flex;
  align-items: baseline;
  gap: .625rem;
  margin-bottom: .75rem;
}
.qnum {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  border-radius: 6px;
  font-size: .8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transform: translateY(2px);
}
.qbody {
  font-size: 1.0625rem;
  line-height: 1.45;
  font-weight: 500;
}

.opts { list-style: none; margin: 1rem 0 0; padding: 0; }
.opts li + li { margin-top: .625rem; }

.opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .75rem;
  text-align: left;
  padding: .75rem .875rem;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  min-height: 56px;
  transition: border-color .12s ease, background .12s ease;
}
.opt .bubble {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: .8125rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.opt.on { border-color: var(--pen); background: var(--pen-soft); }
.opt.on .bubble { background: var(--pen); border-color: var(--pen); color: #fff; }

.opt.correct { border-color: var(--right); background: var(--right-soft); }
.opt.correct .bubble { background: var(--right); border-color: var(--right); color: #fff; }
.opt.picked-wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.opt.picked-wrong .bubble { background: var(--wrong); border-color: var(--wrong); color: #fff; }

/* ------------------------------------------------------ bottom bar --- */
.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: .625rem 1rem calc(.625rem + env(safe-area-inset-bottom));
}
.bottombar .inner {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .625rem;
}
.bottombar .btn { flex: 1; }

.tabbar { display: flex; }
.tabbar a {
  flex: 1;
  text-align: center;
  padding: .375rem 0;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a.on { color: var(--pen-dark); }
.tabbar .ico { display: block; font-size: 1.125rem; line-height: 1.4; }

/* ------------------------------------------------------------ grid --- */
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: .5rem;
}
.pill {
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--muted);
}
.pill.correct { background: var(--right); border-color: var(--right); color: #fff; }
.pill.wrong   { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.pill.answered { border-color: var(--pen); color: var(--pen-dark); background: var(--pen-soft); }
.pill.here { box-shadow: 0 0 0 3px var(--pen-soft); border-color: var(--pen); }

/* ----------------------------------------------------- result hero --- */
.hero {
  padding: 1.5rem 1rem 1.25rem;
  text-align: center;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.hero .rank {
  font-size: 3.5rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.hero .of { font-size: 1.25rem; color: var(--muted); font-weight: 600; }
.hero .cap { font-size: .8125rem; color: var(--muted); margin-top: .375rem; }

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}
.scores div { padding: .875rem .5rem; text-align: center; }
.scores div + div { border-left: 1px solid var(--line); }
.scores b {
  display: block;
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.scores span { font-size: .75rem; color: var(--muted); }
.scores .c b { color: var(--right); }
.scores .w b { color: var(--wrong); }

/* --------------------------------------------------------- review --- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(21, 22, 27, .45);
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(12px); } }

.sheet .grab {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto .875rem;
}
.explain {
  margin-top: .875rem;
  padding: .75rem .875rem;
  background: var(--sheet);
  border-radius: var(--r-md);
  font-size: .875rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 16px);
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: #fff;
  padding: .625rem 1rem;
  border-radius: 999px;
  font-size: .875rem;
  box-shadow: var(--shadow);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .875rem 1rem;
}
.row + .row { border-top: 1px solid var(--line); }

textarea {
  width: 100%;
  min-height: 190px;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .8125rem;
  line-height: 1.5;
  resize: vertical;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
