:root {
  color-scheme: dark;
  --ink: #ffffff;
  --muted: #ababab;
  --panel: #000000;
  --line: #575757;
  --vga-blue: #5f63ff;
  --deep-blue: #000067;
  --cobalt: #0000cb;
  --copper: #bf7a4a;
  --copper-light: #ffb080;
  --copper-dark: #5f4020;
  --yellow: #ccc400;
  --green: #07a700;
  --green-dark: #077f00;
  --violet: var(--copper);
  --cyan: var(--vga-blue);
  --red: #e30000;
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: #000000;
  /* Preserve scrolling and pinch zoom, but suppress Safari's double-tap zoom. */
  touch-action: manipulation;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -12%, rgba(95, 99, 255, 0.14) 0, transparent 38rem),
    radial-gradient(circle at 12% 58%, rgba(191, 122, 74, 0.08) 0, transparent 30rem),
    radial-gradient(circle at 12px 18px, rgba(255, 255, 255, 0.24) 0 1px, transparent 1.2px) 0 0 / 101px 89px,
    radial-gradient(circle at 62px 43px, rgba(95, 99, 255, 0.3) 0 1px, transparent 1.2px) 0 0 / 137px 113px,
    linear-gradient(180deg, #000000 0%, #000000 68%, #000067 100%);
  overflow-x: hidden;
}

button,
select,
canvas {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button {
  font: inherit;
}

select {
  font: inherit;
}

.arcade {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--vga-blue);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  letter-spacing: -0.035em;
}

h1 span {
  display: inline-block;
}

.title-red {
  color: var(--red);
  text-shadow: 1px 0 #d70000, 2px 2px #b30000, -1px -1px #000000;
}

.title-green {
  color: var(--green);
  text-shadow: 1px 0 var(--green-dark), 2px 2px #573f1f, -1px -1px #000000;
}

.title-number {
  margin-left: 0.2em;
  color: var(--yellow);
  text-shadow: 1px 0 #b4ac00, 2px 2px #585400, -1px -1px #000000;
}

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

.tool-button,
.language-button,
.pill-button,
.primary-button,
.danger-button,
.close-button {
  min-height: 38px;
  border: 1px solid #676767;
  border-radius: 2px;
  color: var(--ink);
  background: linear-gradient(180deg, #232323, #000000);
  box-shadow:
    inset 1px 1px rgba(255, 255, 255, 0.1),
    inset -1px -1px #000,
    0 3px 0 #000000;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0 12px;
  text-decoration: none;
  font-size: 0.72rem;
}

.language-switcher {
  display: grid;
  grid-template-columns: repeat(2, 32px);
  overflow: hidden;
  min-height: 38px;
  border: 1px solid #676767;
  border-radius: 2px;
  background: #000000;
  box-shadow: inset 1px 1px #2f2f2f, inset -1px -1px #000000;
}

.language-switcher:focus-within {
  box-shadow:
    inset 0 0 0 2px var(--copper-light),
    inset 1px 1px #2f2f2f,
    inset -1px -1px #000000;
}

.language-button {
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #b7b7b7;
  background: transparent;
  box-shadow: none;
  font-size: 0.66rem;
  font-weight: 800;
}

.language-button + .language-button {
  border-left: 1px solid #575757;
}

.language-button[aria-pressed="true"] {
  color: #000;
  background: var(--yellow);
  box-shadow: inset 1px 1px #fff700, inset -1px -1px #736f00;
}

button:hover,
a.tool-button:hover {
  border-color: var(--copper-light);
  background: linear-gradient(180deg, #5f4020, #2a200f);
}

button:active,
a.tool-button:active {
  transform: translateY(3px);
  box-shadow:
    inset 1px 2px #000000,
    inset -1px -1px rgba(255, 255, 255, 0.1),
    0 0 0 #000000;
}

.language-button:active {
  transform: none;
  box-shadow: none;
}

.language-button[aria-pressed="true"]:active {
  box-shadow: inset 1px 1px #fff700, inset -1px -1px #736f00;
}

button:focus-visible,
a.tool-button:focus-visible,
.language-button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--copper-light);
  outline-offset: 3px;
}

.language-button:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid #ffffff;
  outline-offset: -3px;
}

.language-button[aria-pressed="true"]:focus-visible {
  outline-color: #000000;
}

canvas:focus-visible {
  outline: 2px solid var(--copper-light);
  outline-offset: -3px;
}

