/* ========================================================================== */
/* Root tokens                                                                */
/* ========================================================================== */

:root {
  --nav-h: 64px;
  --bg: #0f1115;
  --fg: #e8e8e8;
  --grid: rgba(255, 255, 255, 0.10);
  --ground: #2a2f3a;
  --accent: #629cc0;
  --hit: #da7d7a;
}

/* Safe-area tokens */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* ========================= THEME PALETTE & ACCENTS ========================= */
/* ========================= NEON MIXED THEME (CONDENSED) ==================== */

:root {
  /* Neon palette */
  --neon-green: #92f100;
  --neon-pink:  #fa1bbc;
  --neon-cyan:  #00d8da;

  /* Icy modal skin (lighter) */
  --modal-bg:   #10233a;
  --modal-bg-2: #153455;
  --modal-border: #2a4c7a;
  --modal-glow: rgba(0, 216, 218, 0.14);

  /* Navbar */
  --header-bg: #0d1018;
  --header-border: var(--neon-cyan);
  --header-glow: rgba(0, 216, 218, 0.18);

  /* Buttons */
  --btn-fg-dark: #0b0e14;

  /* Global panel padding token so it's easy to tune later */
  --panel-pad: 10px;
}

/* If color-mix is supported, sweeten the subtle glows/borders */
@supports (color: color-mix(in oklab, white, black)) {
  :root {
    --header-glow: color-mix(in oklab, var(--neon-cyan) 25%, transparent);
  }
}

/* =============================== NAV BAR ================================== */
header {
  background: var(--header-bg);
  border-bottom: 1px solid
    color-mix(in oklab, var(--header-border) 55%, #222731);
  box-shadow:
    0 1px 0 color-mix(in oklab, var(--neon-cyan) 25%, transparent),
    0 8px 26px -12px var(--header-glow);
}
header nav a:hover,
header nav a:focus-visible {
  color: color-mix(in oklab, var(--neon-cyan) 65%, #cfd3dc);
}
.profile-chip:hover {
  border-color: color-mix(in oklab, var(--neon-cyan) 45%, #2f3d63);
}

/* =============================== MODALS =================================== */
/* Intro modal: KEEP BLACK */
.modal.theme-contrast {
  background: #0b0f16;
  border-color: #2b3b57;
  box-shadow: 0 14px 50px rgba(0,0,0,.55);
}

/* All other modals: icy blue sheet with cyan accent glow */
.modal:not(.theme-contrast) {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), transparent 8%),
    linear-gradient(180deg, var(--modal-bg), var(--modal-bg-2));
  border: 1px solid var(--modal-border);
  box-shadow:
    0 10px 40px rgba(0,0,0,.45),
    0 0 0 1px color-mix(in oklab, var(--neon-cyan) 18%, transparent) inset,
    0 36px 96px -40px var(--modal-glow),
    0 0 64px -48px color-mix(in oklab, var(--neon-cyan) 30%, transparent);
}

/* Close button: subtle cyan focus */
.modal .close-x {
  border-color: color-mix(in oklab, var(--neon-cyan) 35%, #2f3d63);
}
.modal .close-x:hover {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--neon-cyan) 20%, transparent);
}

