/* ==========================================================================
   DUST RUNNER — UI styles
   Retro 32-bit arcade look: chunky type, hard shadows, warm desert palette.
   ========================================================================== */

:root {
  --c-yellow: #f6b90a;
  --c-orange: #ff7a1a;
  --c-red: #e8402c;
  --c-cream: #fff1d6;
  --c-ink: #1b120c;
  --c-panel: rgba(27, 18, 12, 0.62);
  --c-panel-border: rgba(255, 210, 140, 0.35);
  --font-display: "Russo One", "Arial Black", system-ui, sans-serif;
  --font-ui: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120c08;
  color: var(--c-cream);
  font-family: var(--font-ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app { position: fixed; inset: 0; }
#game-canvas { display: block; width: 100%; height: 100%; }

[hidden] { display: none !important; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-shadow: 2px 2px 0 var(--c-ink);
}

.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.hud-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }

.hud-panel {
  background: var(--c-panel);
  border: 2px solid var(--c-panel-border);
  border-radius: 6px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.hud-label { font-size: 11px; letter-spacing: 2px; color: var(--c-yellow); }
.hud-value { font-family: var(--font-display); font-size: 30px; }
.hud-small { font-size: 12px; letter-spacing: 1px; opacity: 0.9; margin-top: 2px; }
.hud-unit { font-size: 11px; letter-spacing: 2px; color: var(--c-yellow); }

.hud-time .hud-value { font-size: 38px; color: var(--c-cream); }
.hud-pos { font-size: 13px; letter-spacing: 2px; color: var(--c-yellow); margin-top: 2px; }
.hud-pos b { font-family: var(--font-display); font-size: 20px; color: var(--c-cream); letter-spacing: 0; }
.hud-time.is-low .hud-value { color: var(--c-red); animation: blink 0.5s steps(2) infinite; }

.hud-stage { align-items: center; text-align: center; }
.hud-stage-name { font-family: var(--font-display); font-size: 13px; letter-spacing: 1px; color: var(--c-yellow); }

.hud-score { align-items: flex-end; text-align: right; }

.hud-speedo { align-items: flex-end; min-width: 132px; margin-left: auto; }
.hud-speedo .hud-value { font-size: 40px; }
.hud-speedbar { width: 100%; height: 6px; background: rgba(255,255,255,0.15); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.hud-speedbar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--c-yellow), var(--c-orange), var(--c-red)); }

.hud-radio {
  max-width: min(520px, 60vw);
  background: rgba(10, 22, 18, 0.72);
  border-left: 4px solid #6ee7a8;
  padding: 8px 12px;
  font-size: 14px;
  color: #d9ffe9;
  text-shadow: none;
  border-radius: 4px;
}
.hud-radio b { color: #6ee7a8; letter-spacing: 1px; }

.hud-center {
  position: absolute;
  left: 0; right: 0; top: 30%;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.hud-banner {
  font-family: var(--font-display);
  font-size: clamp(28px, 7vw, 64px);
  color: var(--c-yellow);
  text-shadow: 3px 3px 0 var(--c-ink), 0 0 18px rgba(255, 160, 40, 0.6);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s, transform 0.15s;
  text-align: center;
}
.hud-banner.is-visible { opacity: 1; transform: scale(1); }
.hud-warning {
  font-family: var(--font-display);
  font-size: clamp(18px, 4vw, 30px);
  color: var(--c-red);
  animation: blink 0.6s steps(2) infinite;
}
.hud-popups { position: relative; height: 0; width: 100%; }
.hud-popup {
  position: absolute;
  left: 50%;
  top: 40px;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--c-cream);
  white-space: nowrap;
  animation: popup 1.1s ease-out forwards;
}

@keyframes popup {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- Touch controls ---------- */
.touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  height: 0;
  pointer-events: none;
}
.touch-group {
  position: absolute;
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  gap: 14px;
  pointer-events: auto;
}
.touch-steer { left: calc(16px + var(--safe-left)); }
.touch-pedals { right: calc(16px + var(--safe-right)); }
.touch-controls button {
  width: 84px; height: 84px;
  border-radius: 18px;
  border: 3px solid rgba(255, 220, 160, 0.55);
  background: rgba(27, 18, 12, 0.45);
  color: var(--c-cream);
  font-family: var(--font-display);
  font-size: 24px;
  touch-action: none;
}
.touch-controls button.is-down { background: rgba(246, 185, 10, 0.55); color: var(--c-ink); }
.touch-pedals .pedal-brake { font-size: 13px; }
.touch-pedals .pedal-gas { font-size: 16px; height: 110px; }
.touch-pause {
  position: fixed;
  pointer-events: auto;
  left: 50%;
  top: calc(74px + var(--safe-top));
  transform: translateX(-50%);
  width: 52px !important; height: 40px !important;
  font-size: 14px !important;
}
/* When touch controls are on, lift the bottom HUD so it does not sit under the thumbs. */
body.has-touch .hud-bottom { margin-bottom: 120px; }
body.has-touch .hud-speedo { margin-right: 0; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  align-items: safe center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 10, 4, 0.25), rgba(20, 10, 4, 0.75));
  overflow-y: auto;
}

