:root {
  color-scheme: dark;
  --bg: #080b0a;
  --grid: #123a2d;
  --line: #4cff9c;
  --hot: #ff6b4a;
  --text: #d6ffe7;
  --muted: #78a88f;
  --panel: #0d1512;
  --edge: #1f5c45;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

html,
body,
#game,
.touch-controls,
.touch-controls button {
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(76, 255, 156, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 50% -10%, #183126, transparent 44rem),
    var(--bg);
  background-size: 100% 4px, auto, auto;
  color: var(--text);
  font-family: "Trebuchet MS", Arial, sans-serif;
}

button {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(320px, 960px) 280px;
  gap: 18px;
  width: min(1280px, calc(100vw - 32px));
  min-height: min(720px, calc(100vh - 32px));
  align-items: stretch;
}

.viewport-wrap {
  position: relative;
  display: grid;
  min-height: 420px;
  border: 1px solid var(--edge);
  background: #020403;
  box-shadow: 0 0 30px rgba(76, 255, 156, 0.16);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(2, 4, 3, 0.74);
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  margin: 0;
  color: var(--line);
  font-size: clamp(2.6rem, 8vw, 6.8rem);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(76, 255, 156, 0.72);
}

.overlay p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.overlay button {
  min-width: 130px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: #09140f;
  color: var(--line);
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: inset 0 0 12px rgba(76, 255, 156, 0.2), 0 0 18px rgba(76, 255, 156, 0.2);
}

.overlay button:hover,
.overlay button:focus-visible {
  outline: 0;
  background: #102318;
}

.touch-controls {
  position: absolute;
  inset: auto 0 18px;
  z-index: 1;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  pointer-events: none;
}

.touch-controls button {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: 56px;
  border: 1px solid var(--line);
  background: rgba(9, 20, 15, 0.76);
  color: var(--line);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
  box-shadow: inset 0 0 12px rgba(76, 255, 156, 0.16), 0 0 16px rgba(76, 255, 156, 0.16);
  pointer-events: auto;
  user-select: none;
}

.touch-controls button:active {
  background: rgba(76, 255, 156, 0.22);
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 8px;
}

.touch-pad [data-touch="forward"] {
  grid-column: 2;
}

.touch-pad [data-touch="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-pad [data-touch="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-pad [data-touch="back"] {
  grid-column: 2;
  grid-row: 3;
}

.fire-button {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  text-transform: uppercase;
}

.panel {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(13, 21, 18, 0.94), rgba(5, 9, 7, 0.94));
}

.brand {
  color: var(--line);
  font-size: 1.4rem;
  font-weight: 800;
  text-transform: uppercase;
}

.readouts {
  display: grid;
  gap: 10px;
}

.readouts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  border-bottom: 1px solid rgba(76, 255, 156, 0.22);
}

.readouts span,
.controls dt {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.readouts strong {
  color: var(--line);
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.35rem;
}

#radar {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--edge);
  background: #030604;
}

.damage-meter {
  display: grid;
  gap: 8px;
}

.damage-segments {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  min-height: 18px;
}

.damage-segments span {
  border: 1px solid rgba(76, 255, 156, 0.45);
  background: rgba(76, 255, 156, 0.18);
  box-shadow: inset 0 0 8px rgba(76, 255, 156, 0.12);
}

.damage-segments span.filled {
  background: var(--line);
  box-shadow: 0 0 10px rgba(76, 255, 156, 0.48);
}

.damage-segments span.low {
  border-color: rgba(255, 107, 74, 0.72);
  background: rgba(255, 107, 74, 0.2);
}

.damage-segments span.low.filled {
  background: var(--hot);
  box-shadow: 0 0 10px rgba(255, 107, 74, 0.52);
}

.controls {
  display: grid;
  align-content: start;
  gap: 12px;
  margin: 0;
}

.controls div {
  display: grid;
  gap: 4px;
}

.controls dd {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}

@media (max-width: 880px) {
  body {
    align-items: start;
    padding: 12px 0;
  }

  .shell {
    grid-template-columns: 1fr;
    width: min(100vw - 24px, 720px);
  }

  .panel {
    grid-template-columns: 1fr 180px;
    grid-template-rows: auto auto;
  }

  .brand,
  .readouts,
  .damage-meter,
  .controls {
    grid-column: 1;
  }

  #radar {
    grid-column: 2;
    grid-row: 1 / span 3;
  }
}

@media (max-width: 560px) {
  .panel {
    grid-template-columns: 1fr;
  }

  #radar {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (hover: none), (pointer: coarse) {
  body {
    overscroll-behavior: none;
  }

  .touch-controls {
    display: flex;
  }

  .controls {
    display: none;
  }

  .viewport-wrap,
  #game {
    min-height: min(68dvh, 520px);
  }
}
