:root {
  --bg: #0b0f14;
  --bg-deep: #071019;
  --text: #e6f2ff;
  --text-dim: rgba(230, 242, 255, 0.72);
  --primary: #00ff88;
  --primary-deep: #00cc77;
  --accent: #ff4d6d;
  --accent-soft: rgba(255, 77, 109, 0.2);
  --secondary: #37d7ff;
  --grid-line: #1a2733;
  --panel: rgba(10, 14, 20, 0.62);
  --panel-strong: rgba(7, 12, 18, 0.78);
  --border: rgba(130, 214, 255, 0.2);
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.5);
  --button-shadow: 0 12px 30px rgba(0, 255, 136, 0.14);
  --focus: 0 0 0 2px rgba(0, 255, 136, 0.95);
  --radius-sm: 12px;
  --radius-lg: 20px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --transition: 150ms ease-out;
  --hud-top: max(16px, env(safe-area-inset-top));
  --hud-right: max(16px, env(safe-area-inset-right));
  --hud-bottom: max(16px, env(safe-area-inset-bottom));
  --hud-left: max(16px, env(safe-area-inset-left));
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(0, 255, 136, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(55, 215, 255, 0.1), transparent 25%),
    linear-gradient(180deg, #061019 0%, #0b0f14 48%, #05080d 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: calc(var(--hud-top) + 10px) calc(var(--hud-right) + 8px)
    calc(var(--hud-bottom) + 10px) calc(var(--hud-left) + 8px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  isolation: isolate;
}

.ambient {
  position: absolute;
  inset: auto;
  width: 42vmax;
  height: 42vmax;
  border-radius: 999px;
  filter: blur(48px);
  pointer-events: none;
  opacity: 0.34;
  z-index: -1;
}

.ambient-a {
  top: -10%;
  left: -8%;
  background: rgba(0, 255, 136, 0.18);
}

.ambient-b {
  right: -10%;
  bottom: -18%;
  background: rgba(55, 215, 255, 0.16);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 160px)) auto;
  gap: 12px;
  align-items: stretch;
  pointer-events: none;
}

.stat-card,
.icon-button,
.overlay-panel,
.dpad-button,
.pause-fab {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.stat-card {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(10, 16, 23, 0.88), rgba(10, 14, 20, 0.62));
  box-shadow: 0 10px 24px var(--shadow);
  display: grid;
  gap: 6px;
}

.stat-card--minor {
  background: linear-gradient(180deg, rgba(9, 13, 18, 0.88), rgba(10, 14, 20, 0.5));
}

.stat-label {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stat-value {
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  justify-self: end;
  align-self: start;
  pointer-events: auto;
  padding: 0 18px;
  min-height: 52px;
  border-radius: 999px;
  background: rgba(7, 12, 18, 0.72);
  border: 1px solid rgba(0, 255, 136, 0.2);
  color: var(--text);
  transition:
    transform var(--transition),
    background var(--transition),
    border-color var(--transition);
}

.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(10, 18, 25, 0.88);
  border-color: rgba(0, 255, 136, 0.38);
}

.scene-shell {
  position: relative;
  min-height: min(74vh, calc(100vh - 160px));
  border-radius: clamp(22px, 3vw, 34px);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(11, 15, 20, 0.26), rgba(6, 9, 13, 0.5)),
    radial-gradient(circle at top, rgba(55, 215, 255, 0.06), transparent 40%);
  border: 1px solid rgba(130, 214, 255, 0.16);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 30px 60px var(--shadow-strong);
}

.scene-shell canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 22%),
    radial-gradient(circle at center, transparent 55%, rgba(0, 0, 0, 0.3) 100%);
  pointer-events: none;
}

.reticle {
  position: absolute;
  inset: 24px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: calc(clamp(22px, 3vw, 34px) - 10px);
  pointer-events: none;
}

.overlay-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(520px, calc(100% - 32px));
  padding: 24px 24px 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(9, 14, 19, 0.82), rgba(7, 12, 18, 0.66));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.42),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  transform: translate(-50%, -50%);
  transition:
    opacity 180ms ease-out,
    transform 180ms ease-out,
    visibility 180ms ease-out;
}

.overlay-panel.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -46%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--secondary);
}

