/* Shared look for the Do-Along STEM games from Book 5 on. Each game's game.css sets the colours (the book's theme)
   and draws its own stage. Same layout as Books 1 to 4: the stage and the step panel on top, the log and chart below. */
:root {
  color-scheme: light;
  --main: #0E5A8A; --main-dark: #0A4568; --accent: #FF8C69; --accent-dark: #D9684A; --soft: #FFE3D8;
  --pass: #2B8A3E; --fail: #C2364A; --hint: #0F7B83;
  --ink: #1D2B45; --muted: #5C6680; --white: #FFFFFF; --line: #D5DEEA; --bg: #EEF4F9; --bg-deep: #DCE7F1;
  --font: "Century Gothic", "Avenir Next", "Avenir", "Nunito", "Segoe UI", system-ui, sans-serif;
  --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.4; }
button, select, output { font: inherit; color: inherit; }
img { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 1.2em; height: 1.2em; flex: none; }
:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 2px; }

/* ---- Top bar ---- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; background: var(--main); color: var(--white); }
.back { color: var(--white); text-decoration: none; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, .16); }
.back:hover { background: rgba(255, 255, 255, .28); }
.game-title { margin: 0; font-size: 1.5rem; letter-spacing: .02em; }
.goal-pill { margin: 0 auto 0 0; background: var(--soft); color: var(--ink); font-weight: 800; border-radius: 999px; padding: 6px 14px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tool { display: inline-flex; align-items: center; gap: 6px; border: 2px solid rgba(255, 255, 255, .55); background: transparent; color: var(--white); border-radius: 999px; padding: 6px 12px; min-height: 40px; cursor: pointer; font-weight: 700; }
.tool:hover { background: rgba(255, 255, 255, .16); }
#soundBtn .mute { display: none; }
#soundBtn[aria-pressed="false"] .mute { display: inline; }
#soundBtn[aria-pressed="false"] .waves { display: none; }
#voiceBtn .mute { display: none; }
#voiceBtn[aria-pressed="false"] .mute { display: inline; }
#voiceBtn[aria-pressed="false"] .lines { display: none; }

/* ---- Layout ---- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "stage controls" "sheet sheet"; gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
.stage-wrap { grid-area: stage; }
.control-panel { grid-area: controls; }
.sheet-panel { grid-area: sheet; display: grid; grid-template-columns: 1.15fr 1fr; gap: 24px; }
.panel { background: var(--white); border-radius: var(--radius); padding: 16px; box-shadow: 0 2px 0 var(--line); }
.panel h2 { margin: 0 0 10px; font-size: 1.15rem; color: var(--main); }
.muted { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }

/* ---- Stage ---- */
.stage { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--bg-deep); box-shadow: 0 2px 0 var(--line); }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer.bg { z-index: 0; }
.layer.front { z-index: 2; pointer-events: none; }
.who { position: absolute; width: auto; z-index: 1; transition: opacity .3s; }
.who.bob { animation: bob .45s ease-out; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-4%); } }
.say { position: absolute; z-index: 3; top: 3%; max-width: 29%; margin: 0; padding: .5em .75em; border-radius: 14px; background: var(--white); border: 3px solid var(--ink); font-weight: 700; font-size: clamp(.72rem, 1.5vw, 1rem); line-height: 1.25; box-shadow: 0 3px 0 rgba(30, 34, 64, .15); }
.say:empty { display: none; }
.say::after { content: ""; position: absolute; bottom: -12px; width: 18px; height: 18px; background: inherit; border: inherit; border-top: 0; border-left: 0; transform: rotate(45deg); }
.say-kid { left: 1.5%; }
.say-kid::after { left: 18%; }
.say-grown { right: 2%; }
.say-grown::after { right: 14%; }
.say.is-loud { color: var(--main); border-color: var(--main); font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.stamp { position: absolute; z-index: 3; top: 30%; left: 50%; margin: 0; transform: translate(-50%, 0) rotate(-7deg); padding: .2em .6em; border: 5px solid currentColor; border-radius: 12px; background: rgba(255, 255, 255, .92); font-weight: 900; font-size: clamp(1.1rem, 3.8vw, 2.6rem); letter-spacing: .04em; white-space: nowrap; animation: stamp-in .35s cubic-bezier(.2, 1.6, .5, 1); }
.stamp.is-pass { color: var(--pass); }
.stamp.is-fail { color: var(--fail); }
.stamp.is-info { color: var(--main); }
@keyframes stamp-in { from { transform: translate(-50%, 0) rotate(-7deg) scale(1.9); opacity: 0; } to { transform: translate(-50%, 0) rotate(-7deg) scale(1); opacity: 1; } }
.caption { position: absolute; z-index: 3; left: 50%; bottom: 2.5%; transform: translateX(-50%); width: 58%; margin: 0; padding: .4em .8em; border-radius: 12px; background: rgba(255, 255, 255, .94); text-align: center; font-weight: 700; font-size: clamp(.68rem, 1.45vw, 1rem); line-height: 1.3; box-shadow: 0 2px 0 rgba(30, 34, 64, .12); }
.caption:empty { display: none; }
.big-word { position: absolute; z-index: 3; margin: 0; transform: translate(-50%, -50%) rotate(-6deg); font-weight: 900; font-size: clamp(1rem, 3.4vw, 2.3rem); color: var(--main); -webkit-text-stroke: 1px var(--white); paint-order: stroke; text-shadow: 0 3px 0 rgba(255, 255, 255, .9); pointer-events: none; animation: stamp-in .3s ease-out; white-space: nowrap; }

/* result card */
.result { margin-top: 12px; background: var(--white); border-radius: var(--radius); border: 4px solid var(--main); padding: 14px 18px; box-shadow: 0 6px 18px rgba(30, 34, 64, .14); text-align: center; animation: pop-card .35s ease-out; }
.result-kicker { margin: 0 0 2px; font-size: .8rem; font-weight: 800; letter-spacing: .14em; color: var(--main); text-transform: uppercase; }
.result h2 { margin: 0 0 4px; font-size: clamp(1.05rem, 2.4vw, 1.6rem); color: var(--main); }
.result h2:focus { outline: none; }
.result p { margin: 4px 0; }
.result .guess-note { font-weight: 700; }
.result .hint { font-weight: 700; color: var(--hint); }
.result .guess-note:empty, .result .hint:empty, .result p:empty { display: none; }
.result.is-pass { border-color: var(--pass); }
.result.is-pass h2 { color: var(--pass); }
.result.is-fail { border-color: var(--fail); }
.result.is-fail h2 { color: var(--fail); }
.result-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
@keyframes pop-card { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.confetti { position: absolute; z-index: 3; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 3px; animation: fall 2.2s ease-in forwards; }
@keyframes fall { to { transform: translateY(620px) rotate(540deg); opacity: .9; } }

/* ---- Controls ---- */
.mission { background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.mission p { margin: 0; }
.mission-step { font-weight: 800; color: var(--main); }
.mission-text { margin: 4px 0 2px !important; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--main); font-weight: 700; text-decoration: underline; cursor: pointer; text-align: left; }
.link-btn:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; }

.checks { display: grid; gap: 10px; }
.check { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 3px solid var(--line); border-radius: 14px; background: var(--white); cursor: pointer; text-align: left; min-height: 64px; }
.check:hover:not(:disabled) { border-color: var(--main); }
.check .tick { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 3px solid var(--main); background: var(--white); }
.check[aria-pressed="true"] { border-color: var(--pass); background: #EEF8F0; }
.check[aria-pressed="true"] .tick { background: var(--pass); border-color: var(--pass); }
.check[aria-pressed="true"] .tick::after { content: ""; width: 9px; height: 17px; border: solid var(--white); border-width: 0 4px 4px 0; transform: translateY(-2px) rotate(45deg); }
.check .c-name { display: block; font-weight: 800; font-size: 1rem; line-height: 1.2; }
.check .c-sub { display: block; font-size: .82rem; color: var(--muted); line-height: 1.2; margin-top: 2px; }

.choose { border: 0; margin: 0 0 12px; padding: 0; min-width: 0; }
.choose legend { padding: 0; margin-bottom: 6px; font-weight: 800; }
.num { display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; margin-right: 4px; border-radius: 50%; background: var(--soft); font-size: .9em; }
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choices.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; border: 3px solid var(--line); border-radius: 14px; background: var(--white); cursor: pointer; text-align: center; transition: transform .1s, border-color .1s; min-height: 44px; }
.choice:hover:not(:disabled) { border-color: var(--main); transform: translateY(-2px); }
.choice[aria-pressed="true"] { border-color: var(--main); background: var(--soft); box-shadow: 0 0 0 2px var(--accent) inset; }
.choice:disabled { opacity: .5; cursor: default; }
.choice svg { width: 76px; height: 44px; display: block; }
.choice img { height: 44px; width: auto; }
.choice .c-name { font-weight: 800; font-size: .95rem; line-height: 1.15; }
.choice .c-sub { font-size: .78rem; color: var(--muted); line-height: 1.15; }
.choice .done-tag { font-size: .72rem; font-weight: 800; color: var(--pass); }
.tip { margin: 8px 0 0; font-size: .86rem; color: var(--muted); text-align: center; }

.guess-q { font-weight: 800; font-size: 1.1rem; margin: 0 0 10px; }
.guesses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.guesses.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.your-guess { text-align: center; color: var(--muted); margin: 10px 0 0; font-weight: 700; }
.your-guess:empty { display: none; }
.counter { text-align: center; font-weight: 900; font-size: 2.4rem; color: var(--main); margin: 6px 0 2px; line-height: 1; }
.counter small { display: block; font-size: .85rem; font-weight: 700; color: var(--muted); margin-top: 4px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 8px 18px; border-radius: 999px; border: 3px solid transparent; font-weight: 800; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.15rem; }
.btn-green { background: var(--pass); color: var(--white); }
.btn-green:hover:not(:disabled) { background: #22702F; }
.btn-accent { background: var(--accent); color: var(--ink); box-shadow: 0 4px 0 var(--accent-dark); }
.btn-accent:hover:not(:disabled) { filter: brightness(1.07); }
.btn-accent:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn-main { background: var(--main); color: var(--white); }
.btn-main:hover:not(:disabled) { background: var(--main-dark); }
.btn-white { background: var(--white); color: var(--ink); border-color: var(--line); }
.btn-white:hover:not(:disabled) { border-color: var(--main); }
.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }

/* ---- Log, chart and reward ---- */
.sheet { width: 100%; border-collapse: collapse; }
.sheet th { background: var(--main); color: var(--white); text-align: center; padding: 8px 6px; font-size: .9rem; }
.sheet th:first-child { text-align: left; padding-left: 10px; }
.sheet td { border: 2px solid var(--ink); padding: 6px; text-align: center; font-weight: 800; font-size: .95rem; height: 54px; }
.sheet td:first-child { text-align: left; }
.sheet tr.is-new td { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { background: #FFE6B8; } 100% { background: transparent; } }
.row-set { display: flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 700; line-height: 1.2; }
.row-set b { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--main); color: var(--white); font-size: .95rem; }
.row-set svg { width: 54px; height: 32px; flex: none; }
.cell-icon { display: inline-flex; flex-direction: column; align-items: center; font-size: .8rem; line-height: 1.1; }
.cell-icon svg { width: 60px; height: 30px; }
.dash { color: #B6BCD4; }
.mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: var(--white); font-size: 1rem; }
.mark.is-pass { background: var(--pass); }
.mark.is-fail { background: var(--fail); }
.empty { color: var(--muted); font-size: .92rem; margin: 10px 0 2px; }
.chart { display: grid; gap: 8px; padding: 4px 0; }
.chart-empty { color: var(--muted); font-size: .9rem; margin: 0; }
.chart-note { color: var(--muted); font-size: .78rem; margin: 2px 0 0; }
.summary { font-weight: 800; color: var(--main); font-size: 1.05rem; margin: 12px 0 4px; }
.summary:empty { display: none; }
.status { margin-top: 14px; border-radius: 14px; padding: 12px 14px; background: var(--bg); border: 3px dashed var(--line); }
.status p { margin: 0 0 6px; }
.status-head { font-weight: 800; }
.status-word { display: inline-block; border-radius: 6px; padding: 1px 8px; color: var(--white); background: var(--fail); letter-spacing: .06em; }
.status.is-ready { border-style: solid; border-color: var(--accent); background: var(--soft); }
.status.is-ready .status-word, .status.is-done .status-word { background: var(--pass); }
.status.is-done { border-style: solid; border-color: var(--pass); background: #EEF8F0; }
.status-text { font-size: .92rem; }

/* ---- Help ---- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(660px, calc(100% - 32px)); max-height: calc(100% - 32px); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(30, 34, 64, .5); }
.help-body { padding: 20px 24px; }
.help-body h2 { margin-top: 0; color: var(--main); }
.help-body h3 { margin: 16px 0 4px; }
.help-body a { color: var(--main); }

/* ---- Smaller screens ---- */
/* Grid children may shrink below their content's width, so a wide table or picture never widens the whole page on a phone. */
.game > *, .sheet-panel > * { min-width: 0; }
@media (max-width: 980px) {
  .game { grid-template-columns: 1fr; grid-template-areas: "stage" "controls" "sheet"; }
  .sheet-panel { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .game { padding: 10px; gap: 10px; }
  .game-title { font-size: 1.2rem; }
  .bar { padding: 8px 10px; }
  .goal-pill { padding: 4px 10px; font-size: .85rem; }
  .tool { padding: 4px 10px; }
  .say { max-width: 34%; font-size: .62rem; padding: .35em .5em; border-width: 2px; }
  .say::after { width: 10px; height: 10px; bottom: -7px; }
  .caption { width: 64%; font-size: .62rem; padding: .3em .5em; }
  .choice svg { width: 60px; height: 34px; }
  .choice .c-name { font-size: .86rem; }
  .sheet td { font-size: .85rem; height: 50px; padding: 4px; }
  .row-set { font-size: .78rem; gap: 5px; }
  .result { padding: 10px 12px; }
  .result p { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
