:root {
  color-scheme: dark;
  --ink: #dfffea;
  --muted: #6f9080;
  --green: #00ff78;
  --green-bright: #70ffa9;
  --panel: rgba(3, 14, 10, .94);
  --line: rgba(65, 255, 142, .2);
  --font: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, Monaco, "Courier New", monospace;
  font-family: var(--font);
  background: #020604;
  color: var(--ink);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 50% 10%, rgba(0, 255, 120, .12), transparent 32rem),
    linear-gradient(rgba(0, 255, 120, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 120, .025) 1px, transparent 1px),
    #020604;
  background-size: auto, 30px 30px, 30px 30px, auto;
}

button { color: inherit; font: inherit; }
button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

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

.rain {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: .1;
  pointer-events: none;
  background-image:
    linear-gradient(180deg, transparent 0 70%, rgba(0, 255, 120, .5)),
    repeating-linear-gradient(90deg, transparent 0 65px, rgba(0, 255, 120, .15) 66px, transparent 67px 132px);
  mask-image: linear-gradient(to bottom, #000, transparent 70%);
}

.game-shell {
  width: 100%;
  max-width: 720px;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  margin-inline: auto;
  padding:
    max(6px, env(safe-area-inset-top))
    max(6px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  overflow: hidden;
}

.game-hud {
  min-width: 0;
  display: grid;
  grid-template-columns: .9fr 1.2fr .65fr 1.15fr .75fr 1fr;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

.game-hud > div {
  min-width: 0;
  min-height: 42px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
}

.game-hud > div:last-child { border-right: 0; }
.game-hud span { color: var(--muted); font-size: 7px; letter-spacing: .12em; }
.game-hud strong { margin-top: 4px; overflow: hidden; color: var(--ink); font-size: clamp(8px, 2.8vw, 13px); line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.game-hud .hud-score strong { color: var(--green-bright); letter-spacing: .03em; text-shadow: 0 0 12px rgba(0, 255, 120, .24); }
.game-hud .hud-brand span { color: var(--green); font-size: 16px; line-height: .65; }
.game-hud .hud-brand strong { color: var(--green); font-size: 7px; letter-spacing: .08em; }
#lives { color: var(--green); font-size: clamp(6px, 2vw, 10px); letter-spacing: 0; }

.game-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  container-type: size;
}

.canvas-frame {
  position: relative;
  width: min(100cqw, calc(100cqh * 17 / 25));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 17 / 25;
  overflow: hidden;
  border: 1px solid rgba(65, 255, 142, .34);
  background: #010503;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .38), 0 0 24px rgba(0, 255, 120, .05);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: crisp-edges;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 0, 0, .32) 4px);
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  padding: clamp(18px, 7vw, 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(circle, rgba(1, 22, 11, .84), rgba(0, 5, 3, .96) 72%);
}

.game-overlay[hidden] { display: none; }

.overlay-symbol {
  width: clamp(42px, 14vw, 60px);
  aspect-ratio: 1;
  margin-bottom: clamp(12px, 4vh, 22px);
  display: grid;
  place-items: center;
  border: 1px solid var(--green);
  color: var(--green);
  font-size: clamp(25px, 8vw, 36px);
  transform: rotate(45deg);
  box-shadow: 0 0 24px rgba(0, 255, 120, .14);
}

.overlay-kicker { margin: 0 0 8px; color: var(--green); font-size: 8px; font-weight: 700; letter-spacing: .2em; }
.game-overlay h2 { margin: 0; font-size: clamp(24px, 8vw, 42px); line-height: .95; letter-spacing: -.06em; }
.game-overlay > p:not(.overlay-kicker) { max-width: 300px; margin: 12px 0 18px; color: var(--muted); font-size: clamp(8px, 2.6vw, 10px); line-height: 1.6; }
.game-overlay small { margin-top: 12px; color: #405c4d; font-size: 7px; letter-spacing: .08em; }

.primary-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--green);
  background: rgba(0, 255, 120, .07);
  color: var(--green-bright);
  box-shadow: inset 0 0 20px rgba(0, 255, 120, .04), 0 0 20px rgba(0, 255, 120, .06);
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .09em;
}

.primary-button:hover,
.primary-button:active { background: var(--green); color: #001a0c; }
.primary-button span { margin-right: 6px; }

.game-controls {
  min-width: 0;
  min-height: 0;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 3px;
  touch-action: none;
}

.dpad button,
.action-buttons button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  background: #06140d;
  color: #7eaa92;
  cursor: pointer;
  touch-action: manipulation;
}

.dpad button:hover,
.dpad button:active,
.action-buttons button:hover,
.action-buttons button:active { border-color: var(--green); color: var(--green); background: rgba(0, 255, 120, .1); }
.dpad [data-direction="up"] { grid-column: 2; }
.dpad [data-direction="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-direction="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-direction="right"] { grid-column: 3; grid-row: 2; }

.action-buttons { display: flex; gap: 6px; }
.action-buttons button { width: 54px; min-height: 54px; }
.action-buttons b,
.action-buttons span { display: block; }
.action-buttons b { color: var(--green); font-size: 18px; line-height: 1; }
.action-buttons span { margin-top: 5px; color: var(--muted); font-size: 7px; letter-spacing: .07em; }

@media (max-height: 640px) and (orientation: portrait) {
  .game-shell { gap: 4px; padding-block: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom)); }
  .game-hud > div { min-height: 36px; padding-block: 4px; }
  .action-buttons button { width: 48px; min-height: 48px; }
  .game-overlay small { display: none; }
  .overlay-symbol { margin-bottom: 10px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .game-shell {
    max-width: 960px;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 27vw);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
  }

  .game-stage { grid-column: 1; grid-row: 1 / 3; }
  .game-hud { grid-column: 2; grid-row: 1; grid-template-columns: repeat(3, 1fr); }
  .game-hud > div:nth-child(3) { border-right: 0; }
  .game-hud > div:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
  .game-controls { grid-column: 2; grid-row: 2; flex-direction: column; justify-content: center; }
}

@media (min-width: 721px) and (min-height: 700px) {
  .game-shell { padding-block: 12px; gap: 10px; }
  .game-hud > div { min-height: 48px; }
  .dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); }
  .dpad button { min-width: 44px; min-height: 44px; }
  .action-buttons button { width: 60px; min-height: 60px; }
}

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