/* =================================================================================
 * Keystone — the solo well: single player and Infinity (`.single-player-stage
 * [data-board='well']`, set by SinglePlayerMode and InfinityMode).
 *
 * The board stands in an open-top well, as in local versus (keystone-versus.css): walls
 * in the mode's own colour (a deep violet for single player, a deep aqua for Infinity) rise from
 * the floor and fade out toward the top, the glass is plain, the pieces meet both walls, and the
 * next queue stands on the well's mouth. Single player keeps its numbers in one ledger
 * beside the well; Infinity has its HUD on the left and the tower map on the right
 * (src/ui/infinity/InfinityHUD.js, InfinityMinimap.js).
 *
 * The board stands at its share of the height it could fill (--sb-board-fill, the same in
 * every mode: keystone-overlays.css), and the queue and the well stand in the middle of the
 * window, so the theme shows above, below and beside them. On portrait screens the board
 * takes all the height, the ledger (or the
 * HUD) becomes one strip under the board and the tower a slim rail beside it. Themes
 * still measure `.single-player-card`, its `.player-next-pieces` and
 * `.single-player-stats-bar` for their composition.
 * ================================================================================ */

/* ---- Sizes ------------------------------------------------------------------------- */
.single-player-stage[data-board='well'] {
    --sp-vh: 100vh;
    --sp-hue: var(--sb-lavender);
    --sp-hue-rgb: var(--sb-lavender-rgb);
    --sp-wall: color-mix(in srgb, var(--sp-hue) 82%, #fff6e9);
    --sp-wall-glow: color-mix(in srgb, var(--sp-hue) 34%, transparent);
    /* The top row (the controls tray), the air under the board, what the column holds
       under the well (portrait: the ledger's strip). */
    --sp-head: calc(var(--sb-play-inset, 16px) + var(--sb-play-tray, 48px) + 10px);
    --sp-bottom: 22px;
    --sp-below: 0px;
    /* The queue on the well's mouth: the next piece's tile height. */
    --sp-next-h: clamp(30px, calc(var(--sp-vh) * 0.062), 62px);
    --sp-queue-gap: 10px;
    /* The ledger (single player) and the air between it and the well. */
    --sp-side: clamp(196px, 15vw, 240px);
    --sp-side-gap: clamp(20px, 2.4vw, 40px);
    --sp-floor-r: 10px;
    /* The height the board could fill, and its share of it (the rest is the theme's). The
       room is measured from the tray's row, never from --sp-top, which follows the board. */
    --sp-board-h-room: calc(var(--sp-vh) - var(--sp-head) - var(--sp-next-h) - var(--sp-queue-gap)
        - var(--sp-below) - var(--sp-bottom));
    --sp-board-h: min(var(--sp-board-h-room),
        max(calc(var(--sp-board-h-room) * var(--sb-board-fill, 1)), var(--sb-board-floor, 0px)));
    --sp-board-w-room: calc(100vw - 2 * (16px + var(--sp-side) + var(--sp-side-gap)));
    --board-width: clamp(140px, min(calc(var(--sp-board-h) / 2), var(--sp-board-w-room)), 640px);
    --board-height: calc(var(--board-width) * 2);
    /* The column (queue, well, anything under it) in the middle of the window, between the
       tray's row and the air at the bottom. Panels beside the well start at --sp-top too. */
    --sp-column-h: calc(var(--sp-next-h) + var(--sp-queue-gap) + var(--board-height) + var(--sp-below));
    --sp-top: clamp(var(--sp-head), calc((var(--sp-vh) - var(--sp-column-h)) / 2),
        calc(var(--sp-vh) - var(--sp-bottom) - var(--sp-column-h)));
    /* The whole window (phones pad the body), a row at every width (main.css stacks a
       narrow stage into a centred column). */
    position: fixed;
    inset: 0;
    box-sizing: border-box;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    width: auto;
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: var(--sp-top) 16px var(--sp-bottom);
    overflow: hidden;
}

@supports (height: 100dvh) {
    .single-player-stage[data-board='well'] {
        --sp-vh: 100dvh;
    }
}

/* Infinity: the HUD on the left, the tower on the right. */
.single-player-stage[data-board='well'].infinity-mode-active {
    --sp-hue: var(--sb-aqua);
    --sp-hue-rgb: var(--sb-aqua-rgb);
    --ih-w: clamp(204px, 17vw, 264px);
    --tower-w: clamp(64px, 6vw, 92px);
    --sp-board-w-room: calc(100vw - 32px - var(--ih-w) - var(--tower-w) - 2 * var(--sp-side-gap));
    gap: 0;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: var(--sp-top) 16px var(--sp-bottom);
}

/* Single player's walls: a deep, warm violet of their own, as deep as Infinity's below. The
   lavender's mix with cream is pale enough to read as light blue round the dark field, so the
   walls do not take it; the ledger keeps the lavender. Odyssey (gold, keystone-overlays.css) and
   Stillfall (coral, stillfall.css) keep the hue's mix; :where() leaves Still Air and danger,
   below, winning. */
.single-player-stage[data-board='well']:not(:where(.infinity-mode-active, [data-odyssey-board], [data-stillfall])) {
    --sp-wall: #ab6adc;
}

/* The brass finial against dusk-blue slate on the Himalayan pass. */
:where(body:has(#himalayan-peak-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #ecd29b;
    --sp-hue-rgb: 236, 210, 155;
    --sp-wall: #8ea2bb;
    --sp-wall-glow: rgb(135 171 202 / 24%);
}

/* Harvest brass at the lip of the well and a slate ledger like the distant fells. */
:where(body:has(#grainfields-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-still-air], [data-danger], [data-stillfall]
)) {
    --sp-hue: #eac587;
    --sp-hue-rgb: 234, 197, 135;
    --sp-wall: #ad8a59;
    --sp-wall-glow: rgb(171 132 73 / 23%);
}

/* The pink crystal reflected in the well, with pale rose quartz at the queue. */
:where(body:has(#kaleidosonic-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #f1b9d9;
    --sp-hue-rgb: 241, 185, 217;
    --sp-wall: #b76caa;
    --sp-wall-glow: rgb(176 78 153 / 25%);
}

/* Jade at the waterline and the lantern's paper around the queue and ledger. */
:where(body:has(#koi-pond-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #e8c58b;
    --sp-hue-rgb: 232, 197, 139;
    --sp-wall: #72a69b;
    --sp-wall-glow: rgb(71 137 122 / 25%);
}

/* Infinity's walls: its aqua deepened, boardWallColor('#9ee8ed') (src/ui/board-walls.js), so
   the dark field never wears a light-blue frame; the HUD keeps the aqua. Odyssey borrows this
   layout and keeps its gold (keystone-overlays.css); :where() leaves Still Air and danger,
   below, winning. */
.single-player-stage[data-board='well'].infinity-mode-active:not(:where([data-odyssey-board])) {
    --sp-wall: #249597;
}

/* Sea glass around the ordinary solo well. The mode and danger cues own their own walls. */
:where(body:has(#luminous-tides-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #89dfc7;
    --sp-hue-rgb: 137, 223, 199;
    --sp-wall: #3a9498;
}

/* The lake's green edge around the well and a frosted silver queue. */
:where(body:has(#aurora-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #badfda;
    --sp-hue-rgb: 186, 223, 218;
    --sp-wall: #69ad9c;
    --sp-wall-glow: rgb(85 173 150 / 22%);
}

/* The mint lake lights the ledger and the violet shore frames the ordinary solo well. */
:where(body:has(#lunara-theme.active)) .single-player-stage[data-board='well']:where(:not(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-danger], [data-still-air]
)) {
    --sp-hue: #a0e1df;
    --sp-hue-rgb: 160, 225, 223;
    --sp-wall: #967ccb;
    --sp-wall-glow: rgb(112 120 204 / 28%);
}

/* Cut blue ice on the wall, moon silver on the queue and score ledger. */
:where(body:has(#ice-temple-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) {
    --sp-hue: #c5d6db;
    --sp-hue-rgb: 197, 214, 219;
    --sp-wall: #4f90aa;
    --sp-wall-glow: rgb(107 183 211 / 24%);
}

/* ---- The column: the queue over the well ------------------------------------------- */
.single-player-stage[data-board='well'] #single-player-container {
    --board-width: inherit;
    --board-height: inherit;
    justify-content: flex-start;
    gap: 0;
    min-width: 0;
    min-height: 0;
    padding: 0;
}

.single-player-stage[data-board='well'] #single-player-container .single-player-card {
    --board-width: inherit;
    --board-height: inherit;
    width: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    /* The old card's frost (multiplayer-ui.css .player-card) blurred the theme round the
       queue; the well's glass is its own. */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: none;
}

.single-player-stage[data-board='well'] #single-player-container .single-player-body,
.single-player-stage[data-board='well'] #single-player-container .single-player-main {
    gap: 0;
    max-height: none;
    overflow: visible;
}

/* ---- The queue: a row on the well's mouth ------------------------------------------- */
.single-player-stage[data-board='well'] #single-player-container .single-player-piece-previews {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0;
    width: var(--board-width);
    height: var(--sp-next-h);
    margin: 0 0 var(--sp-queue-gap);
}

.single-player-stage[data-board='well'] #single-player-container .single-player-piece-previews::before {
    content: 'Next';
    align-self: center;
    margin-right: calc(var(--sp-next-h) * 0.24);
    color: var(--sb-text-faint);
    font: 600 max(8px, calc(var(--sp-next-h) * 0.15)) / 1 var(--sb-font-display);
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

.single-player-stage[data-board='well'] #single-player-container .player-next-pieces {
    flex: none;
    flex-direction: row;
    align-items: flex-end;
    gap: calc(var(--sp-next-h) * 0.18);
    width: auto !important;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
}

.single-player-stage[data-board='well'] #single-player-container .player-next-piece {
    width: calc(var(--sp-next-h) * 1.333);
    height: calc(var(--sp-next-h) * 0.8);
    border: 1px solid var(--sb-line);
    border-radius: calc(var(--sp-next-h) * 0.15);
    background: rgba(12, 10, 30, 0.82);
    box-shadow: none;
    opacity: 0.8;
    transform: none;
}

.single-player-stage[data-board='well'] #single-player-container .player-next-piece.highlight {
    width: calc(var(--sp-next-h) * 1.667);
    height: var(--sp-next-h);
    border-color: rgba(var(--sp-hue-rgb), 0.7);
    background:
        linear-gradient(180deg, rgba(var(--sp-hue-rgb), 0.12), transparent 70%),
        rgba(12, 10, 30, 0.86);
    box-shadow: 0 0 14px rgba(var(--sp-hue-rgb), 0.24);
    opacity: 1;
    transform: none;
}

