/* Dark is the default. An explicit choice wins via [data-theme]; with no
   choice the system preference decides. Every colour that JS derives (line and
   destination swatches) is recomputed against --board when the theme flips, so
   --board is the surface the map is drawn on, and --page sits behind it. */
:root{
  --page:#0a0d11; --board:#0f1216; --panel:#151a20; --raise:#1b2128; --edge:#242b33;
  --ink:#eef2f5; --ink-2:#c3cbd2; --dim:#87929c; --amber:#ffb200;
  --scrim:rgba(0,0,0,.55); --hover:rgba(255,255,255,.055);
  --shadow:rgba(0,0,0,.5); --hairline:rgba(255,255,255,.06);
  --radius:14px;
  --plat:#59626c; --plat-hi:#717b86; --plat-edge:#e3bf2d;
  /* set from JS per line, always contrast-checked against --board */
  --line:#4d8fe0; --line-deep:#2f6fbe; --line-ink:#0f1216;
}
:root[data-theme="light"]{
  --page:#eef1f5; --board:#ffffff; --panel:#ffffff; --raise:#f4f6f9; --edge:#dde3e9;
  --ink:#14181c; --ink-2:#38414a; --dim:#5d6873; --amber:#9a6600;
  --scrim:rgba(20,26,32,.38); --hover:rgba(0,0,0,.04);
  --shadow:rgba(15,25,35,.12); --hairline:rgba(0,0,0,.07);
  --plat:#c9d0d7; --plat-hi:#b2bbc4; --plat-edge:#d2a80f;
}
@media (prefers-color-scheme:light){
  :root:not([data-theme="dark"]){
    --page:#eef1f5; --board:#ffffff; --panel:#ffffff; --raise:#f4f6f9; --edge:#dde3e9;
    --ink:#14181c; --ink-2:#38414a; --dim:#5d6873; --amber:#9a6600;
    --scrim:rgba(20,26,32,.38); --hover:rgba(0,0,0,.04);
    --shadow:rgba(15,25,35,.12); --hairline:rgba(0,0,0,.07);
    --plat:#c9d0d7; --plat-hi:#b2bbc4; --plat-edge:#d2a80f;
  }
}
*{box-sizing:border-box}
html,body{margin:0;background:var(--page);color:var(--ink);
  font-family:"Helvetica Neue",Helvetica,Arial,system-ui,sans-serif;-webkit-font-smoothing:antialiased}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
button{font-family:inherit}
select:focus-visible,button:focus-visible,input:focus-visible{outline:2px solid var(--line);outline-offset:2px}

/* ---- header ---- */
header,.bar,main,footer{max-width:1040px;margin-left:auto;margin-right:auto}
header{display:flex;align-items:center;gap:16px;flex-wrap:wrap;
  padding:20px clamp(16px,4vw,32px) 12px}
.brand{display:flex;align-items:center;gap:13px;min-width:0}
.brand{flex:0 0 auto}
.title{min-width:0}
h1{font-size:clamp(19px,4vw,26px);margin:0;font-weight:700;letter-spacing:-.01em;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sub{color:var(--dim);font-size:13px;margin-top:3px;display:flex;align-items:center;gap:7px}
.live{width:7px;height:7px;border-radius:50%;background:var(--amber);flex:0 0 auto;
  animation:pulse 2.4s ease-out infinite}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(255,178,0,.5)}70%{box-shadow:0 0 0 7px rgba(255,178,0,0)}100%{box-shadow:0 0 0 0 rgba(255,178,0,0)}}
@media (prefers-reduced-motion:reduce){
  .live{animation:none}
  .cd i,.train .lbl,.panel{transition:none;animation:none}
  *{scroll-behavior:auto}
}

/* one row of matching 38px controls */
.controls{margin-left:auto;display:flex;gap:8px;align-items:center}
.line-pick{position:relative;display:block}
.line-pick::after{content:"";position:absolute;right:13px;top:50%;width:7px;height:7px;
  margin-top:-5px;border-right:2px solid var(--dim);border-bottom:2px solid var(--dim);
  transform:rotate(45deg);pointer-events:none}
