:root {
  color-scheme: light;
  --page: #f7f9fc;
  --surface: #fff;
  --ink: #17263a;
  --muted: #506178;
  --line: #cad6e4;
  --accent: #2167bf; /* blue robot: ROBOT_COLORS #4C97FF */
  --accent-soft: #e9f3ff;
  --orange: #bd5e00; /* orange robot: #FF8C1A */
  --green: #267c32; /* green robot: #59C059 */
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #101b2a;
    --surface: #19283a;
    --ink: #edf4ff;
    --muted: #b3c3d7;
    --line: #41566e;
    --accent: #83baff;
    --accent-soft: #203b5b;
    --orange: #ffb766;
    --green: #82d589;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; padding: 0 16px; background: var(--page); color: var(--ink); font: 1rem/1.65 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; overflow-wrap: break-word; }
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }
.site-nav { max-width: 76rem; margin: auto; padding: .8rem 0; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem; border-bottom: 1px solid var(--line); }
.site-nav a { font-weight: 650; text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-decoration-color: var(--orange); text-underline-offset: .3em; }
.site-nav .brand { color: var(--ink); margin-right: auto; }
.site-shell { max-width: 76rem; margin: 0 auto; }
.manual-layout { display: grid; grid-template-columns: minmax(12rem, 15rem) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 4rem); align-items: start; }
.manual-toc { position: sticky; top: 1rem; margin-top: 2rem; padding: 1rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.manual-toc ol { margin: .5rem 0 0; padding-left: 1.3rem; }
.manual-toc li { margin: .3rem 0; }
.manual-content { min-width: 0; max-width: 72ch; padding-bottom: 4rem; }
.manual-content section { margin-top: 3rem; scroll-margin-top: 1rem; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 2.5rem 0 .5rem; }
h2 { font-size: 1.55rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line); }
h3 { font-size: 1.15rem; }
p, li { max-width: 72ch; }
.lede { color: var(--muted); font-size: 1.15rem; }
pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { max-width: 100%; overflow-x: auto; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: .4rem; line-height: 1.5; }
:not(pre) > code { background: var(--accent-soft); padding: .1em .25em; border-radius: .2em; }
.api-group { margin: 1.5rem 0; }
.api-list { margin: 0; }
.api-list > div { border-top: 1px solid var(--line); padding: .7rem 0; }
.api-list dt { font-weight: 700; color: var(--orange); }
.api-list dd { margin: .2rem 0 0; }
.note { border-left: 4px solid var(--green); background: var(--accent-soft); padding: .75rem 1rem; }
@media (max-width: 700px) {
  .manual-layout { display: block; }
  .manual-toc { position: static; margin-top: 1rem; }
  .manual-toc:not([open]) ol { display: none; }
}

