/* Branch Racer — HUD, menus, overlays. */

:root {
  --accent: #ff9a3c;
  --accent-soft: #ffc07a;
  --ink: #f7f8f8;
  --shadow: 0 2px 10px rgba(6, 20, 32, 0.55), 0 0 2px rgba(0, 0, 0, 0.6);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1622;
}

body {
  font-family: "Helvetica Neue", "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

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

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  background:
    radial-gradient(ellipse at 50% 52%, rgba(0, 0, 0, 0) 42%, rgba(6, 14, 22, 0.55) 100%),
    linear-gradient(180deg, rgba(10, 26, 40, 0.22), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(10, 20, 30, 0.25));
  transition: opacity 0.18s linear;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------------ *
 * HUD
 * ------------------------------------------------------------------ */

#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  font-style: italic;
  letter-spacing: 0.02em;
  text-shadow: var(--shadow);
}

#hud-top-left {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  display: flex;
  gap: 26px;
}

.stat {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.stat-value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.stat-label {
  margin-top: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--accent-soft);
}

#hud-top-right {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  text-align: right;
  line-height: 1;
}

.timer {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.sub-timer {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent-soft);
  font-variant-numeric: tabular-nums;
}

#minimap {
  position: absolute;
  top: calc(max(20px, env(safe-area-inset-top)) + 82px);
  right: max(24px, env(safe-area-inset-right));
  width: 132px;
  height: 132px;
  opacity: 0.92;
  filter: drop-shadow(0 2px 8px rgba(0, 15, 25, 0.5));
}

#speed-block {
  position: absolute;
  right: max(26px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  text-align: right;
  line-height: 1;
}

#speed-value {
  font-size: clamp(64px, 11vw, 108px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-shadow: 0 3px 18px rgba(0, 15, 25, 0.65);
}

#speed-unit {
  margin-top: -4px;
  margin-right: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.34em;
  color: var(--accent-soft);
}

#boost-track {
  width: 190px;
  height: 7px;
  margin-top: 14px;
  margin-left: auto;
  border-radius: 3px;
  background: rgba(8, 26, 40, 0.48);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

#boost-fill {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #ffb45c, var(--accent));
  transform-origin: left center;
  transition: transform 0.08s linear, background 0.2s;
}

#message {
  position: absolute;
  top: 27%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(26px, 4.6vw, 52px);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #fff;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
  text-shadow: 0 3px 22px rgba(0, 18, 30, 0.7);
}

#message.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#message.accent {
  color: var(--accent);
}

#countdown {
  position: absolute;
  top: 34%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(84px, 16vw, 190px);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 6px 40px rgba(0, 20, 35, 0.7);
  opacity: 0;
  transform: scale(1.12);
  transition: opacity 0.12s ease-out, transform 0.18s ease-out;
}

#countdown.show {
  opacity: 1;
  transform: scale(1);
}

#countdown.go {
  color: var(--accent);
  font-style: italic;
}

/* ------------------------------------------------------------------ *
 * Screens
 * ------------------------------------------------------------------ */

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(16, 38, 54, 0.42), rgba(4, 12, 20, 0.82) 72%),
    linear-gradient(180deg, rgba(5, 16, 26, 0.5), rgba(3, 10, 16, 0.86));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  text-align: center;
}

.title-inner {
  max-width: 680px;
  padding: 30px 38px 34px;
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 46%, rgba(4, 12, 20, 0.62), rgba(4, 12, 20, 0.34) 62%, rgba(4, 12, 20, 0) 82%);
}

/* the title keeps the live scene visible: light overall tint, real scrim
   only behind the copy, no frost */
#title-screen {
  background: linear-gradient(180deg, rgba(5, 16, 26, 0.28), rgba(3, 10, 16, 0.46));
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}

#title-screen h1 {
  text-shadow: 0 8px 34px rgba(2, 8, 14, 0.55);
}

.kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.46em;
  color: var(--accent);
  margin-bottom: 18px;
}

h1,
h2 {
  font-style: italic;
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(48px, 9vw, 96px);
  text-transform: uppercase;
}

h1 span {
  display: block;
  color: var(--accent);
}

h2 {
  font-size: clamp(40px, 7vw, 76px);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.tagline {
  margin: 22px auto 0;
  max-width: 480px;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(240, 246, 250, 0.78);
}

.title-actions {
  margin-top: 34px;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-style: italic;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #10202c;
  background: var(--accent);
  padding: 16px 44px;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(255, 154, 60, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s;
}

.btn:hover {
  background: #ffab55;
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 14px 34px rgba(255, 154, 60, 0.33), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn.ghost {
  margin-left: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.14);
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  margin-top: 30px;
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(230, 240, 246, 0.55);
}

.controls-hint b {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 800;
}

.panel {
  min-width: min(420px, 82vw);
}

#finish-stats {
  margin: 26px auto 30px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 30px;
  max-width: 330px;
  text-align: left;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(238, 245, 249, 0.72);
}

#finish-stats .value {
  text-align: right;
  font-weight: 800;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: #fff;
  letter-spacing: 0.04em;
}

