/* Same base palette as the homepage (docs/index.html), plus a colour for each section. */
:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --inset: #faf8f5;
  --text: #24211d;
  --muted: #6b645b;
  --border: #ddd6cc;
  --accent: #c96a12;
  --accent-text: #ffffff;
  --code-bg: #efe9e1;
  --locked: #9a9087;
  --c-belts: #b8860b;
  --c-inserters: #3d8a37;
  --c-robots: #2f6fbf;
  --c-mining: #8a5a2b;
  --c-smelting: #c9501c;
  --c-power: #7656c9;
  --c-ratios: #b83b72;
  --c-labs: #1d8a7c;
  --c-planets: #4659b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --panel: #24221f;
    --inset: #1f1d1b;
    --text: #ece7df;
    --muted: #a39b8f;
    --border: #3a3631;
    --accent: #f0952e;
    --accent-text: #1b1a18;
    --code-bg: #312e2a;
    --locked: #7d756b;
    --c-belts: #e0b23a;
    --c-inserters: #6cc25f;
    --c-robots: #66a6f2;
    --c-mining: #cf955c;
    --c-smelting: #f0834d;
    --c-power: #a98cf5;
    --c-ratios: #ec74a8;
    --c-labs: #4fc7b5;
    --c-planets: #8495f0;
    color-scheme: dark;
  }
}
#belts, a[href="#belts"] { --sec: var(--c-belts); }
#inserters, a[href="#inserters"] { --sec: var(--c-inserters); }
#robots, a[href="#robots"] { --sec: var(--c-robots); }
#mining, a[href="#mining"] { --sec: var(--c-mining); }
#smelting, a[href="#smelting"] { --sec: var(--c-smelting); }
#power, a[href="#power"] { --sec: var(--c-power); }
#ratios, a[href="#ratios"] { --sec: var(--c-ratios); }
#labs, a[href="#labs"] { --sec: var(--c-labs); }
#planets, a[href="#planets"] { --sec: var(--c-planets); }

* { box-sizing: border-box; }
html { scroll-padding-top: 3.75rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--code-bg); padding: .1em .35em; border-radius: 3px; }
.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }
.icon { width: 1.1em; height: 1.1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Header */
.top { padding: 1.5rem 0 .25rem; }
.crumbs { margin: 0; font-size: .875rem; color: var(--muted); }
h1 { font-size: 2rem; line-height: 1.2; margin: .25rem 0; letter-spacing: -.01em; }
.lede { color: var(--muted); margin: 0 0 1rem; max-width: 48rem; }
.status { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px; padding: .6rem .9rem; }
.status.warn { border-left-color: var(--locked); }
.controls { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; margin: .75rem 0; font-size: .9rem; }
.mode { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.mode legend { float: left; margin-right: .75rem; color: var(--muted); }
.file { color: var(--muted); }
.file input { font: inherit; font-size: .85rem; max-width: 100%; }

/* Section links: stay at the top while scrolling, and mark the section in view. */
.toc {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.toc .wrap { display: flex; gap: .3rem; padding-top: .5rem; padding-bottom: .5rem; overflow-x: auto; scrollbar-width: none; }
.toc .wrap::-webkit-scrollbar { display: none; }
.toc a {
  display: inline-flex; align-items: center; gap: .35rem; flex: none;
  text-decoration: none; color: var(--text);
  padding: .25rem .7rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); font-size: .875rem;
}
.toc a .icon { color: var(--sec); }
.toc a:hover { border-color: var(--sec); }
.toc a.active { background: var(--sec); border-color: var(--sec); color: var(--panel); }
.toc a.active .icon { color: var(--panel); }

/* At a glance */
.glance { display: grid; grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr)); gap: .6rem; margin: 1.25rem 0 2rem; }
.tile {
  display: grid; grid-template-columns: auto 1fr; column-gap: .5rem; align-items: center;
  text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-top: 3px solid var(--sec); border-radius: 8px;
  padding: .6rem .8rem;
}
.tile:hover { border-color: var(--sec); }
.tile .icon { grid-row: span 3; width: 1.6rem; height: 1.6rem; color: var(--sec); align-self: start; margin-top: .1rem; }
.tile .k { font-size: .8rem; color: var(--muted); }
.tile .v { font-size: 1.4rem; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .78rem; color: var(--muted); }

