/* ── tokens ─────────────────────────────────────────────────────────────
   Black and white, literally. No hue anywhere on this page — every value
   below is neutral, including the glows and shadows. Hierarchy comes from
   brightness and weight only.                                              */

:root {
  --bg:       #000000;
  --panel:    #0a0a0a;
  --line:     #262626;
  --line-lit: #4d4d4d;
  --ink:      #ffffff;
  --ink-mid:  #a3a3a3;
  --ink-dim:  #666666;
  --glow:     rgba(255, 255, 255, 0.28);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: clamp(16px, 4vw, 40px) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink-mid);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  display: flex;
  justify-content: center;
  /* the faint bloom of a tube that's been on a while */
  background-image: radial-gradient(ellipse at 50% 32%, #101010 0%, #000000 68%);
}

.wrap {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 3vw, 28px);
}

a { color: var(--ink); }

/* ── skip link ──────────────────────────────────────────────────────────── */

.skip-to-links {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  z-index: 20;
}
.skip-to-links:focus { left: 8px; top: 8px; }

/* ── header ─────────────────────────────────────────────────────────────── */

.site-head { text-align: center; }

.name {
  margin: 0;
  font-size: clamp(24px, 7vw, 38px);
  letter-spacing: 0.28em;
  text-indent: 0.28em;      /* offset the trailing letter-space, keeps it centred */
  font-weight: 400;
  color: var(--ink);
  text-shadow: 0 0 12px var(--glow), 0 0 28px var(--glow);
}

.tagline {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.08em;
}

/* ── board ──────────────────────────────────────────────────────────────── */

.stage { display: flex; flex-direction: column; gap: 10px; }

/* ── top bar: mode tabs left, score right ───────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.modes {
  display: flex;
  gap: 8px;
  margin-right: auto;      /* hold the left edge even when the score wraps */
}

.mode {
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--line);
  padding: 12px 26px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.mode:hover { color: var(--ink-mid); border-color: var(--line-lit); }
.mode:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.mode[aria-selected="true"] {
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: 0 0 16px var(--glow), inset 0 0 22px rgba(255, 255, 255, 0.07);
}

.scoreline {
  display: flex;
  gap: 20px;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.22em;
}

@media (max-width: 420px) {
  .mode { font-size: 12px; padding: 10px 18px; }
}
.scoreline b {
  color: var(--ink);
  font-weight: 400;
  text-shadow: 0 0 8px var(--glow);
}

.board {
  position: relative;
  border: 1px solid var(--line);
  background: var(--bg);
  /* matches the 28x22 logical grid so the canvas never distorts */
  aspect-ratio: 28 / 22;
  box-shadow: 0 0 0 1px #0d0d0d, 0 0 40px rgba(255, 255, 255, 0.05);
}

/* CRT scanlines, laid over the canvas and ignoring pointer input */
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px,
    rgba(0, 0, 0, 0.22) 4px
  );
}

/* Safari only shipped aspect-ratio in 15. Without this the board collapses to
   zero height and the game is invisible rather than merely misaligned. */
@supports not (aspect-ratio: 28 / 22) {
  .board {
    height: 0;
    padding-bottom: 78.571%;   /* 22 / 28 */
  }
  .board > canvas { position: absolute; inset: 0; }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  outline: none;
}
canvas:focus-visible { outline: 1px solid var(--line-lit); outline-offset: 2px; }

/* ── overlay ────────────────────────────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;                /* above the scanline layer */
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.86);
  text-align: center;
}
.overlay[hidden] { display: none; }

.overlay-title {
  margin: 0;
  font-size: clamp(16px, 4.5vw, 21px);
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--ink);
  text-shadow: 0 0 14px var(--glow);
}
.overlay-body {
  margin: 10px 0 18px;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.1em;
}

/* Outlined, not filled — a filled button was the loudest thing on the page. */
.btn {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line-lit);
  padding: 9px 22px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 16px var(--glow);
}
.btn:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

/* ── d-pad (touch only) ─────────────────────────────────────────────────── */

.dpad { display: none; }

@media (pointer: coarse) {
  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    justify-content: center;
    gap: 6px;
    margin-top: 6px;
    touch-action: none;
  }
  .dbtn {
    font: inherit;
    font-size: 14px;
    color: var(--ink-mid);
    background: var(--panel);
    border: 1px solid var(--line);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }
  .dbtn:active {
    color: var(--ink);
    border-color: var(--line-lit);
    box-shadow: 0 0 14px var(--glow);
  }
  .up    { grid-area: 1 / 2; }
  .left  { grid-area: 2 / 1; }
  .down  { grid-area: 2 / 2; }
  .right { grid-area: 2 / 3; }
}

/* ── links ──────────────────────────────────────────────────────────────── */

.links-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.28em;
  color: var(--ink-dim);
}

.reveal {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  background: none;
  border: 0;
  border-bottom: 1px dotted var(--ink-dim);
  padding: 0 0 1px;
  cursor: pointer;
}
.reveal:hover:not(:disabled) { color: var(--ink); border-color: var(--ink); }
.reveal:disabled { cursor: default; opacity: 0.45; border-bottom-style: none; }

.chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 8px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-mid);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, color 0.15s;
}
.chip:hover {
  border-color: var(--line-lit);
  color: var(--ink);
  box-shadow: 0 0 18px var(--glow);
}
.chip:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

/* The glyph tile mirrors the pellet on the board: a stroked frame, not a
   filled colour swatch. */
.glyph {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 400;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line-lit);
}

.chip-text { display: flex; flex-direction: column; min-width: 0; }
.chip-text b {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
}
.chip-text i {
  font-style: normal;
  font-size: 11px;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * "Locked" is a purely visual tease. The anchor stays focusable and its text
 * stays in the accessibility tree, so keyboard and screen-reader users always
 * have the links — blurring is decoration, not a gate.
 */
.chip.locked { opacity: 0.42; }
.chip.locked .glyph { border-color: var(--line); color: var(--ink-dim); }
.chip.locked .chip-text i { filter: blur(3.5px); }
.chip.locked:hover, .chip.locked:focus-visible { opacity: 1; }
.chip.locked:hover .chip-text i,
.chip.locked:focus-visible .chip-text i { filter: none; }

/* A phosphor flare when a pellet is eaten, rather than a bouncy pop. */
.chip.just-unlocked { animation: flare 0.7s ease-out; }
@keyframes flare {
  0%   { box-shadow: 0 0 26px rgba(255, 255, 255, 0.75); border-color: var(--ink); }
  100% { box-shadow: 0 0 0 rgba(255, 255, 255, 0);       border-color: var(--line); }
}

/* ── footer ─────────────────────────────────────────────────────────────── */

.site-foot {
  color: var(--ink-dim);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-align: center;
}
.site-foot p { margin: 0; }

/* ── about modal ────────────────────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
}

.modal-card {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 26px 24px 24px;
  background: var(--panel);
  border: 1px solid var(--line-lit);
  box-shadow: 0 0 60px rgba(255, 255, 255, 0.1);
  text-align: center;
}

.modal-x {
  position: absolute;
  top: 6px;
  right: 10px;
  font: inherit;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-dim);
  background: none;
  border: 0;
  padding: 4px 6px;
  cursor: pointer;
}
.modal-x:hover { color: var(--ink); }

.modal-card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 0 12px var(--glow);
}

.modal-body { text-align: left; color: var(--ink-mid); font-size: 13px; }
.modal-body p { margin: 0 0 10px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body .bio-footer { color: var(--ink); }

/* ── motion ─────────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
