/* ============================================================
   Moto Racer — Styles
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ============================================================
   HUD — Top bar
   ============================================================ */
#hud {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
  color: #fff;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  font-size: 14px;
}

#hud-left, #hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#hud-lap {
  font-size: 20px;
  font-weight: bold;
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 6px;
}

#hud-position {
  font-size: 18px;
  font-weight: bold;
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 6px;
  color: #fff;
}

#hud-speed {
  font-size: 24px;
  font-weight: bold;
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

#hud-fps {
  font-size: 12px;
  font-weight: 600;
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 6px;
  color: #4fc3f7;
  font-variant-numeric: tabular-nums;
}

#hud-turbo-container {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 6px;
}

#hud-turbo-label {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  color: #aaf;
}

#hud-turbo-bar {
  width: 80px;
  height: 10px;
  background: rgba(255,255,255,0.2);
  border-radius: 5px;
  overflow: hidden;
}

#hud-turbo {
  width: 0%;
  height: 100%;
  background: #44aaff;
  border-radius: 5px;
  transition: width 0.1s;
}

/* ============================================================
   Camera Mode Pill (HUD) — clickable to cycle views (V key)
   ============================================================ */
.cam-mode-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
  cursor: pointer;
  pointer-events: auto;        /* pill is clickable even though HUD is pointer-events:none */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.1s ease;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.cam-mode-pill:hover {
  background: rgba(40, 40, 40, 0.7);
  border-color: rgba(255, 255, 255, 0.35);
}

.cam-mode-pill:active {
  transform: scale(0.96);
  background: rgba(60, 60, 60, 0.75);
}

/* Per-mode tint on the pill icon so the player can tell at a glance. */
.cam-mode-pill[data-mode="chase"]   .cam-mode-icon { color: #88ccff; }
.cam-mode-pill[data-mode="cockpit"] .cam-mode-icon { color: #ff8866; }
.cam-mode-pill[data-mode="far"]     .cam-mode-icon { color: #bb88ff; }

.cam-mode-icon {
  font-size: 14px;
  line-height: 1;
}

.cam-mode-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
}

/* ============================================================
   Camera Mode Toast — centered overlay shown briefly when mode changes
   ============================================================ */
#cam-mode-toast {
  position: fixed;
  top: 28%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 35;
  pointer-events: none;
  text-align: center;
  background: rgba(0, 0, 0, 0.65);
  padding: 18px 36px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(255, 255, 255, 0.04);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  color: #fff;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
  min-width: 200px;
}

#cam-mode-toast.cmt-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#cam-mode-toast .cmt-icon {
  font-size: 38px;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

#cam-mode-toast .cmt-label {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
}

#cam-mode-toast .cmt-desc {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 6px;
  letter-spacing: 0.5px;
  max-width: 260px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================
   Cockpit Visor Overlay — tinted gradient on edges to simulate
   the rider's helmet/windscreen. Center stays clear so gameplay
   isn't obstructed.
   ============================================================ */
#cockpit-visor {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  /* Radial gradient: clear in the center (40-60%), darker amber/brown
     vignette toward the edges. We use a multi-stop radial that creates
     a soft "tunnel vision" effect like a tinted visor. */
  background:
    radial-gradient(
      ellipse 70% 60% at 50% 55%,
      transparent 0%,
      transparent 35%,
      rgba(80, 50, 20, 0.18) 60%,
      rgba(50, 30, 10, 0.45) 85%,
      rgba(20, 10, 0, 0.65) 100%
    );
}

#cockpit-visor.visible {
  opacity: 1;
}

/* A faint helmet/visor frame on top — a curved silhouette at the top
   of the screen suggesting the visor brim. Pure CSS, no images. */
#cockpit-visor::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  background:
    linear-gradient(180deg,
      rgba(20, 10, 0, 0.55) 0%,
      rgba(40, 25, 10, 0.35) 40%,
      transparent 100%
    );
  /* Curved bottom edge — soft fadeout to transparent using mask */
  -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
}

