/* =========================================================
   Pioneer Python — Binary page (binary.html only)

   Linked AFTER /css/styles.css. Four widgets share one small vocabulary:
     .bin-bits / .bin-bit   the place-value toggle row (all four widgets)
     .bin-verdict           the ✓ / "Not yet" marker
     .bin-fall__*           Falling Numbers: field, rows, HUD
     .bin-quiz__*           Three Minutes: gate, clock, results, capture

   Colours come from tokens.css. Green/red appear only on verdicts, lives,
   and the quiz pass mark, matching the site rule that those two colours mean
   "right/wrong" and nothing else. Every animating rule has a counterpart in the
   reduced-motion block at the END of this file.
   ========================================================= */

/* ---- Page scaffolding --------------------------------------------------- */

/* Stacked, not the auto-fit grid from page.css: these widgets read top to
   bottom as a sequence and each one needs the full width. */
.bin-stack {
  display: flex;
  flex-direction: column;
  gap: clamp(1.25rem, 3vw, 2rem);
}

/* Jump links under the hero. */
.bin-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}
.bin-jump a {
  display: inline-block;
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-ink);
  text-decoration: none;
}
.bin-jump a:hover { border-color: var(--color-accent); color: var(--color-accent); }
.bin-jump a:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.bin-card__title {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-accent);
}
.bin-card__lead {
  margin: 0 0 1.1rem;
  color: var(--color-ink-muted);
  font-size: 0.92rem;
  max-width: 70ch;
}

/* ---- The place-value toggle row (shared) -------------------------------- */
/* Built by buildBitRow() in binary.js. Each column is a place-value label
   over a real <button aria-pressed>, so the pressed state, keyboard support,
   and screen-reader announcement all come from the platform. Fills with the
   accent when on, exactly like .ps-toggle__btn in problem-sets.css. */

.bin-bits {
  display: flex;
  gap: clamp(0.35rem, 1.5vw, 0.75rem);
  flex-wrap: wrap;
}
.bin-bits__col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.bin-bits__place {
  font: 600 0.8rem/1 var(--font-mono);
  color: var(--color-ink-muted);
  letter-spacing: 0.04em;
}

.bin-bit {
  font-family: var(--font-mono);
  font-size: clamp(1.35rem, 4vw, 1.9rem);
  font-weight: 700;
  line-height: 1;
  width: clamp(2.75rem, 9vw, 3.5rem);
  min-height: 44px; /* touch target minimum (WCAG / Apple HIG) */
  padding: 0.55rem 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-ink-muted);
  cursor: pointer;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.bin-bit[aria-pressed="true"] {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}
[data-theme="dark"] .bin-bit[aria-pressed="true"] { color: #08243a; }
.bin-bit:hover { border-color: var(--color-accent); }
.bin-bit:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

/* ---- Buttons + inputs (shared) ------------------------------------------ */

.bin-btn {
  font: 600 0.9rem/1 var(--font-sans);
  padding: 0.55rem 1.1rem;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-ink);
  cursor: pointer;
  transition: filter 150ms var(--ease), border-color 150ms var(--ease);
}
.bin-btn:hover { border-color: var(--color-accent); }
.bin-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.bin-btn[disabled] { opacity: 0.55; cursor: default; }

.bin-btn--primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-surface);
}
[data-theme="dark"] .bin-btn--primary { color: #08243a; }
.bin-btn--primary:hover { filter: brightness(1.08); }

/* Mode switch (Explore / Challenges). */
.bin-btn[aria-pressed="true"] {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.bin-input {
  font: 700 1.4rem/1.2 var(--font-mono);
  width: 6rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-ink);
}
.bin-input:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }

.bin-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ---- Verdicts (shared) -------------------------------------------------- */
/* The one place this page uses green/red, matching the playground tester. */

.bin-verdict {
  font: 600 0.95rem/1.4 var(--font-sans);
  min-height: 1.4em;
  color: var(--color-ink-muted);
}
.bin-verdict.is-correct { color: var(--color-pass); }
.bin-verdict.is-incorrect { color: var(--color-fail); }

.bin-hint {
  margin: 0.3rem 0 0;
  font: 700 1rem/1.4 var(--font-mono);
  color: var(--color-ink);
  min-height: 1.4em;
}

.bin-meta {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--color-ink-muted);
}

/* ---- 1. Eight Four Two One ---------------------------------------------- */

