:root {
  --ink: #12202b;
  --muted: #5b6b75;
  --line: #d4dde3;
  --paper: #f6f3ec;
  --panel: #fffdf8;
  --accent: #0f6e62;
  --fast: #c2410c;
  --cheap: #1d4e89;
  --pax: #0f766e;
  --main: #1d4e89;
  --other: #64748b;
  --transit: #7c3aed;
  --oos: #b45309;
  --abn: #b91c1c;
  --rem: #44403c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.45 "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

a { color: var(--accent); }

.top {
  padding: 0.7rem 1rem 0.55rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.brand a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}

.brand strong {
  font-size: 1.05rem;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0.35rem 0 0;
  max-width: 62rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  height: calc(100dvh - 4.6rem);
}

#map,
#map.leaflet-container {
  min-height: 22rem;
  background: #e7eef2;
}

.rail-canvas {
  pointer-events: none;
}

.panel {
  overflow: auto;
  padding: 0.9rem 1rem 1.4rem;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.search { position: relative; margin-bottom: 0.65rem; }

.search input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

#suggest {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  margin: 0.2rem 0 0;
  padding: 0.25rem;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  max-height: 14rem;
  overflow: auto;
  box-shadow: 0 10px 24px rgba(18, 32, 43, 0.12);
}

#suggest button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
}

#suggest button:hover,
#suggest button:focus-visible {
  background: #eef6f4;
}

.status {
  margin: 0.8rem 0 0.4rem;
  font-weight: 650;
}

.picks {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.75rem 0 0.5rem;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.toggles button,
.clear {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.toggles button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.clear {
  margin-left: auto;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin: 0.6rem 0;
}

.stat {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.stat b {
  display: block;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}

.stat span {
  color: var(--muted);
  font-size: 0.75rem;
}

.stat.wide { grid-column: 1 / -1; }

.mix {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.sections h3 {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.88rem;
}

.sections p {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.sections table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.sections th,
.sections td {
  padding: 0.32rem 0.2rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.sections th:nth-child(n + 2),
.sections td:nth-child(n + 2) {
  text-align: right;
  white-space: nowrap;
}

.sections tbody tr:hover {
  background: #eef6f4;
}

.stops {
  margin: 0.55rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.nets,
.formula {
  margin-top: 1.2rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.nets h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.nets p {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.net-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.net-toggles button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
  color: var(--ink);
}

.net-toggles button[aria-pressed="false"] {
  opacity: 0.42;
  background: #f3f0ea;
}

.formula h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.formula p,
.source {
  color: var(--muted);
  font-size: 0.78rem;
}

.formula table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.formula th,
.formula td {
  padding: 0.28rem 0.2rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.swatch {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  margin-right: 0.3rem;
  border-radius: 99px;
  vertical-align: -0.05rem;
}

.formula th:nth-child(n + 2),
.formula td:nth-child(n + 2) {
  text-align: right;
  white-space: nowrap;
}

.start-mark, .end-mark {
  width: 16px;
  height: 16px;
  border-radius: 99px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--ink);
}

.start-mark { background: var(--accent); }
.end-mark { background: var(--fast); }

@media (max-width: 820px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(18rem, 48vh) 1fr;
    height: auto;
    min-height: calc(100dvh - 5.2rem);
  }

  .panel { border-left: 0; border-top: 1px solid var(--line); }
}
