:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #182033;
  --muted: #697386;
  --line: #e3e7ee;
  --route: #f2b400;
  --route-dark: #8b6400;
  --down-color: #d99a00;
  --up-color: #ffd34d;
  --blue: #2563eb;
  --red: #dc2626;
  --green: #15803d;
  --shadow: 0 14px 34px rgba(24, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin-top: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 28px clamp(18px, 4vw, 48px);
  background: #171b24;
  color: #fff;
  border-bottom: 6px solid var(--route);
}

.eyebrow {
  margin: 0 0 6px;
  color: #cbd5e1;
  font-size: 0.9rem;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1.05;
}

.refresh-pill {
  flex: 0 0 auto;
  max-width: 160px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  font-size: 0.9rem;
  text-align: center;
}

.layout {
  width: min(1120px, calc(100% - 32px));
  margin: 26px auto 0;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.bottom-summary {
  margin-top: 28px;
}

.metric {
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.metric strong {
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.error-box {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: #9f1239;
}

.station-section {
  margin-top: 30px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin-bottom: 4px;
  font-size: 1.35rem;
}

.section-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.direction-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(360px, 48vw);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
}

.route-map {
  margin-bottom: 26px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.route-map-grid {
  --route-gap: 5px;
  position: relative;
  display: grid;
  gap: var(--route-gap);
}

.route-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--route-columns), minmax(0, 1fr));
  gap: var(--route-gap);
}

.route-row::before {
  position: absolute;
  top: 50%;
  right: 8px;
  left: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(242, 180, 0, 0.58);
  content: "";
  transform: translateY(-50%);
}

.route-row:not(:last-child)::after {
  position: absolute;
  top: 50%;
  width: 8px;
  height: calc(100% + var(--route-gap));
  border-radius: 999px;
  background: rgba(242, 180, 0, 0.58);
  content: "";
}

.route-row:not(.reverse):not(:last-child)::after {
  right: 8px;
}

.route-row.reverse:not(:last-child)::after {
  left: 8px;
}

.route-stop {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  min-width: 0;
  min-height: 29px;
  padding: 4px 7px;
  border: 1px solid rgba(242, 180, 0, 0.45);
  border-radius: 8px;
  background: #fffdf3;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  word-break: keep-all;
  overflow: hidden;
}

.route-stop-name {
  position: relative;
  z-index: 2;
  justify-self: center;
  padding: 1px 3px;
  border-radius: 4px;
  background: rgba(255, 253, 243, 0.86);
}

.transfer-bars {
  position: absolute;
  top: 4px;
  bottom: 4px;
  z-index: 1;
  display: flex;
  gap: 2px;
  pointer-events: none;
}

.transfer-bars.left {
  left: 5px;
}

.transfer-bars.right {
  right: 5px;
}

.transfer-bar {
  width: 6px;
  border-radius: 999px;
  background: var(--transfer-color);
}

.route-stop.active {
  border-color: var(--route);
  background: #fff8d9;
  color: var(--route-dark);
  box-shadow: 0 6px 16px rgba(139, 100, 0, 0.12);
}

.route-stop.down-live {
  border-bottom-color: var(--down-color);
  border-bottom-width: 4px;
}

.route-stop.up-live {
  border-top-color: var(--up-color);
  border-top-width: 4px;
}

.route-stop.both-live {
  border-top-color: var(--up-color);
  border-bottom-color: var(--down-color);
  border-top-width: 4px;
  border-bottom-width: 4px;
}

.route-stop.active .route-stop-name {
  background: rgba(255, 248, 217, 0.88);
}

.route-stop.express-stop {
  outline: 1px solid var(--red);
  outline-offset: 2px;
}

.route-stop small {
  display: none;
}

.station-list {
  position: relative;
  display: grid;
  gap: 0;
  padding: 8px 0 18px;
}

.station-list::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 10px;
  border-radius: 999px;
  background: var(--route);
  content: "";
  transform: translateX(-50%);
}

.station-list::after {
  position: absolute;
  top: 8px;
  right: 0;
  bottom: 18px;
  left: 0;
  z-index: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='24' viewBox='0 0 18 24'%3E%3Cpath d='M9 18 2 6h14L9 18Z' fill='%23d99a00' fill-opacity='.42'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='24' viewBox='0 0 18 24'%3E%3Cpath d='M9 6 16 18H2L9 6Z' fill='%23ffd34d' fill-opacity='.62'/%3E%3C/svg%3E");
  background-position:
    calc(50% - 222px) 0,
    calc(50% + 204px) 0;
  background-repeat: repeat-y;
  background-size: 18px 24px;
  content: "";
  pointer-events: none;
}

