* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; overflow: hidden; font-family: Georgia, 'Palatino Linotype', 'Times New Roman', serif; }
body { background: #14110c; color: #2a241c; }
#canvas-wrap, #canvas-wrap canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
/* A soft cinematic frame: darker corners draw the eye to the scene (CSS only, no GPU cost). */
#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse 85% 75% at 50% 48%, transparent 58%, rgba(10, 6, 4, 0.34) 100%); }
/* A short dip to black hides a lesson's jump to its viewing spot. */
#fade { position: fixed; inset: 0; z-index: 19; background: #0d0a06; opacity: 0; pointer-events: none; transition: opacity 0.28s ease; }
#fade.on { opacity: 1; }
[hidden] { display: none !important; }

/* ---- overlays share .panel ---- */
#start-screen, #victory, #pause-overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 12, 6, 0.82); padding: 16px; overflow-y: auto;
}
/* The title lets the living street and sky show through. */
#start-screen { background: radial-gradient(ellipse 70% 65% at 50% 50%, rgba(16, 12, 6, 0.38), rgba(16, 12, 6, 0.74)); }
#start-screen .panel { box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55); }
#start-screen h1::before { content: '⚜'; display: block; margin-bottom: 2px; font-size: 1.5rem; color: #c9a13b; }
.panel {
  background: #f3ead7; border: 3px double #7a5b23; border-radius: 10px;
  max-width: 560px; width: 100%; padding: 28px 26px; text-align: center;
  box-shadow: 0 12px 60px rgba(0,0,0,0.6); margin: auto;
}
.panel h1 { font-size: 2rem; color: #7a2f33; letter-spacing: 0.02em; }
.subtitle { color: #6b5a3a; font-style: italic; margin: 6px 0 14px; }
.premise, .controls-hint { margin: 10px 0; line-height: 1.45; }
.fineprint { margin-top: 14px; font-size: 0.85rem; color: #6b5a3a; }
button {
  font: inherit; cursor: pointer; border-radius: 8px; border: 2px solid #7a5b23;
  background: #c9a13b; color: #241c0c; padding: 12px 26px; font-size: 1.05rem; margin-top: 12px;
}
button:hover { filter: brightness(1.08); }

/* ---- HUD ---- */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center;
  gap: 12px; padding: 10px 146px 10px 14px; pointer-events: none; }
#hud-score { background: rgba(20,16,8,0.72); color: #f3ead7; border: 1px solid #c9a13b;
  border-radius: 8px; padding: 6px 12px; font-size: 1.05rem; min-width: 90px; }
#hud-objective { flex: 1; text-align: center; color: #f3ead7; text-shadow: 0 2px 6px #000;
  font-style: italic; font-size: 0.98rem; background: rgba(20,16,8,0.8); padding: 8px; border-radius: 8px; }
#hud-torches { display: flex; gap: 4px; }
#hud-torches .slot { font: 600 0.72rem/1 system-ui, sans-serif; letter-spacing: 0.03em; padding: 6px 7px;
  border-radius: 6px; border: 1px solid #6b5a3a; color: #b8ab8d; background: rgba(20,16,8,0.6); }
#hud-torches .slot.lit { color: #241c0c; background: #c9a13b; border-color: #f3dc8e;
  box-shadow: 0 0 10px rgba(201,161,59,0.7); }
#mute-btn { pointer-events: auto; margin: 0; padding: 4px 10px; font-size: 1rem;
  background: rgba(20,16,8,0.72); color: #f3ead7; border-color: #6b5a3a; position: relative; z-index: 35; }

#interact-prompt { position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: rgba(20,16,8,0.8); color: #f3ead7; border: 1px solid #c9a13b; border-radius: 8px;
  padding: 8px 16px; font-size: 1rem; }

/* ---- quiz overlay ---- */
#quiz-root { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center;
  justify-content: center; background: rgba(16,12,6,0.78); padding: 14px; overflow-y: auto; }
.quiz-panel { background: #f3ead7; border: 3px double #7a5b23; border-radius: 10px;
  max-width: 620px; width: 100%; padding: 22px; margin: auto; }
