/* Night Drift Delivery — neon night UI theme */

:root {
  --cyan: #19f0ff;
  --pink: #ff2ea6;
  --amber: #ffb020;
  --violet: #8a5cff;
  --night: #070818;
  --night-2: #10122a;
  --ink: #eef2ff;
  --ink-dim: rgba(238, 242, 255, 0.72);
  /* Safe areas (notch, home indicator); 0 where the browser has none. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  font-family: "Segoe UI", "Trebuchet MS", Verdana, system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

/* Free-look drag (desktop): the cursor says the view is being swung around. */
html[data-input="keyboard"] #game-canvas.looking {
  cursor: grabbing;
}

.hidden {
  display: none !important;
}

/* Device-specific wording: html[data-input] is set by src/device.js. */
html[data-input="keyboard"] .only-touch,
html[data-input="touch"] .only-keyboard {
  display: none !important;
}

/* ---------- Touch layer ---------- */

#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 4; /* under the HUD (5) so the pause button stays tappable */
  display: none;
  pointer-events: none;
}

html[data-input="touch"] #touch-controls.active {
  display: block;
}

#stick-zone {
  position: absolute;
  top: 110px;
  bottom: 0;
  left: 0;
  width: 46%;
  pointer-events: auto;
  touch-action: none;
}

#stick-base {
  position: absolute;
  left: calc(24px + var(--safe-left));
  bottom: calc(24px + var(--safe-bottom));
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(7, 8, 24, 0.6) 0%, rgba(7, 8, 24, 0.35) 70%, rgba(7, 8, 24, 0.12) 100%);
  border: 2px solid rgba(25, 240, 255, 0.45);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 0 18px rgba(25, 240, 255, 0.18);
  backdrop-filter: blur(3px);
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

#stick-base.held {
  opacity: 1;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan) 0%, #0aa8c0 100%);
  box-shadow: 0 4px 18px rgba(25, 240, 255, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.12s ease;
}

#stick-base.held #stick-knob {
  transition: none;
}

.touch-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border: none;
  border-radius: 50%;
  font-family: inherit;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--night);
  opacity: 0.92;
  transition: transform 0.08s ease, opacity 0.08s ease, box-shadow 0.2s ease;
}

.touch-btn.pressed {
  transform: scale(0.92);
  opacity: 1;
}

