/* PEARL-MAN: stage-select menu, HUD and overlays.
   The maps and the enemy photos carry the look; each stage owns one colour.
   Rules marked LAYOUT are read by resizeGame() (js/ui_net.js) or the sprite offset in game.js. */
:root {
    --pm-bg: #110e0b;
    --pm-panel: #1c1813;
    --pm-panel-2: #28211a;
    --pm-line: #3b3229;
    --pm-ink: #f5ecdc;
    --pm-mute: #a99b8b;
    --pm-gold: #ffc21a;
    --pm-gold-deep: #a87400;
    --pm-shadow: #6e430f;
    --pm-red: #ff4b55;
    --pm-boss: #ff8f1f;
    --pm-rage: #ff5fa2;
    --pm-s1: #ff8a3d;
    --pm-s2: #2ec4b6;
    --pm-s3: #8cc63f;
    --pm-display: 'Dela Gothic One', 'Arial Black', Impact, sans-serif;
    --pm-ui: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
    --pm-ease: cubic-bezier(.2, .9, .25, 1);
    --pm-pop: cubic-bezier(.3, 1.5, .5, 1);
    color-scheme: dark;
}
#stage-1, body[data-stage="1"], .stage-transition[data-next="1"] { --stage: var(--pm-s1); }
#stage-2, body[data-stage="2"], .stage-transition[data-next="2"] { --stage: var(--pm-s2); }
#stage-3, body[data-stage="3"], .stage-transition[data-next="3"] { --stage: var(--pm-s3); }

html, body {
    background: var(--pm-bg) !important;
    background-image: none !important;
    backdrop-filter: none !important;
}
body { color: var(--pm-ink); font-family: var(--pm-ui); }
input, textarea { -webkit-user-select: text; user-select: text; touch-action: manipulation; }
:where(button, a, select, input, textarea, summary):focus-visible { outline: 3px solid var(--pm-gold); outline-offset: 3px; }
.cast { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, .7vw, 10px); margin: 0; padding: 0; list-style: none; }
.cast li { display: grid; align-content: start; gap: 6px; min-width: 0; }
.cast img, .cast__secret b {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    border-radius: 10px;
    background: color-mix(in srgb, var(--stage) 24%, var(--pm-panel));
    object-fit: cover;
    object-position: 50% 18%;
}
.cast__secret b {
    display: grid;
    place-items: center;
    color: var(--stage);
    font: clamp(22px, 2.3vw, 34px)/1 var(--pm-display);
    background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--stage) 18%, var(--pm-bg)) 0 7px, var(--pm-bg) 7px 14px);
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--stage) 55%, transparent);
}
.cast span {
    display: -webkit-box;
    overflow: hidden;
    color: var(--pm-ink);
    font: 600 clamp(13px, 1vw, 15px)/1.12 var(--pm-ui);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}
.cast__secret span { color: var(--stage); }
@keyframes pm-pop { from { opacity: 0; transform: scale(.55); } }
@keyframes pm-fade { from { opacity: 0; } }
@keyframes pm-rise { from { opacity: 0; transform: translateY(18px); } }
@keyframes pm-blink { 50% { opacity: .35; } }

/* ── Stage select ────────────────────────────────────────────── */
#start-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--pm-bg);
    color: var(--pm-ink);
    font-family: var(--pm-ui);
}
#start-screen, #start-screen * { touch-action: pan-y; }
.start-layout {
    display: grid;
    grid-template-rows: auto minmax(0, max-content) auto;
    align-content: center;
    gap: clamp(12px, 2.6vh, 28px);
    width: min(1640px, 100%);
    height: 100%;
    min-height: 520px;
    margin: 0 auto;
    padding: max(clamp(12px, 2.6vh, 28px), env(safe-area-inset-top)) max(clamp(14px, 2.6vw, 36px), env(safe-area-inset-right)) max(clamp(12px, 2.6vh, 28px), env(safe-area-inset-bottom)) max(clamp(14px, 2.6vw, 36px), env(safe-area-inset-left));
}

.pm-top { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-width: 0; animation: pm-fade .5s var(--pm-ease) backwards; }
.pm-brand { display: flex; align-items: center; gap: clamp(14px, 1.6vw, 22px); min-width: 0; }
.pm-brand__tom {
    flex: 0 0 auto;
    width: clamp(60px, 11vh, 104px);
    height: auto;
    aspect-ratio: 1;
    border-radius: 20px;
    background: var(--pm-panel-2);
    box-shadow: 0 0 0 3px var(--pm-gold), 0 6px 0 3px var(--pm-shadow);
    object-fit: cover;
    object-position: 50% 22%;
    transform: rotate(-4deg);
}
.pm-brand__text { min-width: 0; }
.pm-brand__name {
    margin: 0;
    color: var(--pm-gold);
    font: clamp(30px, min(5.4vw, 8vh), 74px)/.95 var(--pm-display);
    letter-spacing: -.01em;
    text-shadow: 0 .07em 0 var(--pm-shadow);
    white-space: nowrap;
}
.pm-brand__line { margin: .55em 0 0; color: var(--pm-mute); font: 600 clamp(15px, 1.5vw, 20px)/1.2 var(--pm-ui); }

