:root {
  --bg: #120d09;
  --panel: #1d150e;
  --line: #3a2a17;
  --amber: #ffb000;
  --amber-soft: #ffd166;
  --text: #f3e2c2;
  --muted: #b39a74;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* space taken by everything except the board, used to fit the board on screen */
  --chrome: 150px;
  --board: min(100vw - 24px, 100vh - var(--chrome), 560px);
  --board: min(100vw - 24px, 100dvh - var(--chrome), 560px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: none;
}
body.modal-open { overflow: hidden; }

.skip {
  position: absolute; left: -999px; top: 0;
  background: var(--amber); color: #120d09; padding: 8px 12px; z-index: 10;
}
.skip:focus { left: 8px; top: 8px; }

a { color: var(--amber-soft); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--amber-soft); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: var(--board); margin: 0 auto; height: 48px;
}
.top h1 {
  margin: 0; font: 700 18px/1 var(--mono); letter-spacing: 0.02em; color: var(--amber);
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
.logo {
  width: 18px; height: 18px; flex: none;
  background:
    linear-gradient(var(--amber), var(--amber)) 0 0 / 12px 6px no-repeat,
    linear-gradient(var(--amber), var(--amber)) 0 6px / 6px 6px no-repeat,
    linear-gradient(var(--amber), var(--amber)) 0 12px / 18px 6px no-repeat,
    linear-gradient(#ff5a3c, #ff5a3c) 12px 0 / 6px 6px no-repeat;
}
.top-actions { display: flex; gap: 8px; }
.chip {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 0 10px; height: 32px; font: 13px/1 var(--mono); color: var(--muted); white-space: nowrap;
}
.chip:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip[aria-pressed="true"]#pause { color: var(--amber); border-color: var(--amber); }

/* ---------- game ---------- */
.game { width: var(--board); margin: 0 auto; }

.hud {
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: 44px; align-items: center; font-family: var(--mono);
}
.hud div { display: flex; align-items: baseline; gap: 8px; }
.hud div:nth-child(2) { justify-content: center; }
.hud div:nth-child(3) { justify-content: flex-end; }
.hud span { font-size: 12px; color: var(--muted); }
.hud b { font-size: 20px; color: var(--amber-soft); font-variant-numeric: tabular-nums; }

.screen {
  position: relative; width: var(--board); height: var(--board);
  border: 2px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #17100a; touch-action: none; user-select: none; -webkit-user-select: none;
}
#board { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 16px;
  background: rgba(18, 13, 9, 0.88); text-align: center; font-family: var(--mono);
}
.overlay-title { margin: 0 0 4px; font-size: clamp(22px, 7vw, 32px); font-weight: 700; color: var(--amber); }
.result { margin: 0 0 4px; color: var(--muted); }
.result b { color: var(--amber-soft); font-size: 20px; }
.hint { margin: 4px 0 0; font-size: 13px; color: var(--muted); max-width: 30ch; }
.hint-touch { display: none; }

.option {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: min(100%, 250px); font-size: 14px;
}
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper b { width: 28px; text-align: center; font-size: 18px; color: var(--amber-soft); }
.stepper button, .toggle {
  height: 40px; min-width: 40px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; font: 700 18px/1 var(--mono); color: var(--text);
}
.toggle { min-width: 88px; font-size: 14px; }
.toggle[aria-checked="true"] { border-color: var(--amber); color: var(--amber); }
.stepper button:hover, .toggle:hover { border-color: var(--muted); }

.btn {
  min-width: 170px; height: 46px; padding: 0 20px; border: 0; border-radius: 6px;
  background: var(--amber); color: #120d09; font: 700 16px/1 var(--mono);
}
.btn:hover:not(:disabled) { background: var(--amber-soft); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-quiet {
  min-width: 0; height: 40px; background: transparent; color: var(--text);
  border: 1px solid var(--line); font-weight: 400; font-size: 14px;
}
.btn-quiet:hover:not(:disabled) { background: var(--panel); border-color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- direction pad (touch devices) ---------- */
.dpad {
  display: none; margin: 14px auto 0; width: 216px;
  grid-template: repeat(2, 64px) / repeat(3, 68px); gap: 6px;
  grid-template-areas: ". up ." "left down right";
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.dpad button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  display: grid; place-items: center; touch-action: none;
}
.dpad button:active { background: var(--line); border-color: var(--amber); }
.dpad svg { width: 26px; height: 26px; fill: var(--amber); pointer-events: none; }
.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="down"] { grid-area: down; }
.dpad [data-dir="right"] { grid-area: right; }

@media (pointer: coarse) {
  :root { --chrome: 300px; }
  .dpad { display: grid; }
  .hint-keys { display: none; }
  .hint-touch { display: block; }
}

/* short landscape screens: board on the left, pad on the right */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --chrome: 104px; }
  .top { width: auto; max-width: 760px; padding: 0 12px; height: 44px; }
  .game {
    width: auto; display: grid; justify-content: center; align-items: center;
    grid-template-columns: var(--board) auto; column-gap: 24px;
    grid-template-areas: "hud pad" "screen pad";
  }
  .hud { grid-area: hud; }
  .screen { grid-area: screen; }
  .dpad { grid-area: pad; margin: 0; }
}