.single-player-stage[data-board='well'] #single-player-container .player-next-piece:nth-child(3) {
    opacity: 0.6;
}

/* ---- The well: plain glass between walls that fade toward the open top -------------- */
.single-player-stage[data-board='well'] #single-player-container .player-board-section {
    position: relative;
    width: var(--board-width);
    height: var(--board-height);
    margin: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
}

.single-player-stage[data-board='well'] #single-player-card #phaser-game-container {
    width: var(--board-width);
    height: var(--board-height);
    overflow: hidden;
    border: 0;
    border-radius: 0 0 var(--sp-floor-r) var(--sp-floor-r);
    background: linear-gradient(180deg, rgba(9, 8, 24, 0.3) 0%, rgba(9, 8, 24, 0.84) 16%, rgba(9, 8, 24, 0.9) 100%);
    box-shadow: none;
}

/* The walls: left, right and floor, fading out toward the top; the pieces meet them. */
.single-player-stage[data-board='well'] #single-player-border {
    position: absolute;
    inset: 0 -3px -3px;
    z-index: 4;
    width: auto !important;
    height: auto !important;
    border: 3px solid var(--sp-wall);
    border-top: 0;
    border-radius: 0 0 calc(var(--sp-floor-r) + 3px) calc(var(--sp-floor-r) + 3px);
    background: none;
    box-shadow:
        0 10px 28px -8px var(--sp-wall-glow),
        inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12);
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 24%);
    mask-image: linear-gradient(180deg, transparent 0%, #000 24%);
    pointer-events: none;
    transition: border-color var(--sb-dur-3) ease, box-shadow var(--sb-dur-3) ease;
}

