@font-face {
  font-family: "Overpass";
  src: url("fonts/overpass-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Overpass Mono";
  src: url("fonts/overpass-mono-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Overpass Mono";
  src: url("fonts/overpass-mono-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* Road-atlas palette */
:root {
  --map: #eef2f3;
  --map-grid: #dfe6e8;
  --panel: #ffffff;
  --ink: #18222b;
  --muted: #5d6b77;
  --rule: #dde3e6;
  --road: #9aa7b2;
  --heavy: #e08a1e;
  --blocked: #d23f3f;
  --closed: #8d979f;
  --route: #0b6e69;
  --route-soft: #dff1ef;
  --sign: #0f5132;
  --radius: 14px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: "Overpass", system-ui, sans-serif;
  color: var(--ink);
  background: var(--map);
  -webkit-font-smoothing: antialiased;
}
button,
select {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 3px solid var(--route);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: 400px 1fr;
  min-height: 100dvh;
}

/* ---------- side panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  max-height: 100dvh;
  overflow-y: auto;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 22px 22px 16px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--route);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-mark svg {
  width: 30px;
  height: 30px;
}
.brand-mark circle {
  fill: #fff;
}
.brand-mark path {
  stroke: #fff;
  stroke-width: 3;
  fill: none;
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.brand p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 2px;
  margin: 0 16px;
  padding: 4px;
  background: var(--map);
  border-radius: 12px;
}
.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 9px 4px 7px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.tabs button:hover {
  color: var(--ink);
}
.tabs button[aria-selected="true"] {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

.view {
  padding: 18px 22px 8px;
  flex: 1;
}
.lead {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.lead.small {
  font-size: 13px;
}
.hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* route form */
.route-form {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
}
.route-form .primary {
  grid-column: 1 / -1;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 5px;
}
select {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--panel);
  font-weight: 600;
  cursor: pointer;
}
select:hover {
  border-color: var(--road);
}
.swap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--rule);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.swap svg {
  width: 20px;
  height: 20px;
  stroke: var(--ink);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.primary {
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--route);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
}
.primary:hover {
  background: #095c58;
}
.primary.small {
  height: 44px;
  padding: 0 16px;
}
.ghost {
  height: 40px;
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  background: transparent;
  padding: 0 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.ghost:hover {
  border-color: var(--road);
}
.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* result card */
.result {
  margin-top: 18px;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.result-head {
  background: var(--route);
  color: #fff;
  padding: 14px 16px;
}
.result-head .big {
  font-family: "Overpass Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
}
.result-head .big small {
  font-size: 15px;
  font-weight: 500;
  margin-left: 4px;
}
.result-head p {
  margin: 6px 0 0;
  font-size: 13px;
  opacity: 0.9;
}
.result.warn .result-head {
  background: var(--blocked);
}
.stops {
  list-style: none;
  margin: 0;
  padding: 14px 16px 6px;
}
.stops li {
  position: relative;
  padding: 0 0 14px 26px;
  font-weight: 700;
}
.stops li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 3px solid var(--route);
  background: #fff;
}
.stops li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 18px;
  bottom: 0;
  width: 4px;
  background: var(--route);
  border-radius: 2px;
}
.stops .leg {
  display: block;
  font-weight: 500;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}
.leg .heavy {
  color: var(--heavy);
  font-weight: 700;
}
.costs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1.5px solid var(--rule);
}
.costs div {
  padding: 12px 14px;
}
.costs div + div {
  border-left: 1.5px solid var(--rule);
}
.costs dt {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.costs dd {
  margin: 3px 0 0;
  font-family: "Overpass Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: 18px;
}
.result-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-top: 1.5px solid var(--rule);
  background: #f7f9f9;
  font-size: 13px;
  color: var(--muted);
}

/* build */
.build-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.build-actions select {
  flex: 1;
}
.stack {
  margin-top: 14px;
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 70px;
}
.stack-empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 12px 0;
}
.stack .stops {
  padding: 4px 4px 0;
}
.stack .top-tag {
  font-size: 11px;
  font-weight: 800;
  color: var(--route);
  margin-left: 6px;
}
.build-total {
  margin-top: 10px;
  font-size: 14px;
}
.build-total strong {
  font-family: "Overpass Mono", ui-monospace, monospace;
}
.error-text {
  color: var(--blocked);
  font-weight: 700;
}

/* traffic */
.road-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}
.road-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--rule);
  border-radius: 8px;
}
.road-list li.selected {
  background: var(--route-soft);
}
.road-name {
  font-weight: 700;
  font-size: 14px;
}
.road-name small {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
}
.seg {
  display: flex;
  border: 1.5px solid var(--rule);
  border-radius: 9px;
  overflow: hidden;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 7px 8px 5px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
}
.seg button + button {
  border-left: 1.5px solid var(--rule);
}
.seg button[aria-pressed="true"][data-v="Normal"] {
  background: #e8edf0;
  color: var(--ink);
}
.seg button[aria-pressed="true"][data-v="Heavy Traffic"] {
  background: #fdf0de;
  color: #8a4d00;
}
.seg button[aria-pressed="true"][data-v="Blocked"] {
  background: #fbe3e3;
  color: #9b1c1c;
}
.open-toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.open-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--route);
}