/* ---------- ads ---------- */
.spot {
  width: min(100% - 24px, 728px); margin: 28px auto 0; text-align: center;
}
.spot-inline { width: 100%; margin: 28px 0; }
.spot-label {
  display: block; margin: 0 0 6px; font: 11px/1 var(--mono); letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.spot-body { min-height: 50px; display: grid; place-items: center; overflow: hidden; }
.spot-body > * { max-width: 100%; }
/* An advert's frame sits on a line of text unless it is a block, which leaves a strip under it; the side margins
   keep a block in the middle of a slot that is wider than it. And this page is dark where an advert's frame is
   not, so the browser paints the frame white before anything is drawn in it: an empty one would be a white box.
   Told that the frame is light, it leaves it clear. */
.spot-body iframe { display: block; margin-inline: auto; color-scheme: light; }
/* One network hands over a frame whether or not it has an advert for it, and nothing outside the frame can tell.
   Its slot (data-blind in the page) has no label and holds no room of its own, so an empty frame shows as
   nothing but blank space; and it is the last thing in the article, so that space is only more room above
   the footer. */
.spot[data-blind] .spot-body { min-height: 0; }

.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(8, 5, 3, 0.92); padding: 16px;
}
.modal-card {
  width: min(100%, 420px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px; text-align: center;
}
.modal-card .spot-body { min-height: 250px; margin-bottom: 20px; }

/* ---------- content ---------- */
.about { width: min(100% - 32px, 680px); margin: 40px auto 0; }
.about h2 { font: 700 22px/1.25 var(--mono); color: var(--amber); margin: 40px 0 12px; text-wrap: balance; }
.about h2:first-child { margin-top: 0; }
.about h3 { font: 700 16px/1.3 var(--mono); color: var(--amber-soft); margin: 24px 0 6px; }
.about p, .about ul { margin: 0 0 12px; color: var(--text); }
.about ul { padding-left: 20px; }
.about li { margin-bottom: 6px; }

.foot {
  width: min(100% - 32px, 680px); margin: 48px auto 0; padding: 20px 0 32px;
  border-top: 1px solid var(--line); font: 13px/1.5 var(--mono); color: var(--muted);
}
.foot p { margin: 0; }

.page { width: min(100% - 32px, 680px); margin: 24px auto 0; }
.page h1 { font: 700 26px/1.2 var(--mono); color: var(--amber); }
.page h2 { font: 700 18px/1.3 var(--mono); color: var(--amber-soft); margin-top: 28px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* small boards (short landscape phones): tighten the overlay so everything fits */
.screen { container-type: inline-size; }
.overlay > * { flex: none; }
.option span { white-space: nowrap; }
@container (max-width: 300px) {
  .overlay { gap: 8px; padding: 10px; }
  .overlay-title { font-size: 20px; margin: 0; }
  .hint { display: none !important; }
  .stepper button, .toggle { height: 34px; min-width: 34px; }
  .btn { height: 40px; }
  .btn-quiet { height: 34px; }
  .result { margin: 0; }
}
@container (max-width: 300px) { .toggle { min-width: 64px; } }

/* the card under the board: keep it card-sized on wide screens instead of a 728px-wide picture */
#spot-main { width: min(100% - 24px, 420px); }
#spot-end .spot-body { min-height: 250px; }