/* Infinity above the ground (the tower map marks it): no floor, the walls run on down. */
.single-player-stage[data-board='well'] #single-player-container[data-off-floor] #single-player-border {
    bottom: 0;
    border-bottom: 0;
    border-radius: 0;
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 24%, #000 76%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0%, #000 24%, #000 76%, transparent 100%);
}

.single-player-stage[data-board='well'] #single-player-container[data-off-floor] #phaser-game-container {
    border-radius: 0;
}

/* Near the top (single player): a coral haze from the open top, the walls breathe. */
.single-player-stage[data-board='well'] #single-player-container .player-board-section::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    z-index: 3;
    height: 34%;
    background: linear-gradient(180deg, rgba(var(--sb-danger-rgb), 0.3), transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--sb-dur-3) ease;
}

/* Still Air (an Odyssey charm): single player's calm violet on the walls while the fall is slowed,
   in a lavender glow. Danger, below, wins. */
.single-player-stage[data-board='well'][data-still-air] {
    --sp-wall: #ab6adc;
    --sp-wall-glow: rgba(var(--sb-lavender-rgb), 0.45);
}

.single-player-stage[data-board='well'][data-still-air] #single-player-border {
    animation: sp-still-air 2.4s var(--sb-ease-breathe) infinite alternate;
}

@keyframes sp-still-air {
    from { box-shadow: 0 10px 28px -8px var(--sp-wall-glow), inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12); }
    to { box-shadow: 0 10px 36px -4px var(--sp-wall-glow), inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12); }
}

@media (prefers-reduced-motion: reduce) {
    .single-player-stage[data-board='well'][data-still-air] #single-player-border {
        animation: none;
        box-shadow: 0 10px 32px -6px var(--sp-wall-glow), inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12);
    }
}

.single-player-stage[data-board='well'][data-danger] {
    --sp-wall: var(--sb-danger);
    --sp-wall-glow: rgba(var(--sb-danger-rgb), 0.55);
}

.single-player-stage[data-board='well'][data-danger] #single-player-container .player-board-section::before {
    opacity: 1;
}

.single-player-stage[data-board='well'][data-danger] #single-player-border {
    animation: sp-danger 1.1s var(--sb-ease-breathe) infinite alternate;
}

@keyframes sp-danger {
    from { box-shadow: 0 10px 28px -8px var(--sp-wall-glow), inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12); }
    to { box-shadow: 0 10px 40px -2px var(--sp-wall-glow), inset 0 -1px 0 rgba(var(--sb-cream-rgb), 0.12); }
}

