:root {
  --bg: #ffffff;
  --bg-2: #f2f4f6;
  --ink: #14181c;          /* body text and the darkest labels */
  --ink-dim: #4d5760;      /* secondary text and ordinary station names */
  --ink-faint: #838d96;
  --line: #e0e4e9;         /* hairlines and card borders */
  --accent: #c8102e;       /* emphasis: not one of the eleven line colours */
  --mark: #ffd300;         /* the "you are here" dot */
  --panel: rgba(255, 255, 255, 0.94);
  --shadow: 0 14px 40px -12px rgba(20, 32, 48, 0.3);
  --radius: 14px;
  --font: "Helvetica Neue", Helvetica, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  /* dvh tracks the area actually visible as the phone's address bar shows and
     hides; vh does not, and on iOS it counts space the bar is sitting on top
     of. Browsers without dvh keep the vh line above it. */
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- map ---------- */

#map-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
}

#map {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  background:
    radial-gradient(ellipse 92% 75% at 50% 45%, #ffffff 0%, #f4f6f8 100%);
  touch-action: none;
}
#map.dragging { cursor: grabbing; }

.edge { fill: none; stroke-linecap: round; }
.transfer { fill: none; stroke: #98a1a9; stroke-width: 1.4px; stroke-dasharray: 2 3; }

.route-leg { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0.28; }
.route-leg.done { opacity: 1; }
.route-leg.trace { opacity: 0.5; }

/* interchanges are hollow rings, ordinary stations solid dots — the
   convention every printed tube map uses on white paper */
.stop { cursor: pointer; }
.stop.interchange { fill: #fff; stroke: var(--ink); }
.stop.plain { fill: #4d5760; stroke: #fff; }
.stop.on-route { fill: #fff; stroke: var(--ink); }
.stop.here { fill: var(--mark); stroke: var(--ink); }

/* dark type with a white halo, so a name stays readable where it crosses
   a line; the halo width is set in app.js because it has to track the zoom */
.label {
  fill: var(--ink-dim);
  stroke: #fff;
  paint-order: stroke fill;
  pointer-events: none;
  font-weight: 500;
}
.label.major { fill: var(--ink); font-weight: 600; }
.label.here { fill: var(--accent); font-weight: 700; }

#g-edges.muted .edge { opacity: 0.18; }
#g-edges.muted .edge.involved { opacity: 1; }
#g-edges .edge { transition: opacity 0.5s ease; }

/* ---------- chrome ---------- */

#title, #goto, #panel, #controls, #hint { position: fixed; z-index: 5; }

#title { top: 22px; left: 24px; max-width: 320px; pointer-events: none; }
/* a soft white wash so the heading stays readable wherever a line runs under it */
#title::before {
  content: "";
  position: absolute;
  inset: -20px -70px -24px -30px;
  background: radial-gradient(ellipse at 25% 45%,
    rgba(255, 255, 255, 0.96) 0%,
    rgba(255, 255, 255, 0.86) 42%,
    rgba(255, 255, 255, 0) 76%);
  z-index: -1;
}
#title h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
#title h1 em { font-style: normal; color: var(--accent); }
#title p { margin: 5px 0 0; font-size: 12.5px; color: var(--ink-faint); line-height: 1.45; }

/* Go to */

#goto { top: 20px; right: 24px; width: 320px; }

.goto-row { display: flex; align-items: center; gap: 10px; }
.goto-row label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-dim);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.combo { position: relative; flex: 1; }

#search {
  width: 100%;
  padding: 11px 32px 11px 13px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  outline: none;
}
#search:focus { border-color: #a7b1bb; }
#search::placeholder { color: var(--ink-faint); }

#clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  display: none;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  color: var(--ink-faint);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
#clear:hover { color: var(--ink); background: #eef1f4; }
.combo.filled #clear { display: block; }

#results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: 320px;
  margin: 0; padding: 5px;
  overflow-y: auto;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
#results li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  border-radius: 7px;
  cursor: pointer;
}
#results li[aria-selected="true"] { background: #eef1f5; }
#results li .pips { display: flex; gap: 3px; margin-left: auto; flex-shrink: 0; }
#results li .pip { width: 7px; height: 7px; border-radius: 50%; }
#results .empty { color: var(--ink-faint); cursor: default; }

/* explanation panel */

#panel {
  right: 24px;
  bottom: 22px;
  width: 380px;
  max-height: 58vh;
  max-height: 58dvh;
  overflow-y: auto;
  padding: 20px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
#panel.show { opacity: 1; transform: none; }

#panel .lines { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 11px; }
#panel .chip {
  padding: 3px 9px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border-radius: 20px;
  white-space: nowrap;
}
#panel h2 { margin: 0 0 3px; font-size: 25px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.15; }
#panel .zone { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 14px; }
#panel .gist {
  margin: 0 0 13px;
  padding-left: 13px;
  border-left: 3px solid var(--accent);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
}
#panel .body { margin: 0; font-size: 13.5px; line-height: 1.62; color: var(--ink-dim); }
/* how the name wore down, form by form */
#panel .chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-dim);
  background: #f4f6f9;
  border: 1px solid var(--line);
  border-radius: 9px;
}
#panel .chain i { font-style: normal; color: #a6b0ba; }
#panel .chain .now { color: var(--ink); font-weight: 700; }

/* further reading */
#panel .src {
  display: inline-block;
  margin-top: 15px;
  font-size: 11.5px;
  color: var(--ink-faint);
  text-decoration: none;
  border-bottom: 1px solid #d9dee4;
}
#panel .src:hover { color: var(--ink); border-bottom-color: currentColor; }
#panel .src.checked { color: var(--ink-dim); }

#panel .note {
  margin-top: 14px;
  padding: 12px 13px;
  background: #fdf7e3;
  border: 1px solid #ecdca6;
  border-radius: 9px;
}
#panel .note .h {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: #8a6a00;
  margin-bottom: 6px;
}
#panel .note p { margin: 0; font-size: 12.5px; line-height: 1.6; color: #5c4a11; }

/* controls */

#controls { left: 24px; bottom: 22px; display: flex; align-items: flex-end; gap: 8px; }
#controls button {
  padding: 9px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  cursor: pointer;
}
#controls button:hover { color: var(--ink); border-color: #a7b1bb; }

#legend {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: 210px;
  padding: 11px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
#legend div { display: flex; align-items: center; gap: 9px; padding: 3px 0; font-size: 12px; color: var(--ink-dim); }
#legend i { width: 20px; height: 4px; border-radius: 2px; flex-shrink: 0; }

#hint {
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-size: 11.5px;
  color: var(--ink-faint);
  background: rgba(255, 255, 255, 0.88);
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}
#hint.show { opacity: 1; }

/* scrollbars */
#panel::-webkit-scrollbar, #results::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb, #results::-webkit-scrollbar-thumb {
  background: #cdd4db; border-radius: 4px;
}

@media (max-width: 900px) {
  #title { top: 14px; left: 14px; max-width: 55%; }
  #title h1 { font-size: 17px; }
  #title p { display: none; }
  #goto { top: 60px; left: 14px; right: 14px; width: auto; }
  #panel {
    left: 14px; right: 14px; bottom: 14px;
    width: auto; max-height: 40dvh; padding: 16px 17px 18px;
  }
  #panel h2 { font-size: 21px; }
  #controls { left: 14px; bottom: calc(40vh + 24px); }
  #hint { display: none; }
}