#drift-button {
  right: calc(24px + var(--safe-right));
  bottom: calc(28px + var(--safe-bottom));
  width: 96px;
  height: 96px;
  font-size: 15px;
  background: linear-gradient(135deg, var(--pink) 0%, #ff7a3a 100%);
  box-shadow: 0 8px 26px rgba(255, 46, 166, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

#brake-button {
  right: calc(134px + var(--safe-right));
  bottom: calc(24px + var(--safe-bottom));
  width: 68px;
  height: 68px;
  font-size: 13px;
  color: var(--ink);
  background: rgba(16, 18, 42, 0.8);
  border: 2px solid rgba(238, 242, 255, 0.5);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#boost-button {
  right: calc(34px + var(--safe-right));
  bottom: calc(138px + var(--safe-bottom));
  width: 68px;
  height: 68px;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(16, 18, 42, 0.8);
  border: 2px solid rgba(25, 240, 255, 0.35);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#boost-button.ready {
  color: var(--night);
  background: linear-gradient(135deg, var(--cyan) 0%, #7dffe0 100%);
  border-color: transparent;
  box-shadow: 0 0 26px rgba(25, 240, 255, 0.8);
  animation: boost-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes boost-pulse {
  from {
    box-shadow: 0 0 14px rgba(25, 240, 255, 0.5);
  }
  to {
    box-shadow: 0 0 32px rgba(25, 240, 255, 0.95);
  }
}

/* Icons used in the touch rows of the control lists. */
.ctl-icon {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  margin-right: 4px;
}

.ctl-icon.stick {
  background: radial-gradient(circle, var(--cyan) 0 5px, transparent 6px), rgba(238, 242, 255, 0.14);
  border: 2px solid rgba(25, 240, 255, 0.55);
}

.ctl-icon.mouse {
  border-radius: 7px 7px 9px 9px;
  background: rgba(238, 242, 255, 0.14);
  border: 2px solid rgba(25, 240, 255, 0.55);
  position: relative;
}

.ctl-icon.mouse::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 2px;
  height: 5px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--cyan);
}

.ctl-icon.drift {
  background: linear-gradient(135deg, var(--pink) 0%, #ff7a3a 100%);
  box-shadow: 0 0 10px rgba(255, 46, 166, 0.6);
}

.pillar {
  display: inline-block;
  width: 8px;
  height: 20px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

.pillar.cyan {
  background: linear-gradient(180deg, transparent, var(--cyan));
  box-shadow: 0 0 10px rgba(25, 240, 255, 0.8);
}

.pillar.pink {
  background: linear-gradient(180deg, transparent, var(--pink));
  box-shadow: 0 0 10px rgba(255, 46, 166, 0.8);
}

.hazard-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9ac0ff, #4d8dff 60%, #1d3f99);
  box-shadow: 0 0 10px rgba(77, 141, 255, 0.9);
}

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

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#hud-left {
  position: absolute;
  top: calc(clamp(10px, 2.2vh, 24px) + var(--safe-top));
  left: calc(clamp(12px, 2.5vw, 28px) + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#timer {
  padding: 6px 18px;
  font-size: clamp(26px, 3.4vw, 40px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(7, 8, 24, 0.62);
  border: 2px solid rgba(25, 240, 255, 0.45);
  border-radius: 14px;
  text-shadow: 0 0 12px rgba(25, 240, 255, 0.5);
  backdrop-filter: blur(4px);
}

#timer.warn {
  color: #ffd0e6;
  border-color: rgba(255, 46, 166, 0.8);
  text-shadow: 0 0 14px rgba(255, 46, 166, 0.9);
  animation: timer-blink 0.5s steps(2, end) infinite;
}

@keyframes timer-blink {
  to {
    border-color: rgba(255, 46, 166, 0.2);
  }
}

#mission-label {
  padding: 5px 14px;
  font-size: clamp(13px, 1.5vw, 17px);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(7, 8, 24, 0.55);
  border-radius: 999px;
  border: 1px solid rgba(25, 240, 255, 0.35);
  width: fit-content;
}

#mission-label.deliver {
  color: #ffb3dc;
  border-color: rgba(255, 46, 166, 0.5);
}

#mission-dist {
  opacity: 0.8;
  font-weight: 600;
  text-transform: none;
}

#minimap {
  position: absolute;
  top: calc(clamp(10px, 2.2vh, 24px) + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: clamp(96px, 16vh, 150px);
  height: clamp(96px, 16vh, 150px);
  opacity: 0.92;
}

#hud-right {
  position: absolute;
  top: calc(clamp(10px, 2.2vh, 24px) + var(--safe-top));
  right: calc(clamp(12px, 2.5vw, 28px) + var(--safe-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#score-box {
  display: flex;
  gap: 14px;
  padding: 6px 16px;
  background: rgba(7, 8, 24, 0.62);
  border: 2px solid rgba(255, 46, 166, 0.45);
  border-radius: 14px;
  backdrop-filter: blur(4px);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
}

.stat > span:last-child {
  font-size: clamp(18px, 2.4vw, 28px);
  font-weight: 900;
  line-height: 1.1;
}

.stat-label {
  font-size: clamp(10px, 1.1vw, 12px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

#hud-buttons {
  display: flex;
  gap: 8px;
}

.icon-btn {
  pointer-events: auto;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(25, 240, 255, 0.4);
  background: rgba(7, 8, 24, 0.62);
  color: var(--cyan);
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  transition: transform 0.12s ease, background 0.12s ease;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(16, 18, 42, 0.9);
  transform: scale(1.06);
  outline: none;
}

html[data-input="touch"] .icon-btn {
  width: 56px;
  height: 56px;
}

#mute-button .cross {
  display: none;
}

html.muted #mute-button .wave {
  display: none;
}