.bin-lab__sum {
  margin: 1rem 0 0;
  font: 700 clamp(1.1rem, 3.5vw, 1.5rem)/1.3 var(--font-mono);
  color: var(--color-ink);
}

.bin-lab__task {
  margin: 0 0 0.9rem;
  font-size: 0.95rem;
  color: var(--color-ink);
}

.bin-lab__controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

/* ---- 2. Read the Bits --------------------------------------------------- */

/* Places and digits are two separate rows (the scaffold switch hides only
   the first), so they line up the way the bit rows in activities 1 and 3 do
   -- by sharing one cell width and one gap rather than by eyeballed
   letter-spacing. The two variables are set on both rows at once, so moving
   one moves the other. Keep the cell wide enough for the largest digit
   glyph: the mono font is about 0.6em per character, so a 4rem digit needs
   ~2.4rem. */
.bin-read__places,
.bin-read__digits {
  --bin-read-cell: clamp(2.75rem, 11vw, 4rem);
  --bin-read-gap: clamp(0.35rem, 1.5vw, 0.75rem);
  display: flex;
  gap: var(--bin-read-gap);
  flex-wrap: wrap;
  letter-spacing: 0; /* alignment comes from the cells, not from tracking */
}

.bin-read__cell {
  width: var(--bin-read-cell);
  text-align: center;
}

/* The scaffold switch hides the places row with the hidden ATTRIBUTE, and an
   author `display: flex` outranks the browser's built-in [hidden] rule --
   the same trap quiz.css documents. Without this the checkbox does nothing. */
.bin-read__places[hidden] { display: none; }

.bin-read__places {
  font: 600 0.85rem/1 var(--font-mono);
  color: var(--color-ink-muted);
  margin: 0 0 0.35rem;
}

.bin-read__digits {
  font: 700 clamp(2.5rem, 11vw, 4rem)/1 var(--font-mono);
  color: var(--color-accent);
  margin: 0 0 1.1rem;
}

.bin-read__scaffold {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--color-ink-muted);
  cursor: pointer;
}

/* ---- 3. Falling Numbers -------------------------------------------------- */

.bin-fall__hud {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--color-ink-muted);
}
.bin-fall__hud b {
  display: block;
  font: 700 1.15rem/1.2 var(--font-mono);
  color: var(--color-ink);
}
.bin-fall__lives { color: var(--color-fail); }

/* The play field. Rows are absolutely positioned inside it and moved with
   translateY by the animation loop in binary.js. */
.bin-fall__field {
  position: relative;
  height: clamp(220px, 38vh, 340px);
  border: 1px solid var(--color-border);
  border-bottom: 2px solid var(--color-fail);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--color-bg);
  overflow: hidden;
  transition: background-color 150ms var(--ease);
}
/* Flashed for 300ms when a target crosses the line. */
.bin-fall__field.is-hit { background: var(--color-fail-soft); }

.bin-fall__row {
  position: absolute;
  top: 0;
  font: 700 clamp(1.3rem, 5vw, 1.9rem)/1 var(--font-mono);
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink-muted);
  box-shadow: var(--shadow-sm);
}
/* The row nearest the line -- the one the bits below are answering. */
.bin-fall__row.is-active {
  border-color: var(--color-accent);
  color: var(--color-accent);
  box-shadow: var(--shadow-md);
}

.bin-fall__banner {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  color: var(--color-ink);
  font-size: 0.9rem;
}

.bin-fall__panel {
  border: 1px solid var(--color-border);
  border-top: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: 1rem;
  background: var(--color-surface);
}

.bin-fall__over {
  margin: 0.85rem 0 0;
  font: 700 1rem/1.4 var(--font-sans);
  color: var(--color-ink);
}

/* ---- 4. Three Minutes (the quiz) ---------------------------------------- */

/* This whole section becomes the submitted PNG, so it anchors the
   watermark overlay. Mirrors .ps-capture in problem-sets.css. */
#binary-quiz { position: relative; }

.bin-quiz__gate { max-width: 32rem; }
.bin-quiz__label {
  display: block;
  margin-bottom: 0.35rem;
  font: 600 0.9rem/1.3 var(--font-sans);
  color: var(--color-ink);
}
.bin-quiz__name {
  display: block;
  width: 100%;
  font: 1rem/1.4 var(--font-sans);
  color: var(--color-ink);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  margin-bottom: 1rem;
}
.bin-quiz__name:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }

