:root {
  --bg: #090818;
  --panel: #14132e;
  --line: #2b2b5c;
  --pink: #ff4fa3;
  --gold: #ffd23f;
  --teal: #35cfc0;
  --text: #e8e8ff;
  --muted: #9a9ac8;
  --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;
  /* the touch pad under the field, and the room everything except the field takes: used to fit the field on screen */
  --pad: 0px;
  --chrome: 128px;
  --field: min(100vw - 24px, (100vh - var(--chrome)) * 0.8, 512px);
  --field: min(100vw - 24px, (100dvh - var(--chrome)) * 0.8, 512px);
}

* { 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);
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
body.modal-open { overflow: hidden; }

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

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

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: var(--field); min-width: min(100vw - 24px, 300px); margin: 0 auto; height: 48px;
}
.top h1 {
  margin: 0; font: 700 18px/1 var(--mono); letter-spacing: 0.04em; color: var(--pink);
  display: flex; align-items: center; gap: 10px; white-space: nowrap; text-transform: uppercase;
}
/* three parts of a wyrm, the head in gold */
.logo {
  width: 20px; height: 8px; flex: none;
  background:
    linear-gradient(var(--pink), var(--pink)) 0 0 / 6px 8px no-repeat,
    linear-gradient(var(--pink), var(--pink)) 7px 0 / 6px 8px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 14px 0 / 6px 8px 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(--gold); border-color: var(--gold); }

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

.hud {
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: 40px; 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: 19px; color: var(--gold); font-variant-numeric: tabular-nums; }

.screen {
  position: relative; width: var(--field); aspect-ratio: 4 / 5;
  border: 2px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #090818; touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: 0 0 40px rgba(255, 79, 163, 0.12), 0 0 90px rgba(53, 207, 192, 0.08);
}
body.playing .screen { cursor: crosshair; }
#board { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
/* faint scanlines and darker corners, like an old tube */
.screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.38) 100%);
}

.overlay {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 16px;
  background: rgba(9, 8, 24, 0.74); text-align: center; font-family: var(--mono);
}
#paused, #over { background: rgba(9, 8, 24, 0.86); }
.overlay > * { flex: none; }
.overlay-title {
  margin: 0; font-size: clamp(24px, 8vw, 38px); font-weight: 700; color: var(--pink);
  letter-spacing: 0.06em; text-transform: uppercase; text-shadow: 0 0 18px rgba(255, 79, 163, 0.55);
}
.tagline { margin: 0 0 6px; color: var(--text); font-size: 14px; max-width: 26ch; text-wrap: balance; }
.result { margin: 0; color: var(--muted); }
.result b { color: var(--gold); font-size: 20px; }
.result-small { margin-bottom: 6px; font-size: 14px; }
.result-small b { font-size: 16px; }
.hint { margin: 4px 0 0; font-size: 13px; color: var(--muted); max-width: 32ch; text-wrap: balance; }
.hint-touch { display: none; }

.btn {
  min-width: 170px; height: 46px; padding: 0 20px; border: 0; border-radius: 6px;
  background: var(--gold); color: #090818; font: 700 16px/1 var(--mono);
}
.btn:hover:not(:disabled) { background: #ffe27a; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-quiet {
  min-width: 170px; height: 40px; background: rgba(20, 19, 46, 0.7); 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); }

/* ---------- touch pad (touch devices): drag here so your thumb is not over the field ---------- */
.pad {
  display: none; margin-top: 10px; height: var(--pad); width: 100%;
  border: 1px dashed var(--line); border-radius: 10px; background: rgba(20, 19, 46, 0.5);
  place-items: center; touch-action: none; user-select: none; -webkit-user-select: none;
  font: 12px/1.3 var(--mono); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; text-align: center;
}
.pad span { pointer-events: none; opacity: 0.8; }

@media (pointer: coarse) {
  :root {
    --pad: clamp(60px, 13vh, 104px);
    --chrome: calc(138px + var(--pad));
  }
  .pad { display: grid; }
  .hint-keys { display: none; }
  .hint-touch { display: block; }
}
@supports (height: 1dvh) {
  @media (pointer: coarse) { :root { --pad: clamp(60px, 13dvh, 104px); } }
}

/* short landscape screens: scores on the left, field in the middle, pad on the right */
@media (orientation: landscape) and (max-height: 540px) {
  :root {
    --chrome: 56px;
    --field: calc((100vh - var(--chrome)) * 0.8);
    --field: calc((100dvh - var(--chrome)) * 0.8);
  }
  .top { width: auto; min-width: 0; max-width: 760px; padding: 0 12px; height: 40px; }
  .game {
    width: auto; display: grid; justify-content: center; align-items: stretch;
    grid-template-columns: 96px var(--field) minmax(0, 96px); column-gap: 16px; padding: 0 12px;
  }
  .hud {
    display: flex; flex-direction: column; justify-content: center; align-items: flex-end; gap: 14px; height: auto;
  }
  .hud div, .hud div:nth-child(2), .hud div:nth-child(3) { flex-direction: column; align-items: flex-end; gap: 2px; }
  .pad { margin: 0; height: auto; }
}
@media (orientation: landscape) and (max-height: 540px) and (pointer: coarse) {
  .game { grid-template-columns: 96px var(--field) minmax(110px, 220px); }
}

/* ---------- 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; }
/* the card under the field: keep it card-sized on wide screens */
#spot-main { width: min(100% - 24px, 420px); }
#spot-end .spot-body { min-height: 250px; }

.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5, 4, 14, 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(--pink); 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(--gold); 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; }
.foot .made { margin-top: 6px; }

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

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

/* small fields (short landscape phones): tighten the overlay so everything fits */
.screen { container-type: inline-size; }
@container (max-width: 300px) {
  .overlay { gap: 8px; padding: 10px; }
  .overlay-title { font-size: 22px; }
  .tagline { font-size: 12px; margin: 0; }
  .hint { font-size: 11px; margin: 0; }
  .btn { height: 40px; }
  .btn-quiet { height: 34px; }
}

/* watch mode (?attract=1): only the field, as large as the window allows, with the demo playing */
body.attract { --field: min(100vw, 100vh * 0.8); overflow: hidden; padding: 0; }
body.attract :is(.top, .hud, .pad, .overlay, .spot, .about, .foot, .skip) { display: none; }
body.attract .screen { border: 0; border-radius: 0; box-shadow: none; }