/* history */
.history-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}
.history-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.history-list .h-path {
  font-weight: 700;
}
.history-list .h-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}
.history-list .h-meta b {
  font-family: "Overpass Mono", monospace;
  color: var(--ink);
}
.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 0;
}

/* stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}
.stats div {
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  padding: 12px 14px;
}
.stats dt {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.stats dd {
  margin: 4px 0 0;
  font-family: "Overpass Mono", monospace;
  font-weight: 700;
  font-size: 24px;
}
.subhead {
  font-size: 16px;
  margin: 22px 0 4px;
}
.sorted {
  columns: 2;
  padding-left: 20px;
  margin: 0;
  font-size: 14px;
  line-height: 1.8;
}

.credits {
  padding: 16px 22px 22px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  border-top: 1px solid var(--rule);
}
.credits a {
  color: var(--route);
  font-weight: 700;
  display: inline-block;
  margin-top: 4px;
}

/* ---------- map ---------- */
.map-wrap {
  position: relative;
  min-height: 100dvh;
  background-color: var(--map);
  background-image:
    linear-gradient(var(--map-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--map-grid) 1px, transparent 1px);
  background-size: 48px 48px;
  overflow: hidden;
}
#map {
  position: absolute;
  inset: 24px 24px 64px;
  width: calc(100% - 48px);
  height: calc(100% - 88px);
}
.road {
  fill: none;
  stroke-linecap: round;
  cursor: pointer;
}
.road-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 22;
  cursor: pointer;
}
.road.normal {
  stroke: var(--road);
  stroke-width: 6;
}
.road.heavy {
  stroke: var(--heavy);
  stroke-width: 6;
}
.road.blocked {
  stroke: var(--blocked);
  stroke-width: 5;
  stroke-dasharray: 2 11;
}
.road.closed {
  stroke: var(--closed);
  stroke-width: 4;
  stroke-dasharray: 10 8;
}
.road.selected {
  stroke-width: 10;
}
.route-line {
  fill: none;
  stroke: var(--route);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.route-line.draw {
  animation: draw 700ms ease-out both;
}
@keyframes draw {
  from {
    stroke-dashoffset: var(--len);
  }
  to {
    stroke-dashoffset: 0;
  }
}
.dist {
  font-family: "Overpass Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  fill: var(--ink);
}
.dist-bg {
  fill: var(--map);
  stroke: var(--rule);
  stroke-width: 1;
}
.node {
  cursor: pointer;
}
.node circle.dot {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 4;
  transition: r 120ms ease-out;
}
.node:hover circle.dot,
.node:focus-visible circle.dot {
  r: 15;
}
.node.on-route circle.dot {
  stroke: var(--route);
  stroke-width: 6;
}
.node.start circle.dot,
.node.end circle.dot {
  fill: var(--route);
  stroke: var(--route);
}
.node:focus {
  outline: none;
}
.node:focus-visible circle.ring {
  stroke: var(--route);
  stroke-width: 3;
  fill: none;
}
.node .name-bg {
  fill: var(--sign);
  rx: 6;
}
.node .name {
  fill: #fff;
  font-size: 15px;
  font-weight: 800;
}
.node .tag {
  fill: var(--route);
  font-size: 12px;
  font-weight: 800;
}

.legend {
  position: absolute;
  left: 24px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: rgb(255 255 255 / 0.85);
  padding: 8px 12px;
  border-radius: 10px;
}
.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sw {
  width: 24px;
  height: 0;
  border-top: 5px solid var(--road);
  border-radius: 3px;
  display: inline-block;
}
.sw.heavy {
  border-color: var(--heavy);
}
.sw.blocked {
  border-top: 5px dotted var(--blocked);
}
.sw.closed {
  border-top: 4px dashed var(--closed);
}
.sw.route {
  border-color: var(--route);
  border-top-width: 7px;
}
.map-note {
  position: absolute;
  right: 24px;
  bottom: 22px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    order: 2;
  }
  .map-wrap {
    order: 1;
    min-height: 0;
    height: min(62vh, calc((100vw - 16px) * 0.72 + 120px));
  }
  #map {
    inset: 8px 8px 56px;
    width: calc(100% - 16px);
    height: calc(100% - 64px);
  }
  .legend {
    left: 8px;
    right: 8px;
    bottom: 8px;
    font-size: 12px;
  }
  .map-note {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .route-line.draw {
    animation: none;
  }
  * {
    transition: none !important;
  }
}

.result > .costs:first-child {
  border-top: 0;
}