/* =============================== BUTTONS ================================== */
/* Secondary buttons → PINK accent (dark fill, neon edge) */
.pixel-btn.secondary {
  position: relative;
  color: #e6ebf3;
  background: linear-gradient(#161a26, #0f1320);
  border-color: color-mix(in oklab, var(--neon-pink) 55%, #223252);
  /* optional glow commented by user retained */
}
.pixel-btn.secondary:hover {
  transform: translateY(-1px);
  border-color: var(--neon-pink);
}
.pixel-btn.secondary:active {
  transform: translateY(1px);
}

/* Big full-width primary CTA → GREEN slab */
.pixel-btn.full.big {
  color: var(--btn-fg-dark);
  background: linear-gradient(
    180deg,
    color-mix(in oklab, var(--neon-green) 90%, white 12%),
    color-mix(in oklab, var(--neon-green) 88%, black 6%)
  );
  border-color: color-mix(in oklab, var(--neon-green) 80%, #2b3b57);
}
.pixel-btn.full.big:hover {
  transform: translateY(-1px);
}
.pixel-btn.full.big:active {
  transform: translateY(1px);
  box-shadow:
    0 1px 0 color-mix(in oklab, var(--neon-green) 70%, #2b3b57),
    inset 0 -1px 0 rgba(0,0,0,.12);
}

/* Pills / Discord: keep dark but align with cyan chrome */
.btn-pill,
.discord-btn {
  border-color: color-mix(in oklab, var(--neon-cyan) 80%, #2f3d63);
  box-shadow:
    0 2px 12px rgba(0,0,0,.25),
    inset 0 1px 0 rgba(255,255,255,.05),
    0 0 20px -8px color-mix(in oklab, var(--neon-cyan) 55%, transparent);
}
.btn-pill:hover,
.discord-btn:hover { border-color: var(--neon-cyan); }

/* ========================================================================== */
/* Resets & base                                                              */
/* ========================================================================== */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  overflow: hidden; /* prevent page scroll when game/menu pinned */
}

/* ========================================================================== */
/* Header / Nav                                                               */
/* ========================================================================== */

header {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #222731;
  background: #0d1018;
  position: sticky;
  top: 0;
  z-index: 3000;
  gap: 12px;
  pointer-events: auto;
}

header .brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}

header .site-nav,
header nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

header nav a {
  color: #cfd3dc;
  text-decoration: none;
  font-weight: 600;
}

header {
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

/* ========================================================================== */
/* Profile chip & menu                                                        */
/* ========================================================================== */

.profile-area {
  position: relative;
  margin-left: auto;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  border: 1px solid #243049;
  background:
    radial-gradient(120% 180% at 0% 0%, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 60%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(10, 14, 26, 0.18));
  color: #e6ebf3;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.profile-chip:hover {
  border-color: #2f3d63;
  transform: translateY(-1px);
}

.profile-chip:active {
  transform: translateY(0);
}

.profile-chip .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  background: #101522;
  border: 1px solid #1e2740;
}

.profile-chip .username {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.profile-chip .caret {
  opacity: 0.8;
  font-size: 12px;
}

/*
.profile-chip::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ad17d;
  position: absolute;
  right: 10px;
  top: 8px;
  box-shadow: 0 0 0 2px #0d1018;
}
*/
.profile-chip.is-logged-out::after {
  background: #a0a7b8;
}

.menu-popover {
  z-index: 2001;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 6px;
  background: #0c0f16;
  border: 1px solid #233049;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.menu-popover button {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: #d7dbeb;
  font-weight: 700;
  cursor: pointer;
}

.menu-popover button:hover {
  background: #111524;
}

.menu-popover .sep {
  height: 1px;
  margin: 6px 0;
  background: #223252;
  opacity: 0.5;
}

/* ========================================================================== */
/* Canvas / Game wrap                                                         */
/* ========================================================================== */

#gameWrap {
  height: calc(100vh - var(--nav-h));
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* Pinned game */
#gameWrap {
  position: fixed;
  inset: var(--nav-h) var(--safe-right) max(0px, var(--safe-bottom)) var(--safe-left);
  width: auto !important;
  height: auto !important;
  z-index: 1; /* below header (3000) and overlay (1800) */
}

/* Canvas fills pinned wrapper */
#game {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  image-rendering: pixelated;
}

/* Height fallback using app-vh if provided */
#gameWrap {
  height: calc(var(--app-vh, 100dvh) - var(--nav-h));
}

/* ========================================================================== */
/* HUD / Milestone                                                            */
/* ========================================================================== */

#hud {
  position: fixed;
  top: calc(var(--nav-h) + var(--safe-top) + 8px);
  left: 12px;
  font-weight: 600;
  z-index: 5;
}

#milestone {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  opacity: 0;
  transition: 0.4s;
  pointer-events: none;
}

#milestone.show {
  opacity: 1;
}

/* ========================================================================== */
/* Panels / Cards / Stats                                                     */
/* ========================================================================== */
/* ===== Panels: cool cyan chrome (reuses --neon-cyan) ===== */

