:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --fg: #ededed;
  --dim: #8a8a8a;
  --faint: #444;
  --line: #1f1f1f;
  --accent: #c8ff2e;
  --font: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --gutter: 24px;
}

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

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }

body:not(.doc) {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

/* header */
.bar {
  display: flex;
  align-items: baseline;
  gap: 28px;
  padding: 20px var(--gutter);
}
.name { font-weight: bold; }
.tabs { display: flex; gap: 18px; }
.tabs button, .text, .options button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  cursor: pointer;
}
.tabs button:hover, .text:hover, .options button:hover, .link:hover, summary:hover { color: var(--fg); }
.tabs button[aria-pressed="true"] { color: var(--fg); }
.link { margin-left: auto; color: var(--dim); }

/* layout */
/* The game and the panel sit side by side as one centred group. The game
   takes as much height as it can while leaving room for the panel. */
.main {
  min-height: 0;
  container-type: size;
  display: flex;
  justify-content: center;
  gap: 56px;
  padding: 0 var(--gutter) var(--gutter);
}
.stage-wrap { flex: none; }
.stage {
  width: min(75cqh, 100cqw - 356px);
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.panel {
  flex: none;
  width: 300px;
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.pane { display: grid; gap: 28px; align-content: start; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; margin: 0; }
dt { color: var(--dim); font-size: 13px; }
dd { margin: 0; font-size: 28px; font-variant-numeric: tabular-nums; }

h2 { margin: 0 0 10px; color: var(--dim); font-size: 13px; font-weight: normal; }
canvas.network { display: block; width: 100%; height: 170px; }
canvas.history { display: block; width: 100%; height: 64px; }

.note { margin: 0; color: var(--dim); font-size: 13px; }
.pane[data-pane="play"] .note { margin-top: -18px; }

.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { margin: 0; accent-color: var(--accent); }
.check:has(input:disabled) { color: var(--faint); cursor: default; }

/* controls */
.controls { display: grid; gap: 12px; }
.row { display: flex; gap: 18px; align-items: baseline; }
.row > span { width: 70px; flex: none; color: var(--dim); }
.options { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.options button[aria-pressed="true"] { color: var(--fg); text-decoration: underline; text-underline-offset: 4px; }
.text { color: var(--fg); }
details > .row, details > .note { margin-top: 12px; }
summary { width: max-content; color: var(--dim); cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: " +"; }
details[open] summary::after { content: " −"; }

/* narrow screens: game on top, panel below, page scrolls */
@media (max-width: 820px) {
  :root { --gutter: 16px; }
  body:not(.doc) { overflow: auto; height: auto; min-height: 100dvh; display: block; }
  .bar { gap: 18px; }
  .main { display: block; container-type: normal; padding: 0 var(--gutter); }
  .stage { width: min(100%, 54dvh); margin: 0 auto; }
  .panel { width: auto; max-height: none; overflow: visible; padding: 24px 0 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .pane[data-pane="play"] .stats { grid-template-columns: repeat(2, 1fr); }
  dd { font-size: 22px; }
}

/* ------------------------------------------------------------ method page */
body.doc { overflow: auto; }
.doc-main { width: min(1040px, 100%); margin: 0 auto; padding: 32px var(--gutter) 96px; }
.doc h1, .doc h2 { margin: 0; color: var(--fg); font-weight: bold; }
.doc h1 { font-size: clamp(26px, 3.4vw, 38px); line-height: 1.15; max-width: 20ch; }
.doc h2 { font-size: 18px; margin-bottom: 12px; }
.doc p { color: var(--dim); font-size: 15px; line-height: 1.65; max-width: 60ch; }
.doc code { color: var(--fg); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.doc-hero { padding: 40px 0 48px; }
.doc-hero h1 + p { margin: 20px 0 0; }
.doc-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(28px, 6vw, 72px); align-items: center; padding: 48px 0; border-top: 1px solid var(--line); }
.doc-row > * { min-width: 0; }
.doc-figure { margin: 0; }
.doc-figure svg { display: block; width: 100%; height: auto; border: 1px solid var(--line); }
.doc-figure figcaption { padding-top: 10px; color: var(--dim); font-size: 13px; }
.doc-figure svg text { fill: var(--dim); font: 12px var(--font); }
.doc-figure svg text.head { fill: var(--faint); }
.doc-figure svg .genes text { font: 12px ui-monospace, Menlo, Consolas, monospace; white-space: pre; }
.doc-figure svg text.off { fill: var(--faint); text-decoration: line-through; }
.doc-figure svg text.new { fill: var(--accent); }
.doc-figure svg .pipe rect { fill: none; stroke: var(--dim); stroke-width: 1; }
.doc-figure svg .bird { fill: var(--accent); }
.doc-figure svg .acc { stroke: var(--accent); stroke-width: 1.25; fill: none; }
.doc-figure svg .dim { stroke: var(--dim); stroke-width: 1; fill: none; }
.doc-figure svg .ln { stroke: var(--fg); stroke-width: 1.25; fill: none; opacity: 0.7; }
.doc-figure svg .ln.dash { stroke-dasharray: 3 3; }
.doc-figure svg .ln.off { stroke: var(--faint); opacity: 1; }
.doc-figure svg .node { fill: var(--bg); stroke: var(--dim); }
.doc-figure svg .node.accent { fill: var(--accent); stroke: var(--accent); }
.formula { margin: 0; padding: 24px; border: 1px solid var(--line); color: var(--fg); font: 13px/1.8 ui-monospace, Menlo, Consolas, monospace; white-space: pre; overflow-x: auto; }
.doc-prose { padding: 0 0 48px; }
.doc-prose:has(h2) { padding-top: 48px; border-top: 1px solid var(--line); }
.doc-prose p { margin: 0 0 16px; }
.doc-end { padding: 48px 0 0; border-top: 1px solid var(--line); }
.doc-end ul { margin: 0; padding: 0; list-style: none; max-width: 60ch; }
.doc-end li { padding: 10px 0; color: var(--dim); font-size: 15px; border-bottom: 1px solid var(--line); }
.doc-end li code { margin-right: 8px; }
.doc-return { display: inline-block; margin-top: 32px; color: var(--fg); text-decoration: underline; text-underline-offset: 4px; }

@media (max-width: 820px) {
  .doc-row { grid-template-columns: 1fr; padding: 36px 0; }
}
