/* hyxor.com site stylesheet: the shared classes for the patterns in
 * docs/design/DESIGN.md. Values come from tokens.css (loaded first; a copy
 * of docs/design/tokens.css). No colours or sizes outside the tokens except
 * layout arithmetic. Templates (hillsrv/views.ml) use these classes and no
 * inline styles. */

/* ---- fonts (files are self-hosted; the @font-face rules with their hashed
   URLs are emitted by views.ml) ---- */

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

body { line-height: 1.5; }

/* The text-width rule (DESIGN.md "Type"): running text never runs wider
   than --text-max. Tables, code blocks, figures and the game screen keep
   the full column and scroll inside their own box. */
p, li, dd, dt, blockquote, label, summary,
.meta, .copy-slot, .field-note, .form-error, .caption, .sub-title {
  max-width: var(--text-max);
}
.copy-slot { display: inline-block; }
ol, ul { margin: 0; padding: 0; }

/* ---- page skeleton ---- */
.page {
  max-width: calc(var(--page-max) + 2 * var(--space-6));
  margin: 0 auto;
  padding: 44px var(--space-6) 56px;
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
  min-height: 100vh;
}
.page > main {
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
  flex: 1 0 auto;
}
.page--manual > main { gap: var(--space-12); }

h1, h2, h3 { margin: 0; font-weight: 500; }
p { margin: 0; }

/* ---- header and navigation ---- */
.site-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: var(--space-8);
  padding-bottom: var(--space-2);
  border-bottom: var(--rule) solid var(--rule-color);
}
.wordmark {
  font-size: var(--text-logo);
  letter-spacing: var(--track-logo);
  text-decoration: none;
  grid-column: 1;
}
.nav, .user-links, .subnav {
  display: flex;
  flex-wrap: wrap;
  column-gap: 22px;
}
.nav { grid-column: 2; }
.subnav { grid-column: 2; grid-row: 2; font-size: var(--text-sm); }
.user-links { grid-column: 3; column-gap: var(--space-5); color: var(--dim); }
.nav a, .subnav a, .user-links a, .inline-links a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}
.nav a.active, .subnav a.active {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: var(--accent-bar);
  text-underline-offset: 6px;
}

@media (max-width: 720px) {
  .site-header { grid-template-columns: 1fr; }
  .wordmark, .nav, .subnav, .user-links { grid-column: 1; grid-row: auto; }
}

