:root {
  --bg: #05060a;
  --cyan: #00f0ff;
  --magenta: #ff2bd6;
  --yellow: #ffe14a;
  --ink: #e8fbff;
  --dim: #8aa0b8;
  --pad: max(0.7rem, env(safe-area-inset-top, 0px));
  --pad-x: max(0.7rem, env(safe-area-inset-right, 0px));
  --pad-b: max(0.7rem, env(safe-area-inset-bottom, 0px));
  --pad-l: max(0.7rem, env(safe-area-inset-left, 0px));
}

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

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  user-select: none;
  touch-action: none;
}

body {
  position: relative;
}

#world {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
}

body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 5;
  background: repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 2px,
      rgba(0, 0, 0, 0.22) 3px,
      rgba(0, 0, 0, 0.22) 4px
    ),
    radial-gradient(ellipse at center, transparent 40%, rgba(5, 6, 10, 0.55) 100%);
}

#boot,
#over {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad) var(--pad-x) var(--pad-b) var(--pad-l);
  background: linear-gradient(
    180deg,
    rgba(5, 6, 10, 0.22) 0%,
    rgba(5, 6, 10, 0.72) 55%,
    rgba(5, 6, 10, 0.88) 100%
  );
}

#boot[hidden],
#over[hidden],
#hud[hidden],
#pip[hidden] {
  display: none !important;
}

.boot-inner,
.over-inner {
  text-align: center;
  margin: auto;
  width: min(960px, 100%);
  padding: 1.25rem 0.85rem 1.6rem;
}

.boot-kicker {
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.16em;
  font-size: clamp(0.58rem, 2.6vw, 0.72rem);
  color: var(--magenta);
  text-shadow: 0 0 12px var(--magenta);
  margin-bottom: 0.8rem;
  overflow-wrap: anywhere;
}

#boot h1 {
  font-family: Syne, sans-serif;
  font-weight: 800;
  font-size: clamp(2.4rem, 16vw, 8.5rem);
  line-height: 0.88;
  letter-spacing: 0.02em;
  color: var(--cyan);
  overflow-wrap: anywhere;
  text-shadow:
    0 0 18px var(--cyan),
    0 0 64px rgba(0, 240, 255, 0.55),
    0 0 120px rgba(255, 43, 214, 0.35),
    4px 4px 0 var(--magenta);
}

.boot-sub {
  font-family: Syne, sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 3.4vw, 2rem);
  margin-top: 1rem;
  color: var(--ink);
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

.boot-help {
  margin: 1rem auto 0;
  max-width: 42rem;
  color: var(--dim);
  font-size: clamp(0.68rem, 2.4vw, 0.78rem);
  line-height: 1.65;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.boot-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin: 1.6rem auto 0;
  width: min(22rem, 100%);
  flex-direction: column;
}

button {
  font-family: Syne, sans-serif;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: clamp(0.78rem, 2.8vw, 0.92rem);
  padding: 0.9rem 1.2rem;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  border-radius: 2px;
  cursor: pointer;
  color: var(--bg);
  background: var(--cyan);
  border: 1px solid var(--cyan);
  box-shadow:
    0 0 18px rgba(0, 240, 255, 0.55),
    inset 0 0 12px rgba(255, 255, 255, 0.25);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 28px rgba(0, 240, 255, 0.85);
}

button:active {
  transform: translateY(1px);
}

#btn-keys,
#btn-restart {
  background: transparent;
  color: var(--magenta);
  border-color: var(--magenta);
  box-shadow: 0 0 18px rgba(255, 43, 214, 0.35);
}

#btn-keys:hover,
#btn-restart:hover {
  background: var(--magenta);
  color: var(--bg);
  box-shadow: 0 0 28px rgba(255, 43, 214, 0.8);
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--pad) var(--pad-x) var(--pad-b) var(--pad-l);
  gap: 0.55rem;
}

.hud-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  min-width: 0;
}

.hud-tl,
.hud-tr {
  display: contents;
}

.hud-tr {
  justify-content: flex-end;
  text-align: right;
}

