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

:root {
  --daka-navy: #1B3665;
  --daka-navy-d: #122548;
  --daka-navy-l: #2A4775;
  --daka-green: #669B41;
  --daka-green-l: #7FB650;
  --daka-green-d: #4F7D31;
  --bg: #0c1830;
  --text: #ffffff;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
}

#game-root { position: fixed; inset: 0; }
canvas { display: block; }

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: flex-start; justify-content: center;
  background: linear-gradient(135deg, rgba(27, 54, 101, 0.95), rgba(18, 37, 72, 0.96));
  z-index: 100;
  /* Menu can be taller than viewport (lots of routes + sliders) — let it scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 12px;
}

.hidden { display: none !important; }

.menu-card {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 28px 36px;
  border-radius: 20px;
  backdrop-filter: blur(10px);
  max-width: 680px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  margin: auto;
}

/* Real CK DAKA logo shown in the menu */
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
}
.brand-logo {
  display: block;
  max-width: 320px;
  width: 100%;
  height: auto;
  background: #ffffff;
  padding: 14px 22px;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.menu-card h1 {
  font-size: 32px;
  margin-bottom: 8px;
  font-weight: 800;
}

.tagline {
  opacity: 0.85;
  margin-bottom: 26px;
  font-size: 15px;
}

.routes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.route-btn {
  background: linear-gradient(160deg, rgba(102, 155, 65, 0.16), rgba(27, 54, 101, 0.30));
  border: 1px solid rgba(102, 155, 65, 0.45);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  margin: 0;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.route-btn:hover {
  background: linear-gradient(160deg, rgba(102, 155, 65, 0.28), rgba(27, 54, 101, 0.45));
  transform: translateY(-3px);
  border-color: var(--daka-green-l);
  box-shadow: 0 10px 26px rgba(102, 155, 65, 0.30);
}
.route-btn .from-to {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--daka-green-l);
  letter-spacing: 0.2px;
}
.route-btn .meta {
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.55;
}

.controls-hint {
  font-size: 13px;
  opacity: 0.78;
  line-height: 1.8;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.menu-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 11.5px;
  opacity: 0.65;
  line-height: 1.6;
  letter-spacing: 0.2px;
}
.menu-footer .heart {
  color: #c0392b;
  display: inline-block;
  animation: heartbeat 1.4s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  10%      { transform: scale(1.2); }
  20%      { transform: scale(1); }
  30%      { transform: scale(1.15); }
  40%      { transform: scale(1); }
}

button {
  background: var(--daka-green);
  color: #ffffff;
  border: none;
  padding: 14px 28px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  margin-top: 18px;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(102, 155, 65, 0.4);
}
button:hover {
  background: var(--daka-green-l);
  transform: translateY(-1px);
}

#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 50;
}

.hud-top {
  position: absolute;
  top: 16px; left: 16px; right: 16px;
  display: flex; gap: 12px;
  justify-content: center;
}

.panel {
  background: rgba(27, 54, 101, 0.85);
  border: 1px solid rgba(102, 155, 65, 0.55);
  border-radius: 10px;
  padding: 8px 18px;
  min-width: 130px;
  text-align: center;
  backdrop-filter: blur(4px);
}
.panel-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.7;
  margin-bottom: 2px;
}
.panel-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--daka-green-l);
  font-variant-numeric: tabular-nums;
}

