/* Snake · Game Lab. Obsidian field manual with a Cyber Yellow trace. */

@font-face {
  font-family: 'Martian Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/martian-mono-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'Martian Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/martian-mono-latin-700-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'Martian Mono';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('../fonts/martian-mono-latin-800-normal.woff2') format('woff2');
}

:root {
  --ink: #09090b;
  --panel: #111115;
  --panel-2: #18181d;
  --line: #2e2e35;
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #facc15;
  --accent-soft: rgba(250, 204, 21, 0.12);
  --food: #fb7185;
  --fast: #22d3ee;
  --slow: #a78bfa;
  --danger: #fb7185;
  --font: 'Martian Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font: 400 13px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  /* A faint scanline-free vignette: the board is the only bright thing. */
  background:
    radial-gradient(1200px 700px at 50% 45%, #121216 0%, var(--ink) 70%) fixed,
    var(--ink);
}

.app {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 700 10px/1.4 var(--font);
  color: var(--muted);
  vertical-align: 1px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------- HUD ---------------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 60px;
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  z-index: 5;
}

.hud-mode {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: auto;
  line-height: 1.25;
}

.hud-mode-name {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-transform: lowercase;
}

.hud-mode-sub {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-stats {
  display: flex;
  gap: 4px;
  margin: 0;
}

.stat {
  min-width: 74px;
  padding: 4px 10px;
  border-left: 1px solid var(--line);
}

.stat dt {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat dd {
  margin: 0;
  font-weight: 800;
  font-size: 18px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat--best dd {
  color: var(--accent);
}

.hud-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .ic-cross {
  display: none;
}

.icon-btn[aria-pressed='true'] .ic-cross {
  display: inline;
}

.icon-btn[aria-pressed='true'] .ic-waves {
  display: none;
}

.icon-btn[aria-pressed='true'] {
  color: var(--muted);
}

.icon-btn:hover {
  border-color: var(--accent);
}

.boost {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 3px;
  background: transparent;
}

.boost-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left;
  background: var(--fast);
}

.boost[data-kind='slow'] .boost-fill {
  background: var(--slow);
}

/* Short landscape screens: the HUD becomes a column on the right. */
.is-side-hud .hud {
  top: 0;
  bottom: 0;
  left: auto;
  width: calc(156px + var(--safe-r));
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) 12px;
  border-left: 1px solid var(--line);
}

.is-side-hud .hud-mode {
  margin: 0;
}

.is-side-hud .hud-stats {
  flex-direction: column;
  gap: 2px;
}

.is-side-hud .stat {
  border-left: 0;
  border-top: 1px solid var(--line);
  padding: 4px 0;
}

.is-side-hud .boost {
  top: 0;
  bottom: 0;
  left: -2px;
  right: auto;
  width: 3px;
  height: auto;
}

.is-side-hud .boost-fill {
  height: 100%;
  transform-origin: bottom;
}

/* Phones in portrait: compact, icons only. */
@media (max-width: 560px) {
  .hud {
    gap: 6px;
    padding-left: calc(8px + var(--safe-l));
    padding-right: calc(8px + var(--safe-r));
  }

  .hud-mode {
    display: none;
  }

  .hud-stats {
    margin-right: auto;
    gap: 0;
  }

  .stat {
    min-width: 0;
    padding: 2px 7px;
  }

  .stat dt {
    font-size: 9px;
  }

  .stat dd {
    font-size: 15px;
  }

  .hud-actions {
    gap: 4px;
  }
}

@media (pointer: coarse) {
  .icon-btn {
    width: 44px;
    height: 44px;
  }
}

/* ---------------- Stage ---------------- */

.stage {
  position: absolute;
  margin: 0;
}

.stage canvas {
  display: block;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #1f1f25,
    0 24px 60px -20px rgba(0, 0, 0, 0.9),
    0 0 80px -30px rgba(250, 204, 21, 0.18);
}

.ready,
.replay-tag {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9, 9, 11, 0.86);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

.ready {
  bottom: 14%;
  color: var(--accent);
  animation: breathe 1.6s ease-in-out infinite;
}

.replay-tag {
  top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.rec {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s steps(2) infinite;
}

.keys-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(8px + var(--safe-b));
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.keys-hint[hidden] {
  display: none;
}

@keyframes breathe {
  50% {
    opacity: 0.6;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------------- Screens & cards ---------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(9, 9, 11, 0.72);
  overflow-y: auto;
  touch-action: pan-y;
}

.screen[hidden] {
  display: none;
}

.screen--title {
  background: linear-gradient(180deg, rgba(9, 9, 11, 0.55), rgba(9, 9, 11, 0.85));
}

.screen--over {
  background: rgba(9, 9, 11, 0.5);
}

.card {
  position: relative;
  width: min(440px, 100%);
  padding: 22px 22px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  /* Clipped corner: the one hard angle in an otherwise soft field. */
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
  box-shadow: 0 30px 80px -30px #000;
}

.card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 22px;
  width: 3px;
  height: 28px;
  background: var(--accent);
}

.card--small {
  width: min(360px, 100%);
}

.card--wide {
  width: min(760px, 100%);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.card p {
  margin: 0 0 10px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 11px;
  margin-top: 14px !important;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.wordmark {
  margin: 0;
  font-size: clamp(44px, 12vw, 64px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--accent);
}

.caret {
  color: var(--text);
  animation: blink 1.1s steps(2) infinite;
}

.tagline {
  margin: 8px 0 16px !important;
  color: var(--muted);
}

.mode-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border-top: 1px solid var(--line);
}

.mode-list li {
  border-bottom: 1px solid var(--line);
}

.mode {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  grid-template-areas: 'idx name best' 'idx desc desc';
  column-gap: 10px;
  align-items: baseline;
  width: 100%;
  padding: 10px 8px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.mode-idx {
  grid-area: idx;
  color: var(--muted);
  font-size: 11px;
}

.mode-name {
  grid-area: name;
  font-weight: 800;
  font-size: 15px;
}

.mode-desc {
  grid-area: desc;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.mode-best {
  grid-area: best;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.mode:hover,
.mode:focus-visible {
  background: var(--accent);
  color: var(--ink);
  outline: none;
}

.mode:hover .mode-idx,
.mode:hover .mode-desc,
.mode:hover .mode-best,
.mode:focus-visible .mode-idx,
.mode:focus-visible .mode-desc,
.mode:focus-visible .mode-best {
  color: var(--ink);
}

.mode:focus-visible {
  box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 2px var(--accent);
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row .btn {
  flex: 1;
}

.stack {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 700;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}

.btn--primary kbd {
  color: var(--ink);
  border-color: rgba(9, 9, 11, 0.35);
}

.btn--ghost {
  background: transparent;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.arena:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle {
  justify-content: space-between;
}

.toggle-state {
  min-width: 64px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}

.toggle[aria-checked='true'] .toggle-state {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}

/* ---------------- Arena grid ---------------- */

.arena-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
}

.arena {
  position: relative;
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 76px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  text-align: left;
  cursor: pointer;
}

.arena-no {
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
}

.arena-name {
  font-weight: 700;
  font-size: 11px;
}

.arena-meta {
  font-size: 10px;
  color: var(--muted);
}

.arena-best {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
}

.arena:not([disabled]):hover,
.arena:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}

.arena:not([disabled]):hover .arena-meta,
.arena:not([disabled]):hover .arena-best,
.arena:focus-visible .arena-meta,
.arena:focus-visible .arena-best {
  color: var(--ink);
}

.arena[disabled] {
  cursor: not-allowed;
  background: transparent;
  color: var(--muted);
  border-style: dashed;
}


.arena.is-cleared::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---------------- Results ---------------- */

.over-cause {
  color: var(--food);
  font-weight: 700;
}

.result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 0;
}

.result div {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result dt {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.result dd {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.new-best {
  margin: 10px 0 0 !important;
  color: var(--accent);
  font-weight: 800;
}

/* ---------------- Help ---------------- */

.help-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 12px 0 16px;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legend li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
}

.sw {
  width: 16px;
  height: 16px;
  justify-self: center;
}

.sw--food {
  width: 11px;
  height: 11px;
  background: var(--food);
  transform: rotate(45deg);
}

.sw--gold {
  background: #fde047;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}

.sw--fast {
  border-radius: 50%;
  background: var(--fast);
}

.sw--slow {
  border-radius: 50%;
  background: var(--slow);
}

.sw--portal {
  border-radius: 50%;
  border: 2px dashed #f472b6;
}

.sw--edge {
  border: 2px solid var(--accent);
  border-right-style: dashed;
  border-bottom-style: dashed;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 560px) {
  .card {
    padding: 18px 16px 16px;
  }

  .help-cols {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .arena-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .keys-hint {
    display: none;
  }
}

/* Short landscape: title splits into two columns so nothing scrolls. */
@media (orientation: landscape) and (max-height: 560px) {
  .screen {
    padding-top: calc(10px + var(--safe-t));
    padding-bottom: calc(10px + var(--safe-b));
  }

  .card {
    padding: 14px 16px;
  }

  .wordmark {
    font-size: 40px;
  }

  .tagline {
    margin-bottom: 0 !important;
  }

  .mode-desc {
    display: none;
  }

  .mode-list {
    margin-bottom: 10px;
  }

  .stack {
    margin-top: 10px;
    gap: 6px;
  }

  .btn {
    min-height: 40px;
  }

  .card--title {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 18px;
    align-items: center;
  }

  .card--title .row {
    grid-column: 2;
  }

  .mode {
    padding: 6px 8px;
  }

  .help-cols {
    gap: 14px;
  }

  .keys-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ready,
  .caret,
  .rec {
    animation: none;
  }
}

.reduce-motion .ready,
.reduce-motion .caret,
.reduce-motion .rec {
  animation: none;
}

/* Phones: no text under 12px. */
@media (pointer: coarse), (max-width: 560px) {
  .hud-mode-sub,
  .stat dt,
  .small,
  .eyebrow,
  .mode-idx,
  .mode-desc,
  .mode-best,
  .toggle-state,
  .arena-name,
  .arena-meta,
  .arena-best,
  .result dt {
    font-size: 12px;
  }

  .stat dt {
    letter-spacing: 0.04em;
  }
}

/* Small boards (landscape phones with the d-pad on): the start hint wraps
   inside the board instead of running over the controls. */
.ready {
  max-width: calc(100% - 16px);
  box-sizing: border-box;
  white-space: normal;
  text-align: center;
  width: max-content;
}

/* Landscape phones: a slightly smaller d-pad leaves more room for the board. */
@media (orientation: landscape) and (max-height: 560px) {
  body .gk-touch .gk-dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
  }

  body .gk-touch {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

/* Landscape phones: mode rows and buttons keep a 44px touch height. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  .mode,
  .btn {
    min-height: 44px;
  }
}
