:root {
  color-scheme: dark;
  --page: #171614;
  --panel: #1d1c19;
  --rim: #34322c;
  --edge: #454239;
  --ink: #f2efe3;
  --muted: #aaa599;
  --lime: #cef562;
  --board: #23241f;
  --terminal: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background-image: radial-gradient(ellipse at 51% 0%, #322d23 0, transparent 57%),
    repeating-linear-gradient(0deg, transparent 0 3px, #07070315 3px 4px);
}
button, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--lime); outline-offset: 4px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
kbd { font-family: var(--terminal); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.arcade {
  width: min(1160px, 100% - 72px);
  margin-inline: auto;
  padding-block: 31px 32px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: end;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--edge);
}

.identity {
  display: flex;
  align-items: center;
  gap: 15px;
}

.mark {
  display: grid;
  grid-template: repeat(3, 9px) / repeat(3, 9px);
  gap: 2px;
  color: var(--lime);
}
.mark i { background: currentColor; }
.mark i:nth-child(1) { grid-area: 1 / 2; }
.mark i:nth-child(2) { grid-area: 2 / 1; }
.mark i:nth-child(3) { grid-area: 2 / 2; }
.mark i:nth-child(4) { grid-area: 2 / 3; }

.identity h1 {
  font-family: "Arial Black", Impact, sans-serif;
  font-weight: 950;
  font-size: clamp(3rem, 5.5vw, 4.85rem);
  letter-spacing: -.075em;
  line-height: .84;
}
.subtitle {
  margin-left: 10px;
  border-left: 1px solid var(--edge);
  padding-left: 23px;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .13em;
}
.edition {
  padding-bottom: 3px;
  color: var(--muted);
  font: 600 .8rem var(--terminal);
  letter-spacing: .09em;
  white-space: nowrap;
}
.edition span { margin-left: 10px; color: var(--lime); }

.machine {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.84fr) minmax(0, 1fr);
  grid-template-areas: "setup board stats" "controls controls controls";
  gap: 20px 22px;
  margin-top: 22px;
}

.setup, .console {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  min-width: 0;
  padding: 19px 20px;
  background: var(--panel);
  border: 1px solid var(--rim);
}
.setup { grid-area: setup; }
.console { grid-area: stats; }
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rim);
}
.section-heading h2, .next h2 { font-size: .95rem; font-weight: 650; }
.section-heading span, .screen-bar {
  color: var(--muted);
  font: 600 .77rem var(--terminal);
  letter-spacing: .12em;
}

