:root { --bg: #ffffff; --fg: #111827; --muted: #4b5563; --line: #d1d5db; --panel: rgba(255, 255, 255, .94); --accent: #1d4ed8; --shadow: 0 2px 10px rgba(0, 0, 0, .25); }
@media (prefers-color-scheme: dark) { :root { --bg: #111827; --fg: #f3f4f6; --muted: #9ca3af; --line: #374151; --panel: rgba(17, 24, 39, .92); --accent: #60a5fa; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font: 15px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--fg); overscroll-behavior: none; }
#map { position: fixed; inset: 0; }
#trails { position: fixed; inset: 0; pointer-events: none; z-index: 400; }
button { font: inherit; color: inherit; }
#status { position: fixed; z-index: 600; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 120px);
  background: var(--panel); box-shadow: var(--shadow); border-radius: 18px; padding: 6px 14px; font-size: 13px; text-align: center; }
#status.live::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #16a34a; margin-right: 6px; vertical-align: 1px; }

/* the time range: one thumb on a vertical rail along the right edge, now at the top; the rail's length is how far back it reaches, set with the grip at its end */
#slider { position: fixed; z-index: 600; right: calc(8px + env(safe-area-inset-right)); top: calc(56px + env(safe-area-inset-top)); bottom: calc(150px + env(safe-area-inset-bottom));
  width: 52px; }                       /* "now" and the top of the rail stay put; only the rail's bottom end and its grip move (placed by app.js) */
#now-label { position: absolute; top: 0; left: 50%; transform: translateX(-50%); border: 0; font: inherit; color: inherit; cursor: pointer; background: var(--panel); box-shadow: var(--shadow); border-radius: 10px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
#track { position: absolute; top: 46px; left: 50%; margin-left: -6px; width: 12px; border-radius: 6px; background: var(--panel); box-shadow: var(--shadow); touch-action: none; }
#track::before { content: ""; position: absolute; inset: 0 -14px; }       /* a wider target than the drawn rail */
#fill { position: absolute; left: 3px; right: 3px; top: 0; background: var(--accent); border-radius: 6px; opacity: .85; pointer-events: none; }      /* narrower: the green shows beside it */
.handle { position: absolute; left: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: var(--bg); border: 3px solid var(--accent);
  box-shadow: var(--shadow); touch-action: none; }
.handle::after { content: ""; position: absolute; inset: -10px; }      /* a bigger target for a finger */
.tag { position: absolute; right: 36px; top: 50%; transform: translateY(-50%); background: var(--panel); box-shadow: var(--shadow); border-radius: 10px; padding: 3px 8px;
  font-size: 12px; white-space: nowrap; pointer-events: none; text-align: right; line-height: 1.25; }
.tag b { display: block; font-size: 13px; }
#max-grip { position: absolute; left: 50%; transform: translateX(-50%); border: 0; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); padding: 4px 6px 6px; min-width: 52px; touch-action: none; cursor: ns-resize;
  font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 1px; white-space: nowrap; }
#max-grip::before { content: ""; width: 22px; height: 4px; border-radius: 2px; border-top: 2px solid var(--muted); border-bottom: 2px solid var(--muted); margin-bottom: 2px; }     /* grip lines */

/* pulling the thumb to the left: a circle under the finger on a line to the thumb; its distance sets the window */
#pull { position: fixed; z-index: 610; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: var(--bg); border: 3px solid var(--accent);
  box-shadow: var(--shadow); pointer-events: none; }
#pull-label { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); background: var(--panel); box-shadow: var(--shadow); border-radius: 10px;
  padding: 3px 8px; font-size: 13px; font-weight: 700; white-space: nowrap; }
#pull-line { position: fixed; z-index: 605; height: 3px; margin-top: -1.5px; background: var(--accent); pointer-events: none; }
#pull[hidden], #pull-line[hidden] { display: none; }

#locate, #line-button { position: fixed; z-index: 600; border: 0; background: var(--panel); box-shadow: var(--shadow); }
#locate { right: calc(10px + env(safe-area-inset-right)); bottom: calc(86px + env(safe-area-inset-bottom)); width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; color: var(--accent); }
#locate.off { color: var(--muted); }
#line-button { left: calc(12px + env(safe-area-inset-left)); bottom: calc(20px + env(safe-area-inset-bottom)); min-height: 52px; min-width: 52px; max-width: calc(100% - 90px);
  border-radius: 26px; padding: 6px 16px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#line-button.empty { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.06); } }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 14px; padding: 3px 10px; color: #fff; font-weight: 700; font-size: 14px; }

#sheet { position: fixed; z-index: 700; left: 0; right: 0; bottom: 0; max-height: 72%; display: flex; flex-direction: column; background: var(--bg); color: var(--fg);
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 20px rgba(0, 0, 0, .3); padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
#sheet[hidden] { display: none; }
#sheet-head { display: flex; gap: 8px; }
#line-search { flex: 1; font: inherit; font-size: 17px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); }
#sheet-done { border: 0; border-radius: 10px; padding: 0 16px; background: var(--accent); color: #fff; font-weight: 600; }
#chosen { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; min-height: 4px; }
#chosen .chip { border: 0; cursor: pointer; }
#line-grid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; padding: 6px 0; }
#line-grid button { border: 1px solid var(--line); border-radius: 10px; background: none; padding: 10px 0; font-weight: 600; }
#line-grid button.on { color: #fff; border-color: transparent; }
#popup { position: fixed; z-index: 650; background: var(--panel); box-shadow: var(--shadow); border-radius: 12px; padding: 8px 12px; font-size: 13px; max-width: 260px; pointer-events: none; }
#popup b { font-size: 15px; }
.leaflet-control-attribution { font-size: 10px; }