/* ---- header band ---- */
.band {
  display: flex;
  flex-wrap: wrap;
  gap: 28px 56px;
  align-items: flex-end;
}
.band-title {
  flex: 2 1 320px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.band-title h1 {
  font-size: var(--text-h1);
  letter-spacing: var(--track-heading);
  overflow-wrap: anywhere;
}
.band-title .prefix { color: var(--dim); }
.meta { color: var(--dim); }
.band-summary {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.band-summary--wide { flex: 3 1 420px; }
.summary-label { color: var(--dim); font-size: var(--text-sm); }
.stats { display: flex; flex-wrap: wrap; gap: var(--space-2) 28px; align-items: flex-end; }
.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat-value { font-size: var(--text-stat); }
.switch { display: flex; gap: var(--space-2); align-items: center; font-size: var(--text-sm); color: var(--faint); }
.switch a { display: inline-flex; align-items: center; min-height: var(--tap); }
.switch .active {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: var(--accent-bar);
  text-underline-offset: 6px;
}
.placements { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); }
.placement { display: inline-flex; align-items: center; gap: var(--space-2); }
.rank { color: var(--dim); }
.inline-links { display: flex; flex-wrap: wrap; column-gap: var(--space-5); color: var(--dim); }
.on-this-page { font-size: 14px; column-gap: var(--space-5); }

.won { color: var(--won); }
.lost, .dim { color: var(--dim); }

/* ---- section label on a rule (the signature pattern) ---- */
.sec {
  position: relative;
  border-top: var(--rule) solid var(--rule-color);
  padding-top: 22px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-margin-top: var(--space-6);
}
.sec-label {
  position: absolute;
  top: -11px;
  left: 0;
  margin: 0;
  padding-right: 10px;
  background: var(--bg);
  color: var(--dim);
  font-size: var(--text-sm);
  font-weight: 400;
  letter-spacing: var(--track-mono);
  line-height: 20px;
}
.page--manual .sec { padding-top: 28px; gap: 18px; }
.intro { display: flex; flex-direction: column; gap: 18px; }
.sub { display: flex; flex-direction: column; gap: var(--space-3); padding-top: var(--space-3); }
.sub-title { font-size: var(--text-h2); letter-spacing: var(--track-heading); font-weight: 600; }
.sub-title .dim { font-weight: 400; letter-spacing: var(--track-mono); }

/* ---- prose (field manual) ---- */
.prose {
  font-family: var(--font-prose);
  font-size: var(--text-prose);
  line-height: 1.6;
  letter-spacing: 0;
  color: var(--fg-prose);
  max-width: var(--measure);
}
.step { display: flex; flex-direction: column; gap: 10px; }

/* ---- data tables ---- */
.table-wrap { overflow-x: auto; max-width: 100%; }
.table-wrap--figure { max-width: var(--figure-max); }
table.data { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 14px; }
table.data--fit { width: auto; min-width: 520px; }
table.data th {
  text-align: left;
  color: var(--dim);
  font-size: var(--text-xs);
  font-weight: 400;
  padding: var(--space-2) var(--space-3);
}
table.data td { padding: var(--space-3); border-top: var(--rule) solid var(--rule-soft); vertical-align: baseline; }
table.data tbody tr:last-child td { border-bottom: var(--rule) solid var(--rule-soft); }
table.data th:first-child, table.data td:first-child { padding-left: 0; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }
table.data .nowrap { white-space: nowrap; }
table.data .end { text-align: right; white-space: nowrap; }
table.data .desc { color: var(--fg-prose); }
table.data .key { padding-right: var(--space-6); white-space: nowrap; }

/* ---- code blocks ---- */
pre.code {
  margin: 0;
  max-width: var(--figure-max);
  background: var(--surface);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  letter-spacing: var(--track-mono);
  color: var(--fg);
  overflow-x: auto;
  white-space: pre;
}
pre.code code { font: inherit; }
pre.code--tall { max-height: 420px; overflow-y: auto; }

/* ---- game figure: the board on its dark screen ---- */
.game-figure { margin: 0; display: flex; flex-direction: column; gap: 14px; }
.screen {
  background: var(--screen);
  padding: 28px;
  display: flex;
  justify-content: center;
}
.screen video, .screen img {
  display: block;
  width: 100%;
  max-width: var(--board-max);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--screen);
}
.screen-empty {
  width: 100%;
  max-width: var(--board-max);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-6);
}
.screen a { display: block; width: 100%; max-width: var(--board-max); }
.game-controls { display: flex; align-items: center; gap: 14px; }
.play {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  background: transparent;
  border: var(--rule) solid var(--control);
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.play svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.play .icon-pause { display: none; }
.play.playing .icon-play { display: none; }
.play.playing .icon-pause { display: block; }
.scrub { flex: 1; min-width: 0; height: var(--tap); accent-color: var(--accent); margin: 0; }
.position { color: var(--dim); font-size: var(--text-sm); white-space: nowrap; }
/* Without JavaScript the native controls stay and ours are hidden. */
.game-controls[hidden] { display: none; }

@media (max-width: 600px) {
  .screen { padding: var(--space-3); }
}

/* ---- explanatory diagrams (field manual): follow the theme ---- */
.diagram { margin: 0; display: flex; flex-direction: column; gap: 10px; max-width: var(--figure-max); }
.diagram-panel { background: var(--panel); padding: var(--space-6); overflow-x: auto; }
.diagram svg { width: 100%; min-width: 560px; display: block; font-family: var(--font-mono); }
.diagram figcaption, .caption { color: var(--dim); font-size: var(--text-sm); }
.dg-label { fill: var(--dim); font-size: 13px; }
.dg-small { fill: var(--dim); font-size: 11px; }
.dg-span { fill: var(--dim); font-size: 12px; }
.dg-text { fill: var(--fg); font-size: 13px; }
.dg-leader { stroke: var(--control); fill: none; }
.dg-divider { stroke: var(--rule-color); }
.dg-path { stroke: var(--control); stroke-dasharray: 2 6; }
.dg-goal { stroke: var(--control); stroke-width: 2; fill: none; stroke-dasharray: 4 4; }
.dg-owner { stroke: var(--player-3); stroke-width: 2; fill: none; }
.dg-owner-fill { fill: var(--player-3); }

/* ---- anatomy diagrams: a command, each token underlined in its colour ---- */
.anatomy-wrap { overflow-x: auto; max-width: var(--figure-max); }
.anatomy {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto auto;
  justify-content: start;
  column-gap: 22px;
  min-width: 520px;
  font-size: 22px;
}
.anatomy .field {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: var(--accent-bar) solid;
  font-size: var(--text-xs);
  color: var(--dim);
}
.tok-1 { color: var(--accent); }
.field.tok-1 { border-color: var(--accent); }
.tok-2 { color: var(--player-3-text, var(--player-3)); }
.field.tok-2 { border-color: var(--player-3); }
.tok-3 { color: var(--player-1-text, var(--player-1)); }
.field.tok-3 { border-color: var(--player-1); }
.tok-4 { color: var(--player-4-text, var(--player-4)); }
.field.tok-4 { border-color: var(--player-4); }
.tok-5 { color: var(--player-5-text, var(--player-5)); }
.field.tok-5 { border-color: var(--player-5); }
.anatomy .field { color: var(--dim); }

/* ---- owner-only section ---- */
.owner { border-top: var(--rule) solid var(--rule-color); padding-top: var(--space-1); }
.owner > summary {
  color: var(--dim);
  font-size: var(--text-sm);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  cursor: pointer;
}
.owner-body { display: flex; flex-direction: column; gap: var(--space-4); padding-top: var(--space-2); }

/* ---- forms ---- */
.form { display: flex; flex-direction: column; gap: var(--space-5); max-width: 420px; }
.field-group { display: flex; flex-direction: column; gap: var(--space-2); }
.field-group label { color: var(--dim); font-size: var(--text-sm); }
.field-note { color: var(--dim); font-size: var(--text-sm); }
.form input, .form select {
  height: var(--tap);
  padding: 0 var(--space-3);
  border: var(--rule) solid var(--control);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  letter-spacing: var(--track-mono);
  width: 100%;
}
.form input:focus-visible, .form select:focus-visible, .play:focus-visible, .button:focus-visible {
  outline: var(--accent-bar) solid var(--accent);
  outline-offset: 2px;
}
.button {
  appearance: none;
  align-self: flex-start;
  min-height: var(--tap);
  padding: 0 var(--space-5);
  border: var(--rule) solid var(--control);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  letter-spacing: var(--track-mono);
  cursor: pointer;
}
.button:hover { border-color: var(--fg); }
.form-error { color: var(--fg); border-left: var(--accent-bar) solid var(--accent); padding-left: var(--space-3); }

/* ---- copy slots: visible placeholders for text the maintainer writes ---- */
.copy-slot { color: var(--faint); }

/* ---- footer ---- */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  border-top: var(--rule) solid var(--rule-color);
  padding-top: 14px;
  color: var(--dim);
  font-size: var(--text-xs);
}
.site-footer .tag { color: var(--accent); margin-right: 10px; }

