:root {
  --bg: #f4f4f2;
  --card: #ffffff;
  --text: #141414;
  --muted: #6b6b6b;
  --line: #e4e4e0;
  --accent: #0039a6;
  --soon: #0a7d2c;
  --dir-n: #0a6fd6; /* toward Manhattan / north */
  --dir-s: #d6336c; /* away from Manhattan / south */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0e;
    --card: #1a1a1a;
    --text: #f2f2f2;
    --muted: #9a9a9a;
    --line: #2a2a2a;
    --accent: #6f9bff;
    --soon: #5fd383;
    --dir-n: #5cb4ff;
    --dir-s: #ff7a9a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  max-width: 560px;
  margin: 0 auto;
}
h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.status { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.refresh {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
}
.refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stations, .foot { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.stations { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding-top: 12px; }

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 14px 16px 6px;
  border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.dist { color: var(--muted); font-size: 13px; white-space: nowrap; }
.card-routes { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 4px; }

.dir { border-top: 1px solid var(--line); padding: 10px 0 8px; margin-top: 8px; }
.dir:first-of-type { border-top: 0; }
.dir-N { --dir: var(--dir-n); }
.dir-S { --dir: var(--dir-s); }
.dir-label { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--dir, var(--text)); margin: 0 0 8px; }
.dir-arrow {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--dir, var(--text)); color: var(--card);
  font-size: 14px; font-weight: 800;
}
.arrivals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.arrival {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}
.mins { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 18px; }
.later { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
.later b { color: var(--text); font-size: 17px; font-weight: 600; }
.mins small { font-weight: 500; font-size: 13px; color: var(--muted); }
.mins.now { color: var(--soon); }
.empty { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

.bullet {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: 15px;
  color: #fff;
  background: #808183;
}
.bullet.small { width: 22px; height: 22px; font-size: 12px; }
.bullet.wide { width: auto; padding: 0 7px; border-radius: 11px; font-size: 11px; }
.bullet.express { border-radius: 4px; transform: rotate(45deg) scale(0.86); }
.bullet.express > span { transform: rotate(-45deg); }
.r-1, .r-2, .r-3 { background: #ee352e; }
.r-4, .r-5, .r-6 { background: #00933c; }
.r-7 { background: #b933ad; }
.r-A, .r-C, .r-E, .r-SIR { background: #0039a6; }
.r-B, .r-D, .r-F, .r-M { background: #ff6319; }
.r-G { background: #6cbe45; }
.r-J, .r-Z { background: #996633; }
.r-L { background: #a7a9ac; }
.r-N, .r-Q, .r-R, .r-W { background: #fccc0a; color: #000; }

.places {
  max-width: 560px;
  margin: 12px auto 0;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.places button {
  font: inherit; font-size: 15px; font-weight: 600;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.places button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.foot { color: var(--muted); font-size: 12px; padding-top: 20px; padding-bottom: 28px; text-align: center; }

.skeleton { height: 150px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); opacity: 0.6; }
