:root {
  color-scheme: dark;
  --ink: #f6f7ff;
  --muted: #9aa6d1;
  --panel: rgba(13, 20, 61, 0.78);
  --line: rgba(126, 151, 255, 0.28);
  --gold: #ffd928;
  --cyan: #37e8ff;
  --bg: #050716;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: clamp(12px, 3vw, 32px);
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(39, 61, 154, 0.38), transparent 42%),
    linear-gradient(rgba(55, 232, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(55, 232, 255, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 32px 32px, 32px 32px, auto;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

.game-shell {
  width: min(100%, 620px);
  margin: 0 auto;
}

.brand,
.hud,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { gap: 16px; margin-bottom: 12px; }
.eyebrow, .mini-title {
  margin: 0 0 3px;
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: clamp(1.8rem, 7vw, 3.2rem); font-style: italic; line-height: 0.92; letter-spacing: -0.06em; }
h1 span { color: var(--gold); text-shadow: 0 0 24px rgba(255, 217, 40, 0.35); }

.icon-button,
.primary-button,
.control {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(13, 20, 61, 0.92);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-button { padding: 9px 12px; border-radius: 999px; color: var(--muted); font-size: 0.78rem; font-weight: 750; }
.icon-button:hover { border-color: var(--cyan); color: var(--ink); }

.hud {
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
}

.hud > div { display: grid; gap: 2px; text-align: center; }
.hud-label { color: var(--muted); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.hud strong { font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }
#lives { color: var(--gold); letter-spacing: 0.15em; }

.game-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(89, 116, 255, 0.46);
  border-radius: 18px;
  background: #030612;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.5), 0 0 35px rgba(41, 79, 255, 0.11);
}

canvas {
  display: block;
  width: min(100%, 504px);
  height: auto;
  max-height: 68vh;
  max-height: 68dvh;
  object-fit: contain;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 18, 0.68);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card {
  width: min(100%, 370px);
  padding: clamp(20px, 6vw, 34px);
  border: 1px solid rgba(55, 232, 255, 0.34);
  border-radius: 18px;
  background: rgba(9, 15, 48, 0.94);
  text-align: center;
  box-shadow: 0 0 45px rgba(55, 232, 255, 0.12);
}
.overlay h2 { margin: 3px 0 10px; color: var(--gold); font-size: clamp(2rem, 10vw, 3.7rem); font-style: italic; letter-spacing: -0.06em; text-transform: uppercase; }
.overlay p:not(.mini-title) { margin: 0 auto 20px; color: #c5ccec; line-height: 1.55; }
.primary-button {
  min-width: 150px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #11131e;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 0 28px rgba(255, 217, 40, 0.25);
}
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }

.mobile-controls {
  display: none;
  justify-items: center;
  margin-top: 12px;
  padding-bottom: max(2px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.joystick {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.joystick:active { cursor: grabbing; }
.joystick:focus-visible { outline: 3px solid var(--cyan); outline-offset: 4px; }

.joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(91, 132, 255, 0.54);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(55, 232, 255, 0.13) 0 8%, transparent 9%),
    radial-gradient(circle, rgba(19, 33, 91, 0.92) 0 52%, rgba(8, 14, 43, 0.92) 53% 100%);
  box-shadow:
    inset 0 0 25px rgba(55, 232, 255, 0.09),
    0 10px 30px rgba(0, 0, 0, 0.3);
}
.joystick-base::before,
.joystick-base::after {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 72%;
  height: 1px;
  content: "";
  background: rgba(126, 151, 255, 0.16);
  transform: translate(-50%, -50%);
}
.joystick-base::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.joystick-knob {
  --stick-x: 0px;
  --stick-y: 0px;
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.68);
  border-radius: 50%;
  background: linear-gradient(145deg, #ffe74d, #f5b900);
  color: #121522;
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 950;
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.42), 0 0 22px rgba(255, 217, 40, 0.18);
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  transition: transform 90ms ease, box-shadow 120ms ease;
  will-change: transform;
}
.joystick.active .joystick-knob {
  border-color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.48), 0 0 30px rgba(255, 217, 40, 0.34);
  transition: box-shadow 120ms ease;
}
.joystick-knob span { pointer-events: none; }
.joystick-hint {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

footer { display: block; margin-top: 14px; color: var(--muted); font-size: 0.72rem; line-height: 1.5; text-align: center; }
footer p { margin: 3px; }
footer strong { color: #dbe0fa; }
.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 (hover: none), (max-width: 720px) {
  .mobile-controls { display: grid; }
  canvas { max-height: 56vh; max-height: 56dvh; }
}

@media (max-width: 430px) {
  body { padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left)); }
  .brand { align-items: end; }
  .eyebrow { font-size: 0.58rem; }
  .hud { padding-inline: 10px; }
  .hud strong { font-size: 0.86rem; }
  .joystick { width: 116px; height: 116px; }
  .joystick-knob { width: 52px; height: 52px; }
  footer { margin-top: 8px; }
}

@media (hover: none) and (orientation: landscape) and (max-height: 600px) {
  body { padding-block: 7px; }
  .brand { margin-bottom: 6px; }
  .hud { margin-bottom: 6px; padding-block: 6px; }
  canvas { max-height: 79vh; max-height: 79dvh; }
  .mobile-controls {
    position: fixed;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 5;
    margin: 0;
  }
  .joystick { width: 108px; height: 108px; }
  .joystick-knob { width: 48px; height: 48px; }
  .joystick-hint, footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
