/* raildot design system
   dark base, single electric-blue accent, one warm alert colour for delays,
   frosted-glass panels, oversized display type. mobile-first. */
:root {
  --bg: #0a0a0b;
  --bg-2: #101013;
  --panel: rgba(22, 23, 28, 0.66);
  --panel-solid: #16171c;
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f5f7;
  --text-dim: #9aa0ad;
  --text-faint: #5e6470;
  --accent: #e5384d;            /* signal red */
  --accent-2: #ff5d6c;
  --accent-glow: rgba(229, 56, 77, 0.35);
  --accent-soft: rgba(229, 56, 77, 0.13);
  --warn: #f0a92b;              /* amber — delays (kept distinct from the red accent) */
  --warn-soft: rgba(240, 169, 43, 0.15);
  --ontime: #34c98a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 88% -12%, rgba(229, 56, 77, 0.07), transparent 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- top chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(10, 10, 11, 0.72);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--stroke);
}
.brand { display: flex; align-items: center; cursor: pointer; user-select: none; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.03em; }
/* the "dot" of raildot — a clean static red mark, no pulse/glow */
.brand-mark { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 2px; vertical-align: baseline; }
.brand-mark.big { width: 16px; height: 16px; margin-left: 4px; }

.searchwrap { position: relative; flex: 1; max-width: 540px; }
.search {
  width: 100%; height: 44px; padding: 0 16px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--stroke); border-radius: var(--radius-sm);
  font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search::placeholder { color: var(--text-faint); }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.results {
  position: absolute; top: 52px; left: 0; right: 0; z-index: 60;
  background: var(--panel-solid); border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-sm); overflow: hidden;
  box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto;
}
.result {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--stroke);
}
.result:last-child { border-bottom: none; }
.result:hover, .result.active { background: var(--accent-soft); }
.result .r-name { font-weight: 600; }
.result .r-region { font-size: 12px; color: var(--text-dim); }
.result .r-region::before { content: ""; }