/* Landing page: the shared tokens and navigation also serve the manual. */
.landing .site-shell { padding-bottom: 5rem; }
.landing-headline { max-width: 32ch; margin: clamp(1.5rem, 4vw, 3.5rem) 0 1.5rem; font-size: clamp(1.8rem, 3.4vw, 3.5rem); line-height: 1.12; letter-spacing: -.035em; }
.arena-section { min-width: 0; }
.arena-frame { position: relative; width: min(100%, calc(100vh - 9rem)); margin: 0 auto; background: #f4f4f0; border: 1px solid var(--line); border-radius: .9rem; overflow: hidden; box-shadow: 0 22px 60px #0b1d3620; }
#battle-replay { display: flex; flex-direction: column; min-width: 0; }
#battle-replay .battle-svg-host { order: -1; width: 100%; line-height: 0; }
#battle-replay svg { width: 100%; height: auto; display: block; }
#battle-loading { display: grid; place-items: center; min-height: min(65vw, 65vh); color: #34465a; font-weight: 650; }
#battle-loading[hidden] { display: none; }
.landing .battle-playback-controls { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; padding: .65rem .8rem; background: var(--surface); border-top: 1px solid var(--line); font-size: .8rem; }
.landing .battle-playback-controls button, .landing .battle-playback-controls input { font: inherit; }
.landing .battle-playback-controls input[type=number] { width: 4.5rem; }
.landing .battle-scrubber { flex: 1 1 8rem; min-width: 6rem; }
.arena-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1.15rem 0 .25rem; }
.battle-legend { display: flex; flex-wrap: wrap; gap: .45rem; }
.legend-robot { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface); color: var(--ink); cursor: pointer; font: inherit; font-size: .83rem; }
.legend-robot[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.robot-swatch { width: .75rem; height: .75rem; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px #0002; }
.legend-damage { color: var(--muted); white-space: nowrap; }
.arena-actions { display: flex; align-items: center; gap: .85rem; white-space: nowrap; color: var(--muted); font-size: .85rem; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
.arena-actions button, .derivation-tools button, .battle-playback-controls button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: .4rem; padding: .4rem .7rem; }
.arena-actions button:hover, .derivation-tools button:hover, .battle-playback-controls button:hover { border-color: var(--accent); }
.battle-status { margin: .2rem 0 0; color: var(--muted); font-size: .85rem; }
.layers-section { margin-top: clamp(3rem, 7vw, 6rem); min-width: 0; }
.section-heading { margin-bottom: 1.3rem; }
.eyebrow { color: var(--orange); font-size: .72rem; font-weight: 750; letter-spacing: .16em; }
.layers-section h2 { margin: .5rem 0; border: 0; font-size: clamp(1.5rem, 3vw, 2.2rem); letter-spacing: -.025em; }
#selected-robot { color: var(--muted); font-size: .65em; font-weight: 450; }
.layer-tabs { display: flex; gap: .3rem; overflow-x: auto; max-width: 100%; border-bottom: 1px solid var(--line); }
.layer-tabs button { flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); padding: .7rem .85rem; font: inherit; font-weight: 650; }
.layer-tabs button span { color: var(--orange); font-size: .7rem; margin-right: .3rem; }
.layer-tabs button[aria-selected=true] { color: var(--ink); border-color: var(--accent); }
.layer-panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 .7rem .7rem; padding: clamp(1rem, 3vw, 2rem); }
.layer-panel[hidden] { display: none; }
.layer-panel p { color: var(--muted); margin-top: 0; }
.layer-panel pre { max-height: 30rem; overflow: auto; white-space: pre; overflow-wrap: normal; font-size: .82rem; }
.derivation-tools { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; font-size: .85rem; color: var(--muted); }
.ast-view { max-height: 34rem; overflow: auto; border: 1px solid var(--line); border-radius: .4rem; padding: .7rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; white-space: nowrap; }
.ast-view ul { list-style: none; padding-left: 1.2rem; border-left: 1px solid var(--line); margin: .2rem 0 .2rem .5rem; }
.ast-view li { max-width: none; }
.ast-view summary { cursor: pointer; }
.wasm-view { min-width: 0; }
.wasm-view details { border-top: 1px solid var(--line); padding: .5rem 0; }
.wasm-view summary { cursor: pointer; font-weight: 650; }
.wasm-view pre { max-height: 20rem; }
.engine-stats { display: grid; grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr); gap: 0 1rem; margin: 1.5rem 0 0; }
.engine-stats dt, .engine-stats dd { border-top: 1px solid var(--line); padding: .65rem 0; margin: 0; }
.engine-stats dt { color: var(--muted); }
.deeper { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-top: 3rem; }
.deeper a { display: flex; flex-direction: column; gap: .7rem; min-width: 0; padding: 1.4rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); color: var(--ink); text-decoration: none; }
.deeper a:hover { border-color: var(--accent); transform: translateY(-2px); }
.deeper a span { color: var(--muted); font-size: .78rem; }
.deeper a strong { font-size: 1.3rem; }
@media (max-width: 700px) {
  .site-nav { gap: .25rem .9rem; font-size: .82rem; }
  .site-nav .brand { flex-basis: 100%; }
  .landing-headline { margin-top: 1.5rem; }
  .arena-meta { align-items: flex-start; }
  .battle-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .legend-robot { min-width: 0; flex-wrap: wrap; }
  .deeper { grid-template-columns: 1fr; }
}
@media (max-width: 390px) {
  .legend-robot { font-size: .76rem; padding: .4rem; }
  .legend-damage { width: 100%; padding-left: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .deeper a:hover { transform: none; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Tournament and challenge */
.activity { padding-bottom: 4rem; }
.activity form, .challenge-goal { padding: 1rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.activity fieldset { border: 0; padding: 0 0 .8rem; margin: 0; }
.activity legend { font-weight: 700; margin-bottom: .5rem; }
.activity input, .activity button, .activity textarea { font: inherit; }
.activity input[type=number] { width: 8rem; max-width: 100%; padding: .35rem; }
.activity button { padding: .35rem .65rem; border: 1px solid var(--line); border-radius: .4rem; color: var(--ink); background: var(--surface); }
.activity button:hover { border-color: var(--accent); }
.entrant-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: .5rem; }
.entrant { display: grid; grid-template-columns: auto 1fr; gap: 0 .5rem; padding: .5rem; border: 1px solid var(--line); border-radius: .4rem; cursor: pointer; }
.entrant input { grid-row: span 2; }
.entrant small { color: var(--muted); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fight-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.activity .fight-link { display: block; max-width: 100%; text-align: left; font-size: .85rem; overflow-wrap: anywhere; }
.activity table { border-collapse: collapse; width: min(100%, 32rem); margin: 1rem 0; }
.activity caption { text-align: left; font-weight: 700; }
.activity th, .activity td { padding: .3rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
.bracket { display: flex; align-items: stretch; gap: 1rem; min-width: 0; }
.bracket-round { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: space-around; gap: 1rem; }
.bracket-match { position: relative; min-width: 0; padding: .5rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface); }
.bracket-match::after { content: ""; position: absolute; left: 100%; top: 50%; width: 1rem; border-top: 1px solid var(--line); }
.bracket-round:last-child .bracket-match::after { display: none; }
.bracket-match .winner { color: var(--green); font-weight: 700; }
.match-games { margin-top: .4rem; padding-top: .4rem; border-top: 1px solid var(--line); display: grid; gap: .3rem; }
.champion { font-size: 1.6rem; font-weight: 750; }
.replay { max-width: min(100%, 38rem); }
.replay svg { display: block; width: 100%; height: auto; }
.replay .battle-playback-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.replay .battle-playback-controls input[type=range] { flex: 1 1 8rem; min-width: 0; }
.battle-output { box-sizing: border-box; width: 100%; min-width: 0; max-height: 9rem; overflow-y: auto; padding: .55rem .75rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: .85rem/1.45 ui-monospace, monospace; }
.battle-output-line { overflow-wrap: anywhere; white-space: pre-wrap; }
.battle-output-name { font-weight: 700; }
.battle-print-label { pointer-events: none; paint-order: stroke; stroke: var(--surface); stroke-width: 7px; stroke-linejoin: round; font: 700 24px sans-serif; }
#hint { white-space: pre-wrap; }
.level-nav { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
.level-nav button[aria-current=step] { background: var(--accent-soft); border-color: var(--accent); }
.challenge-goal { margin-bottom: 1rem; }
.challenge-goal h2 { margin-top: .3rem; }
.challenge-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(14rem, 1fr); gap: 1rem; }
.challenge-layout > * { min-width: 0; }
.challenge-layout .cheat-pane { max-height: 33rem; overflow: auto; padding: .7rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface); }
.challenge-layout .cheat-pane ul { padding-left: 1.2rem; }
.challenge-layout .cheat-pane li { font-size: .85rem; margin: .3rem 0; }
.code-frame { display: flex; min-width: 0; border: 1px solid var(--line); border-radius: .4rem; overflow: hidden; }
.gutter { flex: none; list-style: none; margin: 0; padding: .5rem .4rem; width: 2.8rem; height: 22rem; overflow: hidden; text-align: right; background: var(--surface); color: var(--muted); font: .85rem/1.4 ui-monospace, monospace; }
.gutter li.error { color: #b42d2d; font-weight: 700; }
#editor-source { flex: 1; min-width: 0; height: 22rem; padding: .5rem; resize: vertical; white-space: pre; overflow: auto; background: var(--surface); color: var(--ink); border: 0; font: .85rem/1.4 ui-monospace, monospace; }
#problems { white-space: pre-wrap; }
.ok { color: var(--green); } .bad { color: #b42d2d; }
.deeper { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.deeper .primary-card { border-color: var(--orange); background: var(--accent-soft); }
@media (max-width: 700px) {
  .bracket { display: block; }
  .bracket-round { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); margin-bottom: 1rem; }
  .bracket-match::after { display: none; }
  .challenge-layout { grid-template-columns: minmax(0, 1fr); }
  .deeper { grid-template-columns: 1fr; }
}
@media (prefers-color-scheme: dark) {
  .arena-frame { background: var(--surface); }
  .battle-svg-host svg > rect:first-of-type { fill: #16283b; stroke: #6d839d; }
  .battle-svg-host svg g[id^="robot-"] text { fill: #edf4ff; }
}

.legend-engine { flex-basis: 100%; padding-left: 1.2rem; font-size: .72rem; font-weight: 400; opacity: .78; }

.manual-diagram { margin: 1.5rem 0; padding: .8rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--surface); }
.manual-diagram svg { display: block; width: 100%; max-width: 460px; height: auto; margin: auto; color: var(--ink); }
.manual-diagram svg text { fill: currentColor; font: 14px system-ui, sans-serif; }
.manual-diagram svg rect { fill: var(--page); stroke: var(--ink); stroke-width: 2; }
.manual-diagram svg > circle:not([class]) { fill: var(--accent); }
.manual-diagram svg > path:not([class]) { fill: none; stroke: var(--accent); stroke-width: 3; }
.manual-diagram .scan-wedge { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.manual-diagram .robot-blue { fill: var(--accent); }
.manual-diagram .robot-orange { fill: var(--orange); }
.manual-diagram .missile-path { fill: none; stroke: var(--orange); stroke-width: 3; stroke-dasharray: 7 5; }
.manual-diagram .missile { fill: var(--orange); }
.manual-diagram figcaption { color: var(--muted); font-size: .9rem; margin-top: .5rem; }
.battle-output { min-height: 2.8rem; padding-top: .8rem; scroll-padding-top: .8rem; }
.match-games summary { cursor: pointer; font-size: .85rem; }