.inline { display: inline; }
.form-submit-link {
  background: none;
  border: none;
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--control);
  font: inherit;
  cursor: pointer;
  min-height: var(--tap);
}
.screen .copy-slot, .screen-empty { color: var(--screen-text); }

/* ---- the video feed (Matches page): full-size boards ---- */
.video-feed { list-style: none; display: flex; flex-direction: column; gap: var(--space-10); }
/* a video row is a figure, not running text: the full column, like the match page */
.video-row { max-width: none; }
.video-row .screen-empty { display: block; width: 100%; max-width: var(--board-max); aspect-ratio: 4 / 3; }
.video-caption { display: flex; flex-direction: column; gap: var(--space-1); }
.video-caption p { max-width: var(--text-max); overflow-wrap: anywhere; }

/* ---- feeds: thumbnail rows ---- */
.feed { list-style: none; display: flex; flex-direction: column; }
.feed-row {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-3) 0;
  border-top: var(--rule) solid var(--rule-soft);
  max-width: none;
}
.feed-row:last-child { border-bottom: var(--rule) solid var(--rule-soft); }
.thumb, .thumb-space { flex: none; width: 120px; aspect-ratio: 6 / 5; display: block; }
.thumb { background: var(--screen); }
.thumb-img, .thumb-empty { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--screen); }
.feed-text { min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.feed-text p { overflow-wrap: anywhere; }
.feed-time { color: var(--dim); font-size: var(--text-sm); }
@media (max-width: 600px) {
  .thumb, .thumb-space { width: 88px; }
}
.pager { display: flex; gap: var(--space-5); align-items: center; }
.pager a { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); text-decoration: none; border: var(--rule) solid var(--control); }

/* ---- the still in a game figure links to its match ---- */
.screen-empty a, .screen > a { color: inherit; }

/* ---- toggle (My bots' Active?) ---- */
.toggle-form { margin: 0; }
.toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-2) 0 0;
  border: none;
  background: transparent;
  color: var(--dim);
  font: inherit;
  letter-spacing: var(--track-mono);
  cursor: pointer;
}
.toggle.on { color: var(--fg); }
.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  border: var(--rule) solid var(--control);
  flex: none;
}
.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--control);
}
.toggle.on .toggle-knob { left: 19px; background: var(--won); }
.toggle:focus-visible { outline: var(--accent-bar) solid var(--accent); outline-offset: 2px; }

/* ---- create bot: the image path preview ---- */
.image-path { color: var(--fg); font-family: var(--font-mono); font-size: var(--text-sm); overflow-wrap: anywhere; }

/* ---- numbered steps (field manual) ---- */
.steps { list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: var(--space-5); }
.steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.5em minmax(0, 1fr);
  row-gap: 10px;
  max-width: none;
}
.steps > li::before {
  content: counter(step) ".";
  grid-row: 1;
  color: var(--dim);
  font-size: var(--text-prose);
  line-height: 1.6;
}
.steps > li > * { grid-column: 2; }
.steps > li > .prose { grid-row: 1; }