/* Sections: full-width bands, every other one tinted with its colour. */
section.sec { padding: 2.25rem 0 2.5rem; border-top: 1px solid var(--border); }
section.sec:nth-of-type(even) { background: color-mix(in srgb, var(--sec) 7%, var(--bg)); }
main { counter-reset: sec; }
section.sec > .wrap > h2 {
  counter-increment: sec;
  display: flex; align-items: center; gap: .8rem;
  margin: 0 0 1rem; font-size: 1.75rem; letter-spacing: -.01em; line-height: 1.15;
}
section.sec > .wrap > h2::after {
  content: counter(sec, decimal-leading-zero);
  margin-left: auto; font-size: 2.6rem; font-weight: 800; line-height: 1;
  color: color-mix(in srgb, var(--sec) 22%, transparent);
}
.badge {
  display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 12px;
  background: var(--sec); color: var(--panel);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--sec) 35%, transparent);
}
.badge .icon { width: 1.5rem; height: 1.5rem; stroke-width: 2; }

/* Cards for single things (belts, inserters, robots, labs, planets). */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr)); gap: .8rem; }
.units.small { grid-template-columns: repeat(auto-fill, minmax(min(100%, 13.5rem), 1fr)); }
.units.five { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr)); }
.units.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); }
.unit {
  --c: var(--sec);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .05);
}
.unit:not(:has(> .belt, > .orb, > .pips)) { border-top: 4px solid var(--c); }
.unit-body { padding: .75rem .95rem .9rem; display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.unit-title { font-weight: 650; font-size: 1rem; }
.unit-title .unlock { display: block; font-weight: 400; }
.unit-big { font-size: 2.1rem; font-weight: 750; line-height: 1.1; color: var(--c); font-variant-numeric: tabular-nums; margin-top: .2rem; }
.unit-big small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.unit-sub { font-size: .8rem; color: var(--muted); }
.unit-sub .next { display: inline; }
.unit dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: .6rem 0 0; padding-top: .6rem; border-top: 1px dashed var(--border); font-size: .875rem; }
.unit dt { color: var(--muted); }
.unit dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.unit.locked { opacity: .55; filter: grayscale(.7); }
.unit.locked:hover { opacity: .85; }

/* A belt that moves at its tier's speed. */
.belt {
  height: 1.6rem; background-color: color-mix(in srgb, var(--c) 30%, #2a2723);
  background-image: repeating-linear-gradient(90deg, transparent 0 10px, var(--c) 10px 14px, transparent 14px 24px);
  border-bottom: 3px solid var(--c);
  animation: belt var(--d) linear infinite;
}
@keyframes belt { to { background-position: 24px 0; } }
.unit.locked .belt { animation: none; }
@media (prefers-reduced-motion: reduce) { .belt { animation: none; } }

/* Hand size as squares. */
.pips { display: flex; flex-wrap: wrap; gap: 3px; padding: .7rem .95rem 0; min-height: 1.6rem; }
.pips i { width: 10px; height: 10px; border-radius: 2px; background: var(--c); }

/* A planet. */
.orb {
  height: 4.5rem; position: relative;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 25%, var(--panel)), var(--panel));
}
.orb::before {
  content: ""; position: absolute; left: .95rem; top: .8rem; width: 3rem; height: 3rem; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 40%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 55%, #000));
  box-shadow: 0 0 18px color-mix(in srgb, var(--c) 45%, transparent);
}
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .65rem; }
.chips span { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--c) 35%, var(--border)); }