/* Subtle helmet-bottom curve at the screen bottom — the chin bar. */
#cockpit-visor::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 90px;
  background:
    linear-gradient(0deg,
      rgba(20, 10, 0, 0.55) 0%,
      rgba(40, 25, 10, 0.30) 40%,
      transparent 100%
    );
  -webkit-mask-image: linear-gradient(0deg, #000 0%, transparent 100%);
  mask-image: linear-gradient(0deg, #000 0%, transparent 100%);
}

/* On mobile, slightly tighter visor so it doesn't crowd the HUD too much. */
@media (pointer: coarse) {
  #cam-mode-toast {
    padding: 14px 24px;
    min-width: 160px;
  }
  #cam-mode-toast .cmt-icon { font-size: 30px; }
  #cam-mode-toast .cmt-label { font-size: 18px; }
}

/* ============================================================
   HUD — Race Timer & Lap Time Display
   ============================================================ */
#hud-race-time {
  font-size: 22px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,0.5);
  padding: 2px 14px;
  border-radius: 6px;
  letter-spacing: 1px;
  color: #fff;
}

#hud-lap-time {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,0.4);
  padding: 1px 10px;
  border-radius: 4px;
  color: #88ccff;
}

#hud-lap-time.best-lap {
  color: #44ff44;
}

#hud-lap-time.ahead {
  color: #44ff44;
}

#hud-lap-time.behind {
  color: #ff8844;
}

/* ============================================================
   Lap Time Notification Popup
   ============================================================ */
#lap-time-notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.3s ease;
  opacity: 0;
}

#lap-time-notification.visible {
  opacity: 1;
}

#lap-time-notification .ltn-time {
  font-size: 42px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 20px rgba(255,255,255,0.3), 2px 2px 4px rgba(0,0,0,0.8);
}

#lap-time-notification .ltn-label {
  font-size: 18px;
  font-weight: 600;
  color: #ffdd44;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  margin-top: 4px;
}

#lap-time-notification .ltn-best {
  font-size: 16px;
  font-weight: 600;
  color: #44ff44;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  margin-top: 2px;
}

/* ============================================================
   Sector Time Display — 3 cells (S1/S2/S3) under the race timer.
   The live (currently-in-progress) sector pulses a purple glow.
   Completed sectors freeze in their time; new bests get a star
   and turn bright purple. The "behind" class tints red if slower
   than the player's all-time best for that sector on this track.
   ============================================================ */
#hud-sectors {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px 6px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  margin-top: 2px;
}

#hud-sectors .hs-cell {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: #888;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  min-width: 64px;
  justify-content: center;
}

#hud-sectors .hs-cell .hs-label {
  font-weight: 700;
  font-size: 10px;
  color: inherit;
  opacity: 0.75;
}

#hud-sectors .hs-cell .hs-time {
  font-weight: 600;
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.3px;
}

/* Live (in-progress) sector: pulsing purple glow */
#hud-sectors .hs-cell.hs-live {
  background: rgba(160, 80, 255, 0.15);
  color: #cfa0ff;
  box-shadow: 0 0 0 1px rgba(160, 80, 255, 0.5);
  animation: hs-pulse 1.4s ease-in-out infinite;
}

@keyframes hs-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(160, 80, 255, 0.4); }
  50%      { box-shadow: 0 0 0 2px rgba(160, 80, 255, 0.8), 0 0 12px rgba(160, 80, 255, 0.4); }
}

/* Completed sector with a new personal best */
#hud-sectors .hs-cell.hs-best {
  background: rgba(160, 80, 255, 0.25);
  color: #e0b8ff;
  box-shadow: 0 0 0 1px rgba(160, 80, 255, 0.7);
}
#hud-sectors .hs-cell.hs-best .hs-time::after {
  content: ' ⭐';
  color: #ffd700;
}

/* Completed sector that was slower than best */
#hud-sectors .hs-cell.hs-slower .hs-time {
  color: #ff8c8c;
}

/* ============================================================
   Sector notification popup (S1/S2/S3 split) — top-center, just
   below the HUD. Purple-themed to match the sector HUD cells.
   ============================================================ */
#sector-notification {
  position: fixed;
  top: 110px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 30;
  pointer-events: none;
  text-align: center;
  padding: 10px 28px;
  background: rgba(20, 10, 40, 0.85);
  border: 2px solid rgba(160, 80, 255, 0.6);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(160, 80, 255, 0.3);
  color: #fff;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#sector-notification.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#sector-notification.best {
  border-color: #ffd700;
  box-shadow: 0 4px 24px rgba(255, 215, 0, 0.5);
  background: rgba(50, 30, 80, 0.92);
}