select{appearance:none;-webkit-appearance:none;height:38px;min-width:190px;
  padding:0 36px 0 14px;border-radius:10px;border:1px solid var(--edge);
  background:var(--panel);color:var(--ink);font:600 14px/1 inherit;cursor:pointer;
  box-shadow:inset 3px 0 0 var(--line)}
select:hover{border-color:var(--dim)}
.seg{display:flex;align-items:center;height:38px;padding:0 3px;gap:2px;
  border:1px solid var(--edge);border-radius:10px;background:var(--panel)}
.seg button,.icon-btn{display:grid;place-items:center;width:30px;height:30px;padding:0;
  border:0;border-radius:7px;background:transparent;color:var(--ink);
  font-size:17px;line-height:1;cursor:pointer}
.seg button:hover,.icon-btn:hover{background:var(--hover)}
input[type=range]{width:92px;margin:0 4px;accent-color:var(--line);cursor:pointer}
.icon-btn{width:38px;height:38px;border:1px solid var(--edge);border-radius:10px;background:var(--panel)}
/* show the icon for the mode you are in */
.i-sun{display:none}
:root[data-theme="light"] .i-sun{display:block}
:root[data-theme="light"] .i-moon{display:none}
/* the layout button shows the layout you would switch to */
.i-vert{display:none}
#layout-toggle[data-layout="horizontal"] .i-vert{display:block}
#layout-toggle[data-layout="horizontal"] .i-horiz{display:none}

/* ---- refresh bar ---- */
.bar{display:flex;align-items:center;gap:14px;flex-wrap:wrap;
  padding:0 clamp(16px,4vw,32px) 16px;color:var(--dim);font-size:12.5px}
.refresh{display:inline-flex;align-items:center;gap:8px;padding:6px 12px;
  border:1px solid var(--edge);border-radius:999px;background:var(--panel)}
.refresh b{color:var(--ink);font-weight:600;font-variant-numeric:tabular-nums}
.dot{opacity:.5}
.cd{display:inline-block;width:46px;height:4px;border-radius:2px;background:var(--edge);overflow:hidden}
.cd i{display:block;height:100%;width:100%;background:var(--line);
  transform-origin:left center;transition:transform .25s linear}
.hint{margin-left:auto}

/* ---- layout: the map on a card, the key in a sidebar ---- */
main{display:grid;grid-template-columns:minmax(0,1fr) 230px;gap:18px;align-items:start;
  padding:0 clamp(16px,4vw,32px) 28px}
.map-wrap{grid-column:1;grid-row:1;position:relative;min-width:0}
.map{background:var(--board);border:1px solid var(--edge);
  border-radius:var(--radius);padding:10px 8px 14px;box-shadow:0 1px 2px var(--shadow)}
.track{position:relative;margin:0 auto;max-width:760px;
  /* one finger still scrolls the page; two fingers are ours to pinch */
  touch-action:pan-y}
.skip{position:absolute;left:-9999px;top:0;background:var(--panel);color:var(--ink);
  padding:10px 14px;border:1px solid var(--edge);border-radius:8px;z-index:20}
.skip:focus{left:12px;top:12px}

/* ---- rails ---- */
.rail{position:absolute;width:4px;margin-left:-2px;
  background:linear-gradient(var(--line-deep),var(--line));border-radius:2px}
.forks{position:absolute;left:0;top:0;width:100%;height:100%;overflow:visible;pointer-events:none}
.forks path{fill:none;stroke-linejoin:round;stroke-linecap:butt}
.forks .rails-band path{stroke:var(--line)}
.forks .rails-bed path{stroke:var(--board)}

/* ---- stations ---- */
.station{position:absolute;transform:translate(-50%,-50%);display:flex;
  align-items:center;gap:9px;white-space:nowrap;cursor:pointer;
  padding:4px;border-radius:8px;border:0;background:transparent;
  font-family:inherit;color:inherit;line-height:1}
/* a station is an island platform between the tracks: concrete, a yellow
   safety line along each track edge, and a ramp at each end */
