:root {
  --bg: #07070d;
  --panel: rgba(14, 14, 26, 0.93);
  --line: #3a3a5a;
  --text: #e8e8f0;
  --dim: #9a9ab8;
  --accent: #ffd24a;
  --danger: #ff6a5a;
  --btn: #26264a;
  --btn-hover: #34346a;
  /* Pixel fonts: --head for titles, buttons and labels, --body for text and fields.
     --k scales all sizes (VT323 in War Games mode runs small). */
  --head: 'Silkscreen', 'Pixelify Sans', system-ui, sans-serif;
  --body: 'Pixelify Sans', system-ui, sans-serif;
  --k: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: calc(16px * var(--k))/1.35 var(--body);
  overflow: hidden;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#screen-wrap { position: relative; }

#screen {
  display: block;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- "War Games" green CRT look ---------- */

.crt-glass { display: none; }

.crt #screen { image-rendering: auto; }

.crt .crt-glass {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* one dark scanline per game pixel row, plus a vignette and glass glare */
  background:
    radial-gradient(ellipse at 30% 20%, rgba(180, 255, 200, 0.06), transparent 40%),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%),
    repeating-linear-gradient(to bottom, transparent 0, transparent 50%, rgba(0, 0, 0, 0.32) 50%, rgba(0, 0, 0, 0.32) 100%);
  background-size: 100% 100%, 100% 100%, 100% calc(100% / 360);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
  animation: crt-flicker 4s infinite steps(1);
}

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  48% { opacity: 0.94; }
  50% { opacity: 1; }
  77% { opacity: 0.97; }
}

@media (prefers-reduced-motion: reduce) {
  .crt .crt-glass { animation: none; }
}