.panel {
  padding: var(--panel-pad);
  position: relative;
  border-color: color-mix(in oklab, var(--neon-cyan) 28%, #20283a);
  /* gentle inner hairline + faint outer glow */
  box-shadow:
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 16%, transparent),
    0 18px 48px -28px color-mix(in oklab, var(--neon-cyan) 24%, transparent);
}

.panel.tight {
  padding: calc(var(--panel-pad) - 4px) var(--panel-pad);
}

* Vertical rhythm inside panels: every sibling gets breathing room */
.panel > * + * {
  margin-top: 12px;           /* headings → blocks, rows → next blocks, etc. */
}

/* HR separators a bit roomier */
.panel .hr {
  margin: 12px 0;
}


/* Profile/Guild rows: align & add spacing */
.profile-row,
.guild-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Stats grid already has gap; ensure top spacing from h3 */
#gameStatsPanel .stats-grid {
  margin-top: 10px;
  gap: 12px;
}

/* Character grid + save row spacing */
.char-panel .char-grid {
  padding: 8px;               /* small inner buffer from panel edges */
  gap: 12px;
}
.char-panel .save-row {
  padding-top: 10px;          /* breathing room before the action row */
}

/* Settings content should not hug modal edges and should scroll if long */
.modal > #settingsContent {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;                   /* space between panels themselves */
  padding: 4px 0 0 0;          /* keep panel borders aligned with modal padding */
}
/* tiny top highlight for depth */
.panel::before {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 6px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in oklab, var(--neon-cyan) 22%, white 10%),
    transparent
  );
  opacity: .5;
  pointer-events: none;
}

/* headline gets a minimal cyan underline */
.panel h3 {
  color: #cfd6e4; /* keep */
  position: relative;
  padding-bottom: 4px;
}
.panel h3::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 36px; height: 2px;
  border-radius: 2px;
  background: color-mix(in oklab, var(--neon-cyan) 70%, white 10%);
  box-shadow: 0 0 10px color-mix(in oklab, var(--neon-cyan) 40%, transparent);
}

/* focus/hover state: make the panel clearly active */
.panel:focus-within,
.panel:hover {
  border-color: color-mix(in oklab, var(--neon-cyan) 55%, #20283a);
  box-shadow:
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 28%, transparent),
    0 24px 70px -32px color-mix(in oklab, var(--neon-cyan) 40%, transparent);
}

/* ===== Stat tiles: quiet by default, readable pop on hover/active ===== */