html.muted #mute-button .cross {
  display: block;
}

html.muted #mute-button {
  color: var(--pink);
  border-color: rgba(255, 46, 166, 0.5);
}

#boost-wrap {
  position: absolute;
  bottom: calc(clamp(44px, 8vh, 64px) + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(300px, 40vw);
  height: 16px;
  border-radius: 999px;
  background: rgba(7, 8, 24, 0.7);
  border: 2px solid rgba(25, 240, 255, 0.35);
  overflow: hidden;
}

#boost-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--violet), var(--cyan));
  box-shadow: 0 0 12px rgba(25, 240, 255, 0.7);
  transition: width 0.1s linear;
}

#boost-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.3em;
  color: rgba(238, 242, 255, 0.7);
}

#boost-wrap.ready {
  border-color: var(--cyan);
  animation: boost-pulse 0.9s ease-in-out infinite alternate;
}

#boost-wrap.ready #boost-text {
  color: var(--night);
}

html[data-input="touch"] #boost-wrap {
  bottom: calc(14px + var(--safe-bottom));
  width: min(220px, 30vw);
}

#toast {
  position: absolute;
  /* Above the overlays (10) and the coaching (45): a toast is always about
     what just happened, so it has to be readable on whatever screen is up. */
  z-index: 50;
  top: calc(22% + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(720px, 88vw);
  padding: 12px 28px;
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--night);
  background: linear-gradient(135deg, var(--cyan) 0%, #7dffe0 100%);
  border-radius: 999px;
  box-shadow: 0 6px 30px rgba(25, 240, 255, 0.55);
  text-align: center;
  animation: toast-pop 0.35s ease-out;
}

#toast.bad {
  color: #fff;
  background: linear-gradient(135deg, var(--pink) 0%, #ff5a3a 100%);
  box-shadow: 0 6px 30px rgba(255, 46, 166, 0.55);
}

#toast.info {
  color: var(--ink);
  background: rgba(7, 8, 24, 0.85);
  border: 2px solid rgba(138, 92, 255, 0.7);
  box-shadow: 0 6px 30px rgba(138, 92, 255, 0.3);
  font-weight: 600;
  font-size: clamp(15px, 1.8vw, 21px);
}

#toast.bonus {
  color: var(--night);
  background: linear-gradient(135deg, var(--amber) 0%, #ffe08a 100%);
  box-shadow: 0 6px 30px rgba(255, 176, 32, 0.55);
}

@keyframes toast-pop {
  from {
    transform: translateX(-50%) scale(0.6);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

#controls-hint {
  position: absolute;
  bottom: calc(clamp(10px, 2vh, 22px) + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(12px, 1.4vw, 15px);
  letter-spacing: 0.08em;
  color: rgba(238, 242, 255, 0.85);
  background: rgba(7, 8, 24, 0.5);
  padding: 7px 16px;
  border-radius: 999px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

/* On touch the hint sits above the boost meter and fades once the player
   has had a few seconds to read it. */
html[data-input="touch"] #controls-hint {
  bottom: calc(44px + var(--safe-bottom));
  max-width: min(46vw, 400px);
  white-space: normal;
  text-align: center;
  line-height: 1.35;
  font-size: 12px;
  letter-spacing: 0.05em;
  animation: hint-fade 0.8s ease 7s forwards;
}

@media (orientation: portrait) {
  html[data-input="touch"] #controls-hint {
    bottom: calc(190px + var(--safe-bottom));
    max-width: 82vw;
  }

  html[data-input="touch"] #boost-wrap {
    bottom: calc(170px + var(--safe-bottom));
  }
}

@keyframes hint-fade {
  to {
    opacity: 0;
  }
}