.station-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 164px minmax(0, 1fr);
  gap: 18px;
  min-height: 77px;
  padding: 8px 0;
  scroll-margin-top: 18px;
}

.station-axis {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.station-marker {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 5px solid var(--route);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 6px var(--bg);
}

.station-name {
  position: relative;
  z-index: 2;
  max-width: 148px;
  padding: 7px 10px;
  border: 1px solid rgba(212, 0, 59, 0.22);
  border-radius: 999px;
  background: #fff;
  color: var(--route-dark);
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  word-break: keep-all;
  box-shadow: 0 8px 22px rgba(24, 32, 51, 0.09);
  overflow: visible;
}

.station-name-text {
  position: relative;
  z-index: 2;
}

.station-transfer-marks {
  position: absolute;
  inset: -8px;
  z-index: 1;
  pointer-events: none;
}

.station-transfer-mark {
  position: absolute;
  width: 18px;
  height: 5px;
  border-radius: 999px;
  background: var(--transfer-color);
  opacity: 0.86;
  transform: rotate(-45deg);
}

.station-transfer-mark.ne {
  top: 0;
  right: 2px;
}

.station-transfer-mark.se {
  right: 2px;
  bottom: 0;
  transform: rotate(45deg);
}

.station-transfer-mark.sw {
  bottom: 0;
  left: 2px;
}

.station-transfer-mark.nw {
  top: 0;
  left: 2px;
  transform: rotate(45deg);
}

.direction-column {
  display: grid;
  align-content: center;
  gap: 6px;
  min-width: 0;
}

.down-column {
  justify-items: end;
}

.up-column {
  justify-items: start;
}

.empty {
  position: relative;
  z-index: 1;
  color: #a4adbd;
  font-size: 0.82rem;
}

.last-passed {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--route-dark);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  word-break: keep-all;
}

.train-card {
  position: relative;
  z-index: 1;
  width: min(100%, 280px);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.train-card.express-train {
  border-color: var(--red);
  box-shadow: 0 10px 26px rgba(220, 38, 38, 0.13);
}

.down-column .train-card {
  border-right: 5px solid var(--route);
  text-align: right;
}

.up-column .train-card {
  border-left: 5px solid var(--route);
}

.down-column .train-card.express-train {
  border-right-color: var(--red);
}

.up-column .train-card.express-train {
  border-left-color: var(--red);
}

.train-terminal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--route-dark);
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.25;
  word-break: keep-all;
}

.down-column .train-terminal {
  flex-direction: row;
}

.up-column .train-terminal {
  flex-direction: row;
}

.train-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 5px 8px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.down-column .train-meta {
  flex-direction: row-reverse;
}

.train-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.train-number {
  color: #334155;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.state {
  background: #e8f7ee;
  color: var(--green);
}

.badge.express {
  background: #fef2f2;
  color: var(--red);
}

.badge.local {
  background: #eff6ff;
  color: var(--blue);
}

.badge.last {
  background: #fef2f2;
  color: var(--red);
}

.footer {
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto 22px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.footer p {
  margin-bottom: 6px;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .direction-legend {
    width: 100%;
  }

  .route-map {
    padding: 6px;
  }

  .route-map-grid {
    --route-gap: 4px;
  }

  .route-stop {
    min-height: 25px;
    padding: 3px 5px;
    border-radius: 6px;
    font-size: 0.66rem;
  }

  .route-stop small {
    display: none;
  }

  .station-row {
    grid-template-columns: minmax(0, 1fr) 112px minmax(0, 1fr);
    gap: 8px;
    min-height: 83px;
  }

  .station-list::before {
    width: 8px;
  }

  .station-list::after {
    background-position:
      calc(50% - 132px) 0,
      calc(50% + 114px) 0;
    background-size: 16px 22px;
  }

  .station-name {
    max-width: 104px;
    padding: 6px 8px;
    font-size: 0.82rem;
  }

  .station-marker {
    width: 20px;
    height: 20px;
    border-width: 4px;
  }

  .train-card {
    padding: 6px 7px;
  }

  .train-terminal {
    font-size: 0.88rem;
    gap: 5px;
  }

  .train-meta {
    align-items: center;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 3px 5px;
    font-size: 0.74rem;
  }

  .down-column .train-meta {
    flex-direction: row-reverse;
  }

  .train-info {
    gap: 5px;
  }

  .badge {
    min-height: 18px;
    padding: 2px 6px;
    font-size: 0.72rem;
  }

  .empty {
    display: none;
  }

  .empty.last-passed {
    display: inline-flex;
    max-width: 100%;
    font-size: 0.68rem;
  }
}