.stat {
  border-color: color-mix(in oklab, var(--neon-cyan) 18%, #20283a);
  transition: border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}

/* hover for affordance; add .is-active in JS when selected */
.stat:hover,
.stat.is-active {
  border-color: color-mix(in oklab, var(--neon-cyan) 55%, #20283a);
  box-shadow:
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 26%, transparent),
    0 10px 30px -20px color-mix(in oklab, var(--neon-cyan) 35%, transparent);
  transform: translateY(-1px);
}

/* keys/values stay readable; optional tint for key label */
.stat .k {
  color: color-mix(in oklab, var(--neon-cyan) 28%, #9aa3b3);
}

/* ========================================================================== */
/* Menu layout / Animation panel                                              */
/* ========================================================================== */

/* Container fills viewport minus navbar; anim-panel grows, stage anchors */
.menu-layout {
  display: grid;
  grid-template-rows: 1fr auto; /* row 1 = anim-panel (flex), row 2 = stage */
  gap: 12px;
  /* When used standalone (outside modal), pin under header */
  position: fixed;
  inset: var(--nav-h) var(--safe-right) var(--safe-bottom) var(--safe-left);
  width: auto;
  height: auto;
  min-height: 0; /* allow children to flex/shrink */
  z-index: 1;
}

/* When inside a modal, let menu-layout consume modal’s space */
.modal {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.modal > .menu-layout {
  position: static;
  inset: auto;
  width: auto;
  height: auto;
  z-index: auto;
  flex: 1;
}

/* Settings modal content should stretch and scroll if needed */
.modal > #settingsContent {
  flex: 1 1 auto;
  min-height: 0;          /* critical so overflow can calculate properly */
  overflow: auto;         /* scroll content, keep footer pinned */
  display: flex;          /* optional, matches your stack-y panels nicely */
  flex-direction: column;
  gap: 12px;
}

/* Safety: any first-level panel stacks in modals (How/Leaderboard/etc.) */
.modal > .panel,
.modal > .lb,
.modal > .stack {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;         /* only if those screens can overflow, harmless otherwise */
}

/* Anim panel fills available space */
.panel.anim-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Flexible filler inside anim-panel */
.panel.anim-panel .anim-slot {
  flex: 1 1 auto;
  height: auto;
  min-height: 160px; /* keep a reasonable floor */
}

.anim-panel .tip {
  margin-top: 8px;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 10px;

  /* size & centering */
  width: 100%;
  max-width: 50%;          /* cap at half the viewport/container */
  margin-inline: auto;     /* center as a block element */
  justify-self: center;    /* also center in the grid track (since it's a grid child) */
  align-self: start;       /* stay anchored to the bottom row of the grid */

  /* visuals */
  height: auto;
  border: 1px solid #233049;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(10, 14, 26, 0.25));
  border-radius: 14px;
  padding: 16px;
}

.anim-slot {
  position: relative;
  /* border: 1px solid #233049; */
  border-radius: 12px;
  overflow: hidden;
  background: #0c0f16;
  margin-top: 6px;
  height: clamp(160px, 28vh, 260px);
}

.rider {
  position: absolute;
  left: calc(-1 * var(--img-w, 120px));
  height: 40%;
  image-rendering: pixelated;
  object-fit: contain;
  pointer-events: none;
  visibility: hidden;
}

.rider.top { top: 8%; }
.rider.bottom { bottom: 8%; top: auto; }

@keyframes rideL2R {
  from { left: calc(-1 * var(--img-w)); }
  to   { left: calc(100% + var(--img-w)); }
}

@keyframes rideR2L {
  from { left: calc(100% + var(--img-w)); }
  to   { left: calc(-1 * var(--img-w)); }
}

.rider.run-l2r {
  visibility: visible;
  animation: rideL2R var(--ride-ms, 2400ms) linear forwards;
}

.rider.run-r2l {
  visibility: visible;
  animation: rideR2L var(--ride-ms, 2400ms) linear forwards;
}

.anim-slot .logo-gif {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 600ms ease;
}

.anim-slot .logo-gif.show { opacity: 1; }

.anim-slot .logo-gif img {
  max-width: 65%;
  height: auto;
  image-rendering: pixelated;
}

/* ========================================================================== */
/* Buttons                                                                    */
/* ========================================================================== */

.pixel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 12px 16px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #111;
  background: linear-gradient(#fefefe, #dfe7f1);
  border: 2px solid #2b3b57;
  border-radius: 10px;
  image-rendering: pixelated;
  cursor: pointer;
  width: auto;
}

.pixel-btn.full { width: 100%; }

.pixel-btn.big {
  font-size: 16px;
  padding: 14px 26px;
  letter-spacing: 0.4px;
}

.pixel-btn:hover { transform: translateY(-1px); }

.pixel-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #2b3b57, inset 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.link-btn {
  background: none;
  border: none;
  color: #9bb4ff;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

/* ========================================================================== */
/* Layout helpers                                                             */
/* ========================================================================== */

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* ========================================================================== */
/* Footer                                                                     */
/* ========================================================================== */

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid #233049;
  background: #0c0f16;
  border-radius: 0 0 16px 16px;
}

/* Sticky footer/header for LB sections (kept) */
.lb-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0e1220;
}

.footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #0c0f16;
}

/* ========================================================================== */
/* Text bits                                                                  */
/* ========================================================================== */

.hr {
  height: 1px;
  background: #223252;
  opacity: 0.5;
  margin: 8px 0;
}

.tip {
  font-size: 12px;
  color: #9aa6b8;
}

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid #4666ff;
  outline-offset: 2px;
}

/* Reduced motion (not mobile-specific; accessibility) */
@media (prefers-reduced-motion: reduce) {
  .rider { animation-duration: 1ms !important; }
  .anim-slot .logo-gif { opacity: 1 !important; }
}

/* ========================================================================== */
/* Character picker                                                           */
/* ========================================================================== */

.char-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 4px;
  max-height: 38vh;
  overflow: auto;
  border: 1px solid #233049;
  border-radius: 10px;
  background: #0c101b;
}