/* ---------- Overlay screens ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 20% 110%, rgba(255, 46, 166, 0.28), transparent 55%),
    radial-gradient(ellipse at 85% -10%, rgba(25, 240, 255, 0.22), transparent 55%),
    linear-gradient(180deg, rgba(7, 8, 24, 0.82) 0%, rgba(16, 18, 42, 0.78) 100%);
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.panel {
  max-width: 640px;
  width: 100%;
  margin: auto; /* keeps a tall panel scrollable instead of clipped at the top */
  text-align: center;
  padding: clamp(24px, 5vh, 52px) clamp(20px, 4vw, 48px);
  background: rgba(7, 8, 24, 0.72);
  border: 2px solid rgba(25, 240, 255, 0.35);
  border-radius: 24px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6), 0 0 40px rgba(25, 240, 255, 0.08), inset 0 1px 0 rgba(238, 242, 255, 0.12);
  backdrop-filter: blur(6px);
}

.title {
  font-size: clamp(38px, 7vw, 72px);
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1.02;
  background: linear-gradient(180deg, #ffffff 10%, var(--cyan) 55%, var(--violet) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(25, 240, 255, 0.45));
  margin-bottom: 12px;
}

.title small {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.5em;
  margin-top: 4px;
  background-image: linear-gradient(180deg, #ffd0e6 10%, var(--pink) 90%);
  -webkit-background-clip: text;
  background-clip: text;
}

.title.over {
  background-image: linear-gradient(180deg, #ffd0e6 15%, var(--pink) 60%, #a3132f 100%);
  filter: drop-shadow(0 0 18px rgba(255, 46, 166, 0.45));
}

.hero {
  font-size: clamp(14px, 1.7vw, 18px);
  color: var(--pink);
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  margin: 0 0 12px;
}

.tagline {
  font-size: clamp(15px, 1.8vw, 19px);
  line-height: 1.5;
  color: var(--ink-dim);
  margin-bottom: 20px;
}

.best {
  font-size: clamp(13px, 1.5vw, 16px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--amber);
  margin-bottom: 16px;
}

.controls-list {
  list-style: none;
  text-align: left;
  display: inline-block;
  margin: 0 auto 26px;
  font-size: clamp(14px, 1.7vw, 17px);
  line-height: 2.1;
  color: rgba(238, 242, 255, 0.95);
}

.controls-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.controls-list li > .ctl-icon + span,
.controls-list li > .hazard-dot + span {
  flex: 1 1 0;
  min-width: 0;
}

/* Desktop screens shorter than the start panel (a 1280x800 laptop): tighter
   rhythm so the Start button is on screen without scrolling. */
@media (min-width: 640px) and (max-height: 860px) {
  #start-screen .panel {
    padding: 18px 36px 22px;
  }

  #start-screen .title {
    font-size: clamp(34px, 5vw, 56px);
    margin-bottom: 6px;
  }

  #start-screen .hero {
    margin-bottom: 8px;
  }

  #start-screen .tagline {
    font-size: 15px;
    margin-bottom: 12px;
  }

  #start-screen .controls-list {
    line-height: 1.8;
    margin-bottom: 14px;
  }
}

.controls-list.compact {
  margin-bottom: 14px;
  line-height: 2;
}

kbd {
  display: inline-block;
  min-width: 30px;
  padding: 3px 8px;
  text-align: center;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--night);
  background: linear-gradient(180deg, #ffffff, #b9d8ff);
  border-radius: 6px;
  box-shadow: 0 3px 0 #4a6fa0;
}

.stats-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(16, 18, 42, 0.7);
  border: 1px solid rgba(25, 240, 255, 0.3);
}

.stat-card > span:last-child {
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.record {
  font-size: clamp(15px, 1.9vw, 20px);
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--amber);
  text-shadow: 0 0 14px rgba(255, 176, 32, 0.7);
  margin-bottom: 18px;
}

.note {
  font-size: clamp(13px, 1.5vw, 15px);
  color: rgba(238, 242, 255, 0.65);
  margin-bottom: 20px;
}

.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--night);
  padding: 15px 44px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cyan) 0%, #7dffe0 100%);
  box-shadow: 0 8px 30px rgba(25, 240, 255, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 40px rgba(25, 240, 255, 0.65), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  outline: none;
}

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

.btn-secondary {
  color: var(--ink);
  background: rgba(7, 8, 24, 0.55);
  border: 2px solid rgba(255, 46, 166, 0.55);
  box-shadow: none;
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  box-shadow: 0 8px 30px rgba(255, 46, 166, 0.3);
}