.cabinet {
  position: relative;
  overflow: hidden;
  padding: clamp(10px, 2vw, 18px);
  border: 2px solid var(--copper-light);
  border-radius: 2px;
  background:
    linear-gradient(90deg, transparent 50%, rgba(255, 176, 128, 0.04) 50%) 0 0 / 6px 6px,
    linear-gradient(135deg, rgba(255, 176, 128, 0.09), transparent 24%),
    linear-gradient(180deg, #2a200f, #000000 34%, #000000);
  box-shadow:
    inset 0 0 0 2px var(--copper),
    inset 0 0 28px #000000,
    0 0 0 2px var(--copper-dark),
    0 0 0 4px #2a200f,
    0 24px 70px rgba(0, 0, 0, 0.72),
    inset 1px 1px #ffd5bf,
    inset -1px -1px #5f4020;
}

.cabinet::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 5px;
  left: 8%;
  width: 39px;
  height: 3px;
  opacity: 0.82;
  background: linear-gradient(
    90deg,
    var(--red) 0 11px,
    #000000 11px 14px,
    var(--green) 14px 25px,
    #000000 25px 28px,
    var(--yellow) 28px 39px
  );
  pointer-events: none;
}

.screen-frame,
.statusbar {
  position: relative;
  z-index: 1;
}

.screen-frame {
  padding: clamp(7px, 1.6vw, 13px);
  border: 2px solid #676767;
  border-top-color: #d3d3d3;
  border-left-color: #b7b7b7;
  border-right-color: #3b3b3b;
  border-bottom-color: #2f2f2f;
  border-radius: 0;
  background: linear-gradient(135deg, #b7b7b7 0%, #676767 30%, #8f8f8f 52%, #3b3b3b 100%);
  box-shadow: inset 2px 2px #efefef, inset -2px -2px #232323, 0 0 0 2px #000000;
}

.screen-glass {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 8 / 5;
  background: #000;
  border-radius: 0;
  box-shadow:
    0 0 0 2px #000,
    0 0 0 3px var(--deep-blue),
    0 0 0 4px var(--vga-blue);
}

.screen-glass::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  box-shadow: inset 0 0 20px #000000;
  pointer-events: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  cursor: default;
}

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

.toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 10px;
  max-width: calc(100% - 24px);
  padding: 5px 9px;
  border: 1px solid var(--copper-light);
  border-radius: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.88);
  font-size: clamp(0.48rem, 1.6vw, 0.72rem);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 5px);
  transition: opacity 150ms ease, transform 150ms ease;
}

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

.pause-menu {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(6px, 2.5%, 14px);
  background: rgba(0, 0, 0, 0.84);
}

.pause-menu-panel {
  width: min(88%, 560px);
  padding: clamp(8px, 2.4%, 16px);
  border: 2px solid var(--copper-light);
  color: #ffffff;
  background: #000000;
  box-shadow: inset 0 0 0 1px var(--copper-dark), 4px 4px 0 rgba(0, 0, 0, 0.72);
  text-align: center;
}

.pause-menu-title {
  margin-bottom: 4px;
  color: var(--yellow);
  font-size: clamp(0.7rem, 2.4vw, 1rem);
  font-weight: 800;
  letter-spacing: 0.12em;
}

.pause-menu-note {
  margin-bottom: clamp(6px, 1.8%, 12px);
  color: #d3d3d3;
  font-size: clamp(0.48rem, 1.5vw, 0.68rem);
  line-height: 1.35;
}

.pause-menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px, 1.2vw, 8px);
}

.pause-menu-actions button {
  min-height: clamp(30px, 5.5vw, 38px);
  padding: 3px 8px;
  font-size: clamp(0.48rem, 1.45vw, 0.68rem);
  line-height: 1.15;
}

.pause-menu-actions .pause-abandon {
  grid-column: 1 / -1;
}

.statusbar {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 1px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid #676767;
  border-radius: 0;
  background: var(--deep-blue);
  box-shadow: inset 1px 1px #b7b7b7, inset -1px -1px #2f2f2f;
}

