/* =====================================================================
   GAME 1: BLOCKFALL
   ===================================================================== */
#game-blockfall {
  position: fixed; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: calc(var(--header-h) + 10px) 16px 14px;
}
body[data-game="blockfall"] #game-blockfall { display: flex; }
.bf-crumb {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: min(660px, 100%); padding: 0 2px;
}

.app { display: flex; gap: 20px; align-items: flex-start; }
.panel { display: flex; flex-direction: column; gap: 14px; width: 162px; }
.box {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 10px 12px 12px;
}
.box h2 { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 400; }
.box canvas { display: block; margin: 0 auto; width: 120px; height: auto; }
.stats div {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5px 0; border-bottom: 1px solid var(--line);
}
.stats div:last-child { border-bottom: 0; }
.stats span { font-size: 13px; color: var(--muted); }
.stats b { font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 600; }

.well {
  position: relative; padding: 0;
  background: var(--bg); border: 1px solid var(--line-strong);
}
#board { display: block; height: min(calc(100vh - 166px), 580px); aspect-ratio: 1 / 2; }
/* Shared start screen (js/start-screen.js): the same card over every game's own scene */
.start-screen .r-best { white-space: nowrap; flex-shrink: 0; }
.start-screen .p-msg:empty { display: none; }
.start-ranks { margin: 12px 0 14px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.start-ranks-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.start-ranks-head small { font-size: 12px; color: var(--muted); }
.start-ranks-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.start-rank {
  --rc: var(--muted); --rc-rgb: var(--c1-rgb);
  display: grid; justify-items: center; gap: 2px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.start-rank[data-grade="D"] { --rc: var(--p2); --rc-rgb: var(--p2-rgb); }
.start-rank[data-grade="C"] { --rc: var(--p3); --rc-rgb: var(--p3-rgb); }
.start-rank[data-grade="B"] { --rc: var(--p4); --rc-rgb: var(--p4-rgb); }
.start-rank[data-grade="A"] { --rc: var(--p6); --rc-rgb: var(--p6-rgb); }
.start-rank[data-grade="S"] { --rc: var(--p7); --rc-rgb: var(--p7-rgb); }
.start-rank b { font-family: var(--display); font-size: 15px; font-weight: 700; line-height: 1.1; color: var(--rc); }
.start-rank span { font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.start-rank.got { border-color: rgba(var(--rc-rgb), .55); background: rgba(var(--rc-rgb), .08); }
.start-rank.got span { color: var(--text); font-weight: 600; }
@media (max-width: 420px) {
  .start-ranks-row { gap: 4px; }
  .start-rank { padding: 5px 2px; }
  .start-rank span { font-size: 11px; }
}
#game-type.idle .ty-board { display: block; opacity: .16; pointer-events: none; }
#game-type.idle .ty-caret { display: none; }
#game-type.idle .ty-view { height: calc(var(--lh) * 11); }
#game-blockfall.menu .bf-crumb, #game-blockfall.menu .touch { visibility: hidden; }
#game-blockfall .p-screen { z-index: 5; }
#game-blockfall.menu .app { opacity: .45; }
.p-btn:disabled { opacity: .45; cursor: not-allowed; }
.keys ul { list-style: none; font-size: 13px; color: var(--text-soft); display: grid; gap: 5px; }
.keys li { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
kbd {
  font-family: var(--mono); font-size: 12px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 0 5px; white-space: nowrap;
}
.touch { display: none; gap: 8px; }
.touch button {
  width: 54px; height: 54px; border-radius: calc(10px * var(--rk)); font-size: 18px;
  color: var(--text); background: rgba(var(--glass-rgb), .92); border: 1px solid var(--line-strong);
  
  touch-action: none;
}
.touch button:active { background: var(--tint); border-color: var(--accent); color: var(--accent); }
@media (pointer: coarse) {
  .touch { display: flex; }
  #board { height: min(calc(100vh - 210px), 560px); }
}

/* =====================================================================
   GAME MENU CARD CHROME (Pulse, Slipstream, Kinetic)
   ===================================================================== */
.card-crumb {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.crumb-btn {
  display: inline-flex; align-items: center; gap: 4px; margin-right: 10px;
  padding: 0; border: 0; background: none; color: var(--text);
  font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.crumb-btn:hover { color: var(--strong); }
.crumb-btn svg { display: none; }
.crumb-btn[data-nav="hub"]::before { content: "←"; }
.crumb-tries { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }


/* ---------- Kinetic ---------- */
#game-kinetic { position: fixed; inset: 0; display: none; background: #07090e; }
body[data-game="kinetic"] #game-kinetic { display: block; }
#kinCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-kinetic.playing #kinCanvas { cursor: none; }
.k-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
#game-kinetic.playing .k-hud { display: block; }
.k-top { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); padding: 8px 20px 9px; text-align: center; min-width: 190px; }
.k-sub.open { color: var(--accent); }
.k-cross { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); }
.k-cross::before, .k-cross::after { content: ""; position: absolute; background: rgba(235,241,255,.92); box-shadow: 0 0 0 1px rgba(0,0,0,.6); border-radius: 1px; }
.k-cross::before { left: 10px; top: 3px; width: 2px; height: 16px; }
.k-cross::after { top: 10px; left: 3px; height: 2px; width: 16px; }
.k-cross i { position: absolute; inset: 0; border: 2px solid #ff3d6e; border-radius: 50%; opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s; }
.k-cross.hit i { opacity: 1; transform: scale(1.15); }
.k-cores { position: absolute; right: 18px; bottom: 18px; display: flex; gap: 8px; align-items: flex-end; }
.k-core {
  --c: var(--accent);
  background: rgba(14,18,27,.74); 
  border: 1px solid rgba(255,255,255,.08); border-radius: calc(10px * var(--rk)); padding: 9px 12px 10px; min-width: 128px;
   opacity: .62; transform: scale(.92); transform-origin: bottom right;
  transition: opacity .12s, transform .12s; border-top: 3px solid var(--c);
}
.k-core.cur { opacity: 1; transform: none; }
.k-core-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.k-core b { font-family: var(--display); font-size: 12px; color: var(--c); }
.k-core span { font-size: 13px; font-weight: 600; }
.k-pips { display: flex; gap: 4px; margin: 7px 0 6px; min-height: 6px; }
.k-pips i { width: 14px; height: 6px; border-radius: 2px; background: var(--line); }
.k-pips i.on { background: var(--c); }
.k-core small { font-size: 12px; color: var(--muted); }
.k-speed { position: absolute; left: 18px; bottom: 18px; padding: 9px 14px; display: grid; gap: 3px; }
.k-speed b { font-family: var(--display); font-size: 11px; }
.k-speed span { font-size: 11.5px; color: var(--muted); }
.k-speed em { font-style: normal; font-size: 22px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.k-flash {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); opacity: 0;
  font-family: var(--display); font-size: 15px; font-weight: 800; color: var(--accent);
}
.k-flash.show { animation: kFlash 1.1s ease-out; }
@keyframes kFlash { 0% { opacity: 0; transform: translate(-50%, -30%); } 15% { opacity: 1; transform: translate(-50%, -50%); } 70% { opacity: 1; } 100% { opacity: 0; } }
.k-hint {
  position: absolute; bottom: 104px; left: 50%; transform: translateX(-50%); max-width: min(620px, 80vw); text-align: center;
  font-size: 12.5px; line-height: 1.5; color: var(--text); padding: 9px 16px; opacity: 0; transition: opacity .4s;
}
.k-hint.show { opacity: 1; }
.k-dead { position: absolute; inset: 0; opacity: 0; transition: opacity .1s; background: radial-gradient(ellipse at center, rgba(255,61,110,0) 35%, rgba(255,61,110,.45)); }
#game-kinetic.dead .k-dead { opacity: 1; }
.k-click {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 12px; color: var(--accent);
}
.k-click span { background: rgba(18,23,34,.9); padding: 12px 20px 12px 23px; border-radius: calc(8px * var(--rk)); border: 1px solid var(--line-strong); }
#game-kinetic.playing.unlocked .k-click { display: flex; }
/* Breach (room-clearing) additions */
.k-pen { font-size: 12px; font-weight: 600; color: #ff7a7a; margin-top: 2px; }
.k-pen:empty { display: none; }
.k-hp { display: flex; gap: 4px; margin: 4px 0 3px; }
.k-hp i { width: 24px; height: 7px; border-radius: 2px; background: rgba(255,255,255,.12); }
.k-hp i.on { background: #e8ebf0; }
.k-hp.low i.on { background: #ef4444; animation: kPulse .7s ease-in-out infinite alternate; }
@keyframes kPulse { to { opacity: .45; } }
.k-ammo { font-family: var(--mono); font-size: 22px !important; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.k-ammo small { font-size: 12px; color: var(--muted); }
.k-ammo.empty { color: #ff7a7a; }
.k-core small { display: block; margin-top: 4px; }
#game-kinetic.ads .k-cross { opacity: 0; }
.k-cross { transition: opacity .08s; }
.k-cross i { border-color: rgba(255,255,255,.95); border-radius: 0; border-width: 0; }
.k-cross i::before, .k-cross i::after { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.k-cross i::before { transform: translate(-50%, -50%) rotate(45deg) scaleX(1.6); }
.k-cross i::after { transform: translate(-50%, -50%) rotate(-45deg) scaleX(1.6); }
.k-cross.head i::before, .k-cross.head i::after { background: #ff4d4d; }
#game-kinetic.hurt .k-dead { opacity: .5; }
.k-flash.bad { color: #ff6b6b; }
.k-stats { font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--muted); margin: 6px 0 2px; }
.k-stats .bad { color: #ff7a7a; }
.k-range { display: flex; align-items: center; gap: 8px; }
.k-range input[type=range] { width: 110px; height: auto; accent-color: var(--accent); }
.k-range output { font-family: var(--mono); color: var(--text); min-width: 34px; }

/* ---------- Flick (aim trainer) ---------- */
#game-aim { position: fixed; inset: 0; display: none; }
body[data-game="aim"] #game-aim { display: block; }
#aimCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#game-aim.playing #aimCanvas { cursor: none; }
.aim-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
#game-aim.playing .aim-hud { display: block; }
.aim-top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; padding: 7px 4px; }
.aim-stat { display: grid; gap: 1px; text-align: center; min-width: 96px; padding: 0 12px; }
.aim-stat + .aim-stat { border-left: 1px solid var(--line); }
.aim-stat span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.aim-stat b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.aim-time b.low { color: var(--p1); }
.aim-streak {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .15s;
  font-family: var(--display); font-size: 11px; font-weight: 700;
  color: var(--accent-2);
}
.aim-streak.show { opacity: 1; }
#aimFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#aimMenu .r-best { white-space: nowrap; flex-shrink: 0; }
.aim-cross { --g: 4px; position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.aim-cross i { position: absolute; background: var(--cross); box-shadow: 0 0 0 1px rgba(var(--bg-rgb), .7); }
.aim-cross i:nth-child(1) { left: -1px; top: calc(-1 * var(--g) - 7px); width: 2px; height: 7px; }
.aim-cross i:nth-child(2) { left: -1px; top: var(--g); width: 2px; height: 7px; }
.aim-cross i:nth-child(3) { top: -1px; left: calc(-1 * var(--g) - 7px); height: 2px; width: 7px; }
.aim-cross i:nth-child(4) { top: -1px; left: var(--g); height: 2px; width: 7px; }
.aim-cross.hit { --g: 7px; }
.aim-cross.hit i { background: var(--cross-hit); }
.aim-cross.dot i { display: none; }
.aim-cross.dot i:first-child { display: block; left: -2.5px; top: -2.5px; width: 5px; height: 5px; border-radius: 50%; }
.aim-click { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; pointer-events: none; }
#game-aim.ready .aim-click { display: flex; }
.aim-click > div { margin-top: 150px; padding: 14px 24px; display: grid; gap: 6px; text-align: center; }
.aim-click b { font-family: var(--display); font-size: 13px; color: var(--accent-2); }
.aim-click span { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.aim-range { gap: 8px; }
.aim-range input[type=range] { width: 120px; height: auto; accent-color: var(--accent); }
.aim-range input[type=number] {
  width: 64px; height: auto; font: 12px var(--mono); color: var(--text); padding: 4px 6px;
  border: 1px solid var(--line-strong); border-radius: calc(6px * var(--rk)); background: var(--surface);
}
.aim-range output { font-family: var(--mono); color: var(--text); min-width: 34px; }
/* ---------- Trace (line tracing) ---------- */
#game-trace { position: fixed; inset: 0; display: none; } 
body[data-game="trace"] #game-trace { display: block; }
#traceCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#game-trace.playing #traceCanvas { cursor: crosshair; }
.tr-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
#game-trace.playing .tr-hud { display: block; }
.tr-top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; padding: 7px 4px; }
.tr-stat { display: grid; gap: 1px; text-align: center; min-width: 96px; padding: 0 12px; }
.tr-stat + .tr-stat { border-left: 1px solid var(--line); }
.tr-stat span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.tr-stat b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tr-time b.low { color: var(--p1); }
.tr-streak {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .15s;
  font-family: var(--display); font-size: 11px; font-weight: 700;
  color: var(--accent-2);
}
.tr-streak.show { opacity: 1; }
#traceFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#traceMenu .r-best { white-space: nowrap; flex-shrink: 0; }
@media (max-width: 640px) {
  .aim-stat { min-width: 74px; padding: 0 8px; }
  .aim-stat b { font-size: 17px; }
  .aim-streak { top: 64px; }
  .tr-stat { min-width: 74px; padding: 0 8px; }
  .tr-stat b { font-size: 17px; }
  .tr-streak { top: 64px; }
}

/* ---------- Track (tracking trainer; reuses Flick's .aim-* HUD pieces) ---------- */
#game-track { position: fixed; inset: 0; display: none; }
body[data-game="track"] #game-track { display: block; }
#trackCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#game-track.playing #trackCanvas { cursor: none; }
#game-track.playing .aim-hud { display: block; }
#game-track.ready .aim-click { display: flex; }
#trackFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#trackMenu .r-best { white-space: nowrap; flex-shrink: 0; }
.tk-focus {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
}
.tk-focus span { font-family: var(--display); font-size: 11px; color: var(--muted); }
.tk-bar { width: 180px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.tk-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left center; transition: background .15s; }
.tk-bar i.low { background: var(--p1); }
@media (max-width: 640px) { .tk-focus { top: 64px; } .tk-bar { width: 120px; } }

/* ---------- Keystroke (typing) ---------- */
#game-type { position: fixed; inset: 0; display: none; } 
body[data-game="type"] #game-type { display: block; }
#game-type.playing { background: var(--bg); }
.ty-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
#game-type.playing .ty-hud { display: block; }
.ty-top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; padding: 7px 4px; }
.ty-stat { display: grid; gap: 1px; text-align: center; min-width: 92px; padding: 0 12px; }
.ty-stat + .ty-stat { border-left: 1px solid var(--line); }
.ty-stat span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.ty-stat b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ty-time b.low { color: var(--p1); }
.ty-streak {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .15s;
  font-family: var(--display); font-size: 11px; font-weight: 700;
  color: var(--accent-2);
}
.ty-streak.show { opacity: 1; }

.ty-board {
  --fs: clamp(20px, 2.6vw, 30px); --lh: calc(var(--fs) * 1.7);
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -54%);
  width: min(980px, 92vw); display: none; cursor: text;
}
#game-type.running .ty-board { display: block; }
#game-type.running:not(.playing) .ty-board { opacity: .12; }
.ty-progress { height: 5px; border-radius: 3px; background: rgba(var(--fg-rgb), .1); overflow: hidden; margin-bottom: 22px; }
.ty-progress i { display: block; height: 100%; background: var(--rank, var(--accent)); transform-origin: left; transform: scaleX(1); transition: background .15s; }
#game-type.low .ty-progress i { background: var(--p1); }
.ty-view { height: calc(var(--lh) * 3); overflow: hidden; position: relative; }
.ty-words {
  position: relative; font-family: var(--mono); font-size: var(--fs); line-height: var(--lh); font-weight: 500;
  color: rgba(var(--fg-rgb), .32); word-break: keep-all; white-space: normal; transition: transform .16s ease;
}
.ty-w { display: inline-block; border-radius: calc(4px * var(--rk)); }
.ty-w i { font-style: normal; transition: color .06s; }
.ty-w i.ok { color: var(--strong); }
.ty-w i.ok.was-bad { color: var(--bad-soft); }
.ty-w i.bad { animation: ty-bad .22s ease-out; }
.ty-w.bad { animation: ty-bad-word .22s ease-out; }
.ty-w.dirty { text-decoration: underline 2px rgba(var(--p1-rgb), .55); text-underline-offset: 6px; }
.ty-w.done i.ok { color: var(--rank, var(--p4)); }
.ty-w.done-dirty i.ok { color: color-mix(in srgb, var(--bad-soft) 75%, transparent); }
@keyframes ty-bad { 0% { color: var(--p1); background: rgba(var(--p1-rgb), .4); } 100% { background: transparent; } }
@keyframes ty-bad-word { 0% {  } 100% { box-shadow: none; } }
.ty-caret {
  position: absolute; left: 0; top: 0; width: 2.5px; border-radius: 2px; pointer-events: none;
  background: var(--rank, var(--accent));
  transition: transform .07s linear; margin-left: -1px;
  clip-path: inset(18% 0 18% 0);
}
#game-type.ready .ty-caret { animation: ty-blink 1s steps(1) infinite; }
@keyframes ty-blink { 50% { opacity: 0; } }
.ty-board.shake { animation: ty-shake .16s ease-out; }
@keyframes ty-shake { 25% { margin-left: -5px; } 75% { margin-left: 4px; } }
.ty-hint {
  margin-top: 22px; min-height: 18px; text-align: center; font-family: var(--display); font-size: 11px;
  font-weight: 700; color: var(--accent-2);
}
.ty-pop {
  position: absolute; transform: translate(-50%, -30%); pointer-events: none; white-space: nowrap;
  font: 800 15px var(--display); color: var(--accent-2);
  animation: ty-pop .8s ease-out forwards;
}
.ty-pop.hot { color: var(--gold); font-size: 18px; }
@keyframes ty-pop { 0% { opacity: 0; } 15% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -150%); } }
.ty-input {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  font-size: 16px; /* stops iOS zooming in on focus */ pointer-events: none;
}
#typeFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#typeMenu .r-best { white-space: nowrap; flex-shrink: 0; }
@media (max-width: 640px) {
  .ty-stat { min-width: 64px; padding: 0 7px; }
  .ty-stat b { font-size: 16px; }
  .ty-streak { top: 64px; }
  .ty-board { top: 28%; transform: translate(-50%, 0); }
}

/* ---------- Snap (2D aim trainer) ---------- */
#game-snap { position: fixed; inset: 0; display: none; } 
body[data-game="snap"] #game-snap { display: block; }
#snapCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#game-snap.playing #snapCanvas { cursor: crosshair; }
#snapFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#snapMenu .r-best { white-space: nowrap; flex-shrink: 0; }

/* ---------- Follow (2D tracking; reuses .g-hud and Track's .tk-focus bar) ---------- */
#game-follow { position: fixed; inset: 0; display: none; }
body[data-game="follow"] #game-follow { display: block; }
#followCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#game-follow.playing #followCanvas { cursor: crosshair; }
#followFinish .p-grade { -webkit-background-clip: border-box; background-clip: border-box; }
#followMenu .r-best { white-space: nowrap; flex-shrink: 0; }

/* ---------- Tap (1-minute keyboard WPM sprint) ---------- */
#game-tap { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="tap"] #game-tap { display: block; }
#game-tap .g-top { background: var(--bg); border-color: var(--line-strong); }
.tap-stage {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: calc(var(--header-h) + 56px) 16px 32px;
}
.tap-progress {
  width: min(calc(clamp(20px, min(5.6vw, 10vh), 58px) * 15 + clamp(3px, 0.55vw, 7px) * 14), 100%);
  height: 5px; border-radius: 3px; background: rgba(var(--fg-rgb), .1); overflow: hidden;
}
.tap-progress i { display: block; height: 100%; background: var(--rank, var(--p1)); transform-origin: left; transform: scaleX(1); transition: background .15s; }
#game-tap.low .tap-progress i { background: var(--p1); }
#game-tap.idle .tap-progress { opacity: 0; }
.tap-kb {
  --key: clamp(20px, min(5.6vw, 10vh), 58px);
  --gap: clamp(3px, 0.55vw, 7px);
  --u: calc(var(--key) + var(--gap));
  display: flex; flex-direction: column; gap: var(--gap);
  width: calc(var(--u) * 15 - var(--gap)); max-width: 100%;
}
.tap-kb.shake { animation: ty-shake .16s ease-out; }
.tap-row { display: flex; gap: var(--gap); }
.tap-row-4 { padding-left: calc(var(--u) * 3.75); }
.tap-tile {
  --left: 1;
  position: relative; overflow: hidden; border-radius: clamp(4px, 0.8vw, 9px); cursor: pointer; padding: 0;
  width: calc(var(--w, 1) * var(--u) - var(--gap)); height: var(--key); flex-shrink: 0;
  display: grid; place-items: center;
  background: rgba(var(--fg-rgb), .04); border: 1.5px solid var(--line-strong);
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
.tap-tile.home::after {
  content: ""; position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  width: 24%; height: 2px; border-radius: 1px; background: var(--line-strong); pointer-events: none;
}
.tap-tile.home.lit::after { background: var(--c2); opacity: .75; }
.tap-fill {
  position: absolute; inset: 0; background: var(--rank, var(--p1)); opacity: 0;
  border-radius: inherit; transform-origin: center; transform: scale(var(--left));
}
.tap-tile.lit .tap-fill { opacity: .92; }
.tap-tile.lit { border-color: var(--rank, var(--p1)); }
.tap-tile.next { border-color: rgba(var(--rank-rgb, var(--p1-rgb)), .65); background: rgba(var(--rank-rgb, var(--p1-rgb)), .12); }
.tap-tile.next .tap-key { color: var(--rank, var(--p1)); }
.tap-key {
  position: relative; font-family: var(--mono); font-weight: 600; font-size: clamp(10px, calc(var(--key) * .33), 19px);
  color: var(--muted); pointer-events: none; letter-spacing: .02em;
}
.tap-wide .tap-key { font-size: clamp(8.5px, calc(var(--key) * .22), 13px); letter-spacing: .06em; }
.tap-tile.lit .tap-key { color: var(--c2); }
.tap-tile.start .tap-fill { animation: tap-pulse 1s ease-in-out infinite; }
@keyframes tap-pulse { 50% { opacity: .55; } }
.tap-tile.hit { animation: tap-hit .22s ease-out; }
@keyframes tap-hit { 0% { box-shadow: 0 0 0 0 rgba(var(--rank-rgb, var(--p1-rgb)), .55); transform: scale(.94); } 100% { box-shadow: 0 0 0 12px rgba(var(--rank-rgb, var(--p1-rgb)), 0); transform: scale(1); } }
.tap-tile.bad { animation: tap-bad .4s ease-out; border-color: var(--danger); }
@keyframes tap-bad { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(5px); } }
.tap-hint { font-family: var(--display); font-size: 14px; color: var(--muted); min-height: 1.2em; }
#game-tap.idle .tap-stage { opacity: .35; pointer-events: none; }

/* ---------- Tally (mental math) ---------- */
#game-math { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="math"] #game-math { display: block; }
.mt-stage {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: calc(var(--header-h) + 40px) 16px 40px;
}
.mt-card { width: min(520px, 100%); text-align: center; display: grid; gap: 14px; justify-items: center; }
.mt-timer { width: 100%; height: 6px; border-radius: 3px; background: rgba(var(--fg-rgb), .08); overflow: hidden; }
.mt-timer i { display: block; height: 100%; background: var(--rank, var(--p1)); transform-origin: center; transform: scaleX(1); }
.mt-timer i.low { background: var(--p2); }
.mt-q { font-family: var(--mono); font-weight: 600; font-size: clamp(40px, 9vw, 72px); letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.mt-a {
  min-width: 4ch; min-height: 1.3em; padding: 4px 18px; border-bottom: 2px solid var(--rank, var(--line-strong));
  font-family: var(--mono); font-weight: 600; font-size: clamp(32px, 7vw, 54px); font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center;
}
.mt-caret { display: inline-block; width: 2px; height: .9em; margin-left: 3px; background: var(--text); animation: ty-blink 1s steps(1) infinite; }
.mt-card.right .mt-a { animation: mt-right .3s ease-out; }
@keyframes mt-right { 0% { color: var(--p4); border-color: var(--p4); transform: scale(1.08); } 100% { transform: scale(1); } }
.mt-card.wrong .mt-a { color: var(--danger); border-color: var(--danger); animation: tap-bad .4s ease-out; }
.mt-hint { font-family: var(--display); font-size: 14px; color: var(--muted); min-height: 1.2em; }
.mt-pad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; }
.mt-key {
  height: 52px; border-radius: 10px; border: 1.5px solid var(--line-strong); background: rgba(var(--fg-rgb), .04);
  font-family: var(--mono); font-size: 20px; font-weight: 600; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.mt-key:active { background: rgba(var(--fg-rgb), .12); }
.mt-key[hidden] { visibility: hidden; display: block; }
@media (hover: hover) and (pointer: fine) and (min-width: 700px) { .mt-pad { opacity: .55; } }
#game-math.idle .mt-stage { opacity: .3; pointer-events: none; }
#game-math.idle .mt-caret { display: none; }

/* ---------- Shared in-round HUD (g-*): score / time / … bar and streak line, shown while .playing ---------- */
.g-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
.playing > .g-hud { display: block; }
.g-top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; padding: 7px 4px; }
.g-stat { display: grid; gap: 1px; text-align: center; min-width: 96px; padding: 0 12px; }
.g-stat + .g-stat { border-left: 1px solid var(--line); }
.g-stat span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.g-stat b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.g-time b.low { color: var(--p1); }
.g-streak {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .15s;
  font-family: var(--display); font-size: 11px; font-weight: 700;
  color: var(--accent-2);
}
.g-streak.show { opacity: 1; }
@media (max-width: 640px) {
  .g-stat { min-width: 74px; padding: 0 8px; }
  .g-stat b { font-size: 17px; }
  .g-streak { top: 64px; }
}

/* ---------- Slipstream ---------- */
#game-race { position: fixed; inset: 0; display: none; background: #07090e; }
body[data-game="race"] #game-race { display: block; }
#raceCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-race.racing #raceCanvas { cursor: none; }
#game-race.editing #raceCanvas { cursor: crosshair; }

/* Subtle high-speed focus vignette */
.r-warp {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  transition: opacity .18s ease;
  background:
    radial-gradient(ellipse at center, transparent 58%, rgba(12, 16, 22, 0.16) 86%, rgba(8, 12, 18, 0.34) 100%);
}
#game-race:not(.racing) .r-warp { opacity: 0 !important; }
.r-danger {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 48%, rgba(239, 68, 68, 0.42) 100%);
  transition: opacity .14s;
}
#game-race:not(.racing) .r-danger { opacity: 0 !important; }

.r-hud { position: absolute; inset: 0; pointer-events: none; display: none; font-family: var(--mono); color: var(--text); }
#game-race.racing .r-hud { display: block; }
.r-glass {
  background: rgba(12, 16, 26, 0.78); 
  border: 1px solid rgba(255, 255, 255, 0.10); border-radius: calc(12px * var(--rk));
  
}
.r-test-banner {
  position: absolute; top: 12px; left: 16px; padding: 6px 12px; border-radius: calc(8px * var(--rk));
  background: rgba(245, 158, 11, 0.20); border: 1px solid rgba(245, 158, 11, 0.55);
  color: #fde68a; font-family: var(--display); font-size: 12px; font-weight: 700;
}
.r-test-banner[hidden] { display: none; }
/* Timer & checkpoint readout now live diegetically inside the 3D skybox */
.r-top { display: none; }
.r-chase {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 9px 16px 10px; min-width: 340px; display: grid; gap: 7px;
  border-color: rgba(255, 255, 255, 0.14);
}
.r-chase[hidden] { display: none; }
.r-chase-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.r-chase-lap {
  font-family: var(--display); font-size: 15px; font-weight: 800;
  color: #fbbf24;
}
.r-chase-pace {
  font-family: var(--display); font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: calc(6px * var(--rk)); white-space: nowrap;
  background: rgba(239, 68, 68, 0.18); border: 1px solid rgba(239, 68, 68, 0.45); color: #fca5a5;
}
.r-chase-gap {
  font-family: var(--mono); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #34d399; min-width: 78px; text-align: right;
}
.r-chase-gap.warn { color: #fbbf24; }
.r-chase-gap.danger { color: #fb7185; animation: r-pulse .45s ease-in-out infinite alternate; }
@keyframes r-pulse { from { opacity: 1; } to { opacity: .45; } }
.r-chase-bar {
  position: relative; height: 7px; border-radius: calc(99px * var(--rk));
  background: rgba(255, 255, 255, 0.08); overflow: visible;
}
.r-chase-bar::after {
  content: ''; position: absolute; right: 3.5%; top: -2px; bottom: -2px; width: 2px;
  border-radius: 2px; background: rgba(255, 255, 255, 0.72);
}
.r-chase-fill {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: calc(99px * var(--rk));
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.45), rgba(239, 68, 68, 0.85));
  width: 4%;
}
.r-chase-dot {
  position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px;
  border-radius: 50%; border: 2px solid #090e1a;
}
.r-chase-dot.ghost {
  background: #ef4444;  left: 4%; z-index: 1;
}
.r-chase-dot.player {
  background: #fbbf24;  left: 4%; z-index: 2;
}
.r-time { font-size: 31px; font-weight: 700; font-variant-numeric: tabular-nums; }
.r-sub { font-family: var(--display); font-size: 12px; color: var(--muted); margin-top: 2px; }
.r-split {
  position: absolute; top: 88px; left: 50%; transform: translateX(-50%) translateY(-6px); opacity: 0;
  font-size: 18px; font-weight: 700; padding: 6px 16px; border-radius: calc(9px * var(--rk)); transition: opacity .18s, transform .18s;
  background: rgba(14, 19, 30, 0.92); border: 1px solid rgba(255,255,255,.12); color: var(--text); white-space: nowrap;
}
.r-split.show { opacity: 1; transform: translateX(-50%); }
.r-split.ahead { color: #34d399; border-color: rgba(16, 185, 129, 0.45); }
.r-split.behind { color: #fb7185; border-color: rgba(244, 63, 94, 0.45); }

/* Bottom Left: Minimap + Track Info */
.r-left-col { position: absolute; left: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.r-minimap-wrap { padding: 6px; border-radius: calc(12px * var(--rk)); }
#rcMini { display: block; width: 138px; height: 138px; border-radius: calc(8px * var(--rk)); background: rgba(6, 9, 16, 0.55); }
.r-info { padding: 8px 13px; display: grid; gap: 2px; min-width: 150px; }
.r-info b { font-family: var(--display); font-size: 11px; }
.r-info span { font-size: 11px; color: var(--muted); }

/* Bottom Center: Hints only (keeps car completely unobstructed!) */
.r-bottom-mid {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.r-hint {
  white-space: nowrap; font-size: 11.5px; color: var(--text-soft); padding: 6px 13px;
  opacity: 0; transition: opacity .35s;
}
.r-hint.show { opacity: 1; }
/* Top Right: Live Input Display (Trackmania 2020 placement, never overlaps car!) */
.r-inputs {
  position: absolute; top: 18px; right: 18px;
  padding: 7px 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.r-inputs[hidden] { display: none; }
.r-keys-grid { display: grid; grid-template-columns: repeat(3, 24px); gap: 3px; }
.r-keys-grid b {
  height: 20px; border-radius: calc(4px * var(--rk)); display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.10);
  transition: background .06s, color .06s, border-color .06s;
}
.r-keys-grid b.on  { background: rgba(34, 197, 94, 0.26); color: #dcfce7; border-color: #22c55e; }
.r-keys-grid b.brk { background: rgba(239, 68, 68, 0.28); color: #fee2e2; border-color: #ef4444; }
.r-keys-grid b.st  { background: rgba(245, 158, 11, 0.26); color: #fef3c7; border-color: #f59e0b; }
.r-steer-bar {
  position: relative; width: 78px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,.08);
}
.r-steer-bar i {
  position: absolute; top: -2px; left: 50%; width: 8px; height: 8px; margin-left: -4px;
  border-radius: 50%; background: var(--accent-2); 
}

/* Bottom Right: Speedometer + 5-Gear Cluster */
.r-speed { position: absolute; right: 18px; bottom: 18px; padding: 10px 16px 12px; min-width: 215px; }
.r-state-badge {
  position: absolute; top: -28px; right: 0; padding: 3px 10px; border-radius: calc(6px * var(--rk));
  font-family: var(--display); font-size: 12px; font-weight: 800;
  opacity: 0; transform: translateY(4px); transition: opacity .14s, transform .14s;
  background: rgba(14, 18, 28, 0.9); border: 1px solid rgba(255,255,255,.16); color: #fff;
}
.r-state-badge.show { opacity: 1; transform: none; }
.r-state-badge.drift { color: #fbbf24; border-color: rgba(245,158,11,.55); }
.r-state-badge.sd { color: #34d399; border-color: rgba(16,185,129,.6); }
.r-state-badge.boost { color: #fbbf24; border-color: rgba(245,158,11,.65); }
.r-state-badge.super { color: #f87171; border-color: rgba(239,68,68,.7); }
.r-state-badge.reactor { color: #34d399; border-color: rgba(16,185,129,.7); }
.r-state-badge.free { color: #c084fc; border-color: rgba(192,132,252,.65); }
.r-state-badge.air { color: #fde68a; border-color: rgba(251,191,36,.5); }
.r-state-badge.grass { color: #84cc16; border-color: rgba(132,204,22,.65); }

.r-spd-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.r-gear-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: calc(9px * var(--rk));
  background: rgba(var(--accent-rgb), 0.16); border: 1px solid rgba(var(--accent-rgb), 0.45);
}
.r-gear-box span { font-family: var(--display); font-size: 12px; color: var(--accent-2); }
.r-gear-box b { font-family: var(--display); font-size: 21px; font-weight: 800; line-height: 1.05; color: #fff; }
.r-spd-num { text-align: right; }
.r-spd-num b { font-size: 42px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 0.95; }
.r-spd-num span { font-family: var(--display); font-size: 12px; color: var(--muted); margin-left: 5px; }
.r-rpm-row { margin-top: 9px; display: grid; gap: 5px; }
.r-meter { height: 5px; border-radius: 3px; background: rgba(255,255,255,.08); overflow: hidden; }
.r-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #e2e8f0, #f59e0b); transition: width .04s linear; }
.r-meter i.boost { background: linear-gradient(90deg, #d97706, #fbbf24); }
.r-meter i.super { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.r-meter i.reactor { background: linear-gradient(90deg, #15803d, #22c55e); }
.r-rpm-dots { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.r-rpm-dots i { height: 4px; border-radius: 2px; background: rgba(255,255,255,.10); }
.r-rpm-dots i.on { background: #22c55e; }
.r-rpm-dots i.amber { background: #eab308; }
.r-rpm-dots i.red { background: #ef4444; }

.r-count {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); opacity: 0;
  font-family: var(--display); font-size: 112px; font-weight: 800;
  background: var(--accent);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 8px 26px rgba(var(--accent-rgb), 0.38));
}
.r-fall {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .2s;
  font-family: var(--display); font-size: 12px; color: var(--danger);
}
.r-fall.show { opacity: 1; }

/* Menu Enhancements */
.r-menu-card { width: min(640px, 100%) !important; }
.r-menu-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.r-menu-ctas { display: flex; gap: 8px; flex-shrink: 0; margin-top: 4px; }
.r-tabs { display: flex; gap: 6px; margin: 14px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.r-tab {
  font-family: var(--heading); font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-radius: calc(8px * var(--rk)); padding: 6px 12px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: all .15s;
}
.r-tab:hover { color: var(--text); background: rgba(var(--fg-rgb), .04); }
.r-tab.active { color: var(--strong); background: rgba(var(--accent-rgb), 0.16); border-color: rgba(var(--accent-rgb), 0.45); }
.r-tab span { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: calc(99px * var(--rk)); background: rgba(var(--fg-rgb), .09); }

.r-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: 0; }

/* collapsible menu dropdowns (Mods + Settings) */
.menu-drops { border-top: 1px solid var(--line); margin: 4px 0 0; }
.menu-drop { border-bottom: 1px solid var(--line); }
.menu-drop > summary {
  list-style: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 2px; cursor: pointer;
  font-family: var(--heading); font-size: 14px; font-weight: 600; color: var(--text);
}
.menu-drop > summary::-webkit-details-marker { display: none; }
.menu-drop > summary::before {
  content: ""; width: 6px; height: 6px; flex-shrink: 0; margin-right: 2px;
  border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s ease, border-color .15s ease;
}
.menu-drop[open] > summary::before { transform: rotate(45deg); border-color: var(--text); }
.menu-drop > summary:hover { color: var(--strong); }
.menu-drop > summary:hover::before { border-color: var(--text); }
.menu-drop-body { padding: 4px 2px 14px; }
.menu-drop-body .r-settings { border-top: 0; padding: 2px 0 0; }

.mod-drop-pill {
  --mc: var(--muted); --mc-rgb: var(--c1-rgb);
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 2px 8px; border-radius: 99px;
  color: var(--mc); background: rgba(var(--mc-rgb), .09); border: 1px solid rgba(var(--mc-rgb), .24);
}
.mod-drop-pill[data-mod="none"]   { --mc: var(--muted); --mc-rgb: var(--c1-rgb); }
.mod-drop-pill[data-mod="easy"]   { --mc: var(--p4); --mc-rgb: var(--p4-rgb); }
.mod-drop-pill[data-mod="medium"] { --mc: var(--p2); --mc-rgb: var(--p2-rgb); }
.mod-drop-pill[data-mod="hard"]   { --mc: var(--p1); --mc-rgb: var(--p1-rgb); }
.mod-drop-pill[data-mod="dual"]   { --mc: var(--p6); --mc-rgb: var(--p6-rgb); }
.mod-drop-pill em { font-style: normal; opacity: .9; }
.mod-btn-ico { display: grid; place-items: center; }
.mod-btn-ico svg { width: 13px; height: 13px; display: block; }

/* square arcade mod icon tiles + separate explainer strip inside the Mods dropdown */
.mods-wrap { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px 14px; }
.mods { display: flex; align-items: center; gap: 10px; }
.mod {
  --mc: var(--p4); --mc-rgb: var(--p4-rgb);
  position: relative;
  width: 60px; height: 60px; flex-shrink: 0;
  display: grid; place-items: center; padding: 0;
  border: 2px solid rgba(var(--mc-rgb), .38);
  border-radius: 10px;
  background: rgba(var(--mc-rgb), .08);
  color: var(--mc);
  box-shadow: 0 3px 0 rgba(var(--mc-rgb), .24);
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease, background .14s ease, border-color .14s ease, color .14s ease;
}
.mod[data-mod="easy"],   .mods-info[data-mod="easy"]   { --mc: var(--p4); --mc-rgb: var(--p4-rgb); }
.mod[data-mod="medium"], .mods-info[data-mod="medium"] { --mc: var(--p2); --mc-rgb: var(--p2-rgb); }
.mod[data-mod="hard"],   .mods-info[data-mod="hard"]   { --mc: var(--p1); --mc-rgb: var(--p1-rgb); }
.mod[data-mod="dual"],   .mods-info[data-mod="dual"]   { --mc: var(--p6); --mc-rgb: var(--p6-rgb); }
.mod:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--mc-rgb), .85);
  background: rgba(var(--mc-rgb), .16);
  box-shadow: 0 5px 0 rgba(var(--mc-rgb), .38);
}
.mod:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(var(--mc-rgb), .45);
}
.mod.on {
  border-color: var(--mc);
  background: var(--mc);
  color: #fff;
  box-shadow: 0 4px 0 rgba(var(--mc-rgb), .55);
  transform: translateY(-1px);
}
.mod.on:hover {
  background: var(--mc);
  transform: translateY(-2px);
  box-shadow: 0 5px 0 rgba(var(--mc-rgb), .6);
}
.mod.on:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(var(--mc-rgb), .6);
}
.mod-ico { display: grid; place-items: center; transform: translateY(-4px); }
.mod-ico svg { width: 25px; height: 25px; display: block; }
.mod-tag {
  position: absolute; bottom: 5px; left: 0; right: 0; text-align: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; opacity: .9;
}

.mods-info {
  --mc: var(--muted); --mc-rgb: var(--c1-rgb);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px;
  padding: 8px 11px; min-height: 58px; align-content: center;
  border-left: 3px solid var(--mc);
  border-radius: 0 5px 5px 0;
  background: rgba(var(--mc-rgb), .06);
  transition: border-color .14s ease, background .14s ease;
}
.mods-info[data-mod="none"] { --mc: var(--muted); --mc-rgb: var(--c1-rgb); }
.mods-info b { font-family: var(--heading); font-size: 14px; font-weight: 700; color: var(--mc); }
.mods-info-k { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--mc); font-variant-numeric: tabular-nums; }
.mods-info small { flex: 1 0 100%; font-size: 12.5px; color: var(--muted); line-height: 1.38; margin-top: 2px; }

.mods-play { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 14px; }
.mods-play .r-best { margin-left: auto; }
@media (max-width: 520px) { .mods-wrap { grid-template-columns: 1fr; } }
.r-tracks { display: grid; gap: 6px; margin: 10px 0 14px; }
.r-track {
  font: inherit; text-align: left; color: var(--text); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); padding: 10px 12px;
}
.r-track:hover { background: var(--tint); }
.r-track-main { display: grid; gap: 3px; min-width: 0; }
.r-track h3 { font-family: var(--heading); font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.r-track h3 i { font-style: normal; font-size: 14px; font-weight: 400; color: var(--muted); }
.r-track h3 i::before { content: "– "; }
.r-best { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 7px; }
.r-best em { font-style: normal; font-size: 13px; font-weight: 400; color: var(--muted); }
.r-track small { color: var(--muted); font-size: 13px; line-height: 1.45; }
.r-track-actions { display: flex; gap: 6px; flex-shrink: 0; }
.r-act-btn {
  font-family: var(--heading); font-size: 11px; font-weight: 600; color: var(--text-soft);
  background: rgba(var(--fg-rgb), .05); border: 1px solid var(--line-strong); border-radius: calc(7px * var(--rk));
  padding: 6px 10px; cursor: pointer; transition: all .14s; white-space: nowrap;
}
.r-act-btn:hover { color: var(--strong); border-color: var(--accent); background: rgba(var(--accent-rgb), 0.18); }
.r-act-btn.ranked { color: var(--gold); border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.12); }
.r-act-btn.ranked:hover { background: rgba(245, 158, 11, 0.28); color: var(--strong); }
.r-act-btn.danger:hover { border-color: var(--danger); background: rgba(251, 75, 107, 0.2); color: #ffe4e6; }
.r-empty {
  border: 1px dashed var(--line-strong); border-radius: calc(10px * var(--rk)); padding: 24px 16px;
  text-align: center; display: grid; gap: 12px; justify-items: center; color: var(--muted); font-size: 13px;
}

.r-settings { display: flex; flex-wrap: wrap; gap: 10px 18px; font-size: 12px; color: var(--muted); padding: 12px 0 10px; border-top: 1px dashed var(--line); }
.r-settings label { display: flex; align-items: center; gap: 7px; }
.r-settings select {
  font: inherit; color: var(--text); padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: calc(6px * var(--rk)); background: var(--surface);
}
.r-settings input { accent-color: var(--accent); width: 15px; height: 15px; }
.r-delta { font-family: var(--mono); font-size: 14px; color: var(--muted); }
.r-delta.ahead { color: #34d399; }
.r-delta.behind { color: var(--danger); }
.r-medal { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 13px; font-weight: 700; }
.r-medal .r-dot { width: 16px; height: 16px; }
.r-medals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.r-medals div { border: 1px solid var(--line); border-radius: calc(8px * var(--rk)); padding: 8px 4px; background: var(--surface); display: grid; gap: 4px; justify-items: center; opacity: .5; }
.r-medals div.got { opacity: 1; border-color: rgba(var(--accent-rgb), 0.5); }
.r-medals span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.r-medals b { font-family: var(--mono); font-size: 13px; }

/* ---------- Slipstream 3D Level Editor UI ---------- */
#game-race .p-btn[hidden] { display: none !important; }
.ed-ui {
  position: absolute; inset: 0; pointer-events: none; display: none; z-index: 25;
  flex-direction: column; justify-content: space-between; gap: 10px; padding: 12px 14px;
}
#game-race.editing .ed-ui { display: flex; }

.ed-top {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px;
}
.ed-top-left, .ed-top-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ed-name {
  font-family: var(--heading); font-size: 13px; font-weight: 700; color: var(--strong);
  background: rgba(var(--fg-rgb), .06); border: 1px solid var(--line-strong); border-radius: calc(7px * var(--rk));
  padding: 5px 9px; width: 155px; outline: none;
}
.ed-name:focus { border-color: var(--accent); }
.ed-select {
  font-family: var(--font); font-size: 12px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: calc(7px * var(--rk)); padding: 5px 7px;
}
.ed-status {
  font-family: var(--mono); font-size: 11px; padding: 5px 9px; border-radius: calc(7px * var(--rk));
  background: rgba(var(--fg-rgb), .05); border: 1px solid var(--line); color: var(--text-soft);
}
.ed-status.ok { color: #34d399; border-color: rgba(16,185,129,.45); background: rgba(16,185,129,.12); }
.ed-status.warn { color: #fda4af; border-color: rgba(244,63,94,.45); background: rgba(244,63,94,.12); }
.ed-status.ready { color: var(--gold); border-color: rgba(245,158,11,.45); background: rgba(245,158,11,.10); }

.ed-btn {
  font-family: var(--heading); font-size: 12px; font-weight: 600; color: var(--text);
  background: rgba(var(--fg-rgb), .07); border: 1px solid var(--line-strong); border-radius: calc(7px * var(--rk));
  padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  transition: all .14s; white-space: nowrap;
}
.ed-btn:hover:not(:disabled) { background: rgba(var(--fg-rgb), .14); border-color: rgba(var(--fg-rgb), .28); }
.ed-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ed-btn.icon { padding: 5px 8px; font-size: 14px; font-weight: 700; }
.ed-btn.ghost { background: rgba(var(--fg-rgb), .04); }
.ed-btn.primary {
  background: var(--accent); color: #090c14; font-weight: 800;
  border-color: transparent; 
}
.ed-btn.primary:hover { filter: brightness(1.08); }
.ed-btn.primary kbd { background: rgba(var(--shadow-rgb), calc(.22 * var(--sk))); border-color: rgba(var(--shadow-rgb), calc(.3 * var(--sk))); color: #090c14; font-size: 12px; }
.ed-btn.ai {
  background: rgba(16, 185, 129, 0.16); border-color: rgba(16, 185, 129, 0.45); color: #6ee7b7;
}
.ed-btn.ai:hover { background: rgba(16, 185, 129, 0.28); color: var(--strong); }
.ed-btn.danger-tog.active { background: rgba(244, 63, 94, 0.28); border-color: #f43f5e; color: #ffe4e6; }

/* AI Track Lab modal helpers */
.ai-section { display: grid; gap: 6px; }
.ai-lbl-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ai-lbl { font-family: var(--display); font-size: 12px; color: var(--muted); }
.ai-styles { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-pill {
  font-family: var(--heading); font-size: 12px; font-weight: 600; color: var(--text-soft);
  background: rgba(var(--fg-rgb), .05); border: 1px solid var(--line-strong); border-radius: calc(7px * var(--rk));
  padding: 6px 11px; cursor: pointer; transition: all .14s;
}
.ai-pill:hover { color: var(--strong); border-color: rgba(var(--accent-rgb), 0.55); }
.ai-pill.active { color: var(--strong); background: rgba(var(--accent-rgb), 0.22); border-color: var(--accent-2); }

.gbx-drop {
  border: 1.5px dashed rgba(34, 211, 238, 0.42); border-radius: calc(10px * var(--rk));
  padding: 13px 14px; text-align: center; cursor: pointer;
  background: rgba(34, 211, 238, 0.05); display: grid; gap: 3px;
  transition: border-color .15s, background .15s;
}
.gbx-drop:hover, .gbx-drop.over { border-color: #22d3ee; background: rgba(34, 211, 238, 0.14); }
.gbx-drop b { font-family: var(--heading); font-size: 13px; color: #cffafe; }
.gbx-drop span { font-size: 11px; color: var(--muted); }
.gbx-report {
  padding: 10px 12px; border-radius: calc(9px * var(--rk)); background: rgba(var(--fg-rgb), .04);
  border: 1px solid var(--line-strong); display: grid; gap: 3px; font-size: 12px;
}
.gbx-report[hidden] { display: none; }
.gbx-rep-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.gbx-rep-head b { color: var(--strong); font-family: var(--heading); }
.gbx-rep-head span { font-family: var(--mono); font-size: 12px; color: var(--accent-2); }
.gbx-report small { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.ed-mid {
  flex: 1; display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; min-height: 0;
}
.ed-side-tools {
  pointer-events: auto;
  padding: 10px; display: grid; gap: 10px; width: 124px;
}
.ed-tool-group { display: grid; gap: 5px; }
.ed-tool-group small { font-family: var(--display); font-size: 12px; color: var(--muted); }
.ed-mini-row { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.ed-mini-row b { font-family: var(--mono); font-size: 13px; color: var(--accent-2); }

.ed-help {
  padding: 8px 12px;
  display: grid; gap: 3px; font-size: 11px; color: var(--muted); pointer-events: none;
}
.ed-help b { color: var(--text); font-family: var(--mono); font-weight: 600; }

.ed-dock {
  pointer-events: auto;
  padding: 9px 12px 10px; display: grid; gap: 8px;
}
.ed-dock-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.ed-cats { display: flex; gap: 5px; flex-wrap: wrap; }
.ed-cat {
  font-family: var(--heading); font-size: 12px; font-weight: 600; color: var(--muted);
  background: rgba(var(--fg-rgb), .04); border: 1px solid transparent; border-radius: calc(7px * var(--rk));
  padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: all .12s;
}
.ed-cat:hover { color: var(--text); background: rgba(var(--fg-rgb), .08); }
.ed-cat.active { color: var(--strong); background: rgba(var(--accent-rgb), 0.22); border-color: rgba(var(--accent-rgb), 0.55); }
.ed-cat kbd { font-size: 12px; padding: 0 4px; }

.ed-surf-wrap { display: flex; align-items: center; gap: 8px; }
.ed-surf-lbl { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.ed-surfs { display: flex; gap: 5px; transition: opacity .15s; }
.ed-surfs.dim { opacity: 0.35; }
.ed-surf {
  font-family: var(--heading); font-size: 11.5px; font-weight: 600; color: var(--text-soft);
  background: rgba(var(--fg-rgb), .04); border: 1px solid var(--line); border-radius: calc(7px * var(--rk));
  padding: 4px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.ed-surf i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.ed-surf.active { color: var(--strong); border-color: var(--accent-2); background: rgba(var(--accent-rgb), 0.20); }

.ed-blocks { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.ed-blk {
  flex: 0 0 auto; min-width: 96px; padding: 8px 10px; border-radius: calc(8px * var(--rk)); text-align: left;
  background: rgba(var(--fg-rgb), .04); border: 1px solid var(--line); color: var(--text);
  cursor: pointer; display: grid; gap: 2px; transition: all .12s;
}
.ed-blk:hover { border-color: rgba(var(--accent-rgb), 0.5); background: rgba(var(--fg-rgb), .08); }
.ed-blk.active { border-color: var(--accent-2); background: rgba(var(--accent-rgb), 0.24); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.35); }
.ed-blk b { font-family: var(--display); font-size: 11px; color: var(--accent-2); }
.ed-blk span { font-size: 11px; color: var(--text-soft); white-space: nowrap; }

.ed-modal {
  position: fixed; inset: 0; z-index: 90; pointer-events: auto;
  background: rgba(var(--glass-rgb), 0.78); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.ed-modal[hidden] { display: none; }
.ed-modal-card { width: min(520px, 100%); pointer-events: auto; }
.ed-share-text {
  width: 100%; font-family: var(--mono); font-size: 11.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: calc(8px * var(--rk));
  padding: 10px; resize: vertical; outline: none;
  user-select: text; -webkit-user-select: text;
}
.ed-share-text:focus { border-color: var(--accent); }

/* ---------- Pulse ---------- */
#game-pulse { position: fixed; inset: 0; display: none; }
body[data-game="pulse"] #game-pulse { display: block; }
#pulseCanvas { position: absolute; inset: 0; display: block; touch-action: none; }
#game-pulse.playing #pulseCanvas { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ccircle cx='16' cy='16' r='11' fill='%23121722' fill-opacity='.9' stroke='%234a7dff' stroke-width='3'/%3E%3Ccircle cx='16' cy='16' r='3' fill='%234a7dff'/%3E%3C/svg%3E") 16 16, crosshair; }
#game-pulse.playing.auto #pulseCanvas { cursor: none; }
.p-timing { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--muted); }
.p-timing[hidden] { display: none; }
.p-timing .p-btn { padding: 8px 14px; font-size: 12px; }
.p-timing .p-btn:disabled { opacity: .6; cursor: default; }
.p-drop {
  border: 1.5px dashed var(--line-strong); border-radius: calc(10px * var(--rk)); padding: 18px;
  text-align: center; display: grid; gap: 6px; justify-items: center;
  background: rgba(var(--fg-rgb), .02); transition: border-color .15s, background .15s;
}
.p-drop b { font-family: var(--display); font-size: 11px; }
.p-drop span { color: var(--muted); font-size: 12.5px; }
#game-pulse.dragging .p-drop { border-color: var(--accent); background: var(--tint); }
.p-drop .p-btn { margin-top: 6px; }
.p-lib { display: grid; gap: 10px; margin: 16px 0; }
.p-set { border: 1px solid var(--line); border-radius: calc(10px * var(--rk)); background: rgba(var(--fg-rgb), .025); padding: 13px 15px; }
.p-set h3 { font-family: var(--heading); font-size: 15.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.p-set h3 i {
  font-style: normal; font-family: var(--mono); font-size: 12px; font-weight: 700;
  color: var(--accent-2); border: 1px solid rgba(var(--accent-rgb), 0.45); background: rgba(var(--accent-rgb), 0.1);
  border-radius: calc(5px * var(--rk)); padding: 2px 7px;
}
.p-set small { color: var(--muted); font-size: 12px; }
.p-diffs { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.p-diff {
  font: inherit; font-size: 12.5px; font-weight: 600; display: flex; flex-direction: column;
  align-items: flex-start; gap: 2px; padding: 8px 13px; border-radius: calc(8px * var(--rk));
  border: 1px solid var(--line-strong); background: var(--surface-2); cursor: pointer; color: var(--text); text-align: left;
  transition: border-color .15s, background .15s, transform .15s;
}
.p-diff:hover:not(:disabled) { border-color: var(--accent); background: var(--tint); transform: translateY(-1px); }
.p-diff em { font-style: normal; font-weight: 400; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.p-diff:disabled { opacity: .45; cursor: not-allowed; }
.p-settings {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; font-size: 12px; color: var(--muted);
  padding: 14px 0 12px; border-top: 1px dashed var(--line);
}
.p-settings label { display: flex; flex-direction: column; gap: 5px; }
.p-settings input[type=range] { accent-color: var(--accent); width: 100%; }
.p-settings input[type=number] {
  width: 90px; font-family: var(--mono); font-size: 12px; padding: 5px 7px; color: var(--text);
  border: 1px solid var(--line-strong); border-radius: calc(6px * var(--rk)); background: var(--surface);
}
.p-settings .p-check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.p-settings .p-check input { accent-color: var(--accent); width: 15px; height: 15px; }
.p-keys { font-size: 12px; color: var(--muted); line-height: 2; }
.p-msg { font-size: 14px; margin-top: 6px; color: var(--success); min-height: 1.2em; }
.p-msg.err { color: var(--danger); }
.p-center { text-align: center; display: grid; gap: 14px; justify-items: center; }
.p-label { font-family: var(--display); font-size: 12px; color: var(--muted); }
.p-grade { font-size: 64px; font-weight: 700; line-height: 1; color: var(--text); }
/* time-trial results (Slipstream, Breach): the finish time takes the grade letter's place */
.p-grade.p-time { font-size: 56px; font-variant-numeric: tabular-nums; }
.p-center h3 { font-size: 17px; font-weight: 600; }
.p-center small { color: var(--muted); font-size: 12.5px; }
.p-big { display: flex; align-items: baseline; gap: 14px; }
.p-big b { font-family: var(--mono); font-size: 30px; font-weight: 600; }
.p-big span { font-family: var(--mono); font-size: 16px; color: var(--muted); }
.p-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; }
.p-stats div { border: 1px solid var(--line); border-radius: calc(8px * var(--rk)); padding: 8px 4px; background: var(--surface); display: grid; gap: 3px; }
.p-stats span { font-family: var(--display); font-size: 12px; color: var(--muted); }
.p-stats b { font-family: var(--mono); font-size: 17px; }
.p-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- Results card (every game's end screen) ----------
   Header line (what was played) · hero: grade tile beside the score and how it compares to your best
   · one divided strip of stats · leaderboard · actions. Time trials put the time in the hero instead. */
.p-results {
  display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 18px; row-gap: 0;
  justify-items: stretch; text-align: left; width: min(560px, 100%); padding: 18px 22px 20px;
}
.p-results > * { grid-column: 1 / -1; margin: 0; }
.p-results > .p-label {
  order: -2; padding-bottom: 12px; margin-bottom: 18px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--text-soft);
}
.p-results > .p-grade:not(.p-time) {
  grid-column: 1; grid-row: span 2; align-self: center;
  min-width: 84px; height: 84px; padding: 0 12px; display: grid; place-items: center;
  font-size: 52px; border-radius: calc(12px * var(--rk));
  background: color-mix(in srgb, currentColor 10%, transparent) !important;
  border: 1.5px solid color-mix(in srgb, currentColor 40%, transparent);
}
.p-results > .p-big { grid-column: 2; align-self: end; gap: 10px; flex-wrap: wrap; }
.p-results > .p-big b { font-size: 40px; line-height: 1.05; }
.p-results > .p-big span { font-size: 15px; }
.p-results > .p-big span:empty { display: none; }
.p-results > .r-delta { grid-column: 2; align-self: start; margin-top: 6px; font-size: 13px; }
.p-results > .r-delta:empty { display: none; }
/* time trials: the time is the hero, full width */
.p-results > .p-time { font-family: var(--mono); font-size: 52px; }
.p-results > .p-time ~ .r-delta { grid-column: 1 / -1; }

.p-results > .p-stats {
  margin-top: 20px; gap: 0; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.p-results > .p-stats:empty { display: none; }
.p-results > .p-stats div {
  border: 0; border-radius: 0; background: none; padding: 12px 12px; gap: 4px; align-content: start;
}
.p-results > .p-stats div + div { border-left: 1px solid var(--line); }
.p-results > .p-stats div:first-child { padding-left: 0; }
.p-results > .p-stats span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-results > .p-stats b { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.p-results > .p-stats b.bad { color: var(--danger); }

/* medals (time trials): what you earned and the next target on one line, then the ladder */
.p-results > .r-medal { grid-column: 1; margin-top: 18px; }
.p-results > .r-medal + small { grid-column: 2; margin-top: 18px; align-self: center; justify-self: end; font-family: var(--mono); }
.p-results > .r-medals { margin-top: 10px; }
.p-results > .p-timing { margin-top: 16px; justify-content: space-between; }

.p-results > .a-board { margin-top: 20px; }
.p-results > .p-row { margin-top: 20px; justify-content: flex-start; }
.p-results > .p-row .a-share { margin-left: auto; }
.p-results > small:last-child { margin-top: 10px; text-align: right; }
/* Wide screens: the leaderboard gets its own column on the right, beside the results.
   12 auto rows hold the results (empty ones collapse to 0); the last 1fr row soaks up the
   leaderboard's extra height so the results on the left don't spread out to match it. */
@media (min-width: 860px) {
  .p-results:has(> .a-board:not([hidden])) {
    width: min(900px, 100%);
    grid-template-columns: auto minmax(0, 1fr) minmax(260px, 320px);
    grid-template-rows: repeat(12, auto) 1fr;
  }
  .p-results:has(> .a-board:not([hidden])) > * { grid-column: 1 / 3; }
  .p-results:has(> .a-board:not([hidden])) > .p-grade:not(.p-time) { grid-column: 1; }
  .p-results:has(> .a-board:not([hidden])) > .p-big,
  .p-results:has(> .a-board:not([hidden])) > .r-delta:not(.p-time ~ .r-delta) { grid-column: 2; }
  .p-results:has(> .a-board:not([hidden])) > .r-medal { grid-column: 1; }
  .p-results:has(> .a-board:not([hidden])) > .r-medal + small { grid-column: 2; }
  .p-results > .a-board:not([hidden]) {
    grid-column: 3; grid-row: 1 / -1; align-self: stretch;
    margin: 0 0 0 24px; padding-left: 24px; border-left: 1px solid var(--line);
  }
}

@media (max-width: 780px) {
  .p-screen { padding: calc(var(--header-h) + 10px) 12px 76px; }
  .p-card { max-height: calc(100vh - var(--header-h) - 86px); padding: 18px 18px 16px; }
  #game-blockfall { padding: calc(var(--header-h) + 8px) 8px 72px; }
}
@media (max-width: 640px) {
  .app { gap: 8px; }
  .panel { width: 82px; gap: 8px; }
  .box { padding: 8px; border-radius: calc(8px * var(--rk)); }
  .box canvas { width: 64px; }
  .keys { display: none; }
  .stats b { font-size: 13px; }
  .stats div { flex-direction: column; align-items: flex-start; padding: 3px 0; }
  .stats span { font-size: 12px; }
  .touch button { width: 48px; height: 48px; }
  .r-medals { grid-template-columns: repeat(2, 1fr); }
  .r-time { font-size: 24px; }
  .r-spd-num b { font-size: 30px; }
  .r-minimap-wrap { display: none; }
  .r-inputs { display: none; }
  .ed-help { display: none; }
  .r-track { flex-direction: column; align-items: stretch; }
  .r-track-actions { justify-content: flex-end; }
  .p-settings { grid-template-columns: 1fr; }
  .p-stats { grid-template-columns: repeat(3, 1fr); }
  .p-results { padding: 16px 16px 18px; column-gap: 14px; }
  .p-results > .p-grade:not(.p-time) { min-width: 68px; height: 68px; font-size: 42px; }
  .p-results > .p-big b { font-size: 32px; }
  .p-results > .p-time { font-size: 42px; }
  .p-results > .p-stats { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .p-results > .p-stats div { border-left: 0 !important; padding: 10px 8px 6px 0; }
}

/* ---------- Glide (Trace on a gamepad) ---------- */
#game-glide { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="glide"] #game-glide { display: block; }
#glideCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-glide.playing #glideCanvas { cursor: none; }

/* ---------- Weave (left/right road) ---------- */
#game-weave { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="weave"] #game-weave { display: block; }
#weaveCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-weave.playing #weaveCanvas { cursor: none; }

/* ---------- Veer (Weave in 3D) ---------- */
#game-veer { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="veer"] #game-veer { display: block; }
#veerCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game-veer.playing #veerCanvas { cursor: none; }

/* ---------- Stop (timing bar) ---------- */
#game-stop { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="stop"] #game-stop { display: block; }
#stopCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
#game-stop.playing #stopCanvas { cursor: pointer; }
.sp-lives { letter-spacing: .12em; color: var(--p1); }

/* ---------- Cadence (call-and-response rhythm) ---------- */
#game-cadence { position: fixed; inset: 0; display: none; background: var(--c2); }
body[data-game="cadence"] #game-cadence { display: block; }
#cadenceCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
#game-cadence.playing #cadenceCanvas { cursor: pointer; }
#game-cadence .g-top { background: var(--bg); border-color: var(--line-strong); }
.cd-off { display: inline-flex; align-items: center; gap: 8px; }
.cd-off input[type=number] {
  width: 72px; font-family: var(--mono); font-size: 12px; padding: 4px 6px; color: var(--text);
  border: 1px solid var(--line-strong); border-radius: calc(6px * var(--rk)); background: var(--surface);
}
.cd-stats { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 640px) { .cd-stats { grid-template-columns: repeat(2, 1fr); } }


/* Ranks (js/ranks.js): the rank-up banner and the rank on the results screen */
.rank-up {
  position: absolute; left: 50%; top: calc(var(--header-h, 0px) + 84px); z-index: 6; pointer-events: none;
  display: grid; justify-items: center; gap: 2px; padding: 8px 22px; border-radius: 12px;
  background: var(--c2); box-shadow: 0 0 0 2px currentColor, 0 10px 30px rgba(var(--fg-rgb), .12);
  opacity: 0; transform: translate(-50%, -8px) scale(.94); transition: opacity .25s, transform .25s;
}
.rank-up.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.rank-up span { font-family: var(--display); font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.rank-up b { font-family: var(--display); font-size: 26px; font-weight: 700; line-height: 1.1; }
.rank-tag { font-weight: 700; }