/* Settings rows (language, quality) on the start + pause screens. The two
   sit side by side where there is room and stack on a narrow panel. */
.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  margin-bottom: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.setting-label {
  font-size: clamp(13px, 1.5vw, 15px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(238, 242, 255, 0.65);
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(7, 8, 24, 0.6);
  border: 2px solid rgba(25, 240, 255, 0.3);
}

.seg-btn {
  cursor: pointer;
  pointer-events: auto;
  min-width: 72px;
  min-height: 40px;
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: clamp(13px, 1.5vw, 15px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(238, 242, 255, 0.75);
  background: transparent;
  transition: background 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
}

.seg-btn:hover,
.seg-btn:focus-visible {
  color: var(--ink);
  outline: none;
}

.seg-btn.active {
  color: var(--night);
  background: linear-gradient(135deg, var(--cyan) 0%, #7dffe0 100%);
  box-shadow: 0 4px 14px rgba(25, 240, 255, 0.45);
}

html[data-input="touch"] .seg-btn {
  min-height: 48px;
}

/* ---------- Rotate nudge (touch + portrait) ---------- */

#rotate-hint {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: min(92vw, 440px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 12px 14px;
  background: rgba(7, 8, 24, 0.94);
  border: 2px solid rgba(25, 240, 255, 0.5);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: toast-pop 0.35s ease-out;
}

.rotate-icon {
  width: 40px;
  height: 40px;
  flex: none;
  color: var(--cyan);
}

.rotate-text {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(238, 242, 255, 0.85);
}

.rotate-text strong {
  color: var(--ink);
  font-size: 14px;
}

/* While the card is up, overlay panels start below it instead of under it. */
html.rotate-hint-on .overlay {
  padding-top: calc(144px + var(--safe-top));
}

.link-btn {
  pointer-events: auto;
  cursor: pointer;
  min-height: 44px;
  padding: 8px 14px;
  margin-left: auto;
  border: 2px solid rgba(25, 240, 255, 0.55);
  border-radius: 999px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan);
  touch-action: manipulation;
}

/* ---------- FPS readout (?fps=1) ---------- */

#fps-meter {
  position: absolute;
  bottom: calc(8px + var(--safe-bottom));
  left: calc(8px + var(--safe-left));
  z-index: 40;
  padding: 4px 12px;
  border-radius: 999px;
  font-family: Consolas, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--ink);
  background: rgba(7, 8, 24, 0.75);
  border: 1px solid rgba(25, 240, 255, 0.4);
  pointer-events: none;
  white-space: nowrap;
}

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

@media (max-width: 560px) {
  .controls-list {
    line-height: 2;
  }

  #hud-left {
    gap: 4px;
  }

  #timer {
    padding: 4px 12px;
  }

  #mission-label {
    font-size: 11px;
    padding: 4px 10px;
  }
}

/* Landscape phones: the panel would overflow a ~390px-tall viewport, so the
   story and the actions sit side by side. */
@media (max-height: 520px) and (min-width: 640px) {
  #start-screen .panel,
  #pause-screen .panel {
    max-width: 840px;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    column-gap: 24px;
    align-items: center;
    padding: 14px 22px;
    border-radius: 18px;
  }

  #start-screen .panel-story {
    text-align: left;
  }

  #start-screen .title,
  #pause-screen .title {
    font-size: clamp(26px, 8.5vh, 42px);
    margin-bottom: 4px;
  }

  .title small {
    margin-top: 0;
  }

  .hero {
    font-size: 11px;
    margin: 0 0 6px;
  }

  .tagline {
    font-size: 12.5px;
    line-height: 1.4;
    margin-bottom: 6px;
  }

  .best {
    font-size: 12px;
    margin-bottom: 0;
  }

  .controls-list {
    font-size: 12px;
    line-height: 1.7;
    margin-bottom: 8px;
  }

  .settings {
    margin-bottom: 8px;
    gap: 6px 14px;
  }

  .note {
    margin-bottom: 8px;
  }

  .btn {
    padding: 10px 26px;
    font-size: 15px;
  }

  #over-screen .panel {
    padding: 14px 22px;
  }

  #over-screen .title {
    font-size: clamp(26px, 9vh, 40px);
    margin-bottom: 6px;
  }

  #over-screen .tagline {
    margin-bottom: 10px;
  }

  .stats-grid {
    margin-bottom: 10px;
  }

  .stat-card {
    padding: 8px 14px;
    min-width: 110px;
  }

  .record {
    margin-bottom: 10px;
  }

  #minimap {
    width: 84px;
    height: 84px;
  }
}