.panel-title {
  margin: 0;
  font-size: clamp(32px, 6vw, 56px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.panel-copy {
  margin: 14px 0 0;
  max-width: 42ch;
  color: var(--text-dim);
  line-height: 1.6;
}

.panel-stats {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.panel-stat {
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: grid;
  gap: 6px;
}

.panel-stat span {
  font-size: 12px;
  color: var(--text-dim);
}

.panel-stat strong {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.panel-actions {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.primary-button,
.ghost-button,
.dpad-button,
.pause-fab {
  min-height: 44px;
  border-radius: 14px;
  transition:
    transform var(--transition),
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
}

.primary-button,
.ghost-button {
  padding: 0 18px;
  min-width: 140px;
}

.primary-button {
  background: linear-gradient(180deg, var(--primary), var(--primary-deep));
  color: #03150d;
  font-weight: 800;
  box-shadow: var(--button-shadow);
}

.primary-button:hover,
.pause-fab:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.ghost-button:active,
.dpad-button:active,
.pause-fab:active,
.is-pressed {
  transform: scale(0.97);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.ghost-button:hover,
.dpad-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.control-legend {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  font-size: 13px;
  color: rgba(230, 242, 255, 0.64);
}

.mobile-controls {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0 calc(var(--hud-right) + 6px) calc(var(--hud-bottom) + 6px)
    calc(var(--hud-left) + 6px);
  display: none;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
}

.dpad {
  position: relative;
  width: 176px;
  height: 176px;
}

.dpad-button,
.pause-fab {
  pointer-events: auto;
  background: rgba(8, 13, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.32);
}

.dpad-button {
  position: absolute;
  width: 68px;
  height: 68px;
  font-size: 22px;
}

.dpad-up {
  top: 0;
  left: 54px;
}

.dpad-left {
  top: 54px;
  left: 0;
}

.dpad-right {
  top: 54px;
  right: 0;
}

.dpad-down {
  bottom: 0;
  left: 54px;
}

.pause-fab {
  min-width: 88px;
  padding: 0 20px;
  min-height: 54px;
  border-radius: 999px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .app-shell {
    gap: 14px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .icon-button {
    justify-self: stretch;
  }

  .scene-shell {
    min-height: min(70vh, calc(100vh - 220px));
  }
}

@media (max-width: 599px), (pointer: coarse) {
  .app-shell {
    padding-top: calc(var(--hud-top) + 6px);
    gap: 10px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 10px 12px;
  }

  .stat-card--minor {
    order: 3;
  }

  .stat-label {
    font-size: 11px;
  }

  .stat-value {
    font-size: 16px;
  }

  .icon-button {
    order: 4;
    min-height: 42px;
    padding: 0 14px;
  }

  .overlay-panel {
    width: min(480px, calc(100% - 20px));
    top: 44%;
    max-height: calc(100% - 20px);
    padding: 18px 16px 16px;
    overflow: auto;
  }

  .panel-title {
    font-size: clamp(28px, 10vw, 40px);
  }

  .panel-copy {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.45;
  }

  .panel-stats {
    margin-top: 14px;
    gap: 8px;
  }

  .panel-stat {
    padding: 10px 12px;
  }

  .panel-stat strong {
    font-size: 22px;
  }

  .panel-actions {
    margin-top: 16px;
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
    min-height: 46px;
  }

  .control-legend {
    margin-top: 14px;
    gap: 6px;
    font-size: 12px;
  }

  .mobile-controls {
    display: flex;
  }

  .dpad {
    width: 144px;
    height: 144px;
  }

  .dpad-button {
    width: 54px;
    height: 54px;
    font-size: 20px;
  }

  .dpad-up {
    left: 45px;
  }

  .dpad-left,
  .dpad-right {
    top: 45px;
  }

  .dpad-right {
    right: 0;
  }

  .dpad-down {
    left: 45px;
  }

  .pause-fab {
    min-width: 80px;
    min-height: 48px;
    padding: 0 18px;
  }
}

@media (max-width: 420px) {
  .dpad {
    width: 132px;
    height: 132px;
  }

  .dpad-button {
    width: 50px;
    height: 50px;
  }

  .dpad-up,
  .dpad-down {
    left: 41px;
  }

  .dpad-left,
  .dpad-right {
    top: 41px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .ambient {
    opacity: 0.18;
    filter: blur(30px);
  }
}
