:root {
  color-scheme: dark;
  --paper: #e9e4d9;
  --orange: #ff4b1f;
  --acid: #d7ff3f;
  --controls-space: 158px;
  --surface-height: min(calc(100dvh - var(--controls-space)), 75vw);
}

* { box-sizing: border-box; }

html,
body,
.game-stage,
button,
button * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--paper);
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.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;
}

.game-stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 360px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #000;
}

.game-surface {
  position: absolute;
  top: calc(50% - var(--controls-space) / 2);
  left: 50%;
  width: calc(var(--surface-height) * 4 / 3);
  height: var(--surface-height);
  overflow: hidden;
  transform: translate(-50%, -50%);
  background: #000;
}

.dos-frame,
.dos-frame > div,
.dos-frame canvas {
  width: 100% !important;
  height: 100% !important;
}

.dos-frame {
  position: absolute;
  inset: 0;
  background: #000;
}

.dos-frame canvas { image-rendering: pixelated; }

.swipe-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  touch-action: none;
  cursor: ns-resize;
}

.scanlines {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.09;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(0, 0, 0, 0.88) 4px);
}

.wordmark,
.status {
  position: absolute;
  z-index: 7;
  top: max(11px, env(safe-area-inset-top));
  text-shadow: 0 2px 12px #000;
  pointer-events: none;
}

.wordmark {
  left: max(12px, env(safe-area-inset-left));
  font-size: clamp(13px, 1.4vw, 20px);
  font-weight: 950;
  letter-spacing: -0.035em;
}

.wordmark span { color: var(--orange); }

.status {
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(233, 228, 217, 0.72);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 11px var(--orange);
}

.status.ready i {
  background: var(--acid);
  box-shadow: 0 0 11px var(--acid);
}

.boot-cover {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 46%, rgba(255, 75, 31, 0.16), transparent 30rem), #050504;
  transition: opacity 300ms ease, visibility 300ms ease;
}

.boot-cover.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-content {
  width: min(600px, 90vw);
  text-align: center;
}

.boot-title {
  color: var(--paper);
  font-size: clamp(50px, 9vw, 120px);
  font-weight: 950;
  letter-spacing: -0.08em;
  line-height: 0.78;
  transform: scaleX(0.9);
}

.boot-title span {
  display: block;
  color: var(--orange);
}

.boot-content p {
  margin: 26px 0 12px;
  color: rgba(233, 228, 217, 0.66);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.load-track {
  width: min(280px, 70%);
  height: 3px;
  margin: 0 auto 22px;
  overflow: hidden;
  background: #282720;
}

.load-track span {
  display: block;
  width: 12%;
  height: 100%;
  background: var(--acid);
  transition: width 300ms ease;
  animation: loading 1.8s ease-in-out infinite;
}

.boot-cover.ready .load-track span {
  width: 100%;
  animation: none;
}

#startButton {
  min-width: min(310px, 86vw);
  min-height: 56px;
  padding: 0 22px;
  color: #080806;
  background: var(--acid);
  border: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0.1em;
  cursor: pointer;
}

#startButton:disabled {
  color: #77736a;
  background: #25231e;
  cursor: wait;
}

.turn-button,
.fire-button,
.restart-button {
  position: absolute;
  z-index: 9;
  display: grid;
  place-items: center;
  border-radius: 999px;
  cursor: pointer;
  touch-action: none;
  backdrop-filter: blur(7px);
  transition: transform 70ms ease, filter 70ms ease;
}

.turn-controls {
  position: absolute;
  z-index: 9;
  top: calc(50% - var(--controls-space) / 2 + var(--surface-height) / 2 + 12px);
  left: 50%;
  display: flex;
  width: calc(var(--surface-height) * 4 / 3);
  max-width: 100vw;
  justify-content: space-between;
  padding: 0 16px;
  transform: translateX(-50%);
  pointer-events: none;
}

.turn-button {
  position: relative;
  top: auto;
  width: clamp(66px, 9vw, 88px);
  height: 52px;
  transform: none;
  color: var(--paper);
  background: rgba(5, 5, 4, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.52);
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 700;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.38);
  pointer-events: auto;
}

.left-button,
.right-button {
  left: auto;
  right: auto;
}

.fire-button {
  top: calc(50% - var(--controls-space) / 2 + var(--surface-height) / 2 + 76px);
  right: auto;
  bottom: auto;
  left: 50%;
  width: clamp(104px, 12vw, 132px);
  height: 52px;
  transform: translateX(-50%);
  color: #090805;
  background: rgba(255, 75, 31, 0.94);
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: clamp(15px, 1.7vw, 22px);
  font-weight: 950;
}

.restart-button {
  top: calc(50% - var(--controls-space) / 2 + var(--surface-height) / 2 + 76px);
  left: 50%;
  width: clamp(170px, 22vw, 220px);
  height: 52px;
  transform: translateX(-50%);
  color: #090805;
  background: var(--acid);
  border: 2px solid rgba(255, 255, 255, 0.68);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55), 0 0 24px rgba(215, 255, 63, 0.2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(11px, 1.4vw, 15px);
  font-weight: 950;
  letter-spacing: 0.08em;
}

.restart-button[hidden] { display: none; }

.game-stage.dead .fire-button {
  opacity: 0;
  pointer-events: none;
}

.turn-button:active,
.turn-button.active {
  transform: scale(0.9);
  color: #090805;
  background: var(--acid);
}

.fire-button:active {
  transform: translateX(-50%) scale(0.9);
  filter: brightness(1.22);
}

.restart-button:active {
  transform: translateX(-50%) scale(0.94);
  filter: brightness(1.12);
}

.gesture-hint {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: calc(50% - var(--controls-space) / 2 + var(--surface-height) / 2 - 38px);
  bottom: auto;
  transform: translateX(-50%);
  transition: opacity 220ms ease;
  pointer-events: none;
}

.gesture-hint.dismissed { opacity: 0; }

.gesture-hint span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  color: rgba(233, 228, 217, 0.82);
  background: rgba(4, 4, 3, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.gesture-hint b { color: var(--acid); font-size: 14px; }

.direction-flash {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: calc(50% - var(--controls-space) / 2 - var(--surface-height) / 2 + 16px);
  padding: 6px 9px;
  color: #080806;
  background: var(--acid);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: 0.1em;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: 90ms ease;
  pointer-events: none;
}

.direction-flash.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes loading {
  from { transform: translateX(-110%); }
  to { transform: translateX(820%); }
}

@media (max-width: 620px) {
  .wordmark { font-size: 13px; }
  .status { font-size: 7px; }
  .turn-button { width: 66px; height: 52px; font-size: 31px; }
  .fire-button { width: 108px; height: 52px; }
  .restart-button { width: 180px; height: 52px; }
  .gesture-hint span { font-size: 7px; }
}

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