#sector-notification .sn-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #cfa0ff;
  margin-bottom: 2px;
}

#sector-notification.best .sn-label {
  color: #ffd700;
}

#sector-notification .sn-time {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(160, 80, 255, 0.4);
}

#sector-notification .sn-best {
  font-size: 14px;
  font-weight: 700;
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
  margin-top: 2px;
  letter-spacing: 1px;
}

#sector-notification .sn-delta {
  font-size: 12px;
  font-weight: 600;
  color: #ff8c8c;
  margin-top: 2px;
  letter-spacing: 0.5px;
}

/* ============================================================
   Sector splits row on the race results screen
   ============================================================ */
.results-sectors {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: #ccc;
}

.results-sectors .rs-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  min-width: 72px;
}

.results-sectors .rs-cell .rs-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #888;
  text-transform: uppercase;
}

.results-sectors .rs-cell .rs-time {
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.results-sectors .rs-cell.rs-best {
  background: rgba(160, 80, 255, 0.18);
}
.results-sectors .rs-cell.rs-best .rs-time::after {
  content: ' ⭐';
  color: #ffd700;
}
.results-sectors .rs-cell.rs-best .rs-label {
  color: #cfa0ff;
}
.results-sectors .rs-cell.rs-empty .rs-time {
  color: #555;
}

/* ============================================================
   Minimap — Top right (small, doesn't block view)
   ============================================================ */
#minimap {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 140px;
  height: 140px;
  background: rgba(0,0,0,0.7);
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  overflow: hidden;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#minimap canvas {
  width: 100%;
  height: 100%;
}

/* ============================================================
   Mobile Touch Controls
   ============================================================ */
#touch-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: none; /* shown by game.js on touch devices */
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px 16px 24px;
  z-index: 20;
  pointer-events: none;
}

#touch-controls > div {
  display: flex;
  pointer-events: auto;
}

.tc-left {
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.tc-right {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

.tc-btn {
  width: 64px;
  height: 64px;
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 12px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.tc-btn:active {
  background: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.7);
}

.tc-btn-wide {
  width: 72px;
  height: 64px;
  font-size: 11px;
  line-height: 1.2;
}

.tc-btn-turbo {
  width: 56px;
  height: 56px;
  font-size: 22px;
  border-color: rgba(255,200,0,0.5);
  background: rgba(255,200,0,0.12);
  color: #ffdd44;
}

.tc-btn-turbo:active {
  background: rgba(255,200,0,0.3);
  border-color: #ffdd44;
}

/* ============================================================
   Media queries for mobile detection
   ============================================================ */
@media (pointer: coarse) {
  #touch-controls {
    display: flex !important;
    padding: 10px 12px 20px;
  }
  #hud {
    font-size: 13px;
  }
  #hud-speed {
    font-size: 22px;
  }
  /* On mobile, the touch controls occupy the bottom strip, so put the
     minimap in the top-left where it doesn't overlap anything. */
  #minimap {
    width: 120px;
    height: 120px;
    top: 60px;
    left: 10px;
    right: auto;
    bottom: auto;
  }
  .tc-btn {
    width: 84px;
    height: 84px;
    font-size: 22px;
  }
  .tc-btn-wide {
    width: 96px;
    height: 84px;
    font-size: 12px;
  }
  .tc-btn-turbo {
    width: 76px;
    height: 76px;
    font-size: 22px;
  }
  #hud-race-time {
    font-size: 18px;
    padding: 2px 10px;
  }

  #hud-lap-time {
    font-size: 12px;
    padding: 1px 8px;
  }

  /* Sector row stays compact on mobile — drop the per-cell padding */
  #hud-sectors {
    font-size: 10px;
    padding: 2px 4px;
  }
  #hud-sectors .hs-cell {
    min-width: 52px;
    padding: 2px 4px;
  }
  #hud-sectors .hs-cell .hs-time {
    font-size: 10px;
  }
  #hud-sectors .hs-cell .hs-label {
    font-size: 9px;
  }
}

/* ============================================================
   Speed lines overlay (Section 3.5)
   ============================================================ */
#speed-lines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.1s linear;
  overflow: hidden;
}

#speed-lines.visible {
  opacity: 1;
}

#speed-lines .speed-line {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  background: rgba(255, 255, 255, 0.3);
  transform-origin: 0 0;
  border-radius: 1px;
}