.char-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid #20283a;
  border-radius: 10px;
  background: #0f1320;
  cursor: pointer;
  transition: transform 0.06s ease, border-color 0.06s ease, box-shadow 0.06s ease;
}

.char-card:hover {
  transform: translateY(-1px);
  border-color: #2b3b57;
  box-shadow: 0 3px 0 rgba(43, 59, 87, 0.6);
}

.char-card.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.char-thumb {
  width: 100%;
  height: 96px;
  border-radius: 8px;
  background: #0b0f19;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #1c273c;
}

.char-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.char-name {
  font-size: 13px;
  font-weight: 700;
  color: #cfd6e4;
  text-align: center;
}

.save-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.badge-note {
  font-size: 12px;
  color: #9aa6b8;
}

/* ========================================================================== */
/* Mode picker                                                                */
/* ========================================================================== */

.stage .row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.mode-picker {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-picker .k {
  font-size: 12px;
  color: #9aa6b8;
  font-weight: 700;
}
/* ===== Segmented control: reuse global neon variables (no local theme) ===== */

/* base polish (keeps your existing structure) */
.seg {
  border-radius: 12px;
}

/* hide radios; keep accessible */
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Segmented control: dark fill, neon-cyan border on selection */

.seg label {
  padding: 10px 16px;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: #aeb6c4;
  border: 1px solid transparent; /* avoid layout shift */
  border-radius: 10px;
  transition: border-color .12s ease, color .12s ease, box-shadow .12s ease;
}

/* keep your subtle divider */
.seg label + input + label {
  border-left: 1px solid rgba(255,255,255,0.06);
}

/* selected = same dark bg, cyan accent border */
.seg input:checked + label {
  color: #e6ebf3;
  background: linear-gradient(#161a26, #0f1320);
  border-color: color-mix(in oklab, var(--neon-cyan) 55%, #223252);
  box-shadow:
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 35%, transparent);
}

/* hover + focus with cyan nudge */
.seg label:hover {
  color: color-mix(in oklab, var(--neon-cyan) 40%, #cfd6e4);
}
.seg input:focus-visible + label,
.seg label:focus-visible {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--neon-cyan) 28%, transparent),
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 45%, transparent);
}

/* ========================================================================== */
/* Discord / Buttons / Pills                                                  */
/* ========================================================================== */

.discord-btn,
.btn-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #2f3d63;
  background: linear-gradient(180deg, #1b2338, #0f1526);
  color: #e6ebf3;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.discord-btn:hover,
.btn-pill:hover {
  transform: translateY(-1px);
  border-color: #3b4c79;
}

.discord-btn img,
.btn-pill img {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: #1d2235;
}

/* ========================================================================== */
/* Profile row                                                                */
/* ========================================================================== */

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-card .avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #1e2740;
  background: #101522;
  image-rendering: pixelated;
  object-fit: cover;
}

.profile-card .meta .name {
  font-weight: 800;
  color: #e6ebf3;
}

.profile-card .meta .sub {
  font-size: 12px;
  color: #9aa6b8;
}

/* ========================================================================== */
/* Switch                                                                     */
/* ========================================================================== */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch .track {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #0f1320;
  border: 1px solid #233049;
  position: relative;
}

.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e6ebf3;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: left 0.15s ease;
}

input[type="checkbox"].audio-toggle {
  display: none;
}

input[type="checkbox"].audio-toggle:checked + .track .knob {
  left: 22px;
}

input[type="checkbox"].audio-toggle:checked + .track {
  background: #2a3b63;
}

/* ========================================================================== */
/* Death screen / Stats grid                                                  */
/* ========================================================================== */

.death-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in oklab, var(--neon-cyan) 18%, #20283a);
}

.death-title {
  font-size: 26px;
  font-weight: 900;
  color: #e6ebf3;
  line-height: 1.1;
  position: relative;
}
.death-title::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 44px;
  height: 2px;
  border-radius: 2px;
  background: color-mix(in oklab, var(--neon-cyan) 72%, white 10%);
  box-shadow: 0 0 10px color-mix(in oklab, var(--neon-cyan) 45%, transparent);
}

