/* Bridge Builder — styles. Same game chrome as Knowledge Keep (deep navy around a bright scene, gold for
   score and the main action, raised things on a solid 2px darker bottom edge). Readability floor for a
   Chromebook at arm's length or a projector: nothing under 14px, answers 18px+, the prompt 20-24px,
   tap targets 48px+. The game screen fits a 1366x768 window (about 1366x650 inside the browser) with no
   scrolling: header, then the scene (it takes what is left), then the question panel. */
:root {
  --bb-page: #0e1424;
  --bb-chrome: #141b2d;
  --bb-panel: #1a2340;
  --bb-raised: #243056;
  --bb-raised-hover: #2d3b69;
  --bb-edge: #0a0f1c;
  --bb-line: #33406a;
  --bb-line-soft: #27325a;
  --bb-ink: #f2f5fc;
  --bb-muted: #aeb8d4;
  --bb-gold: #ffc53d;
  --bb-gold-edge: #b9820c;
  --bb-gold-ink: #1d1400;
  --bb-gold-tint: #3a3014;
  --bb-good: #3ddc97;
  --bb-good-bg: #10392c;
  --bb-bad: #ff8a8a;
  --bb-bad-bg: #401a22;
  --bb-amber: #ffb547;
  --bb-red: #ff6b6b;
  --bb-focus: #7cc4ff;
  --bb-font: 'Lexend', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bb-mono: 'DM Mono', ui-monospace, monospace;
  font-family: var(--bb-font);
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--bb-ink); background: var(--bb-page); min-height: 100vh; font-size: 16px; line-height: 1.45; }
.app-shell { color: var(--bb-ink); background: var(--bb-page); font-family: var(--bb-font); }
button, input { font: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-weight: 800; letter-spacing: -.02em; }
:where(button, a, input, [tabindex]):focus-visible { outline: 3px solid var(--bb-focus); outline-offset: 3px; }
.hidden { display: none !important; }
.bb-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.kicker { margin: 0; color: var(--bb-muted); font-family: var(--bb-mono); font-size: 14px; letter-spacing: .1em; text-transform: uppercase; }
kbd { padding: 0 6px; font: 500 14px/1.4 var(--bb-mono); color: inherit; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .22); border-bottom-width: 2px; border-radius: 6px; }
.card { background: var(--bb-panel); border: 2px solid var(--bb-line-soft); border-radius: 12px; }

/* While a run is on screen the game owns the viewport; on the start screen the footer steps aside. */
body.bb-playing .tlg-header, body.bb-playing .tlg-footer, body.bb-playing .tlg-skip { display: none; }
body.bb-playing { overflow: hidden; }
body.bb-start .tlg-footer { display: none; }

/* ---- buttons ---------------------------------------------------------------------------------- */
.play-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 0; border-radius: 10px; font-weight: 800; transition: transform .08s, box-shadow .08s, background .12s; }
.play-button { width: 100%; min-height: 60px; color: var(--bb-gold-ink); background: var(--bb-gold); box-shadow: 0 4px 0 var(--bb-gold-edge); font-size: 26px; }
.play-button:hover:not(:disabled) { background: #ffd162; }
.play-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--bb-gold-edge); }
.play-button:disabled { cursor: progress; opacity: .7; }
.play-button svg { width: 26px; height: 26px; }
.secondary-button { min-height: 52px; padding: 0 22px; color: var(--bb-ink); background: var(--bb-raised); box-shadow: 0 3px 0 var(--bb-edge); font-size: 18px; }
.secondary-button:hover { background: var(--bb-raised-hover); }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; color: var(--bb-ink); background: var(--bb-raised); border: 0; border-radius: 10px; box-shadow: 0 2px 0 var(--bb-edge); }
.icon-button:hover { background: var(--bb-raised-hover); }
.icon-button svg { width: 22px; height: 22px; }