/* ---- The ledger (single player): one panel beside the well, from its top ----------- */
.single-player-stage[data-board='well'] .single-player-stats-bar {
    position: absolute;
    top: calc(var(--sp-top) + var(--sp-next-h) + var(--sp-queue-gap));
    left: calc(50% + var(--board-width) / 2 + var(--sp-side-gap));
    z-index: 10;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    width: var(--sp-side);
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--sb-line);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(25, 21, 56, 0.92) 0%, rgba(12, 10, 30, 0.94) 100%);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(var(--sb-cream-rgb), 0.05);
    transform: none;
}

:where(body:has(#himalayan-peak-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) .single-player-stats-bar {
    border-color: rgb(207 182 134 / 33%);
    background: linear-gradient(148deg, rgb(40 47 65 / 97%), rgb(19 26 42 / 96%) 76%);
}

:where(body:has(#grainfields-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-still-air], [data-danger], [data-stillfall]
)) .single-player-stats-bar {
    background: linear-gradient(157deg, rgb(43 45 47 / 97%), rgb(20 26 32 / 96%) 72%);
    border-color: rgb(205 171 113 / 35%);
}

:where(body:has(#kaleidosonic-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall]
)) .single-player-stats-bar {
    --sb-text-faint: #cab9d2;
    border-color: rgb(201 145 188 / 31%);
    background: linear-gradient(145deg, rgb(43 23 54 / 97%), rgb(18 15 37 / 96%) 65%, rgb(18 27 40 / 96%));
}

:where(body:has(#aurora-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall], [data-still-air], [data-danger]
)) .single-player-stats-bar {
    --sb-text-faint: #b4caca;
    border-color: rgb(136 197 183 / 31%);
    background: linear-gradient(150deg, #1a363bfa, #101c2aef 72%);
}

/* The mode's hue as the ledger's left edge, like a seat's plate in local versus. */
.single-player-stage[data-board='well'] .single-player-stats-bar::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--sp-hue);
}

:where(body:has(#luminous-tides-theme.active)) .single-player-stage[data-board='well']:not(:where(
    .infinity-mode-active, [data-odyssey-board], [data-stillfall]
)) .single-player-stats-bar {
    background: linear-gradient(160deg, rgba(18, 41, 52, 0.95), rgba(12, 18, 37, 0.95) 74%);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 6px 10px;
    width: auto;
    margin: 0;
    padding: 14px 16px 14px 18px;
    border: 0;
    border-top: 1px solid var(--sb-line);
    border-radius: 0;
    background: none;
    box-shadow: none;
    opacity: 1;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat:first-child {
    border-top: 0;
    box-shadow: none;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat-label {
    color: var(--sb-text-faint);
    font: 600 9px / 1.2 var(--sb-font-display);
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat .single-player-stat-value {
    justify-self: end;
    color: var(--sb-text);
    font: 600 20px / 1.1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
    text-shadow: none;
    white-space: nowrap;
    filter: none;
}

/* The score leads: its own line, large. */
.single-player-stage[data-board='well'] .single-player-stats-bar .stat-score {
    grid-template-columns: 1fr;
    padding-top: 16px;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .stat-score .single-player-stat-value {
    justify-self: start;
    font-size: clamp(24px, 2.2vw, 34px);
}

:where(body:has(#lunara-theme.active)) .single-player-stage[data-board='well']:not(:where(.infinity-mode-active, [data-odyssey-board], [data-stillfall])) .single-player-stats-bar {
    --sb-text-faint: #c3bbd6;
    border-color: rgb(159 169 212 / 33%);
    background: linear-gradient(158deg, rgb(39 31 65 / 96%), rgb(13 18 38 / 95%) 72%);
}

/* The level, its bar toward the next one, the lines left. */
.single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-track {
    grid-column: 1 / -1;
    position: relative;
    height: 6px;
    overflow: hidden;
    border-radius: 3px;
    background: rgba(var(--sb-cream-rgb), 0.08);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sp-hue), var(--sb-gold));
    transform: scaleX(var(--sp-level, 0));
    transform-origin: left center;
    transition: transform 420ms var(--sb-ease-lock);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-caption {
    grid-column: 1 / -1;
    color: var(--sb-text-muted);
    font: 600 11px / 1.2 var(--sb-font-text);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-caption .single-player-stat-value {
    color: var(--sb-text);
    font: 700 11px / 1.2 var(--sb-font-text);
}

/* The pace: three small numbers in a row. */
.single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--sb-line);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace .single-player-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 8px 14px 18px;
    border-top: 0;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace .single-player-stat + .single-player-stat {
    padding-left: 8px;
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace .single-player-stat-value {
    justify-self: start;
    color: var(--sb-text-muted);
    font: 600 13px / 1.1 var(--sb-font-display);
}

.single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace .single-player-stat-label {
    font-size: 8px;
}

.single-player-stage[data-board='well'] .single-player-stat-value.warning {
    color: var(--sb-gold);
}

.single-player-stage[data-board='well'] .single-player-stat-value.danger {
    color: var(--sb-coral);
}

/* ---- Infinity: the HUD, the well, the tower, bottoms aligned with the floor -------- */
.single-player-stage[data-board='well'] #single-player-container.infinity-mode-active {
    flex-direction: row;
    align-items: flex-end;
    justify-content: center;
    gap: var(--sp-side-gap);
    width: 100%;
    min-width: 0;
    padding: 0;
}

.single-player-stage[data-board='well'] #single-player-container.infinity-mode-active .single-player-card {
    order: 2;
    align-self: flex-end;
    flex: none;
}

/* The HUD: as tall as the well, its sections from the top. */
#single-player-container.infinity-mode-active #infinity-hud.infinity-hud {
    order: 1;
    align-self: flex-end;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    width: var(--ih-w, 240px);
    height: var(--board-height);
    max-height: none;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    border: 1px solid var(--sb-line);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(25, 21, 56, 0.92) 0%, rgba(12, 10, 30, 0.94) 100%) !important;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(var(--sb-cream-rgb), 0.05);
    color: var(--sb-text);
    font-family: var(--sb-font-text);
    font-size: 13px;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: none;
}

#infinity-hud .ih-kicker {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px 12px;
    color: var(--sb-aqua);
    font: 700 11px / 1 var(--sb-font-display);
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

#infinity-hud .ih-kicker__mark {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--sb-aqua);
    box-shadow: 0 0 12px rgba(var(--sb-aqua-rgb), 0.5);
}

