:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #646b7a;
  --border: #dde1e7;
  --accent: #e77500;      /* Princeton orange */
  --faster: #19834d;
  --slower: #c53b32;
  --unchanged: #526778;
  --closed: #9aa1ad;
  --empty: #c9ced6;
  --map-bg: #fbfbfc;
  --bus: #2f6fdb;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
}

header { padding: 12px 20px 4px; }
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
h1 { margin: 0; font-size: 1.45rem; }
h1::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; border-radius: 3px; background: var(--accent); }
h2 { margin: 0 0 10px; font-size: 1rem; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.status { margin: 0; font-size: 0.85rem; color: var(--muted); }
.status.error { color: var(--jam); font-weight: 600; }

/* The map takes most of the screen; the results panel stays beside it and scrolls on its own. */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 10px 20px 16px;
}
.panel { min-height: 0; min-width: 0; overflow-y: auto; padding-right: 2px; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  html, body { height: auto; }
  main { grid-template-columns: 1fr; padding: 10px 16px 16px; }
  header { padding: 12px 16px 4px; }
  .panel { overflow: visible; }
  .map-frame { flex: none; height: 62vh; }
}

.map-card, .card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.map-card { padding: 10px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.card { padding: 14px 16px; margin-bottom: 12px; }
.panel .card:last-child { margin-bottom: 0; }
.map-tool-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.map-tool-buttons > button {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; text-align: left; font-size: .81rem; font-weight: 600;
}
.trip-demand {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  gap: 3px 4px; font-size: .8rem;
}
.trip-demand label { grid-column: 1 / -1; }
.trip-demand input { width: 100%; min-width: 0; font: inherit; }
.trip-demand button { padding: 3px 5px; font-size: inherit; }
.map-tool-buttons svg {
  flex: 0 0 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.map-tool-buttons button[aria-pressed="true"] { background: #eeeaff; border-color: var(--accent); color: #392693; }
.map-tool-heading {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin: 10px 0 8px; padding-top: 8px; border-top: 1px solid var(--border);
}
.map-tool-heading p { margin: 0; font-size: .85rem; font-weight: 600; }
.map-tool-heading button { padding: 3px 8px; font-size: .8rem; }

.map-frame { flex: 1; min-height: 360px; border-radius: 6px; overflow: hidden; position: relative; }
.map-frame[hidden] { display: none; }
#leaflet-map { position: absolute; inset: 0; background: #e8eaee; }
.street-map-plane { position: absolute; inset: 0; }
.street-map-plane.is-tilted { transform: perspective(1250px) rotateX(32deg) scale(1.23); }
.princeton-buildings { position: absolute; top: 0; left: 0; }
.building-legend {
  position: absolute; bottom: 24px; left: 8px; z-index: 800;
  padding: 4px 7px; border-radius: 4px; background: #fff; color: #283340;
  font-size: .72rem; box-shadow: 0 1px 4px #0003;
}
.building-legend span, .building-legend a { display: block; }
.building-legend i { display: inline-block; width: 8px; height: 8px; background: #e5ded2; border: 1px solid #8e8677; }
.schematic { background: var(--map-bg); display: flex; }
#map { width: 100%; height: 100%; display: block; background: var(--map-bg); }

.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.view-switch .seg { border: none; border-radius: 0; padding: 6px 12px; background: #fff; }
.view-switch .seg + .seg { border-left: 1px solid var(--border); }
.view-switch .seg[aria-pressed="true"] { background: var(--text); color: #fff; }
.map-note { margin: 0 0 8px; padding: 6px 10px; border-radius: 6px; background: #fff4e5; color: #8a4b00; font-size: 0.85rem; }

/* Street map (Leaflet) overlays */
.road-hit { cursor: pointer; }
.car-icon { pointer-events: none; }
.car-icon .car-rot { width: 14px; height: 26px; transform-origin: 7px 13px; will-change: transform; }
.car-icon svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.45)); }
.map-badge, .map-x { pointer-events: none; }
.map-badge span {
  display: inline-block; transform: translate(-50%, -150%); white-space: nowrap;
  font: 600 12px/1 system-ui, sans-serif; color: var(--text);
  background: rgba(255, 255, 255, 0.92); border: 1px solid var(--border); border-radius: 10px; padding: 3px 7px;
}
.map-x span { display: inline-block; transform: translate(-50%, -50%); font: 700 20px/1 system-ui, sans-serif; color: var(--jam); text-shadow: 0 0 3px #fff, 0 0 3px #fff; }
.road-tip { font-weight: 600; }
.venue-pin { width: 26px; height: 26px; border-radius: 50%; background: rgba(231, 117, 0, 0.25); display: grid; place-items: center; animation: venue-pulse 2s ease-out infinite; }
.venue-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2.5px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
@keyframes venue-pulse { 0% { box-shadow: 0 0 0 0 rgba(231, 117, 0, 0.45); } 100% { box-shadow: 0 0 0 14px rgba(231, 117, 0, 0); } }
@media (prefers-reduced-motion: reduce) { .venue-pin { animation: none; } }
.leaflet-tooltip.venue-label { background: var(--accent); color: #fff; border: none; font-size: 12px; line-height: 1.3; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }
.leaflet-tooltip.venue-label::before { border-right-color: var(--accent); }
.leaflet-container { font-family: inherit; }

/* Roads */
.road .line { stroke-linecap: round; fill: none; transition: stroke 0.2s; }
.road .hit { stroke: transparent; stroke-width: 26; stroke-linecap: round; cursor: pointer; }
.road.closed .line { stroke-dasharray: 10 10; }
.road .halo { stroke: var(--accent); stroke-opacity: 0; stroke-linecap: round; fill: none; }
.road:hover .halo, .road:focus .halo { stroke-opacity: 0.35; }
.road.selected .halo { stroke-opacity: 0.6; }
.road:focus { outline: none; }
.road .x-mark { stroke: var(--jam); stroke-width: 4; stroke-linecap: round; pointer-events: none; display: none; }
.road.closed .x-mark { display: inline; }
.trip-badge { font-size: 13px; font-weight: 600; fill: var(--text); pointer-events: none; paint-order: stroke; stroke: var(--map-bg); stroke-width: 4px; }

/* Bus route overlay */
.bus-line { stroke: currentColor; stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; }

/* Animated cars */
.car { fill: #fff; stroke: var(--text); stroke-width: 1.5; pointer-events: none; }

/* Intersections */
.node { cursor: pointer; }
.node:focus { outline: none; }
.node .dot { fill: #fff; stroke: var(--text); stroke-width: 2; }
.node .ring { fill: none; stroke: transparent; stroke-width: 3; }
.node.can-signal .ring { stroke: var(--accent); stroke-opacity: 0.55; }
.node:hover .ring, .node:focus .ring { stroke: var(--accent); stroke-opacity: 0.8; }
.node.selected .ring { stroke: var(--accent); stroke-opacity: 1; stroke-width: 4; }
.node .node-label { font-size: 12px; fill: var(--muted); pointer-events: none; paint-order: stroke; stroke: var(--map-bg); stroke-width: 4px; }
.node .signal-icon { display: none; pointer-events: none; }
.node.has-signal .signal-icon { display: inline; }
.signal-icon rect { fill: #2b2f38; }
.signal-icon .lamp.red { fill: #ff5a4f; }
.signal-icon .lamp.amber { fill: #6b5a1e; }
.signal-icon .lamp.green { fill: #3ddc84; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 0.82rem; color: var(--muted); }
.swatch { display: inline-block; width: 22px; height: 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.swatch.faster { background: var(--faster); }
.swatch.slower { background: var(--slower); }
.swatch.unchanged { background: var(--unchanged); }
.swatch.empty { background: var(--empty); }
.swatch.closed { background: repeating-linear-gradient(90deg, var(--closed) 0 5px, transparent 5px 9px); }
.swatch.bus { background: repeating-linear-gradient(90deg, var(--bus) 0 3px, transparent 3px 8px); }
.dot.signal-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); margin-right: 6px; vertical-align: middle; }

.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; }

.actions { margin: 12px 0 4px; }
.stepper { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.92rem; }
.stepper span { flex: 1; }
.stepper button { width: 34px; padding: 4px 0; font-weight: 700; }
.stepper .count { min-width: 1.5em; text-align: center; font-variant-numeric: tabular-nums; }
button:disabled { opacity: 0.45; cursor: not-allowed; border-color: var(--border); }

.slider { margin-top: 12px; }
.slider label { display: block; font-size: 0.92rem; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 2px; }

.changes { list-style: none; margin: 0 0 12px; padding: 0; font-size: 0.9rem; }
.changes > li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.changes > li:last-child { border-bottom: none; }
.changes > .road-edit { display: block; }
.road-edit-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.road-edit-actions button[aria-pressed="true"] { font-weight: 700; }
.road-edit-details summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.road-edit-details p { margin: 4px 0; }
.road-edit-segments { list-style: none; padding: 0; }
.road-edit-segments li { margin: 5px 0; }
button.link { border: none; background: none; padding: 2px 4px; color: var(--accent); font-size: 0.85rem; }
button.link:hover { text-decoration: underline; }
#conservation { margin: 10px 0 0; }
.note { margin: 6px 0 0; font-size: 0.78rem; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; margin-top: -4px; }

.compare { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.compare th, .compare td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.compare th[scope="row"], .compare thead th:first-child { text-align: left; font-weight: 500; color: var(--muted); }
.compare thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.compare td { font-variant-numeric: tabular-nums; font-weight: 600; }
.worse { color: var(--jam); }
.better { color: var(--free); }

#closed-list { font-size: 0.85rem; margin: 10px 0; }

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(0.95); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.selected-meta { font-size: 0.85rem; margin: 0 0 10px; }
.selected-meta code { font-size: 0.8rem; }

.shifts { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.shifts li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.shifts li:last-child { border-bottom: none; }
.shifts .nums { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }

/* Shuttle routes, stops and recommendation results */
#bus-layer { display: inline; pointer-events: none; }
#bus-layer > g { opacity: 0.5; }
#bus-layer > .operating { opacity: 1; }
.road-hit:focus-visible { stroke: var(--accent); stroke-opacity: 0.45; outline: none; }
.schematic-stop, .schematic-bus rect { fill: currentColor; stroke: #fff; }
.schematic-stop { pointer-events: auto; }
.schematic-bus .bus-window { fill: #fff; }
.schematic-bus { pointer-events: none; }
.shuttle-stop span { display: block; width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #354052; }
.route-swatch { width: 10px; height: 10px; border-radius: 50%; }
.route-status { margin: 2px 0 10px; font-size: 0.8rem; }
.approach-waits { padding-left: 18px; font-size: 0.83rem; }
#recommendations { font-size: 0.9rem; }
#recommendations h3 { margin: 12px 0 0; font-size: 1rem; }
#recommendations summary { cursor: pointer; }
.recommendation-list { list-style: none; padding: 0; }
.recommendation-option { padding: 9px 0; border-top: 1px solid var(--border); }
.recommendation-option p { margin: 3px 0 7px; }

#trip-controls { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 7px; }
#trip-controls:empty, .trip-mode:empty, .trip-feedback:empty { display: none; }
.endpoint-control { position: relative; display: flex; flex: 1 1 270px; align-items: center; gap: 6px; min-width: 0; }
.endpoint-control label { font-size: 0.9rem; font-weight: 650; min-width: 34px; }
.endpoint-control input { font: inherit; flex: 1; width: 0; min-width: 75px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.endpoint-control > button { padding: 6px 8px; white-space: nowrap; font-size: 0.83rem; }
.endpoint-control > button[aria-pressed="true"] { background: #eeeaff; border-color: #6047d9; }
.endpoint-matches { position: absolute; inset: 100% 0 auto 38px; z-index: 1100; max-height: 230px; overflow: auto; list-style: none; margin: 3px 0 0; padding: 4px; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px #1d233026; }
.endpoint-matches button { display: block; width: 100%; text-align: left; border: 0; padding: 5px 7px; font-size: 0.88rem; }
.endpoint-matches button:hover, .endpoint-matches button:focus-visible { background: #eeeaff; }
.trip-mode, .trip-feedback { margin: 0 0 8px; padding: 5px 8px; font-size: 0.85rem; border-radius: 5px; }
.trip-mode { color: #453393; background: #eeeaff; }
.trip-feedback { color: #8a291f; background: #ffede7; }
.picking-endpoint .road-hit, .picking-endpoint .node, .picking-endpoint .leaflet-marker-icon { cursor: crosshair; }
.road.on-route .halo { stroke: #6047d9; stroke-opacity: 0.7; }
.swatch.trip-route { background: var(--unchanged); outline: 1px solid #263a5838; }
.endpoint-pin { display: grid; place-items: center; font-size: 13px; font-weight: 750; color: #fff; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 1px 4px #1d233055; pointer-events: none; }
.endpoint-pin-A { --pin: #0e7265; }
.endpoint-pin-B { --pin: #8237a4; }
.endpoint-pin { background: var(--pin); }
.schematic-pin { pointer-events: none; }
.schematic-pin circle { fill: var(--pin); stroke: white; stroke-width: 2; }
.schematic-pin text { fill: white; font-size: 12px; font-weight: 700; }
.schematic-landmark, .landmark-icon span { fill: #8b4923; background: #8b4923; stroke: #fff; stroke-width: 1.5; }
.landmark-icon span { display: block; width: 14px; height: 14px; border: 2px solid white; border-radius: 4px; box-shadow: 0 1px 3px #1d233055; }
.schematic-landmark, .schematic-stop { cursor: pointer; }

.schematic-imported-roads { fill:none; stroke:#8797a9; stroke-width:0.65; pointer-events:none; }
.schematic-coverage { fill:#f0f5fb; stroke:#52739a; stroke-width:1; stroke-dasharray:5 5; }
#bus-editor { border-top:1px solid var(--border); padding:9px 0; }
#bus-editor h3 { margin:0 0 8px; font-size:1rem; }
#bus-editor label { display:block; margin-top:6px; font-size:.85rem; }
#bus-editor input, #bus-editor select { width:100%; font:inherit; }
#bus-draft-points { padding-left:1.4em; font-size:.84rem; }
#bus-draft-points li { margin:.3em 0; }
.bus-stop-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
#bus-draft-points button { padding:1px 5px; }
#bus-storage:empty { display:none; }
.custom-route-actions { display:flex; gap:.4em; margin-bottom:.65em; }
.custom-route-actions button { padding:2px 8px; font-size:.8rem; }
.custom-shuttle-stop span, .custom-waypoint span { display:grid; place-items:center; min-width:16px; width:max-content; padding:0 2px; height:16px; color:white; font-size:11px; font-weight:700; border:1px solid white; border-radius:4px; }
.schematic-stop-number { fill: white; font-size: 5px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.lane-divider { stroke: #fff; stroke-width: 1px; stroke-dasharray: 4 5; opacity: .8; }
.lane-count-label { padding: 1px 4px; font-size: 11px; font-weight: 600; pointer-events: none; }
.schematic-lane-count { fill: var(--text); stroke: white; stroke-width: 2px; paint-order: stroke; font-size: 9px; font-weight: 600; text-anchor: middle; }
#comparison-empty, #conservation { margin: 0; }

.vehicle-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.moving-vehicle { position: absolute; left: 0; top: 0; }
.moving-vehicle .car-rot { margin: -13px 0 0 -7px; }
.moving-bus { z-index: 1; }

#create-bus { width: 100%; margin-bottom: 8px; }
#bus-draft-points button[aria-pressed="true"] { border-color: var(--accent); }
.bus-route-entry { padding-top: 6px; }
.route-stops { margin: 2px 0; font-size: .8rem; }
.bus-route-entry + .bus-route-entry { border-top: 1px solid var(--border); }
.bus-line-controls { display: flex; align-items: center; gap: 6px; }
.bus-line-name { padding: 2px 6px; font-weight: 650; border: 0; background: transparent; text-align: left; }
.bus-line-name:hover, .bus-line-name[aria-pressed="true"] { background: #edf1f6; }

#add-lane-map { margin-bottom: 8px; }
#lane-editor { margin-bottom: 10px; }
#lane-status { font-size: .85rem; margin: 4px 0 8px; }
#lane-options-label { font-size: .85rem; margin-bottom: 8px; }
#lane-options-label:not([hidden]) { display: block; }
#lane-options { display: block; max-width: 100%; }
.lane-preview-pin { display: grid; place-items: center; border-radius: 50%; background: #702e9d;
  color: white; border: 2px solid white; font-weight: 700; box-shadow: 0 1px 5px #0004; }

.schematic-junction-picks { display: none; fill: none; stroke-linecap: round; pointer-events: none; }
.picking-endpoint .schematic-junction-picks { display: inline; }
.endpoint-pin::after, .custom-shuttle-stop::after, .lane-preview-pin::after {
  content: ""; position: absolute; left: 50%; top: var(--pin-tip, 31px);
  width: 5px; height: 5px; transform: translate(-50%, -50%);
  border: 1px solid white; border-radius: 50%; background: #175f9b;
}
.custom-shuttle-stop { --pin-tip: 20px; }
.lane-preview-pin { --pin-tip: 21px; }
.picking-endpoint #leaflet-map :is(.landmark-icon, .venue-icon, .custom-shuttle-stop, .speed-edit-sign) {
  pointer-events: none;
}

.speed-edit-endpoint, .speed-edit-sign {
  display: grid; place-items: center; font-weight: 750; box-shadow: 0 1px 4px #0005;
}
.speed-edit-endpoint {
  border-radius: 50%; border: 2px solid white; background: #6943a0; color: white;
}
.speed-edit-endpoint::after, .speed-edit-sign::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  border: 3px solid transparent; border-top-color: #6943a0; top: 100%;
}
.speed-edit-sign {
  border-radius: 5px; border: 2px solid #6943a0; background: #fff; color: #242034;
  grid-template-rows: 1fr auto; font-size: 15px; line-height: 1; padding: 3px;
}
.speed-edit-sign small { font-size: 9px; }
.speed-edit-sign::after { border-width: 4px; margin-top: 1px; }
.speed-edit-details > div { margin-top: 4px; }
