/* Bridge Test. Colours are Book 2's theme colours (rust, sky blue, peach, espresso ink). */
:root {
  color-scheme: light;
  --rust: #A63D17; --rust-dark: #7F2E10; --sky: #9AD8F5; --blue: #1B4F9C; --river: #3F8FD6; --plum: #6B3FA0;
  --green: #2B8A3E; --amber: #F2A541; --amber-dark: #E08E1F; --peach: #FFF2E2; --ink: #33261F; --muted: #6E5E54;
  --white: #FFFFFF; --line: #F0D9BF;
  --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(--peach); 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(--plum); outline-offset: 2px; }

/* ---- Top bar ---- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; background: var(--rust); 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(--sky); 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) 350px; 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.1fr 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(--rust); }
.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: #F8E1C4; box-shadow: 0 2px 0 var(--line); }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.who { position: absolute; bottom: 3%; width: auto; transition: transform .25s; }
.who-zuri { left: 1%; }
.who-grandma { right: 1%; }
.who.bob { animation: bob .5s ease-out; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-3%); } }
.say { position: absolute; top: 3%; max-width: 34%; 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(51, 38, 31, .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-zuri { left: 2%; }
.say-zuri::after { left: 22%; }
.say-grandma { right: 2%; }
.say-grandma::after { right: 24%; }
.say-grandma.is-insp { color: var(--rust); border-color: var(--rust); font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.counter { position: absolute; top: 3%; left: 50%; transform: translateX(-50%); margin: 0; background: var(--white); border: 3px solid var(--amber); border-radius: 999px; padding: .15em .8em; font-size: clamp(.8rem, 1.8vw, 1.2rem); font-weight: 700; white-space: nowrap; }
.counter strong { font-size: 1.45em; color: var(--ink); }
.counter.is-goal { border-color: var(--green); background: #EAF6EC; }
.stamp { position: absolute; 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.2rem, 4.2vw, 2.8rem); letter-spacing: .04em; white-space: nowrap; animation: stamp-in .35s cubic-bezier(.2, 1.6, .5, 1); }
.stamp.is-open { color: var(--green); }
.stamp.is-closed { color: var(--blue); }
.stamp.is-held { color: var(--rust); }
@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; left: 50%; bottom: 2.5%; transform: translateX(-50%); width: 58%; margin: 0; padding: .4em .8em; border-radius: 12px; background: rgba(255, 255, 255, .93); text-align: center; font-weight: 700; font-size: clamp(.68rem, 1.45vw, 1rem); line-height: 1.3; box-shadow: 0 2px 0 rgba(51, 38, 31, .12); }
.caption:empty { display: none; }

/* scene animations (SVG groups) */
#scene .pop { transform-box: fill-box; transform-origin: 50% 100%; animation: pop .45s ease-out; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

/* result card */
.result { margin-top: 12px; background: var(--white); border-radius: var(--radius); border: 4px solid var(--rust); padding: 14px 18px; box-shadow: 0 6px 18px rgba(51, 38, 31, .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(--rust); text-transform: uppercase; }
.result h2 { margin: 0 0 4px; font-size: clamp(1.05rem, 2.4vw, 1.6rem); color: var(--rust); }
.result h2:focus { outline: none; }
.result p { margin: 4px 0; }
.result .guess-note { font-weight: 700; }
.result .hint { font-weight: 700; color: var(--plum); }
.result .guess-note:empty, .result .hint:empty { display: none; }
.result.is-pass { border-color: var(--green); }
.result.is-pass h2 { color: var(--green); }
.result.is-fail { border-color: var(--blue); }
.result.is-fail h2 { color: var(--blue); }
.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; 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(--peach); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.mission p { margin: 0; }
.mission-step { font-weight: 800; color: var(--rust); }
.mission-text { margin: 4px 0 2px !important; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--rust-dark); font-weight: 700; text-decoration: underline; cursor: pointer; text-align: left; }
.links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; }

.bridges { display: grid; gap: 10px; }
.bridge-btn { display: grid; grid-template-columns: 118px 1fr; align-items: center; gap: 12px; text-align: left; padding: 10px; border: 3px solid var(--line); border-radius: 14px; background: var(--white); cursor: pointer; transition: transform .1s, border-color .1s; }
.bridge-btn:hover { border-color: var(--rust); transform: translateY(-2px); }
.bridge-btn svg { width: 118px; height: 68px; display: block; }
.bridge-btn .b-num { display: block; font-size: .78rem; font-weight: 800; letter-spacing: .12em; color: var(--rust); text-transform: uppercase; }
.bridge-btn .b-name { display: block; font-weight: 800; font-size: 1.08rem; }
.bridge-btn .b-cap { display: block; font-size: .86rem; color: var(--muted); margin-top: 2px; }
.bridge-btn .b-done { display: inline-block; margin-top: 4px; font-size: .8rem; font-weight: 800; border-radius: 999px; padding: 1px 8px; color: var(--white); }
.b-done.is-pass { background: var(--green); }
.b-done.is-fail { background: var(--blue); }
.key { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 0; font-size: .8rem; color: var(--muted); }
.key span.swatch::before { content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 5px; border: 1px solid var(--ink); vertical-align: -1px; background: var(--k); }

