:root {
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-fg: #1d1d1f;
  --muted: #6b6b70;
  --accent: #0a5fd6;
  --line: #e2e2e6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tap: 40px;                 /* minimum touch target */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
body.night {
  --panel-bg: rgba(24, 28, 40, 0.94);
  --panel-fg: #eef0f6;
  --muted: #a0a6b8;
  --line: #333a4d;
  --accent: #5b9dff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* beat display:flex etc. on hidden elements */
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--panel-fg); overscroll-behavior: none; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-top-right { top: calc(var(--safe-t) + 8px); }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--safe-b) + 118px); }

.panel {
  position: absolute; z-index: 5;
  background: var(--panel-bg); color: var(--panel-fg);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: background .3s, color .3s;
}
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.only-mobile { display: none; }
a { color: var(--accent); }

/* ---------- buttons ---------- */
.btn { border: none; background: var(--accent); color: #fff; min-width: var(--tap); height: var(--tap); border-radius: 10px; font-size: 15px; cursor: pointer; font-family: inherit; }
.btn.small { height: 34px; min-width: 34px; padding: 0 10px; font-size: 12.5px; background: var(--line); color: var(--panel-fg); }
.btn.primary { background: var(--accent); color: #fff; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.x { border: none; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; width: var(--tap); height: var(--tap); border-radius: 50%; }
.x:hover { background: var(--line); }

/* ---------- header ---------- */
.panel.top {
  top: calc(var(--safe-t) + 12px); left: 12px; max-width: min(780px, calc(100% - 70px));
  padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.title h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.title .sub { font-size: 12px; color: var(--muted); }
.head-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.modes { display: flex; gap: 4px; }
.mode { border: 1px solid var(--line); background: transparent; color: var(--panel-fg); height: 34px; padding: 0 12px; border-radius: 8px; font-size: 12.5px; cursor: pointer; font-family: inherit; }
.mode.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.lines { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.line-group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.line-pill, .line-all {
  border: none; cursor: pointer; min-width: 30px; height: 28px; padding: 0 8px;
  border-radius: 7px; font-weight: 700; font-size: 13px; font-family: inherit; transition: opacity .15s, transform .1s;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.line-pill.off { opacity: 0.2; }
.line-pill:hover, .line-all:hover { transform: translateY(-1px); }
.line-all { background: var(--line); color: var(--panel-fg); font-weight: 600; font-size: 11.5px; }

/* ---------- bottom bar ---------- */
.panel.bottom {
  left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.panel.bottom .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.slider-row { padding: 0 2px; }
.slider-row .speed-wrap { margin-left: 4px; }
.date-wrap { display: flex; align-items: center; gap: 4px; }
.date-wrap input { font: inherit; font-size: 13px; height: 34px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--panel-fg); color-scheme: light dark; }
.clock-wrap { display: flex; align-items: center; gap: 8px; }
.clock { font-family: var(--mono); font-size: 20px; font-variant-numeric: tabular-nums; min-width: 9ch; }
#time-slider { flex: 1; accent-color: var(--accent); min-width: 140px; height: 28px; margin: 0; touch-action: pan-x; }
.speed-wrap { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.speed-wrap select { font: inherit; font-size: 13px; height: 34px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--panel-fg); }
#share, #info-toggle, #now { white-space: nowrap; }

/* ---------- side panel ---------- */
.panel.side {
  right: 12px; top: calc(var(--safe-t) + 12px); width: 370px; max-width: calc(100% - 24px);
  max-height: calc(100% - var(--safe-b) - 150px); overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px; font-size: 13.5px; line-height: 1.45; display: none;
}
.panel.side.open { display: block; }
.grip { display: none; }
.p-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.p-head h2 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.p-title { font-weight: 600; }
.p-sub { color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.p-actions { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.pill { display: inline-block; min-width: 26px; text-align: center; padding: 2px 7px; border-radius: 6px; font-weight: 800; font-size: 12.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
h3 { font-size: 13px; margin: 12px 0 6px; }
.dir { padding: 8px 0; border-top: 1px solid var(--line); }
.stop-chain { margin-top: 4px; font-size: 11.5px; line-height: 1.7; color: var(--muted); }
.stop-chain span { cursor: pointer; }
.stop-chain span:hover { color: var(--accent); text-decoration: underline; }
.stop-chain i { font-style: normal; margin: 0 3px; opacity: .5; }

table.dep { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.dep th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; padding: 4px; border-bottom: 1px solid var(--line); }
table.dep td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.dep tr[data-trip] { cursor: pointer; }
table.dep tr[data-trip]:hover td { background: rgba(10, 95, 214, 0.08); }
table.dep tr.left td { opacity: .5; }
table.dep small { color: var(--muted); }

ol.trip-stops { list-style: none; margin: 8px 0; padding: 0; }
ol.trip-stops li { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 5px 0; cursor: pointer; }
ol.trip-stops li:hover .name { color: var(--accent); }
ol.trip-stops .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #999; justify-self: center; }
ol.trip-stops li.here .dot { box-shadow: 0 0 0 3px rgba(10, 95, 214, 0.25); }
ol.trip-stops li.here .name { font-weight: 700; }
ol.trip-stops li.done .name { color: var(--muted); }
ol.trip-stops .t small { color: var(--muted); }
sup { font-size: 9px; color: var(--muted); }

/* ---------- info panel ---------- */
.panel.info { right: 12px; bottom: calc(var(--safe-b) + 130px); width: 380px; max-width: calc(100% - 24px); max-height: calc(100% - 160px); overflow: auto; padding: 14px 16px; font-size: 13px; line-height: 1.45; display: none; z-index: 6; }
.panel.info.open { display: block; }
.panel.info h2 { margin: 0; font-size: 15px; }
.panel.info p { margin: 0 0 10px; }
.panel.info dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 10px; }
.panel.info dt { color: var(--muted); }
.panel.info dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-word; }
.warn { background: #fff3cd; color: #6b4e00; padding: 6px 8px; border-radius: 6px; font-size: 12px; }

/* ---------- consent ---------- */
.consent {
  position: absolute; z-index: 30; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 130px);
  margin: 0 auto; max-width: 560px; background: var(--panel-bg); color: var(--panel-fg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.consent-actions { display: flex; gap: 6px; margin-left: auto; }

/* ---------- tooltip / status / noscript ---------- */
.tooltip { position: absolute; z-index: 10; pointer-events: none; background: var(--panel-bg); color: var(--panel-fg); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; min-width: 230px; font-size: 12.5px; }
.tt-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.tt-row { display: flex; justify-content: space-between; gap: 12px; }
.tt-row span { color: var(--muted); }
.tt-foot { margin-top: 6px; font-size: 10.5px; color: var(--muted); }
.status { position: absolute; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel-bg); color: var(--panel-fg); padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 14px; max-width: 80%; }
.status.error { background: #fde8e8; color: #8a1c1c; }
.noscript { position: absolute; z-index: 40; inset: 0; padding: 24px; background: #fff; color: #111; font-size: 15px; line-height: 1.5; }

/* ---------- phones & small tablets ---------- */
@media (max-width: 720px), (pointer: coarse) and (max-width: 1024px) {
  .only-mobile { display: inline-block; }
  .panel.top { left: 8px; right: 8px; max-width: none; padding: 8px 10px; gap: 6px 10px; }
  .title h1 { font-size: 16px; }
  .title .sub { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
  .lines { display: none; max-height: 38vh; overflow: auto; }
  .lines.open { display: flex; }
  .line-pill, .line-all { height: 34px; min-width: 36px; font-size: 14px; }

  .panel.bottom { left: 8px; right: 8px; bottom: calc(var(--safe-b) + 8px); padding: 8px 10px; gap: 6px; }
  .panel.bottom .row { gap: 6px; flex-wrap: nowrap; }
  .clock { font-size: 17px; min-width: 8ch; }
  .clock-wrap { gap: 4px; }
  .speed-wrap span { display: none; }
  .speed-wrap select { padding: 0 2px; font-size: 12px; }
  #date-prev, #date-next { display: none; }   /* native date picker is enough on phones */
  .date-wrap input { width: 118px; font-size: 12px; padding: 0 4px; }
  .panel.bottom .row:first-child > * { flex-shrink: 0; }
  .clock-wrap { margin-left: auto; }
  .btn.small { padding: 0 8px; }
  .maplibregl-ctrl-top-right { top: auto; bottom: calc(var(--safe-b) + 120px); }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--safe-b) + 108px); }

  /* Side panel becomes a bottom sheet above the control bar */
  .panel.side {
    left: 8px; right: 8px; top: auto; bottom: calc(var(--safe-b) + 114px); width: auto; max-width: none;
    max-height: 48vh; border-radius: 14px; padding: 6px 14px 14px;
  }
  .grip { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 8px; }
  .panel.info { left: 8px; right: 8px; width: auto; max-width: none; bottom: calc(var(--safe-b) + 114px); max-height: 60vh; }
  .consent { bottom: calc(var(--safe-b) + 114px); }
  .tooltip { display: none; }
}

@media (max-width: 380px) {
  .date-wrap input { width: 104px; }
  .clock { font-size: 15px; }
}