/* the dial: a full-screen layer, a ring of digits (greyed where no line goes on with that digit; the first dial's 0 is the alphabet), and the letters' circle */
#dial { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 800; pointer-events: none; touch-action: none; display: none; }
#dial.open { display: block; pointer-events: auto; background: rgba(0, 0, 0, .35); }
#dial .sector { fill: var(--panel); stroke: var(--line); stroke-width: 1; }
#dial .sector.off { fill: var(--bg); opacity: .55; }
#dial .sector.lit { fill: var(--accent); }
#dial text { text-anchor: middle; dominant-baseline: central; font: 600 17px system-ui, sans-serif; fill: var(--fg); pointer-events: none; user-select: none; }
#dial text.off { fill: var(--muted); opacity: .45; font-weight: 400; }
#dial text.lit { fill: #fff; }
#dial .hub { fill: var(--bg); stroke: var(--accent); stroke-width: 3; }
#dial .hub.done { fill: var(--panel); }
#dial .hub.lit { fill: var(--accent); }
#dial .prefix { font-size: 24px; font-weight: 700; }
#dial .tick { font-size: 12px; fill: var(--accent); }
#dial .button { fill: var(--panel); stroke: var(--line); }
#dial .button.lit { fill: var(--accent); }
#dial .button.off { opacity: .4; }
#dial .button-label { font-size: 20px; }
#dial-guide { position: fixed; z-index: 790; left: 50%; top: calc(50% - 20px); width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 3px dashed var(--accent); background: rgba(29, 78, 216, .08); display: grid; place-items: center; pointer-events: none; font-size: 13px; font-weight: 600; color: var(--accent); }
#dial-guide[hidden] { display: none; }
#line-button { touch-action: none; }
#dial text.small { font-size: 14px; }
#dial .sector.behind { opacity: .5; }
#dial .letters-back { fill: rgba(0, 0, 0, .25); }

/* the line button: + opens the dial (drag) or the sheet (tap); a chip dragged out of the button removes its line */
#line-button .plus { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 2px dashed var(--muted); color: var(--muted); font-size: 20px; font-weight: 700; }
.chip.lifted { opacity: .3; }
.chip.ghost { position: fixed; z-index: 900; transform: translate(-50%, -50%) scale(1.15); box-shadow: var(--shadow); pointer-events: none; transition: opacity .1s; }
.chip.ghost.out { opacity: .6; outline: 3px solid #dc2626; outline-offset: 2px; }
.chip.ghost.out::after { content: "✕"; margin-left: 4px; }

/* a line's route, pulsing while its fixes are loading */
.route-loading { animation: route-pulse 1.2s ease-in-out infinite; }
@keyframes route-pulse { 0%, 100% { stroke-opacity: .15; } 50% { stroke-opacity: .75; } }

/* the view toggle (top left): buses and trails, or a heatmap */
#view-toggle { position: fixed; z-index: 600; left: calc(12px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); width: 44px; height: 44px; border: 0;
  border-radius: 22px; background: var(--panel); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--accent); cursor: pointer; }
#view-toggle .heat-icon, #view-toggle.on .trail-icon { display: none; }
#view-toggle.on .heat-icon { display: block; }
#view-toggle.on { box-shadow: var(--shadow), 0 0 0 2px var(--accent); }

/* green on the rail: the time whose fixes are already here for every chosen line */
#track .cached { position: absolute; left: 0; right: 0; background: #16a34a; border-radius: 6px; pointer-events: none; }
#status.nodata { background: #fef3c7; color: #78350f; }

/* the base map: the button under the view toggle, and its list of styles */
#map-style { position: fixed; z-index: 600; left: calc(12px + env(safe-area-inset-left)); top: calc(62px + env(safe-area-inset-top)); width: 44px; height: 44px; border: 0;
  border-radius: 22px; background: var(--panel); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--accent); cursor: pointer; }
#style-menu { position: fixed; z-index: 650; left: calc(62px + env(safe-area-inset-left)); top: calc(62px + env(safe-area-inset-top)); background: var(--bg); box-shadow: var(--shadow);
  border-radius: 12px; padding: 6px; display: flex; flex-direction: column; min-width: 190px; }
#style-menu[hidden] { display: none; }
#style-menu button { border: 0; background: none; text-align: left; padding: 9px 10px 9px 30px; border-radius: 8px; font-size: 14px; position: relative; cursor: pointer; }
#style-menu button[aria-checked="true"] { background: rgba(96, 165, 250, .18); font-weight: 600; }
#style-menu button[aria-checked="true"]::before { content: "✓"; position: absolute; left: 10px; color: var(--accent); }
.tiles-dimmed { filter: grayscale(1) contrast(.8) brightness(1.08); }
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.85) grayscale(.4); }