.pm-scores { display: flex; gap: clamp(16px, 2.6vw, 40px); margin: 0; }
.pm-scores div { display: grid; align-content: start; gap: 4px; min-width: 0; text-align: right; }
.pm-scores dt { color: var(--pm-mute); font: 700 13px/1 var(--pm-ui); letter-spacing: .14em; text-transform: uppercase; }
.pm-scores dd { margin: 0; color: var(--pm-ink); font: 700 clamp(22px, 2.5vw, 34px)/1 var(--pm-ui); font-variant-numeric: tabular-nums; }
.pm-scores__week dd { color: var(--pm-gold); }
.pm-scores__week small {
    display: block;
    max-width: 13ch;
    margin: 4px 0 0 auto;
    overflow: hidden;
    color: var(--pm-ink);
    font: 600 14px/1.1 var(--pm-ui);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.pm-stages {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    gap: clamp(10px, 1.5vw, 22px);
    min-height: 0;
}
.stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-self: center;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
    border-radius: 16px;
    background: var(--pm-panel);
    box-shadow: inset 0 0 0 1px var(--pm-line);
    animation: pm-deal .65s var(--pm-ease) backwards;
}
#stage-1 { --tilt: -3deg; }
#stage-2 { --tilt: 2deg; animation-delay: .08s; }
#stage-3 { --tilt: 4deg; animation-delay: .16s; }
@keyframes pm-deal { from { opacity: 0; transform: translateY(40px) rotate(var(--tilt)); } }
.stage__map {
    position: relative;
    flex: 0 1 auto;
    aspect-ratio: 5 / 4;
    min-height: 64px;
    overflow: hidden;
    background: #0b0907;
}
.stage__map::after { content: ''; position: absolute; right: 0; bottom: 0; left: 0; height: 4px; background: var(--stage); }
#start-screen .stage-preview {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    border: 0;
    background: #0b0907;
    object-fit: cover;
    animation: pm-drift 16s ease-in-out infinite alternate;
}
#stage-2 .stage-preview { animation-delay: -5s; }
#stage-3 .stage-preview { animation-delay: -10s; }
@keyframes pm-drift { to { transform: scale(1.08) translate(-2%, -1.5%); } }
.stage__no {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    display: flex;
    align-items: baseline;
    gap: 7px;
    margin: 0;
    padding: 9px 14px 10px 13px;
    border-bottom-right-radius: 14px;
    background: var(--stage);
    color: var(--pm-bg);
    font: clamp(22px, 2.3vw, 32px)/.8 var(--pm-display);
}
.stage__no span { font: 700 12px/1 var(--pm-ui); letter-spacing: .16em; }
.stage__info {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: clamp(6px, 1.1vh, 10px);
    min-width: 0;
    padding: clamp(10px, 1.7vh, 18px) clamp(12px, 1.3vw, 18px) clamp(12px, 1.9vh, 18px);
}
.stage__name { margin: 0; overflow: hidden; color: var(--pm-ink); font: clamp(18px, 1.9vw, 27px)/1.1 var(--pm-display); white-space: nowrap; text-overflow: ellipsis; }
.stage__tip { margin: 0; color: var(--pm-mute); font: 500 clamp(15px, 1.15vw, 17px)/1.25 var(--pm-ui); }
.stage .cast { margin-top: 4px; }
.stage .cast li { animation: pm-pop .4s var(--pm-pop) backwards; animation-delay: calc(var(--d, .35s) + var(--i) * .07s); }
#stage-2 .cast { --d: .43s; }
#stage-3 .cast { --d: .51s; }
.stage .cast span { min-height: 2.24em; } /* names wrap to two lines; keep the three cards level */
.cast li:nth-child(1) { --i: 0; }
.cast li:nth-child(2) { --i: 1; }
.cast li:nth-child(3) { --i: 2; }
.cast li:nth-child(4) { --i: 3; }

