:root {
  --paper: #f4f1ea;
  --ink: #1c1b19;
  --muted: #7a756b;
  --rule: #d9d4c8;
  --card: #fbf9f4;
  --accent: #c8402f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141413;
    --ink: #ebe7dd;
    --muted: #8c877c;
    --rule: #2e2d2a;
    --card: #1b1b19;
    --accent: #ef6a55;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header { padding: 28px 32px 8px; }
h1 {
  margin: 0;
  font: italic 400 34px/1.1 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  letter-spacing: -0.01em;
}
.tagline { margin: 4px 0 0; color: var(--muted); }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  padding: 16px 32px 24px;
  min-height: 0;
}

.panel { display: flex; flex-direction: column; gap: 12px; }
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
label output { float: right; font-variant-numeric: tabular-nums; }
select, button {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 7px 8px;
}
select { width: 100%; text-transform: none; letter-spacing: 0; font-size: 14px; }
button { cursor: pointer; }
button:hover { border-color: var(--ink); }
button.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  flex: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
  padding: 10px;
}
button.primary:disabled { opacity: 0.4; cursor: default; }
button.ghost { background: transparent; }
#swap { align-self: flex-start; padding: 2px 10px; margin: -6px 0; }
input[type="range"] { width: 100%; accent-color: var(--ink); }
.layers { border: 1px solid var(--rule); border-radius: 2px; margin: 0; padding: 6px 10px 8px;
  display: flex; flex-direction: column; gap: 5px; }
.layers legend { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  padding: 0 4px; }
.layers label { flex-direction: row; align-items: baseline; gap: 7px; font-size: 14px;
  letter-spacing: 0; text-transform: none; color: var(--ink); cursor: pointer; }
.layers input { accent-color: var(--ink); margin: 0; }
.layers input:disabled + * { opacity: 0.4; }
.buttons { display: flex; gap: 8px; margin-top: 4px; }
.buttons .ghost { padding: 7px 12px; }
button:disabled { opacity: 0.4; cursor: default; }
.tip { margin: -4px 0 0; font-size: 12px; color: var(--muted); }

.summary { margin: 4px 0 0; color: var(--muted); font-size: 13px; min-height: 3.2em; }
.summary strong { color: var(--ink); font-weight: 500; }

.legend { list-style: none; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--rule);
  display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 18px; height: 3px; border-radius: 2px; flex: none; }

.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.map-wrap {
  position: relative;
  flex: 1;
  min-height: 380px;
  border: 1px solid var(--rule);
  background: var(--card);
  overflow: hidden;
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map .line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke; transition: opacity 0.3s; }
#map.has-route .line { opacity: 0.22; }
#map .walk { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3;
  vector-effect: non-scaling-stroke; fill: none; }
#map .route { fill: none; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke; }
#map .route.walk-leg { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 1 5; }
#map .station { fill: var(--card); stroke: var(--ink); stroke-width: 1.2;
  vector-effect: non-scaling-stroke; cursor: pointer; transition: opacity 0.3s; }
#map.has-route .station:not(.on-route) { opacity: 0.35; }
#map .station:hover { fill: var(--ink); opacity: 1 !important; }
#map .station.end { fill: var(--ink); }
#map .train { fill: var(--accent); stroke: var(--card); stroke-width: 2;
  vector-effect: non-scaling-stroke; pointer-events: none; }
#map text { fill: var(--ink); pointer-events: none; paint-order: stroke; stroke: var(--card);
  stroke-linejoin: round; }
#map text.hover { fill: var(--muted); }

.zoom { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 28px; height: 28px; padding: 0; background: var(--card); line-height: 1; }
.hint { position: absolute; left: 12px; bottom: 8px; margin: 0; font-size: 12px; color: var(--muted);
  pointer-events: none; }

.profile-wrap { border: 1px solid var(--rule); background: var(--card); padding: 10px 14px 6px; }
.now { display: flex; gap: 16px; align-items: baseline; font-size: 13px; min-height: 22px; }
#nowStation { font: italic 17px "Iowan Old Style", Palatino, Georgia, serif; }
#nowElev, #nowChord, #nowTime { color: var(--muted); font-variant-numeric: tabular-nums; }
#nowChord { margin-left: auto; color: var(--ink); letter-spacing: 0.04em; }
#profile { display: block; width: 100%; height: 150px; }
#profile .rowlabel { letter-spacing: 0.06em; text-transform: uppercase; font-size: 9px; }
#profile text { fill: var(--muted); font-size: 10px; }
#profile .axis { stroke: var(--rule); stroke-width: 1; }
#profile .tick { stroke: var(--rule); stroke-width: 1; }
#profile .seg { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#profile .raw { stroke-width: 0.75; opacity: 0.35; }
#profile .fill { opacity: 0.12; stroke: none; }
#profile .walk-leg { stroke: var(--muted); stroke-dasharray: 2 4; stroke-width: 1; }
#profile .playhead { stroke: var(--accent); stroke-width: 1.5; }
#profile .dot { fill: var(--accent); }
#profile .stop { fill: var(--card); stroke: var(--ink); stroke-width: 1; }

footer { padding: 0 32px 20px; font-size: 11px; color: var(--muted); }

/* Desktop: the page fits the window; the side panel scrolls if it must, so the
   map and the terrain profile stay in view together. */
@media (min-width: 761px) {
  body { height: 100vh; }
  main { overflow: hidden; }
  .panel { overflow-y: auto; padding-right: 4px; }
  .stage { min-height: 0; }
  .map-wrap { min-height: 160px; }
}

@media (max-width: 760px) {
  header { padding: 20px 16px 4px; }
  main { grid-template-columns: 1fr; padding: 12px 16px 16px; }
  .map-wrap { min-height: 320px; }
  footer { padding: 0 16px 16px; }
}