.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 12px; border: 1px solid var(--stroke); }
.tab {
  appearance: none; border: none; background: transparent; color: var(--text-dim);
  padding: 8px 16px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.tab[aria-current="true"] { background: var(--accent); color: #fff; }

.iconbtn {
  appearance: none; display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  background: var(--panel); color: var(--text-dim);
  border: 1px solid var(--stroke); border-radius: var(--radius-sm); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.iconbtn:hover { color: var(--text); border-color: var(--stroke-strong); }

/* ---------- views ---------- */
.view { display: none; }
.view[data-active="true"] { display: block; }
#view-map.view { position: fixed; inset: 64px 0 0 0; }

/* ---------- welcome ---------- */
.welcome { min-height: 70vh; display: grid; place-items: center; padding: 40px 20px; }
.welcome-card {
  text-align: center; max-width: 560px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.welcome-card h1 { font-size: clamp(40px, 9vw, 76px); margin: 6px 0 0; letter-spacing: -0.04em; }
.welcome-card p { color: var(--text-dim); font-size: 16px; line-height: 1.6; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 6px; }
.chip {
  padding: 9px 16px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--stroke); color: var(--text); cursor: pointer; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.adapters { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.adapter-pill { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.adapter-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.adapter-pill .dot.live { background: var(--ontime); box-shadow: 0 0 8px var(--ontime); }
.adapter-pill .dot.stub { background: var(--text-faint); }

/* ---------- board ---------- */
.board { max-width: 1100px; margin: 0 auto; padding: clamp(18px, 4vw, 36px); }
.board-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.board-eyebrow { color: var(--accent); font-weight: 700; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.board-station { font-size: clamp(30px, 6vw, 54px); margin: 4px 0 0; letter-spacing: -0.03em; line-height: 1; }
.board-clock { font-family: var(--mono); font-size: clamp(22px, 4vw, 34px); color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* oversized next-train hero */
.hero {
  position: relative; overflow: hidden;
  background: var(--panel); border: 1px solid var(--stroke);
  border-radius: var(--radius); padding: clamp(20px, 4vw, 30px);
  margin-bottom: 22px; backdrop-filter: blur(14px); cursor: pointer;
  box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(420px 220px at 90% 0%, var(--accent-soft), transparent 70%);
  pointer-events: none;
}
.hero-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hero-label { color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.hero-dest { font-size: clamp(22px, 4vw, 34px); font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 0; }
.hero-eta { display: flex; align-items: baseline; gap: 16px; margin-top: 14px; flex-wrap: wrap; }
.hero-time { font-family: var(--mono); font-size: clamp(56px, 14vw, 104px); line-height: .9; font-weight: 700; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.hero-sched { color: var(--text-faint); font-size: 18px; }
.hero-sched s { text-decoration-color: var(--warn); }
.hero-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 16px; color: var(--text-dim); font-size: 14px; }
.hero-meta b { color: var(--text); }

/* rows */
.rows-head, .row {
  display: grid;
  grid-template-columns: 72px 78px 1fr 56px 120px 64px;
  gap: 10px; align-items: center;
}
.rows-head { padding: 0 16px 10px; color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--stroke); }
.rows { display: flex; flex-direction: column; }
.row {
  padding: 15px 16px; border-bottom: 1px solid var(--stroke); cursor: pointer;
  transition: background .12s; border-radius: 10px;
}
.row:hover { background: rgba(255,255,255,0.03); }
.t-sched { font-family: var(--mono); font-size: 17px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.t-sched.struck { text-decoration: line-through; text-decoration-color: var(--warn); opacity: .65; }
.t-exp { font-family: var(--mono); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.t-exp.ontime { color: var(--ontime); }
.t-exp.late { color: var(--warn); }
.t-exp.cancelled { color: var(--warn); font-weight: 700; }
.t-dest { min-width: 0; }
.t-dest .d-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-dest .d-delay { font-size: 12.5px; color: var(--text-dim); }
.t-dest .d-delay.late { color: var(--warn); }
.t-dest .d-delay.ontime { color: var(--ontime); }
.t-plat { font-family: var(--mono); font-size: 15px; color: var(--text); text-align: center; background: rgba(255,255,255,0.05); border-radius: 8px; padding: 4px 0; }
.t-plat.empty { color: var(--text-faint); background: none; }
.t-op { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conf { display: inline-flex; align-items: center; gap: 3px; }
.conf .bar { width: 4px; border-radius: 2px; background: var(--text-faint); }
.conf .bar.b1 { height: 7px; } .conf .bar.b2 { height: 11px; } .conf .bar.b3 { height: 15px; }
.conf.high .bar { background: var(--ontime); }
.conf.medium .bar.b1, .conf.medium .bar.b2 { background: var(--accent); }
.conf.low .bar.b1 { background: var(--warn); }
.badge-sched { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-weight: 700; letter-spacing: .04em; }

/* ---------- detail sheet ---------- */
.detail {
  position: fixed; z-index: 80; right: 0; top: 0; bottom: 0; width: min(460px, 100%);
  background: var(--panel-solid); border-left: 1px solid var(--stroke-strong);
  box-shadow: var(--shadow); display: block; /* block, not flex: a flex column shrinks the fixed-height map to 0 */
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  overflow-y: auto;
}
.detail-map { flex: none; }
.detail[data-open="true"] { transform: translateX(0); }
.detail-grab { display: none; }
.detail-close { position: absolute; top: 14px; right: 14px; z-index: 2; width: 38px; height: 38px; }
.detail-head { padding: 26px 24px 18px; border-bottom: 1px solid var(--stroke); }
.detail-line { display: inline-block; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-2); letter-spacing: .04em; }
.detail-route { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 12px; }
.detail-delay { margin-top: 8px; font-size: 15px; font-weight: 600; }
.detail-delay.late { color: var(--warn); } .detail-delay.ontime { color: var(--ontime); }
.detail-map { height: 220px; width: 100%; background: var(--bg-2); }
.detail-map:empty { display: none; }
.calling { padding: 10px 24px 40px; }
.cp { position: relative; display: grid; grid-template-columns: 56px 70px 1fr; gap: 12px; padding: 11px 0; }
.cp-rail { position: absolute; left: 84px; top: 0; bottom: 0; width: 2px; background: var(--stroke-strong); }
.cp:first-child .cp-rail { top: 50%; } .cp:last-child .cp-rail { bottom: 50%; }
.cp-dot { position: absolute; left: 79px; top: 50%; width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text-faint); transform: translateY(-50%); z-index: 1; display: grid; place-items: center; }
/* departed: filled grey rail behind, solid dot. the traversed rail is tinted. */
.cp.departed .cp-dot { background: var(--text-faint); border-color: var(--text-faint); }
.cp.departed .cp-rail { background: var(--text-faint); }
/* train standing at a stop */
.cp.at .cp-dot { width: 22px; height: 22px; background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), 0 0 14px var(--accent-glow); color: #fff; }
.cp-train-dot { display: grid; place-items: center; line-height: 0; }
/* train between stops: glyph sits on the rail above the approached stop */
.cp.approaching .cp-train { position: absolute; left: 73px; top: -10px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--accent-soft), 0 0 14px var(--accent-glow); z-index: 2; animation: trainpulse 2s ease-in-out infinite; }
.cp.approaching .cp-rail { background: linear-gradient(var(--text-faint) 0 40%, var(--stroke-strong) 40% 100%); }
@keyframes trainpulse { 0%,100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
.cp-origin { padding: 2px 0 12px 110px; color: var(--text-faint); font-size: 13px; font-style: italic; }
.cp-times { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cp-sched { color: var(--text-dim); font-size: 14px; }
.cp-sched.struck { text-decoration: line-through; opacity: .55; }
.cp-exp { font-size: 15px; font-weight: 600; }
.cp-exp.late { color: var(--warn); } .cp-exp.ontime { color: var(--ontime); }
.cp-name { padding-left: 26px; align-self: center; }
.cp-name .n { font-weight: 600; } .cp.departed .cp-name .n { color: var(--text-dim); }
.cp.at .cp-name .n { color: var(--accent-2); }
.cp-name .meta { font-size: 12px; color: var(--text-faint); }
.cp-name .meta .late { color: var(--warn); }
.cp-name .meta .live { color: var(--accent-2); font-weight: 700; }

/* ---------- formation / composition ---------- */
.formation:empty { display: none; }
.formation { padding: 18px 20px 8px; border-bottom: 1px solid var(--stroke); }
.formation-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.formation-head > span:first-child { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; }
.formation-meta { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; text-align: right; }
.formation-meta b { color: var(--text); font-weight: 700; }
.formation-strip { display: flex; align-items: flex-start; gap: 4px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: thin; }
.formation-strip::-webkit-scrollbar { height: 6px; }
.formation-strip::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }
.car { flex: none; width: 76px; text-align: center; }
.car-num { font-family: var(--mono); font-size: 11px; color: var(--text-dim); height: 15px; }
.car-svg { display: block; height: 38px; width: 100%; overflow: visible; }
.car-out { fill: #262935; stroke: rgba(255,255,255,.18); stroke-width: 1.5; }
.car-win { fill: #99a2b6; opacity: .9; }
.car-door { stroke: rgba(255,255,255,.18); stroke-width: 1.3; }
.car-wheel { fill: #41475a; }
.car-panto { stroke: var(--text-dim); stroke-width: 1.4; fill: none; }
.car-svg.c1 .car-out { fill: #3a2230; stroke: var(--accent); }
.car-svg.c1 .car-win { fill: var(--accent-2); }
.car-svg.rest .car-out { fill: #33291a; stroke: var(--warn); }
.car-svg.rest .car-win { fill: #e9c98a; }
.car-svg.power .car-out { fill: #1a1c25; }
.car-svg.power .car-win { fill: #5b6275; }
.car-amen { display: flex; gap: 4px; justify-content: center; min-height: 16px; margin-top: 6px; color: var(--text); }
.amen { display: inline-flex; }
.car-foot { margin-top: 4px; min-height: 17px; }
.car-cls { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 5px; }
.car-cls.c1 { background: var(--accent); color: #fff; }
.car-cls.c2 { background: rgba(255,255,255,.08); color: var(--text-dim); }
.car-cls.note { background: var(--warn-soft); color: var(--warn); }
.car-cls.type { background: rgba(255,255,255,.06); color: var(--text-dim); font-family: var(--mono); font-weight: 600; }
.dir-arrow { align-self: center; color: var(--accent); font-size: 14px; margin-left: 4px; flex: none; }

/* ---------- map ---------- */
.map { width: 100%; height: 100%; background: var(--bg-2); }
.map-legend {
  position: absolute; left: 16px; bottom: 16px; z-index: 500;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 999px;
  padding: 8px 14px; font-size: 12.5px; color: var(--text-dim);
  backdrop-filter: blur(14px);
}
.map-legend .dot { width: 9px; height: 9px; border-radius: 50%; }
.map-legend .dot.ontime { background: var(--ontime); } .map-legend .dot.late { background: var(--warn); }
.map-count { margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--stroke); color: var(--text); }
.train-marker { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 3px rgba(0,0,0,.4); }
.train-marker.ontime { background: var(--ontime); } .train-marker.late { background: var(--warn); }
/* station pin — distinct hollow ring so it never reads as a train dot */
.station-marker { width: 13px; height: 13px; border-radius: 50%; background: #11131a; border: 3px solid var(--accent); box-shadow: 0 0 0 1.5px rgba(0,0,0,.5); cursor: pointer; transition: transform .12s; }
.station-marker:hover { transform: scale(1.35); }
.legend-stn { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: #11131a; border: 3px solid var(--accent); vertical-align: -1px; }
.map-hint { color: var(--text-faint); font-style: italic; }
.leaflet-tooltip.station-tip { background: var(--panel-solid); color: var(--text); border: 1px solid var(--stroke-strong); border-radius: 7px; font-weight: 600; font-size: 12.5px; box-shadow: var(--shadow); }
.leaflet-tooltip.station-tip::before { border-top-color: var(--stroke-strong); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-solid); color: var(--text); border: 1px solid var(--stroke-strong); }
.leaflet-popup-content { font-family: var(--font); }
.leaflet-container { background: var(--bg-2); }
.leaflet-tile { filter: brightness(.7) invert(1) contrast(.9) hue-rotate(180deg) saturate(.5); }

/* ---------- kiosk / signage mode ---------- */
body.kiosk .topbar, body.kiosk .tabs, body.kiosk #brand .brand-name { display: none; }
body.kiosk { overflow: hidden; }
body.kiosk #view-map.view { inset: 0; }
body.kiosk .board { max-width: none; padding: clamp(24px, 4vw, 56px); height: 100vh; display: flex; flex-direction: column; }
body.kiosk .board-head, body.kiosk .hero, body.kiosk .rows-head { flex: none; } /* don't let flex shrink the hero below its content */
body.kiosk .board-station { font-size: clamp(40px, 7vw, 80px); }
body.kiosk .board-clock { font-size: clamp(34px, 5vw, 56px); }
body.kiosk .hero-time { font-size: clamp(72px, 16vw, 150px); }
body.kiosk .rows { flex: 1; }
body.kiosk .row { padding: 20px 16px; }
body.kiosk .t-sched, body.kiosk .t-exp { font-size: 22px; }
body.kiosk .t-dest .d-name { font-size: 21px; }
.kiosk-exit {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  background: var(--panel); border: 1px solid var(--stroke-strong); color: var(--text);
  padding: 10px 16px; border-radius: 999px; cursor: pointer; opacity: 0; transition: opacity .2s;
}
body.kiosk .kiosk-exit { opacity: 0; }
body.kiosk:hover .kiosk-exit { opacity: 1; }

.empty-msg { padding: 60px 20px; text-align: center; color: var(--text-dim); line-height: 1.6; }
.empty-msg.notice-auth, .empty-msg.notice-err { max-width: 540px; margin: 0 auto; }
.empty-msg.notice-auth strong { color: var(--warn); display: inline-block; margin-bottom: 6px; font-size: 17px; }
.empty-msg.notice-err strong { color: var(--accent); display: inline-block; margin-bottom: 6px; font-size: 17px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--stroke-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
.mini-spin { width: 15px; height: 15px; border: 2px solid var(--stroke-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
.result.loading { color: var(--text-dim); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .searchwrap { order: 3; flex-basis: 100%; max-width: none; }
  .rows-head { display: none; }
  .row { grid-template-columns: 64px 70px 1fr 48px; gap: 8px; }
  .col-op, .t-op, .conf { display: none; }
  .detail { width: 100%; top: auto; height: 90vh; border-left: none; border-top: 1px solid var(--stroke-strong); border-radius: 20px 20px 0 0; transform: translateY(100%); }
  .detail[data-open="true"] { transform: translateY(0); }
  .detail-grab { display: block; width: 42px; height: 5px; border-radius: 3px; background: var(--stroke-strong); margin: 10px auto 0; }
}
