.stage{max-width:780px}
.turnbar{--tb-msg-lines:2;--tb-st-lines:1;--tb-rt:0px}
.turnbar .message{font-size:16px}
#play-area{max-width:none}
.route-summary{display:flex;flex-wrap:wrap;gap:6px 14px;margin:0 0 10px;font-size:16px;line-height:1.4}
#next-target{font-weight:600;color:var(--accent)}
#contact-budget{margin-left:auto}
.maze-layout{display:grid;grid-template-columns:minmax(0,460px) minmax(0,1fr);gap:18px;align-items:start}
.maze-board,.maze-dock{min-width:0}
.maze-board{position:relative}
#board{border-radius:6px;--surface:#fffdf7;--line:#e7e3d9;--line-strong:#6d726c}
#board:focus-visible,#pad:focus-visible{outline:3px solid var(--accent);outline-offset:3px}
#board-wrap.holding #token-halo{stroke-dasharray:none}
.checkpoint .next-ring{visibility:hidden}
.checkpoint.current .next-ring{visibility:visible}
.goal-flag,.start-ring,.goal-ring,#token-halo,.checkpoint,.endpoint,.route-guide{pointer-events:none}
#pad{flex-direction:column;gap:4px;min-height:86px;margin:0 0 8px;padding:10px;text-align:center;font-size:16px;line-height:1.35}
#pad svg{width:34px;height:24px;fill:none;stroke:currentColor;stroke-width:2}
#pad.active{background:var(--accent-light,var(--surface));color:var(--accent)}
#pad[aria-disabled=true]{opacity:.55}
.primary-actions{display:grid;grid-template-columns:1fr;gap:8px;margin:8px 0}
.primary-actions .btn{min-height:44px;width:100%}
/* No241: the four direction buttons stay removed; Wait stands alone and only appears on stages with moving devices. */
#wait{display:flex;align-items:center;justify-content:center;gap:6px;width:100%;min-height:44px;margin:8px 0}
.stage:not([data-devices=true]) #wait{display:none}
/* After a finish or a final contact, the result takes the place of the controls, right beside/below the board. */
.stage:is([data-phase=won],[data-phase=lost]) :is(#pad,.primary-actions,#wait){display:none}
.maze-legend{display:flex;gap:12px;flex-wrap:wrap;font-size:14px;line-height:1.4;margin:8px 0 0;color:var(--ink-sub)}
.maze-legend span{display:inline-flex;align-items:center;gap:5px}
.legend-dot{display:inline-block;width:10px;height:10px;border-radius:50%;background:radial-gradient(circle at 35% 30%,#f4fafc,#597487 60%,#203743);border:1px solid #385669}
.legend-wall{display:inline-block;width:14px;height:14px;background:#333d44;border:2px solid #c4875a}
.legend-zone{display:inline-block;width:14px;height:14px;background:repeating-linear-gradient(45deg,#e0a526 0 3px,#1d2226 3px 6px);border:1px solid #1d2226}
.legend-bay{display:inline-block;width:14px;height:12px;border:2px dashed #2e9a58;border-radius:3px}
.legend-plate{display:inline-block;width:14px;height:10px;background:#2f6b46;border:1px solid #173a24;border-radius:2px}
.legend-lamps{display:inline-flex;gap:2px}
.legend-lamps b{display:inline-block;width:8px;height:8px;border-radius:50%;border:1px solid #11181d}
.legend-lamps b:nth-child(1){background:#4fd27f}
.legend-lamps b:nth-child(2){background:#f0b429}
.legend-lamps b:nth-child(3){background:#ff5440}
.stage:not([data-devices=true]) .legend-device{display:none}
.stage:not([data-switches=true]) .legend-switch{display:none}
#input-note,#record{margin:10px 0;min-height:0}
.aux-tools{margin-top:12px;font-size:14px}
.aux-tools summary{cursor:pointer;min-height:44px;display:flex;align-items:center}
#result{margin:8px 0}
#result .controls{gap:8px}
#result .btn{width:100%;min-height:44px}
#setup label{display:grid;gap:6px;font-size:16px}
#setup select{font:inherit;font-size:16px;min-height:44px;max-width:100%;color:var(--ink);background:var(--surface);border:1px solid var(--line-strong);border-radius:4px;padding:8px}
[hidden]{display:none!important}
.guide-screen{position:relative;width:100%;max-width:358px}
.guide-screen img{display:block;width:100%;max-width:100%;height:auto}
.guide-annotation{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
.howto figcaption{font-size:16px;line-height:1.6;margin-top:10px;max-width:540px}
@media(max-width:620px){
 .turnbar{--tb-st-lines:2}
 .maze-layout{grid-template-columns:minmax(0,1fr);gap:8px}
 .route-summary{gap:4px 10px;margin-bottom:8px;font-size:16px}
 #contact-budget{margin-left:0}
 /* Slide pad on the left, Wait on the right (device stages), Pause/Release below: the board keeps the screen. */
 .maze-dock{display:grid;grid-template-columns:minmax(0,1fr) auto;column-gap:10px;align-items:stretch}
 .maze-dock>*{grid-column:1/-1}
 #pad{grid-row:1;min-height:98px;margin:0;gap:6px;padding:8px}
 .stage[data-devices=true] #pad{grid-column:1}
 #pad svg{flex:none}
 #wait{grid-column:2;grid-row:1;flex-direction:column;gap:4px;width:auto;min-width:72px;margin:0}
 .primary-actions{grid-template-columns:1fr 1fr;margin:8px 0 0}
 .primary-actions .btn{font-size:16px}
 #record{font-size:14px}
}
/* English on 360–374px: the longest message (device-range contact) takes 3 lines; reserve them before play. */
@media(max-width:374px){:root:lang(en) .turnbar{--tb-msg-lines:3}}
@media(prefers-color-scheme:dark){#board{--surface:#fffdf7;--line:#e7e3d9;--line-strong:#6d726c;--ink:#213a35;--ink-sub:#48564f}}

/* The metal board keeps one fixed palette in both page themes. */
#board{--accent:#245779;--ok:#286843;--ng:#bb3030}
.danger-area{fill:#333d44}
.checkpoint .waypoint{fill:#56676f}
.checkpoint.passed .waypoint{fill:#2e7a4d}
.cp-badge circle{fill:#182127;stroke:#9fadb5;stroke-width:1.5}
.cp-badge text{fill:#eef3f5}
.checkpoint.current .cp-badge circle{fill:#f5f2ea;stroke:#2f6a96;stroke-width:3}
.checkpoint.current .cp-badge text{fill:#17232b}
.checkpoint.passed .cp-badge circle{fill:#2e7a4d;stroke:#c3ead0}
.checkpoint.passed .cp-badge text{fill:#fff}
.endpoint-label{fill:#dfe6ea;font-weight:600}
.ep-key{fill:#fff}
.goal-ring{stroke:#7d8d95;stroke-dasharray:3 3}
.stage[data-phase=won] .goal-ring{stroke:#2e9a58;stroke-dasharray:none}
#goal-glow{stroke:#4fc67c}
#halo,.cp-badge,.spark-burst,.spark-ring,#goal-glow{transform-box:fill-box;transform-origin:center}
/* Paused until Continue: the plate dims slightly; marks, marker and contact point stay bright. */
#hold-veil{transition:opacity var(--dur)}
#board-wrap[data-hold=true] #hold-veil{opacity:.26}
/* Lamp: green while tracing or after a finish, red after a contact, dark otherwise. */
.lamp-lens{fill:#2a3034;stroke:#0b0f12;stroke-width:1;transition:fill var(--dur)}
.lamp-glow{fill:transparent}
#board-wrap:is([data-lamp=on],[data-lamp=done]) .lamp-lens{fill:#4fd27f}
#board-wrap:is([data-lamp=on],[data-lamp=done]) .lamp-glow{fill:#4fd27f;fill-opacity:.28}
#board-wrap[data-lamp=alert] .lamp-lens{fill:#ff5440}
#board-wrap[data-lamp=alert] .lamp-glow{fill:#ff5440;fill-opacity:.32}
@media(prefers-reduced-motion:reduce){#hold-veil,.lamp-lens{transition:none}}

/* Stage devices (fixed board palette). Every shape is drawn at the rectangle the rules test against. */
.dev-zone{opacity:.5}
.bay{fill:none;stroke:#3cc46e;stroke-width:2;stroke-dasharray:5 4}
.housing{fill:#1b2226;stroke:#5d6a72;stroke-width:1}
.dev-bar{stroke:#10171b;stroke-width:1}
.dev-face{fill:#e2492f}
.plate-face{fill:#7a5236;stroke:#2b1a10;stroke-width:1}
.plate-mark{stroke:#f3d29b;stroke-width:1.8;stroke-linejoin:round;stroke-linecap:round}
.plate[data-state=warn] .plate-face{fill:#8a5c2c;stroke:#f0b429;stroke-width:2}
.plate[data-state=warn][data-blink=true] .plate-face{fill:#b77a2a}
.plate[data-state=live] .plate-face{fill:#d8462c;stroke:#ffd27a;stroke-width:2}
.plate[data-state=live] .plate-mark{stroke:#fff}
.switch-plate{fill:#2f6b46;stroke:#9fe0b4;stroke-width:1.5}
.switch-cap{fill:#5fd08a;stroke:#173a24;stroke-width:1.5;transform-box:fill-box;transform-origin:center}
.switch[data-armed=true] .switch-cap{fill:#d6ffe4}
/* Device lamps: colour plus a mark inside (none = go, ! = about to move, bar = shut, zigzag = live). */
.dev-lamp .lamp-ring{fill:#12191d;stroke:#8d9aa2;stroke-width:1.2}
.dev-lamp .lens{fill:#2a3034}
.dev-lamp .glyph{fill:none;stroke:#10161a;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;visibility:hidden}
.dev-lamp:is([data-state=open],[data-state=off]) .lens{fill:#4fd27f}
.dev-lamp[data-state=warn] .lens{fill:#f0b429}
.dev-lamp:is([data-state=shut],[data-state=live]) .lens{fill:#ff5440}
.dev-lamp[data-state=warn] .glyph-warn,.dev-lamp[data-state=shut] .glyph-shut,.dev-lamp[data-state=live] .glyph-live{visibility:visible}
.gauge-ring{stroke:#9fe0b4}
.dev-lamp[data-state=warn] .gauge-ring{stroke:#f0b429}
@media(prefers-reduced-motion:reduce){.plate[data-state=warn][data-blink=true] .plate-face{fill:#8a5c2c}}
