:root {
  --bg: #0f1318; --panel: #181e26; --panel-2: #1f2630; --line: #2d3744;
  --ink: #e5eaf1; --ink-2: #aab5c3; --ink-3: #7c8999;
  --amber: #f2b63c; --teal: #5ad1b3; --yellow: #f4d635; --cyan: #2fd3e8; --red: #ff7a6b; --blue: #7ab2ff;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); font-variant-ligatures: none; }
a { color: var(--amber); }
canvas { display: block; width: 100%; height: 100%; }
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--ink-3); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
button.primary { background: var(--amber); border-color: var(--amber); color: #15120a; font-weight: 650; min-width: 72px; }
button.toggle.on { background: var(--amber); color: #15120a; border-color: var(--amber); }

/* Demo page: world first, logic in the sidebar */
.demo { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; }
.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top h1 { font-size: 18px; margin: 0; font-weight: 650; }
.top .back { text-decoration: none; color: var(--ink-2); white-space: nowrap; }
.top .back:hover { color: var(--ink); }
.top .ctl { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.top .blurb { color: var(--ink-2); flex: 1 1 280px; min-width: 200px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 10px; padding: 10px 14px; }
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.panel > h2 { font-size: 11px; line-height: 16px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 4px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; }
.statline { font-size: 12.5px; line-height: 18px; min-height: 18px; color: var(--ink-2); margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; }
.min-world { min-height: 260px; }
.min-code { min-height: 250px; }
.min-sm { min-height: 210px; }
.grow { flex: 1 1 0; }
.canvas-wrap { flex: 1 1 0; min-height: 60px; position: relative; }
.canvas-wrap canvas { position: absolute; inset: 0; cursor: pointer; }
.row { display: flex; gap: 10px; }
.row > .panel { min-width: 0; }

/* FSM */
#fsm { flex: 0 0 auto; }
.fsm { display: block; width: 100%; height: auto; }
.node rect { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.2; }
.node .heat { fill: var(--amber); stroke: none; pointer-events: none; }
.node-title { font: 650 11px var(--sans); fill: var(--ink); pointer-events: none; }
.node-action { font: 10.5px var(--mono); fill: var(--ink-2); pointer-events: none; font-variant-ligatures: none; }
.node.rule rect { stroke: var(--teal); }
.node.update rect { stroke: var(--blue); }
.node.active rect:first-child { fill: var(--amber); stroke: var(--amber); }
.node.active .node-title, .node.active .node-action { fill: #15120a; }
.node.peek rect:first-child { stroke: var(--amber); stroke-width: 2.4; }
.edge polyline { stroke: #5c6a7b; stroke-width: 1.3; }
.edge.on polyline { stroke: var(--amber); stroke-width: 2.4; }
.arrowhead { fill: #5c6a7b; }
.arrowhead.on { fill: var(--amber); }
.edge-bg { fill: var(--panel); }
.edge-label { font: 10.5px var(--mono); fill: var(--ink-2); font-variant-ligatures: none; }
.edge.on .edge-label { fill: var(--amber); font-weight: 700; }

/* Note, code, registers */
#note { font-size: 13.5px; padding: 6px 9px; border-left: 3px solid var(--amber); background: var(--panel-2); border-radius: 0 5px 5px 0; min-height: 2.9em; margin-bottom: 6px; color: var(--ink); }
#note.fast { color: var(--ink-3); border-left-color: var(--line); }
.logic-low { display: grid; grid-template-columns: minmax(0, 1fr) 165px; gap: 10px; flex: 1 1 0; min-height: 0; }
.logic-low > * { min-height: 0; }
#code { overflow: auto; font: 12.5px/1.5 var(--mono); flex: 1 1 0; min-height: 0; position: relative; }
.line { display: flex; white-space: pre; border-radius: 3px; }
.line .tag { flex: 0 0 104px; color: var(--ink-3); font-size: 10px; line-height: 18.75px; padding: 0 6px; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.line code { font: inherit; color: var(--ink); padding-right: 8px; font-variant-ligatures: none; }
.line.plain code { color: var(--ink-2); }
.line.on { background: var(--amber); }
.line.on code, .line.on code * , .line.on .tag { color: #15120a !important; }
.line.peek { box-shadow: inset 0 0 0 1px var(--amber); }
.kw { color: #d3a6ff; font-weight: 500; }
.num { color: #8fd0ff; }
.cm { color: var(--ink-3); }
#regs { font: 12.5px var(--mono); overflow: auto; }
.reg { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.reg .k { color: var(--ink-2); white-space: nowrap; }
.reg .v { color: var(--ink); text-align: right; word-break: break-all; }

/* Transport */
#transport { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.speed-group { display: flex; align-items: center; gap: 8px; flex: 1 1 380px; }
.speed-group label { font-weight: 650; }
.speed-group .end { color: var(--ink-3); font-size: 12px; }
#t-rate { flex: 1; accent-color: var(--amber); min-width: 90px; }
.readout { color: var(--ink-2); font: 12.5px var(--mono); min-width: 210px; text-align: right; }
.extra { display: flex; gap: 8px; align-items: center; color: var(--ink-2); }
.extra:empty { display: none; }

/* Rule tables */
table.rules { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rules th { text-align: left; font-size: 11px; color: var(--ink-3); font-weight: 600; padding: 2px 6px; }
table.rules td { padding: 3px 6px; border-top: 1px solid var(--line); }
table.rules td.n { text-align: right; font-family: var(--mono); }
table.rules td.m { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
table.rules tr.fired td { background: var(--panel-2); color: var(--ink); font-weight: 650; box-shadow: inset 0 2px 0 var(--amber), inset 0 -2px 0 var(--amber); }
table.rules tr.fired td.m { color: var(--ink); }

/* Sliders in a panel */
.sliders { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(70px, 1fr) 48px; gap: 3px 8px; align-items: center; font-size: 13px; }
.sliders input { accent-color: var(--amber); width: 100%; }
.sliders .val { font-family: var(--mono); font-size: 12px; text-align: right; color: var(--ink-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* GA genome strips: one thin cell per bit, grouped by what the genes control */
.genome { font: 11px var(--mono); }
.strip-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; align-items: center; margin-top: 3px; }
.strip-row .who { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip { display: flex; gap: 6px; min-width: 0; }
.strip .grp { display: flex; gap: 2px; min-width: 0; }
.strip .gene { display: flex; flex: 1 1 0; min-width: 0; }
.bit { flex: 1 1 0; min-width: 0; height: 15px; background: #2a323d; }
.bit.b1 { background: #8d9aab; }
.bit.fromA { box-shadow: inset 0 -3px 0 var(--teal); }
.bit.fromB { box-shadow: inset 0 -3px 0 var(--blue); }
.bit.flip { background: var(--red); box-shadow: none; }
.bit.cut { box-shadow: inset 2px 0 0 var(--amber); }
.bit.cut.fromA, .bit.cut.fromB { box-shadow: inset 2px 0 0 var(--amber), inset 0 -3px 0 var(--blue); }
.strip-head { color: var(--ink-3); }
.strip-head .grp { font: 10.5px var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.traits { color: var(--ink); font: 12px var(--sans); margin-top: 5px; line-height: 1.45; }
.traits b { color: var(--ink-2); font-weight: 500; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-2); font-size: 12px; margin-top: 5px; }
.legend i { display: inline-block; width: 16px; height: 3px; margin-right: 5px; vertical-align: middle; }

/* Start page */
.home { max-width: 1240px; margin: 0 auto; padding: 44px 24px 40px; }
.home .eyebrow { color: var(--amber); font: 650 13px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.home h1 { font-size: 40px; line-height: 1.12; margin: 8px 0 12px; }
.home .lede { font-size: 17px; color: var(--ink-2); max-width: 760px; margin: 0 0 30px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: inherit; text-decoration: none; display: flex; flex-direction: column; transition: border-color .15s; }
.card:hover, .card:focus-visible { border-color: var(--amber); }
.card .thumb { height: 230px; background: var(--bg); border-bottom: 1px solid var(--line); }
.card .body { padding: 14px 16px 16px; }
.card h2 { margin: 0 0 4px; font-size: 20px; }
.card p { margin: 0; color: var(--ink-2); }
.card .zoom { margin-top: 8px; color: var(--ink); font-size: 13px; }
.card .zoom b { color: var(--amber); font-weight: 650; }
.how { margin-top: 32px; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; color: var(--ink-2); }
.how b { color: var(--ink); display: block; margin-bottom: 2px; }
.keys { margin-top: 26px; color: var(--ink-3); font-size: 13px; }
kbd { font: 12px var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--ink-2); }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .col > .panel, .col > .row { flex: 0 0 auto !important; }
  .min-world .canvas-wrap, .min-sm .canvas-wrap { min-height: 320px; }
  .logic-low { flex: 0 0 340px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .home h1 { font-size: 30px; }
}
}
