:root {
  color-scheme: dark;
  --ink: #f8f3dc;
  --muted: #a9b2d4;
  --night: #030617;
  --panel: #080d2b;
  --panel-2: #101846;
  --red: #ef2636;
  --red-dark: #a80d27;
  --gold: #ffd43b;
  --blue: #3c8cff;
  --cyan: #58e5ff;
  --stage-ratio: 0.913043;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  background: var(--night);
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(55, 78, 190, 0.32), transparent 42%),
    linear-gradient(180deg, #080d2b 0, #030617 60%);
  font-family: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", ui-monospace, monospace;
  font-weight: 700;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

.back-home {
  display: inline-flex;
  margin: 0 4px 8px;
  color: #a9b2d4;
  font-size: 9px;
  letter-spacing: 0.09em;
  text-decoration: none;
}

.back-home:hover,
.back-home:focus-visible {
  color: var(--gold);
}

.topbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 4px 8px;
}

.brand {
  display: grid;
  gap: 1px;
  line-height: 1;
  letter-spacing: -0.06em;
}

.brand-kicker {
  color: var(--cyan);
  font-size: 8px;
  letter-spacing: 0.28em;
}

.brand strong {
  font-size: clamp(20px, 5.2vw, 30px);
  text-shadow: 3px 3px 0 var(--red-dark);
}

.brand em {
  color: var(--gold);
  font-style: normal;
}

.sound-controls {
  display: flex;
  gap: 7px;
}

.icon-button {
  width: 42px;
  height: 38px;
  border: 2px solid #344175;
  border-radius: 8px;
  color: var(--ink);
  background: linear-gradient(#172153, #0a1035);
  box-shadow: inset 0 1px 0 #5063a1, 0 3px 0 #02040e;
  cursor: pointer;
}

.icon-button[aria-pressed="false"] {
  color: #68729b;
  box-shadow: inset 0 1px 0 #30395f;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 7px;
  margin-bottom: 9px;
}

.scoreboard > div {
  min-width: 0;
  padding: 7px 8px 6px;
  border: 1px solid #293567;
  border-bottom-color: #5a2452;
  border-radius: 7px;
  background: rgba(8, 13, 43, 0.88);
  box-shadow: inset 0 0 12px rgba(74, 105, 255, 0.08);
}

.scoreboard span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(7px, 1.9vw, 10px);
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
}

.scoreboard strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: clamp(15px, 4.2vw, 22px);
  letter-spacing: 0.08em;
  line-height: 1;
}

.scoreboard .objective {
  text-align: center;
}

#lives {
  color: var(--red);
  white-space: nowrap;
}

.game-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 3px solid var(--gold);
  border-radius: 13px;
  background: #02040f;
  box-shadow:
    0 0 0 3px var(--red-dark),
    0 0 30px rgba(255, 211, 59, 0.14),
    inset 0 0 30px #000;
  aspect-ratio: 672 / 736;
  isolation: isolate;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
}

.scanlines {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
  opacity: 0.11;
  background: repeating-linear-gradient(180deg, transparent 0 3px, #000 4px 5px);
  mix-blend-mode: multiply;
}

.game-toast {
  position: absolute;
  z-index: 6;
  top: 14px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 26px);
  padding: 8px 12px;
  border: 2px solid var(--gold);
  border-radius: 5px;
  color: var(--night);
  background: var(--gold);
  font-size: clamp(9px, 2.8vw, 14px);
  letter-spacing: 0.06em;
  text-align: center;
  box-shadow: 4px 4px 0 var(--red-dark);
  transform: translate(-50%, -170%);
  transition: transform 180ms steps(3, end);
  pointer-events: none;
}

.game-toast.show {
  transform: translate(-50%, 0);
}

.game-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 4, 18, 0.83);
  backdrop-filter: blur(3px);
  transition: opacity 160ms ease;
}

.game-overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  width: min(100%, 430px);
  padding: clamp(20px, 5vw, 34px);
  border: 3px solid var(--red);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(#11194b, #070b24);
  box-shadow: 7px 7px 0 #000, inset 0 0 0 2px #5f183a;
  text-align: center;
}