/* Portrait phones: tighter vertical rhythm so the start panel fits. */
@media (max-width: 560px) and (orientation: portrait) {
  .panel {
    padding: 20px 16px;
  }

  .title {
    margin-bottom: 8px;
  }

  .tagline {
    font-size: 14px;
    margin-bottom: 14px;
  }

  .controls-list {
    font-size: 13px;
    line-height: 1.8;
    margin-bottom: 16px;
  }

  .settings {
    margin-bottom: 14px;
  }

  #minimap {
    top: auto;
    bottom: calc(210px + var(--safe-bottom));
    left: auto;
    right: calc(12px + var(--safe-right));
    transform: none;
    width: 96px;
    height: 96px;
  }
}

/* ---------- Delivery flash ---------- */

#flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, rgba(230, 255, 255, 0.95), rgba(25, 240, 255, 0.55) 45%, rgba(25, 240, 255, 0) 80%);
  opacity: 0;
  animation: flash-out 0.55s ease-out;
}

@keyframes flash-out {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---------- District label ---------- */

#district-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 12px;
  width: fit-content;
  font-size: clamp(12px, 1.4vw, 15px);
  font-weight: 800;
  color: var(--amber);
  background: rgba(7, 8, 24, 0.5);
  border: 1px solid rgba(255, 176, 32, 0.35);
  border-radius: 999px;
}

#district-label .stat-label {
  font-size: 10px;
}

/* ---------- First-run coaching ---------- */

/* The layer covers the screen but ignores every pointer event, so the
   touch controls under it keep working; only Skip takes a tap. */
#coach {
  position: absolute;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}

#coach-bubble {
  position: absolute;
  top: calc(30% + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, 86vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 20px 12px;
  border-radius: 18px;
  border: 2px solid rgba(25, 240, 255, 0.45);
  background: rgba(7, 8, 24, 0.9);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: coach-in 0.28s ease-out;
}

/* Moved down when the ring is in the upper half, so the bubble never covers
   the pillar it is pointing at. Above the boost meter and the touch buttons. */
#coach.coach-low #coach-bubble {
  top: auto;
  bottom: calc(24% + var(--safe-bottom));
}

#coach-text {
  margin: 0;
  font-size: clamp(14px, 1.9vw, 17px);
  line-height: 1.45;
  color: var(--ink);
}

#coach-skip {
  pointer-events: auto;
}

.btn-small {
  padding: 8px 20px;
  font-size: 14px;
}

/* The ring is moved with a transform from the top-left corner, so width and
   height stay honest and only one property animates. */
#coach-ring {
  position: absolute;
  top: 0;
  left: 0;
  border: 3px solid var(--amber);
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(255, 176, 32, 0.22), 0 0 22px rgba(255, 176, 32, 0.6);
  animation: coach-pulse 1.5s ease-in-out infinite;
}

@keyframes coach-in {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes coach-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #coach-ring { animation: none; opacity: 1; }
  #coach-bubble { animation: none; }
}

/* ---------- Tips, garage and the rescue offer ---------- */

.tip-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  background: radial-gradient(circle at 35% 35%, #fff2c0, var(--amber) 55%, #b86a00);
  box-shadow: 0 0 8px rgba(255, 176, 32, 0.8);
}

.reward-row,
.balance {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 800;
  color: var(--amber);
  margin-bottom: 16px;
}

.panel-wide {
  max-width: 720px;
}

