:root {
  --me: #7cf29c;
  --station: #7cf29c;
  --bg: #0d1a12;
  --fg: #eef6ee;
  --dim: #8fa894;
  --panel: #16271c;
  /* Safari's swipe-back gesture can't be blocked, so controls stay clear of the sides. */
  --edge: max(24px, env(safe-area-inset-left), env(safe-area-inset-right));
  color-scheme: dark;
}

/* Lockdown: nothing on this page scrolls, zooms, selects or calls out. */
html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

input { user-select: text; -webkit-user-select: text; }

.hidden { display: none !important; }
.fill { position: absolute; inset: 0; width: 100%; height: 100%; }

.screen {
  position: absolute;
  inset: 0;
  padding: max(12px, env(safe-area-inset-top)) var(--edge) max(12px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }

h1 { margin: 0; font-size: 34px; letter-spacing: 0.5px; }
h2 { margin: 0 0 10px; font-size: 20px; }
.sub { margin: 0; color: var(--dim); font-size: 18px; }
.fine { margin: 0; color: var(--dim); font-size: 13px; }

button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 2px solid #2c4733;
  border-radius: 14px;
  padding: 10px 18px;
  touch-action: manipulation;
}
button.big { font-size: 22px; font-weight: 700; padding: 14px 40px; background: #2f7d43; border-color: #46a35e; }
button:active { filter: brightness(1.3); }

#room { text-transform: uppercase; letter-spacing: 6px; }
#name, #room {
  font: inherit;
  font-size: 20px;
  width: min(320px, 80vw);
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid #2c4733;
  background: #0a140e;
  color: var(--fg);
  text-align: center;
}

.host-link { color: var(--me); font-weight: 700; text-decoration: none; margin-top: 6px; }

.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid #2c4733; border-top-color: var(--me);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- lobby --- */
#screen-lobby { display: flex; flex-direction: column; }
#roles { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; min-height: 0; }
.role {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  text-align: left; border-width: 3px; padding: 12px; min-height: 0; overflow: hidden;
}
.role-title { font-size: 22px; font-weight: 800; }
.role-blurb { font-size: 13px; color: var(--dim); flex: 1; }
.role-who { font-size: 15px; font-weight: 700; }
.role.mine { background: #24412c; box-shadow: 0 0 0 3px var(--me) inset; }
.role.taken { opacity: 0.55; }
.lobby-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; }
@media (orientation: portrait) {
  #roles { grid-template-columns: 1fr 1fr; }
}

/* --- stations --- */
#screen-station { padding: 0; }
#station { position: absolute; inset: 0; }
#station-bar {
  position: absolute; top: max(6px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; pointer-events: none;
}
#station-bar button { pointer-events: auto; padding: 4px 12px; font-size: 18px; border-radius: 10px; }
#station-name { font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: var(--station); }

.station { position: absolute; inset: 0; display: flex; gap: 10px; padding: 50px var(--edge) max(14px, env(safe-area-inset-bottom)); box-sizing: border-box; }
.zone {
  position: relative; flex: 1; border-radius: 22px; border: 3px solid color-mix(in srgb, var(--station) 45%, transparent);
  background: color-mix(in srgb, var(--station) 12%, var(--bg));
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  transition: background 0.06s;
}
.zone.on { background: color-mix(in srgb, var(--station) 55%, var(--bg)); }
.zone-label { font-size: 26px; font-weight: 900; letter-spacing: 3px; opacity: 0.45; pointer-events: none; }
.zone-col { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.driver .stick-zone { flex: 1.15; }
.driver .boost { --station: #ffd166; }
.driver .brake { --station: #ff6b6b; }
.stick-base {
  position: absolute; width: 150px; height: 150px; margin: -75px 0 0 -75px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--station) 70%, transparent); pointer-events: none;
}
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 70px; height: 70px; margin: -35px 0 0 -35px; border-radius: 50%;
  background: var(--station); opacity: 0.85;
}

.spray { flex-direction: column; gap: 14px; text-align: center; padding: 0 20px; }
.big-title { font-size: 44px; font-weight: 900; letter-spacing: 6px; color: var(--station); pointer-events: none; }
.hint { color: var(--dim); font-size: 14px; pointer-events: none; }

.scanner, .spotter { padding-top: 46px; }
.sonar { position: relative; flex: 1; }
.legend { position: absolute; left: var(--edge); bottom: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--dim); pointer-events: none; }
.spotter-sonar { position: relative; flex: 1.3; display: flex; }
.spotter-spray { position: relative; flex: 1; display: flex; }
.spotter .legend { left: 4px; }

/* --- overlays --- */
.badge {
  position: fixed; right: var(--edge); top: max(6px, env(safe-area-inset-top));
  font-size: 12px; color: var(--dim); background: #0008; padding: 2px 8px; border-radius: 8px; pointer-events: none;
}
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
#flash.go { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 0.35; } to { opacity: 0; } }

/* iPhone Safari can't lock orientation, so ask nicely during play. */
#rotate { display: none; }
@media (orientation: portrait) {
  body[data-screen="station"] #rotate {
    display: flex; position: fixed; inset: 0; z-index: 10; flex-direction: column; align-items: center; justify-content: center;
    background: var(--bg); font-size: 20px;
  }
  /* The sprayer works in any grip; its screen is just a big hold-to-spray pad. */
  body[data-screen="station"]:has(.station.sprayer) #rotate { display: none; }
}
.rotate-icon { font-size: 72px; animation: tip 1.6s ease-in-out infinite; }
@keyframes tip { 50% { transform: rotate(-90deg); } }
