:root {
  --bg: #04060c;
  --panel: rgba(8, 12, 24, 0.92);
  --text: #e8ecff;
  --muted: #8b93b8;
  --accent: #4de8ff;
  --accent-2: #7b61ff;
  --danger: #ff4466;
  --success: #44ffaa;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#game-root {
  position: fixed;
  inset: 0;
  touch-action: none;
}

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

#ui-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding:
    calc(var(--safe-top) + 12px)
    calc(var(--safe-right) + 12px)
    calc(var(--safe-bottom) + 12px)
    calc(var(--safe-left) + 12px);
}

#ui-root .screen,
#ui-root .btn,
#ui-root input,
#ui-root select {
  pointer-events: auto;
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(30, 40, 80, 0.35), rgba(4, 6, 12, 0.92));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease;
}

.screen.visible {
  opacity: 1;
  visibility: visible;
}

.screen-panel {
  width: min(92vw, 420px);
  padding: 28px 24px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid rgba(77, 232, 255, 0.15);
  box-shadow: 0 0 40px rgba(77, 232, 255, 0.08);
  text-align: center;
}

.screen-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.screen-title {
  font-size: 1.4rem;
  margin-bottom: 16px;
}

.menu-logo {
  font-size: clamp(2.5rem, 12vw, 4rem);
  letter-spacing: 0.2em;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.menu-sub {
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.menu-tagline {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 24px;
}

.screen-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #041018;
  box-shadow: 0 0 20px rgba(77, 232, 255, 0.25);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.placeholder-text {
  color: var(--muted);
  line-height: 1.6;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: left;
}

.stat-grid span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-grid strong {
  font-size: 1.3rem;
  color: var(--accent);
}

/* Settings */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.setting-row input,
.setting-row select {
  accent-color: var(--accent);
}

/* HUD */
.hud {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.hud.visible {
  opacity: 1;
  visibility: visible;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.hud-score {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 700;
  text-shadow: 0 0 12px rgba(77, 232, 255, 0.4);
}

.hud-combo {
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 600;
}

.hud-bars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.hud-bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.15s linear;
}

.hud-bar.health .hud-bar-fill {
  background: linear-gradient(90deg, var(--danger), #ff8866);
  box-shadow: 0 0 10px rgba(255, 68, 102, 0.5);
}

.hud-bar.energy .hud-bar-fill {
  background: linear-gradient(90deg, #00cc88, var(--success));
  box-shadow: 0 0 10px rgba(68, 255, 170, 0.4);
}

.hud-event {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

.hud-overcharge {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s ease;
  text-shadow: 0 0 16px var(--accent);
}

.hud-overcharge.active {
  opacity: 1;
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.06); }
}

.boot-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: var(--text);
  background: rgba(4, 6, 12, 0.92);
  pointer-events: auto;
}

.boot-error p:first-child {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--danger);
}

.boot-error p:last-child {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-word;
}