.pm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; animation: pm-rise .5s .25s var(--pm-ease) backwards; }
#start-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45em;
    min-width: clamp(220px, 24vw, 320px);
    height: clamp(56px, 8vh, 72px);
    margin: 0;
    padding: 0 40px;
    overflow: hidden;
    border: 0;
    border-radius: 14px;
    background: var(--pm-gold);
    box-shadow: 0 6px 0 var(--pm-gold-deep);
    color: var(--pm-bg);
    font: clamp(24px, 2.5vw, 34px)/1 var(--pm-display);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .12s, box-shadow .12s;
}
#start-btn::before { content: ''; flex: 0 0 auto; width: .6em; height: .72em; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
#start-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 38%, rgba(255, 255, 255, .6) 50%, transparent 62%);
    transform: translateX(-110%);
    animation: pm-sheen 3.4s 1.4s ease-in-out infinite;
}
@keyframes pm-sheen { 0% { transform: translateX(-110%); } 35%, 100% { transform: translateX(110%); } }
#start-btn:disabled { background: var(--pm-panel-2); box-shadow: 0 6px 0 #0a0806; color: var(--pm-mute); font-size: clamp(16px, 1.6vw, 22px); cursor: wait; }
#start-btn:disabled::before, #start-btn:disabled::after { display: none; }
@media (hover: hover) { #start-btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 8px 0 var(--pm-gold-deep); } }
#start-btn:not(:disabled):active { transform: translateY(5px); box-shadow: 0 1px 0 var(--pm-gold-deep); }

.pm-link, :is(#bgm-preview-btn, .start-details__close, .pause-panel button, .game-result__actions a, #submitBtn, #pause-btn) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    margin: 0;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    background: var(--pm-panel-2);
    box-shadow: inset 0 0 0 1px var(--pm-line), 0 4px 0 #0a0806;
    color: var(--pm-ink);
    font: 700 16px/1 var(--pm-ui);
    letter-spacing: .06em;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
}
.pm-link { height: clamp(48px, 7vh, 58px); padding: 0 22px; font-size: clamp(16px, 1.4vw, 19px); }
summary.pm-link { list-style: none; }
summary.pm-link::-webkit-details-marker { display: none; }
@media (hover: hover) {
    .pm-link:hover, :is(#bgm-preview-btn, .start-details__close, .pause-panel button, .game-result__actions a, #submitBtn, #pause-btn):hover { background: #342b22; color: var(--pm-gold); }
}
.pm-link:active, :is(#bgm-preview-btn, .start-details__close, .pause-panel button, .game-result__actions a, #submitBtn, #pause-btn):active { transform: translateY(3px); box-shadow: inset 0 0 0 1px var(--pm-line), 0 1px 0 #0a0806; }
.pm-actions__hint { margin: 0 0 0 auto; color: var(--pm-mute); font: 600 16px/1 var(--pm-ui); }
kbd, .control-pill {
    display: inline-block;
    min-width: 1.9em;
    margin: 0 2px;
    padding: 3px 6px 2px;
    border-radius: 6px;
    background: var(--pm-panel-2);
    box-shadow: inset 0 0 0 1px var(--pm-line), 0 2px 0 #0a0806;
    color: var(--pm-ink);
    font: 700 .85em/1.2 var(--pm-ui);
    text-align: center;
}

/* How to play & options: the open <summary> becomes the backdrop, so a tap outside closes it. */
.start-details[open] > summary::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(10, 8, 6, .82);
    cursor: default;
}
.start-details__body {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 41;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 22px 32px;
    width: min(780px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
    padding: clamp(18px, 3vw, 30px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 18px;
    background: var(--pm-panel);
    box-shadow: inset 0 0 0 1px var(--pm-line), 0 24px 60px rgba(0, 0, 0, .6);
    text-align: left;
    transform: translate(-50%, -50%);
    animation: pm-sheet .28s var(--pm-ease) both;
}
@keyframes pm-sheet { from { opacity: 0; transform: translate(-50%, -46%); } }
.start-instructions { grid-column: 1 / -1; }
.start-details__body h2 { margin: 0 0 14px; color: var(--pm-gold); font: 22px/1 var(--pm-display); }
.pm-brief { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 18px; padding: 0; list-style: none; }
.pm-brief li { display: grid; gap: 8px; padding: 12px 14px; border-radius: 12px; background: var(--pm-panel-2); color: var(--pm-ink); font: 600 17px/1.2 var(--pm-ui); }
.pm-brief b { color: var(--pm-gold); font: 26px/1 var(--pm-display); }
.control-list { display: grid; gap: 8px; }
.control-list p { margin: 0; color: var(--pm-mute); font: 500 16px/1.45 var(--pm-ui); }
.control-list strong { display: inline-block; min-width: 72px; color: var(--pm-ink); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.start-audio, .comfort-settings { display: grid; align-content: start; gap: 14px; }
.start-audio label, .comfort-settings label, .pause-audio label {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) 48px;
    align-items: center;
    gap: 12px;
    color: var(--pm-ink);
    font: 700 15px/1 var(--pm-ui);
    letter-spacing: .06em;
    text-align: left;
    text-transform: uppercase;
}
.comfort-settings label, .pause-audio .pause-motion { grid-template-columns: auto minmax(0, 1fr); }
.comfort-settings p { margin: 0; color: var(--pm-mute); font: 500 15px/1.4 var(--pm-ui); }
:is(.start-audio, .pause-audio) label span { color: var(--pm-mute); font-variant-numeric: tabular-nums; text-align: right; }
:is(#start-screen, #pause-screen) input[type="range"] { width: 100%; min-width: 0; margin: 0; accent-color: var(--pm-gold); cursor: pointer; }
:is(#start-screen, #pause-screen) select {
    min-width: 0;
    min-height: 42px;
    padding: 6px 10px;
    border: 0;
    border-radius: 10px;
    background: var(--pm-panel-2);
    box-shadow: inset 0 0 0 1px var(--pm-line);
    color: var(--pm-ink);
    font: 600 16px var(--pm-ui);
}
#bgm-preview-btn { justify-self: start; }
.start-details__close { grid-column: 1 / -1; justify-self: center; min-width: 200px; background: var(--pm-gold); box-shadow: 0 4px 0 var(--pm-gold-deep); color: var(--pm-bg); }
@media (hover: hover) { .start-details__close:hover { background: #ffd04d; color: var(--pm-bg); } }

/* PLAY: the stage 1 map flies onto the maze (js/pearl-attract.js leaveMenu) while the menu falls away. */
#start-screen.is-launching { overflow: hidden; pointer-events: none; animation: pm-out .25s .45s forwards; }
@keyframes pm-out { to { opacity: 0; } }
.is-launching .start-layout { opacity: 0; transform: scale(.97); transition: opacity .28s, transform .4s var(--pm-ease); }
.is-launching #stage-1 .stage-preview { visibility: hidden; }
.pm-flyer {
    position: fixed;
    z-index: 10005;
    display: block;
    margin: 0;
    border: 0;
    background: #000;
    transform-origin: 0 0;
    pointer-events: none;
    will-change: transform, clip-path;
}

/* The stage card lands on the maze, then GO! */
.game-start-intro {
    position: fixed;
    inset: 0;
    z-index: 10010;
    display: grid;
    place-items: center;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}
.game-start-intro.is-visible { visibility: visible; }
.game-start-intro p { grid-area: 1 / 1; margin: 0; }
.game-start-intro__stage {
    display: grid;
    justify-items: center;
    gap: 10px;
    width: 100%;
    padding: 18px 16px 22px;
    border-block: 4px solid var(--pm-s1);
    background: rgba(17, 14, 11, .94);
    color: var(--pm-ink);
    font: clamp(30px, 6.4vw, 70px)/1 var(--pm-display);
    text-align: center;
    transform: translateX(-100%);
}
.game-start-intro__stage span { padding: 5px 10px 4px; border-radius: 6px; background: var(--pm-s1); color: var(--pm-bg); font: 700 16px/1 var(--pm-ui); letter-spacing: .22em; }
.game-start-intro.is-visible .game-start-intro__stage { animation: pm-band 1s .5s linear both; }
@keyframes pm-band {
    0% { transform: translateX(-100%); animation-timing-function: cubic-bezier(.2, .9, .25, 1); }
    24% { transform: translateX(0); }
    78% { transform: translateX(0); animation-timing-function: cubic-bezier(.7, 0, .9, .4); }
    100% { transform: translateX(105%); }
}
.game-start-intro__go { color: var(--pm-gold); font: clamp(72px, 15vw, 170px)/1 var(--pm-display); text-shadow: 0 .06em 0 var(--pm-shadow), 0 .1em .3em rgba(0, 0, 0, .55); opacity: 0; }
.game-start-intro.is-visible .game-start-intro__go { animation: pm-go .35s 1.42s var(--pm-pop) both; }
.game-start-intro.is-leaving .game-start-intro__go { animation: pm-go-out .4s ease-in forwards; }
@keyframes pm-go { from { opacity: 0; transform: scale(2.6) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes pm-go-out { from { opacity: 1; } to { opacity: 0; transform: scale(1.5); } }

/* ── HUD ─────────────────────────────────────────────────────── */
#ui { /* LAYOUT: resizeGame measures its bottom edge */
    position: relative;
    z-index: 100;
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 26px;
    width: 100%;
    padding: max(10px, env(safe-area-inset-top)) max(16px, calc((100% - 1100px) / 2)) 10px;
    border: 0;
    border-bottom: 1px solid var(--pm-line);
    background: var(--pm-bg);
    box-shadow: none;
    color: var(--pm-ink);
    font: 600 15px/1 var(--pm-ui);
}
#ui::before { content: ''; order: 4; flex-basis: 100%; height: 0; }
#ui [hidden] { display: none !important; }
#ui .stat {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--pm-ink);
    font: inherit;
    white-space: nowrap;
}
#ui .hud-k { color: var(--pm-mute); font-size: 13px; font-weight: 700; letter-spacing: .14em; }
#ui .hud-title-row { order: 1; display: flex; flex: 1 1 0; min-width: 0; }
#ui .stage-heading { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
#ui .stage-label { flex: 0 0 auto; padding: 6px 10px 5px; border-radius: 7px; background: var(--stage); color: var(--pm-bg); font: 15px/1 var(--pm-display); white-space: nowrap; }
#ui .stage-label:empty { display: none; }
#ui .stage-place { overflow: hidden; color: var(--pm-mute); font-size: 14px; letter-spacing: .06em; white-space: nowrap; text-overflow: ellipsis; }
#ui .stat--score { order: 2; flex: 0 0 auto; }
#ui .stat--high { order: 3; flex: 1 1 0; justify-content: flex-end; }
#ui #score, #ui #hud-high { min-width: 5ch; font: 700 26px/1 var(--pm-ui); font-variant-numeric: tabular-nums; }
#ui #score { color: var(--pm-gold); }
#ui #lives-card { order: 5; }
#ui #lives-card .hud-k { color: var(--pm-red); }
#ui #lives, #ui #boss-hp { min-width: 3ch; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
#ui #objective-card { order: 6; }
#ui #objective-label { color: var(--pm-ink); font-weight: 700; letter-spacing: .04em; }
#ui #boss-hp-ui { order: 7; display: none; }
#ui #boss-hp-ui[style*="block"] { display: flex !important; }
#ui #boss-hp-ui .hud-k { color: var(--pm-boss); }
#ui #ammo-card { order: 8; }
#ui #ammo-card .hud-k { color: var(--pm-gold); }
#ui #rage-card { order: 9; }
#ui #rage-card .hud-k { color: var(--pm-rage); }
#ui #ammo-label, #ui #rage-label { min-width: 4.5ch; font-weight: 700; font-variant-numeric: tabular-nums; }
#ui #ammo-card.is-low #ammo-label { color: var(--pm-boss); }
#ui #rage-card.is-ready #rage-label { color: var(--pm-gold); animation: pm-blink .5s steps(1) infinite; }
#ui #lives-card.is-low :is(.hud-k, #lives, .bar) { animation: pm-blink .45s steps(1) infinite; }
#ui:has(#boss-hp-ui[style*="block"]) #objective-card .bar { display: none; }
/* Segmented meters: ten cells per bar */
#ui .bar {
    width: 92px;
    height: 9px;
    border: 0;
    border-radius: 0;
    background: #2e271f;
    -webkit-mask: repeating-linear-gradient(90deg, #000 0 7.2px, transparent 7.2px 9.2px);
    mask: repeating-linear-gradient(90deg, #000 0 7.2px, transparent 7.2px 9.2px);
}
#ui .bar > div { height: 100%; box-shadow: none; transition: width .15s linear; }
#ui #hp-fill { width: 100%; background: var(--pm-red); }
#ui #objective-fill { background: var(--stage); }
#ui #boss-fill { background: var(--pm-boss); }
#ui #ammo-fill { background: var(--pm-gold); }
#ui #ammo-card.is-low #ammo-fill { background: var(--pm-boss); }
#ui #rage-fill { background: var(--pm-rage); box-shadow: none; }
#ui #rage-card.is-ready #rage-fill { background: var(--pm-gold); }
/* Power-ups float under the HUD so the maze never shifts. */
#ui #power-status {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    z-index: 6;
    padding: 7px 12px 6px;
    border-radius: 8px;
    background: var(--pm-gold);
    color: var(--pm-bg);
    font: 700 14px/1 var(--pm-ui);
    letter-spacing: .06em;
    transform: translateX(-50%);
    pointer-events: none;
}
#ui #pause-btn { order: 10; min-height: 38px; padding: 0 14px; font-size: 15px; }
.pause-key { color: var(--pm-mute); font-size: 12px; }

/* ── Playfield ───────────────────────────────────────────────── */
#game-outer-wrapper { flex: 0 0 auto; margin-top: 0 !important; line-height: 0; } /* LAYOUT */
#game-viewport { position: relative; display: inline-block; overflow: hidden; vertical-align: top; line-height: normal; background: var(--pm-bg); } /* LAYOUT */
/* LAYOUT: game.js offsets the player sprite by this 2px border */
#gameCanvas { margin: 0; border: 2px solid color-mix(in srgb, var(--stage, var(--pm-s1)) 55%, var(--pm-bg)); background: #000; max-height: none; }
#player-animation { /* LAYOUT */
    position: absolute;
    z-index: 2;
    width: 6%;
    height: auto;
    pointer-events: none;
    visibility: hidden;
    transform: translate(-50%, -50%);
    will-change: transform;
}

/* Stage name tag slides in from the maze's edge */
.stage-toast {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 5;
    max-width: calc(100% - 28px);
    padding: 10px 16px 9px 14px;
    border-left: 6px solid var(--stage);
    border-radius: 0 10px 10px 0;
    background: rgba(17, 14, 11, .92);
    color: var(--pm-ink);
    font: clamp(14px, 1.8vw, 19px)/1.1 var(--pm-display);
    text-align: left;
    opacity: 0;
    pointer-events: none;
}
.stage-toast.is-visible { animation: pm-toast 2.7s var(--pm-ease) forwards; }
@keyframes pm-toast {
    0% { opacity: 0; transform: translateX(-30px); }
    9%, 84% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateX(-14px); }
}

.resource-notices {
    position: absolute;
    top: 12px;
    left: 50%;
    z-index: 32;
    display: flex;
    justify-content: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100% - 16px);
    font-family: var(--pm-ui);
    pointer-events: none;
    transform: translateX(-50%);
}
.resource-notices.is-player-near-top { top: auto; bottom: 64px; }
.resource-notices > div { padding: 8px 14px 7px; border-radius: 10px; background: rgba(17, 14, 11, .94); box-shadow: inset 0 0 0 2px var(--pm-boss); color: var(--pm-boss); text-align: center; }
.resource-notices > div[hidden] { display: none; }
.resource-notices strong { display: block; font: 700 17px/1 var(--pm-ui); letter-spacing: .06em; }
.resource-notices span { display: block; margin-top: 4px; color: var(--pm-ink); font: 600 13px/1 var(--pm-ui); letter-spacing: .04em; }
.resource-notices #rage-notice { box-shadow: inset 0 0 0 2px var(--pm-rage); color: var(--pm-gold); }
.resource-notices #rage-notice strong { animation: pm-blink .5s steps(1) infinite; }

.play-coach {
    position: absolute;
    bottom: 16px;
    left: 50%;
    z-index: 30;
    width: max-content;
    max-width: calc(100% - 24px);
    padding: 10px 16px 9px;
    border-radius: 10px;
    background: rgba(17, 14, 11, .94);
    color: var(--pm-ink);
    font: 600 16px/1.3 var(--pm-ui);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 10px);
    transition: opacity .2s, transform .25s var(--pm-ease);
}
.play-coach.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Stage clear: the maze drains of colour, CLEAR is stamped, then the next stage's card is dealt in. */
.stage-transition {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: grid;
    place-items: center;
    padding: 18px;
    overflow: hidden;
    color: var(--pm-ink);
    font-family: var(--pm-ui);
    text-align: center;
    visibility: hidden;
    pointer-events: none;
}
.stage-transition.is-visible {
    visibility: visible;
    background-color: rgba(17, 14, 11, .72);
    -webkit-backdrop-filter: grayscale(1);
    backdrop-filter: grayscale(1);
    animation: pm-fade .35s ease-out both;
    transition: background-color .3s;
}
.stage-transition.is-next { background-color: var(--pm-bg); }
.stage-transition.is-leaving { animation: pm-wipe .45s cubic-bezier(.7, 0, .3, 1) forwards; }
@keyframes pm-wipe { to { clip-path: inset(0 0 100% 0); } }
.stage-transition__panel { display: grid; justify-items: center; gap: 10px; width: min(560px, 100%); }
.stage-transition__eyebrow { margin: 0; color: var(--pm-gold); font: 700 clamp(13px, 1.6vw, 17px)/1.2 var(--pm-ui); letter-spacing: .18em; }
.stage-transition h2 { margin: 0; color: var(--pm-ink); font: clamp(32px, 6vw, 64px)/1.05 var(--pm-display); }
.stage-transition.is-visible:not(.is-next) h2 { animation: pm-stamp .45s .15s var(--pm-pop) both; }
@keyframes pm-stamp { from { opacity: 0; transform: scale(1.9) rotate(-6deg); } to { opacity: 1; transform: rotate(-2deg); } }
#transition-detail { margin: 0; color: var(--pm-mute); font: 700 clamp(15px, 1.8vw, 19px)/1.2 var(--pm-ui); letter-spacing: .1em; }
.stage-transition.is-next .stage-transition__eyebrow { color: var(--stage); }
.stage-transition.is-next h2 { animation: pm-rise .35s var(--pm-ease) both; }
.stage-transition.is-next #transition-detail { color: var(--stage); font: clamp(20px, 3vw, 30px)/1.1 var(--pm-display); letter-spacing: 0; animation: pm-rise .35s .06s var(--pm-ease) both; }
.next-stage { display: none; justify-items: center; gap: 14px; width: 100%; margin-top: 6px; }
.stage-transition.is-next .next-stage { display: grid; }
#next-stage-map {
    width: min(340px, 64%);
    height: auto;
    aspect-ratio: 5 / 4;
    margin: 0;
    border: 0;
    border-radius: 14px;
    background: #0b0907;
    box-shadow: 0 0 0 4px var(--stage), 0 18px 40px rgba(0, 0, 0, .5);
    animation: pm-map-in .55s var(--pm-ease) both;
}
@keyframes pm-map-in { from { opacity: 0; transform: translateX(80px) rotate(6deg); } to { transform: rotate(-1.5deg); } }
.next-stage .cast { width: min(360px, 88%); }
.next-stage .cast li { animation: pm-pop .35s var(--pm-pop) backwards; animation-delay: calc(.3s + var(--i) * .1s); }
.next-stage .cast span { font-size: 14px; }

/* Boss: hazard bands slide in, the portrait drops between them. */
.boss-warning {
    position: absolute;
    inset: 0;
    z-index: 24;
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: clamp(10px, 3vh, 26px);
    padding: 12px 0;
    overflow: hidden;
    background: rgba(17, 14, 11, .86);
    font-family: var(--pm-ui);
}
.boss-warning.is-visible { display: flex; }
.boss-warning.is-leaving { animation: pm-wipe .5s cubic-bezier(.7, 0, .3, 1) forwards; }
.boss-warning__band {
    flex: 0 0 auto;
    height: 46px;
    overflow: hidden;
    border-block: 6px solid transparent;
    border-image: repeating-linear-gradient(-45deg, var(--pm-bg) 0 8px, var(--pm-gold) 8px 16px) 6;
    background: #e8262f;
}
.boss-warning.is-visible .boss-warning__band { animation: pm-band-l .4s var(--pm-ease) both; }
.boss-warning.is-visible .boss-warning__band--low { animation-name: pm-band-r; }
.boss-warning__band span {
    display: inline-block;
    color: var(--pm-bg);
    font: 22px/34px var(--pm-display);
    white-space: nowrap;
    animation: pm-marquee 6s linear infinite; /* the span holds the word twice over, so -50% loops seamlessly */
}
.boss-warning__band--low span { animation-direction: reverse; }
@keyframes pm-marquee { to { transform: translateX(-50%); } }
@keyframes pm-band-l { from { transform: translateX(-100%); } }
@keyframes pm-band-r { from { transform: translateX(100%); } }
.boss-warning__panel {
    align-self: center;
    width: min(440px, calc(100% - 32px));
    padding: clamp(12px, 2.6vh, 24px) clamp(14px, 3vw, 26px);
    border-radius: 18px;
    background: var(--pm-panel);
    box-shadow: inset 0 0 0 2px #e8262f;
    color: var(--pm-ink);
    text-align: center;
}
.boss-warning.is-visible .boss-warning__panel { animation: pm-drop .5s .35s var(--pm-pop) both; }
@keyframes pm-drop { from { opacity: 0; transform: translateY(-60px) scale(.9); } }
.boss-warning__eyebrow { margin: 0; color: #ff6b73; font: 700 15px/1 var(--pm-ui); letter-spacing: .18em; animation: pm-blink .5s steps(1) infinite; }
.boss-warning__image {
    display: block;
    width: clamp(80px, 18vh, 136px);
    height: auto;
    aspect-ratio: 1;
    margin: clamp(10px, 2vh, 16px) auto;
    border-radius: 16px;
    background: #2a0f10;
    box-shadow: 0 0 0 4px #e8262f;
    object-fit: cover;
    object-position: 50% 18%;
}
.boss-warning__panel h2 { margin: 0 0 8px; color: var(--pm-gold); font: clamp(20px, 3.4vw, 32px)/1.1 var(--pm-display); }
.boss-warning__panel p:last-child { margin: 0; color: var(--pm-mute); font: 600 16px/1.3 var(--pm-ui); }

/* ── Game over / all clear ───────────────────────────────────── */
#game-over-screen {
    position: fixed;
    inset: 0;
    z-index: 10030;
    display: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    background: rgba(17, 14, 11, .93);
    color: var(--pm-ink);
    font-family: var(--pm-ui);
    text-align: center;
    animation: pm-fade .4s both;
}
#game-over-screen:focus { outline: none; }
#game-over-screen, #game-over-screen * { touch-action: pan-y; }
.go-banner { margin: 0 0 clamp(14px, 3vh, 26px); font: clamp(38px, 7vw, 80px)/1 var(--pm-display); animation: pm-slam .55s .1s var(--pm-pop) both; }
.go-banner span { display: none; }
#game-over-screen:not(.is-victory) .go-banner__lose, #game-over-screen.is-victory .go-banner__win { display: inline-block; }
.go-banner__lose { color: var(--pm-red); text-shadow: 0 .07em 0 #5e1418; }
.go-banner__win { color: var(--pm-gold); text-shadow: 0 .07em 0 var(--pm-shadow); }
@keyframes pm-slam { from { opacity: 0; transform: scale(2.4) rotate(-7deg); } to { opacity: 1; transform: rotate(-2deg); } }
.game-result__panel {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    width: min(980px, 100%);
    margin: 0 auto;
    overflow: hidden;
    border-radius: 20px;
    background: var(--pm-panel);
    box-shadow: inset 0 0 0 1px var(--pm-line);
    text-align: left;
    animation: pm-rise .5s .55s var(--pm-ease) both;
}
.game-result__main, .game-result__board { min-width: 0; padding: clamp(18px, 3vw, 32px); }
.game-result__board { background: #17130f; }
.game-result__eyebrow { margin: 0 0 8px; color: var(--pm-mute); font: 700 14px/1.2 var(--pm-ui); letter-spacing: .14em; }
#game-result-title { margin: 0 0 18px; color: var(--pm-ink); font: clamp(22px, 2.8vw, 32px)/1.1 var(--pm-display); }
#game-over-screen.is-victory #game-result-title { color: var(--pm-gold); }
.game-result__score-label { margin: 0; color: var(--pm-mute); font: 700 13px/1 var(--pm-ui); letter-spacing: .16em; }
.game-result__score { margin: 6px 0 8px; color: var(--pm-gold); font: 700 clamp(56px, 7vw, 84px)/.95 var(--pm-ui); font-variant-numeric: tabular-nums; }
.result-rank { min-height: 1.3em; margin: 0 0 14px; color: var(--pm-ink); font: 700 17px/1.3 var(--pm-ui); }
.run-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 16px; }
.run-stats div { display: grid; gap: 6px; padding: 10px 12px; border-radius: 12px; background: var(--pm-panel-2); }
.run-stats dt { color: var(--pm-mute); font: 700 12px/1 var(--pm-ui); letter-spacing: .14em; }
.run-stats dd { margin: 0; color: var(--pm-ink); font: 700 24px/1 var(--pm-ui); font-variant-numeric: tabular-nums; }
.result-tip { margin: 0 0 16px; color: var(--pm-mute); font: 500 16px/1.35 var(--pm-ui); }
.result-tip:empty { display: none; }
.game-result__save { display: grid; gap: 10px; margin: 0 0 14px; padding: 14px; border-radius: 14px; background: var(--pm-panel-2); box-shadow: inset 0 0 0 2px var(--pm-gold); animation: pm-pop .3s var(--pm-pop) both; }
.game-result__save[hidden] { display: none; }
.game-result__save label { color: var(--pm-gold); font: 700 14px/1 var(--pm-ui); letter-spacing: .14em; }
.name-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.name-entry input {
    min-width: 0;
    min-height: 48px;
    padding: 8px 12px;
    border: 0;
    border-radius: 10px;
    background: var(--pm-bg);
    box-shadow: inset 0 0 0 1px var(--pm-line);
    color: var(--pm-ink);
    caret-color: var(--pm-gold);
    font: 700 24px/1 var(--pm-ui);
    letter-spacing: .06em;
    text-transform: uppercase;
}
.name-entry input::placeholder { color: #5a4f43; }
.name-entry input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--pm-gold); }
.name-entry button, .game-result__actions button {
    min-height: 48px;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    background: var(--pm-gold);
    box-shadow: 0 4px 0 var(--pm-gold-deep);
    color: var(--pm-bg);
    font: 17px/1 var(--pm-display);
    cursor: pointer;
    touch-action: manipulation;
}
.name-entry button { font: 700 17px/1 var(--pm-ui); letter-spacing: .06em; }
.name-entry button:active, .game-result__actions button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pm-gold-deep); }
#status-msg { min-height: 1.3em; margin: 0 0 12px; color: var(--pm-mute); font: 600 16px/1.3 var(--pm-ui); }
.game-result__actions { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; }
.game-result__actions > * { min-height: 54px; }
.game-result__board h2 { margin: 0 0 14px; color: var(--pm-ink); font: 20px/1 var(--pm-display); }
#result-board .tgb-head { justify-content: flex-start; }
#result-board .tgb-table :is(th, td):nth-child(n+5) { display: none; }
.game-result__more { display: inline-block; margin-top: 14px; padding: 8px 0; color: var(--pm-gold); font: 700 15px/1 var(--pm-ui); letter-spacing: .06em; text-decoration: none; }
@media (hover: hover) { .game-result__more:hover { text-decoration: underline; } }