.death-sub {
  font-size: 12px;
  color: #9aa6b8;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin: 12px 0 8px;
}

.stat-card {
  background: #0f1320;
  border: 1px solid color-mix(in oklab, var(--neon-cyan) 24%, #20283a);
  border-radius: 10px;
  padding: 12px; /* was 10px 12px */
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 12%, transparent);
}

.stat-card .k {
  font-size: 12px;
  color: color-mix(in oklab, var(--neon-cyan) 28%, #9aa3b3);
}

.stat-card .v {
  font-weight: 900;
  font-size: 18px;
  color: #e6ebf3;
}

.recent {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 16px;
}

.recent-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-weight: 800;
  font-size: 12px;
  color: #d7dbeb;
  background: #0f1320;
  border: 1px solid #20283a;
  border-radius: 8px;
  padding: 6px 8px;
}

.actions-row {
  display: flex;
  gap: 12px;             /* a touch more room */
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}

/* gentle neon cues for the two actions (no new button theme) */
#btnRestart {
  border-color: color-mix(in oklab, var(--neon-green) 50%, #2b3b57);
}
#btnRestart:hover {
  border-color: var(--neon-green);
  transform: translateY(-1px);
}
#btnLeaderboardFromDeath {
  border-color: color-mix(in oklab, var(--neon-pink) 55%, #223252);
}
#btnLeaderboardFromDeath:hover {
  border-color: var(--neon-pink);
  transform: translateY(-1px);
}

.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  font-size: 11px;
  background: #0f1320;
  border: 1px solid #233049;
  border-radius: 6px;
  padding: 2px 6px;
  color: #cfd6e4;
}
/* ===== Crash modal inner padding (reuse globals) ========================= */

/* Add comfortable insets + safe-area awareness */
#modalBox.modal.theme-contrast {
  padding-top:    var(--panel-pad, 16px);
  padding-bottom: var(--panel-pad, 16px);
  padding-left:   calc(var(--panel-pad, 16px) + var(--safe-left));
  padding-right:  calc(var(--panel-pad, 16px) + var(--safe-right));
}

/* Ensure content doesn’t butt into the footer’s top border */
#modalBox .actions-row { margin-bottom: 8px; }

/* Optional: nudge the stats grid and header to align with the new padding rhythm */
#modalBox .death-header { margin-top: 2px; }
#modalBox .stats-grid   { margin-left: 0; margin-right: 0; }

/* If you have any full-width elements inside, let them respect the new insets */
#modalBox .stats-grid,
#modalBox .actions-row {
  padding-inline: 0; /* keep them flush to the modal’s inner edge */
}

/* ========================================================================== */
/* Leaderboard                                                                */
/* ========================================================================== */

.lb {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Tabs: dark fill + neon-cyan border on selection (mirrors .seg) */
.lb-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 8px;
}

.lb-tab {
  position: relative;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid #233049;
  background: linear-gradient(#161a26, #0f1320);
  color: #cfd6e4;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, box-shadow .12s ease, transform .06s ease;
}

.lb-tab:hover {
  color: color-mix(in oklab, var(--neon-cyan) 40%, #cfd6e4);
  border-color: color-mix(in oklab, var(--neon-cyan) 30%, #233049);
}

.lb-tab[aria-selected="true"] {
  color: #e6ebf3;
  border-color: color-mix(in oklab, var(--neon-cyan) 55%, #233049);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 35%, transparent);
  transform: translateY(-1px);
}

.lb-tab:focus-visible {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--neon-cyan) 28%, transparent),
    inset 0 0 0 1px color-mix(in oklab, var(--neon-cyan) 45%, transparent);
}

/* Actions + limit input */
.lb-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#lbLimit {
  background: #0f1320;
  color: #cfd6e4;
  border: 1px solid #233049;
  border-radius: 8px;
  padding: 6px 8px;
}

/* Body + table */
.lb-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid #233049;
  border-radius: 12px;
  background: #0c101b;
}

.lb-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.lb-table th,
.lb-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #1d263a;
}

.lb-table th {
  position: sticky;
  top: 0;
  background: #0e1220;
  z-index: 1;
  font-size: 12px;
  color: #9aa6b8;
  text-align: left;
}

