/* ==========================================================================
   The study app: setup, session and summary.

   Every value that exists as a token comes from ../design/tokens.css — see
   CLAUDE.md. The few literals here are layout-local (percentages, 1px
   hairlines) with no token equivalent.

   Register per DESIGN.md: "Focused Competitor". Energy is spent only on the
   feedback moment and the streak; nothing else animates beyond 180ms.
   ========================================================================== */

* { box-sizing: border-box; }

/* An author `display` rule outranks the UA stylesheet's [hidden] rule, so
   the screen containers below would stay visible while "hidden". */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 22px;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: var(--font-display); font-weight: 900; margin: 0; }

.overline {
  font-size: 11px; line-height: 14px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin: 0;
}

.sub { color: var(--muted); font-size: 14px; line-height: 20px; }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.cta {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--teal);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  box-shadow: var(--shadow-cta);
  transition: background var(--dur-micro) var(--ease-standard);
}
.cta:hover  { background: var(--teal-bright); }
.cta:focus-visible { outline: 2px solid var(--teal-dark); outline-offset: 2px; }
.cta:active { background: var(--teal-dark); }

.linkish {
  background: none; border: 0; padding: var(--sp-sm);
  color: var(--teal); font: inherit; font-weight: 600; cursor: pointer;
}
.linkish:hover { text-decoration: underline; }

/* ── Setup ───────────────────────────────────────────────────────────── */
/* preview-desktop "02 Study Setup": the filter in a card that becomes the
   340px rail on desktop, the event as a teal hero, a plain summary of what
   Start will deal, and Start as the only loud thing on the page. */

.setup {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--sp-lg) var(--sp-4xl);
  display: flex; flex-direction: column; gap: var(--sp-2xl);
}

.topbar { display: flex; align-items: center; min-height: 64px; }
.brand {
  display: inline-flex; align-items: center; gap: var(--sp-sm);
  font-family: var(--font-display); font-weight: 900; font-size: 19px;
  letter-spacing: -.02em; color: var(--text); text-decoration: none;
}
.logo {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--teal-bright));
  color: #fff; font-size: 16px;
}

.setup-head h1 { font-size: 28px; line-height: 32px; letter-spacing: -.01em; }
.setup-head .sub { margin: var(--sp-xs) 0 0; text-wrap: pretty; }

.setup-grid { display: grid; gap: var(--sp-xl); }
@media (min-width: 1024px) {
  .setup-grid { grid-template-columns: var(--filter-rail) 1fr; align-items: start; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-xl);
  box-shadow: var(--shadow-md);
}
.card-title {
  font-family: var(--font-display); font-weight: 900;
  font-size: 17px; line-height: 24px; margin: 0 0 var(--sp-lg);
}

.filters { display: grid; gap: var(--sp-lg); }

/* `min-width: 0` is what stops a <select> from setting the grid's width
   from its longest option. The tournament list runs to
   "captainstryouts-waubonsievalley 2020 · Div C (81)", which pushed the
   setup screen 26px wider than a 375px phone and gave the whole page a
   horizontal scroll. */
.field { display: grid; gap: var(--sp-xs); min-width: 0; }
.field select {
  width: 100%;
  min-width: 0;
  min-height: var(--tap-min);
  padding: 0 var(--sp-md);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: border-color var(--dur-micro) var(--ease-standard);
}
.field select:hover { border-color: var(--teal); }
.field select:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

.setup-main { display: grid; gap: var(--sp-lg); }
/* Below the rail breakpoint the event and Start come first: a student who
   takes the default taps Start without scrolling past four menus. */
@media (max-width: 1023px) { .setup-main { order: -1; } }

.event-hero {
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  border-radius: var(--r-lg);
  padding: var(--sp-2xl);
  color: #fff;
}
.hero-name {
  font-size: 28px; line-height: 32px; letter-spacing: -.02em;
  text-wrap: balance;
}
.hero-meta { margin: var(--sp-xs) 0 0; font-size: 14px; line-height: 20px; opacity: .9; }

