:root {
  --ink: #102052;
  --sky: #bfeeff;
  --yellow: #ffd84d;
  --pink: #ef5799;
  --blue: #3e7bff;
  --cyan: #00d2ff;
  --green: #25a854;
  --cream: #fffdf5;
  --line: rgba(16, 32, 82, 0.15);
  --shadow: 0 10px 24px rgba(16, 32, 82, 0.16);
  --card-border: 4px solid var(--ink);
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 85% 6%, #fff7be 0, transparent 26rem),
              linear-gradient(160deg, #b0e8ff 0%, #d4eeff 40%, #e6f7df 100%);
  display: flex;
  flex-direction: column;
}

main {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px;
  flex-wrap: wrap;
}

.back-link {
  font-size: 13px;
  font-weight: 900;
  color: var(--ink);
  text-decoration: none;
  padding: 9px 15px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 4px 0 rgba(16, 32, 82, 0.12);
  transition: transform 0.15s ease;
}

.back-link:hover {
  transform: translateY(-2px);
}

.header-center {
  text-align: center;
  flex: 1;
  min-width: 220px;
}

.game-tag {
  display: block;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.15em;
  color: var(--pink);
  text-transform: uppercase;
}

.header-center h1 {
  margin: 2px 0;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: -0.06em;
  line-height: 1;
}

.sub-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  color: #2b568a;
  background: rgba(255, 255, 255, 0.65);
  padding: 2px 10px;
  border-radius: 999px;
}

.hud-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 6px 14px;
  text-align: center;
  box-shadow: 3px 4px 0 rgba(16, 32, 82, 0.12);
}

.badge-label {
  display: block;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: rgba(16, 32, 82, 0.6);
}

.badge-value {
  display: block;
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  line-height: 1.1;
}

.altitude-badge .badge-value {
  color: #0b6cb9;
}

.altitude-badge .badge-value small {
  font-size: 12px;
  margin-left: 1px;
}

.stars-badge .badge-value {
  color: #f59e0b;
}

.score-badge .badge-value {
  color: #e11d48;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 3px solid var(--ink);
  background: var(--cream);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 3px 4px 0 rgba(16, 32, 82, 0.12);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease;
}

.icon-btn:hover {
  transform: translateY(-2px);
}

/* Stage Container */
.game-stage {
  position: relative;
  width: 100%;
  height: min(72vh, 680px);
  min-height: 480px;
  border: 5px solid var(--ink);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 10px 14px 0 rgba(16, 32, 82, 0.18);
  background: #0f2142;
  user-select: none;
  touch-action: none;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* In-Game Floating Canvas HUD */
.canvas-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 20px;
}

.telemetry-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.telemetry-chip {
  background: rgba(16, 32, 82, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.lidar-chip {
  border-color: rgba(0, 210, 255, 0.5);
  color: #a4f2ff;
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #00f0ff;
  box-shadow: 0 0 10px #00f0ff;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.4; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.2); }
}

.speed-chip {
  font-family: monospace, ui-monospace;
  font-size: 15px;
  color: #ffd84d;
}

.speed-chip small {
  font-size: 10px;
  color: #fff;
  font-family: inherit;
}

.grade-chip {
  color: #38bdf8;
  font-weight: 900;
  border-color: rgba(56, 189, 248, 0.4);
}

.grade-chip.steep {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.6);
  animation: pulse 0.8s infinite alternate;
}

.cheetah-chip {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(45, 27, 4, 0.85);
}

.cheetah-chip.drafting {
  border-color: #38bdf8;
  color: #38bdf8;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.8);
  animation: pulse 0.4s infinite alternate;
}

.bear-chip {
  color: #fed7aa;
  border-color: rgba(249, 115, 22, 0.45);
  background: rgba(43, 21, 6, 0.85);
}

.bear-chip.near {
  border-color: #ef4444;
  color: #fecaca;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.8);
  animation: pulse 0.5s infinite alternate;
}

.bear-chip strong {
  color: #ff9800;
  font-size: 14px;
  margin-left: 4px;
}

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

/* Mountain Ascent Elevation Track (Right Side) */
.ascent-track {
  position: absolute;
  right: 18px;
  top: 70px;
  bottom: 120px;
  width: 48px;
  background: rgba(16, 32, 82, 0.82);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.summit-flag, .base-camp {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 16px;
  line-height: 1;
}

.summit-flag span, .base-camp span {
  font-size: 8px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 3px;
  font-family: monospace;
}

.track-line {
  position: relative;
  flex: 1;
  width: 6px;
  margin: 6px 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.track-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(to top, #22c55e, #38bdf8, #f59e0b);
  border-radius: 999px;
  transition: height 0.1s linear;
}

.track-pin {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 50%);
  bottom: 0%;
  font-size: 18px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  transition: bottom 0.15s ease-out;
  cursor: default;
}

.track-pin-car {
  z-index: 3;
}

.track-pin-cheetah {
  z-index: 2;
  font-size: 16px;
}

.track-pin-bear {
  z-index: 1;
  font-size: 16px;
}

/* Perception Alert Banner */
.perception-banner {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245, 158, 11, 0.94);
  color: #102052;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.05em;
  padding: 8px 18px;
  border-radius: 999px;
  border: 3px solid #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: bounceAlert 0.4s infinite alternate;
}

@keyframes bounceAlert {
  from { transform: translateX(-50%) translateY(0); }
  to { transform: translateX(-50%) translateY(-4px); }
}

/* Touch / Mobile Controls */
.touch-controls {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 100%;
  gap: 16px;
  padding-bottom: 4px;
}

.touch-group {
  display: flex;
  gap: 12px;
}

.touch-btn {
  pointer-events: auto;
  touch-action: manipulation;
  border: 3px solid #102052;
  border-radius: 20px;
  background: var(--cream);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #102052, 0 10px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  user-select: none;
}

.touch-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #102052, 0 4px 8px rgba(0, 0, 0, 0.2);
}