.stat {
  min-width: 0;
  flex: 1 1 0;
  max-width: 11rem;
  padding: 0.55rem 0.65rem;
  background: linear-gradient(180deg, rgba(5, 6, 10, 0.72), rgba(5, 6, 10, 0.28));
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.12);
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.stat .label,
.hud-steer .label {
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  color: var(--magenta);
  margin-bottom: 0.15rem;
}

#speed,
#score,
#hits,
#hand-status {
  font-family: Syne, sans-serif;
  font-weight: 800;
  font-size: clamp(0.95rem, 4.2vw, 1.55rem);
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.7);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

#hand-status {
  font-size: clamp(0.72rem, 3.1vw, 1.05rem);
  letter-spacing: 0.04em;
}

.hud-steer {
  width: min(420px, 100%);
  align-self: center;
  text-align: center;
}

.steer-track {
  position: relative;
  height: 10px;
  margin-top: 0.35rem;
  border: 1px solid rgba(0, 240, 255, 0.45);
  background: linear-gradient(
    90deg,
    rgba(255, 43, 214, 0.35),
    rgba(5, 6, 10, 0.8) 50%,
    rgba(0, 240, 255, 0.35)
  );
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.2);
  overflow: hidden;
}

#steer-bar {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  background: var(--yellow);
  box-shadow: 0 0 12px var(--yellow);
  transform: translateX(0);
}

#pip {
  position: fixed;
  top: max(5.6rem, calc(env(safe-area-inset-top, 0px) + 4.6rem));
  right: var(--pad-x);
  width: min(220px, 38vw);
  aspect-ratio: 4 / 3;
  height: auto;
  z-index: 25;
  border: 1px solid var(--cyan);
  box-shadow:
    0 0 22px rgba(0, 240, 255, 0.35),
    inset 0 0 18px rgba(0, 240, 255, 0.08);
  overflow: hidden;
  background: #000;
  pointer-events: none;
}

#cam,
#hand-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#hand-overlay {
  pointer-events: none;
}

#pip-label {
  position: absolute;
  left: 8px;
  top: 6px;
  z-index: 2;
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
}

#over h2 {
  font-family: Syne, sans-serif;
  font-weight: 800;
  font-size: clamp(2rem, 10vw, 5.4rem);
  color: var(--magenta);
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  text-shadow:
    0 0 18px var(--magenta),
    0 0 60px rgba(255, 43, 214, 0.45);
}

.over-score,
.over-dist {
  margin-top: 0.85rem;
  font-size: clamp(0.85rem, 3vw, 1.05rem);
  letter-spacing: 0.12em;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
}

#over #btn-restart {
  margin-top: 1.6rem;
  width: min(22rem, 100%);
}

@media (min-width: 640px) {
  .boot-actions {
    flex-direction: row;
    width: auto;
  }

  button {
    width: auto;
    padding: 0.95rem 1.7rem;
    letter-spacing: 0.14em;
  }
}

#pads {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 26;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 0 12px max(14px, env(safe-area-inset-bottom));
  pointer-events: auto;
}
#pads[hidden] { display: none !important; }
#pads button {
  min-height: 56px;
  font-size: 1.1rem;
  letter-spacing: 0;
  background: rgba(5, 6, 10, 0.72);
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.45);
  box-shadow: none;
}
#pads button:active,
#pads button.is-down {
  background: var(--cyan);
  color: var(--bg);
}

@media (max-width: 720px) {
  .stat {
    padding: 0.45rem 0.5rem;
    max-width: none;
  }

  #pip {
    width: 88px;
    top: auto;
    bottom: 88px;
    right: 10px;
  }

  .hud-steer {
    margin-bottom: 72px;
  }
}

@media (min-width: 721px) {
  #pads { display: none !important; }
}

@media (max-height: 520px) {
  #boot h1 {
    font-size: clamp(1.6rem, 12vh, 3.2rem);
  }

  .boot-help {
    display: none;
  }

  .boot-sub {
    font-size: 1rem;
    margin-top: 0.45rem;
  }

  .boot-actions {
    margin-top: 0.9rem;
  }
}