/* Row states & cells */
.lb-row.me { background: rgba(98, 156, 192, 0.12); }

.lb-rank {
  width: 60px;
  color: #9aa6b8;
  font-weight: 800;
}

.lb-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lb-user img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid #1e2740;
  image-rendering: pixelated;
  object-fit: cover;
  background: #101522;
}

.lb-val {
  text-align: right;
  font-weight: 900;
  color: #e6ebf3;
}

.lb-footer {
  font-size: 12px;
  color: #9aa6b8;
}

/* Role chips inside LB */
.lb-role-icon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  image-rendering: pixelated;
  border: 1px solid #1e2740;
  background: #101522;
}

.lb-user-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ========================================================================== */
/* Overlay + Intro + Modals (two-layer overlay)                               */
/* ========================================================================== */

#overlay {
  position: fixed;
  top: var(--nav-h);                       /* respect navbar height */
  right: var(--safe-right);
  bottom: 0;
  left: var(--safe-left);
  z-index: 1800;                           /* below header (3000), above game */
  background: transparent;
  /* safe area inside the overlay, not the page */
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#overlay[hidden] { display: none; }

.intro-layer {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0f16;
}

/* mild vignette */
.intro-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(140% 120% at 50% -20%, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0) 40%),
    radial-gradient(120% 140% at 50% 120%, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 60%);
}

.modal-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
}

.modal-layer[hidden] { display: none; }

.modal-layer:not([hidden]) ~ .intro-layer { pointer-events: none; }

/* Base modal sizing (desktop) */
.modal {
  width: min(1100px, 96vw);
  height: calc(100vh - var(--nav-h) - 24px);
  max-height: calc(100vh - var(--nav-h) - 8px);
  margin-top: 12px;                        /* keep your breathing room */
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.modal > .menu-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
}

/* Celebrate rail */
.celebrate-rail {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 96px;
}

.celebrate-rail .celebrate-gif {
  height: 72px;
  image-rendering: pixelated;
  border-radius: 8px;
  border: 1px solid #1e2740;
  background: #101522;
  padding: 4px;
  opacity: 0.95;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.6s ease;
}

.celebrate-rail.celebrate-live .celebrate-gif:nth-child(odd) {
  animation: floatA 2.4s ease-in-out infinite;
}

.celebrate-rail.celebrate-live .celebrate-gif:nth-child(even) {
  animation: floatB 2.8s ease-in-out infinite;
}

@keyframes floatA {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

@keyframes floatB {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(5px); }
}

/* Role chips */
.role-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.role-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid #233049;
  border-radius: 10px;
  background: #0f1320;
}

.role-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  image-rendering: pixelated;
  border: 1px solid #1e2740;
  background: #101522;
}

.role-emoji { font-size: 16px; line-height: 1; }

.role-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.role-name {
  font-weight: 800;
  font-size: 12px;
  color: #d7dbeb;
}

/* Modal footer: right-aligned, centered, padded from the right edge */
.modal-footer {
  margin-top: auto;
  display: flex;
  align-items: center;                         /* vertical centering */
  justify-content: flex-end;                   /* right-align contents */
  gap: 10px;
  padding: 12px calc(16px + var(--safe-right)) 12px 16px; /* right padding w/ safe area */
  border-top: 1px solid #233049;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0));
}

/* Pink-secondary Close in the footer (inherits your secondary look) */
.modal-footer .close-x {
  position: static;
  width: auto;
  height: auto;
  padding: 10px 16px;
  border-radius: 10px;
  background: linear-gradient(#161a26, #0f1320);
  color: #e6ebf3;
  border: 1px solid color-mix(in oklab, var(--neon-pink) 55%, #223252);
  font-weight: 800;
  transition: border-color .12s ease, transform .06s ease;
}
.modal-footer .close-x:hover {
  transform: translateY(-1px);
  border-color: var(--neon-pink);
}
.modal-footer .close-x:focus-visible {
  outline: none;
  border-color: var(--neon-pink);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--neon-pink) 28%, transparent),
    inset 0 0 0 1px color-mix(in oklab, var(--neon-pink) 45%, transparent);
}
.modal-footer .close-x:active { transform: translateY(1px); }