/* ============================================================
   Track picker (Section 5.4)
   ============================================================ */
.setup-track-picker {
  width: 340px;
  margin-bottom: 20px;
}

.track-picker-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #aaa;
  margin-bottom: 10px;
  text-align: center;
}

.track-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.track-card {
  background: rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.track-card:hover {
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-2px);
}

.track-card.selected {
  border-color: #4fc3f7;
  background: rgba(79, 195, 247, 0.15);
}

.track-card .track-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.track-card .track-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 2px;
}

.track-card .track-time {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.track-card .track-swatch {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  margin-top: 8px;
}

#boost-tint {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
  background: radial-gradient(circle at center, rgba(255, 80, 0, 0.12), transparent 70%);
  opacity: 0;
  transition: opacity 0.2s ease-out;
}

#boost-tint.active {
  opacity: 1;
}

#vignette {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(circle, transparent 50%, rgba(0,0,0,0.35) 100%);
}

/* ============================================================
   Loading screen
   ============================================================ */
#loading {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  font-size: 24px;
  transition: opacity 0.5s;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: #4fc3f7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Screen Overlays (Menu, Setup, Results)
   ============================================================ */
.screen-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  color: #fff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  transition: opacity 0.4s ease;
  pointer-events: auto;
}

.screen-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   Main Menu
   ============================================================ */
#menu-overlay .menu-title {
  font-size: 52px;
  font-weight: 800;
  margin-bottom: 4px;
  text-shadow: 0 0 30px rgba(79, 195, 247, 0.4);
  letter-spacing: 2px;
}

#menu-overlay .menu-subtitle {
  font-size: 18px;
  color: #88ccff;
  margin-bottom: 40px;
  letter-spacing: 4px;
  text-transform: uppercase;
  opacity: 0.8;
}

.menu-coins {
  font-size: 16px;
  color: #ffd700;
  margin-bottom: 20px;
  background: rgba(255,215,0,0.1);
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255,215,0,0.2);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.menu-btn {
  width: 240px;
  padding: 14px 24px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-family: inherit;
}

.menu-btn:hover {
  background: rgba(79, 195, 247, 0.2);
  border-color: #4fc3f7;
  transform: scale(1.03);
}

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

