:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1b1d21;
  --muted: #6b6f76;
  --line: #e6e1d6;
  --accent: #b8452e;       /* Rome: terracotta */
  --accent-ink: #ffffff;
  --soon: #1f7a4d;
  --late: #b26b00;
  --gone: #a7a9ad;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
body[data-city="boston"] { --accent: #1c4f9c; }
body[data-view="pescara"] { --accent: #0f766e; --accent-ink: #ffffff; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2127;
    --ink: #eceef1;
    --muted: #9aa0a8;
    --line: #2c3038;
    --accent: #e0694f;
    --soon: #4cc38a;
    --late: #e3a33b;
    --gone: #5d6168;
    --shadow: none;
    color-scheme: dark;
  }
  body[data-city="boston"] { --accent: #6b9cf0; --accent-ink: #0d1626; }
  body[data-view="pescara"] { --accent: #2dd4bf; --accent-ink: #04241f; }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.brand { margin: 0 0 2px; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-size: 30px; line-height: 1.1; letter-spacing: -.02em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface);
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* City slider */
.switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  margin-top: 14px; padding: 4px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.switch button {
  position: relative; z-index: 1; border: 0; background: none;
  padding: 9px 0; border-radius: 999px; font-weight: 600; cursor: pointer;
  transition: color .25s;
}
.switch button[aria-checked="true"] { color: var(--accent-ink); }
.switch .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
  border-radius: 999px; background: var(--accent);
  transition: transform .28s cubic-bezier(.3,.7,.2,1), background .25s;
}
body[data-city="boston"] #city-switch .thumb, .switch[data-pos="1"] .thumb { transform: translateX(100%); }
.auto-note { margin: 8px 2px 0; font-size: 12px; color: var(--muted); min-height: 1em; }

main { padding: 14px 16px 8px; display: grid; gap: 12px; }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  overflow: hidden;
}
.card-head { padding: 14px 16px 6px; display: flex; align-items: baseline; gap: 10px; }
.card-head .arrow { color: var(--accent); font-weight: 700; }
.card-head h2 { margin: 0; font-size: 19px; line-height: 1.25; letter-spacing: -.01em; }
.card-head .via { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }

.row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 16px; border-top: 1px solid var(--line);
}
.card-head + .row { border-top: 0; }
.badge {
  min-width: 46px; height: 32px; padding: 0 8px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 15px; letter-spacing: -.01em;
}
.badge.night { background: #2b2f6b; color: #fff; }
.stop { min-width: 0; }
.stop .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop .hint { font-size: 12px; color: var(--muted); }
.stop .hint.go { color: var(--soon); font-weight: 600; }
.times { display: flex; gap: 6px; align-items: baseline; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.t { font-size: 14px; color: var(--muted); white-space: nowrap; }
.t.first { font-size: 22px; font-weight: 800; color: var(--ink); }
.t.first small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 1px; }
.t.now { color: var(--soon); }
.t.gone { color: var(--gone); text-decoration: line-through; }

.empty, .error {
  text-align: center; color: var(--muted); padding: 40px 20px;
  background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line);
}
.error { color: var(--late); }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); opacity: .6; }

.foot { padding: 6px 16px 24px; font-size: 12px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .switch .thumb, .switch button { transition: none; }
  .icon-btn.spin svg { animation: none; }
}

/* ---------- Sections + bottom tabs ---------- */
.view { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.view[hidden] { display: none; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1fr;
  max-width: 640px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  border: 0; background: none; cursor: pointer;
  display: grid; justify-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabs button[aria-current="page"] { color: var(--accent); }
.tabs button[aria-current="page"] svg { transform: translateY(-1px); }

/* ---------- Roma <-> Pescara ---------- */
#dir-switch button { font-size: 15px; }
.days {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 12px -16px 0; padding: 2px 16px 4px; scroll-snap-type: x proximity;
}
.days::-webkit-scrollbar { display: none; }
.days button, .days .pick {
  flex: 0 0 auto; scroll-snap-align: center;
  display: grid; justify-items: center; gap: 1px;
  min-width: 64px; padding: 7px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-size: 12px; color: var(--muted); position: relative;
}
.days b { font-size: 14px; color: var(--ink); white-space: nowrap; }
.days button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.days button[aria-selected="true"] b { color: var(--accent-ink); }
.days .pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.sort { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.sort button { border: 0; background: none; padding: 5px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.sort button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.avail-only { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.avail-only input { accent-color: var(--accent); width: 16px; height: 16px; }

#ic-list { gap: 10px; }
.ride {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "times side" "meta side";
  gap: 6px 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: inherit; text-decoration: none;
}
.ride:active { transform: scale(.99); }
.ride.soldout { opacity: .55; }
.ride-times { grid-area: times; display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.ride-times b { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.ride-times sup { font-size: 11px; color: var(--late); margin-left: 1px; }
.ride-line { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 60px; max-width: 150px; }
.ride-line i { flex: 1; height: 2px; background: var(--line); border-radius: 2px; }
.ride-line em { font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; }
.ride-meta { grid-area: meta; display: flex; align-items: center; gap: 8px; min-width: 0; }
.op { flex: 0 0 auto; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 6px; letter-spacing: .01em; }
.stations { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ride-side { grid-area: side; display: grid; justify-items: end; align-content: center; gap: 4px; }
.price { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--soon) 15%, transparent); color: var(--soon); }
.pill.few { background: color-mix(in srgb, var(--late) 18%, transparent); color: var(--late); }
.pill.out { background: color-mix(in srgb, #c0392b 15%, transparent); color: #c0392b; }
.pill.best { background: var(--accent); color: var(--accent-ink); }
.note { margin: 4px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
#ic-sources { line-height: 1.8; }
.src { display: inline-block; padding: 0 7px; border-radius: 999px; border: 1px solid var(--line); }
.src.ok::before { content: "✓ "; color: var(--soon); }
.src.bad { color: var(--late); }
.src.bad::before { content: "! "; }
@media (max-width: 380px) {
  .ride-times b { font-size: 18px; }
  .sort button { padding: 5px 8px; }
}