#infinity-hud section {
    padding: 14px 18px;
    border-top: 1px solid var(--sb-line);
}

#infinity-hud .ih-label {
    color: var(--sb-text-faint);
    font: 600 9px / 1.3 var(--sb-font-display);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

#infinity-hud .ih-label--gold {
    color: rgba(var(--sb-gold-rgb), 0.75);
}

#infinity-hud .ih-height {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 6px 0 12px;
}

#infinity-hud .ih-height__value {
    color: var(--sb-text);
    font: 700 clamp(32px, 3vw, 44px) / 1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
}

#infinity-hud .ih-height__unit {
    color: rgba(var(--sb-aqua-rgb), 0.8);
    font: 600 11px / 1 var(--sb-font-display);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

#infinity-hud .ih-next__track {
    position: relative;
    height: 6px;
    overflow: hidden;
    border-radius: 3px;
    background: rgba(var(--sb-cream-rgb), 0.08);
}

#infinity-hud .ih-next__fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sb-aqua), var(--sb-gold));
    transform: scaleX(var(--ih-progress, 0));
    transform-origin: left center;
    transition: transform 420ms var(--sb-ease-lock);
}

#infinity-hud .ih-next__caption {
    margin-top: 8px;
    color: var(--sb-text-muted);
    font: 600 12px / 1.3 var(--sb-font-text);
}

/* The milestones: a row of pips, passed in gold, the next lit. */
#infinity-hud .ih-milestones {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

#infinity-hud .ih-milestone {
    padding: 4px 8px;
    border: 1px solid var(--sb-line);
    border-radius: 7px;
    color: var(--sb-text-faint);
    font: 700 10px / 1 var(--sb-font-text);
    font-variant-numeric: tabular-nums;
    transition: color 400ms ease, border-color 400ms ease, background 400ms ease;
}

#infinity-hud .ih-milestone.is-next {
    border-color: rgba(var(--sb-aqua-rgb), 0.7);
    color: var(--sb-text);
    background: rgba(var(--sb-aqua-rgb), 0.12);
}

#infinity-hud .ih-milestone.is-passed {
    border-color: rgba(var(--sb-gold-rgb), 0.6);
    color: var(--sb-gold);
    background: rgba(var(--sb-gold-rgb), 0.12);
}

#infinity-hud .ih-milestone.is-new {
    animation: ih-milestone 700ms var(--sb-ease-lock);
}

@keyframes ih-milestone {
    0% { transform: scale(1); }
    40% { transform: scale(1.25); box-shadow: 0 0 16px rgba(var(--sb-gold-rgb), 0.6); }
    100% { transform: scale(1); }
}

#infinity-hud .ih-ceiling {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    color: var(--sb-text-faint);
    font: 600 11px / 1.3 var(--sb-font-text);
}

#infinity-hud .ih-ceiling span:last-child {
    color: var(--sb-text-muted);
}

#infinity-hud .ih-score {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

#infinity-hud .ih-score__value {
    color: var(--sb-text);
    font: 600 clamp(20px, 1.8vw, 26px) / 1.1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
}

#infinity-hud .ih-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
}

#infinity-hud .ih-best .ih-pair {
    margin-top: 10px;
}

/* The climb at the head of the HUD, the records at its foot. */
#infinity-hud .ih-best {
    margin-top: auto;
}

#infinity-hud .ih-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

#infinity-hud .ih-stat .ih-label {
    font-size: 8px;
    letter-spacing: 0.12em;
}

#infinity-hud .ih-stat__value {
    color: var(--sb-text);
    font: 700 14px / 1.2 var(--sb-font-text);
    font-variant-numeric: tabular-nums;
}

#infinity-hud .ih-best .ih-stat__value {
    color: var(--sb-gold);
}

