:root {
  --bg: #02040a;
  --panel: rgba(8, 18, 34, 0.96);
  --accent: #62f5ff;
  --accent2: #ff4d6d;
  --essence: #ffd166;
  --text: #e6f7ff;
  --muted: #8aa3b8;
  --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);
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(1rem + var(--safe-top)) calc(1rem + var(--safe-right)) calc(1rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
}

.screen.hidden {
  display: none;
}

#screen-hud {
  display: flex;
  justify-content: space-between;
  padding: 0;
}

#screen-hud.hidden {
  display: none;
}

.screen.overlay {
  z-index: 10;
  pointer-events: none;
}

.screen.overlay .panel {
  pointer-events: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(61, 243, 255, 0.25);
  border-radius: 1rem;
  padding: 2rem;
  max-width: min(90vw, 26rem);
  text-align: center;
  box-shadow: 0 0 30px rgba(61, 243, 255, 0.08);
}

.panel.compact {
  padding: 1.5rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.8rem, 8vw, 3rem);
  color: var(--accent);
  text-shadow: 0 0 18px rgba(98, 245, 255, 0.45);
}

h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.4rem, 6vw, 2rem);
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.meta {
  margin-top: 1rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.help {
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.help p {
  margin: 0.35rem 0;
}

.btn {
  appearance: none;
  border: 1px solid rgba(61, 243, 255, 0.35);
  background: rgba(14, 34, 51, 0.85);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 0.55rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 80ms ease, background 120ms ease, box-shadow 120ms ease;
  min-height: 44px;
}

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

.btn:hover, .btn:focus-visible {
  background: rgba(30, 64, 90, 0.9);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: linear-gradient(180deg, rgba(61, 243, 255, 0.22), rgba(61, 243, 255, 0.08));
  border-color: var(--accent);
  font-weight: 600;
  width: 100%;
  padding: 0.85rem;
}

.btn.dash {
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.22), rgba(255, 209, 102, 0.06));
  border-color: var(--essence);
  color: var(--essence);
  font-weight: 700;
  min-width: 92px;
  min-height: 64px;
  font-size: 1.05rem;
}

.btn.icon {
  font-size: 1.2rem;
  padding: 0.45rem 0.7rem;
}

.hud {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.5rem + var(--safe-top)) calc(0.75rem + var(--safe-right)) 0.5rem calc(0.75rem + var(--safe-left));
  background: linear-gradient(180deg, rgba(2, 4, 10, 0.9), transparent);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.hud.bottom {
  top: auto;
  bottom: 0;
  padding: 0.5rem calc(0.75rem + var(--safe-right)) calc(0.75rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left));
  background: linear-gradient(0deg, rgba(2, 4, 10, 0.92), transparent);
  align-items: flex-end;
  pointer-events: auto;
  flex-wrap: wrap;
}

.hud-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 3.2rem;
}

.hud-group .label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hud-group .value {
  font-size: 1rem;
  font-weight: 700;
}

.hud-group .lives {
  color: var(--accent2);
}

.meters {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.meter-row .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--muted);
  width: 2.2rem;
}

.bar {
  flex: 1;
  height: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 0.5rem;
  overflow: hidden;
  position: relative;
}

.bar .fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #3df3ff);
  transition: width 100ms linear;
}

.bar .notch {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.8);
  left: 50%;
}

.ring {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: conic-gradient(var(--essence) 0%, transparent 0%);
  border: 1px solid rgba(255, 209, 102, 0.4);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

@media (max-width: 460px) {
  .hud.bottom {
    gap: 0.4rem;
    padding-bottom: calc(0.5rem + var(--safe-bottom));
  }
  .hud.bottom .meters {
    flex: 1 1 100%;
    min-width: 0;
    order: 2;
  }
  .hud.bottom .btn {
    padding: 0.45rem 0.6rem;
    font-size: 0.85rem;
    min-height: 40px;
  }
  .btn.dash {
    min-width: 64px;
    min-height: 52px;
    font-size: 0.9rem;
  }
  .meter-row .label {
    width: 1.9rem;
  }
}

@media (min-width: 700px) {
  .hud {
    gap: 1.25rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
  }
  .hud.bottom {
    padding-bottom: calc(1rem + var(--safe-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition-duration: 0.001ms !important;
  }
}