.pixel-ball {
  position: relative;
  width: 66px;
  height: 66px;
  margin: 0 auto 16px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: linear-gradient(#e62032 0 25%, #ffd83d 25% 75%, #e62032 75%);
  box-shadow: 5px 5px 0 #000;
}

.pixel-ball::after {
  content: "";
  position: absolute;
  top: 18px;
  right: -3px;
  width: 37px;
  height: 29px;
  background: #0b1032;
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
}

.pixel-ball span {
  position: absolute;
  z-index: 1;
  top: 11px;
  right: 27px;
  width: 7px;
  height: 7px;
  background: #111;
}

.overlay-eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: 10px;
  letter-spacing: 0.24em;
}

.overlay-card h1 {
  margin: 0;
  color: var(--gold);
  font-size: clamp(24px, 7vw, 42px);
  line-height: 0.96;
  letter-spacing: -0.08em;
  text-shadow: 4px 4px 0 var(--red-dark);
}

.overlay-card > p:not(.overlay-eyebrow) {
  margin: 18px auto;
  color: #d5d9ef;
  font-family: system-ui, sans-serif;
  font-size: clamp(13px, 3.6vw, 16px);
  font-weight: 650;
  line-height: 1.45;
}

.overlay-tip {
  margin: 0 auto 17px;
  padding: 8px;
  border: 1px dashed #58679e;
  color: #9aa6d1;
  font-size: clamp(8px, 2.6vw, 11px);
  letter-spacing: 0.08em;
}

.start-button {
  min-width: 158px;
  padding: 13px 22px 11px;
  border: 0;
  border-radius: 4px;
  color: #1d080d;
  background: var(--gold);
  box-shadow: 0 5px 0 #a86a0a, 0 8px 0 #000;
  font-size: 17px;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.start-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #a86a0a, 0 4px 0 #000;
}

.mobile-controls {
  width: 190px;
  height: 142px;
  margin: 11px auto 4px;
  display: grid;
  grid-template: repeat(3, 44px) / repeat(3, 58px);
  justify-content: center;
  gap: 4px;
  touch-action: none;
  user-select: none;
}

.dpad,
.dpad-center {
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: 8px;
}

.dpad {
  border: 2px solid #364374;
  color: var(--ink);
  background: linear-gradient(#1d285b, #0d1338);
  box-shadow: inset 0 2px 0 #4c5b91, 0 4px 0 #02040e;
  font-size: 19px;
  cursor: pointer;
}

.dpad:active,
.dpad.pressed {
  color: var(--gold);
  background: #121a43;
  box-shadow: inset 0 2px 5px #030617, 0 1px 0 #02040e;
  transform: translateY(3px);
}

.dpad.up { grid-area: 1 / 2; }
.dpad.left { grid-area: 2 / 1; }
.dpad.right { grid-area: 2 / 3; }
.dpad.down { grid-area: 3 / 2; }

.dpad-center {
  grid-area: 2 / 2;
  border: 2px solid #6b182e;
  color: var(--gold);
  background: var(--red-dark);
  box-shadow: inset 0 0 0 4px #d91f35;
  font-size: 11px;
}

.game-help {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  padding: 6px 4px 4px;
  color: #7883ae;
  font-size: 8px;
  letter-spacing: 0.03em;
}

.game-help span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.game-help i {
  display: inline-grid;
  width: 12px;
  height: 12px;
  place-items: center;
  font-style: normal;
}

.legend-team,
.legend-final {
  border: 1px solid #fff;
  border-radius: 50%;
}

.legend-team { background: linear-gradient(#1d8c43 33%, #f7d438 33% 66%, #1d8c43 66%); }
.legend-final { background: linear-gradient(#70bde8 33%, #fff 33% 66%, #70bde8 66%); }
.legend-power { color: var(--gold); }

@media (min-width: 760px) and (min-height: 900px) {
  .app-shell { padding-top: 18px; }
  .mobile-controls { margin-top: 16px; }
}

@media (max-height: 760px) {
  .app-shell { width: min(100%, 560px); }
  .topbar { min-height: 44px; }
  .brand-kicker { display: none; }
  .scoreboard > div { padding-block: 5px; }
  .mobile-controls {
    width: 216px;
    height: 52px;
    grid-template: 46px / repeat(4, 50px);
    gap: 5px;
    margin-top: 8px;
  }
  .dpad.up { grid-area: 1 / 2; }
  .dpad.left { grid-area: 1 / 1; }
  .dpad.down { grid-area: 1 / 3; }
  .dpad.right { grid-area: 1 / 4; }
  .dpad-center { display: none; }
  .game-help { display: none; }
}

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