/* ── Pause ───────────────────────────────────────────────────── */
#pause-screen {
    position: fixed;
    inset: 0;
    z-index: 10020;
    display: grid;
    place-items: center;
    align-items: safe center;
    overflow-y: auto;
    padding: 16px;
    background: rgba(10, 8, 6, .8);
    color: var(--pm-ink);
    font-family: var(--pm-ui);
    text-align: center;
}
#pause-screen[hidden] { display: none; }
.pause-panel { width: min(440px, 100%); padding: clamp(18px, 4vw, 28px); border-radius: 20px; background: var(--pm-panel); box-shadow: inset 0 0 0 1px var(--pm-line), 0 24px 60px rgba(0, 0, 0, .6); animation: pm-pop .22s var(--pm-ease) both; }
.pause-panel h2 { margin: 0 0 10px; color: var(--pm-gold); font: clamp(28px, 5vw, 36px)/1 var(--pm-display); }
.pause-summary { display: flex; justify-content: center; gap: 22px; margin: 0 0 18px; color: var(--pm-mute); font: 700 14px/1 var(--pm-ui); letter-spacing: .12em; }
.pause-summary strong { color: var(--pm-ink); font-size: 17px; letter-spacing: 0; }
.pause-panel__actions { display: grid; gap: 8px; margin: 0 0 18px; }
.pause-panel__actions button { min-height: 50px; font-size: 18px; }
.pause-panel__actions #resume-btn { background: var(--pm-gold); box-shadow: 0 4px 0 var(--pm-gold-deep); color: var(--pm-bg); font: 20px/1 var(--pm-display); letter-spacing: 0; }
@media (hover: hover) { .pause-panel__actions #resume-btn:hover { background: #ffd04d; color: var(--pm-bg); } }
.pause-audio { display: grid; gap: 12px; margin: 0 0 16px; padding: 14px; border-radius: 14px; background: #17130f; }
.pause-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
.pause-tools button { padding: 0 10px; font-size: 14px; }
.pause-tools #size-btn.is-on { color: var(--pm-gold); box-shadow: inset 0 0 0 2px var(--pm-gold), 0 4px 0 #0a0806; }
.pause-panel small { display: block; color: var(--pm-mute); font: 600 13px/1.5 var(--pm-ui); letter-spacing: .04em; }

/* ── Guestbook ───────────────────────────────────────────────── */
#comments {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 10026;
    flex-direction: column;
    width: min(560px, calc(100% - 24px));
    max-width: none;
    max-height: 85dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 20px;
    background: var(--pm-panel);
    box-shadow: inset 0 0 0 1px var(--pm-line), 0 24px 60px rgba(0, 0, 0, .6);
    color: var(--pm-ink);
    font-family: var(--pm-ui);
    text-align: left;
    transform: translate(-50%, -50%);
}
#comments, #comments *, #pause-screen, #pause-screen *, .start-details__body, .start-details__body * { touch-action: pan-y; }
#comments .mobile-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 12px 20px; border-bottom: 1px solid var(--pm-line); }
#comments h2 { margin: 0; color: var(--pm-gold); font: 22px/1 var(--pm-display); }
#comments .mobile-header button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: none; color: var(--pm-ink); font: 28px/1 var(--pm-ui); cursor: pointer; }
#comments .scroll-area { flex: 1; min-height: 0; padding: 16px 20px; overflow-y: auto; }
.guestbook-form { display: grid; gap: 8px; margin-bottom: 18px; }
.guestbook-form input, .guestbook-form textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: var(--pm-bg);
    box-shadow: inset 0 0 0 1px var(--pm-line);
    color: var(--pm-ink);
    font: 500 17px/1.35 var(--pm-ui);
}
.guestbook-form textarea { min-height: 96px; resize: vertical; }
#submitBtn { justify-self: end; background: var(--pm-gold); box-shadow: 0 4px 0 var(--pm-gold-deep); color: var(--pm-bg); }
#commentList { display: grid; gap: 14px; color: var(--pm-mute); font: 500 15px/1.4 var(--pm-ui); }
.gb-entry { padding-bottom: 14px; border-bottom: 1px solid var(--pm-line); }
.gb-entry strong { color: var(--pm-ink); font-size: 17px; }
.gb-entry small { margin-left: 6px; color: var(--pm-mute); font-size: 13px; }
.gb-entry p { margin: 6px 0 0; color: var(--pm-ink); font: 500 17px/1.4 var(--pm-ui); overflow-wrap: anywhere; }