/* A chain of machines. */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: .5rem; margin: .5rem 0 1rem; }
.flow .step {
  display: flex; flex-direction: column; justify-content: center; min-width: 7.5rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .85rem;
}
.flow .step b { font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.flow .step span { font-size: .8rem; color: var(--muted); }
.flow .step.result { background: var(--sec); border-color: var(--sec); color: var(--panel); }
.flow .step.result span { color: color-mix(in srgb, var(--panel) 80%, transparent); }
.flow .arrow { align-self: center; font-size: 1.3rem; color: var(--sec); font-weight: 700; }
.reactors { display: inline-grid; grid-template-columns: repeat(var(--cols), 8px); gap: 2px; margin-right: .6rem; vertical-align: middle; }
.reactors i { width: 8px; height: 8px; border-radius: 2px; background: var(--sec); }

h3 { font-size: 1.05rem; margin: 1.4rem 0 .4rem; }
section.sec h3:not(.ratio h3, .unit h3) { padding-left: .6rem; border-left: 3px solid var(--sec); }
.intro { color: var(--muted); margin: 0 0 .75rem; max-width: 52rem; }
.bonuses { display: flex; flex-wrap: wrap; gap: .6rem; margin: .25rem 0 1rem; }
.bonus {
  background: color-mix(in srgb, var(--sec) 7%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--sec) 30%, var(--border)); border-left: 4px solid var(--sec);
  border-radius: 6px; padding: .5rem .85rem; min-width: 12rem;
}
.bonus .k { color: var(--muted); font-size: .8rem; }
.bonus .v { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Tables */
.scroll + .scroll { margin-top: .75rem; }
.scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: .45rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; font-weight: 550; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--inset); border-bottom: 2px solid color-mix(in srgb, var(--sec, var(--border)) 45%, var(--border)); }
tbody tr:nth-child(even) td { background: var(--inset); }
tbody tr:hover td { background: color-mix(in srgb, var(--sec, var(--accent)) 8%, var(--panel)); }
tbody tr:last-child td { border-bottom: 0; }
tr.locked td { color: var(--locked); font-weight: 400; }
.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; background: var(--c); margin-right: .45rem; vertical-align: -.05rem; }
tr.locked .swatch { opacity: .45; }
.tag { font-size: .75rem; color: var(--muted); font-weight: 400; }
.next { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }
.next b { color: var(--accent); font-weight: 600; }
.note { color: var(--muted); font-size: .85rem; margin: .5rem 0 0; max-width: 52rem; }
.unlock { font-size: .8rem; color: var(--muted); font-weight: 400; }

/* Ratios, grouped by planet */
section.sec h3.group { display: flex; align-items: center; gap: .5rem; border-left: 0; padding-left: 0; margin-top: 1.5rem; }
h3.group::before { content: ""; width: .8rem; height: .8rem; border-radius: 50%; background: var(--c); }
h3.group::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.ratios { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 27rem), 1fr)); gap: .75rem; }
.ratio { background: var(--inset); border: 1px solid var(--border); border-radius: 8px; padding: .65rem .8rem; }
.ratio h3 { margin: 0 0 .15rem; }
.ratio .sum { font-size: 1.15rem; font-weight: 650; margin: .1rem 0 .4rem; color: var(--sec); }
.ratio .sum .tag { color: var(--muted); }
.ratio table { font-size: .875rem; }
.ratio th, .ratio td { padding: .28rem .45rem; }
.ratio td:nth-child(-n+2), .ratio th:nth-child(-n+2) { white-space: normal; text-align: left; }
.ratio .scroll { overflow-x: visible; }
.ratio .raw { font-size: .8rem; color: var(--muted); margin: .4rem 0 0; white-space: normal; }
.size { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .25rem 0 .5rem; font-size: .9rem; }
.size select { font: inherit; }

footer { color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); margin-top: 2rem; padding-top: 1rem; padding-bottom: 3rem; }

@media (max-width: 40rem) {
  section.sec { padding: 1.5rem 0 1.75rem; }
  section.sec > .wrap > h2 { font-size: 1.4rem; }
  section.sec > .wrap > h2::after { font-size: 1.8rem; }
  .flow .step { min-width: 0; flex: 1 1 6rem; }
}

/* Copy a generated blueprint string. */
button.bp { font: inherit; font-size: .8rem; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 4px; padding: .15rem .6rem; cursor: pointer; white-space: nowrap; }
button.bp:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.bp-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; max-width: min(40rem, 92vw); }
.bp-dialog::backdrop { background: rgb(0 0 0 / .5); }
.bp-dialog textarea { width: 100%; font: .75rem ui-monospace, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; }
.bp-dialog form { text-align: right; margin-top: .5rem; }