.steer-btn {
  width: 62px;
  height: 62px;
  font-size: 26px;
  color: #102052;
}

.action-btn {
  padding: 10px 18px;
  height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1.1;
}

.action-btn span {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.turbo-btn {
  background: #ffeb3b;
  color: #102052;
}

.horn-btn {
  background: #ff5722;
  color: #fff;
  border-color: #5c1800;
  box-shadow: 0 6px 0 #5c1800, 0 10px 18px rgba(0, 0, 0, 0.3);
}

.horn-btn.pulse-ready {
  animation: hornReady 0.5s infinite alternate;
}

@keyframes hornReady {
  from { transform: scale(1); background: #ff5722; }
  to { transform: scale(1.08); background: #ff7043; box-shadow: 0 0 18px #ff7043, 0 6px 0 #5c1800; }
}

/* Modals / Panels */
.panel-card {
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 92%);
  max-height: 92%;
  overflow-y: auto;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 28px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 10px 14px 0 rgba(16, 32, 82, 0.25);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-hero {
  margin-bottom: -4px;
}

.panel-icon {
  font-size: 42px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.panel-card h2 {
  margin: 0;
  font-size: clamp(24px, 3.5vw, 32px);
  letter-spacing: -0.06em;
  line-height: 1.05;
}

.panel-desc {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(16, 32, 82, 0.85);
}

.instructions-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  background: rgba(16, 32, 82, 0.04);
  border-radius: 18px;
  padding: 12px 14px;
  border: 2px dashed rgba(16, 32, 82, 0.18);
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.inst-icon {
  font-size: 22px;
  line-height: 1.2;
}

.instruction-item strong {
  display: block;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.instruction-item span {
  font-size: 11px;
  color: rgba(16, 32, 82, 0.75);
  line-height: 1.35;
}

.difficulty-select {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-option {
  display: block;
  cursor: pointer;
}

.diff-option input {
  display: none;
}

.diff-option span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  border: 2px solid rgba(16, 32, 82, 0.2);
  border-radius: 14px;
  background: #fff;
  font-size: 11px;
  font-weight: 800;
  transition: all 0.15s ease;
}

.diff-option span small {
  font-size: 9px;
  font-weight: normal;
  color: rgba(16, 32, 82, 0.65);
  margin-top: 2px;
}

.diff-option input:checked + span {
  border-color: var(--ink);
  background: #ffd84d;
  box-shadow: 0 4px 0 var(--ink);
}

.cta-btn {
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 15px 24px;
  background: #ffd84d;
  color: var(--ink);
  font: 900 17px inherit;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--ink);
}

.cta-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--ink);
}

.controls-hint {
  font-size: 11px;
  font-weight: 800;
  color: rgba(16, 32, 82, 0.65);
}

/* Result Stats */
.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 6px 0;
}

.stat-box {
  background: #fff;
  border: 2px solid rgba(16, 32, 82, 0.2);
  border-radius: 16px;
  padding: 10px;
}

.stat-label {
  display: block;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: rgba(16, 32, 82, 0.6);
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
  margin-top: 2px;
}

.hide {
  display: none !important;
}

/* Footer Tip */
.game-footer {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: rgba(16, 32, 82, 0.7);
  padding: 4px;
}

.game-footer p {
  margin: 0;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .game-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .header-center {
    order: -1;
  }
  .hud-badges {
    justify-content: center;
  }
  .game-stage {
    min-height: 520px;
  }
  .steer-btn {
    width: 54px;
    height: 54px;
    font-size: 22px;
  }
  .action-btn {
    padding: 8px 12px;
    height: 54px;
  }
  .ascent-track {
    right: 8px;
    top: 60px;
    bottom: 110px;
    width: 38px;
  }
}