/* ── Touch controls ──────────────────────────────────────────── */
#mobile-controls { background: transparent; }
#mobile-controls .joy-base { border: 0; background: radial-gradient(circle, rgba(40, 33, 26, .75) 0 60%, rgba(40, 33, 26, .35) 61%); box-shadow: inset 0 0 0 2px var(--pm-line); }
#mobile-controls #knob { border-radius: 50%; background: var(--pm-ink); box-shadow: 0 4px 0 #8f8270, 0 6px 16px rgba(0, 0, 0, .5); }
#mobile-controls .m-btn { border: 0; color: var(--pm-bg); font: 700 15px/1 var(--pm-ui); letter-spacing: .08em; }
#mobile-controls #m-fire { background: var(--pm-gold); box-shadow: 0 5px 0 var(--pm-gold-deep); }
#mobile-controls #m-fire.is-empty { background: var(--pm-panel-2); box-shadow: inset 0 0 0 2px var(--pm-line), 0 5px 0 #0a0806; color: var(--pm-boss); }
#mobile-controls #m-rage { background: var(--pm-rage); box-shadow: 0 5px 0 #9c2c63; animation: none; }
#mobile-controls #m-rage.is-ready { background: var(--pm-gold); box-shadow: 0 5px 0 var(--pm-gold-deep), 0 0 0 4px var(--pm-rage); animation: pm-ring .6s ease-in-out infinite alternate; }
@keyframes pm-ring { to { box-shadow: 0 5px 0 var(--pm-gold-deep), 0 0 0 9px rgba(255, 95, 162, .25); } }
#mobile-controls .m-btn:active { transform: translateY(4px); }