.station .stn{position:relative;flex:0 0 auto}
.station .plat{position:absolute;top:0;bottom:0;left:50%;transform:translateX(-50%);
  background:var(--plat);
  box-shadow:inset 2px 0 0 var(--plat-edge),inset -2px 0 0 var(--plat-edge);
  clip-path:polygon(0 7%,30% 0,70% 0,100% 7%,100% 93%,70% 100%,30% 100%,0 93%);
  transition:background .12s}
/* offsets are set inline from the track gap; 50% is the station mark's centre,
   so the label clears a train marker sitting on the outer rail */
.station .nm{position:absolute;color:var(--ink-2);font-size:12.5px;transform:translateY(-1px);
  overflow:hidden;text-overflow:ellipsis;padding:3px 0;transition:color .12s}
.station.left .nm{text-align:right;direction:rtl}
.station:hover .nm{color:var(--ink)}
.station:hover .plat{background:var(--plat-hi)}
.station.active .plat{background:var(--line)}
.station.active .nm{color:var(--ink);font-weight:700}

/* direction tags on every branch: which way each track's trains run */
.edge-note{position:absolute;transform:translateY(-50%);white-space:nowrap;
  font-size:9px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;line-height:1;
  color:var(--ink-2);background:var(--panel);border:1px solid var(--edge);
  padding:3px 7px;border-radius:999px;pointer-events:none;user-select:none;z-index:2}
/* compass points pinned to the map card, outside the scrolling track */
.compass{position:absolute;z-index:5;pointer-events:none;white-space:nowrap;
  font-size:11px;font-weight:800;letter-spacing:.14em;text-transform:uppercase;line-height:1;
  color:var(--line-ink);background:var(--line);padding:5px 10px;border-radius:999px;
  box-shadow:0 2px 8px var(--shadow)}
.compass:empty{display:none}
.compass.start{top:10px;left:50%;transform:translateX(-50%)}
.compass.end{bottom:10px;left:50%;transform:translateX(-50%)}
main.horiz .compass.start{top:10px;left:12px;transform:none}
main.horiz .compass.end{top:10px;right:12px;bottom:auto;left:auto;transform:none}
.edge-note.l{transform:translate(-100%,-50%)}

/* ---- trains: one rounded tag, sitting on the rail, numbered ---- */
.train{position:absolute;left:50%;will-change:transform;z-index:3;
  display:flex;align-items:center;justify-content:center;
  min-width:32px;height:17px;padding:0 5px;border:0;border-radius:5px;
  font-family:inherit;font-size:10px;font-weight:700;letter-spacing:.02em;
  font-variant-numeric:tabular-nums;
  color:var(--line-ink);background:var(--line);cursor:pointer;
  /* the ring in the board colour keeps two overlapping trains distinct */
  box-shadow:0 0 0 2px var(--board),0 2px 6px var(--shadow)}
.train .num{pointer-events:none}
/* no number to show (the DLR sends none): a compact tag, not an empty pill */
.train[data-noid]{min-width:18px;padding:0}
/* a notch on the leading end shows which way it is heading */
.train::after{content:"";position:absolute;top:3px;bottom:3px;width:2px;border-radius:1px;
  background:currentColor;opacity:.4}
.train.down::after{right:3px}
.train.up::after{left:3px}
.train .lbl{position:absolute;left:calc(100% + 10px);top:50%;transform:translateY(-50%);
  font-size:11px;font-weight:500;line-height:1.4;color:var(--ink);background:var(--panel);
  border:1px solid var(--edge);padding:6px 9px;border-radius:9px;
  opacity:0;transition:opacity .12s;white-space:nowrap;pointer-events:none;z-index:5;
  box-shadow:0 6px 20px var(--shadow)}
.train .lbl b{font-variant-numeric:tabular-nums;letter-spacing:.02em}
.train .lbl i{font-style:normal;color:var(--dim)}
/* trains on the left-hand rail open their detail leftwards */
.train.up .lbl{left:auto;right:calc(100% + 10px)}
.train:hover,.train.pinned{z-index:7}
.train:hover .lbl,.train.pinned .lbl{opacity:1}
.train.pinned{box-shadow:0 0 0 2px var(--board),0 0 0 4px var(--ink)}

