/* Purr Prix -- layout + UI. Mobile first: portrait = handheld (screen on top, deck below),
   landscape = full-bleed screen with overlay controls. */
@font-face {
    font-family: 'PPVGA';
    src: url('/style/fonts/Perfect DOS VGA 437.ttf') format('truetype');
    font-display: swap;
}

:root {
    --pp-bg: #120f1c;
    --pp-shell: #2a2340;
    --pp-shell-hi: #3b3159;
    --pp-ink: #f4efe6;
    --pp-dim: #a69cc0;
    --pp-gold: #ffd23a;
    --pp-pink: #ff6fae;
    --pp-cyan: #5ee6e8;
    --pp-red: #ff4d5a;
    --pp-green: #57d67a;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; height: 100%;
    background: var(--pp-bg);
    color: var(--pp-ink);
    font-family: 'PPVGA', ui-monospace, monospace;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; }

#screen {
    position: relative;
    container-type: size;   /* HUD sizes use cqh so they scale with the game screen, not the window */
    flex: none;
    overflow: hidden;
    background: #000;
    image-rendering: pixelated;
}
#screen > canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ---------- portrait: handheld ---------- */
#app[data-layout="portrait"] { justify-content: flex-start; }
#app[data-layout="portrait"] #screen {
    border-bottom: 4px solid #000;
    box-shadow: 0 4px 0 var(--pp-shell-hi);
}
#app[data-layout="portrait"] #deck {
    flex: 1; width: 100%; min-height: 0;
    display: flex; flex-direction: column; gap: 12px;
    padding: 12px 14px calc(28px + var(--safe-b));
    background: linear-gradient(var(--pp-shell), #1d1830);
}
#app[data-layout="portrait"] .controls {
    margin-top: auto;   /* controls sit low in the thumb zone */
    display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}

/* map + standings: in the deck on portrait phones, a HUD corner otherwise */
#info { display: flex; gap: 12px; min-height: 0; flex: 0 1 auto; max-height: 34vh; }
#info > #minimap { height: 100%; max-height: 34vh; aspect-ratio: 1; width: auto; image-rendering: auto; background: #0005; border: 3px solid #000; border-radius: 10px; }
#info .standings { flex: 1; }
#app[data-phase="menu"] #deck #info { visibility: hidden; }
#info.compact { position: absolute; right: 2%; top: 17%; max-height: none; pointer-events: none; }
#info.compact > #minimap { height: 30cqh; max-height: none; border-width: 2px; background: #0004; }
#info.compact .standings { display: none; }

.standings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; justify-content: space-between; font-size: 12px; }
.standings li { display: flex; align-items: center; gap: 6px; padding: 1px 6px; border-radius: 4px; color: var(--pp-dim); }
.standings li b { width: 1.2em; text-align: right; color: var(--pp-ink); }
.standings li i { width: 10px; height: 10px; background: var(--kart); border: 2px solid #000; border-radius: 50%; }
.standings .head-icon { width: 16px; height: 16px; flex: 0 0 16px; image-rendering: pixelated; }
.standings li.me { background: #fff2; color: #fff; }
/* the race's rival CPU (PP.AI.rivalFor): small tag after the name */
em.rival { font-style: normal; font-size: 9px; line-height: 1; letter-spacing: 1px; padding: 2px 3px 1px; margin-left: 6px; border-radius: 3px; background: var(--pp-red); color: #fff; vertical-align: 1px; }
.standings li em.rival { margin-left: auto; }

/* ---------- landscape: full bleed, controls float ---------- */
#app[data-layout="landscape"] { justify-content: center; }
#app[data-layout="landscape"] #deck {
    position: absolute; inset: 0;
    pointer-events: none;
}
#app[data-layout="landscape"] .controls {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: flex-end; justify-content: space-between;
    padding: 0 calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l));
}
#app[data-layout="landscape"] .controls > * { pointer-events: auto; opacity: 0.62; }
#app[data-layout="landscape"] .pad { width: 36vh; height: 24vh; }
#app[data-layout="landscape"] .btns { width: 34vh; }
#app[data-layout="landscape"] .btn.drift { width: 18vh; height: 18vh; }
#app[data-layout="landscape"] .btn { width: 12vh; height: 12vh; font-size: 11px; }

#app[data-touch="0"] #deck { display: none; }
#app[data-touch="0"] .touch-only { display: none; }
#app[data-touch="1"] .keys-only { display: none; }