.hud-bottom {
  position: absolute;
  bottom: 16px; left: 16px; right: 16px;
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.speedo {
  background: rgba(27, 54, 101, 0.92);
  border: 3px solid var(--daka-green);
  border-radius: 50%;
  width: 130px; height: 130px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.speedo-value {
  font-size: 38px;
  font-weight: 900;
  color: var(--daka-green-l);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.speedo-unit { font-size: 11px; opacity: 0.75; margin-top: 2px; }

.meters {
  flex: 1; max-width: 380px;
  display: flex; flex-direction: column;
  gap: 10px;
}
.meter {
  background: rgba(27, 54, 101, 0.85);
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.meter-label {
  font-size: 11px;
  opacity: 0.75;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.meter-bar {
  height: 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, #c0392b 0%, var(--daka-navy-l) 50%, var(--daka-green) 100%);
  transition: width 0.3s ease;
}
.meter-text {
  font-size: 22px;
  font-weight: 800;
  color: var(--daka-green-l);
  font-variant-numeric: tabular-nums;
}

#minimap {
  background: rgba(27, 54, 101, 0.92);
  border: 1px solid rgba(102, 155, 65, 0.55);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

#hud-audio-control {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(27, 54, 101, 0.88);
  border: 1px solid rgba(102, 155, 65, 0.55);
  padding: 5px 10px 5px 6px;
  border-radius: 18px;
  pointer-events: auto;
}
#hud-mute-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  margin: 0;
  border-radius: 50%;
  line-height: 1;
  box-shadow: none;
}
#hud-mute-btn:hover { background: rgba(255,255,255,0.1); transform: none; }
#hud-vol-slider {
  width: 110px;
  cursor: pointer;
  accent-color: #669B41;
}
@media (max-width: 768px) {
  /* Move audio control to the top-LEFT — out of the way of the centre HUD
     panels and easy to reach with the left thumb. */
  #hud-audio-control {
    top: 8px; left: 8px; right: auto;
    padding: 6px 12px 6px 8px;
    gap: 10px;
    z-index: 90;            /* above HUD panels */
  }
  #hud-mute-btn { font-size: 22px; padding: 6px 8px; }
  #hud-vol-slider {
    width: 110px;
    height: 28px;            /* bigger touch target */
  }
  #hud-vol-slider::-webkit-slider-thumb { width: 22px; height: 22px; }
}