/* Accent, not red: a missing name is a prompt, not a wrong answer. */
.bin-quiz__error {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0.65rem;
  background: var(--color-accent-soft);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--color-ink);
}

.bin-quiz__bar {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding-bottom: 0.85rem;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-ink-muted);
}
.bin-quiz__clock {
  font: 700 clamp(1.6rem, 6vw, 2.2rem)/1 var(--font-mono);
  color: var(--color-ink);
}

.bin-quiz__prompt {
  font: 700 clamp(2.2rem, 10vw, 3.5rem)/1 var(--font-mono);
  letter-spacing: 0.12em;
  color: var(--color-accent);
  margin: 0 0 1.1rem;
}

/* The per-question ✓ / ✗, shown for 400ms. Sized and positioned so the
   question below never shifts when it appears and disappears. */
.bin-quiz__flash {
  display: block;
  min-height: 2rem;
  margin-top: 0.6rem;
  font: 700 1.6rem/1 var(--font-sans);
  color: transparent;
}
.bin-quiz__flash.is-correct { color: var(--color-pass); }
.bin-quiz__flash.is-incorrect { color: var(--color-fail); }

.bin-quiz__results {
  display: flex;
  gap: clamp(1.25rem, 5vw, 3rem);
  flex-wrap: wrap;
  padding: 1.25rem 0;
  border-block: 1px solid var(--color-border);
  margin-bottom: 1.25rem;
}
.bin-quiz__stat { font-size: 0.85rem; color: var(--color-ink-muted); }
.bin-quiz__stat b {
  display: block;
  font: 700 clamp(1.8rem, 7vw, 2.6rem)/1.1 var(--font-mono);
  color: var(--color-ink);
}
.bin-quiz__stat--right b { color: var(--color-pass); }
.bin-quiz__stat--wrong b { color: var(--color-fail); }
.bin-quiz__stat--percent b { color: var(--color-accent); }

/* The pass mark, which is the one thing a grader reads off the PNG at a
   glance: the score goes green at QUIZ_PASS correct or better and red below
   it, so the colour is a real result and not decoration. stop() in binary.js
   sets is-pass / is-fail on the scoreboard and the verdict together. The
   verdict line carries the number in words as well, because colour alone is
   never the whole message (WCAG 1.4.1). */
.bin-quiz__results.is-pass .bin-quiz__stat--percent b { color: var(--color-pass); }
.bin-quiz__results.is-fail .bin-quiz__stat--percent b { color: var(--color-fail); }

.bin-quiz__verdict {
  margin: 0 0 1.25rem;
  font: 700 clamp(1.05rem, 3.5vw, 1.35rem)/1.35 var(--font-sans);
}
.bin-quiz__verdict:empty { display: none; }
.bin-quiz__verdict.is-pass { color: var(--color-pass); }
.bin-quiz__verdict.is-fail { color: var(--color-fail); }

/* Submission stamp: name · quiz · score · percent · elapsed · date. Hidden
   except during the capture, when submit() fills it in so it is burned
   into the PNG. Mirrors .ps-capture__stamp. */
.bin-quiz__stamp {
  margin: 1rem 0 0;
  color: var(--color-ink-muted);
  font-size: 0.9rem;
}

/* Capture mode: drop the controls that mean nothing in a still image, so
   the PNG is just the heading, the score, and the stamp. */
.bin-quiz--capture .bin-quiz__nocapture { display: none; }

/* ---- Submission watermark ------------------------------------------------ */
/* Injected by buildWatermark() in binary.js just before the PNG renders and
   removed right after. The hardcoded red is shared with .ps-watermark and
   .pyenv-watermark deliberately: the stamp must look the same on every
   submission across the site, in both themes, so it uses no theme tokens. */
.bin-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* clip the rotated text at the card edges */
  pointer-events: none;
}
.bin-watermark__stamp {
  transform: rotate(-45deg);
  text-align: center;
  color: #dc2626;
  opacity: 0.38;
  font-family: var(--font-sans);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.15;
  white-space: nowrap;
}

/* =========================================================
   Reduced motion

   At the END of the file on purpose: media queries add no specificity, so
   these only win by coming last. binary.js checks the same media query in
   JS — under reduce, Falling Numbers paints rows in discrete jumps rather
   than sliding, and the auto-advance pauses drop to zero.
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  .bin-bit,
  .bin-btn,
  .bin-fall__field {
    transition: none;
  }
}
