:root {
  --bg: #1a0b2e;
  --panel: rgba(255, 255, 255, 0.96);
  --ink: #2d1b4e;
  --muted: #6b5a8a;
  --primary: #a855f7;
  --primary-dark: #7c3aed;
  --accent: #fbbf24;
  --pink: #fb7185;
  --cyan: #22d3ee;
  --green: #4ade80;
  --hud-ink: #f8fafc;
  --hud-surface: rgba(15, 23, 42, 0.82);
  --hud-surface-strong: rgba(15, 23, 42, 0.94);
  --hud-border: rgba(255, 255, 255, 0.2);
  --race-accent: #a855f7;
  --focus: #fde047;
  --shadow: 0 12px 40px rgba(76, 29, 149, 0.35);
  --radius: 22px;
  --font: "Fredoka", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #5b21b6 0%, #7c3aed 40%, #c4b5fd 100%);
}

/* Race free-look: hide cursor; pointer lock also hides system cursor */
body.race-look,
body.race-look #game-canvas,
body.pointer-locked,
body.pointer-locked * {
  cursor: none !important;
}

body.race-look #hud {
  pointer-events: none;
}

.hidden { display: none !important; }

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 20%, rgba(168, 85, 247, 0.35), transparent 55%),
              linear-gradient(160deg, #2e1065 0%, #4c1d95 50%, #701a75 100%);
}