/* ---- destination key ---- */
.key{grid-column:2;grid-row:1;position:sticky;top:16px;
  background:var(--panel);border:1px solid var(--edge);border-radius:var(--radius);
  padding:14px 16px;font-size:12.5px;z-index:4}
.key:empty{display:none}
.key h3{margin:0 0 10px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--dim);font-weight:600}
.key ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:8px}
.key li{display:flex;align-items:center;gap:9px;color:var(--ink)}
.key .sw{width:16px;height:10px;border-radius:3px;flex:0 0 auto}
.key .ct{margin-left:auto;min-width:22px;text-align:center;padding:1px 6px;border-radius:999px;
  background:var(--raise);color:var(--ink-2);font-size:11px;font-weight:600;font-variant-numeric:tabular-nums}
/* which side of the rail is which direction of travel */
.key .tracks{display:flex;justify-content:space-between;gap:10px;margin:12px 0 0;
  padding-top:10px;border-top:1px solid var(--edge);color:var(--dim);font-size:11px}

/* ---- station detail panel ---- */
.scrim{position:fixed;inset:0;background:var(--scrim);z-index:9;animation:fade .15s ease-out}
.panel{position:fixed;top:12px;right:12px;bottom:12px;width:min(390px,calc(100vw - 24px));z-index:10;
  background:var(--panel);border:1px solid var(--edge);border-radius:18px;overflow:hidden;
  display:flex;flex-direction:column;box-shadow:0 20px 50px var(--shadow);
  animation:slide-in .18s ease-out}
@keyframes slide-in{from{transform:translateX(24px);opacity:0}}
@keyframes rise{from{transform:translateY(40px);opacity:0}}
@keyframes fade{from{opacity:0}}
/* the class sets display:flex, which outranks the UA [hidden] rule — without
   this the panel is permanently on screen, covering the map */
.panel[hidden],.scrim[hidden]{display:none}
.panel-head{display:flex;align-items:center;gap:10px;padding:16px 16px 14px 20px;
  border-bottom:1px solid var(--edge);box-shadow:inset 0 3px 0 var(--line)}
.panel-head h2{margin:0;font-size:17px;font-weight:700;flex:1;min-width:0;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#panel-close{display:grid;place-items:center;width:32px;height:32px;padding:0;border-radius:50%;
  border:0;background:var(--raise);color:var(--ink);font-size:19px;line-height:1;cursor:pointer;flex:0 0 auto}
#panel-close:hover{background:var(--hover);outline:1px solid var(--edge)}
.panel-body{overflow:auto;padding:14px 16px 22px}
.pf{margin:0 0 12px;padding:12px 14px;border:1px solid var(--edge);border-radius:12px;background:var(--raise)}
.pf-head{display:flex;align-items:baseline;gap:8px;margin-bottom:8px}
.pf-num{font-size:12px;font-weight:700;color:var(--line-ink);background:var(--line);
  border-radius:6px;padding:2px 8px}
.pf-dir{font-size:12px;color:var(--dim)}
.pf table{width:100%;border-collapse:collapse;font-size:13px}
.pf td{padding:6px 0;border-bottom:1px solid var(--hairline);vertical-align:middle}
.pf td.d{color:var(--ink)}
.pf td.v{color:var(--dim);width:48px;font-variant-numeric:tabular-nums}
.pf td.t{text-align:right;color:var(--ink);font-weight:700;width:60px;font-variant-numeric:tabular-nums}
.pf tr:last-child td{border-bottom:0}
.pf .swatch{display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:7px;vertical-align:-1px}
.empty{color:var(--dim);font-size:13px;text-align:center;padding:28px 8px}

footer{display:flex;flex-direction:column;gap:8px;
  color:var(--dim);font-size:12px;line-height:1.5;padding:0 clamp(16px,4vw,32px) 32px}
footer .credits p{margin:0}
footer .credits strong{color:var(--ink-2);font-weight:700}
.err{color:var(--amber);font-weight:600}