#finish-stats .record {
  color: var(--accent);
}

/* ------------------------------------------------------------------ *
 * Touch controls
 * ------------------------------------------------------------------ */

#touch-ui {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

#touch-steer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 46%;
  height: 62%;
  pointer-events: auto;
  touch-action: none;
}

#touch-steer-knob {
  position: absolute;
  left: 50%;
  bottom: 16%;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
  transition: transform 0.08s linear;
}

.touch-label {
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.34em;
  color: rgba(255, 255, 255, 0.4);
}

#touch-buttons {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 78px);
  grid-template-rows: repeat(2, 78px);
  gap: 12px;
  pointer-events: auto;
}

.touch-btn {
  pointer-events: auto;
  appearance: none;
  border: 0;
  border-radius: 50%;
  font-family: inherit;
  font-style: italic;
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: #fff;
  background: rgba(10, 28, 42, 0.42);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  touch-action: none;
}

.touch-btn.gas {
  background: rgba(255, 154, 60, 0.8);
  color: #17242f;
  box-shadow: inset 0 0 0 2px rgba(255, 210, 160, 0.8);
}

.touch-btn.boost {
  background: rgba(60, 170, 255, 0.42);
  box-shadow: inset 0 0 0 2px rgba(150, 210, 255, 0.6);
}

.touch-btn.small {
  width: 54px;
  height: 54px;
  margin: 24px 0 0 24px;
  font-size: 9px;
  background: rgba(10, 28, 42, 0.32);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

.touch-btn.small.on {
  color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(255, 154, 60, 0.8);
}

.touch-btn.pressed {
  transform: scale(0.96);
  filter: brightness(1.18);
}

/* ------------------------------------------------------------------ *
 * Error overlay
 * ------------------------------------------------------------------ */

#error-overlay {
  position: fixed;
  inset: auto 16px 16px 16px;
  z-index: 50;
  pointer-events: none;
}

.error-box {
  max-width: 720px;
  margin: 0 auto;
  background: rgba(120, 18, 18, 0.92);
  border: 1px solid rgba(255, 120, 110, 0.55);
  border-radius: 6px;
  padding: 12px 16px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

.error-box h3 {
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: #ffd9d4;
}

.error-box pre {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ffe7e4;
}

/* ------------------------------------------------------------------ *
 * Small screens
 * ------------------------------------------------------------------ */

@media (max-width: 720px) {
  .stat-value {
    font-size: 24px;
  }
  .timer {
    font-size: 22px;
  }
  #minimap {
    width: 96px;
    height: 96px;
    top: calc(max(16px, env(safe-area-inset-top)) + 62px);
    right: max(16px, env(safe-area-inset-right));
  }
  #hud-top-left {
    gap: 16px;
  }
  #boost-track {
    width: 130px;
  }
  #speed-block {
    bottom: max(150px, calc(env(safe-area-inset-bottom) + 130px));
    right: max(18px, env(safe-area-inset-right));
  }
  #speed-value {
    font-size: 56px;
  }
  .btn {
    font-size: 17px;
    padding: 14px 32px;
  }
  .controls-hint {
    display: none;
  }
}


/* Touch devices: keep the speedo clear of the on-screen buttons. */
@media (pointer: coarse) {
  #speed-block {
    bottom: max(300px, calc(env(safe-area-inset-bottom) + 280px));
    right: max(18px, env(safe-area-inset-right));
  }
  #speed-value {
    font-size: 52px;
  }
  #boost-track {
    width: 120px;
  }
}


/* Short touch screens (phones in landscape). */
@media (pointer: coarse) and (max-height: 520px) {
  #speed-block {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: calc(max(16px, env(safe-area-inset-right)) + 180px);
  }
  #speed-value {
    font-size: 38px;
  }
  #speed-unit {
    font-size: 9px;
    letter-spacing: 0.2em;
  }
  #boost-track {
    width: 90px;
    margin-top: 8px;
  }
  #minimap {
    width: 74px;
    height: 74px;
    top: calc(max(12px, env(safe-area-inset-top)) + 54px);
    right: max(12px, env(safe-area-inset-right));
  }
  .stat-value {
    font-size: 20px;
  }
  .timer {
    font-size: 18px;
  }
  .sub-timer {
    font-size: 9px;
  }
}
