/* Neon Racer — UI styling. Dark glassmorphism over a synthwave scene.
   CSS keys off html[data-input] for keyboard vs touch wording, and off
   #touch-controls.active for the touch layer during a run. */

:root {
  --neon-cyan: #00f0ff;
  --neon-pink: #ff2d95;
  --neon-amber: #ffb347;
  --ink: #0d0118;
  --panel: rgba(16, 6, 36, 0.82);
  --text: #efe8ff;
  --text-dim: #b7a8d8;
  --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 {
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
}

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

.hidden {
  display: none !important;
}

/* ---------- device-specific wording ---------- */
html[data-input='keyboard'] .only-touch {
  display: none;
}
html[data-input='touch'] .only-keyboard {
  display: none;
}

/* ---------- overlays (start / pause / game over) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 40%, rgba(43, 10, 74, 0.35), rgba(13, 1, 24, 0.78));
  z-index: 30;
  overflow-y: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 18px;
  box-shadow:
    0 0 24px rgba(0, 240, 255, 0.18),
    0 0 64px rgba(255, 45, 149, 0.12),
    inset 0 0 32px rgba(0, 240, 255, 0.04);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 28px 30px;
  max-width: 520px;
  width: 100%;
  text-align: center;
}

.title {
  font-size: clamp(34px, 7vw, 56px);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fff;
  text-shadow:
    0 0 8px var(--neon-cyan),
    0 0 22px var(--neon-cyan),
    0 0 46px rgba(0, 240, 255, 0.6);
}
.title.over {
  font-size: clamp(24px, 5vw, 38px);
  text-shadow:
    0 0 8px var(--neon-pink),
    0 0 22px var(--neon-pink),
    0 0 46px rgba(255, 45, 149, 0.6);
}

.hero {
  margin-top: 6px;
  color: var(--neon-amber);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-shadow: 0 0 12px rgba(255, 179, 71, 0.55);
}

.tagline {
  margin-top: 12px;
  color: var(--text-dim);
  line-height: 1.55;
  font-size: 15px;
}

.best-line {
  margin-top: 10px;
  color: var(--neon-cyan);
  font-weight: 700;
  letter-spacing: 0.04em;
  min-height: 1.2em;
}

.controls-list {
  list-style: none;
  margin: 18px 0;
  text-align: left;
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.controls-list.compact {
  margin: 14px 0 0;
}
.controls-list li {
  display: block;
  line-height: 1.55;
}
.controls-list kbd,
.controls-list .gem,
.controls-list .hazard-dot,
.controls-list .pad-icon,
.controls-list .ctl-icon {
  vertical-align: middle;
  margin-right: 5px;
}

kbd {
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid rgba(0, 240, 255, 0.5);
  border-radius: 6px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--neon-cyan);
  box-shadow: 0 2px 0 rgba(0, 240, 255, 0.25);
}

.gem {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: var(--neon-cyan);
  transform: rotate(45deg);
  border-radius: 3px;
  box-shadow: 0 0 8px var(--neon-cyan);
}
.gem.small {
  width: 11px;
  height: 11px;
}

.hazard-dot {
  width: 13px;
  height: 13px;
  display: inline-block;
  background: #ff2d55;
  border-radius: 3px;
  box-shadow: 0 0 8px #ff2d55;
}

.pad-icon {
  width: 16px;
  height: 12px;
  display: inline-block;
  background: var(--neon-amber);
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
  box-shadow: 0 0 8px var(--neon-amber);
}

.ctl-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.5);
}
.ctl-icon.drag {
  border-radius: 50%;
  border-style: dashed;
}
.ctl-icon.jump {
  border-radius: 50%;
  border-color: var(--neon-amber);
  box-shadow: 0 0 8px rgba(255, 179, 71, 0.5);
}
.ctl-icon.drift {
  border-radius: 4px;
  border-color: var(--neon-pink);
  box-shadow: 0 0 8px rgba(255, 45, 149, 0.5);
}

.quality-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 6px 0 16px;
  flex-wrap: wrap;
}
.quality-label {
  color: var(--text-dim);
  font-size: 13px;
}
.seg {
  display: flex;
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 10px;
  overflow: hidden;
}
.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 9px 16px;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn + .seg-btn {
  border-left: 1px solid rgba(0, 240, 255, 0.25);
}
.seg-btn.active {
  background: rgba(0, 240, 255, 0.18);
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
}

.btn {
  background: linear-gradient(135deg, var(--neon-pink), #b3127f);
  border: none;
  border-radius: 12px;
  color: #fff;
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 14px 34px;
  min-height: 52px;
  cursor: pointer;
  box-shadow:
    0 0 18px rgba(255, 45, 149, 0.55),
    0 4px 0 #6d0a50;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active {
  transform: translateY(3px);
  box-shadow:
    0 0 18px rgba(255, 45, 149, 0.55),
    0 1px 0 #6d0a50;
}
.btn-secondary {
  background: transparent;
  border: 1px solid rgba(0, 240, 255, 0.5);
  color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.2);
  font-size: 15px;
}
.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.note {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-bottom: 10px;
}

.big-score {
  font-size: clamp(44px, 10vw, 72px);
  font-weight: 800;
  color: #fff;
  text-shadow:
    0 0 10px var(--neon-cyan),
    0 0 34px var(--neon-cyan);
  margin: 8px 0 2px;
}

.record {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 16px;
  border: 1px solid var(--neon-amber);
  border-radius: 999px;
  color: var(--neon-amber);
  font-weight: 800;
  letter-spacing: 0.12em;
  font-size: 13px;
  text-shadow: 0 0 10px rgba(255, 179, 71, 0.7);
  box-shadow: 0 0 16px rgba(255, 179, 71, 0.3);
  animation: recordPulse 1.1s ease-in-out infinite;
}
@keyframes recordPulse {
  50% {
    transform: scale(1.07);
    box-shadow: 0 0 26px rgba(255, 179, 71, 0.55);
  }
}

.stats {
  color: var(--text-dim);
  margin: 8px 0 16px;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
#hud button {
  pointer-events: auto;
}

#hud-top-left {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(14px + var(--safe-left));
}
#score-value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-shadow:
    0 0 8px var(--neon-cyan),
    0 0 22px rgba(0, 240, 255, 0.55);
}
#speed-row {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
#speed-row #speed-value {
  color: var(--neon-amber);
  font-size: 17px;
  text-shadow: 0 0 8px rgba(255, 179, 71, 0.6);
}

#lives {
  display: flex;
  gap: 6px;
  margin-top: 7px;
}
#lives .pip {
  width: 15px;
  height: 15px;
  transform: rotate(45deg);
  border-radius: 3px;
  background: var(--neon-pink);
  box-shadow: 0 0 9px var(--neon-pink);
  transition: opacity 0.25s, background 0.25s;
}
#lives .pip.off {
  background: transparent;
  border: 1px solid rgba(255, 45, 149, 0.4);
  box-shadow: none;
  opacity: 0.45;
}

#hud-top-right {
  position: absolute;
  top: calc(10px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(0, 240, 255, 0.4);
  background: rgba(16, 6, 36, 0.6);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: var(--neon-cyan);
}
.icon-btn svg [fill='none'],
.icon-btn svg path[fill='none'] {
  stroke: var(--neon-cyan);
}
#mute-button .spk-off {
  display: none;
}
#mute-button.muted .spk-on {
  display: none;
}
#mute-button.muted .spk-off {
  display: block;
}
#mute-button.muted {
  border-color: rgba(255, 45, 149, 0.55);
}
#mute-button.muted svg * {
  fill: var(--neon-pink);
  stroke: var(--neon-pink);
}
#mute-button.muted svg path[fill='none'] {
  fill: none;
}

#crystal-counter {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 19px;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
}

#boost-meter {
  position: absolute;
  bottom: calc(18px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 179, 71, 0.6);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}
#boost-meter.on {
  opacity: 1;
}
#boost-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-amber), #ff5e3a);
  box-shadow: 0 0 12px var(--neon-amber);
  transform-origin: left;
  transform: scaleX(0);
}

#toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  background: rgba(16, 6, 36, 0.85);
  border: 1px solid rgba(255, 45, 149, 0.5);
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 0 10px var(--neon-pink);
  box-shadow: 0 0 20px rgba(255, 45, 149, 0.3);
  animation: toastPop 0.25s ease;
  white-space: nowrap;
  max-width: 92vw;
}
@keyframes toastPop {
  from {
    transform: translateX(-50%) scale(0.8);
    opacity: 0;
  }
}

#controls-hint {
  position: absolute;
  bottom: calc(10px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  opacity: 0.85;
}
html[data-input='touch'] #controls-hint {
  bottom: auto;
  top: calc(64px + var(--safe-top));
}

/* ---------- touch layer ---------- */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: none;
}
html[data-input='touch'] #touch-controls.active {
  display: block;
}