.panel-narrow {
  max-width: 480px;
}

#garage-screen .panel {
  padding: clamp(16px, 3vh, 30px) clamp(18px, 3vw, 34px);
}

#garage-screen .title {
  font-size: clamp(30px, 5vw, 52px);
  margin-bottom: 6px;
}

#garage-screen .tagline {
  margin-bottom: 10px;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  margin-bottom: 18px;
}

/* Name and blurb on the left, level and current effect in the middle, price on
   the right. Fixed columns so every row lines up down the whole list. */
.upgrade {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 7px 14px;
  border-radius: 14px;
  border: 2px solid rgba(25, 240, 255, 0.28);
  background: rgba(16, 18, 42, 0.6);
}

.upgrade.maxed {
  border-color: rgba(255, 176, 32, 0.45);
  background: rgba(52, 38, 14, 0.45);
}

.upgrade-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.upgrade-name {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upgrade-desc {
  font-size: 12px;
  color: rgba(238, 242, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upgrade-meter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.upgrade-value {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
  white-space: nowrap;
}

.upgrade.maxed .upgrade-value {
  color: var(--amber);
}

.upgrade-pips {
  display: flex;
  gap: 3px;
}

.pip {
  width: 11px;
  height: 5px;
  border-radius: 2px;
  background: rgba(238, 242, 255, 0.2);
}

.pip.on {
  background: linear-gradient(90deg, var(--violet), var(--cyan));
}

.upgrade.maxed .pip.on {
  background: linear-gradient(90deg, #fff1b8, var(--amber));
}

.upgrade-buy {
  pointer-events: auto;
  cursor: pointer;
  width: 82px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 999px;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  color: var(--night);
  background: linear-gradient(135deg, var(--amber) 0%, #ffe08a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  touch-action: manipulation;
}

.upgrade-buy:disabled {
  cursor: default;
  opacity: 0.45;
  background: rgba(238, 242, 255, 0.18);
  color: rgba(238, 242, 255, 0.7);
}

html[data-input="touch"] .upgrade-buy {
  min-height: 56px;
}

.btn-quiet {
  opacity: 0.7;
}

/* The rewarded-ad offer. The play triangle says "video" without a word, in
   whichever language the player is reading. */
.btn-reward {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--night);
  background: linear-gradient(135deg, var(--amber) 0%, #ffe08a 100%);
  border: none;
  box-shadow: 0 6px 24px rgba(255, 176, 32, 0.4);
}

.btn-reward:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.ad-badge {
  width: 0;
  height: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}

.btn-col {
  flex-direction: column;
  align-items: stretch;
}

/* Below this the three garage columns stop fitting side by side, so the meter
   and the price move under the name and the row becomes two lines. */
@media (max-width: 520px) {
  .upgrade {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'body body'
      'meter buy';
    gap: 8px 12px;
    padding: 10px 12px;
  }

  .upgrade-body {
    grid-area: body;
  }

  .upgrade-meter {
    grid-area: meter;
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .upgrade-buy {
    grid-area: buy;
  }

  .upgrade-name,
  .upgrade-desc {
    white-space: normal;
  }
}

@media (max-height: 520px) and (min-width: 640px) {
  #garage-screen .panel {
    display: block;
    max-width: 760px;
    padding: 10px 18px;
  }

  #garage-screen .title {
    font-size: 26px;
    margin-bottom: 2px;
  }

  #garage-screen .tagline {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .balance {
    margin-bottom: 8px;
    font-size: 14px;
  }

  .upgrade-list {
    gap: 4px;
    margin-bottom: 8px;
  }

  .upgrade {
    min-height: 40px;
    padding: 4px 12px;
  }

  .upgrade-desc {
    display: none;
  }

  .upgrade-buy {
    min-height: 36px;
  }

  #coach-bubble {
    top: calc(14% + var(--safe-top));
    padding: 8px 14px;
  }

  #coach.coach-low #coach-bubble {
    bottom: calc(30% + var(--safe-bottom));
  }

  #district-label {
    font-size: 11px;
    padding: 2px 10px;
  }
}