/* ------------------------ TOUCH CONTROLS ------------------------ */
/* Hidden on desktops with a fine pointer (mouse). Visible on touch devices
   (pointer: coarse) OR narrow viewports — pure CSS, no JS required. */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
  display: none;
}
@media (pointer: coarse), (max-width: 900px) {
  #touch-controls { display: block; }
  #touch-controls.hidden { display: none; }
}
/* Keep the JS-driven mode as an additional escape hatch */
body.touch-mode #touch-controls { display: block; }
body.touch-mode #touch-controls.hidden { display: none; }
.tc-cluster {
  position: absolute;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.tc-cluster .tc-row { display: flex; gap: 14px; }
.tc-left   { left: 24px; }
.tc-right  { right: 24px; }
.tc-btn {
  pointer-events: auto;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: rgba(27, 54, 101, 0.78);
  border: 2px solid rgba(102, 155, 65, 0.85);
  color: #ffffff;
  font-size: 32px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  padding: 0;
  margin: 0;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.08s, transform 0.08s;
}
.tc-btn:active, .tc-btn.pressed {
  background: rgba(102, 155, 65, 0.92);
  transform: scale(0.94);
}
.tc-btn.tc-gas    { background: rgba(102, 155, 65, 0.78); }
.tc-btn.tc-brake  { background: rgba(192, 57, 43, 0.78); border-color: rgba(255,255,255,0.6); }
.tc-btn.tc-small  { width: 58px; height: 58px; font-size: 22px; }

/* ------------------------ MOBILE BREAKPOINTS ------------------------ */
@media (max-width: 768px) {
  .overlay { align-items: flex-start; padding: 12px 0; overflow-y: auto; }
  .menu-card { padding: 16px 14px; max-width: 100%; max-height: none; }
  .brand { margin-bottom: 12px; }
  .brand-logo { max-width: 170px; padding: 8px 12px; border-radius: 8px; }
  .menu-card h1 { font-size: 18px; line-height: 1.2; margin-bottom: 4px; }
  .tagline { font-size: 12px; margin-bottom: 14px; line-height: 1.35; }
  .routes { grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
  .route-btn { padding: 10px 12px; font-size: 12px; }
  .route-btn .from-to { font-size: 13px; margin-bottom: 3px; }
  .route-btn .meta { font-size: 11px; line-height: 1.4; }
  .controls-hint { display: none; }   /* keyboard hints irrelevant on touch */
  .menu-footer { font-size: 10px; line-height: 1.5; margin-top: 12px; padding-top: 10px; }
  #vol-wrap { font-size: 12px !important; }
  #vol-wrap button { padding: 6px 12px !important; font-size: 12px !important; margin-top: 4px !important; }
  #vol-wrap input[type=range] { width: 120px !important; }

  /* HUD top — compact panels in a row */
  /* Push HUD panels DOWN below the audio control on top-left */
  .hud-top { top: 56px; left: 8px; right: 8px; gap: 6px; }
  .panel { min-width: 0; padding: 4px 8px; flex: 1; }
  .panel-label { font-size: 9px; letter-spacing: 1px; }
  .panel-value { font-size: 14px; }

  /* HUD bottom — speedo + meters smaller, room above for touch buttons */
  .hud-bottom { bottom: 130px; left: 8px; right: 8px; gap: 8px; }
  .speedo { width: 90px; height: 90px; border-width: 2px; }
  .speedo-value { font-size: 28px; }
  .speedo-unit { font-size: 9px; }
  .meter { padding: 6px 10px; }
  .meter-label { font-size: 9px; }
  .meter-text { font-size: 16px; }
  #minimap { width: 90px; height: 90px; }
  .toast { font-size: 13px; padding: 10px 18px; top: 80px; }

  /* Touch button sizes scale to thumbs */
  .tc-btn { width: 64px; height: 64px; font-size: 26px; }
  .tc-btn.tc-small { width: 46px; height: 46px; font-size: 18px; }
  .tc-cluster { bottom: 18px; gap: 8px; }
  .tc-cluster .tc-row { gap: 10px; }

  #hud-audio-pill { font-size: 10px; padding: 4px 8px; top: 8px; right: 8px; }
}

/* Very small screens (older phones) — even tighter */
@media (max-width: 420px) {
  .menu-card { padding: 12px 10px; }
  .brand-logo { max-width: 140px; padding: 6px 10px; }
  .menu-card h1 { font-size: 16px; }
  .tagline { font-size: 11px; margin-bottom: 10px; }
  .route-btn { padding: 8px 10px; }
  .route-btn .from-to { font-size: 12px; }
  .route-btn .meta { font-size: 10px; }
  .menu-footer { font-size: 9px; }
  .hud-bottom { gap: 6px; bottom: 120px; }
  .speedo { width: 78px; height: 78px; }
  .speedo-value { font-size: 24px; }
  #minimap { display: none; }   /* save space, route is forgiving anyway */
  .tc-btn { width: 60px; height: 60px; font-size: 24px; }
}

/* Landscape orientation on phones — re-arrange the bottom strip */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .hud-bottom { bottom: 8px; gap: 6px; }
  .tc-cluster { bottom: 8px; gap: 6px; }
  .speedo { width: 70px; height: 70px; }
  .speedo-value { font-size: 20px; }
  #minimap { width: 70px; height: 70px; }
  .tc-btn { width: 56px; height: 56px; font-size: 22px; }
  .tc-btn.tc-small { width: 40px; height: 40px; font-size: 15px; }
}

.toast {
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--daka-green);
  color: #ffffff;
  padding: 14px 28px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#end-summary {
  text-align: left;
  line-height: 1.9;
  margin: 18px 0;
  font-size: 16px;
  background: rgba(0, 0, 0, 0.25);
  padding: 16px 22px;
  border-radius: 10px;
}
#end-summary b { color: var(--daka-green-l); }
#end-summary .pb-line {
  margin-top: 12px;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(102, 155, 65, 0.35), rgba(127, 182, 80, 0.25));
  border: 1px solid rgba(127, 182, 80, 0.8);
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(102, 155, 65, 0.35);
}
.stars-big {
  text-align: center;
  font-size: 38px;
  letter-spacing: 6px;
  margin-bottom: 14px;
  color: #ffd700;
  text-shadow: 0 0 18px rgba(255, 215, 0, 0.55);
  line-height: 1;
}
.route-stars {
  color: #ffd700;
  letter-spacing: 2px;
  font-size: 14px;
}
.route-stars.dim {
  color: rgba(255, 255, 255, 0.25);
}

/* End-screen lets the scene show through so cars keep driving in the background */
#end {
  background: linear-gradient(135deg, rgba(27, 54, 101, 0.55), rgba(18, 37, 72, 0.65));
}
#end .menu-card {
  background: rgba(18, 37, 72, 0.94);
}