.title-card { text-align: center; max-width: 640px; }
.title-kicker { letter-spacing: 4px; font-size: 12px; color: var(--c-yellow); margin: 0 0 4px; }
.title-logo {
  font-family: var(--font-display);
  font-size: clamp(34px, min(11vw, 15vh), 96px);
  margin: 0;
  line-height: 0.95;
  color: var(--c-yellow);
  text-shadow: 4px 4px 0 var(--c-red), 8px 8px 0 var(--c-ink);
  letter-spacing: 2px;
}
.title-sub {
  font-family: var(--font-display);
  font-size: clamp(18px, 4vw, 30px);
  letter-spacing: 8px;
  margin: 6px 0 4px;
  text-shadow: 3px 3px 0 var(--c-ink);
}
.title-tagline { font-style: italic; opacity: 0.85; margin: 0 0 18px; }
.title-stage {
  display: inline-flex; flex-direction: column; gap: 2px;
  background: var(--c-panel);
  border: 2px solid var(--c-panel-border);
  border-radius: 6px;
  padding: 8px 18px;
  margin-bottom: 18px;
}
.title-stage span { font-size: 12px; letter-spacing: 2px; color: var(--c-yellow); }
.title-stage strong { font-family: var(--font-display); font-size: 20px; letter-spacing: 1px; }
.track-select {
  display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 0 0 12px;
}
.track-select button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 108px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  background: rgba(27, 18, 12, 0.7); color: var(--c-cream);
  border: 2px solid var(--c-panel-border);
  font-family: var(--font-ui);
}
.track-select button b { font-family: var(--font-display); font-size: 14px; letter-spacing: 1px; }
.track-select button span { font-size: 11px; letter-spacing: 1px; opacity: 0.8; }
.track-select button.is-selected { background: var(--c-yellow); color: var(--c-ink); border-color: var(--c-ink); box-shadow: 3px 3px 0 var(--c-ink); }
.difficulty {
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
  margin: 0 0 16px;
}
.difficulty-label { font-size: 12px; letter-spacing: 3px; color: var(--c-yellow); margin-right: 4px; }
.difficulty button {
  font-family: var(--font-display); font-size: 13px; letter-spacing: 1px;
  padding: 7px 12px; border-radius: 5px; cursor: pointer;
  background: rgba(27, 18, 12, 0.7); color: var(--c-cream);
  border: 2px solid var(--c-panel-border);
}
.difficulty button.is-selected { background: var(--c-yellow); color: var(--c-ink); border-color: var(--c-ink); box-shadow: 3px 3px 0 var(--c-ink); }
.title-best { min-height: 1em; font-size: 13px; color: var(--c-yellow); }
.title-controls { font-size: 12px; opacity: 0.8; line-height: 1.7; margin-top: 8px; }
.title-controls b { color: var(--c-yellow); font-weight: 700; }

.panel {
  min-width: min(360px, 92vw);
  background: rgba(27, 18, 12, 0.88);
  border: 3px solid var(--c-panel-border);
  border-radius: 10px;
  padding: 22px 26px;
  text-align: center;
  display: flex; flex-direction: column; gap: 10px;
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 34px; margin: 0; color: var(--c-yellow);
  text-shadow: 3px 3px 0 var(--c-ink);
}
.results-sub { margin: 0; opacity: 0.85; }
.results-table { width: 100%; border-collapse: collapse; font-size: 15px; margin: 6px 0; }
.results-table td { padding: 5px 4px; border-bottom: 1px dashed rgba(255, 220, 160, 0.2); }
.results-table td:last-child { text-align: right; font-family: var(--font-display); }
.results-table tr.total td { color: var(--c-yellow); font-size: 20px; border-bottom: none; }
.results-best { margin: 0; color: var(--c-yellow); min-height: 1em; }

.btn {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 2px;
  padding: 12px 22px;
  border-radius: 6px;
  border: 3px solid var(--c-ink);
  background: var(--c-cream);
  color: var(--c-ink);
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--c-ink);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--c-ink); }
.btn-primary { background: var(--c-yellow); font-size: 20px; }
.btn-small { font-size: 12px; padding: 7px 12px; box-shadow: 3px 3px 0 var(--c-ink); }
.btn-small.is-off { background: #8d8172; text-decoration: line-through; }
.settings-row { display: flex; gap: 10px; justify-content: center; margin: 12px 0 2px; }
.panel .settings-row { margin: 0; }
.screen-title .btn-primary { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }

.loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); letter-spacing: 3px; color: var(--c-yellow);
  background: #120c08;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px), (max-height: 480px) {
  .hud-value { font-size: 22px; }
  .hud-time .hud-value { font-size: 28px; }
  .hud-speedo .hud-value { font-size: 28px; }
  .hud-speedo { min-width: 96px; }
  .hud-stage-name { font-size: 10px; }
  .hud-radio { font-size: 12px; }
  .touch-controls button { width: 70px; height: 70px; }
  .touch-pedals .pedal-gas { height: 92px; }
  body.has-touch .hud-bottom { margin-bottom: 100px; }
  .title-controls { display: none; }
}

@media (max-height: 480px) {
  .title-kicker, .title-tagline { margin-bottom: 6px; }
  .title-stage { margin-bottom: 10px; padding: 6px 14px; }
  .difficulty { margin-bottom: 10px; }
  .track-select { margin-bottom: 8px; gap: 5px; }
  .track-select button { min-width: 0; padding: 5px 8px; }
  .track-select button span { display: none; }
  .title-stage { display: none; }
  .difficulty button { padding: 5px 9px; font-size: 11px; }
  .panel { padding: 12px 18px; gap: 6px; }
  .panel h2 { font-size: 26px; }
  .results-table { font-size: 13px; margin: 2px 0; }
  .results-table td { padding: 3px 4px; }
  .results-table tr.total td { font-size: 16px; }
  .btn { padding: 8px 16px; font-size: 14px; }
  .btn-primary { font-size: 16px; }
}