/* ---- The tower map (Infinity's minimap; also each Last Standing board) ------------- */
/* A definite box (Infinity and Last Standing size their own; Odyssey's tall boards take
   this one): the canvas fills it, so its backing store never feeds back into its size. */
.infinity-minimap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-sizing: border-box;
    width: 96px;
    height: 420px;
    padding: 12px 10px;
    border: 1px solid var(--sb-line);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(25, 21, 56, 0.92) 0%, rgba(12, 10, 30, 0.94) 100%);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
    cursor: grab;
    touch-action: none;
    transition: border-color var(--sb-dur-3) ease, box-shadow var(--sb-dur-3) ease;
}

.infinity-minimap:active {
    cursor: grabbing;
}

.infinity-minimap .minimap-title {
    color: var(--sb-text-faint);
    font: 600 9px / 1 var(--sb-font-display);
    letter-spacing: 0.2em;
    text-align: center;
    text-transform: uppercase;
}

.infinity-minimap .minimap-canvas,
.infinity-minimap canvas {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border-radius: 6px;
    background: rgba(9, 8, 24, 0.6);
    image-rendering: pixelated;
}

.infinity-minimap .minimap-instruction {
    color: var(--sb-text-faint);
    font: 600 8px / 1.2 var(--sb-font-text);
    text-align: center;
    opacity: 0;
    transition: opacity var(--sb-dur-3) ease;
}

/* Paused (or pointed at): the map can be dragged to look around. A controller never hovers,
   so with one in hand the right-stick line stays on the map (read-only maps have none). */
.infinity-minimap:hover .minimap-instruction,
.infinity-minimap.is-explorable .minimap-instruction,
body.sb-input-gamepad .infinity-minimap .minimap-instruction {
    opacity: 1;
}

.infinity-minimap.is-explorable,
.infinity-minimap:hover {
    border-color: rgba(var(--sb-aqua-rgb), 0.5);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3), 0 0 22px rgba(var(--sb-aqua-rgb), 0.16);
}

/* In Infinity: beside the well, as tall as it. */
#single-player-container.infinity-mode-active #infinity-minimap.infinity-minimap {
    order: 3;
    align-self: flex-end;
    width: var(--tower-w, 80px);
    height: var(--board-height);
    max-height: none;
    margin: 0 !important;
    padding: 12px 10px !important;
    overflow: hidden;
    border-radius: 14px !important;
    background: linear-gradient(180deg, rgba(25, 21, 56, 0.92) 0%, rgba(12, 10, 30, 0.94) 100%) !important;
    opacity: 1;
    transform: none;
}

#single-player-container.infinity-mode-active #infinity-minimap canvas {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    object-fit: fill;
}

#single-player-container.infinity-mode-active #infinity-minimap .minimap-title {
    margin: 0 !important;
    font-size: 9px !important;
}

/* ---- Portrait: the ledger and the HUD become a strip under the board --------------- */
@media (max-aspect-ratio: 1/1) {
    .single-player-stage[data-board='well'] {
        --sp-strip: clamp(52px, calc(var(--sp-vh) * 0.07), 66px);
        --sp-below: calc(var(--sp-strip) + 12px);
        --sp-board-w-room: calc(100vw - 32px);
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar {
        top: calc(var(--sp-top) + var(--sp-next-h) + var(--sp-queue-gap) + var(--board-height) + 12px);
        left: 50%;
        flex-direction: row;
        width: var(--board-width);
        height: var(--sp-strip);
        transform: translateX(-50%);
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        gap: 4px;
        padding: 8px 12px;
        border-top: 0;
        border-left: 1px solid var(--sb-line);
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat:first-child {
        flex: 1.4 1 0;
        padding-left: 14px;
        border-left: 0;
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .stat-score .single-player-stat-value {
        font-size: 20px;
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .single-player-stat .single-player-stat-value {
        justify-self: start;
        font-size: 16px;
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-caption,
    .single-player-stage[data-board='well'] .single-player-stats-bar .sp-pace {
        display: none;
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-track {
        width: 100%;
        height: 4px;
    }

    /* Infinity: the tower a slim rail beside the board, the HUD a strip under it. */
    .single-player-stage[data-board='well'].infinity-mode-active {
        --tower-w: clamp(34px, 9vw, 48px);
        --sp-side-gap: 10px;
        --sp-board-w-room: calc(100vw - 32px - var(--tower-w) - var(--sp-side-gap));
    }

    /* (InfinityMode sets the container's display inline.) */
    .single-player-stage[data-board='well'] #single-player-container.infinity-mode-active {
        display: grid !important;
        grid-template-columns: var(--board-width) var(--tower-w);
        grid-template-areas:
            "card tower"
            "hud hud";
        justify-content: center;
        align-items: end;
        column-gap: var(--sp-side-gap);
        row-gap: 12px;
    }

    .single-player-stage[data-board='well'] #single-player-container.infinity-mode-active .single-player-card {
        grid-area: card;
    }

    #single-player-container.infinity-mode-active #infinity-minimap.infinity-minimap {
        grid-area: tower;
        width: var(--tower-w);
        padding: 6px 4px !important;
        border-radius: 10px !important;
    }

    #single-player-container.infinity-mode-active #infinity-minimap .minimap-title,
    #single-player-container.infinity-mode-active #infinity-minimap .minimap-instruction {
        display: none;
    }

    #single-player-container.infinity-mode-active #infinity-hud.infinity-hud {
        grid-area: hud;
        flex-direction: row;
        align-items: stretch;
        width: auto;
        height: var(--sp-strip);
    }

    #infinity-hud .ih-kicker,
    #infinity-hud .ih-best,
    #infinity-hud .ih-milestones,
    #infinity-hud .ih-ceiling,
    #infinity-hud .ih-pair,
    #infinity-hud .ih-next__caption {
        display: none;
    }

    #infinity-hud section {
        display: flex;
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        padding: 6px 12px;
        border-top: 0;
    }

    #infinity-hud section + section {
        border-left: 1px solid var(--sb-line);
    }

    #infinity-hud .ih-height {
        margin: 2px 0 4px;
    }

    #infinity-hud .ih-height__value {
        font-size: 20px;
    }

    #infinity-hud .ih-score {
        margin: 0;
    }

    #infinity-hud .ih-score__value {
        font-size: 18px;
    }
}