/* ── Reduced motion: hold every final frame ── */
.pearl-reduced-motion *, .pearl-reduced-motion *::before, .pearl-reduced-motion *::after {
    animation-duration: .001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
}
.pearl-reduced-motion #start-screen .stage-preview, .pearl-reduced-motion #start-btn::after, .pearl-reduced-motion .game-start-intro__stage { animation: none !important; }
.pearl-reduced-motion .game-start-intro__stage { transform: none; }
.pearl-reduced-motion .game-start-intro__go { display: none; }

/* ── Smaller screens ─────────────────────────────────────────── */
@media (max-height: 780px) {
    .stage__tip { display: none; }
    .cast span { -webkit-line-clamp: 1; }
    .stage .cast span { min-height: 0; }
}
@media (max-width: 1440px) {
    #ui .stage-place { display: none; }
}
@media (max-width: 1100px) {
    #ui { gap: 8px 18px; }
    #ui .bar { width: 74px; }
}
@media (max-width: 900px) {
    .pm-scores { gap: 18px; }
    .pm-brand__line { display: none; }
    .start-details__body { grid-template-columns: 1fr; }
    .pm-brief { grid-template-columns: 1fr; }
    .pm-brief li { grid-template-columns: auto 1fr; align-items: center; }
    .game-result__panel { grid-template-columns: 1fr; }
}