.menu-btn.primary {
  background: linear-gradient(135deg, #4fc3f7, #1a73e8);
  border-color: transparent;
  font-size: 20px;
  padding: 16px 30px;
}

.menu-btn.primary:hover {
  background: linear-gradient(135deg, #64d8ff, #2b8af0);
  border-color: transparent;
}

.menu-btn.small {
  width: 180px;
  padding: 10px 18px;
  font-size: 15px;
}

.controls-panel {
  margin-top: 24px;
  padding: 16px 24px;
  background: rgba(0,0,0,0.4);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  max-width: 400px;
  font-size: 14px;
  line-height: 1.8;
  display: none;
}

.controls-panel.visible {
  display: block;
}

.controls-panel kbd {
  background: rgba(255,255,255,0.12);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ============================================================
   Bike Setup
   ============================================================ */
#setup-overlay .setup-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 24px;
}

.setup-bike-card {
  background: rgba(0,0,0,0.4);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 24px;
  width: 340px;
  margin-bottom: 20px;
}

.setup-bike-card .bike-color-bar {
  height: 6px;
  border-radius: 3px;
  margin-bottom: 16px;
}

.setup-bike-card .bike-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.setup-bike-card .rarity-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.rarity-common { background: #556677; color: #aabbcc; }
.rarity-uncommon { background: #1a6b4a; color: #4ecca3; }
.rarity-rare { background: #1a3a7a; color: #5b8def; }
.rarity-legendary { background: #5a3a0a; color: #f0c040; }

.stat-bar-container {
  margin-bottom: 12px;
}

.stat-bar-container .stat-label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 4px;
  color: #ccc;
}

.stat-bar-container .stat-label .stat-name {
  font-weight: 600;
}

.stat-bar-container .stat-label .stat-val {
  color: #fff;
}

.stat-bar-track {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  background: linear-gradient(90deg, #ff4444, #ffaa00, #44cc44);
}

.setup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.setup-no-bike {
  text-align: center;
  color: #aaa;
  padding: 20px;
  font-size: 16px;
  margin-bottom: 16px;
}

/* ============================================================
   Race Results
   ============================================================ */
#results-overlay .results-title {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
  text-shadow: 0 0 20px rgba(255,215,0,0.3);
}

.results-subtitle {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 24px;
}

.results-position {
  font-size: 48px;
  font-weight: 800;
  margin-bottom: 20px;
}

.results-position.gold { color: #ffd700; }
.results-position.silver { color: #c0c0c0; }
.results-position.other { color: #fff; }

.results-podium {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 24px;
  justify-content: center;
}

.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90px;
  padding: 12px 8px 8px;
  border-radius: 12px 12px 0 0;
  text-align: center;
}

.podium-step .podium-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.podium-step .podium-pos {
  font-size: 22px;
  font-weight: 800;
}

.podium-1 { background: rgba(255,215,0,0.25); height: 120px; border: 1px solid rgba(255,215,0,0.3); }
.podium-2 { background: rgba(192,192,192,0.2); height: 90px; border: 1px solid rgba(192,192,192,0.3); }
.podium-3 { background: rgba(205,127,50,0.2); height: 70px; border: 1px solid rgba(205,127,50,0.3); }

.results-coins {
  background: rgba(255,215,0,0.1);
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #ffd700;
}

.results-times {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 15px;
  color: #ccc;
  margin-bottom: 16px;
  background: rgba(0,0,0,0.3);
  padding: 10px 24px;
  border-radius: 8px;
}

.results-times span {
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* ============================================================
   HUD bike stats flash
   ============================================================ */
#hud-bike-stats {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  background: rgba(0,0,0,0.6);
  padding: 8px 16px;
  border-radius: 10px;
  z-index: 11;
  font-size: 12px;
  color: #ccc;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}

#hud-bike-stats.visible {
  opacity: 1;
}

#hud-bike-stats .hbs-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

#hud-bike-stats .hbs-item .hbs-label {
  color: #888;
}

#hud-bike-stats .hbs-item .hbs-value {
  font-weight: 600;
  color: #4fc3f7;
}

/* ============================================================
   Results transition delay overlay
   ============================================================ */
#race-transition {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}

#race-transition.visible {
  opacity: 1;
}

/* ============================================================
 * GARAGE UI (adapted from portal bike-garage)
 * ============================================================ */

/* Hidden overlay toggle */
.hidden {
  display: none !important;
}

/* Garage container */
#garage-overlay.screen-overlay {
  overflow-y: auto;
  z-index: 100;
  justify-content: flex-start;
  align-items: flex-start;
  display: block;
}
.garage-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
}

.garage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding: 20px 20px 0;
  width: 100%;
}
.garage-header-left {
  min-width: 80px;
}
.garage-header-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Coin display */
.coin-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 1.1rem;
  font-weight: 700;
}
.coin-icon {
  font-size: 1.3rem;
}
.coin-amount {
  color: #e94560;
  min-width: 60px;
  text-align: right;
}

/* --- Toolbar --- */
.garage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border: 1px solid #2a2a4a;
  border-radius: 20px;
  background: transparent;
  color: #a0a0b8;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover {
  border-color: #e94560;
  color: #e94560;
}
.filter-btn.active {
  background: #e94560;
  border-color: #e94560;
  color: white;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #a0a0b8;
  font-size: 0.85rem;
}

.sort-controls select {
  padding: 6px 12px;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  background: #0f0f1a;
  color: #eee;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}
.sort-controls select:focus {
  border-color: #e94560;
}

/* --- Bike Grid --- */
.bike-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding-bottom: 40px;
}

/* Bike Card */
.bike-card {
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}
.bike-card:hover {
  transform: translateY(-3px);
  border-color: #e94560;
  box-shadow: 0 6px 24px rgba(233, 69, 96, 0.12);
}

.bike-color-bar {
  height: 6px;
  width: 100%;
}

.bike-card-body {
  padding: 14px;
}

