:root {
  --bg: #080b11;
  --fg: #e8eef8;
  --muted: #7f8ea8;
  --accent: #38bdf8;
  --escape: #2ee59d;
  --danger: #ff4d6d;
  --warn: #fbbf24;
  --surface: rgba(13, 18, 28, 0.78);
  --border: rgba(255, 255, 255, 0.1);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html,
body {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

.safe-area-probe {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  pointer-events: none;
  visibility: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

body.is-playing #stage {
  cursor: none;
}

/* Minimal top telemetry bar */
.hud {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  height: 44px;
  padding: 0 max(14px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 11, 17, 0.88) 0%, rgba(8, 11, 17, 0) 100%);
  transition: opacity 0.25s ease;
}

body.is-playing .hud {
  opacity: 0.62;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--fg);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

body[data-state="PLAYING"] .brand-dot {
  background: var(--escape);
  box-shadow: 0 0 10px var(--escape);
}

body[data-state="PARKED"] .brand-dot {
  background: var(--warn);
  box-shadow: 0 0 10px var(--warn);
}

body[data-state="CRASHED"] .brand-dot {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
}

.stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 12px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat-value {
  font-weight: 600;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

/* Prevent accidental HUD button hits during active maze run */
body.is-playing .controls {
  pointer-events: none;
}

.pill-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.pill-btn:hover {
  color: var(--fg);
  border-color: rgba(255, 255, 255, 0.26);
}

.pill-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Non-blocking floating prompt */
.banner {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
  text-align: center;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(11, 15, 24, 0.82);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  max-width: min(92vw, 520px);
  transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.25s ease;
}

body[data-state="BOOT"] .banner {
  bottom: 50%;
  transform: translate(-50%, 50%);
  padding: 20px 28px;
  background: rgba(11, 15, 24, 0.9);
}

body[data-state="PLAYING"] .banner {
  opacity: 0;
  transform: translate(-50%, 8px);
}

body[data-state="CRASHED"] .banner {
  border-color: rgba(255, 77, 109, 0.45);
}

body[data-state="ESCAPED"] .banner {
  border-color: rgba(46, 229, 157, 0.5);
}

body[data-state="PARKED"] .banner {
  border-color: rgba(251, 191, 36, 0.5);
}

.banner-headline {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg);
}

body[data-state="BOOT"] .banner-headline {
  font-size: 16px;
  margin-bottom: 4px;
}

body[data-state="CRASHED"] .banner-headline {
  color: var(--danger);
}

body[data-state="ESCAPED"] .banner-headline {
  color: var(--escape);
}

body[data-state="PARKED"] .banner-headline {
  color: var(--warn);
}

.banner-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

@media (max-width: 640px) {
  .hud {
    padding: 0 max(10px, env(safe-area-inset-right, 0px)) 0
      max(10px, env(safe-area-inset-left, 0px));
    gap: 6px;
  }

  .brand-name {
    display: none;
  }

  .stats {
    gap: 9px;
    font-size: 11px;
  }

  .pill-btn {
    font-size: 10px;
    padding: 4px 7px;
  }

  .banner {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 8px 14px;
  }
}