/* ---- The ascent: looking around the tower (Infinity) -------------------------------------
 * src/ui/infinity/ascent/ascent-overlay.js draws in the well: the height ruler on its wall,
 * the milestones as floors of light, the tower's memories, the way home with the ring that
 * fills before the view flies back, and the altimeter. Every part is placed by a transform
 * from the camera row; --ia-presence fades the whole with the look.
 * src/ui/infinity/ascent/ascent-sky-stage.js lays the sky between the theme and the board.
 * ----------------------------------------------------------------------------------------- */
.ia-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    overflow: hidden;
    visibility: hidden;
    opacity: var(--ia-presence, 0);
    pointer-events: none;
}

.ia-overlay.is-shown {
    visibility: visible;
}

.ia-ruler {
    position: absolute;
    inset: 0 auto 0 0;
    width: 48px;
}

.ia-tick {
    position: absolute;
    top: 0;
    left: 0;
    width: 10px;
    height: 1px;
    background: rgba(var(--sb-cream-rgb), 0.5);
    will-change: transform;
}

.ia-tick.is-major {
    width: 16px;
    background: rgba(var(--sb-aqua-rgb), 0.85);
}

.ia-tick__label {
    position: absolute;
    top: -5px;
    left: 14px;
    color: rgba(var(--sb-cream-rgb), 0.62);
    font: 600 9px / 1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.ia-tick.is-major .ia-tick__label {
    left: 20px;
    color: rgba(var(--sb-aqua-rgb), 0.92);
}

.ia-floor {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 2px;
    margin-top: -1px;
    background: linear-gradient(90deg, transparent, rgba(var(--sb-cream-rgb), 0.34) 12%, rgba(var(--sb-cream-rgb), 0.34) 88%, transparent);
    box-shadow: 0 0 10px rgba(var(--sb-cream-rgb), 0.18);
    will-change: transform;
}

.ia-floor.is-reached {
    background: linear-gradient(90deg, transparent, rgba(var(--sb-gold-rgb), 0.95) 10%, rgba(var(--sb-gold-rgb), 0.95) 90%, transparent);
    box-shadow: 0 0 14px rgba(var(--sb-gold-rgb), 0.5);
}

.ia-floor__label {
    position: absolute;
    right: 10px;
    bottom: 6px;
    color: rgba(var(--sb-cream-rgb), 0.72);
    font: 600 9px / 1 var(--sb-font-display);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
}

.ia-floor.is-reached .ia-floor__label {
    color: var(--sb-gold);
}

/* The element only moves (its transform is the camera's); the diamond is its ::before, so the
   rotation never turns the translation (a `rotate` property here would apply after it). */
.ia-mark {
    position: absolute;
    top: 0;
    right: 7px;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    will-change: transform;
}

.ia-mark::before {
    position: absolute;
    inset: 0;
    border-radius: 1px;
    background: var(--sb-aqua);
    box-shadow: 0 0 10px rgba(var(--sb-aqua-rgb), 0.85);
    content: '';
    transform: rotate(45deg);
}

.ia-mark[data-kind='lines']::before {
    background: var(--sb-cream);
    box-shadow: 0 0 10px rgba(var(--sb-cream-rgb), 0.7);
}

.ia-mark[data-kind='perfect']::before {
    background: var(--sb-gold);
    box-shadow: 0 0 12px rgba(var(--sb-gold-rgb), 0.9);
}

.ia-caption {
    position: absolute;
    top: 0;
    right: 22px;
    margin-top: -12px;
    padding: 6px 11px;
    border: 1px solid rgba(var(--sb-aqua-rgb), 0.38);
    border-radius: 999px;
    background: rgba(9, 8, 24, 0.82);
    color: var(--sb-cream);
    font: 600 11px / 1.1 var(--sb-font-text);
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--sb-dur-3) ease;
}

.ia-caption.is-shown {
    opacity: 1;
}