/* ---------- steer pad ---------- */
.pad {
    position: relative;
    width: min(48vw, 260px); height: min(36vw, 170px);
    border-radius: 22px;
    background: rgba(0, 0, 0, 0.35);
    border: 3px solid #000;
    box-shadow: inset 0 0 0 2px var(--pp-shell-hi);
    touch-action: none;
}
.pad .rail {
    position: absolute; left: 14%; right: 14%; top: 50%; height: 6px; margin-top: -3px;
    background: rgba(255, 255, 255, 0.12); border-radius: 3px;
}
.pad .knob {
    position: absolute; left: 50%; top: 50%;
    width: 56px; height: 56px; margin: -28px 0 0 -28px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffffff55, transparent 45%), var(--pp-cyan);
    border: 3px solid #000;
    box-shadow: 0 4px 0 #0007;
    pointer-events: none;
}
.pad.active .knob { background: radial-gradient(circle at 35% 30%, #ffffff77, transparent 45%), #8ff5ff; }
.pad .label { position: absolute; bottom: 6px; width: 100%; text-align: center; font-size: 11px; color: var(--pp-dim); pointer-events: none; }

/* ---------- buttons ---------- */
.btns {
    position: relative;
    width: min(46vw, 250px); height: min(40vw, 190px);
}
.btn {
    position: absolute;
    border-radius: 50%;
    border: 3px solid #000;
    box-shadow: 0 5px 0 #0008, inset 0 3px 0 #ffffff40;
    font-size: 12px; letter-spacing: 1px;
    touch-action: none;
}
.btn.down { transform: translateY(3px); box-shadow: 0 2px 0 #0008, inset 0 3px 0 #ffffff30; filter: brightness(1.2); }
.btn.drift { right: 0; bottom: 0; width: 46%; height: auto; aspect-ratio: 1; background: var(--pp-pink); }
.btn.brake { left: 6%; bottom: 0; width: 30%; aspect-ratio: 1; height: auto; background: var(--pp-red); }
.btn.item { left: 22%; top: 0; width: 30%; aspect-ratio: 1; height: auto; background: var(--pp-gold); color: #241a00; }
.btn:disabled { opacity: 0.35; }
.btn.item:not(.ready) { filter: saturate(0.3) brightness(0.7); }
.btn.item.ready { box-shadow: 0 5px 0 #0008, inset 0 3px 0 #ffffff50, 0 0 0 3px #fff8; }
#app[data-layout="landscape"] .btn.brake { left: 0; bottom: 0; }
#app[data-layout="landscape"] .btn.item { left: auto; right: 2vh; top: auto; bottom: 20vh; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; color: #fff; }
#hud > div { text-shadow: 0.25cqh 0.25cqh 0 #000, -0.15cqh -0.15cqh 0 #000; }
.hud-time { position: absolute; top: 3%; right: 3%; font-size: 6.5cqh; }
.hud-lap { position: absolute; top: 3%; left: 50%; transform: translateX(-50%); font-size: 6.5cqh; }
.hud-pos {
    position: absolute; right: 3%; bottom: 4%;
    font-size: 15cqh; line-height: 1; letter-spacing: -0.03em;
    color: var(--pp-ink);
    text-shadow: 0.5cqh 0.5cqh 0 #000, -0.3cqh -0.3cqh 0 #000 !important;
}
.hud-pos[data-place="1"] { color: var(--pp-gold); }
.hud-pos[data-place="2"] { color: #dfe6f2; }
.hud-pos[data-place="3"] { color: #f0a868; }
.hud-wrong {
    position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
    font-size: 8cqh; color: var(--pp-red);
    animation: blink 0.5s steps(2) infinite;
}
.hud-wrong[hidden], .banner[hidden] { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.banner {
    position: absolute; top: 34%; left: 0; right: 0; text-align: center;
    font-size: 11cqh; color: #fff; letter-spacing: 0.05em;
}
.banner[data-kind="count"] { font-size: 26cqh; top: 22%; color: var(--pp-gold); }
.banner[data-kind="go"] { font-size: 24cqh; top: 22%; color: var(--pp-green); }
.banner[data-kind="good"] { color: var(--pp-gold); }
.banner[data-kind="bad"] { color: var(--pp-red); }
.banner.pop { animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.hud-pause {
    position: absolute; top: 3%; left: 2%;
    color: #fff;
    pointer-events: auto;
    width: 34px; height: 30px;
    background: #0008; border: 2px solid #000; border-radius: 6px;
    font-size: 13px;
}
/* item slot (top left, under pause) + fish count */
.hud-item {
    position: absolute; top: 15%; left: 2%;
    width: 19cqh; height: 19cqh;
    background: #0009; border: 0.6cqh solid #000; border-radius: 2.5cqh;
    box-shadow: inset 0 0 0 0.5cqh var(--pp-shell-hi);
}
.hud-item canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.hud-item[data-state="roll"] { box-shadow: inset 0 0 0 0.5cqh var(--pp-cyan); }
.hud-item[data-state="ready"] { box-shadow: inset 0 0 0 0.5cqh var(--pp-gold); }
.hud-item[data-state="drag"] { box-shadow: inset 0 0 0 0.5cqh var(--pp-pink); }
.hud-item b { position: absolute; right: 0.6cqh; bottom: 0; font-size: 5.5cqh; font-weight: normal; color: #fff; }
.hud-fish { position: absolute; top: 36%; left: 2%; display: flex; align-items: center; gap: 0.8cqh; font-size: 6.5cqh; }
.hud-fish canvas { width: 8cqh; height: 8cqh; image-rendering: pixelated; }
.hud-fish[data-max="1"] { color: var(--pp-gold); }
.debug {
    position: absolute; left: 0; bottom: 0; right: 0;
    font-size: 10px; background: #0008; padding: 2px 4px; color: var(--pp-green);
    pointer-events: none;
}

/* ---------- panels ---------- */
.panel {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2%;
    padding: 3%;
    background: rgba(18, 15, 28, 0.86);
    text-align: center;
    overflow-y: auto;
}
.panel[hidden], #hud[hidden] { display: none; }
/* Menus cover the whole window (in portrait that includes the idle deck), and center
   without clipping when they're taller than the window. */
.panel.menu, .panel.loading { position: fixed; z-index: 5; justify-content: flex-start; }
.panel.menu > :first-child { margin-top: auto; }
.panel.menu > :last-child { margin-bottom: auto; }
.loading { font-size: 18px; }
.panel.loading { z-index: 6; }   /* M7: over the standings panel while the next track bakes */
.logo {
    margin: 0;
    font-size: clamp(22px, 8vmin, 48px);
    color: var(--pp-gold);
    letter-spacing: 3px;
    text-shadow: 3px 3px 0 #000, 0 0 0 #000, 6px 6px 0 var(--pp-pink);
}
.sub, .hint { margin: 0; font-size: 12px; color: var(--pp-dim); max-width: 46ch; }
.back { color: var(--pp-cyan); font-size: 12px; }

/* ---------- menu look (2026-11-06) ----------
   Every menu but the title, podium and pause sits on a dimmed, blurred copy of the title art (--menu-art, set on
   #app by js/ui.js) under a faint checker. Pieces: .mhead (kicker + title + checkered rule), .card (bevelled box),
   arcade buttons, .track-banner (a track's skyline art as a strip), .brow (a leaderboard row). */
.panel.menu {
    gap: 12px;
    padding: 16px 14px calc(16px + var(--safe-b));
    background:
        repeating-conic-gradient(#ffffff07 0 25%, transparent 0 50%) 0 0 / 24px 24px,
        radial-gradient(ellipse at 50% -10%, #3b2a5c 0%, #1d1830 55%, #120f1c 100%);
    isolation: isolate;
    touch-action: pan-y;
}
.panel.menu::before {
    content: ''; position: fixed; inset: -24px; z-index: -1; pointer-events: none;
    background: var(--menu-art, none) center / cover no-repeat;
    filter: blur(5px) brightness(0.32) saturate(1.15);
    image-rendering: auto;
}
.panel.menu.title-screen::before, .panel.menu.podium::before { display: none; }
.panel.menu.see-through { background: rgba(18, 15, 28, 0.72); }
.panel.menu.see-through::before { display: none; }

.mhead { display: flex; flex-direction: column; align-items: center; gap: 2px; width: min(460px, 100%); }
.mhead small { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--pp-cyan); text-shadow: 1px 1px 0 #000; }
.menu .mhead h2 {
    margin: 0; font-size: 26px; font-weight: normal; letter-spacing: 1px; line-height: 1.1;
    color: var(--pp-gold); text-shadow: 2px 2px 0 #000, 4px 4px 0 var(--pp-pink);
}
.mhead::after {
    content: ''; align-self: stretch; height: 8px; margin-top: 8px;
    background: repeating-conic-gradient(var(--pp-ink) 0 25%, #000 0 50%) 0 0 / 8px 8px;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent);
    opacity: 0.85;
}
.menu h2 { margin: 0; font-size: 22px; }
.menu h3 { margin: 0 0 4px; font-size: 18px; font-weight: normal; color: var(--pp-gold); text-shadow: 1px 1px 0 #000; }
.menu [hidden] { display: none !important; }
.menu .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.card {
    background: linear-gradient(#2e2648f0, #1b1630f0);
    border: 3px solid #000; border-radius: 10px;
    box-shadow: inset 0 0 0 2px #ffffff14, inset 0 2px 0 2px #ffffff10, 0 4px 0 #000;
}

/* arcade buttons: a lit top edge, a dark lip, a hard drop shadow; they press down */
.menu button {
    min-width: 140px; padding: 7px 16px;
    background: linear-gradient(#ffffff22, #ffffff00 55%), var(--btn, var(--pp-shell-hi));
    border: 3px solid #000; border-radius: 8px;
    box-shadow: inset 0 2px 0 #ffffff38, inset 0 -3px 0 #00000055, 0 4px 0 #000;
    color: var(--btn-ink, var(--pp-ink)); text-shadow: 1px 1px 0 #00000080;
    cursor: pointer;
    transition: transform 0.06s, box-shadow 0.06s, filter 0.1s;
}
.menu button:hover:not(:disabled) { filter: brightness(1.12); }
.menu button:active:not(:disabled) { transform: translateY(3px); box-shadow: inset 0 2px 0 #ffffff30, inset 0 -2px 0 #00000055, 0 1px 0 #000; }
.menu button.big { --btn: var(--pp-pink); min-width: 160px; font-size: 18px; padding: 10px 26px; letter-spacing: 1px; }
.menu button.ghost { background: #0006; border-color: var(--pp-shell-hi); box-shadow: 0 3px 0 #000; color: var(--pp-dim); text-shadow: none; }
.menu button:disabled { opacity: 0.45; cursor: default; }
.menu button:focus-visible, .menu summary:focus-visible { outline: 2px solid var(--pp-cyan); outline-offset: 3px; }

.racer-list { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; width: 100%; max-width: 640px; }
.menu .racer-list .racer {
    min-width: 0; padding: 3px 0 4px;
    display: flex; flex-direction: column; align-items: center;
    background: radial-gradient(ellipse at 50% 30%, #ffffff14, #0000 70%), #0008;
    border: 3px solid #000; border-radius: 8px; box-shadow: inset 0 0 0 2px #ffffff10, 0 3px 0 #000;
    font-size: 10px;
}
.racer-list .racer canvas { width: 100%; max-width: 64px; aspect-ratio: 1; image-rendering: pixelated; }
.menu .racer-list .racer[aria-pressed="true"] {
    background: radial-gradient(ellipse at 50% 30%, #ffffff55, #0000 70%), var(--kart);
    box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--pp-gold), 0 3px 0 #000;
    color: #000; text-shadow: 0 0 2px #fff;
    transform: translateY(-2px);
}
@media (max-aspect-ratio: 1/1) {
    .racer-list { grid-template-columns: repeat(4, 1fr); }
    .racer-list .racer canvas { max-width: 52px; }
}

.cc-pick { display: flex; gap: 6px; }
.menu .cc-pick button { min-width: 0; padding: 4px 12px; font-size: 13px; }
.menu .cc-pick button[aria-pressed="true"] { --btn: var(--pp-cyan); --btn-ink: #04282a; text-shadow: none; }

/* title */
.panel.menu.title-screen { background: radial-gradient(ellipse at 50% 30%, #3b2a5c 0%, rgba(18, 15, 28, 0.96) 70%); }
.logo-img { width: min(480px, 90vw); image-rendering: pixelated; filter: drop-shadow(0 6px 0 #0008); animation: logo-bob 3.2s ease-in-out infinite; }
@keyframes logo-bob { 50% { transform: translateY(-5px); } }
.logo-img[hidden], .logo[hidden] { display: none; }
.panel.menu.title-screen.with-art {
    background-color: var(--pp-bg);
    background-image: linear-gradient(#120f1c55, #120f1c22 40%, #120f1cbb), var(--menu-art);
    background-position: center;
    background-size: cover;
    image-rendering: pixelated;
}
.with-art .sub, .with-art .howto, .with-art .back { text-shadow: 1px 2px 0 #120f1c, -1px -1px 0 #120f1c; }
.with-art .sub, .with-art .howto { color: var(--pp-ink); }
.tagline { letter-spacing: 1px; }
.title-btns { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 4px 0; }
.menu .title-btns button.big { min-width: 230px; font-size: 22px; padding: 12px 28px; }
.menu .title-btns .row button { min-width: 110px; }
.trophy-rows { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.trophy-row { display: flex; align-items: center; gap: 10px; margin: 2px 0; padding: 6px 12px; background: #120f1caa; border: 2px solid #000; border-radius: 10px; }
.cup-emblem { width: var(--sz, 32px); height: var(--sz, 32px); flex: none; image-rendering: pixelated; }
.trophy-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--pp-dim); font-size: 11px; }
.trophy-cell .trophy-icon { width: 40px; height: 40px; background: #0006; border: 2px solid #000; border-radius: 8px; image-rendering: pixelated; }
.trophy-cell[data-got=""] .trophy-icon { opacity: 0.4; }
.trophy-cell[data-got="gold"] small { color: var(--pp-gold); }
.howto { max-width: 46ch; font-size: 12px; color: var(--pp-dim); }
.howto summary { cursor: pointer; color: var(--pp-cyan); padding: 4px; }
.howto .hint { margin-top: 6px; text-align: left; padding: 8px 10px; background: #120f1cdd; border: 2px solid #000; border-radius: 8px; }

/* cc select: one colour per class, speed chevrons */
.cc-list { display: flex; flex-direction: column; gap: 12px; width: min(340px, 92%); }
.menu .cc-card {
    --cc: var(--pp-green);
    display: grid; grid-template-columns: 52px 1fr auto; grid-template-rows: auto auto; align-items: center;
    text-align: left; padding: 10px 14px 10px 10px; gap: 0 12px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--cc) 30%, #1b1630) 0 64px, #1b1630 64px);
}
.menu .cc-card[data-cc="100"] { --cc: var(--pp-cyan); }
.menu .cc-card[data-cc="150"] { --cc: var(--pp-pink); }
.cc-card .chev { grid-row: 1 / 3; font-size: 20px; letter-spacing: -3px; color: var(--cc); text-shadow: 2px 2px 0 #000; text-align: center; }
.cc-card b { font-size: 22px; font-weight: normal; color: var(--pp-ink); }
.cc-card small { grid-column: 2; grid-row: 2; font-size: 11px; color: var(--cc); }
.cc-card .trophy-icon { grid-row: 1 / 3; grid-column: 3; width: 40px; height: 40px; image-rendering: pixelated; }
.menu .cc-card:disabled { opacity: 0.6; filter: grayscale(0.7); }
.menu .cc-card:disabled small { color: var(--pp-dim); }

/* character select */
.char-sel { gap: 10px; }
.racer-list .racer { position: relative; }
.racer-list .racer[data-locked="1"] canvas { filter: grayscale(1) brightness(0.35); }
.racer-list .racer[data-locked="1"]::after {
    content: 'LOCKED'; position: absolute; left: 0; right: 0; top: 38%;
    font-size: 9px; letter-spacing: 1px; color: var(--pp-gold); text-shadow: 1px 1px 0 #000;
}
.racer-card {
    display: flex; align-items: center; gap: 12px;
    width: min(440px, 100%); padding: 8px 12px 8px 8px;
    border-left: 10px solid var(--kart, var(--pp-shell-hi));
    text-align: left;
}
#kartPreview {
    width: 104px; height: 104px; flex: none; image-rendering: pixelated;
    background: radial-gradient(ellipse at 50% 82%, #000a 0 26%, transparent 28%), radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--kart, #555) 35%, transparent) 0 46%, transparent 48%);
}
.racer-info { flex: 1; min-width: 0; }
.racer-name b { font-size: 20px; font-weight: normal; }
.racer-name small { color: #000; background: var(--kart, var(--pp-dim)); font-size: 10px; margin-left: 6px; padding: 1px 5px; border-radius: 3px; vertical-align: 2px; }
.stat-bars { display: grid; gap: 4px; margin-top: 6px; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--pp-dim); }
.stat span { width: 7ch; }
.stat b { display: flex; gap: 3px; }
.stat i { width: 18px; height: 9px; background: #ffffff1a; border: 1px solid #000; transform: skewX(-15deg); }
.stat i.on { background: linear-gradient(#ffffff60, #0000 60%), var(--pp-cyan); }
.lock-note { margin: 4px 0 0; font-size: 11px; color: var(--pp-gold); }
.lock-note[hidden] { display: none; }

/* ---------- track banners: a track's far skyline as a strip, with a gradient for tracks without art ---------- */
.track-banner {
    position: relative;
    background:
        linear-gradient(90deg, #120f1cee 0%, #120f1c99 45%, #120f1c33 100%),
        var(--track-art, none) center bottom / auto 100% repeat-x,
        linear-gradient(#3b2a5c, #1d1830);
    image-rendering: pixelated;
    border: 3px solid #000; border-radius: 8px;
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}

/* cup select */
.cup-card { display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 12px; width: min(460px, 100%); }
.cup-top { display: flex; gap: 12px; align-items: center; }
#cupEmblem { width: 88px; height: 88px; flex: none; image-rendering: pixelated; filter: drop-shadow(0 0 10px #ffd23a55); }
.cup-top h3 { font-size: 22px; }
/* A locked cup still shows its tracks and the trophy needed to open it. */
.cup-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; width: min(460px, 100%); }
.cup-tabs[hidden] { display: none; }
.menu .cup-tab { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; align-content: center; justify-content: center; gap: 3px 5px; padding: 4px; font-size: 13px; text-align: center; border-radius: 8px; box-shadow: 0 3px 0 #000; }
.menu .cup-tab span { flex: 0 0 100%; order: 1; min-width: 0; line-height: 1.15; }
.menu .cup-tab .cup-emblem { width: 28px; height: 28px; }
.menu .cup-tab .trophy-icon { width: 20px; height: 20px; flex: none; image-rendering: pixelated; }
.menu .cup-tab[aria-pressed="false"] { filter: grayscale(0.5) brightness(0.8); }
.menu .cup-tab[aria-pressed="true"] { border-color: var(--pp-gold); color: var(--pp-gold); box-shadow: 0 0 0 2px #000, 0 0 10px #ffd23a88, 0 3px 0 #000; }
.menu .cup-tab[data-locked="1"] span::after { content: " (locked)"; color: var(--pp-dim); font-size: 10px; }
@media (max-width: 420px) {
    .cup-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.cup-lock { margin: 0; padding: 6px 10px; font-size: 12px; color: var(--pp-gold); background: #120f1cdd; border: 2px solid #000; border-radius: 8px; }
.cup-lock[hidden] { display: none; }
.cup-card[data-locked="1"] #cupEmblem { filter: grayscale(1) brightness(0.6); }
.cup-card[data-locked="1"] .track-strips { filter: grayscale(0.8) brightness(0.7); }
.track-strips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.track-strips .strip { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 0 10px 0 0; height: 44px; overflow: hidden; }
.strip .n { height: 100%; display: grid; place-items: center; background: var(--pp-gold); color: #241a00; text-shadow: none; font-weight: normal; border-right: 3px solid #000; }
/* Long names (Retro Portal Raceway) wrap to a second line: the VGA font has no ellipsis glyph. */
.strip .tn { font-size: 14px; line-height: 1.15; overflow: hidden; }
.strip small { font-size: 11px; color: var(--pp-cyan); white-space: nowrap; padding: 2px 6px; background: #120f1cdd; border: 1px solid #000; border-radius: 4px; }
em.ph { font-style: normal; font-size: 9px; letter-spacing: 1px; padding: 1px 4px; border-radius: 3px; background: var(--pp-shell-hi); color: var(--pp-gold); white-space: nowrap; }

/* ---------- leaderboard rows (results + records) ---------- */
.board-rows { display: flex; flex-direction: column; gap: 4px; width: min(440px, 100%); }
.brow {
    display: grid; grid-template-columns: 30px 26px 1fr auto auto; align-items: center; gap: 0 8px;
    height: 32px; padding-right: 10px; overflow: hidden;
    background: linear-gradient(90deg, color-mix(in srgb, var(--kart) 28%, #1b1630) 0 4px, #1b1630e8 4px);
    border: 2px solid #000; border-left: 6px solid var(--kart); border-radius: 6px;
    font-size: 13px; text-align: left;
    animation: row-in 0.35s ease-out both; animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes row-in { from { transform: translateX(28px); opacity: 0; } }
.brow .pl { height: 100%; display: grid; place-items: center; background: #0006; color: var(--pp-ink); font-size: 15px; }
.brow[data-place="1"] .pl { background: var(--pp-gold); color: #241a00; }
.brow[data-place="2"] .pl { background: #dfe6f2; color: #20242c; }
.brow[data-place="3"] .pl { background: #f0a868; color: #2c1606; }
.brow .head-icon, .srow .head-icon { width: 24px; height: 24px; image-rendering: pixelated; }
.brow .nm { white-space: nowrap; overflow: hidden; text-overflow: clip; }
.brow .tm { font-variant-numeric: tabular-nums; color: var(--pp-ink); }
.brow .pts, .srow .pts { min-width: 3ch; text-align: right; color: var(--pp-green); }
.brow .dt { min-width: 6ch; text-align: right; font-size: 11px; color: var(--pp-dim); }
.brow.me { background: linear-gradient(90deg, #ffd23a33, #ffd23a14); border-color: var(--pp-gold); box-shadow: 0 0 0 1px #000, 0 0 12px #ffd23a55; }
.brow.me .nm { color: var(--pp-gold); }
.brow-gap { color: var(--pp-dim); font-size: 12px; letter-spacing: 2px; line-height: 1; }
em.as, em.fresh { font-style: normal; font-size: 9px; letter-spacing: 1px; padding: 2px 4px 1px; margin-left: 6px; border-radius: 3px; vertical-align: 1px; }
em.as { background: var(--pp-shell-hi); color: var(--pp-ink); }
em.fresh { background: var(--pp-cyan); color: #04282a; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; width: min(440px, 100%); }
.chips:empty { display: none; }
.chip { font-size: 12px; padding: 4px 8px; border: 2px solid #000; border-radius: 6px; background: #1b1630; color: var(--pp-ink); }
.chip.hot { background: var(--pp-pink); color: #2a0614; }
.chip.gold { background: var(--pp-gold); color: #241a00; animation: chip-pop 0.5s 0.6s ease-out both; }
.chip.cool { background: var(--pp-cyan); color: #04282a; }
@keyframes chip-pop { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.12); } }

/* ---------- results ---------- */
.results .track-banner { width: min(440px, 100%); display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px; text-align: left; }
.track-banner small { font-size: 11px; color: var(--pp-cyan); letter-spacing: 1px; }
.track-banner b { font-size: 18px; font-weight: normal; }
.res-hero { display: flex; align-items: center; justify-content: center; gap: 6px; }
.result-portrait {
    width: 104px; height: 104px; object-fit: contain; image-rendering: pixelated;
    background: radial-gradient(circle, #ffffff22 0 55%, transparent 57%);
    animation: hero-in 0.5s ease-out both;
}
@keyframes hero-in { from { transform: translateY(14px) scale(0.85); opacity: 0; } }
.menu .place-big {
    font-size: 64px; line-height: 1; letter-spacing: -2px;
    color: var(--pp-ink); text-shadow: 3px 3px 0 #000, 6px 6px 0 var(--pp-shell-hi);
    animation: place-in 0.45s 0.1s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.place-big small { font-size: 26px; letter-spacing: 0; margin-left: 2px; }
.place-big[data-place="1"] { color: var(--pp-gold); text-shadow: 3px 3px 0 #000, 6px 6px 0 var(--pp-pink); }
.place-big[data-place="2"] { color: #dfe6f2; }
.place-big[data-place="3"] { color: #f0a868; }
@keyframes place-in { from { transform: scale(2.2); opacity: 0; } }
.results[data-place="1"] .res-hero { position: relative; }
.results[data-place="1"] .res-hero::before {
    content: ''; position: absolute; inset: -30px -60px; z-index: -1;
    background: repeating-conic-gradient(from 0deg, #ffd23a22 0 10deg, transparent 10deg 20deg);
    -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 65%);
    mask-image: radial-gradient(circle, #000 20%, transparent 65%);
    animation: spin 18s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------- cup standings ---------- */
.cup-progress { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; width: min(440px, 100%); }
.cup-progress li {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    height: 58px; padding: 2px; font-size: 11px; border-width: 2px; overflow: hidden;
}
.cup-progress li b { font-size: 14px; font-weight: normal; line-height: 1; }
.cup-progress li span { white-space: nowrap; overflow: hidden; text-overflow: clip; max-width: 100%; }
.cup-progress li small { font-size: 10px; color: var(--pp-dim); }
.cup-progress li .head-icon { position: absolute; right: 2px; top: 2px; width: 20px; height: 20px; image-rendering: pixelated; background: #120f1c; border: 1px solid var(--pp-gold); border-radius: 50%; }
.cup-progress li.track-banner { background: linear-gradient(#120f1c99, #120f1cdd), var(--track-art, none) center bottom / auto 100% repeat-x, linear-gradient(#3b2a5c, #1d1830); }
.cup-progress li.done small { color: var(--pp-green); }
.cup-progress li.next { border-color: var(--pp-gold); box-shadow: 0 0 10px #ffd23a66; }
.cup-progress li.next small { color: var(--pp-gold); animation: blink 1s steps(2) infinite; }
.cup-progress li.todo { filter: grayscale(0.8) brightness(0.7); }

/* Rows sit at --row (0 = top) and slide when it changes; the points bar fills to --fill (points / max points). */
.stand-board { --rh: 34px; position: relative; width: min(440px, 100%); height: calc(var(--rows, 8) * var(--rh)); flex: none; }
.srow {
    position: absolute; left: 0; right: 0; top: 0; height: calc(var(--rh) - 4px);
    transform: translateY(calc(var(--row, 0) * var(--rh)));
    transition: transform 0.7s cubic-bezier(0.5, 0, 0.2, 1);
    display: grid; grid-template-columns: 30px 26px 1fr auto auto 3ch; align-items: center; gap: 0 8px; padding-right: 10px;
    background: #1b1630e8; border: 2px solid #000; border-left: 6px solid var(--kart); border-radius: 6px;
    font-size: 13px; text-align: left; overflow: hidden; isolation: isolate;
}
.srow::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; z-index: -1;
    width: calc(var(--fill, 0) * 100%);
    background: linear-gradient(90deg, color-mix(in srgb, var(--kart) 15%, transparent), color-mix(in srgb, var(--kart) 45%, transparent));
    transition: width 0.6s ease-out;
}
.srow .pl { height: 100%; display: grid; place-items: center; background: #0006; font-size: 15px; }
.srow .nm { white-space: nowrap; overflow: hidden; text-overflow: clip; }
.srow .mv { font-size: 11px; min-width: 3ch; text-align: right; }
.srow[data-mv="up"] .mv { color: var(--pp-green); }
.srow[data-mv="down"] .mv { color: var(--pp-red); }
.srow .pts { opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.3s; }
.srow.scored .pts { opacity: 1; transform: none; }
.srow .pt { font-weight: normal; text-align: right; font-size: 15px; }
.srow.scored .pt { animation: pt-pop 0.35s ease-out; }
@keyframes pt-pop { 50% { transform: scale(1.4); color: var(--pp-gold); } }
.srow.me { border-color: var(--pp-gold); border-left-color: var(--kart); box-shadow: 0 0 12px #ffd23a55; }
.srow.me .nm { color: var(--pp-gold); }
.next-card { width: min(440px, 100%); display: grid; grid-template-columns: 1fr; gap: 2px; padding: 8px 12px; text-align: left; }
.next-card span { font-size: 11px; color: var(--pp-dim); }

/* ---------- records ---------- */
.records { gap: 10px; }
.rec-tracks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; width: min(440px, 100%); }
.menu .rec-tab { min-width: 0; height: 46px; padding: 0 4px; display: flex; align-items: flex-end; justify-content: center; font-size: 11px; box-shadow: 0 3px 0 #000; border-radius: 8px; }
.menu .rec-tab span { padding-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.menu .rec-tab.track-banner { background: linear-gradient(#120f1c22, #120f1cdd), var(--track-art, none) center bottom / auto 100% repeat-x, linear-gradient(#3b2a5c, #1d1830); }
.menu .rec-tab[aria-pressed="false"] { filter: grayscale(0.6) brightness(0.75); }
.menu .rec-tab[aria-pressed="true"] { border-color: var(--pp-gold); box-shadow: 0 0 0 2px #000, 0 0 10px #ffd23a88, 0 3px 0 #000; color: var(--pp-gold); }
.rec-cc { width: min(300px, 100%); }
.menu .rec-cc button { flex: 1; }
.rec-board .brow { grid-template-columns: 30px 26px 1fr auto 6ch; }
.rec-you { width: min(440px, 100%); padding: 10px 12px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.rec-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 5px; }
.rstat { display: flex; flex-direction: column; gap: 1px; padding: 4px 6px; background: #0006; border: 2px solid #000; border-radius: 6px; }
.rstat small { font-size: 10px; color: var(--pp-dim); }
.rstat b { font-size: 14px; font-weight: normal; font-variant-numeric: tabular-nums; }
.rstat.gold b { color: var(--pp-gold); }
.rstat.good b { color: var(--pp-green); }
.rec-chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.rec-chart .legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--pp-dim); margin-bottom: 2px; }
.legend span::before { content: ''; display: inline-block; width: 14px; height: 0; margin-right: 5px; vertical-align: 3px; border-top: 2px solid; }
.legend .k-runs::before { border-color: var(--pp-dim); width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--pp-dim); vertical-align: 0; }
.legend .k-best::before { border-color: var(--pp-gold); }
.legend .k-top::before { border-top-style: dashed; border-color: var(--pp-pink); }
.rec-chart .grid { stroke: #ffffff18; stroke-width: 1; }
.rec-chart .ax { fill: var(--pp-dim); font: 9px 'PPVGA', monospace; }
.rec-chart .runs { fill: none; stroke: #a69cc088; stroke-width: 1.5; stroke-linejoin: round; }
.rec-chart .best { fill: none; stroke: var(--pp-gold); stroke-width: 2; }
.rec-chart .top { stroke: var(--pp-pink); stroke-width: 1.5; stroke-dasharray: 5 4; }
.rec-chart .dot { fill: var(--pp-dim); stroke: #1b1630; stroke-width: 2; }
.rec-chart .dot.pb { fill: var(--pp-gold); }
.rec-chart .cursor { fill: none; stroke: var(--pp-ink); stroke-width: 2; }
.rec-chart .readout { margin: 2px 0 0; min-height: 1.3em; font-size: 11px; color: var(--pp-ink); }
.rec-chart .empty { max-width: none; padding: 14px 4px; text-align: center; }
.rec-runs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: 11px; }
.rec-runs:empty { display: none; }
.rec-runs li { display: grid; grid-template-columns: 4ch 7ch 1fr 4ch auto 3ch; gap: 6px; align-items: center; padding: 3px 6px; background: #0004; border-radius: 4px; color: var(--pp-dim); }
.rec-runs li b { font-weight: normal; color: var(--pp-ink); font-variant-numeric: tabular-nums; }
.rec-runs li em { font-style: normal; color: var(--pp-gold); }
.rec-runs li.pb b { color: var(--pp-gold); }

/* pause */
.pause-btns { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(240px, 80%); }

/* podium */
.panel.menu.podium { background: radial-gradient(ellipse at 50% 40%, #4a2a5c 0%, rgba(18, 15, 28, 0.96) 70%); }
.stage { display: flex; align-items: flex-end; justify-content: center; gap: 6px; }
.step { display: flex; flex-direction: column; align-items: center; width: min(110px, 28vw); }
.step .pod-racer { width: 100%; max-width: 112px; aspect-ratio: 1; image-rendering: pixelated; }
.step .block {
    width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 4px;
    background: linear-gradient(var(--pp-shell-hi), var(--pp-shell)); border: 2px solid #000; border-top: 6px solid var(--kart);
    font-size: 11px;
}
.step .block b { font-size: 22px; font-weight: normal; line-height: 1; }
.step .block small { color: var(--pp-dim); font-size: 10px; }
.step .block .who { display: flex; flex-direction: column; align-items: center; }
.step[data-place="1"] .block { height: 100px; }
.step[data-place="1"] .block b { color: var(--pp-gold); }
.step[data-place="2"] .block { height: 80px; }
.step[data-place="3"] .block { height: 62px; }   /* fits number + name + points (54 px of text with the top border) */
.step.me .block span { color: var(--pp-gold); }

/* Podium with Codex's art (ui-v1/podium-bg.png, 480 x 320): the art is the stage, at its own 3:2 aspect, and each
   racer stands on its painted stand. Positions are % of the art, measured from its pixels:
   stand    x range    top surface y   face y     (480 x 320 px)
   2nd      40-173     215-236         248-282
   1st      173-304    198-217         230-282
   3rd      304-440    232-252         264-282
   The faces are too short for three lines on a phone, so only the place number goes on the face; the name and
   points float above the racer's head. */
.podium.art .stage {
    position: relative; display: block; width: min(480px, 100%); aspect-ratio: 3 / 2; margin: 0 auto;
    background: var(--pod-art) 0 0 / 100% 100% no-repeat; image-rendering: pixelated;
    border: 2px solid #000; container-type: inline-size;
}
.podium.art .step { position: absolute; top: 0; bottom: 0; display: block; }
.podium.art .step[data-place="2"] { left: 8.33%; width: 27.71%; --top: 48.4%; --face: 82.8%; }
.podium.art .step[data-place="1"] { left: 36.04%; width: 27.29%; --top: 42.8%; --face: 80%; }
.podium.art .step[data-place="3"] { left: 63.33%; width: 28.33%; --top: 53.4%; --face: 85.3%; }
.podium.art .step .pod-racer { position: absolute; left: 50%; top: var(--top); width: 57%; max-width: none; transform: translateX(-50%); }
.podium.art .step .block { display: contents; }
.podium.art .step .block b {
    position: absolute; left: 0; right: 0; top: var(--face); transform: translateY(-50%); text-align: center;
    font-size: clamp(10px, 3.4cqw, 18px); color: var(--pp-ink); text-shadow: 1px 1px 0 #000;
}
.podium.art .step[data-place="1"] .block b { font-size: clamp(14px, 5.4cqw, 28px); color: var(--pp-gold); }
.podium.art .step .who {
    position: absolute; left: 50%; bottom: calc(100% - var(--top)); transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; white-space: nowrap; line-height: 1.15;
    padding: 1px 5px; background: rgba(18, 15, 28, 0.78); border: 1px solid #000;
    font-size: clamp(9px, 2.5cqw, 13px);
}
.podium.art .step .who small { font-size: 0.85em; }
.losers { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.loser { display: flex; flex-direction: column; align-items: center; width: 64px; font-size: 10px; color: var(--pp-dim); }
.loser canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.loser.me small { color: var(--pp-gold); }
.prize { display: flex; align-items: center; gap: 12px; text-align: left; }
#podTrophy { width: 96px; height: 96px; image-rendering: pixelated; }
#podTrophy[hidden] { display: none; }
.prize-line { margin: 0; font-size: 15px; }
.prize-line[data-trophy="gold"] { color: var(--pp-gold); }
.prize-line[data-trophy="silver"] { color: #dfe6f2; }
.prize-line[data-trophy="bronze"] { color: #f0a868; }
.unlocks { color: var(--pp-green); }

.prize { padding: 8px 14px; }

/* settings */
.set-card { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; width: min(380px, 94%); }
.settings .set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; font-size: 14px; }
.set-row input[type="range"] { flex: 1; accent-color: var(--pp-pink); }
.set-row output { width: 3ch; text-align: right; color: var(--pp-dim); }
.seg { display: flex; }
.menu .seg button { min-width: 0; padding: 4px 10px; border-radius: 0; box-shadow: 0 3px 0 #000; }
.menu .seg button:first-child { border-radius: 6px 0 0 6px; }
.menu .seg button:last-child { border-radius: 0 6px 6px 0; }
.menu .seg button + button { border-left: 0; }
.menu .seg button[aria-pressed="true"], .menu button.toggle[aria-pressed="true"] { --btn: var(--pp-cyan); --btn-ink: #04282a; text-shadow: none; }
.menu button.toggle { min-width: 70px; }

@media (prefers-reduced-motion: reduce) {
    .menu *, .menu *::before { animation: none !important; transition: none !important; }
}

/* pre-race tag: which cup race this is (and whether its track is still a placeholder) */
.hud-tag {
    position: absolute; left: 50%; top: 12%; transform: translateX(-50%);
    max-width: 70%; text-align: center; white-space: nowrap;
    padding: 0.8cqh 2cqh; background: #000a; border: 0.5cqh solid #000; border-radius: 1.5cqh;
    font-size: 4.6cqh; line-height: 1.25;
}
.hud-tag[hidden] { display: none; }
.hud-tag b { color: var(--pp-gold); font-weight: normal; margin-right: 1ch; }
.hud-tag small { display: block; font-size: 3.6cqh; color: var(--pp-pink); }
.banner { z-index: 1; }

/* ---------- time trial ---------- */
.menu .title-btns button.tt-btn { --btn: var(--pp-cyan); --btn-ink: #04282a; text-shadow: none; min-width: 230px; font-size: 16px; }
.menu .cc-pick button:disabled { opacity: 0.35; }
.menu .tt-tracks button.strip { width: 100%; min-width: 0; text-align: left; color: var(--pp-ink); box-shadow: 0 3px 0 #000; border-radius: 8px;
    background: linear-gradient(90deg, #120f1cee 0%, #120f1c99 45%, #120f1c33 100%), var(--track-art, none) center bottom / auto 100% repeat-x, linear-gradient(#3b2a5c, #1d1830); }
.tt-tracks .strip small.gold { color: var(--pp-gold); }
/* No one to place against: the place number and the standings go. */
#app[data-mode="tt"] .hud-pos, #app[data-mode="tt"] #standings { display: none; }
.brow.tt-best .tm { color: var(--pp-gold); }
