:root {
  color-scheme: dark;
  --black: #050505;
  --panel: #111111;
  --steel-0: #2f2f2f;
  --steel-1: #4b4b4b;
  --steel-2: #7f7f7f;
  --steel-3: #b7b7b7;
  --blue: #00008b;
  --red: #cb0000;
  --yellow: #e4d800;
  --green: #074f00;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--black);
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(127, 127, 127, 0.2), transparent 38rem),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 5px),
    #050505;
  color: #d3d3d3;
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 18px 20px 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 12px;
  max-width: 960px;
}

.wordmark {
  display: flex;
  align-items: baseline;
  filter: drop-shadow(0 3px 0 #000);
  font-family: Georgia, serif;
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 900;
  letter-spacing: -0.1em;
  line-height: 0.9;
}

.wordmark span:nth-child(odd) { color: var(--yellow); }
.wordmark span:nth-child(even) { color: var(--red); }

.wordmark small {
  margin-left: 0.75em;
  color: var(--steel-3);
  font-family: "Courier New", monospace;
  font-size: 0.2em;
  letter-spacing: 0.1em;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.toolbar button,
.dialog-close {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--steel-2);
  border-radius: 3px;
  background: linear-gradient(#3b3b3b, #191919);
  box-shadow: inset 0 1px #b7b7b7, 0 2px 0 #000;
  color: #f0e96b;
}

.toolbar button:active,
.dialog-close:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px #111;
}

.console {
  position: relative;
  padding: 10px 12px 12px;
  border: 1px solid #676767;
  border-radius: 7px;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,0.08) 48%, transparent 52%),
    repeating-linear-gradient(0deg, #292929 0 2px, #1b1b1b 2px 4px);
  box-shadow:
    inset 0 0 0 2px #101010,
    inset 0 0 0 4px #4b4b4b,
    0 18px 55px #000;
}

.console-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1px 6px 8px;
  color: #d3d3d3;
  font-size: 10px;
  letter-spacing: 0.12em;
}

.console-label i {
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--blue));
}

.screen-bezel {
  padding: clamp(8px, 1.6vw, 15px);
  border: 2px solid #0c0c0c;
  border-radius: 5px;
  background: linear-gradient(145deg, #737373, #202020 18%, #111 82%, #676767);
  box-shadow:
    inset 2px 2px #b7b7b7,
    inset -2px -2px #000;
}

.screen-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  width: 100%;
  border: 2px solid #000;
  border-radius: 2px;
  background: #000;
  box-shadow: 0 0 24px rgba(0, 0, 139, 0.2);
  touch-action: none;
}

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

.scanlines,
.screen-glare {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scanlines {
  opacity: 0.12;
  background: repeating-linear-gradient(0deg, transparent 0 3px, #000 3px 4px);
}

.screen-glare {
  background: linear-gradient(115deg, rgba(255,255,255,0.06), transparent 23%, transparent 72%, rgba(255,255,255,0.025));
}

.mobile-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 13px 8px 3px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 44px);
}

.dpad button,
.fire-button {
  border: 1px solid #7f7f7f;
  background: linear-gradient(#4b4b4b, #1b1b1b);
  box-shadow: inset 0 1px #b7b7b7, 0 3px #000;
  color: #e4d800;
  touch-action: none;
}

.dpad button:active,
.dpad button.active,
.fire-button:active,
.fire-button.active {
  transform: translateY(2px);
  background: linear-gradient(#1a1a1a, #343434);
  box-shadow: inset 0 1px #000, 0 1px #000;
}

.dpad button[data-control="up"] { grid-column: 2; grid-row: 1; border-radius: 5px 5px 0 0; }
.dpad button[data-control="left"] { grid-column: 1; grid-row: 2; border-radius: 5px 0 0 5px; }
.dpad button[data-control="down"] { grid-column: 2; grid-row: 3; border-radius: 0 0 5px 5px; }
.dpad button[data-control="right"] { grid-column: 3; grid-row: 2; border-radius: 0 5px 5px 0; }

.fire-button {
  width: 82px;
  height: 82px;
  border-color: #bf0000;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #e23b31, #8b0000 58%, #3b0000);
  color: #fff3a0;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.fire-button span,
.fire-button small { display: block; }
.fire-button small { margin-top: 3px; color: #d3d3d3; font-size: 9px; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 6px 0;
  color: #e4d800;
  font-size: 11px;
}

footer .credit {
  color: #8f8f8f;
  text-align: right;
}

dialog {
  width: min(92vw, 540px);
  border: 2px solid #7f7f7f;
  border-radius: 4px;
  background: #111;
  box-shadow: inset 0 0 0 2px #2f2f2f, 0 18px 80px #000;
  color: #d3d3d3;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(2px);
}

dialog form { position: relative; padding: 8px 14px 14px; }
dialog h2 { margin: 6px 38px 14px 0; color: #e4d800; }
dialog p { line-height: 1.5; }

.dialog-close {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 34px;
  padding: 5px 9px;
  color: #fff;
}

.help-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 14px;
  align-items: center;
  margin: 18px 0;
}

kbd {
  padding: 3px 7px;
  border: 1px solid #676767;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #292929;
  color: #f0e96b;
  font: inherit;
  font-size: 12px;
}

.help-note { color: #b7b7b7; font-size: 13px; }

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  .app-shell { padding: 10px 8px 18px; }
  .topbar { align-items: center; }
  .wordmark { font-size: 34px; }
  .toolbar button { min-height: 34px; padding: 6px 9px; font-size: 11px; }
  .console { padding: 8px; }
  .console-label { font-size: 8px; }
  .screen-bezel { padding: 7px; }
  .mobile-controls { display: flex; }
  footer { font-size: 9px; }
  footer .credit { display: none; }
}

@media (max-width: 430px) {
  .topbar { margin-bottom: 8px; }
  .wordmark small { display: none; }
  .toolbar { gap: 5px; }
  .console-label span:first-child { display: none; }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 41px); }
  .fire-button { width: 74px; height: 74px; }
}

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