.crt {
  --head: 'VT323', ui-monospace, monospace;
  --body: 'VT323', ui-monospace, monospace;
  --k: 1.3;
  --bg: #000000;
  --panel: rgba(0, 8, 2, 0.94);
  --line: #1d6a30;
  --text: #6dff8f;
  --dim: #2fa04c;
  --accent: #9dffb4;
  --danger: #c8ffd6;
  --btn: #021a08;
  --btn-hover: #063414;
}
.crt body { text-shadow: 0 0 4px rgba(80, 255, 130, 0.55); }
.crt button.big { color: #001a06; background: #5dff84; border-color: #b8ffc9; text-shadow: none; }
.crt button.big:hover, .crt button.big:focus-visible { background: #8dffa8; }
.crt .swatch { filter: grayscale(1) brightness(1.4) sepia(1) hue-rotate(70deg) saturate(4); }
.crt .version { color: #145a24; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  padding: 16px;
  overflow: auto;
  background: rgba(4, 4, 10, 0.25);
}
.overlay.dim { background: rgba(4, 4, 10, 0.6); }
.overlay[hidden] { display: none; }

.panel {
  margin: auto;
  width: 100%;
  max-width: 760px;
  padding: 16px 20px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 4px 4px 0 #000;
}
.panel.small { max-width: 460px; }

.logo {
  display: block;
  margin: 0 auto 4px;
  max-width: 100%;
  image-rendering: pixelated;
}

.sub, .foot, .hint { color: var(--dim); }
.sub { text-align: center; margin: 0 0 12px; }
.foot { margin: 12px 0 0; font-size: calc(14px * var(--k)); }
.error { color: var(--danger); min-height: 1em; margin: 6px 0; white-space: pre-wrap; word-break: break-word; }

h2 { margin: 0 0 6px; color: var(--accent); font: calc(24px * var(--k))/1.2 var(--head); text-transform: uppercase; }
h3 { margin: 12px 0 4px; color: var(--accent); font: calc(16px * var(--k))/1.2 var(--head); text-transform: uppercase; }

button, select, input, textarea {
  font: inherit;
  color: var(--text);
}

button {
  padding: 6px 12px;
  background: var(--btn);
  border: 2px solid var(--line);
  box-shadow: 2px 2px 0 #000;
  font-family: var(--head);
  font-size: calc(14px * var(--k));
  text-transform: uppercase;
  cursor: pointer;
}
button:hover, button:focus-visible { background: var(--btn-hover); border-color: var(--accent); outline: none; }
button:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #000; }
button.big {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  font-size: calc(24px * var(--k));
  color: #1a1206;
  background: var(--accent);
  border-color: #fff0b0;
}
button.big:hover, button.big:focus-visible { background: #ffe07a; }

select, input, textarea {
  background: #0c0c18;
  border: 2px solid var(--line);
  padding: 3px 4px;
  max-width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { width: 100%; font: calc(13px * var(--k))/1.3 ui-monospace, Menlo, Consolas, monospace; resize: vertical; }

.table-wrap { overflow-x: auto; }
table.players { width: 100%; border-collapse: collapse; }
table.players th { text-align: left; color: var(--dim); padding: 2px 4px; font: calc(12px * var(--k)) var(--head); text-transform: uppercase; }
table.players td { padding: 3px 4px; white-space: nowrap; }
table.players input { width: 9.5em; }
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid #000;
  box-shadow: 1px 1px 0 #000;
}

button.remove { padding: 2px 8px; font-size: calc(12px * var(--k)); box-shadow: none; }
button.add { display: block; margin: 6px 0 0; }
button.add[hidden] { display: none; }

/* Graphics: two-way switch (radio buttons styled as one segmented control). */
.gfx { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
.gfx-label { color: var(--dim); font: calc(12px * var(--k)) var(--head); text-transform: uppercase; }
.switch { display: inline-flex; border: 2px solid var(--line); box-shadow: 2px 2px 0 #000; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch label {
  padding: 6px 14px;
  font: calc(14px * var(--k)) var(--head);
  text-transform: uppercase;
  color: var(--dim);
  background: var(--btn);
  cursor: pointer;
}
.switch label + input + label { border-left: 2px solid var(--line); }
.switch input:checked + label { color: #1a1206; background: var(--accent); }
.crt .switch input:checked + label { color: #001a06; background: #5dff84; text-shadow: none; }
.switch input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -4px; }

details.settings { margin-top: 8px; }

.opts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 6px 12px;
  margin: 8px 0 6px;
}
.opts label { display: flex; flex-direction: column; gap: 2px; }
.opts label span { color: var(--dim); font: calc(12px * var(--k)) var(--head); text-transform: uppercase; }

details { margin-top: 12px; border-top: 2px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; color: var(--accent); font-family: var(--head); text-transform: uppercase; }
table.keys { border-collapse: collapse; }
table.keys td { padding: 2px 10px 2px 0; vertical-align: top; }
kbd {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line);
  background: #0c0c18;
  font: inherit;
  white-space: nowrap;
}

.stack { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.version {
  position: fixed;
  right: 6px;
  bottom: 4px;
  color: #44445a;
  font: calc(12px * var(--k)) var(--head);
  pointer-events: none;
}

.noscript { padding: 20px; text-align: center; }

/* ---------- touch controls (phones and tablets) ---------- */

.touch-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 4px 10px;
  width: 100%;
  padding: 4px 6px 2px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.touch-bar[hidden] { display: none; }
.touch-bar.idle button { opacity: 0.4; }
.touch-bar.idle button[data-press="Escape"], .touch-bar.idle #fs-btn { opacity: 1; }

.tgroup { display: flex; flex-wrap: wrap; gap: 4px; max-width: 120px; justify-content: center; }
.tgroup span {
  flex-basis: 100%;
  text-align: center;
  color: var(--dim);
  font: calc(10px * var(--k))/1.2 var(--head);
  text-transform: uppercase;
}
.touch-bar button {
  min-width: 44px;
  height: 40px;
  padding: 0 6px;
  font-size: calc(18px * var(--k));
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.touch-bar button.fire {
  min-width: 84px;
  font-size: calc(18px * var(--k));
  color: #1a1206;
  background: var(--accent);
  border-color: #fff0b0;
}
.crt .touch-bar button.fire { color: #001a06; background: #5dff84; border-color: #b8ffc9; text-shadow: none; }
.touch-bar button.held { background: var(--btn-hover); border-color: var(--accent); }

.rotate-hint { display: none; flex-basis: 100%; margin: 0; text-align: center; color: var(--dim); font-size: calc(13px * var(--k)); }
@media (orientation: portrait) { .rotate-hint { display: block; } }

/* Landscape phone: buttons in two columns left and right of the game screen,
   so the game gets the full screen height. main.js resize() reads --side. */
@media (orientation: landscape) {
  :root { --side: 96px; }
  #app:has(#touch:not([hidden])) {
    display: grid;
    grid-template-columns: var(--side) 1fr var(--side);
    grid-template-rows: repeat(4, 1fr);
    align-items: center;
    justify-items: center;
  }
  #app:has(#touch:not([hidden])) #screen-wrap { grid-column: 2; grid-row: 1 / -1; }
  .touch #touch:not([hidden]) { display: contents; }
  .tgroup.l { grid-column: 1; }
  .tgroup.r { grid-column: 3; }
  /* left column sits low, where the thumb is */
  .tgroup.l:nth-of-type(1) { grid-row: 2; }
  .tgroup.l:nth-of-type(2) { grid-row: 3; }
  .tgroup.l:nth-of-type(3) { grid-row: 4; }
  .tgroup { max-width: var(--side); }
  .touch-bar button { min-width: 42px; height: 42px; }
  .touch-bar button.fire { min-width: 88px; height: 48px; }
}

/* Phones: no zoom-on-focus for form fields, bigger tap targets in the menu. */
.touch select, .touch input { font-size: 16px; }
.touch .panel button { min-height: 36px; }
.touch .overlay { padding: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
.touch .panel { padding: 12px; }
.touch .version { display: none; }
.touch-bar #fs-btn { font-size: calc(12px * var(--k)); padding: 0 4px; }