.bike-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #eee;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Rarity badges */
.rarity-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.rarity-common { background: rgba(136, 153, 170, 0.2); color: #8899aa; }
.rarity-uncommon { background: rgba(78, 204, 163, 0.2); color: #4ecca3; }
.rarity-rare { background: rgba(91, 141, 239, 0.2); color: #5b8def; }
.rarity-legendary { background: rgba(240, 192, 64, 0.2); color: #f0c040; }

/* Stat bars */
.bike-stats { margin: 10px 0; }

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #a0a0b8;
  width: 36px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.stat-bar-bg {
  flex: 1;
  height: 8px;
  background: #0f0f1a;
  border-radius: 4px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.stat-speed { background: linear-gradient(90deg, #e94560, #ff6b81); }
.stat-accel { background: linear-gradient(90deg, #5b8def, #7aa5ff); }
.stat-handling { background: linear-gradient(90deg, #4ecca3, #7ee8b7); }

.stat-value {
  font-size: 0.75rem;
  font-weight: 700;
  color: #eee;
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* Card footer */
.bike-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #2a2a4a;
}

.bike-price {
  font-size: 0.8rem;
  font-weight: 700;
  color: #e94560;
}

.selected-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(78, 204, 163, 0.2);
  color: #4ecca3;
  border: 1px solid #4ecca3;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.owned-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(78, 204, 163, 0.15);
  color: #4ecca3;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Small buttons in cards */
.btn-sm {
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-buy {
  background: #e94560;
  color: white;
}
.btn-buy:hover:not(:disabled) {
  background: #ff6b81;
}
.btn-buy:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-select {
  background: rgba(78, 204, 163, 0.2);
  color: #4ecca3;
  border: 1px solid #4ecca3;
}
.btn-select:hover {
  background: #4ecca3;
  color: white;
}
.btn-sell {
  background: rgba(233, 69, 96, 0.15);
  color: #e94560;
  border: 1px solid #e94560;
}
.btn-sell:hover {
  background: #e94560;
  color: white;
}

/* Detail Panel (overlay) */
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.detail-panel {
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: garageSlideUp 0.3s ease;
}

@keyframes garageSlideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #a0a0b8;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  line-height: 1;
}
.detail-close:hover { color: #eee; }

.detail-color-bar {
  height: 10px;
  width: 100%;
}

.detail-body { padding: 20px; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.detail-header h2 {
  font-size: 1.3rem;
  color: #eee;
}

.detail-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-stat { display: flex; flex-direction: column; gap: 4px; }

.detail-stat-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #a0a0b8;
}

.detail-stat .stat-bar-bg { height: 12px; }
.detail-stat .stat-value { font-size: 0.9rem; width: auto; }

.detail-info {
  background: #0f0f1a;
  border: 1px solid #2a2a4a;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.detail-price-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #a0a0b8;
  padding: 4px 0;
}
.detail-price-row span:last-child {
  color: #e94560;
  font-weight: 700;
}

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-actions .btn {
  flex: 1;
  min-width: 120px;
  justify-content: center;
}

/* Primary/secondary buttons in detail panel */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary {
  background: #e94560;
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: #ff6b81;
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-secondary {
  background: rgba(233, 69, 96, 0.15);
  color: #e94560;
  border: 1px solid #e94560;
}
.btn-secondary:hover {
  background: #e94560;
  color: white;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #a0a0b8;
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 600px) {
  .bike-grid {
    grid-template-columns: 1fr;
  }
  .garage-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-buttons {
    justify-content: center;
  }
  .detail-panel {
    max-width: 100%;
    border-radius: 12px;
    margin: 10px;
  }

  /* Mobile garage header: back button on its own row */
  .garage-header {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px 0 !important;
  }
  .garage-header-left {
    width: 100%;
    min-width: unset;
  }
  .garage-header-title {
    font-size: 1.1rem;
    text-align: center;
    flex: 1;
    margin-left: 0;
  }
  .coin-display {
    margin-left: auto;
    font-size: 0.9rem;
    padding: 4px 10px !important;
  }
}

/* ============================================================
   Countdown overlay (Red → Yellow → Green lights)
   ============================================================ */
#countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none; /* Allow clicks to pass through to game canvas */
  user-select: none;
}

.countdown-lights {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 24px;
  padding: 30px 40px;
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.countdown-light {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

/* Red */
.countdown-red {
  background: #330000;
  border-color: #550000;
}
.countdown-red.active {
  background: #ff0000;
  border-color: #ff4444;
  box-shadow: 0 0 40px rgba(255, 0, 0, 0.8), 0 0 80px rgba(255, 0, 0, 0.4);
}

/* Yellow */
.countdown-yellow {
  background: #332800;
  border-color: #554400;
}
.countdown-yellow.active {
  background: #ffcc00;
  border-color: #ffdd44;
  box-shadow: 0 0 40px rgba(255, 204, 0, 0.8), 0 0 80px rgba(255, 204, 0, 0.4);
}

/* Green */
.countdown-green {
  background: #003300;
  border-color: #005500;
}
.countdown-green.active {
  background: #00ff00;
  border-color: #44ff44;
  box-shadow: 0 0 40px rgba(0, 255, 0, 0.8), 0 0 80px rgba(0, 255, 0, 0.4);
}

/* Countdown number / GO! text */
.countdown-number {
  font-size: 4rem;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
  margin-top: 20px;
  text-align: center;
  transition: transform 0.3s ease;
}

.countdown-number.go-text {
  color: #00ff00;
  text-shadow: 0 0 40px rgba(0, 255, 0, 0.8), 0 0 80px rgba(0, 255, 0, 0.4);
  animation: goPulse 0.5s ease-in-out 3;
}

@keyframes goPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ============================================================
   Pause button — top right, visible during race
   ============================================================ */
#pause-btn {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.2s;
}
#pause-btn:active {
  background: rgba(255,255,255,0.25);
}
#pause-btn.hidden {
  display: none;
}

/* ============================================================
   Pause overlay — full-screen dark overlay with Resume/Quit
   ============================================================ */
.pause-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 1001;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pause-overlay.hidden {
  display: none;
}
.pause-title {
  font-size: 42px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 30px rgba(255,255,255,0.2);
  letter-spacing: 4px;
}
.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 220px;
}
.pause-menu-btn {
  font-size: 18px;
  padding: 14px 32px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.pause-menu-btn:active {
  background: rgba(255,255,255,0.2);
  transform: scale(0.97);
}
.pause-menu-btn.primary {
  background: #4fc3f7;
  color: #000;
  border-color: #4fc3f7;
  font-weight: 700;
}
.pause-menu-btn.primary:active {
  background: #39b0e4;
}
.pause-menu-btn:hover {
  border-color: rgba(255,255,255,0.4);
}

.portal-link {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

@media (pointer: coarse) {
  #pause-btn {
    width: 52px;
    height: 52px;
    font-size: 26px;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
  }
  .pause-title {
    font-size: 36px;
  }
  .pause-menu-btn {
    font-size: 20px;
    padding: 16px 36px;
  }
}

/* ============================================================
   Trophy System (Section: Achievement Cabinet)
   - Sliding top-right toast (#trophy-toast)
   - Modal overlay with backdrop (#trophy-modal / .trophy-panel)
   - Grid of trophy cards (.trophy-card)
   ============================================================ */

/* ---- Sliding toast (top-right) ---- */
#trophy-toast {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
  width: 320px;
  max-width: calc(100vw - 48px);
  background: linear-gradient(135deg, rgba(45,30,15,0.96), rgba(20,15,8,0.96));
  border: 2px solid #ffd54f;
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
  box-shadow: 0 8px 32px rgba(255,213,79,0.4), 0 0 24px rgba(255,213,79,0.2) inset;
  font-family: inherit;
  opacity: 0;
  transform: translateX(420px);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
  pointer-events: none;
}
#trophy-toast.visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
#trophy-toast .tt-icon {
  font-size: 44px;
  line-height: 1;
  animation: tt-icon-pulse 1.6s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(255,213,79,0.7));
}
@keyframes tt-icon-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18) rotate(-8deg); }
}
#trophy-toast .tt-body {
  flex: 1;
  min-width: 0;
}
#trophy-toast .tt-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffd54f;
  text-transform: uppercase;
}
#trophy-toast .tt-name {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
  margin-bottom: 4px;
}
#trophy-toast .tt-desc {
  font-size: 12px;
  color: rgba(255,255,255,0.78);
  line-height: 1.35;
}

/* ---- Modal: backdrop + panel ---- */
.trophy-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.trophy-modal.hidden { display: none; }
.trophy-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.trophy-panel {
  position: relative;
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: linear-gradient(180deg, #1c1810 0%, #0e0c08 100%);
  border: 2px solid #ffd54f;
  border-radius: 18px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.6), 0 0 40px rgba(255,213,79,0.15) inset;
  color: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: trophy-panel-in 0.35s ease-out;
}
@keyframes trophy-panel-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.trophy-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 22px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2;
  transition: background 0.2s, transform 0.2s;
}
.trophy-close:hover { background: rgba(255,80,80,0.4); transform: rotate(90deg); }