.about { display: flex; flex-direction: column; }
.about-rows { margin: 0; }
.about-rows div {
  display: flex; align-items: baseline; gap: var(--sp-md);
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.about-rows dt {
  flex: none; width: 92px;
  font-size: 11px; line-height: 14px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.about-rows dd {
  margin: 0; font-size: 14px; font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.start {
  margin-top: var(--sp-xl);
  display: flex; align-items: center; justify-content: center; gap: var(--sp-sm);
  font-weight: 900; font-size: 19px; letter-spacing: -.01em;
}
.start .count {
  background: rgba(255, 255, 255, .22);
  padding: var(--sp-2xs) var(--sp-md);
  border-radius: var(--r-full);
}
.start:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.start:disabled:hover { background: var(--teal); }

.empty { color: var(--muted); text-align: center; margin: var(--sp-lg) 0 0; font-size: 14px; }
.about .linkish { align-self: center; margin-top: var(--sp-sm); }

.setup-foot {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-lg);
  color: var(--muted);
  font-size: 12px; line-height: 16px;
}

/* ── Session chrome ──────────────────────────────────────────────────── */

.session { min-height: 100vh; display: flex; flex-direction: column; }

.s-top {
  display: flex; align-items: center; gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
}
.s-x {
  width: var(--tap-min); height: var(--tap-min);
  border: 0; border-radius: var(--r-full);
  background: none; color: var(--muted);
  font-size: 18px; cursor: pointer;
}
.s-x:hover { background: var(--surface-2); }

.prog { flex: 1; height: 6px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.prog i {
  display: block; height: 100%; width: 0;
  background: var(--teal); border-radius: var(--r-full);
  transition: width var(--dur-short) var(--ease-standard);
}

.flame { font-size: 15px; font-family: var(--font-display); font-weight: 700; }

/* ── Question canvas ─────────────────────────────────────────────────── */

.canvas {
  width: 100%; max-width: var(--session-max);
  margin: 0 auto; padding: var(--sp-xl) var(--sp-lg) var(--sp-4xl);
  display: flex; flex-direction: column; gap: var(--sp-lg);
}

.qmeta { color: var(--muted); font-size: 12px; font-weight: 600; margin: 0; }

.qtext {
  font-size: 18px; line-height: 24px; font-weight: 700;
  white-space: pre-wrap;
}
@media (min-width: 1024px) { .qtext { font-size: 26px; line-height: 30px; } }

.stimulus {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface-2);
  padding: var(--sp-lg);
  font-size: 14px; line-height: 20px;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 220px; overflow: auto;
}
.stimulus b { color: var(--text); }
/* A carried passage is read, not glanced at: body text colour, and room for
   a case study before it scrolls. */
.stimulus.passage { color: var(--text); max-height: 320px; margin-bottom: var(--sp-md); }

/* ── Options ─────────────────────────────────────────────────────────── */

.ans { display: grid; gap: var(--sp-md); }
@media (min-width: 1024px) { .ans.two-up { grid-template-columns: 1fr 1fr; } }

.opt {
  display: flex; align-items: center; gap: var(--sp-md);
  min-height: 46px; padding: var(--sp-md) var(--sp-lg);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
  transition: border-color var(--dur-micro) var(--ease-standard),
              background var(--dur-micro) var(--ease-standard);
}
@media (min-width: 1024px) { .opt { min-height: 56px; } }
.opt:hover:not(:disabled) { border-color: var(--teal); }
.opt:disabled { cursor: default; }

.opt .k {
  flex: none;
  width: 26px; height: 26px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
  font-family: var(--font-display); font-weight: 700; font-size: 13px;
}

.opt.picked { border-color: var(--teal); background: color-mix(in srgb, var(--teal) 6%, transparent); }
.opt.picked .k { background: var(--teal); color: #fff; }

/* Correct/incorrect never rely on colour alone — each carries a glyph. */
.opt.correct   { border-color: var(--correct); background: color-mix(in srgb, var(--correct) 8%, transparent); }
.opt.correct .k   { background: var(--correct); color: #fff; }
.opt.incorrect { border-color: var(--error);   background: color-mix(in srgb, var(--error) 8%, transparent); }
.opt.incorrect .k { background: var(--error); color: #fff; }
.opt .mark { margin-left: auto; font-weight: 700; }
.opt.correct   .mark { color: var(--correct); }
.opt.incorrect .mark { color: var(--error); }

@media (prefers-reduced-motion: no-preference) {
  .opt.correct { animation: snap var(--dur-medium) var(--ease-reward); }
}
@keyframes snap { 0% { transform: scale(1); } 45% { transform: scale(1.025); } 100% { transform: scale(1); } }

/* ── Typed answer ────────────────────────────────────────────────────── */

.typed { display: grid; gap: var(--sp-sm); }
.typed input {
  min-height: 46px; padding: 0 var(--sp-lg);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit;
}
.typed input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }
.typed .hint { color: var(--muted); font-size: 12px; text-align: center; }

/* ── Label-the-parts blanks ──────────────────────────────────────────── */
/* One row per lettered part. The letter is a fixed-width chip so the rows
   line up into a column the eye can scan against the diagram's callouts,
   and it uses the mono face because it is a label to match, not prose. */

.blanks { display: grid; gap: var(--sp-sm); margin-bottom: var(--sp-md); }
.blank {
  display: grid; grid-template-columns: 34px 1fr; align-items: center;
  gap: var(--sp-sm); position: relative;
}
.blank-key {
  display: grid; place-items: center; min-height: 34px;
  border-radius: var(--r-sm); background: var(--surface-2);
  font-family: var(--font-mono); font-weight: 600; color: var(--muted);
}
.blank input {
  min-height: 40px; padding: 0 var(--sp-md);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit;
  min-width: 0; /* let the input shrink inside the grid on narrow phones */
}
.blank input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

/* Marked state never relies on colour alone — the key text appears beside
   every miss, which is also the thing worth learning. */
.blank.correct   .blank-key { background: var(--correct); color: #fff; }
.blank.incorrect .blank-key { background: var(--error);   color: #fff; }
.blank.correct   input { border-color: var(--correct); }
.blank.incorrect input { border-color: var(--error); opacity: .7; }
.blank-key-text {
  grid-column: 2; font-size: 13px; font-weight: 600;
  color: var(--correct); padding-left: var(--sp-xs);
}

/* A multi-part question: the sub-question sits on its own line above its
   box, so the pair reads as one unit instead of the student counting rows
   to match a stacked stem against anonymous inputs. */
.blank.has-prompt {
  grid-template-columns: 34px 1fr; row-gap: var(--sp-xs);
  align-items: start; margin-bottom: var(--sp-xs);
}
.blank.has-prompt .blank-key { grid-row: 1; align-self: start; }
.blank-prompt {
  grid-column: 2; grid-row: 1; align-self: center;
  font-size: 14px; line-height: 1.4; color: var(--text);
}
.blank.has-prompt input { grid-column: 2; grid-row: 2; }
.blank.has-prompt .blank-key-text { grid-row: 3; }

/* ── Feedback ────────────────────────────────────────────────────────── */

.fb {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-lg);
  display: grid; gap: var(--sp-md);
}
.fb-head { font-family: var(--font-display); font-weight: 900; font-size: 22px; margin: 0; }
.fb-head.ok   { color: var(--correct); }
.fb-head.bad  { color: var(--error); }
.fb-answer { font-size: 15px; }
.fb-answer > b + br { display: none; }
.fb-answer b { font-weight: 700; }
.flagged { color: var(--correct); font-size: 13px; font-weight: 600; margin: 0; }

/* A caution, not a reward — DESIGN.md reserves amber-as-accent for streaks
   and level-ups, so this borrows only the semantic --warning and stays a
   quiet tinted note. It must read as "check this", never as a celebration. */
.fb-shaky {
  margin: 0;
  padding: var(--sp-sm) var(--sp-md);
  border-left: 3px solid var(--warning);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

/* ── Summary ─────────────────────────────────────────────────────────── */

.summary {
  max-width: var(--session-max); margin: 0 auto;
  padding: var(--sp-5xl) var(--sp-lg);
  display: flex; flex-direction: column; gap: var(--sp-xl);
  text-align: center; align-items: center;
}
.summary h1 { font-size: 40px; line-height: 44px; }
.burst {
  width: 96px; height: 96px; border-radius: var(--r-full);
  background: linear-gradient(140deg, var(--amber), var(--coral));
}
@media (prefers-reduced-motion: no-preference) {
  .burst { animation: pop var(--dur-celebrate) var(--ease-reward); }
}
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.scores { display: flex; gap: var(--sp-4xl); }
.scores div { display: grid; gap: var(--sp-2xs); }
.big { font-family: var(--font-display); font-weight: 900; font-size: 28px; line-height: 32px; }

/* Multi-part answers: one per line when they are too long to read inline. */
.answer-list { margin: var(--sp-sm) 0 0; padding-left: var(--sp-xl); }
.answer-list li { margin-bottom: var(--sp-xs); }

/* Matching answer bank: a scannable grid, not a prose run-on. */
.bank {
  margin: var(--sp-sm) 0 0; padding: 0; list-style: none;
  display: grid; gap: var(--sp-2xs);
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  color: var(--text);
}
.bank li { font-size: 13px; }

/* Cipher text (Codebusters): monospace, wrapping, letter-countable. */
.cipher {
  display: block;
  font-family: var(--font-mono);
  font-size: 14px; line-height: 22px;
  letter-spacing: .06em;
  word-break: break-all;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: var(--sp-md);
  margin: var(--sp-sm) 0;
  font-weight: 400;
}

/* A bound figure: the diagram leads, so it gets the full column width. */
.stimulus:has(.figure) { background: var(--surface); padding: var(--sp-sm); max-height: none; }
.figure {
  display: block; width: 100%; height: auto;
  max-height: 420px; object-fit: contain;
  border-radius: var(--r-lg); background: #fff;
}

/* ── A gap in the sentence ───────────────────────────────────────────── */
/* What the paper printed as a ruled line and the pipeline carries as
   "[blank]". Drawn as the rule rather than as the marker: a student reading
   "known as the [blank]." has to decode a token, where an underline is the
   thing itself. Sized in em so it tracks the question's own type scale, and
   baseline-aligned so a gap mid-sentence does not push the line apart.
   When a question has several, the number rides above the rule — it is what
   pairs each gap with its box. */
.gap {
  display: inline-block;
  min-width: 2.6em;
  border-bottom: 2px solid var(--muted);
  /* Sits on the text baseline, not below it. */
  margin: 0 0.12em -0.08em;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.62em;
  line-height: 1;
  font-weight: 700;
  color: var(--muted);
  /* The rule is the affordance; the number is a caption on it. */
  padding-bottom: 0.22em;
  vertical-align: baseline;
}
