:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --fg: #1d1f24;
  --muted: #5d6270;
  --line: #dcd9d0;
  --accent: #1f5f8b;
  --accent-fg: #ffffff;
  --bad: #b3261e;
  --chip: #eef2f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --card: #1e2128;
    --fg: #e9e9ec;
    --muted: #a3a8b4;
    --line: #353a45;
    --accent: #6fb3e0;
    --accent-fg: #0d1117;
    --bad: #ff8a80;
    --chip: #262b35;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c;
  --card: #1e2128;
  --fg: #e9e9ec;
  --muted: #a3a8b4;
  --line: #353a45;
  --accent: #6fb3e0;
  --accent-fg: #0d1117;
  --bad: #ff8a80;
  --chip: #262b35;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 48px;
}
.wrap { max-width: 980px; margin: 0 auto; }
h1, h2 { font-family: "Space Grotesk", "Inter", system-ui, sans-serif; text-wrap: balance; margin: 0; }
h1 { font-size: 28px; letter-spacing: -0.01em; }
h2 { font-size: 17px; }

.top { padding-top: 28px; padding-bottom: 8px; }
.lede { color: var(--muted); margin: 6px 0 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 16px 0;
  min-width: 0;
}
.step { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step span {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  font-size: 13px; font-weight: 600; flex: none;
}

.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.row.run-row { align-items: flex-start; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; flex: 1 1 160px; }
.field.grow { flex: 2 1 260px; }
.field > span { font-size: 13px; color: var(--muted); }
.field > code { font-size: 11px; color: var(--muted); }
.field.estimate strong { font-size: 15px; }
select, input[type="number"], input[type="file"] {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  min-width: 0; width: 100%;
}
input[type="file"] { padding: 5px; }

.muted { color: var(--muted); font-size: 14px; margin: 6px 0 10px; }
.msg { margin: 10px 0 0; font-size: 14px; min-height: 0; }
.msg:empty { display: none; }
.error { color: var(--bad); }

dl.facts {
  display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px;
  margin: 14px 0 0; font-size: 14px;
}
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.params { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.params .field { flex: 1 1 200px; }
.params .btn { align-self: flex-start; }

.chips-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.count { color: var(--muted); font-size: 13px; margin-left: auto; }
.ops-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px; margin: 10px 0 14px;
}
.op {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: start;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: var(--bg); cursor: pointer; min-width: 0;
}
.op input { margin: 3px 0 0; }
.op-name { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 14px; }
.op-group { font-size: 12px; color: var(--muted); }
.op small { grid-column: 2; color: var(--muted); font-size: 12px; line-height: 1.35; }

.btn {
  font: inherit; font-size: 14px; color: var(--fg); background: var(--chip);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.status { font-size: 14px; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.status.error { color: var(--bad); }

.progress { height: 6px; background: var(--chip); border-radius: 4px; margin-top: 14px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.bad, td .bad { color: var(--bad); }

.log {
  margin: 14px 0 0; padding: 12px; max-height: 320px; overflow: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font: 12px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre;
}
.about p { font-size: 14px; }

@media (max-width: 560px) {
  h1 { font-size: 24px; }
  .card { padding: 16px; }
  .field { min-width: 0; flex: 1 1 100%; }
  .count { margin-left: 0; width: 100%; }
}

/* ---------- navigation and Learn page ---------- */
.nav { display: flex; gap: 14px; margin-bottom: 10px; font-size: 14px; }
.nav a { color: var(--accent); text-decoration: none; padding: 2px 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 600; }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.op-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.op-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--bg); min-width: 0; }
.op-card h3 { margin: 0 0 6px; font-size: 15px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.op-card p { margin: 4px 0; font-size: 14px; }
.op-card .ref { color: var(--muted); font-size: 13px; }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }

.fig { margin: 16px 0 6px; min-width: 0; }
.fig svg { width: 100%; height: auto; display: block; }
.fig figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; }
.diagrams { display: grid; gap: 14px; margin-top: 10px; }

.node-box { fill: var(--chip); stroke: var(--accent); stroke-width: 1.2; }
.arrow { stroke: var(--muted); stroke-width: 1.4; }
.arrow-head { fill: var(--muted); }
.lbl { fill: var(--fg); font-size: 14px; font-family: "Inter", system-ui, sans-serif; }
.lbl.small { font-size: 13px; }
.lbl.bold { font-weight: 600; }
.divider { stroke: var(--line); stroke-dasharray: 3 3; }
.grid { stroke: var(--line); stroke-width: 1; }
.axis { stroke: var(--muted); stroke-width: 1.2; }
.series { stroke-width: 2.4; }
.series.s0 { stroke: var(--accent); }
.series.s1 { stroke: #c2410c; }
.series.s2 { stroke: #15803d; }
.bar { fill: var(--accent); }

.refs, .bullets { padding-left: 20px; font-size: 14px; }
.refs li, .bullets li { margin: 6px 0; }

/* operator mini charts and family legend */
.op-card { border-top-width: 4px; }
.family-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 6px 0 4px; font-size: 13px; }
.family-legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.mini-cap { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.mini-cap code { font-size: 12px; }
.lbl.tiny { font-size: 10px; fill: var(--muted); }

/* move diagrams: route colours, depots and highlighted customers */
.rt { stroke-width: 2.2; }
.rt.r0 { stroke: #1f5f8b; }
.rt.r1 { stroke: #c2410c; stroke-dasharray: 0; }
.node { fill: var(--card); stroke-width: 2; }
.node.r0 { stroke: #1f5f8b; }
.node.r1 { stroke: #c2410c; }
.node.hl { fill: #f59e0b; stroke: #b45309; }
.lbl.hltxt { fill: #1d1f24; font-weight: 600; font-size: 13px; }
.depot { fill: #15803d; }
.lbl.depot-lbl { fill: #ffffff; font-size: 12px; font-weight: 600; }
.diagrams { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 10px; }
.diag { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 8px; margin: 0; }
.diag figcaption strong { color: var(--fg); }

/* literature matrix */
.matrix { font-size: 13px; }
.matrix td.tick { text-align: center; color: var(--muted); }
.matrix td.yes { color: #15803d; font-weight: 700; font-size: 16px; }
.matrix td.pending { color: #b45309; font-weight: 600; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; vertical-align: 0; }

/* Instance map and gap strip (style follows the CLRP lab: customers dots, depots squares) */
.map-fig { margin: 12px 0 0; }
.map-fig svg { display: block; width: 100%; max-width: 640px; height: auto; }
.map-bg { fill: var(--chip); }
.map-cust { fill: var(--fg); fill-opacity: 0.72; }
.map-depot { fill: #E8A317; stroke: var(--fg); stroke-width: 1.2; }
.map-axis { stroke: var(--line); stroke-width: 1.5; }
.map-ref { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.map-dot { fill: var(--accent); fill-opacity: 0.75; }
.map-med { stroke: var(--fg); stroke-width: 2; }
.map-lbl { fill: var(--muted); font: 12px system-ui, sans-serif; }
.conv-seed { stroke: var(--accent); stroke-opacity: 0.4; }
.conv-med { stroke: var(--fg); }

/* Redesign: progress nav, hero problem figure, step hints, result sub-nav, about lead-ins */
.steps-nav { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0 0 14px; }
.steps-nav a { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .92rem; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.steps-nav a span { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: .75rem; }
.steps-nav a:hover { color: var(--fg); border-color: var(--accent); }
.hero figure { margin: 10px 0 0; }
.hero svg { width: 100%; height: auto; display: block; color: var(--fg); }
.hero figcaption { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.problem-lead { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.problem-lead p { margin: 0; padding: 12px 14px; background: var(--chip); border-radius: 8px; font-size: .94rem; }
.hint { color: var(--muted); font-size: .93rem; margin: -4px 0 12px; max-width: 72ch; }
.subnav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 12px; font-size: .92rem; }
.subnav a { color: var(--accent); font-weight: 600; text-decoration: none; }
.subnav a:hover { text-decoration: underline; }
.about p { max-width: 78ch; }
.about strong { color: var(--fg); }

/* Learn page: CLRP-style layout (jump links, two-column problem, equation boxes) */
.jump { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 0 16px; padding: 0; list-style: none; }
.jump a { text-decoration: none; font-weight: 600; font-size: .92rem; color: var(--accent); }
.jump a:hover { text-decoration: underline; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.grid2 > div { min-width: 0; }
.eq { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; font-family: var(--mono, ui-monospace, Menlo, Consolas, monospace); font-size: .9rem; overflow-x: auto; white-space: pre; margin: 8px 0 12px; }

/* Typeset mathematics (KaTeX, pre-rendered; see tools/render_math.js) */
.math-box { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 14px; margin: 8px 0 12px; overflow-x: auto; }
.math-box .katex-display { margin: .55em 0; text-align: left; }
.math-box .katex-display > .katex { text-align: left; }
.notation { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 6px 28px; margin: 8px 0 14px; }
.notation > div { display: flex; gap: .8rem; align-items: baseline; }
.notation dt { min-width: 3.2rem; margin: 0; }
.notation dd { margin: 0; }

/* Guide for uploading own instance data */
.tpl { margin: 12px 0 4px; border: 1px solid var(--line); border-radius: 8px; padding: 0 14px; background: var(--card); }
.tpl > summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.tpl[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tpl p { font-size: 14px; margin: 8px 0; max-width: 78ch; }
.tpl-scroll { overflow-x: auto; margin: 8px 0; }
.tpl-table { border-collapse: collapse; font-size: 14px; width: 100%; }
.tpl-table th, .tpl-table td { text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.tpl-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tpl-table td:last-child { color: var(--muted); white-space: nowrap; }
.tpl-label { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.tpl-example { margin: 0 0 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto;
  font: 12.5px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre; }
.tpl-actions { gap: 10px; margin-bottom: 8px; }
.tpl-tips { font-size: 13.5px; color: var(--muted); padding-left: 1.2rem; margin: 6px 0 12px; max-width: 78ch; }
.tpl-tips code { font-size: 12.5px; }