.settings { margin: 1px 0 0; padding: 0; border: 0; min-width: 0; }
.setting {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: .875rem;
}
.setting select {
  appearance: none;
  min-width: 0;
  width: 100%;
  padding: 9px 33px 9px 11px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: #25241f;
  color: var(--ink);
  cursor: pointer;
  grid-row: 2;
  grid-column: 1;
}
.setting::after {
  content: "";
  grid-row: 2;
  grid-column: 1;
  place-self: center end;
  margin-right: 13px;
  width: 7px;
  height: 7px;
  border-right: 1px solid var(--lime);
  border-bottom: 1px solid var(--lime);
  transform: translateY(-2px) rotate(45deg);
  pointer-events: none;
}
.setting select:hover:enabled { border-color: var(--muted); }
.setting select:disabled { color: #a9a390; cursor: default; }
.settings:disabled .setting::after { opacity: .4; }

.setup-note {
  margin-top: auto;
  padding-top: 18px;
  color: var(--muted);
  font-size: .8rem;
}
.setup-note img {
  display: block;
  width: min(143px, 100%);
  height: auto;
  margin: 0 0 4px -6px;
  mix-blend-mode: screen;
}

.cabinet {
  grid-area: board;
  container-type: inline-size;
  min-width: 0;
  padding: 0 12px;
  background: #26241e;
  border: 1px solid var(--edge);
  box-shadow: 0 10px 30px #0e0c0873, inset 0 0 0 3px #211f19;
}
.screen-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding-inline: 3px;
}
.screen-bar h2 { font: inherit; }
.screen-bar.screen-info {
  min-height: 32px;
  font-weight: 400;
  letter-spacing: .05em;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  letter-spacing: .02em;
}
.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a19b84;
}
.status[data-state="playing"], .status[data-state="ai"] { color: var(--lime); }
.status[data-state="playing"] i, .status[data-state="ai"] i { background: var(--lime); }
.status[data-state="paused"] i { background: #ffd477; }
.status[data-state="over"] i { background: #ff8b7f; }

.screen {
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
  background: #151512;
  border: 1px solid #0d0d0b;
  box-shadow: inset 0 0 0 1px #2d2c25;
}
.well {
  --columns: 10;
  --rows: 20;
  --cell: min(26px, calc((100cqw - 22px) / var(--columns)));
  position: relative;
  width: calc(var(--columns) * var(--cell));
  height: calc(var(--rows) * var(--cell));
  outline: 1px solid #37382d;
  isolation: isolate;
}
.well::after {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: repeating-linear-gradient(0deg, #08080422 0 1px, transparent 1px 4px);
  content: "";
  pointer-events: none;
}
#board { display: block; width: 100%; height: 100%; background: var(--board); }
canvas { image-rendering: pixelated; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 10px;
  background: #10110ded;
}
.overlay:has(.splash-paused:not([hidden])) { background: #10110dcf; }
.splash {
  display: grid;
  justify-items: center;
  gap: clamp(10px, 2vh, 20px);
}
.splash img {
  display: block;
  width: auto;
  max-width: min(100%, 192px);
  height: auto;
  max-height: calc(var(--rows) * var(--cell) - 78px);
  object-fit: contain;
  mix-blend-mode: screen;
  image-rendering: pixelated;
}
.splash-over img { max-width: min(100%, 250px); }
.splash-paused strong { font-size: 1.45rem; letter-spacing: .15em; }
.start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 7px 13px;
  border: 1px solid var(--lime);
  border-radius: 3px;
  background: var(--lime);
  color: #171c0b;
  font-size: .9rem;
  font-weight: 750;
}
.start:hover { background: #e3fc9f; }
.start kbd {
  padding: 2px 5px;
  border: 1px solid #657735;
  border-radius: 2px;
  font-size: .72rem;
}

.scoreboard { padding: 15px 0 14px; border-bottom: 1px solid var(--rim); }
#score {
  display: block;
  color: var(--lime);
  font: 600 clamp(1.45rem, 3.1vw, 2.85rem)/1.1 var(--terminal);
  letter-spacing: .035em;
  overflow-wrap: anywhere;
}
.lines {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: .82rem;
}
.lines output { color: var(--ink); font: 550 .9rem var(--terminal); }

.next {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 8px;
  min-height: 130px;
  padding: 16px 0;
}
.next h2 { padding-top: 1px; }
#preview {
  display: block;
  width: clamp(70px, 7.5vw, 100px);
  height: auto;
  background: #161613;
  border: 1px solid var(--rim);
  border-radius: 2px;
}

.autopilot {
  margin-top: auto;
  padding-top: 17px;
  border-top: 1px solid var(--rim);
}
.ai-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  min-height: 43px;
  border: 1px solid #759140;
  border-radius: 3px;
  background: #282e1d;
  color: var(--lime);
  text-align: left;
  font-size: .95rem;
  font-weight: 650;
}
.ai-button kbd {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 2px;
  background: var(--lime);
  color: #181d10;
}
.ai-button:hover:enabled, .ai-button[aria-pressed="true"] { background: var(--lime); color: #191e11; }
.ai-button:hover:enabled kbd, .ai-button[aria-pressed="true"] kbd { background: #222719; color: var(--lime); }
.autopilot p {
  margin-top: 9px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.55;
}

.controls {
  grid-area: controls;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--rim);
}
.controls > div { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 10px;
  border: 1px solid var(--rim);
  border-radius: 3px;
  background: #23221e;
  font-size: .8rem;
  white-space: nowrap;
  touch-action: none;
  user-select: none;
}
.controls button:hover:enabled { border-color: var(--muted); }
.controls button:active:enabled { background: #39392b; }
.controls button:disabled { opacity: .57; }
.controls kbd {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding-inline: 3px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  color: var(--lime);
  font-size: .92rem;
}

@media (max-width: 1020px) {
  .arcade { width: min(950px, 100% - 36px); }
  .machine { grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr) minmax(0, 1fr); gap: 14px; }
  .setup, .console { padding-inline: 13px; }
  .next { grid-template-columns: 1fr; }
}

@media (max-width: 740px) {
  .arcade { width: min(528px, 100% - 24px); padding-block: 20px 22px; }
  .masthead { padding-bottom: 15px; align-items: center; }
  .identity { gap: 9px; }
  .identity h1 { font-size: 3rem; }
  .mark { grid-template: repeat(3, 6px) / repeat(3, 6px); }
  .subtitle { margin-left: 2px; padding-left: 10px; font-size: .8rem; letter-spacing: .04em; }
  .edition { display: grid; text-align: right; gap: 3px; font-size: .65rem; }
  .edition span { margin: 0; }
  .machine {
    grid-template-columns: minmax(0, 1fr) minmax(0, .43fr);
    grid-template-areas: "board stats" "controls controls" "setup setup";
    gap: 10px;
    margin-top: 14px;
  }
  .cabinet { padding-inline: 5px; }
  .screen-bar { padding-inline: 2px; font-size: .67rem; min-height: 30px; }
  .screen-bar.screen-info { min-height: 27px; }
  .screen { padding: 4px; }
  .well { --cell: min(23px, calc((100cqw - 12px) / var(--columns)), max(13px, calc((100svh - 224px) / var(--rows)))); }
  .splash img { max-width: min(100%, 154px); }
  .splash-over img { max-width: min(100%, 210px); }
  .setup, .console { padding: 11px 8px; }
  .section-heading { padding-bottom: 9px; }
  .section-heading span { display: none; }
  .next { min-height: 0; padding: 12px 0; }
  #preview { width: min(100%, 72px); }
  #score { font-size: clamp(1rem, 4.9vw, 1.6rem); letter-spacing: 0; }
  .scoreboard { padding-block: 10px; }
  .lines { flex-wrap: wrap; gap: 4px; }
  .lines, .autopilot p { font-size: .72rem; }
  .autopilot { padding-top: 10px; }
  .ai-button { flex-wrap: wrap; gap: 5px; padding: 6px 5px; font-size: .76rem; }
  .ai-button kbd { width: 22px; height: 22px; }
  .controls { padding: 7px; flex-direction: column; gap: 6px; }
  .controls > div { gap: 5px; }
  .controls button { min-height: 44px; padding-inline: 3px; }
  .settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; }
  .setting { margin-top: 11px; }
  .setup-note { display: flex; align-items: center; gap: 10px; padding-top: 10px; }
  .setup-note img { width: 86px; margin: 0; }
}

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