/* ---- horizontal layout: the line runs left to right ---- */
/* the map takes the full width and the key sits above it as a strip */
main.horiz{grid-template-columns:minmax(0,1fr);gap:12px}
main.horiz .map-wrap{grid-row:2}
main.horiz .map{overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:thin}
main.horiz .key{grid-column:1;grid-row:1;position:static;display:flex;flex-wrap:wrap;
  align-items:center;gap:8px 16px;padding:12px 16px}
main.horiz .key h3{margin:0}
main.horiz .key ul{flex-direction:row;flex-wrap:wrap;gap:6px 16px}
main.horiz .key .ct{margin-left:2px}
main.horiz .key .tracks{margin:0 0 0 auto;padding:0 0 0 16px;border:0;border-left:1px solid var(--edge);gap:16px}
.track.horiz{max-width:none;margin:0;touch-action:pan-x pan-y}
.horiz .rail{width:auto;height:4px;margin:-2px 0 0;
  background:linear-gradient(90deg,var(--line-deep),var(--line))}
.horiz .station .plat{left:0;right:0;top:50%;bottom:auto;transform:translateY(-50%);
  box-shadow:inset 0 2px 0 var(--plat-edge),inset 0 -2px 0 var(--plat-edge);
  clip-path:polygon(7% 0,93% 0,100% 30%,100% 70%,93% 100%,7% 100%,0 70%,0 30%)}
/* names stand at 45 degrees, rising from stations above the line and
   falling from those below it */
.horiz .station .nm{left:50%;margin-left:-3px;padding:0;transform:none}
.horiz .station.up .nm{transform-origin:left bottom;transform:rotate(-45deg)}
.horiz .station.down .nm{transform-origin:left top;transform:rotate(45deg)}
.horiz .edge-note,.horiz .edge-note.l{transform:translate(-50%,-50%)}
.horiz .train{left:0;top:0}
/* the notch leads: top-rail trains head right, bottom-rail trains left */
.horiz .train.up::after{left:auto;right:3px}
.horiz .train.down::after{right:auto;left:3px}
.horiz .train .lbl,.horiz .train.up .lbl{left:50%;right:auto;top:auto;
  bottom:calc(100% + 10px);transform:translateX(-50%)}
.horiz .train.down .lbl{bottom:auto;top:calc(100% + 10px)}

/* ---- tablets and phones: one column, the key above the map ---- */
@media (max-width:820px){
  main{grid-template-columns:minmax(0,1fr);gap:12px}
  .map-wrap{grid-row:2}
  .key{grid-column:1;grid-row:1;position:static;display:flex;flex-wrap:wrap;
    align-items:center;gap:8px 14px;padding:12px 14px}
  .key h3{margin:0}
  .key ul{flex-direction:row;flex-wrap:wrap;gap:6px 14px}
  .key .ct{margin-left:2px}
  .key .tracks{flex-basis:100%;margin:2px 0 0;padding-top:8px}
}
@media (max-width:560px){
  html,body{overflow-x:hidden}
  header{gap:12px;padding-top:16px;padding-bottom:10px}
  .brand{width:38px;height:38px}
  .controls{margin-left:0;width:100%}
  .line-pick{flex:1;min-width:0}
  select{min-width:0;width:100%}
  /* the buttons and pinch cover zoom on a phone */
  input[type=range]{display:none}
  .bar{padding-bottom:12px}
  .hint{display:none}
  .map{padding:8px 2px 12px;border-radius:12px}
  .station .nm{font-size:11px;max-width:96px}
  main.horiz .key .tracks{flex-basis:100%;justify-content:space-between;margin:2px 0 0;
    padding:8px 0 0;border-left:0;border-top:1px solid var(--edge)}
  .panel{top:auto;left:0;right:0;bottom:0;width:auto;height:72vh;
    border-radius:20px 20px 0 0;border-width:1px 0 0;animation-name:rise}
  .panel-head{padding-top:22px;position:relative}
  /* grab handle, so it reads as a sheet */
  .panel-head::before{content:"";position:absolute;top:8px;left:50%;width:36px;height:4px;
    margin-left:-18px;border-radius:2px;background:var(--edge)}
  .train{min-width:28px;height:16px;font-size:9.5px}
}