.guess-q { font-weight: 800; font-size: 1.1rem; margin: 0 0 10px; }
.picker { display: flex; align-items: center; justify-content: center; gap: 14px; }
.pick-btn { width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--rust); background: var(--white); color: var(--rust); font-size: 1.8rem; font-weight: 800; line-height: 1; cursor: pointer; }
.pick-btn:hover:not(:disabled) { background: var(--peach); }
.pick-btn:disabled { opacity: .35; cursor: default; }
.guess-num { min-width: 2.4em; text-align: center; font-size: 3rem; font-weight: 900; color: var(--ink); }
.quick { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 12px 0 14px; }
.quick button { min-width: 46px; min-height: 40px; border-radius: 999px; border: 2px solid var(--line); background: var(--white); font-weight: 800; cursor: pointer; }
.quick button:hover { border-color: var(--rust); }
.quick button[aria-pressed="true"] { background: var(--sky); border-color: var(--sky); }

.coin-btn { width: 100%; font-size: 1.35rem; min-height: 64px; }
.coin-ico { width: 1.6em; height: 1.6em; }
.count-line { text-align: center; font-size: 1.1rem; margin: 12px 0 4px; }
.count-line strong { font-size: 1.3em; }
.your-guess { text-align: center; color: var(--muted); margin: 0; }
.your-guess:empty { display: none; }

/* ---- 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(--green); color: var(--white); }
.btn-green:hover:not(:disabled) { background: #22702F; }
.btn-amber { background: var(--amber); color: var(--ink); box-shadow: 0 4px 0 var(--amber-dark); }
.btn-amber:hover:not(:disabled) { background: #F6B45C; }
.btn-amber:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--amber-dark); }
.btn-rust { background: var(--rust); color: var(--white); }
.btn-rust:hover:not(:disabled) { background: var(--rust-dark); }
.btn-white { background: var(--white); color: var(--ink); border-color: var(--line); }
.btn-white:hover:not(:disabled) { border-color: var(--rust); }

/* ---- Test sheet and chart ---- */
.sheet { width: 100%; border-collapse: collapse; }
.sheet th { background: var(--rust); 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: 1.15rem; height: 64px; }
.sheet td:first-child { text-align: left; }
.row-name { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.row-name svg { width: 72px; height: 42px; flex: none; }
.row-name b { color: var(--rust); }
.held-note { display: block; font-size: .72rem; font-weight: 700; color: var(--green); }
.dash { color: #C9B8A8; }
.mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--white); font-size: 1rem; }
.mark.is-pass { background: var(--green); }
.mark.is-fail { background: var(--blue); }
.mark.is-empty { border: 2px dashed var(--rust); background: transparent; }
.sheet tr.is-current td { background: #FFF8EC; }

.chart { position: relative; display: grid; gap: 10px; padding: 26px 0 4px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 8px; }
.bar-name { font-weight: 800; font-size: .92rem; }
.bar-name b { color: var(--rust); }
.bar-track { position: relative; height: 30px; }
.cbar { position: absolute; left: 0; top: 3px; bottom: 3px; border-radius: 0 6px 6px 0; transition: width .5s ease-out; min-width: 4px; }
.cbar.is-pass { background: var(--green); }
.cbar.is-fail { background: var(--blue); }
.bar-num { position: absolute; top: 50%; transform: translateY(-50%); font-weight: 900; font-size: 1.05rem; padding-left: 6px; white-space: nowrap; }
.bar-num.is-empty { font-weight: 600; font-size: .85rem; color: var(--muted); background: var(--white); padding: 0 6px 0 0; z-index: 1; }
.goal-line { position: absolute; top: -6px; bottom: -6px; border-left: 2px dashed var(--ink); pointer-events: none; }
.goal-line span { position: absolute; top: 0; transform: translateX(-50%); font-size: .78rem; font-weight: 800; white-space: nowrap; }
.summary { font-weight: 800; color: var(--rust); font-size: 1.05rem; margin: 12px 0 4px; }
.summary:empty { display: none; }

/* ---- Help ---- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(640px, 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(51, 38, 31, .5); }
.help-body { padding: 20px 24px; }
.help-body h2 { margin-top: 0; color: var(--rust); }
.help-body h3 { margin: 16px 0 4px; }
.help-body a { color: var(--rust-dark); }

/* ---- Smaller screens ---- */
@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: 36%; font-size: .64rem; padding: .35em .5em; border-width: 2px; }
  .counter { font-size: .66rem; padding: .05em .5em; border-width: 2px; }
  .caption { width: 64%; font-size: .62rem; padding: .3em .5em; }
  .bridge-btn { grid-template-columns: 90px 1fr; }
  .bridge-btn svg { width: 90px; height: 52px; }
  .sheet td { font-size: 1rem; height: 56px; padding: 4px; }
  .row-name svg { width: 52px; height: 30px; }
  .row-name { gap: 6px; font-size: .82rem; }
  .bar-row { grid-template-columns: 104px 1fr; }
  .result { padding: 10px 12px; }
  .result p { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
