@font-face { font-family: 'Plex Cond'; src: url('/fonts/plex-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Plex Cond'; src: url('/fonts/plex-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Source Serif'; src: url('/fonts/serif-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Source Serif'; src: url('/fonts/serif-400i.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Source Serif'; src: url('/fonts/serif-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Pen'; src: url('/fonts/pen-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }

/* An answer sheet: form paper, drop-out green ink, pencil, and a red grading pen. */
:root {
  --sheet: #fdfdfb;
  --form: #002868;        /* drop-out ink in Texas flag blue, text weight */
  --form-line: #8fa2c9;   /* drop-out ink, rules and bubbles */
  --form-tint: #e9eef8;   /* row banding */
  --graphite: #26282b;
  --graphite-soft: #55595e;
  --pen: #d42a1e;

  --serif: 'Source Serif', Georgia, serif;
  --label: 'Plex Cond', 'Arial Narrow', sans-serif;
  --hand: 'Pen', 'Comic Sans MS', cursive;

  /* type scale, 1.25 ratio from 17px */
  --t-xs: 12px;
  --t-sm: 14px;
  --t-md: 17px;
  --t-lg: 21px;
  --t-xl: clamp(26px, 3.4vw, 33px);
  --t-2xl: clamp(38px, 6.2vw, 64px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  color: var(--graphite);
  font: 400 var(--t-md)/1.55 var(--serif);
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--form); outline-offset: 3px; }

/* The black timing marks down the edge of a machine-read answer sheet. */
.timing {
  position: fixed; top: 0; bottom: 0; left: 0; width: 14px; z-index: 0;
  background: repeating-linear-gradient(to bottom, transparent 0 18px, var(--graphite) 18px 26px);
  opacity: .9;
}

/* ---------- Form header ---------- */
.form-head { padding: 22px 32px 0 48px; }
.form-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  border-bottom: 2px solid var(--form); padding-bottom: 8px;
}
.exam {
  font: 700 var(--t-sm)/1.1 var(--label); letter-spacing: .22em; text-transform: uppercase;
  color: var(--form); text-decoration: none;
}
.form-no { font: 500 var(--t-xs)/1 var(--label); letter-spacing: .16em; text-transform: uppercase; color: var(--form); white-space: nowrap; }
.fields {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0;
  border-bottom: 1px solid var(--form-line);
}
.fields div { padding: 8px 12px 9px; border-left: 1px solid var(--form-line); }
.fields div:first-child { border-left: 0; padding-left: 0; }
.fields dt { font: 500 10px/1 var(--label); letter-spacing: .18em; text-transform: uppercase; color: var(--form); }
.fields dd { margin: 4px 0 0; min-height: 26px; font: 400 28px/1 var(--hand); color: var(--graphite); }
.fields div:last-child dd { color: var(--pen); }

/* ---------- Layout ---------- */
main {
  flex: 1; width: 100%;
  padding: 56px 32px 96px 48px;
}
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 272px; gap: 72px; align-items: start; max-width: 1180px; }
.layout > aside { position: sticky; top: 24px; }

.label {
  font: 700 var(--t-xs)/1 var(--label); letter-spacing: .2em; text-transform: uppercase; color: var(--form);
  margin: 0 0 12px;
}

/* ---------- Home ---------- */
h1 {
  font: 600 var(--t-2xl)/1.04 var(--serif); letter-spacing: -.022em;
  margin: 0; max-width: 13em;
}
h1 .marked { position: relative; white-space: nowrap; }
.directions {
  margin: 40px 0 0; max-width: 34em; padding: 18px 0 0; border-top: 1px solid var(--form-line);
  font-size: var(--t-md);
}
.directions p { margin: 0 0 10px; }
.start-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-top: 32px; }
.pen-note { font: 400 26px/1.1 var(--hand); color: var(--pen); transform: rotate(-3deg); }
/* A pencil doodle of Texas in the margin, like one on a seventh-grade test. */
.doodle { display: block; width: 190px; height: auto; margin: 44px 0 0 auto; transform: rotate(-6deg); opacity: .92; }
.challenge {
  margin: 0 0 36px; padding: 12px 0 12px 16px; border-left: 3px solid var(--pen);
  font-size: var(--t-md);
}
.challenge .hand { font: 400 30px/1 var(--hand); color: var(--pen); margin-right: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 0 26px; border-radius: 2px;
  border: 2px solid var(--graphite); background: var(--graphite); color: var(--sheet);
  font: 700 var(--t-sm)/1 var(--label); letter-spacing: .16em; text-transform: uppercase; text-decoration: none;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.btn:hover { background: #000; }
.btn.line { background: transparent; color: var(--graphite); }
.btn.line:hover { background: var(--form-tint); border-color: var(--form); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Answer sheet (the grid) ---------- */
.sheet { border: 1px solid var(--form-line); }
.sheet-head {
  display: grid; grid-template-columns: 34px repeat(4, 1fr) 30px; align-items: center;
  font: 500 10px/1 var(--label); letter-spacing: .14em; color: var(--form); text-transform: uppercase;
  padding: 8px 10px; border-bottom: 1px solid var(--form-line);
}
.sheet-head span { text-align: center; }
.sheet-head span:first-child { text-align: left; }
.sheet-row {
  display: grid; grid-template-columns: 34px repeat(4, 1fr) 30px; align-items: center;
  padding: 4px 10px; min-height: 30px;
}
.sheet-row:nth-child(odd) { background: var(--form-tint); }
.sheet-row .n { font: 500 13px/1 var(--label); color: var(--form); }
.sheet-row .mark { width: 24px; height: 22px; justify-self: end; }
.sheet-row.now { box-shadow: inset 3px 0 0 var(--graphite); }
.bub {
  justify-self: center; width: 20px; height: 13px; border-radius: 50%;
  border: 1.2px solid var(--form-line);
  display: grid; place-items: center; font: 500 8px/1 var(--label); color: var(--form-line);
  position: relative;
}
.bub.filled { background: var(--graphite); border-color: var(--graphite); color: transparent;
  background-image: radial-gradient(circle at 30% 35%, #4a4d52 0 1px, transparent 2px), radial-gradient(circle at 70% 60%, #3a3c40 0 1px, transparent 2px); }
.bub .ring { position: absolute; inset: -6px -8px; width: auto; height: auto; }

/* ---------- Question ---------- */
.qnum { font: 700 var(--t-xs)/1 var(--label); letter-spacing: .2em; text-transform: uppercase; color: var(--form); margin: 0 0 14px; display: flex; gap: 14px; align-items: center; }
.qnum .tally { font: 400 22px/1 var(--hand); color: var(--pen); letter-spacing: 0; text-transform: none; }
.question { position: relative; }
h2 { font: 600 var(--t-xl)/1.22 var(--serif); letter-spacing: -.012em; margin: 0; max-width: 24em; }
.choices { list-style: none; margin: 30px 0 0; padding: 0; display: grid; gap: 4px; max-width: 36em; }
.choice {
  width: 100%; display: flex; align-items: center; gap: 16px; text-align: left;
  padding: 12px 14px; min-height: 54px; border: 0; border-radius: 2px; background: transparent;
  font: 400 var(--t-md)/1.35 var(--serif);
  transition: background-color .2s ease;
}
.choice:hover:not([disabled]) { background: var(--form-tint); }
.choice[disabled] { cursor: default; }
.choice .bub { width: 30px; height: 20px; flex: none; font-size: 11px; color: var(--form); border-color: var(--form-line); border-width: 1.5px; justify-self: auto; }
.choice.picked .bub { background-color: var(--graphite); border-color: var(--graphite); color: var(--sheet); }
.choice .txt { position: relative; }
.choice.dim { color: var(--graphite-soft); }

/* red pen */
.pen { position: absolute; pointer-events: none; overflow: visible; }
.pen path { fill: none; stroke: var(--pen); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.draw path { stroke-dasharray: var(--len, 600); stroke-dashoffset: var(--len, 600); animation: draw .3s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.choice .verdict { position: static; flex: none; width: 34px; height: 34px; margin: -6px 0 -6px 14px; }
.choice .verdict path { stroke-width: 3.2; }

.note { margin: 26px 0 0; max-width: 36em; padding-left: 18px; border-left: 2px solid var(--pen); }
.note .hand { display: block; font: 400 30px/1 var(--hand); color: var(--pen); margin-bottom: 4px; }
.note p { margin: 0; font-style: italic; }
.next-row { margin-top: 28px; }

/* compact sheet strip for phones */
.strip { display: none; }

/* ---------- Result ---------- */
.graded { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 20px 48px; align-items: center; }
.score { position: relative; padding: 18px 34px 10px 26px; }
.score .num { font: 400 clamp(96px, 15vw, 150px)/.9 var(--hand); color: var(--pen); white-space: nowrap; }
.score .pen { inset: 0; width: 100%; height: 100%; }
.rank { font: 400 clamp(38px, 5vw, 52px)/1 var(--hand); color: var(--pen); margin: 0 0 8px; }
.rank-line { margin: 0; max-width: 26em; font-size: var(--t-lg); line-height: 1.4; }
.stamp {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 18px;
  padding: 6px 12px 5px; border: 2.5px solid var(--pen); border-radius: 3px; color: var(--pen);
  font: 700 var(--t-sm)/1 var(--label); letter-spacing: .22em; text-transform: uppercase;
  transform: rotate(-4deg); opacity: .88;
}
.stamp.fail { border-color: var(--graphite-soft); color: var(--graphite-soft); }
.stamp svg { width: 14px; height: 14px; fill: currentColor; }

.share { margin-top: 48px; padding-top: 22px; border-top: 1px solid var(--form-line); }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; max-width: 44em; }
.sheet-inline { display: none; }
.corrections .more { margin-top: 8px; }
.toast { font: 400 22px/1.2 var(--hand); color: var(--form); min-height: 1.3em; margin: 12px 0 0; }
.copy-field { display: block; width: 100%; margin-top: 8px; padding: 10px 12px; border: 1.5px solid var(--form); border-radius: 2px; background: var(--sheet); font: 400 15px/1.3 var(--label); color: var(--graphite); }

.extra-credit { margin-top: 48px; padding: 24px 26px 26px; border: 1.5px solid var(--form); background: var(--form-tint); max-width: 40em; }
.extra-credit h2 { margin: 0 0 8px; }
.extra-credit > p:not(.label) { margin: 0; }
.extra-credit .start-row { margin-top: 20px; }
.extra-credit .fine { font: 500 var(--t-xs)/1.3 var(--label); letter-spacing: .12em; text-transform: uppercase; color: var(--form); }
.corrections { margin-top: 56px; }
.corrections ol { list-style: none; padding: 0; margin: 0; }
.corrections li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 4px 12px; padding: 18px 0; border-top: 1px solid var(--form-line); }
.corrections .n { font: 500 var(--t-sm)/1.5 var(--label); color: var(--form); }
.corrections .q { font-weight: 600; margin: 0 0 4px; }
.corrections .a { margin: 0; }
.corrections .a .hand { font: 400 24px/1 var(--hand); color: var(--pen); }
.corrections .why { margin: 4px 0 0; font-style: italic; color: var(--graphite-soft); font-size: 16px; }

.loading { font: 400 28px/1 var(--hand); color: var(--form); }

/* ---------- Footer ---------- */
.foot {
  display: flex; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap;
  margin: 0 32px 0 48px; padding: 14px 0 22px; border-top: 1px solid var(--form-line);
  font: 500 var(--t-xs)/1.4 var(--label); letter-spacing: .1em; text-transform: uppercase; color: var(--form);
}

/* ---------- Motion: reveal on view change ---------- */
.enter > * { animation: rise .26s ease-out both; }
.enter > *:nth-child(2) { animation-delay: .04s; }
.enter > *:nth-child(3) { animation-delay: .08s; }
.enter > *:nth-child(4) { animation-delay: .12s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .layout > aside { position: static; }
  .home-sheet, .quiz-sheet.live, .result-sheet { display: none; }
  /* Answer sheet moves up under the score. */
  .sheet-inline { display: block; margin-top: 28px; max-width: 460px; }
  .strip { display: grid; grid-template-columns: repeat(20, 1fr); gap: 3px; margin: 0 0 28px; }
  .strip span { height: 24px; border: 1px solid var(--form-line); font: 500 10px/22px var(--label); text-align: center; color: var(--form); position: relative; }
  .strip span.done { background: var(--graphite); border-color: var(--graphite); color: var(--sheet); }
  .strip span.miss::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--pen); transform: rotate(35deg); }
  .strip span.now { border: 2px solid var(--graphite); }
}
@media (max-width: 620px) {
  .timing { width: 8px; background: repeating-linear-gradient(to bottom, transparent 0 16px, var(--graphite) 16px 22px); }
  .form-head { padding: 16px 16px 0 26px; }
  .form-no { display: none; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fields div:nth-child(3) { border-left: 0; padding-left: 0; border-top: 1px solid var(--form-line); }
  .fields div:nth-child(4) { border-top: 1px solid var(--form-line); }
  main { padding: 36px 16px 72px 26px; }
  .foot { margin: 0 16px 0 26px; }
  .strip { grid-template-columns: repeat(10, 1fr); }
  .choice { padding: 12px 6px; }
  .graded { grid-template-columns: minmax(0, 1fr); }
  .score { justify-self: start; }
  .btn-row .btn { flex: 1 1 100%; }
  /* One big share button; the rest small, two to a row. */
  .share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .share-actions .btn { min-height: 44px; padding: 0 8px; font-size: 12px; letter-spacing: .12em; }
  .share-actions .btn.social { background: transparent; color: var(--graphite); }
  .share-actions .primary { grid-column: 1 / -1; min-height: 54px; font-size: var(--t-sm); }
  .share-actions .wide { grid-column: 1 / -1; }

}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .draw path { stroke-dashoffset: 0; }
}
