:root {
  color-scheme: dark;
  --black: #050505;
  --blue: #0000ab;
  --blue-bright: #5757ff;
  --red: #e51d26;
  --red-bright: #ff5757;
  --yellow: #ffff57;
  --gray: #ababab;
  --gray-dark: #575757;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--white);
  background:
    linear-gradient(90deg, rgba(0, 0, 171, 0.12) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(229, 29, 38, 0.06) 1px, transparent 1px) 0 0 / 24px 24px,
    radial-gradient(circle at 50% 12%, #181818 0, #070707 48%, #020202 100%);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button {
  appearance: none;
  border: 1px solid var(--gray-dark);
  color: var(--white);
  background: #101010;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
button:focus-visible {
  color: var(--yellow);
  border-color: var(--yellow);
  outline: none;
}

.app-shell {
  width: min(100%, 1030px);
  margin: 0 auto;
  padding: 18px clamp(10px, 3vw, 28px) 28px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 10px;
  width: min(100%, 960px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  line-height: 1;
}

.brand > span {
  color: var(--red);
  font: 900 clamp(25px, 5vw, 46px) Georgia, serif;
  letter-spacing: -0.07em;
  text-shadow: 2px 2px 0 #560000, 0 0 12px rgba(255, 40, 40, 0.22);
}

.brand small {
  color: var(--yellow);
  font-size: clamp(8px, 1.5vw, 12px);
  letter-spacing: 0.12em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.toolbar button {
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px #242424;
  font-size: 11px;
}

.cabinet {
  position: relative;
  width: min(100%, 960px);
  margin: 0 auto;
  padding: clamp(10px, 2vw, 18px);
  border: 2px solid var(--gray-dark);
  background: linear-gradient(145deg, #222 0, #0b0b0b 46%, #171717 100%);
  box-shadow:
    0 0 0 2px #000,
    0 0 0 3px #333,
    0 18px 55px rgba(0, 0, 0, 0.7);
}

.cabinet-stripe {
  position: absolute;
  inset: 3px 3px auto;
  height: 5px;
  background: linear-gradient(90deg, var(--red) 0 32%, var(--yellow) 32% 38%, var(--blue) 38% 100%);
  opacity: 0.86;
}

.screen-bezel {
  padding: clamp(8px, 1.7vw, 15px);
  border: 1px solid #474747;
  background: #020202;
  box-shadow: inset 0 0 20px #000, 0 0 0 1px #000;
}

.screen-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 8 / 5;
  background: #000;
  border: 1px solid #1f1f1f;
}

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

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

.scanlines {
  opacity: 0.13;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.7) 2px 3px);
}

.glass {
  background: linear-gradient(118deg, rgba(255,255,255,0.055), transparent 22%, transparent 72%, rgba(255,255,255,0.02));
  box-shadow: inset 0 0 38px rgba(0, 0, 0, 0.45);
}

.cabinet-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 3px 0;
  color: var(--gray);
  font-size: clamp(8px, 1.4vw, 11px);
  letter-spacing: 0.03em;
}

.cabinet-footer span:last-child {
  color: var(--yellow);
  text-align: right;
}

.mobile-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 15px 4px 2px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 47px);
  gap: 5px;
}

.dpad button,
.action-button {
  touch-action: none;
  border: 1px solid #666;
  background: linear-gradient(#252525, #0d0d0d);
  box-shadow: inset 0 0 0 1px #050505, 0 3px 0 #000;
  font-weight: 800;
}

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

.action-button {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  color: var(--yellow);
  border-color: var(--red);
  font-size: 23px;
}

dialog {
  width: min(92vw, 570px);
  color: var(--white);
  border: 2px solid var(--yellow);
  border-radius: 2px;
  background: #080808;
  box-shadow: 0 18px 70px #000;
  font-size: 14px;
  user-select: text;
  -webkit-user-select: text;
}

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

dialog h2 {
  margin: 3px 34px 15px 0;
  color: var(--red-bright);
}

.dialog-close {
  float: right;
  width: 32px;
  height: 32px;
  font-size: 20px;
}

.help-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 9px 15px;
  margin: 18px 0;
}

kbd {
  min-width: 76px;
  padding: 4px 7px;
  color: var(--yellow);
  border: 1px solid var(--gray-dark);
  background: var(--blue);
  text-align: center;
}

.help-note {
  margin-bottom: 3px;
  color: var(--gray);
  font-size: 12px;
  line-height: 1.45;
}

@media (hover: none), (pointer: coarse), (max-width: 720px) {
  .mobile-controls { display: flex; }
  .app-shell { padding-top: 10px; }
  .cabinet-footer { flex-direction: column; gap: 5px; }
  .cabinet-footer span:last-child { text-align: left; }
}

@media (max-width: 520px) {
  .topbar { align-items: flex-start; }
  .brand { display: block; }
  .brand small { display: block; margin-top: 5px; }
  .toolbar button { min-height: 32px; padding: 5px 8px; font-size: 9px; }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 43px); }
  .action-button { width: 68px; height: 68px; }
}

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