/* Phones and tablets held upright: three stage rows, map on the left. */
@media (orientation: portrait) and (max-width: 900px) {
    .start-layout { grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; min-height: 500px; }
    .pm-top { flex-direction: column; align-items: stretch; gap: 10px; }
    .pm-brand { gap: 14px; }
    .pm-brand__tom { width: clamp(52px, 13vw, 76px); border-radius: 14px; }
    .pm-brand__name { font-size: clamp(30px, 9vw, 58px); }
    .pm-scores { justify-content: space-between; padding: 9px 14px; border-radius: 12px; background: var(--pm-panel); }
    .pm-scores div { text-align: left; }
    .pm-scores dt { font-size: 11px; }
    .pm-scores dd { font-size: 20px; }
    .pm-scores__week { min-width: 0; }
    .pm-scores__week dd { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
    .pm-scores__week small { margin: 0; font-size: 13px; }
    .pm-stages { grid-template-columns: 1fr; grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .stage { flex-direction: row; align-self: stretch; max-height: none; container-type: size; }
    .stage__map { flex: 0 0 38%; aspect-ratio: auto; min-height: 0; }
    .stage__map::after { top: 0; left: auto; width: 4px; height: auto; }
    .stage__no { gap: 5px; padding: 6px 10px 7px 9px; border-bottom-right-radius: 10px; font-size: 19px; }
    .stage__no span { font-size: 10px; }
    .stage__info { flex: 1 1 auto; justify-content: center; gap: 6px; padding: 8px 10px 8px 12px; }
    .stage__name { font-size: clamp(16px, 4.6vw, 24px); }
    .stage__tip { display: none; }
    .stage .cast { gap: 6px; margin: 0; }
    .stage .cast :is(img, b) { max-height: 52cqh; border-radius: 8px; }
    .stage .cast span { min-height: 2.24em; font-size: 12px; -webkit-line-clamp: 2; }
    .pm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    #start-btn { grid-column: 1 / -1; width: 100%; min-width: 0; height: 58px; }
    .start-details { min-width: 0; }
    .pm-link { width: 100%; height: 46px; padding: 0 10px; font-size: 15px; }
    .pm-actions__hint { display: none; }
}
@media (orientation: portrait) and (max-width: 900px) and (max-height: 640px) {
    .stage .cast span { display: none; }
}

/* LAYOUT: phones scroll the maze under a camera (ui_net.js updateMobileCamera). */
@media (max-width: 768px), (max-width: 950px) and (pointer: coarse) and (orientation: landscape) {
    #game-outer-wrapper { width: 100%; }
    #game-viewport { display: block; width: 100%; }
    #game-container { position: absolute !important; top: 0; left: 0; margin: 0; will-change: transform; transition: none; }
    #gameCanvas { margin: 0; max-height: none; }
    #mobile-controls { height: 142px !important; }
    #mobile-controls .btn-group { flex-direction: row; gap: 14px; }
    #pause-screen #toggleBtn { display: inline-flex !important; }
    #pause-screen #size-btn { display: none !important; }

    #ui {
        gap: 7px 14px;
        padding: max(7px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 7px max(10px, env(safe-area-inset-left));
        font-size: 13px;
    }
    #ui .hud-title-row, #ui .stat--high, #ui #ammo-label, #ui #rage-label, #ui #objective-card .bar { display: none !important; }
    #ui .hud-k { font-size: 11px; }
    #ui #score { min-width: 0; font-size: 21px; }
    #ui .stat--score { order: 1; }
    #ui #lives-card { order: 2; }
    #ui #pause-btn { order: 3; min-height: 34px; margin-left: auto; padding: 0 12px; font-size: 14px; }
    #ui .bar { width: 54px; height: 8px; }
    #ui #ammo-card .bar, #ui #rage-card .bar { width: 46px; }
    #ui:has(#boss-hp-ui[style*="block"]) #objective-card { display: none; }
    #ui #power-status { font-size: 12px; }
    .pause-key { display: none; }
    .resource-notices { top: 8px; gap: 6px; }
    .resource-notices > div { padding: 6px 10px 5px; }
    .resource-notices strong { font-size: 14px; }
    .resource-notices span { font-size: 11px; }
    .play-coach { bottom: 8px; padding: 8px 12px 7px; font-size: 14px; }
    .stage-toast { top: 10px; left: 10px; font-size: 13px; }
    .run-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .game-result__actions, .name-entry { grid-template-columns: 1fr; }
}

/* Phone on its side, or a short window: one header row, three short cards, one action row. */
@media (max-width: 950px) and (pointer: coarse) and (orientation: landscape), (max-height: 540px) and (orientation: landscape) {
    .start-layout { grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; min-height: 280px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .pm-brand { gap: 12px; }
    .pm-brand__tom { width: 38px; border-radius: 10px; box-shadow: 0 0 0 2px var(--pm-gold), 0 3px 0 2px var(--pm-shadow); }
    .pm-brand__name { font-size: 24px; }
    .pm-brand__line { display: none; }
    .pm-scores { gap: 16px; }
    .pm-scores dt { font-size: 10px; }
    .pm-scores dd { font-size: 17px; }
    .pm-scores__week small { display: none; }
    .pm-stages { gap: 8px; }
    .stage { align-self: stretch; max-height: none; border-radius: 12px; }
    .stage__map { flex: 1 1 auto; aspect-ratio: auto; min-height: 40px; }
    .stage__no { padding: 5px 8px 6px; border-bottom-right-radius: 9px; font-size: 16px; }
    .stage__no span { display: none; }
    .stage__info { gap: 5px; padding: 6px 8px 8px; }
    .stage__name { font-size: 15px; }
    .stage__tip { display: none; }
    .stage .cast { gap: 5px; margin: 0; }
    .stage .cast :is(img, b) { border-radius: 7px; font-size: 20px; }
    .stage .cast span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .pm-actions { flex-wrap: nowrap; gap: 8px; }
    #start-btn { min-width: 0; flex: 1.3 1 0; height: 46px; font-size: 21px; }
    #start-btn:disabled { font-size: 15px; }
    .pm-link { height: 44px; padding: 0 14px; font-size: 14px; }
    #start-leaderboard-button, .start-details { flex: 1 1 0; }
    .start-details summary { width: 100%; }
    .pm-actions__hint { display: none; }
    .next-stage { grid-template-columns: auto auto; align-items: center; }
    #next-stage-map { width: min(200px, 34vw); }
    .go-banner { margin-bottom: 10px; font-size: 40px; }
    .game-result__score { margin: 2px 0 6px; font-size: 52px; }
    #game-result-title { margin-bottom: 10px; }
    .run-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .run-stats div { padding: 8px 10px; }
    .run-stats dd { font-size: 20px; }
}

/* Touch controls float over the maze on a phone held sideways. */
@media (max-width: 950px) and (pointer: coarse) and (orientation: landscape) {
    #ui { flex-wrap: nowrap; }
    #ui::before { display: none; }
    #ui #pause-btn { order: 10; }
    #mobile-controls {
        position: fixed !important;
        inset: auto 0 0 !important;
        display: flex !important;
        width: 100%;
        height: 120px !important;
        padding: 0 max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
        z-index: 1000;
        pointer-events: none;
    }
    #mobile-controls .joy-base { width: 104px !important; height: 104px !important; }
    #mobile-controls #knob { top: 28px !important; left: 28px !important; width: 40px !important; height: 40px !important; }
    #mobile-controls .m-btn { width: 64px !important; height: 64px !important; font-size: 13px; }
}