.screen.overlay {
  background: rgba(15, 5, 30, 0.45);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.panel {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 26px 22px;
  box-shadow: var(--shadow);
  border: 3px solid #fff;
  animation: pop-in 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.lobby-panel {
  width: min(920px, 100%);
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.screen-lobby {
  align-items: stretch;
  padding: 12px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 22px;
  align-items: start;
}

.lobby-play,
.lobby-character {
  min-width: 0;
}

.lobby-character {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px 16px;
  border-radius: 18px;
  background: linear-gradient(165deg, #faf5ff 0%, #f3e8ff 55%, #ede9fe 100%);
  border: 2px solid #e9d5ff;
}

.lobby-preview-stage {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, #c4b5fd 0%, #a78bfa 45%, #7c3aed 100%);
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow: inset 0 0 24px rgba(76, 29, 149, 0.2);
  margin-bottom: 10px;
}

#lobby-preview {
  display: block;
  width: 100%;
  height: 200px;
}

.lobby-preview-name {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(30, 20, 50, 0.78);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby-character .account-bar {
  margin: 4px 0 10px;
}

.lobby-color-field {
  margin-bottom: 10px;
}

.lobby-shop-btn {
  margin-top: 4px;
  width: 100%;
}

.logo-compact {
  margin-bottom: 12px;
}

.logo-compact .logo-bean {
  font-size: 2.2rem;
}

.logo-compact h1 {
  font-size: 2rem;
}

.logo-compact .tagline {
  font-size: 0.88rem;
}

.lobby-secondary-btns {
  margin-top: 8px;
}

@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.logo {
  text-align: center;
  margin-bottom: 18px;
}

.logo-bean {
  font-size: 3rem;
  display: block;
  filter: drop-shadow(0 6px 0 rgba(124, 58, 237, 0.25));
  animation: bounce-bean 1.4s ease-in-out infinite;
}

@keyframes bounce-bean {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.logo h1 {
  font-size: 2.4rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--primary-dark), var(--pink), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.lobby-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
}

.chip {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f3e8ff, #fce7f3);
  color: var(--primary-dark);
  border: 1px solid #e9d5ff;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 4px;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, #faf5ff, #f5f3ff);
  border: 1.5px solid #e9d5ff;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.account-stat {
  font-variant-numeric: tabular-nums;
}

.account-divider {
  color: var(--muted);
  font-weight: 400;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.field input {
  font-family: var(--font);
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid #e9d5ff;
  background: #faf5ff;
  outline: none;
  color: var(--ink);
  touch-action: manipulation;
}

.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.25);
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.12);
  transition: transform 0.12s ease;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected {
  border-color: var(--ink);
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.difficulty-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.difficulty-btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 8px;
  border-radius: 14px;
  border: 2px solid #e9d5ff;
  background: #faf5ff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}

.difficulty-btn:active {
  transform: scale(0.97);
}

.difficulty-btn.active {
  background: linear-gradient(135deg, #c084fc, #a855f7);
  color: #fff;
  border-color: var(--primary-dark);
  box-shadow: 0 4px 0 rgba(124, 58, 237, 0.25);
}

.mode-btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid #e9d5ff;
  background: #faf5ff;
  color: var(--muted);
  cursor: pointer;
}

.mode-btn.active {
  background: linear-gradient(135deg, #c084fc, #a855f7);
  color: #fff;
  border-color: var(--primary-dark);
}

.tiny {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 4px;
}

/* Friends section */
.friends-section {
  margin-bottom: 14px;
}

.friends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.friends-header .btn.tiny {
  margin-top: 0;
  padding: 4px 10px;
  font-size: 0.75rem;
  width: auto;
  border-radius: 8px;
}

.friends-list {
  max-height: 160px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: #faf5ff;
  border-radius: 12px;
  padding: 4px;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.friend-item:last-child {
  margin-bottom: 0;
}

.friend-name {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-online {
  color: var(--green);
  font-size: 0.65rem;
  font-weight: 700;
}

.friend-code {
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary-dark);
  background: #f3e8ff;
  padding: 2px 6px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.friend-code:hover {
  background: #e9d5ff;
}

.friend-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn.tiny {
  margin-top: 0;
  padding: 4px 10px;
  font-size: 0.75rem;
  width: auto;
  border-radius: 8px;
}

.btn.ghost.tiny {
  border: 1px solid #e9d5ff;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
}

.btn.ghost.tiny:hover {
  background: #f3e8ff;
}

.add-friend-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.add-friend-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #e9d5ff;
  background: #faf5ff;
  outline: none;
  color: var(--ink);
}

.add-friend-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

.friends-empty {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 8px 0;
}

/* Multiplayer lobby */
.lobby-mp-panel h2 {
  text-align: center;
  margin-bottom: 6px;
}

.mp-code {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--primary-dark);
  background: #faf5ff;
  border-radius: 14px;
  padding: 10px;
  border: 2px dashed #e9d5ff;
  margin: 8px 0 6px;
  user-select: all;
}

.mp-map-line {
  text-align: center;
  font-weight: 700;
  color: var(--ink);
  margin: 6px 0 10px;
}

.mp-map-picker {
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}

.map-pick-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-right: 2px;
}

.map-pick-row .mode-btn {
  font-size: 0.85rem;
  padding: 8px 10px;
}

.map-pick-row .map-random-btn {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #4a1d07;
  border-color: #f59e0b;
  font-weight: 800;
}

.mp-player-list {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  margin: 8px 0 12px;
  background: #faf5ff;
  border-radius: 14px;
  padding: 6px;
}

.mp-player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff;
  margin-bottom: 4px;
  font-weight: 600;
}

.mp-player-list li:last-child { margin-bottom: 0; }

.mp-player-list .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mp-player-list .host-tag {
  margin-left: auto;
  font-size: 0.7rem;
  background: var(--accent);
  color: #4a1d07;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 800;
}

.mp-player-list .you-tag {
  margin-left: auto;
  font-size: 0.7rem;
  background: var(--ink);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
}

.btn {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  border-radius: 16px;
  padding: 12px 18px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn:active { transform: scale(0.97); }

.btn.primary {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #4a1d07;
  box-shadow: 0 6px 0 #d97706;
  touch-action: manipulation;
  cursor: pointer;
}

.btn.primary:hover { filter: brightness(1.05); }

.btn.primary.big {
  font-size: 1.35rem;
  padding: 16px;
  margin-top: 12px;
}

.btn.ghost {
  background: transparent;
  color: var(--primary-dark);
  box-shadow: none;
  border: 2px solid #e9d5ff;
  touch-action: manipulation;
  cursor: pointer;
}

.footer-note {
  text-align: center;
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

.status-link {
  color: var(--primary-dark);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(124, 58, 237, 0.35);
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.status-link:hover {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.howto {
  list-style: none;
  margin: 12px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.howto li {
  background: #faf5ff;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  color: var(--ink);
}

kbd {
  font-family: var(--font);
  background: #2d1b4e;
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Countdown */
#countdown-num {
  font-size: clamp(5rem, 20vw, 9rem);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 8px 0 rgba(0,0,0,0.25), 0 0 40px rgba(251, 191, 36, 0.6);
  animation: count-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes count-pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
}

.pill {
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  font-size: 1rem;
}

.map-pill {
  font-size: 0.85rem;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(243,232,255,0.95));
}

.stage-pill {
  font-size: 0.8rem;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #4a1d07;
  font-weight: 800;
  padding: 6px 12px;
}

/* Power-up HUD */
.powerup-hud {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid;
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: powerup-pop 0.3s ease-out;
}

@keyframes powerup-pop {
  0% { transform: translateX(-50%) scale(0.5); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

.powerup-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.powerup-label {
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.powerup-timer {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.hud-bottom {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(320px, 70vw);
}

@media (max-width: 899px), (pointer: coarse) {
  .hud-bottom {
    bottom: 28%;
    width: min(280px, 55vw);
  }
}

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  border: 2px solid #fff;
  max-width: min(90vw, 420px);
  text-align: center;
  pointer-events: none;
  animation: pop-in 0.3s ease;
}

.progress-wrap {
  width: 100%;
  height: 10px;
  background: rgba(45, 27, 78, 0.45);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.35);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #a855f7, #f472b6, #fbbf24);
  border-radius: 999px;
  transition: width 0.1s linear;
}

.hint {
  background: rgba(45, 27, 78, 0.75);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Mid-race finished banner */
.finished-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  pointer-events: none;
  text-align: center;
}

.finished-card {
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #fff;
  border-radius: 20px;
  padding: 18px 28px;
  box-shadow: var(--shadow);
  animation: pop-in 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
  min-width: 220px;
}

.finished-emoji {
  font-size: 2.4rem;
  line-height: 1;
}

#finished-headline {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 4px;
}

#finished-sub {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 2px;
}

/* Results / Leaderboard */
.results-screen {
  z-index: 60 !important;
  pointer-events: auto !important;
  touch-action: manipulation;
  background: rgba(15, 5, 30, 0.72) !important;
  backdrop-filter: blur(8px);
  overflow-y: auto;
  align-items: flex-start;
  padding: 24px 16px 32px;
}

.results-panel {
  width: min(440px, 100%);
  margin: auto;
  pointer-events: auto;
  touch-action: manipulation;
  max-height: none;
}

.results-header {
  text-align: center;
  margin-bottom: 10px;
}

.results-medal {
  font-size: 2.8rem;
  line-height: 1;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,0.12));
  animation: bounce-bean 1.2s ease-in-out infinite;
}

.results-panel h2 {
  text-align: center;
  font-size: 1.85rem;
  margin: 6px 0 2px;
  background: linear-gradient(90deg, var(--primary-dark), var(--pink), #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.results-sub {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}

/* Mini podium */
.podium {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 8px;
  align-items: end;
  margin: 14px 0 16px;
  min-height: 110px;
}

.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.podium-bean {
  width: 36px;
  height: 44px;
  border-radius: 50% 50% 45% 45%;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
}

.podium-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.podium-block {
  width: 100%;
  border-radius: 12px 12px 6px 6px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  border: 2px solid rgba(255,255,255,0.5);
}

.podium-slot.p1 .podium-block {
  height: 72px;
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  color: #4a1d07;
}
.podium-slot.p2 .podium-block {
  height: 52px;
  background: linear-gradient(180deg, #cbd5e1, #94a3b8);
  color: #1e293b;
}
.podium-slot.p3 .podium-block {
  height: 40px;
  background: linear-gradient(180deg, #fdba74, #d97706);
  color: #431407;
}
.podium-slot.p1 { order: 2; }
.podium-slot.p2 { order: 1; }
.podium-slot.p3 { order: 3; }

.lb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lb-meta {
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
}

.leaderboard {
  list-style: none;
  margin-bottom: 14px;
  max-height: min(280px, 38vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border-radius: 14px;
  background: #f5f3ff;
  padding: 6px;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 36px 16px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 4px;
  background: #fff;
  font-weight: 600;
  border: 2px solid transparent;
}

.leaderboard li:last-child { margin-bottom: 0; }

.leaderboard li.you {
  background: linear-gradient(90deg, #fef3c7, #fde68a);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.25);
}

.leaderboard li.dnf {
  opacity: 0.72;
}

.leaderboard .place {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  flex-shrink: 0;
}

.leaderboard li:nth-child(1) .place { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #4a1d07; }
.leaderboard li:nth-child(2) .place { background: linear-gradient(135deg, #e2e8f0, #94a3b8); color: #1e293b; }
.leaderboard li:nth-child(3) .place { background: linear-gradient(135deg, #fdba74, #d97706); color: #431407; }

.leaderboard .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}

.leaderboard .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.leaderboard .you-tag {
  font-size: 0.7rem;
  background: var(--ink);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}

.leaderboard .time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.leaderboard li.you .time { color: #92400e; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  background: #faf5ff;
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  border: 2px solid #f3e8ff;
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-value.record {
  color: #b45309;
}

.row-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lobby-extra-btns {
  margin-top: 8px;
  grid-template-columns: 1fr 1fr 1fr;
}

.lobby-extra-btns .btn {
  margin-top: 0;
  font-size: 0.92rem;
  padding: 10px 8px;
}

.settings-panel h2 {
  text-align: center;
  margin-bottom: 14px;
}

.settings-panel input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  touch-action: manipulation;
}

.setting-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.setting-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.settings-hint {
  margin: 8px 0 14px;
  line-height: 1.4;
}

.shop-panel {
  width: min(500px, 100%);
}

.shop-panel h2 {
  text-align: center;
  margin-bottom: 6px;
}

.shop-coins {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 12px;
}

.shop-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
  max-height: min(380px, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.shop-item {
  background: #faf5ff;
  border: 2px solid #e9d5ff;
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s, border-color 0.12s;
}

.shop-item:hover {
  transform: scale(1.02);
}

.shop-item.owned {
  border-color: var(--green);
  background: #f0fdf4;
}

.shop-item.equipped {
  border-color: var(--accent);
  background: linear-gradient(135deg, #fef3c7, #fde68a);
}

.shop-item-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.shop-item-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
}

.shop-item-type {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.shop-item-price {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.shop-item.owned .shop-item-price {
  color: var(--green);
}

.shop-item.equipped .shop-item-price {
  color: #92400e;
}

.shop-item-btn {
  margin-top: 4px;
  font-size: 0.78rem;
  padding: 6px 14px;
  min-width: auto;
  width: auto;
  border-radius: 10px;
}

.row-btns .btn { margin-top: 0; }

.results-actions {
  position: relative;
  z-index: 2;
}

.results-actions .btn {
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
  min-height: 48px;
}

.results-actions .btn:hover {
  filter: brightness(1.05);
}

.results-actions .btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* Loading */
#screen-loading {
  flex-direction: column;
  gap: 16px;
  color: #fff;
  font-weight: 600;
  pointer-events: all;
}

.loading-blob {
  width: 64px;
  height: 80px;
  background: linear-gradient(180deg, #fb7185, #a855f7);
  border-radius: 50% 50% 45% 45%;
  animation: blob-bounce 0.7s ease-in-out infinite;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}

@keyframes blob-bounce {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(-24px) scaleY(1.05); }
}

.elimination-card {
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #fff;
  border-radius: 20px;
  padding: 24px 36px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
  min-width: 260px;
}

.elimination-emoji {
  font-size: 3rem;
  line-height: 1;
  animation: bounce-bean 1s ease-in-out infinite;
}

.elimination-text {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 8px;
}

.elimination-sub {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 4px;
}

.solo-lobby-panel {
  text-align: center;
  min-width: 380px;
}

.solo-lobby-header {
  margin-bottom: 16px;
}

.solo-lobby-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--primary-dark), var(--pink), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
}

.solo-lobby-beans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 16px 0;
}

.solo-lobby-bean {
  display: flex;
  align-items: center;
}

.solo-lobby-bean-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 12px;
  background: #faf5ff;
  border: 2px solid transparent;
}

.solo-lobby-bean--player .solo-lobby-bean-row {
  background: linear-gradient(90deg, #fef3c7, #fde68a);
  border-color: var(--accent);
}

.solo-lobby-bean--bot .solo-lobby-bean-row {
  opacity: 0.82;
}

.solo-lobby-bean-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.solo-lobby-bean-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.solo-lobby-badge {
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.solo-lobby-badge--you {
  background: var(--ink);
  color: #fff;
}

.solo-lobby-badge--bot {
  background: #e9d5ff;
  color: var(--primary-dark);
}

.solo-lobby-footer {
  margin-top: 14px;
}

.solo-lobby-countdown {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

#solo-lobby-timer {
  display: inline-block;
  font-weight: 700;
  animation: solo-countdown-pulse 1s ease-in-out infinite;
}

@keyframes solo-countdown-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.solo-lobby-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.solo-lobby-actions .btn {
  margin-top: 0;
}

/* Touch controls */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

#stick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 45%;
  height: 45%;
  pointer-events: auto;
}

#stick-base {
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 3px solid rgba(255,255,255,0.45);
  touch-action: none;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
}

#touch-buttons {
  position: absolute;
  right: 20px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

#touch-buttons button {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.28);
  font-size: 1.5rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  touch-action: manipulation;
}

#touch-buttons button:active {
  background: rgba(251, 191, 36, 0.7);
  transform: scale(0.95);
}

#touch-buttons .touch-item {
  border-color: rgba(34, 211, 238, 0.8);
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-family: var(--font);
  font-weight: 800;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}

#touch-buttons .touch-item:disabled {
  opacity: 0.42;
  filter: grayscale(0.7);
}

#touch-buttons .touch-item.item-ready {
  border-color: #fff;
  background: var(--item-color, rgba(34, 211, 238, 0.78));
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.18), 0 0 22px var(--item-color, #22d3ee);
  animation: item-ready-pulse 1.1s ease-in-out infinite;
}

@keyframes item-ready-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@media (max-width: 899px) {
  .panel { padding: 22px 18px 18px; }
  .logo h1 { font-size: 2rem; }

  .lobby-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .lobby-character {
    order: -1;
  }

  #lobby-preview {
    height: 180px;
  }

  .lobby-panel {
    max-height: none;
    overflow: visible;
  }
}

/* ---------- Minimap (race HUD) ---------- */
.minimap {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 120px;
  height: 120px;
  background: rgba(30, 20, 50, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 2;
}

/* ---------- Lobby: recent race + daily quests ---------- */
.lobby-recent-card,
.lobby-daily-card {
  width: 100%;
  background: rgba(30, 20, 50, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 10px 0;
  color: #fff;
  font-size: 13px;
  box-sizing: border-box;
}
.lobby-recent-title,
.lobby-daily-title {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 6px;
}
.lobby-recent-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2px 0;
}
.lobby-recent-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.lobby-recent-place {
  font-weight: 700;
  color: #fde68a;
}
.daily-quest-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name meta" "bar bar" "claim claim";
  gap: 4px 6px;
  margin: 8px 0;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
}
.daily-quest-name { grid-area: name; font-weight: 600; }
.daily-quest-meta {
  grid-area: meta;
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.daily-quest-bar {
  grid-area: bar;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}
.daily-quest-fill {
  height: 100%;
  background: linear-gradient(90deg, #a855f7, #f472b6);
  transition: width 0.3s ease;
}
.daily-quest-row.ready .daily-quest-fill {
  background: linear-gradient(90deg, #fbbf24, #fde68a);
}
.daily-quest-row.claimed { opacity: 0.5; }
.daily-quest-claim {
  grid-area: claim;
  width: 100%;
  margin-top: 4px;
}
.daily-quest-claim:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Friends online dot ---------- */
.friend-online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
  margin-right: 6px;
  vertical-align: middle;
  animation: friend-pulse 2s ease-in-out infinite;
}
@keyframes friend-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ---------- Visual pass: keyboard-first race presentation ---------- */

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent 75%);
}

.panel {
  position: relative;
  isolation: isolate;
  box-shadow: 0 24px 70px rgba(15, 5, 30, 0.32), 0 5px 0 rgba(124, 58, 237, 0.16);
}

.lobby-play,
.lobby-character {
  position: relative;
}

.lobby-play::before,
.lobby-character::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.lobby-character {
  box-shadow: inset 0 0 0 1px rgba(124, 58, 237, 0.08), 0 12px 30px rgba(124, 58, 237, 0.1);
}

.lobby-chips {
  margin-top: 14px;
}

.chip {
  background: linear-gradient(135deg, #eef2ff, #fdf2f8);
  border-color: #ddd6fe;
  color: #5b21b6;
}

.btn,
.mode-btn,
.difficulty-btn,
.color-swatch {
  will-change: transform;
}

.btn:hover,
.mode-btn:hover,
.difficulty-btn:hover {
  transform: translateY(-1px);
}

.btn:active,
.mode-btn:active,
.difficulty-btn:active {
  transform: translateY(1px) scale(0.98);
}

/* Race HUD: a dark floating layer stays legible over every themed map. */
#hud::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 8, 22, 0.38), transparent 24%),
    linear-gradient(0deg, rgba(5, 8, 22, 0.34), transparent 28%);
}

.hud-top {
  position: relative;
  z-index: 3;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud-group-right {
  justify-content: flex-end;
}

.pill {
  border: 1px solid var(--hud-border);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(49, 46, 129, 0.78));
  color: var(--hud-ink);
  box-shadow: 0 10px 26px rgba(2, 6, 23, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  text-shadow: 0 1px 2px rgba(2, 6, 23, 0.6);
}

.timer-pill {
  min-width: 86px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.position-pill {
  background: linear-gradient(135deg, color-mix(in srgb, var(--race-accent) 72%, #0f172a), rgba(15, 23, 42, 0.92));
  border-color: color-mix(in srgb, var(--race-accent) 70%, white 20%);
  font-size: 1.05rem;
  min-width: 78px;
  text-align: center;
}

.map-pill {
  background: rgba(15, 23, 42, 0.78);
  color: #e0e7ff;
  border-color: rgba(224, 231, 255, 0.24);
}

.stage-pill {
  border-color: rgba(251, 191, 36, 0.72);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.powerup-hud {
  top: 72px;
  z-index: 4;
  min-height: 44px;
  padding: 7px 14px;
  border-color: var(--race-accent);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.9));
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.32), 0 0 22px color-mix(in srgb, var(--race-accent) 35%, transparent);
}

.powerup-icon {
  filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--race-accent) 72%, transparent));
}

.powerup-label {
  letter-spacing: 0.01em;
}

.powerup-timer {
  color: #cbd5e1;
  font-weight: 700;
}

.powerup-hud.powerup-ready {
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.32), 0 0 28px color-mix(in srgb, var(--race-accent) 45%, transparent);
}

.powerup-hud.powerup-ready::after {
  content: "E to use";
  margin-left: 3px;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hud-bottom {
  bottom: 22px;
  z-index: 3;
  width: min(520px, 54vw);
  gap: 9px;
}

.progress-wrap {
  height: 13px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(15, 23, 42, 0.7);
  box-shadow: 0 8px 22px rgba(2, 6, 23, 0.22), inset 0 1px 3px rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(8px);
}

.progress-bar {
  background: linear-gradient(90deg, var(--race-accent), #f472b6 62%, #fbbf24);
  box-shadow: 0 0 12px color-mix(in srgb, var(--race-accent) 58%, transparent);
}

.hint {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.2);
  backdrop-filter: blur(10px);
}

.race-controls-hint {
  position: absolute;
  left: 22px;
  bottom: 22px;
  z-index: 3;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.68);
  color: rgba(248, 250, 252, 0.9);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 22px rgba(2, 6, 23, 0.18);
  backdrop-filter: blur(10px);
}

.race-controls-hint kbd {
  padding: 2px 5px;
  margin-right: 3px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font-size: 0.68rem;
}

.minimap-wrap {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 132px;
  padding: 7px 6px 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.76);
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px) saturate(1.15);
  pointer-events: none;
}

.minimap-label {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 3px 4px;
  color: rgba(241, 245, 249, 0.78);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.minimap-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--race-accent);
  box-shadow: 0 0 8px var(--race-accent);
}

.minimap {
  position: static;
  display: block;
  width: 120px;
  height: 120px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
}

.minimap-legend {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 3px 0;
  color: rgba(226, 232, 240, 0.65);
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.minimap-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.minimap-legend i {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.legend-you { background: #fff; box-shadow: 0 0 5px rgba(255, 255, 255, 0.9); }
.legend-racer { background: #94a3b8; }

.toast {
  border-color: rgba(255, 255, 255, 0.24);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(49, 46, 129, 0.94));
  color: #f8fafc;
  box-shadow: 0 16px 36px rgba(2, 6, 23, 0.3);
}

@media (min-width: 900px) and (pointer: fine) {
  .screen { padding: 24px; }

  #touch-controls {
    display: none !important;
  }

  .lobby-panel {
    width: min(1040px, calc(100vw - 48px));
  }

  .hud-top {
    padding: 20px 24px;
  }

  .race-controls-hint {
    display: flex;
  }

  .minimap-wrap {
    top: 94px;
    right: 22px;
    width: 176px;
    padding: 9px 9px 8px;
  }

  .minimap {
    width: 156px;
    height: 156px;
  }

  .minimap-label {
    font-size: 0.68rem;
  }

  .minimap-legend {
    font-size: 0.62rem;
  }

  .hud-bottom {
    bottom: 24px;
  }
}

@media (max-width: 899px), (pointer: coarse) {
  .hud-top {
    padding: 10px 12px;
    gap: 6px;
  }

  .hud-group { gap: 5px; }
  .pill { padding: 7px 10px; font-size: 0.86rem; }
  .map-pill { max-width: 34vw; }
  .position-pill { min-width: 65px; }
  .powerup-hud { top: 54px; max-width: 78vw; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .btn:hover,
  .mode-btn:hover,
  .difficulty-btn:hover,
  .shop-item:hover {
    transform: none;
  }
}

/* ---------- Lobby redesign: make the bean the hero ---------- */

.screen-lobby {
  position: absolute;
}

.screen-lobby::after {
  content: "";
  position: absolute;
  width: 48vw;
  height: 48vw;
  max-width: 680px;
  max-height: 680px;
  left: -14vw;
  bottom: -30vw;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(236, 72, 153, 0.32), rgba(236, 72, 153, 0) 68%);
  filter: blur(8px);
}

.lobby-panel {
  z-index: 1;
}

.field-heading {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5b21b6;
}

.mode-row-3 {
  gap: 10px;
}

#screen-lobby .mode-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding: 9px 10px;
  text-align: left;
  color: var(--ink);
  border-color: #ddd6fe;
  background: linear-gradient(155deg, #ffffff, #f5f3ff);
  box-shadow: 0 3px 0 rgba(124, 58, 237, 0.08);
  transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

#screen-lobby .mode-btn.active {
  color: #fff;
  border-color: #6d28d9;
  background: linear-gradient(145deg, #8b5cf6, #6d28d9);
  box-shadow: 0 5px 0 rgba(76, 29, 149, 0.28), 0 10px 22px rgba(124, 58, 237, 0.2);
}

#screen-lobby .mode-btn:hover {
  border-color: #a78bfa;
  box-shadow: 0 5px 0 rgba(124, 58, 237, 0.13), 0 8px 18px rgba(124, 58, 237, 0.12);
}

#screen-lobby .mode-btn.active:hover {
  border-color: #5b21b6;
}

.mode-btn-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 10px;
  background: #ede9fe;
  font-size: 1.05rem;
}

.mode-btn.active .mode-btn-icon {
  background: rgba(255, 255, 255, 0.18);
}

.mode-btn-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
}

.mode-btn-copy strong {
  font-size: 0.85rem;
  line-height: 1.1;
  white-space: nowrap;
}

.mode-btn-copy small {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.15;
  white-space: normal;
}

.mode-btn.active .mode-btn-copy small {
  color: rgba(255, 255, 255, 0.76);
}

.play-zone {
  margin-top: 18px;
  padding: 12px 12px 10px;
  border: 1px solid #fde68a;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 251, 235, 0.92), rgba(254, 243, 199, 0.62));
}

.play-kicker {
  display: block;
  margin-bottom: 2px;
  color: #92400e;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.play-zone .btn.primary.big {
  margin-top: 6px;
}

.lobby-preview-stage {
  min-height: 220px;
  border-color: rgba(255, 255, 255, 0.8);
  background:
    radial-gradient(circle at 50% 58%, rgba(255, 255, 255, 0.45), transparent 26%),
    radial-gradient(circle at 50% 100%, rgba(76, 29, 149, 0.26), transparent 55%),
    linear-gradient(155deg, #ddd6fe 0%, #a78bfa 48%, #6d28d9 100%);
  box-shadow: inset 0 -26px 36px rgba(76, 29, 149, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 12px 26px rgba(124, 58, 237, 0.14);
}

.lobby-preview-stage::before {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 16px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(30, 20, 50, 0.32), rgba(30, 20, 50, 0) 70%);
  filter: blur(4px);
  pointer-events: none;
}

.lobby-preview-stage::after {
  content: "✦  ✦  ✦";
  position: absolute;
  top: 18px;
  right: 20px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.68rem;
  letter-spacing: 0.7em;
  pointer-events: none;
}

.lobby-stage-kicker {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 2;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 999px;
  background: rgba(49, 46, 129, 0.42);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.lobby-character .account-bar {
  justify-content: flex-start;
  margin: 10px 0 12px;
  padding: 8px 12px;
  border-color: #ddd6fe;
  background: rgba(255, 255, 255, 0.68);
}

.lobby-meta {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 14px;
}

.lobby-meta .hidden {
  display: none !important;
}

.lobby-recent-card,
.lobby-daily-card {
  margin: 0;
  border: 1px solid #ddd6fe;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(245, 243, 255, 0.88));
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.08);
}

.lobby-recent-title,
.lobby-daily-title {
  color: #6d28d9;
}

.lobby-recent-sub,
.daily-quest-meta {
  color: var(--muted);
}

.lobby-recent-place {
  color: #b45309;
}

.daily-quest-row {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(221, 214, 254, 0.8);
}

.daily-quest-bar {
  background: #e9d5ff;
}

@media (min-width: 900px) and (pointer: fine) {
  .lobby-panel {
    width: min(1040px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #c4b5fd transparent;
  }

  .lobby-layout {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 28px;
  }

  .lobby-play {
    padding: 4px 2px 2px;
  }

  .logo-compact {
    margin-bottom: 16px;
  }

  .logo-compact .logo-bean {
    font-size: 2.05rem;
  }

  .logo-compact h1 {
    font-size: 2.15rem;
  }

  #lobby-preview {
    height: 300px;
  }

  .lobby-preview-stage {
    min-height: 320px;
  }

  .lobby-character {
    padding: 18px 18px 18px;
  }

  .lobby-shop-btn {
    margin-top: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-preview-stage::after {
    content: "✦";
    letter-spacing: 0;
  }
}

/* ---------- Laptop release controls ---------- */

.mode-row-5 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.mode-row-5 .mode-btn:nth-child(-n + 3) {
  grid-column: span 2;
}

.mode-row-5 .mode-btn:nth-child(n + 4) {
  grid-column: span 3;
}

.field select {
  width: 100%;
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 11px 36px 11px 12px;
  border: 2px solid #e9d5ff;
  border-radius: 13px;
  background: #faf5ff;
  color: var(--ink);
}

.field select:focus-visible {
  border-color: var(--primary);
}

.lobby-meta-disclosure {
  margin-top: 12px;
  border: 1px solid #ddd6fe;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.58);
}

.lobby-meta-disclosure summary {
  padding: 10px 12px;
  color: #6d28d9;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.lobby-meta-disclosure[open] summary {
  border-bottom: 1px solid #e9d5ff;
}

.lobby-meta-disclosure .lobby-meta {
  margin: 0;
  padding: 10px;
}

.settings-panel {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}

.keybind-field {
  margin: 14px 0;
  padding: 12px;
  border: 2px solid #ede9fe;
  border-radius: 14px;
}

.keybind-field legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.keybind-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 12px;
}

.keybind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 600;
}

.keybind-btn {
  min-width: 86px;
  padding: 6px 8px;
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  background: #f5f3ff;
  color: #5b21b6;
  font: 700 0.72rem var(--font);
  cursor: pointer;
}

.keybind-btn.listening {
  border-color: var(--accent);
  background: #fef3c7;
  color: #92400e;
}

.focus-screen,
.pause-screen {
  z-index: 90;
  pointer-events: auto !important;
  background: rgba(15, 5, 30, 0.45) !important;
  backdrop-filter: blur(3px);
}

.focus-card {
  display: flex;
  min-width: min(390px, calc(100vw - 36px));
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 24px 28px;
  border: 2px solid rgba(255, 255, 255, 0.74);
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  box-shadow: 0 20px 55px rgba(2, 6, 23, 0.45);
  font-family: var(--font);
  cursor: pointer;
}

.focus-card strong {
  font-size: 1.2rem;
}

.focus-card small {
  color: #cbd5e1;
}

.focus-icon {
  font-size: 2rem;
}

.pause-panel {
  width: min(360px, 100%);
  text-align: center;
}

.pause-actions {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.btn.danger {
  background: #fee2e2;
  color: #991b1b;
  border: 2px solid #fecaca;
  box-shadow: none;
}

.delta-pill {
  min-width: 78px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.delta-pill.ahead {
  border-color: rgba(74, 222, 128, 0.7);
  background: rgba(20, 83, 45, 0.88);
}

.delta-pill.behind {
  border-color: rgba(251, 113, 133, 0.7);
  background: rgba(127, 29, 29, 0.88);
}

.target-hint {
  position: absolute;
  top: 72px;
  left: 50%;
  z-index: 5;
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid rgba(147, 197, 253, 0.55);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  color: #dbeafe;
  font-size: 0.78rem;
  font-weight: 700;
}

body.high-contrast {
  --hud-surface: rgba(0, 0, 0, 0.94);
  --hud-surface-strong: #000;
  --hud-border: rgba(255, 255, 255, 0.72);
  --hud-ink: #fff;
}

body.high-contrast .pill,
body.high-contrast .minimap-wrap,
body.high-contrast .hint,
body.high-contrast .race-controls-hint {
  background: #000;
  border-color: rgba(255, 255, 255, 0.78);
  backdrop-filter: none;
}

@media (max-height: 820px) and (min-width: 900px) and (pointer: fine) {
  .screen {
    padding: 14px;
  }

  .lobby-panel {
    max-height: calc(100vh - 28px);
  }

  #lobby-preview {
    height: 230px;
  }

  .lobby-preview-stage {
    min-height: 250px;
  }

  .logo-compact {
    margin-bottom: 10px;
  }

  .play-zone {
    margin-top: 10px;
  }
}

@media (max-width: 760px) {
  .mode-row-5 {
    grid-template-columns: 1fr 1fr;
  }

  .mode-row-5 .mode-btn {
    grid-column: auto !important;
  }

  .mode-row-5 .mode-btn:last-child {
    grid-column: 1 / -1 !important;
  }

  .keybind-grid {
    grid-template-columns: 1fr;
  }
}