.trophy-header {
  padding: 22px 28px 16px;
  border-bottom: 1px solid rgba(255,213,79,0.18);
  text-align: center;
  background: linear-gradient(180deg, rgba(255,213,79,0.06) 0%, transparent 100%);
}
.trophy-title {
  font-size: 26px;
  font-weight: 800;
  color: #ffd54f;
  letter-spacing: 1px;
}
.trophy-subtitle {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin-top: 4px;
  margin-bottom: 14px;
}
.trophy-progress-wrap {
  max-width: 360px;
  margin: 0 auto;
}
.trophy-progress-text {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-bottom: 6px;
  font-weight: 600;
}
.trophy-progress-track {
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
.trophy-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd54f, #ff9800);
  border-radius: 5px;
  transition: width 0.5s ease;
  box-shadow: 0 0 12px rgba(255,213,79,0.6);
  position: relative;
}
.trophy-progress-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.3) 50%,
    transparent 100%);
  animation: trophy-progress-shimmer 2s linear infinite;
}
@keyframes trophy-progress-shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.trophy-grid {
  padding: 16px 24px 8px;
  overflow-y: auto;
  flex: 1;
  /* Subtle custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,213,79,0.4) transparent;
}
.trophy-grid::-webkit-scrollbar { width: 8px; }
.trophy-grid::-webkit-scrollbar-thumb {
  background: rgba(255,213,79,0.4);
  border-radius: 4px;
}
.trophy-grid::-webkit-scrollbar-track { background: transparent; }

.trophy-category {
  margin-bottom: 16px;
}
.tc-header {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,213,79,0.8);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 8px 0 8px 4px;
  border-bottom: 1px solid rgba(255,213,79,0.12);
  margin-bottom: 10px;
}
.tc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.trophy-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.trophy-card.locked {
  opacity: 0.55;
  filter: grayscale(0.5);
}
.trophy-card.unlocked {
  background: linear-gradient(135deg, rgba(255,213,79,0.12), rgba(255,152,0,0.06));
  border-color: rgba(255,213,79,0.45);
  box-shadow: 0 4px 14px rgba(255,213,79,0.15);
}
.trophy-card:hover {
  transform: translateY(-2px);
}
.tc-icon {
  font-size: 30px;
  line-height: 1;
  margin-bottom: 4px;
}
.trophy-card.unlocked .tc-icon {
  filter: drop-shadow(0 0 6px rgba(255,213,79,0.6));
  animation: tc-icon-glow 2.4s ease-in-out infinite;
}
@keyframes tc-icon-glow {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(255,213,79,0.4)); }
  50%      { filter: drop-shadow(0 0 10px rgba(255,213,79,0.9)); }
}
.tc-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}
.tc-desc {
  font-size: 11.5px;
  color: rgba(255,255,255,0.65);
  line-height: 1.4;
}
.tc-date {
  font-size: 10.5px;
  color: rgba(255,213,79,0.85);
  margin-top: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.trophy-empty {
  text-align: center;
  padding: 60px 24px;
  color: rgba(255,255,255,0.55);
  font-size: 15px;
}
.trophy-empty.hidden { display: none; }

.trophy-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid rgba(255,213,79,0.18);
  display: flex;
  justify-content: center;
  background: rgba(0,0,0,0.2);
}
.trophy-reset-btn {
  background: rgba(255,80,80,0.12);
  border: 1px solid rgba(255,80,80,0.45);
  color: #ff8a80;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  font-family: inherit;
}
.trophy-reset-btn:hover {
  background: rgba(255,80,80,0.3);
  color: #fff;
}

/* ---- Mobile tweaks ---- */
@media (max-width: 600px) {
  #trophy-toast {
    top: 70px;
    right: 12px;
    width: calc(100vw - 24px);
    padding: 12px 14px;
  }
  #trophy-toast .tt-icon { font-size: 36px; }
  #trophy-toast .tt-name { font-size: 15px; }
  #trophy-toast .tt-desc { font-size: 11px; }

  .trophy-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 32px);
  }
  .trophy-header { padding: 18px 18px 12px; }
  .trophy-title { font-size: 22px; }
  .tc-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}