/* ---- start screen (matches Knowledge Keep): title bar + three columns ------------------------- */
.screen { min-height: 100vh; }
.start-screen { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - var(--tlg-header-h, 68px) - 1px); height: calc(100dvh - var(--tlg-header-h, 68px) - 1px); min-height: 520px; padding: 12px clamp(16px, 2.4vw, 32px) 16px; overflow: hidden; background: var(--bb-page); }
.start-bar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 1320px; margin: 0 auto; }
.crumbs { display: flex; align-items: center; gap: 10px; min-width: 0; }
.crumbs h1 { margin: 0; font-size: 26px; line-height: 1.1; white-space: nowrap; }
.crumb-sep { color: var(--bb-muted); font-size: 20px; font-weight: 700; }
.brand, .game-brand a { color: var(--bb-ink); text-decoration: none; font-size: 16px; font-weight: 800; letter-spacing: .12em; white-space: nowrap; }
.brand span, .game-brand a span { color: var(--bb-gold); }
.start-columns { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.15fr) minmax(0, 1.1fr); gap: 16px; width: 100%; max-width: 1320px; min-height: 0; margin: 0 auto; }
.start-col { display: flex; flex-direction: column; min-height: 0; padding: 16px; background: var(--bb-panel); border: 2px solid var(--bb-line-soft); border-radius: 12px; }
.step-heading { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 20px; line-height: 1.2; }
.step-num { display: grid; flex: 0 0 32px; place-items: center; width: 32px; height: 32px; color: var(--bb-gold-ink); background: var(--bb-gold); border-radius: 8px; box-shadow: 0 2px 0 var(--bb-gold-edge); font-size: 17px; font-weight: 800; }
.subject-picker { flex: 0 1 auto; display: grid; grid-auto-rows: minmax(54px, 74px); gap: 10px; min-height: 0; }
.subject-option { display: flex; align-items: center; gap: 14px; min-width: 0; padding: 8px 14px; color: var(--bb-ink); background: var(--bb-raised); border: 2px solid transparent; border-radius: 12px; box-shadow: 0 3px 0 var(--bb-edge); font-size: 20px; font-weight: 800; line-height: 1.2; text-align: left; }
.subject-option .subject-icon { display: grid; flex: 0 0 46px; place-items: center; width: 46px; height: 46px; color: #fff; background: var(--subject-color); border-radius: 10px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25); }
.subject-icon svg { width: 28px; height: 28px; }
.subject-option:hover { background: var(--bb-raised-hover); }
.subject-option.selected { background: color-mix(in srgb, var(--subject-color) 30%, var(--bb-raised)); border-color: var(--subject-color); }
.how-to { flex: 0 0 auto; margin-top: auto; padding: 12px 14px 4px; background: var(--bb-chrome); border: 2px solid var(--bb-line-soft); border-radius: 10px; }
.how-to h3 { margin: 0 0 6px; color: var(--bb-gold); font-size: 16px; letter-spacing: .02em; }
.how-to ul { margin: 0; padding-left: 20px; }
.how-to li { margin: 0 0 8px; font-size: 15px; line-height: 1.35; }
.topic-list { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; margin: 0 -6px; padding: 0 6px 6px; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: var(--bb-line) transparent; }
.unit-heading { margin: 6px 0 0; color: var(--bb-muted); font-size: 14px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.unit-heading:first-child { margin-top: 0; }
.bank-option { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 46px; padding: 4px 12px 4px 6px; color: var(--bb-ink); background: var(--bb-raised); border: 2px solid transparent; border-radius: 10px; box-shadow: 0 2px 0 var(--bb-edge); text-align: left; font-size: 16px; font-weight: 700; line-height: 1.2; }
.bank-option .bank-icon { display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: var(--bank-color); border-radius: 8px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25); font-size: 19px; }
.bank-option:hover { background: var(--bb-raised-hover); }
.bank-option.selected { background: color-mix(in srgb, var(--bank-color) 26%, var(--bb-raised)); border-color: var(--bb-gold); }
.bank-best { color: var(--bb-gold); font-size: 16px; font-weight: 800; white-space: nowrap; }
.bank-best.none { color: var(--bb-muted); font-size: 14px; font-weight: 500; }
.play-col .start-leaderboard { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.play-dock { flex: 0 0 auto; display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 2px solid var(--bb-line-soft); }
.your-best { margin: 0; padding: 10px 14px; background: var(--bb-gold-tint); border: 2px solid var(--bb-gold); border-radius: 10px; font-size: 18px; font-weight: 700; }
.your-best b { color: var(--bb-gold); font-size: 21px; font-weight: 800; }
.your-rank { margin-left: 6px; color: var(--bb-muted); font-size: 16px; font-weight: 500; }
.question-set .lgq-picker { margin: 0 0 4px; }
.topic-list.is-overridden { opacity: .45; }
.play-status { margin: 0; color: var(--bb-muted); font-size: 16px; font-weight: 700; text-align: center; }
.play-status:empty { display: none; }
.play-status.error { color: var(--bb-bad); }

/* ---- leaderboard rows (markup from games/shared/leaderboard.js) -------------------------------- */
.bb-leaderboard { display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 10px; background: var(--bb-raised); border-radius: 10px; box-shadow: 0 2px 0 var(--bb-edge); font-size: 16px; }
.lb-row.hi { background: var(--bb-gold-tint); outline: 2px solid var(--bb-gold); }
.lb-med { flex: 0 0 34px; color: var(--bb-gold); font-weight: 800; }
.lb-name { flex: 1 1 auto; min-width: 0; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.lb-pts { flex: 0 0 auto; color: var(--bb-gold); font-weight: 800; }
.lb-empty, .lb-note, .lb-you, .lb-signin { color: var(--bb-muted); font-size: 16px; }
.lb-you { padding: 6px 4px; color: var(--bb-ink); }
.lb-signin a, .lb-note a, .lb-you a { color: var(--bb-focus); font-weight: 700; }
.lb-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 18px; font-weight: 800; }
.lb-title svg { width: 22px; height: 22px; color: var(--bb-gold); }
.lb-celebrate { color: var(--bb-gold); font-size: 18px; font-weight: 800; }

/* ---- game screen ------------------------------------------------------------------------------ */
.game-screen { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; background: var(--bb-page); }
.game-header { flex: 0 0 60px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 0 clamp(12px, 2vw, 24px); background: var(--bb-chrome); border-bottom: 2px solid var(--bb-edge); }
.game-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.game-brand h2 { margin: 0; font-size: 20px; white-space: nowrap; }
.game-divider { width: 2px; height: 24px; background: var(--bb-line); }
.game-header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.pill { display: flex; align-items: baseline; gap: 6px; padding: 6px 12px; color: var(--bb-muted); background: var(--bb-raised); border-radius: 10px; box-shadow: 0 2px 0 var(--bb-edge); font-size: 15px; font-weight: 700; white-space: nowrap; }
.pill b { color: var(--bb-gold); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill-of { font-size: 14px; }
.score-pill svg { width: 18px; height: 18px; align-self: center; color: var(--bb-gold); }

/* The clock: big, center top. Amber under 0:30, red under 0:10 with a gentle pulse; the warning word
   beside it says the same thing, so color is never the only signal. */
.clock { display: flex; align-items: baseline; gap: 4px; padding: 2px 18px; color: var(--bb-ink); background: var(--bb-page); border: 3px solid var(--bb-line); border-radius: 14px; font-variant-numeric: tabular-nums; }
.clock svg { width: 26px; height: 26px; align-self: center; margin-right: 6px; }
#clock-value { font-size: 40px; font-weight: 800; line-height: 1.1; letter-spacing: -.01em; }
#clock-tenths { font-size: 22px; font-weight: 700; color: var(--bb-muted); }
.clock-warn { align-self: center; margin-left: 8px; font-size: 15px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.clock-warn:empty { display: none; }
.clock.amber { color: var(--bb-amber); border-color: var(--bb-amber); }
.clock.red { color: var(--bb-red); border-color: var(--bb-red); animation: bb-pulse 1s ease-in-out infinite; }
.clock.paused #clock-value, .clock.paused #clock-tenths { opacity: .6; }
@keyframes bb-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.scene-wrap { position: relative; flex: 1 1 auto; min-height: 200px; overflow: hidden; background: #8ec9ee; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.progress { position: absolute; left: 50%; top: 10px; display: flex; gap: 5px; padding: 6px 10px; background: rgba(14, 20, 36, .72); border-radius: 999px; transform: translateX(-50%); }
.progress i { width: 18px; height: 10px; border: 2px solid rgba(255, 255, 255, .55); border-radius: 3px; }
.progress i.on { background: var(--bb-gold); border-color: var(--bb-gold); }
.banner { position: absolute; left: 50%; top: 22%; padding: 12px 26px; color: var(--bb-ink); background: rgba(14, 20, 36, .86); border: 2px solid var(--bb-gold); border-radius: 14px; font-size: 26px; font-weight: 800; text-align: center; transform: translateX(-50%); white-space: nowrap; }
.banner small { display: block; color: var(--bb-muted); font-size: 17px; font-weight: 600; }
.banner.bad { border-color: var(--bb-bad); }
.pop { position: absolute; left: 50%; top: 40%; color: var(--bb-gold); font-size: 44px; font-weight: 800; text-align: center; text-shadow: 0 3px 0 #000, 0 0 18px rgba(0, 0, 0, .6); transform: translateX(-50%); animation: bb-pop 1.8s ease-out forwards; pointer-events: none; white-space: nowrap; }
.pop small { display: block; color: #fff; font-size: 20px; font-weight: 700; }
@keyframes bb-pop { 0% { opacity: 0; transform: translate(-50%, 16px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 25% { transform: translate(-50%, 0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -26px); } }

/* Question panel: under the scene, never over it. */
.question-panel { flex: 0 0 auto; min-height: 268px; align-content: start; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px clamp(14px, 3vw, 40px) 14px; background: var(--bb-panel); border-top: 3px solid var(--bb-edge); }
.question-panel > * { width: 100%; max-width: 1180px; margin: 0 auto; }
.question-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.question-tag { color: var(--bb-gold); font-size: 15px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.question-type { color: var(--bb-muted); font-size: 14px; font-weight: 600; }
.question-text { margin: 0; min-height: 1.3em; font-size: clamp(20px, 1.7vw, 24px); font-weight: 700; line-height: 1.3; letter-spacing: 0; }
.question-text:focus { outline: none; }
.answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; transition: opacity .2s; }
.answers.arming { opacity: .55; }
.answers.tf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.answer { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 14px; color: var(--bb-ink); background: var(--bb-raised); border: 2px solid transparent; border-radius: 10px; box-shadow: 0 3px 0 var(--bb-edge); font-size: 18px; font-weight: 600; line-height: 1.25; text-align: left; }
.answer:hover:not(:disabled) { background: var(--bb-raised-hover); }
.answer .key { display: grid; flex: 0 0 30px; place-items: center; height: 30px; color: var(--bb-gold-ink); background: var(--bb-gold); border-radius: 7px; font-size: 16px; font-weight: 800; }
.answer.right { background: var(--bb-good-bg); border-color: var(--bb-good); }
.answer.wrong { background: var(--bb-bad-bg); border-color: var(--bb-bad); }
.answer:disabled { cursor: default; }
.fill { display: flex; gap: 10px; grid-column: 1 / -1; }
.fill input { flex: 1 1 auto; min-height: 54px; padding: 8px 14px; color: var(--bb-ink); background: #0f1629; border: 2px solid var(--bb-line); border-radius: 10px; font-size: 20px; font-weight: 600; }
.fill input:focus { border-color: var(--bb-focus); outline: none; box-shadow: 0 0 0 3px rgba(124, 196, 255, .3); }
.fill input.right { border-color: var(--bb-good); }
.fill input.wrong { border-color: var(--bb-bad); }
.fill button { flex: 0 0 auto; min-height: 54px; padding: 0 22px; color: var(--bb-gold-ink); background: var(--bb-gold); border: 0; border-radius: 10px; box-shadow: 0 3px 0 var(--bb-gold-edge); font-size: 18px; font-weight: 800; }
.feedback { min-height: 26px; font-size: 18px; font-weight: 700; }
.feedback.good { color: var(--bb-good); }
.feedback.bad { color: var(--bb-bad); }
.feedback .correct-answer { color: var(--bb-ink); }

/* ---- results ----------------------------------------------------------------------------------- */
.results-screen { padding: 20px clamp(16px, 3vw, 40px) 32px; }
.results-shell { max-width: 1180px; margin: 0 auto; }
.results-head h1 { margin: 4px 0 6px; font-size: clamp(30px, 3.4vw, 44px); }
.results-head h1 span { color: var(--bb-gold); }
.results-lede { margin: 0 0 16px; color: var(--bb-muted); font-size: 18px; }
.results-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.results-score { display: flex; flex-direction: column; gap: 8px; padding: 18px; }
.score-label { color: var(--bb-muted); font-size: 15px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
#results-score { color: var(--bb-gold); font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.results-bank { color: var(--bb-muted); font-size: 16px; font-weight: 600; }
.level-table { width: 100%; margin: 8px 0; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
.level-table th { padding: 6px 8px; color: var(--bb-muted); font-size: 14px; font-weight: 700; text-align: left; border-bottom: 2px solid var(--bb-line); }
.level-table td { padding: 6px 8px; border-bottom: 1px solid var(--bb-line-soft); }
.level-table td:last-child, .level-table th:last-child { text-align: right; }
.level-table tr.not-cleared td { color: var(--bb-muted); }
.results-actions { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.results-side { display: flex; flex-direction: column; gap: 18px; }
.results-side .bb-leaderboard { padding: 16px; }
.missed { padding: 16px; }
.missed h2 { margin: 0 0 8px; font-size: 18px; }
.missed ul { margin: 0; padding-left: 20px; }
.missed li { margin-bottom: 8px; font-size: 16px; }
.missed li b { color: var(--bb-good); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ---- small screens: the start columns stack and the page scrolls ------------------------------- */
@media (max-width: 980px) {
  .start-screen { height: auto; overflow: visible; }
  .start-columns { grid-template-columns: minmax(0, 1fr); }
  .topic-list { max-height: 360px; }
  .results-layout { grid-template-columns: minmax(0, 1fr); }
  .game-header { grid-template-columns: auto 1fr; }
  .game-brand h2, .game-divider { display: none; }
  .game-header-actions { grid-column: 1 / -1; grid-row: 2; justify-content: center; padding-bottom: 6px; }
  .game-header { flex-basis: auto; padding-top: 6px; }
  .answers { grid-template-columns: minmax(0, 1fr); }
  .question-panel { min-height: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .clock.red, .pop { animation: none; }
}