#steer-zone {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#steer-indicator {
  position: absolute;
  bottom: calc(96px + var(--safe-bottom));
  left: 50%;
  width: 54px;
  height: 5px;
  border-radius: 999px;
  background: var(--neon-cyan);
  box-shadow: 0 0 14px var(--neon-cyan);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#steer-indicator.held {
  opacity: 0.9;
}

#jump-button,
#brake-button {
  position: absolute;
  bottom: calc(20px + var(--safe-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: none;
}
#jump-button {
  right: calc(18px + var(--safe-right));
  border: 2px solid var(--neon-amber);
  background: rgba(255, 179, 71, 0.16);
  color: var(--neon-amber);
  box-shadow: 0 0 18px rgba(255, 179, 71, 0.35);
}
#jump-button.pressed {
  background: rgba(255, 179, 71, 0.45);
  color: #fff;
}
#brake-button {
  left: calc(18px + var(--safe-left));
  border: 2px solid var(--neon-pink);
  background: rgba(255, 45, 149, 0.14);
  color: var(--neon-pink);
  box-shadow: 0 0 18px rgba(255, 45, 149, 0.3);
}
#brake-button.pressed {
  background: rgba(255, 45, 149, 0.4);
  color: #fff;
}

/* ---------- FPS meter (?fps=1) ---------- */
#fps-meter {
  position: absolute;
  bottom: calc(8px + var(--safe-bottom));
  right: calc(10px + var(--safe-right));
  z-index: 40;
  font: 12px/1.4 monospace;
  color: #9ff;
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: 6px;
  pointer-events: none;
}

/* ---------- small screens ---------- */
@media (max-width: 560px) {
  .panel {
    padding: 20px 18px;
  }
  #score-value {
    font-size: 27px;
  }
  .icon-btn {
    width: 56px;
    height: 56px;
  }
}

/* Portrait phones: HUD reads top-down, panels get breathing room. */
@media (orientation: portrait) {
  #controls-hint {
    white-space: normal;
    text-align: center;
    max-width: 86vw;
  }
}