.statusbar span {
  min-width: 0;
  padding: 9px 11px;
  border-top: 2px solid var(--cobalt);
  background: linear-gradient(180deg, #000067, #000000);
}

.statusbar small,
.statusbar strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar small {
  margin-bottom: 2px;
  color: var(--yellow);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.statusbar strong {
  color: #fff;
  font-size: 0.76rem;
  text-shadow: 1px 1px var(--deep-blue);
}

.controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 18px;
}

.dpad {
  display: grid;
  grid-template: repeat(3, 52px) / repeat(3, 52px);
  gap: 4px;
}

.control {
  border: 1px solid #676767;
  border-radius: 2px;
  color: #fff;
  background: linear-gradient(135deg, #575757, #232323 55%);
  box-shadow: inset 1px 1px #b7b7b7, inset -1px -1px #000, 0 3px 0 #000000;
  font-size: 1rem;
  touch-action: none;
}

.control.up { grid-area: 1 / 2; }
.control.left { grid-area: 2 / 1; }
.control.center { grid-area: 2 / 2; color: var(--yellow); }
.control.right { grid-area: 2 / 3; }
.control.down { grid-area: 3 / 2; }

.quick-actions {
  display: grid;
  gap: 10px;
}

.pill-button {
  min-width: 138px;
  padding: 0 14px;
  font-size: 0.7rem;
}

.key-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.8;
  text-align: center;
}

kbd {
  padding: 2px 5px;
  border: 1px solid var(--copper);
  border-bottom-color: var(--copper-light);
  border-radius: 0;
  color: #fff;
  background: #000000;
  box-shadow: inset 1px 1px #3b3b3b;
}

dialog {
  width: min(700px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 22px;
  border: 2px solid var(--copper-light);
  border-radius: 2px;
  color: var(--ink);
  background: #000000;
  box-shadow: 0 0 0 2px var(--copper-dark), 0 30px 120px #000;
}

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

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

dialog.dialog-fallback[open] {
  position: fixed;
  z-index: 20;
  inset: 16px;
  margin: auto;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.78), 0 0 0 2px var(--copper-dark);
}

.fullscreen-exit {
  position: absolute;
  z-index: 6;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: var(--copper-light);
  background: rgba(0, 0, 0, 0.88);
  font-size: 1.25rem;
}

.arcade:fullscreen {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: #000000;
}

.arcade:fullscreen .cabinet {
  width: min(1040px, 100%, calc((100vh - 150px) * 1.6));
  width: min(1040px, 100%, calc((100dvh - 150px) * 1.6));
  margin-right: auto;
  margin-left: auto;
}

.arcade:fullscreen .key-hint {
  display: none;
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.dialog-heading h2 {
  margin-bottom: 0;
}

.close-button {
  width: 40px;
  padding: 0;
  font-size: 1.4rem;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 22px 0;
}

.help-grid section {
  padding: 14px;
  border: 1px solid #676767;
  border-radius: 0;
  background: linear-gradient(180deg, #232323, #000000);
}

.help-grid h3 {
  margin-bottom: 7px;
  color: var(--yellow);
  font-size: 0.78rem;
}

.help-grid p {
  margin-bottom: 0;
  color: #d3d3d3;
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
  line-height: 1.55;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 22px 0 14px;
}

.settings-field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid #676767;
  color: var(--yellow);
  background: linear-gradient(180deg, #232323, #000000);
  font-size: 0.72rem;
}

.settings-field select {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--copper);
  border-radius: 0;
  color: #ffffff;
  background: #000000;
  font: inherit;
}

.volume-field output {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.volume-field input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--yellow);
  cursor: pointer;
}

.settings-note {
  margin: 0 0 20px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  line-height: 1.5;
}

.settings-actions {
  justify-content: flex-end;
}

.primary-button,
.danger-button {
  padding: 0 16px;
  font-size: 0.72rem;
}

.primary-button {
  color: #000;
  border-color: var(--yellow);
  background: var(--yellow);
  font-weight: 800;
}

.danger-button {
  color: #ff0000;
  border-color: #a70000;
}

@media (hover: hover) and (pointer: fine) and (min-width: 701px) and (max-height: 880px) {
  .arcade:not(:fullscreen) {
    width: min(1040px, 100%, max(620px, calc(160vh - 200px)));
    width: min(1040px, 100%, max(620px, calc(160dvh - 200px)));
    padding-top: 8px;
    padding-bottom: 12px;
  }

  .arcade:not(:fullscreen) .eyebrow {
    display: none;
  }

  .arcade:not(:fullscreen) .topbar {
    gap: 12px;
    margin-bottom: 8px;
  }

  .arcade:not(:fullscreen) .cabinet {
    padding: 10px;
  }

  .arcade:not(:fullscreen) .screen-frame {
    padding: 7px;
  }

  .arcade:not(:fullscreen) .statusbar span {
    padding: 6px 9px;
  }

  .arcade:not(:fullscreen) .key-hint {
    display: none;
  }
}

@media (hover: none), (pointer: coarse) {
  .controls {
    display: flex;
  }

  .key-hint {
    display: none;
  }

  .tool-button,
  .language-switcher,
  .language-button,
  .pill-button {
    min-height: 44px;
  }
}

@media (max-width: 700px) {
  .arcade {
    padding-top: 14px;
  }

  .topbar {
    align-items: center;
  }

  #help-button,
  #editor-link,
  #fullscreen-button {
    width: 38px;
    overflow: hidden;
    padding: 0 10px;
    white-space: nowrap;
  }

  .statusbar {
    grid-template-columns: repeat(4, 1fr);
  }

  .statusbar span:first-child {
    display: none;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .arcade {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .cabinet {
    padding: 8px;
  }

  .screen-frame {
    padding: 4px;
  }

  .cabinet::before {
    top: 3px;
    height: 2px;
    opacity: 0.64;
  }
}

@media (max-width: 430px) {
  .topbar {
    gap: 8px;
  }

  .tool-button {
    width: 38px !important;
    overflow: hidden;
    padding: 0 10px;
    white-space: nowrap;
  }

  .tool-button > span:not([aria-hidden="true"]) {
    display: none;
  }

  .controls {
    gap: 12px;
  }

  .dpad {
    grid-template: repeat(3, 46px) / repeat(3, 46px);
  }

  .pill-button {
    min-width: 112px;
    padding: 0 8px;
    font-size: 0.62rem;
  }

  .statusbar span {
    padding: 7px;
  }

  dialog {
    padding: 17px;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