.quiz-zone { color: #7a2f33; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; }
.quiz-progress { float: right; color: #6b5a3a; font-size: 0.85rem; }
.quiz-prompt { margin: 12px 0 16px; font-size: 1.12rem; line-height: 1.4; }
.quiz-prompt.quote { font-style: italic; }
.quiz-listen { margin: 0 0 10px; padding: 7px 12px; min-height: 44px; font-size: .85rem; }
.quiz-intro { margin: 10px 0 4px; font-size: 0.9rem; color: #6b5a3a; font-style: italic; line-height: 1.4; }
.quiz-hint { font-size: 0.9rem; color: #6b5a3a; margin-bottom: 8px; }
.shake { animation: shake 0.3s; }
.quiz-options { display: grid; gap: 10px; }
.quiz-options button, .chip {
  text-align: left; background: #fff9ec; border: 2px solid #b09a6a; color: #2a241c;
  padding: 11px 14px; margin: 0; font-size: 1rem; border-radius: 8px;
}
.quiz-options button.wrong { border-color: #a33; background: #f6dcd6; animation: shake 0.3s; }
.quiz-options button.right { border-color: #2c7a3f; background: #ddeed9; }
.chip.selected { border-color: #7a2f33; background: #f0dfc0; }
.chip.placed { opacity: 0.45; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.bins.wide { grid-template-columns: 1fr; }
.bins.wide .bin { min-height: 0; }
.bin { border: 2px dashed #b09a6a; border-radius: 8px; min-height: 74px; padding: 8px; font-size: 0.85rem;
  background: none; text-align: left; font: inherit; cursor: pointer; margin: 0; color: #2a241c; }
.bin.active { border-color: #7a2f33; background: #f0dfc0; }
.bin.flash-wrong { border-color: #a33; background: #f6dcd6; animation: shake 0.3s; }
.bin .placed-item { display: block; font-size: 0.82rem; margin-top: 4px; color: #2c7a3f; }
.order-slots { display: grid; gap: 6px; margin-top: 10px; }
.order-slots .filled { border: 2px solid #2c7a3f; border-radius: 8px; padding: 8px 10px;
  background: #ddeed9; font-size: 0.92rem; }
.order-slots .empty-slot { border: 2px dashed #b09a6a; border-radius: 8px; padding: 8px 10px;
  color: #8a7a58; font-size: 0.92rem; }
.explain-box { margin-top: 14px; border-left: 4px solid #c9a13b; background: #fff9ec;
  padding: 10px 12px; text-align: left; line-height: 1.4; }
.explain-box.wrong-note { border-left-color: #a33; }
.points-earned { color: #2c7a3f; font-weight: bold; margin-top: 8px; }
.quiz-continue { display: block; margin-left: auto; margin-right: auto; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---- victory ---- */
.parchment h1 { font-size: 1.6rem; }
.victory-stats { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 14px 0; }
.stat { background: #fff9ec; border: 2px solid #b09a6a; border-radius: 8px; padding: 10px 18px; }
.stat-label { display: block; font-size: 0.75rem; color: #8a7a58; text-transform: uppercase; }
.stat span:last-child { font-size: 1.5rem; color: #7a2f33; }
.victory-title { font-size: 1.15rem; }
.screenshot-cta { margin-top: 12px; font-size: 1.02rem; background: #f0dfc0; border-radius: 8px; padding: 8px; }

/* ---- subtitles & cannon ---- */
#subtitle { position: fixed; top: 100px; left: 50%; transform: translateX(-50%); z-index: 28;
  width: min(720px, calc(100vw - 32px)); max-height: 36vh; overflow-y: auto; pointer-events: none;
  background: rgba(16,12,6,0.94); color: #f3ead7;
  border: 1px solid #c9a13b; border-left: 4px solid #c9a13b; border-radius: 8px;
  padding: 10px 16px; font-size: 1.05rem; line-height: 1.4; font-style: italic; text-align: center; }
#subtitle .speaker { display: block; margin-bottom: 3px; color: #e2b955; font: 700 0.72rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.14em; text-transform: uppercase; font-style: normal; }
#subtitle .line { display: block; }
#subtitle .line.spoken { font-style: normal; } /* dialogue upright, narration in italics */
#fire-btn { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 28;
  font-size: 1.3rem; padding: 16px 34px; background: #7a2f33; color: #f3ead7; border-color: #c9a13b;
  box-shadow: 0 6px 30px rgba(0,0,0,0.6); }
#fire-btn:active { transform: translateX(-50%) scale(0.96); }

/* ---- drag & drop ---- */
.chip.dragging { opacity: 0.35; }
.drag-ghost { position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -60%) rotate(-2deg);
  background: #fff9ec; border: 2px solid #7a2f33; color: #2a241c; padding: 11px 14px;
  font-size: 1rem; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  font-family: Georgia, 'Palatino Linotype', serif; }
.bin.drop-hover { border-color: #7a2f33; background: #f0dfc0; }
.order-slots.drop-hover { outline: 2px dashed #7a2f33; outline-offset: 4px; border-radius: 8px; }

/* ---- touch ---- */
#touch-ui { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
#joystick { position: absolute; left: 4vw; bottom: 5vh; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(243,234,215,0.15); border: 2px solid rgba(243,234,215,0.4); pointer-events: auto; touch-action: none; }
#joystick-knob { position: absolute; left: 38px; top: 38px; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(201,161,59,0.8); }
#touch-jump { position: absolute; right: 5vw; bottom: 6vh; width: 64px; height: 64px; border-radius: 50%;
  pointer-events: auto; font-size: 1.4rem; }
#touch-interact { position: absolute; right: 5vw; bottom: calc(6vh + 80px); pointer-events: auto; }

@media (max-width: 640px) {
  .panel { padding: 18px 14px; }
  .panel h1 { font-size: 1.45rem; }
  #hud { display: grid; grid-template-columns: auto 1fr; padding: 8px 146px 8px 10px; gap: 6px; }
  #hud-objective { font-size: 0.9rem; grid-row: 2; grid-column: 1 / -1; }
  #hud-torches { justify-content: flex-start; min-width: 0; }
  /* Five names don't fit beside the score on a phone: initials instead. */
  #hud-torches .slot { font-size: 0; padding: 4px 6px; }
  #hud-torches .slot::before { content: attr(data-short); font-size: 0.72rem; }
  #hud-objective { min-width: 0; }
  #subtitle { top: 135px; font-size: 0.96rem; max-height: 32vh; }
  #interact-prompt { display: none; }
  .bins { grid-template-columns: 1fr; }
  .quiz-prompt { font-size: 1rem; }
}
@media (max-height: 480px) {
  #subtitle { font-size: 0.92rem; max-height: 26vh; padding: 7px 12px; }
}

button:focus-visible, summary:focus-visible { outline: 3px solid #15798c; outline-offset: 3px; }
#pause-btn { position: fixed; z-index: 37; right: 12px; top: 10px; margin: 0; padding: 9px 12px; background: #243440; color: #fff5df; border-color: #b69c68; }
#mute-btn { position: fixed; top: 10px; right: 94px; z-index: 37; min-height: 40px; }
#sound-off-hint { position: fixed; top: 58px; right: 12px; z-index: 37; margin: 0; padding: 8px 12px;
  background: rgba(20,16,8,0.88); color: #f3ead7; border: 1px solid #c9a13b; border-radius: 8px;
  font-size: 0.9rem; max-width: calc(100vw - 24px); }
@media (max-width: 700px) { #sound-off-hint { top: 88px; } }
body:has(#victory:not([hidden])) #mute-btn { z-index: 41; }
#route-btn { position: fixed; z-index: 24; bottom: 22px; left: 50%; transform: translateX(-50%); background: #263f49; color: #fff4d9; max-width: calc(100vw - 40px); }
#skip-intro { position: fixed; z-index: 24; right: 16px; bottom: 18px; background: #243440cc; color: #f2ead6; border-color: #88a4ac; font-size: 0.85rem; padding: 10px 14px; }

@media (max-width: 700px) {
  #route-btn { bottom: 18px; max-width: calc(100vw - 165px); left: auto; right: 10px; transform: none; font-size: 0.9rem; padding: 12px; }
  #fire-btn { bottom: 24px; font-size: 1.05rem; }
  /* Stack jump above the one action button instead of across its top edge. */
  #touch-jump { right: 12px; bottom: 84px; width: 56px; height: 56px; }
}
@media (prefers-reduced-motion: reduce) { .shake, .quiz-options button.wrong, .bin.flash-wrong { animation: none; } }

/* ---- pause-menu sound settings ---- */
.sound-settings { margin-top: 18px; text-align: left; border: 1px solid #aa9364; border-radius: 8px;
  font-family: system-ui, sans-serif; color: #322c23; background: #fff9ec; }
.sound-settings summary { min-height: 44px; padding: 12px 14px; cursor: pointer; font-size: 0.98rem; font-weight: 650; }
.sound-settings-content { padding: 0 14px 10px; }
.sound-settings-note, .sound-settings-status { font-size: 0.84rem; line-height: 1.45; color: #5c503b; }
.sound-settings-note { margin: 0 0 12px; }
.sound-settings-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 10px; margin-top: 5px; }
.sound-settings-row label { font-size: 0.92rem; }
.sound-settings-row output { min-width: 4ch; text-align: right; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.sound-settings-row input[type="range"] { grid-column: 1 / -1; min-width: 0; width: 100%; height: 44px;
  margin: 0; padding: 0; accent-color: #356678; cursor: pointer; }
.sound-settings-row input:focus-visible { outline: 3px solid #15798c; outline-offset: 2px; border-radius: 5px; }
.sound-settings-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.sound-settings-presets button { flex: 1; min-height: 44px; margin: 0; padding: 9px 12px; font: 600 0.9rem/1.3 system-ui, sans-serif;
  background: #244959; color: #fff4d8; border-color: #244959; }
.sound-settings-status:not(:empty) { margin-top: 10px; }
@media (max-width: 400px) {
  .sound-settings-content { padding: 0 10px 10px; }
  .sound-settings summary { padding: 12px 10px; }
}

.start-controls { margin: 16px auto 0; font: 0.85rem/1.45 system-ui, sans-serif; }
.start-controls summary { cursor: pointer; padding: 10px; }

/* Courtroom word bursts (the rigged trial): ORDER!, GUILTY., OBJECTION!… */
#trial-burst {
  position: fixed;
  inset: 0;
  display: grid;
  justify-items: center;
  align-items: start;
  padding-top: clamp(175px, 33vh, 290px); /* under a two- or three-line caption, over the scene */
  pointer-events: none;
  z-index: 40;
}
#trial-burst span {
  max-width: min(92vw, 980px);
  text-align: center;
  font: 900 clamp(2rem, 7vw, 4.4rem)/1 Georgia, serif;
  letter-spacing: 0.04em;
  padding: 0.14em 0.4em;
  border: 0.09em solid currentColor;
  border-radius: 0.14em;
  background: rgba(20, 14, 10, 0.85);
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.55);
  animation: burst-pop 1.6s ease forwards;
}
.burst-guilty { color: #ff5a45; }
.burst-free { color: #ffd75e; }
.burst-objection { color: #f3ead7; }
.burst-order { color: #d8b45a; font-size: clamp(1.6rem, 5.5vw, 3rem) !important; }
/* Long phrases (UNTIL FRANCE HAS A CONSTITUTION…) read as a banner, not a wall. */
#trial-burst span.burst-banner { font-size: clamp(1.15rem, 3.4vw, 2.3rem); letter-spacing: 0.06em; }
@keyframes burst-pop {
  0% { transform: scale(0.2) rotate(-14deg); opacity: 0; }
  12% { transform: scale(1.16) rotate(-3deg); opacity: 1; }
  22% { transform: scale(1) rotate(-4.5deg); }
  78% { transform: scale(1) rotate(-4.5deg); opacity: 1; }
  100% { transform: scale(1.05) rotate(-4.5deg); opacity: 0; }
}

/* A stop's in-scene question: docked under the live scene, never a full
   overlay, so the answer can play out above it. */
#scene-q { position: fixed; z-index: 31; left: 50%; bottom: 14px; transform: translateX(-50%);
  width: min(700px, calc(100% - 24px)); max-height: 48vh; overflow-y: auto; }
.scene-q-panel { background: #f3ead7f7; border: 3px double #7a5b23; border-radius: 12px;
  padding: 12px 16px 14px; box-shadow: 0 10px 40px rgba(0,0,0,0.55); animation: scene-q-in 0.28s ease-out; }
.scene-q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scene-q-label { color: #7a2f33; font: 700 0.78rem/1 system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; }
.scene-q-listen { margin: 0; padding: 6px 10px; min-height: 36px; font-size: 0.85rem; }
.scene-q-prompt { margin: 8px 0 10px; font-size: 1.12rem; line-height: 1.35; font-weight: 600; }
.scene-q-prompt.quote { font-style: italic; }
.scene-q-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scene-q-options button { text-align: left; background: #fff9ec; border: 2px solid #b09a6a; color: #2a241c;
  padding: 10px 12px; margin: 0; font-size: 0.98rem; line-height: 1.3; border-radius: 8px; min-height: 48px; }
.scene-q-options button.wrong { border-color: #a33; background: #f6dcd6; animation: shake 0.3s; }
.scene-q-options button.right { border-color: #2c7a3f; background: #ddeed9; }
.scene-q-note { margin-top: 9px; padding: 8px 10px; border-left: 4px solid #a33; background: #fff9ec; line-height: 1.38; font-size: 0.95rem; }
.scene-q-note.right-note { border-left-color: #2c7a3f; color: #2c7a3f; font-weight: bold; }
@keyframes scene-q-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 600px) {
  #scene-q { bottom: 8px; width: calc(100% - 16px); max-height: 56vh; }
  .scene-q-options { grid-template-columns: 1fr; }
  .scene-q-prompt { font-size: 1rem; }
}
@media (max-height: 480px) and (min-width: 601px) {
  #scene-q { left: auto; right: 8px; transform: none; bottom: 8px; width: min(420px, 48%); max-height: calc(100vh - 70px); }
  .scene-q-options { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .scene-q-panel, .scene-q-options button.wrong { animation: none; } }

.victory-recap { margin: 14px 0 4px; text-align: left; background: #fff9ec; border: 2px solid #b09a6a; border-radius: 8px; padding: 10px 14px; }
.victory-recap h2 { font-size: 1rem; color: #7a2f33; margin-bottom: 6px; text-align: center; }
.victory-recap ul { padding-left: 18px; line-height: 1.45; font-size: 0.95rem; }

/* A question's document: a picture or a small bar chart, exam style. */
.q-figure { margin: 10px 0 4px; padding: 8px 10px; background: #fff9ec; border: 1px solid #c8b58a; border-radius: 8px; }
.q-figure img { display: block; width: 100%; max-height: 34vh; object-fit: contain; border-radius: 4px; background: #eee6d2; }
.q-figure figcaption { margin-top: 6px; font-size: 0.8rem; color: #6b5a3a; font-style: italic; }
.q-figure .bars-title { font-weight: bold; margin-bottom: 6px; color: #2a241c; }
.q-figure .bar-row { display: grid; grid-template-columns: minmax(7.5em, 38%) 1fr 3em; align-items: center; gap: 8px; margin: 3px 0; font-size: 0.88rem; }
.q-figure .bar-track { height: 14px; background: #ece2c8; border-radius: 3px; overflow: hidden; }
.q-figure .bar { display: block; height: 100%; background: #7a2f33; border-radius: 3px; }
.q-figure .bar-value { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .q-figure .bar-row { font-size: 0.8rem; grid-template-columns: minmax(6em, 42%) 1fr 2.6em; } }

/* A review card or the victory screen carries its own words: the caption
   strip behind it would only peek out around its edges. The voice plays on. */
body:has(#quiz-root:not([hidden])) #subtitle,
body:has(#victory:not([hidden])) #subtitle { visibility: hidden; }

/* Short laptop screens (Chromebooks with browser bars, split screens): a whole
   card, its chart or picture and all four answers stay in view without
   scrolling. Phones keep their own rules. */
@media (max-height: 700px) and (min-width: 641px) {
  .quiz-panel { padding: 14px 18px; }
  .quiz-prompt { margin: 8px 0 10px; font-size: 1.04rem; }
  .quiz-options { gap: 7px; }
  .quiz-options button, .chip { padding: 8px 12px; }
  .quiz-listen { min-height: 36px; margin-bottom: 6px; }
  .q-figure { margin: 6px 0 2px; padding: 6px 8px; }
  .q-figure img { max-height: 22vh; }
  .q-figure figcaption { margin-top: 3px; font-size: 0.74rem; }
  .q-figure .bars-title { margin-bottom: 3px; }
  .q-figure .bar-row { margin: 1px 0; font-size: 0.78rem; }
  .q-figure .bar-track { height: 10px; }
  .panel { padding: 16px 20px; }
  .parchment h1 { font-size: 1.35rem; margin: 0 0 4px; }
  .victory-stats { margin: 8px 0; }
  .victory-recap { font-size: 0.86rem; }
  .screenshot-cta { margin-top: 8px; padding: 6px; }
  /* The in-scene card fits whole, with room for a wrong answer's note. */
  .scene-q-panel { padding: 9px 14px 11px; }
  .scene-q-prompt { margin: 6px 0 8px; font-size: 1.02rem; }
  .scene-q-options { gap: 6px; }
  .scene-q-options button { padding: 7px 11px; min-height: 40px; font-size: 0.93rem; }
  .scene-q-note { margin-top: 7px; padding: 6px 9px; font-size: 0.9rem; }
}
/* Below 480px the card docks at the side instead, at its own height. */
@media (max-height: 700px) and (min-height: 481px) and (min-width: 641px) { #scene-q { max-height: 60vh; } }
/* Fingers need 44 px, however short the screen. */
@media (pointer: coarse) {
  .quiz-options button, .chip, .quiz-listen, .scene-q-listen, .scene-q-options button { min-height: 44px; }
}
/* Very short screens: the whole victory panel, Play Again included, without scrolling. */
@media (max-height: 580px) {
  #victory { padding: 8px; }
  #victory .subtitle { margin: 4px 0 8px; font-size: 0.92rem; }
  #victory .stat { padding: 6px 14px; }
  #victory .stat span:last-child { font-size: 1.3rem; }
  .victory-recap { margin-top: 8px; padding: 8px 12px; }
  .victory-recap ul { line-height: 1.35; }
}