/* The way home: a badge in the well's right corner, on the side the player's rows lie (the
   altimeter, top left, says it in words). */
.ia-home {
    position: absolute;
    right: 10px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px 4px 4px;
    border: 1px solid rgba(var(--sb-aqua-rgb), 0.4);
    border-radius: 999px;
    background: rgba(9, 8, 24, 0.82);
    color: var(--sb-cream);
    font: 600 11px / 1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--sb-dur-3) ease;
}

.ia-home.is-up {
    top: 12px;
    bottom: auto;
}

.ia-home.is-shown {
    opacity: 1;
}

.ia-home__ring {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    transform: rotate(-90deg);
}

.ia-home__track,
.ia-home__fill {
    fill: none;
    stroke-width: 2;
}

.ia-home__track {
    stroke: rgba(var(--sb-cream-rgb), 0.2);
}

.ia-home__fill {
    stroke: var(--sb-aqua);
    stroke-linecap: round;
}

.ia-home__arrow {
    position: absolute;
    top: 4px;
    left: 4px;
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    color: var(--sb-aqua);
    font: 700 12px / 1 var(--sb-font-text);
}

.ia-home__arrow::before {
    content: '\2193';
}

.ia-home.is-up .ia-home__arrow::before {
    content: '\2191';
}

.ia-home.is-returning {
    border-color: rgba(var(--sb-aqua-rgb), 0.75);
    box-shadow: 0 0 18px rgba(var(--sb-aqua-rgb), 0.25);
}

.ia-altimeter {
    position: absolute;
    top: 12px;
    left: 12px;
    display: grid;
    grid-template-columns: max-content 1fr;
    align-items: baseline;
    justify-items: start;
    column-gap: 6px;
    padding: 9px 13px 10px;
    border: 1px solid var(--sb-line-strong);
    border-radius: 12px;
    background: rgba(9, 8, 24, 0.74);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.ia-altimeter__label {
    grid-column: 1 / -1;
    margin-bottom: 5px;
    color: rgba(var(--sb-aqua-rgb), 0.88);
    font: 600 8px / 1 var(--sb-font-display);
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

.ia-altimeter__value {
    color: var(--sb-cream);
    font: 600 24px / 1 var(--sb-font-display);
    font-variant-numeric: tabular-nums;
}

.ia-altimeter__unit {
    color: var(--sb-text-muted);
    font: 600 10px / 1 var(--sb-font-text);
}

.ia-altimeter__sub {
    grid-column: 1 / -1;
    margin-top: 6px;
    color: var(--sb-text-muted);
    font: 600 10px / 1.2 var(--sb-font-text);
}

.ia-altimeter__hint {
    display: none;
    grid-column: 1 / -1;
    max-width: 156px;
    margin-top: 7px;
    color: var(--sb-text-faint);
    font: 500 9px / 1.4 var(--sb-font-text);
}

.ia-altimeter.is-first .ia-altimeter__hint {
    display: block;
}

/* The sky between the theme and the board: after the theme layer at its z-index, so it wins on
   document order and stays under the well. Its canvas is transparent where it covers nothing. */
.ia-sky {
    position: fixed;
    inset: 0;
    z-index: -1;
    visibility: hidden;
    pointer-events: none;
}

.ia-sky.is-shown {
    visibility: visible;
}

.ia-sky__canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

/* Without a renderer: two gradients stand in for the night and the depths. */
.ia-sky__css-night,
.ia-sky__css-deep {
    position: absolute;
    inset: 0;
}

.ia-sky__css-night {
    background: linear-gradient(180deg,
        rgb(var(--ia-night-rgb, 8, 9, 24)) 0%,
        rgb(var(--ia-night-rgb, 8, 9, 24)) 45%,
        rgba(var(--ia-glow-rgb, 104, 116, 168), 0.6) 78%,
        transparent 100%);
    opacity: calc(var(--ia-presence, 0) * min(1, var(--ia-sky, 0) * 1.4));
    transform: scaleY(calc(0.2 + var(--ia-sky, 0) * 1.6));
    transform-origin: top;
}

.ia-sky__css-deep {
    background: linear-gradient(0deg,
        rgb(var(--ia-ground-rgb, 26, 22, 44)) 0%,
        rgba(var(--ia-ground-rgb, 26, 22, 44), 0.6) 45%,
        transparent 100%);
    opacity: calc(var(--ia-presence, 0) * var(--ia-deep, 0));
}

@media (max-aspect-ratio: 1/1) {
    .ia-altimeter {
        top: 8px;
        left: 8px;
        padding: 7px 10px 8px;
    }

    .ia-altimeter__value {
        font-size: 18px;
    }

    .ia-altimeter.is-first .ia-altimeter__hint,
    .ia-tick__label,
    .ia-floor__label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .single-player-stage[data-board='well'][data-danger] #single-player-border,
    #infinity-hud .ih-milestone.is-new {
        animation: none;
    }

    .single-player-stage[data-board='well'] .single-player-stats-bar .sp-level-fill,
    #infinity-hud .ih-next__fill,
    .ia-caption,
    .ia-home {
        transition: none;
    }
}
