/* Hopper Reach — map-first design (operator-owned).
   Palette: bus red, blind black with LED amber, frog green; colour-blind-safe reach dots.
   Type: Archivo (condensed, signage) for display, Atkinson Hyperlegible Next for text, its Mono for times.
   Dark colours apply only on touch devices (phones, tablets); desktops always stay light. */

@font-face { font-family: "Archivo"; src: url("vendor/fonts/archivo.woff2") format("woff2");
             font-weight: 400 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("vendor/fonts/atkinson-next.woff2") format("woff2");
             font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Mono"; src: url("vendor/fonts/atkinson-mono.woff2") format("woff2");
             font-weight: 200 800; font-display: swap; }

:root {
    --display: "Archivo", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
    --body: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
    --mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --bus: #DA1F26; --on-bus: #FFFFFF;
    --frog: #2E9E4F; --frog-deep: #1E7B34; --frog-tint: #E3F2E6;
    --text: #1B1F26; --muted: #5B6270; --line: #DDE1D9;
    --surface: #FFFFFF; --surface-2: #F3F5F0; --ground: #ECEEE7;
    --blind: #15181E; --blind-text: #FFC940;
    --shadow: 0 1px 2px rgba(21, 24, 30, .08), 0 10px 30px rgba(21, 24, 30, .16);
    --shadow-sm: 0 1px 2px rgba(21, 24, 30, .10), 0 3px 10px rgba(21, 24, 30, .10);
    --tiles: saturate(.55) brightness(1.04) contrast(.94);
    --ok: #1E6B30; --ok-bg: #E3F3E7; --warn: #7A4B00; --warn-bg: #FFF1CC; --bad: #A11B1B; --bad-bg: #FDE7E7;
    --focus: #15181E;
    --top-h: 118px;
    --sheet-h: 46%;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) and (hover: none) and (pointer: coarse) {
    :root {
        --bus: #E23A43;
        --frog: #4CC06C; --frog-deep: #7FD99A; --frog-tint: #16301F;
        --text: #E9ECEF; --muted: #9AA3AF; --line: #2A3039;
        --surface: #171B21; --surface-2: #1F242C; --ground: #101318;
        --blind: #060709;
        --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .55);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5), 0 3px 10px rgba(0, 0, 0, .4);
        --tiles: invert(1) hue-rotate(180deg) brightness(.92) saturate(.4) contrast(.88);
        --ok: #86DCA0; --ok-bg: #12301C; --warn: #FFCF70; --warn-bg: #3A2B08; --bad: #FF9C9C; --bad-bg: #3A1212;
        --focus: #FFFFFF;
        color-scheme: dark;
    }
}

/* Base */
html { font-size: 100%; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--ground); color: var(--text);
       font-family: var(--body); font-size: 1rem; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; min-height: 44px; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.hint { font-size: 0.875rem; color: var(--muted); }
h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); }

/* App shell: the map fills the window; search floats on top; results sit in a sheet or side panel */
#app { position: fixed; inset: 0; overflow: hidden; }
#map-column { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; height: 100%; background: var(--ground); }
.leaflet-container { font-family: var(--body); }
.leaflet-tile-pane { filter: var(--tiles); }
.leaflet-control-attribution { font-size: 11px; }
.leaflet-bottom.leaflet-right { bottom: var(--sheet-h); transition: bottom .3s; }
.leaflet-top.leaflet-left { top: calc(var(--top-h) + 64px); }
@media (hover: none) { .leaflet-control-zoom { display: none; } }

#topbar { position: absolute; z-index: 1001; top: calc(env(safe-area-inset-top, 0px) + 12px); left: 12px; right: 12px;
          display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
#search-form, .options { display: contents; }
.searchbar { box-sizing: border-box; flex: 1 0 100%; display: flex; align-items: center; gap: 6px; height: 56px; padding: 0 6px 0 8px;
             background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); }
.searchbar img { width: 40px; height: 40px; flex: none; }
.searchbar:focus-within { box-shadow: var(--shadow), 0 0 0 2.5px var(--focus); }
.place-field { flex: 1; min-width: 0; }
.place-field label, .chip-field .hint { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#place-input { width: 100%; height: 44px; border: 0; background: none; font-weight: 700; font-size: 17px; outline: none; }
#place-input::placeholder { color: var(--muted); font-weight: 400; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; flex: none; padding: 0; border: 0; border-radius: 50%; background: var(--surface-2); }
.icon-button:hover { background: var(--line); }
.icon-button.primary { background: var(--bus); color: var(--on-bus); }

.chip-field, #filters-box > summary {
    flex-direction: row; align-items: center; gap: 6px; height: 40px; padding: 0 4px 0 14px;
    background: var(--surface); border-radius: 999px; box-shadow: var(--shadow-sm); font-size: 14px; }
.chip-field label { color: var(--muted); font-weight: 600; white-space: nowrap; }
.chip-field select, .chip-field input { field-sizing: content; min-height: 36px; border: 0; background: none; font-weight: 700; padding: 0 6px; outline: none; max-width: 11rem; }
.chip-field:focus-within { box-shadow: var(--shadow-sm), 0 0 0 2.5px var(--focus); }
#filters-box { position: relative; }
#filters-box > summary { display: flex; min-height: 40px; padding: 0 14px; font-weight: 700; cursor: pointer; list-style: none; }
#filters-box > summary::-webkit-details-marker { display: none; }
#filters-box[open] > summary { background: var(--text); color: var(--surface); }
#filters { box-sizing: border-box; position: absolute; top: 48px; left: 0; width: min(360px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto;
           display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; background: var(--surface);
           border-radius: 18px; box-shadow: var(--shadow); }
#filters label { font-weight: 700; font-size: 14px; }
#filters select { border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); padding: 0 8px; }
#filters .hint { font-size: 12.5px; }

/* Results sheet (phones) */
#panel { box-sizing: border-box; position: absolute; z-index: 1000; left: 0; right: 0; bottom: 0; height: var(--sheet-h); overflow-y: auto; overscroll-behavior: contain;
         background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: 0 -8px 30px rgba(21, 24, 30, .18);
         transition: height .35s cubic-bezier(.2, .8, .2, 1); padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 24px); }
#app[data-sheet="peek"] { --sheet-h: 150px; }
#app[data-sheet="full"] { --sheet-h: calc(100% - var(--top-h) - 20px); }
#app.dragging #panel { transition: none; }
#sheet-handle { position: sticky; top: 0; z-index: 2; display: grid; place-items: center; width: calc(100% + 32px); height: 28px; min-height: 28px;
                margin: 0 -16px; padding: 0; border: 0; background: var(--surface); cursor: grab; touch-action: none; }
#sheet-handle::before { content: ""; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }

/* Floating map furniture */
.map-status { position: absolute; z-index: 999; top: calc(var(--top-h) + 22px); right: 12px; display: flex; align-items: center; gap: 8px;
              padding: 6px 12px 6px 8px; background: var(--surface); color: var(--text); border-radius: 999px; box-shadow: var(--shadow-sm);
              font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.map-status::before { content: ""; width: 18px; height: 18px; border-radius: 50%; flex: none;
                      background: conic-gradient(var(--bus) calc(var(--progress, 1) * 360deg), var(--line) 0);
                      -webkit-mask: radial-gradient(circle, transparent 5px, #000 5.5px); mask: radial-gradient(circle, transparent 5px, #000 5.5px); }
.map-status[hidden] { display: none; }
.map-legend { box-sizing: border-box; position: absolute; z-index: 999; left: 12px; bottom: calc(var(--sheet-h) + 12px); max-width: calc(100% - 24px);
              display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 0; padding: 7px 12px; list-style: none;
              background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-sm); font-size: 12px; font-weight: 600; color: var(--muted);
              transition: bottom .35s cubic-bezier(.2, .8, .2, 1); }
.map-legend li { display: inline-flex; align-items: center; }
.map-tools { position: absolute; z-index: 999; right: 12px; top: calc(var(--top-h) + 64px); max-width: 60%; text-align: right;
             transition: bottom .35s cubic-bezier(.2, .8, .2, 1); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px 0 10px; background: var(--surface);
          border-radius: 999px; box-shadow: var(--shadow-sm); font-size: 13px; font-weight: 700; cursor: pointer; }
.toggle input { min-height: 0; width: 18px; height: 18px; accent-color: var(--frog); }
#rings-note:empty { display: none; }
#rings-note { margin: 6px 0 0; padding: 6px 10px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-sm); font-size: 12px; }

/* Tablet and desktop: a floating side panel */
@media (min-width: 48rem) {
    #topbar { left: 16px; top: 16px; right: auto; width: 400px; }
    #panel { left: 16px; right: auto; top: calc(var(--top-h) + 28px); bottom: 16px; width: 400px; height: auto; border-radius: 22px; box-shadow: var(--shadow); padding-top: 16px; }
    #sheet-handle { display: none; }
    #app, #app[data-sheet] { --sheet-h: 0px; }
    .leaflet-bottom.leaflet-right { bottom: 0; }
    .leaflet-top.leaflet-left { top: 0; left: 432px; }
    .map-legend { left: 432px; bottom: 16px; max-width: calc(100% - 640px); }
    .map-tools { top: auto; bottom: 16px; }
    .map-status { top: 16px; right: 16px; }
}
@media (max-width: 400px) {
    .chip-field, #filters-box > summary { font-size: 13px; padding-left: 12px; }
    .chip-field select { max-width: 7.5rem; }
}

/* Colour keys */
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.c0 { background: #009E73; }
.c1 { background: #0072B2; }
.c2 { background: #E69F00; }
.c3 { background: #D55E00; }
.t0 { background: #440154; }
.t1 { background: #3B528B; }
.t2 { background: #21918C; }
.t3 { background: #5EC962; }
.t4 { background: #FDE725; }

/* Bus tags on the map */
.bus-marker { background: none; border: 0; }
.bus-tag { background: #DA1F26; color: #fff; border: 2px solid #fff; border-radius: 7px; padding: 0 5px 0 6px; display: inline-flex; align-items: center; gap: 3px;
           font: 800 12px/18px var(--display); font-stretch: 85%; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); }
.bus-arrow { display: inline-block; font-size: 11px; }

/* Panel contents */
#intro h1 { margin: 6px 0 8px; font-family: var(--display); font-weight: 900; font-stretch: 72%; line-height: 1; letter-spacing: -0.005em; text-wrap: balance; }
#intro p { margin: 0 0 12px; color: var(--muted); }
#intro[hidden] { display: none; }
#status { margin: 4px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: .02em; color: var(--muted); }
#status:empty { display: none; }
#choices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
#choices[hidden] { display: none; }
#choices button { border: 2px solid var(--frog); border-radius: 999px; padding: 0.4rem 1rem; min-height: 44px; background: var(--surface); color: var(--frog-deep); font-weight: 700; }
.eyebrow { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }

/* Reach dots fade while a trip is on the map */
.leaflet-reach-pane { transition: opacity .3s ease; }
.leaflet-reach-pane.faded { opacity: .3; }

/* "Reaches" line: a few area names, each a quiet link to its trip */
#reach[hidden] { display: none; }
.headline { margin: 4px 0 10px; font: 900 30px/1 var(--display); font-stretch: 72%; text-wrap: balance; }
.areas { margin: -4px 0 12px; font-size: 15px; line-height: 1.6; color: var(--muted); }
.areas-label { margin-right: 6px; }
.areas .sep { margin: 0 6px; }
.areas .area { border: 0; padding: 0; background: none; font: inherit; font-weight: 700; color: var(--text); cursor: pointer;
    text-decoration: underline; text-decoration-color: var(--line); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.areas .area:hover { text-decoration-color: var(--frog); }

/* Destination blind: route number beside an LED destination */
.blind { display: inline-flex; align-items: stretch; max-width: 100%; border-radius: 8px; overflow: hidden; background: var(--blind); vertical-align: middle; }
.blind .rt { display: grid; place-items: center; min-width: 44px; padding: 0 8px; background: var(--bus); color: #fff; font: 900 19px/1 var(--display); font-stretch: 78%; }
.blind.tram .rt { background: #5FB526; }
.blind .dest { padding: 7px 12px 6px; color: var(--blind-text); font: 700 16px/1.1 var(--display); font-stretch: 70%; letter-spacing: .02em;
               background-image: radial-gradient(rgba(255, 255, 255, .07) .9px, transparent 1.2px); background-size: 3px 3px;
               text-shadow: 0 0 6px rgba(255, 201, 64, .45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Hop-on routes */
#results > p { font-size: 13.5px; color: var(--muted); }
#results ol { list-style: none; margin: 0; padding: 0; }
#results button { display: block; width: 100%; margin: 2px 0; text-align: left; min-height: 44px; border: 0; border-radius: 10px; background: none; padding: 8px 6px; }
#results button:hover { background: var(--surface-2); }
.route-group { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.route-group[open] { border-color: transparent; box-shadow: var(--shadow-sm); }
.route-group summary { position: relative; padding-right: 40px !important; cursor: pointer; min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px; font-weight: 600; list-style: none; border-radius: 16px; }
.route-group summary::-webkit-details-marker { display: none; }
.route-group summary::after { content: ""; position: absolute; right: 18px; top: 20px; width: 9px; height: 9px; border-right: 2.5px solid var(--muted); border-bottom: 2.5px solid var(--muted); transform: rotate(45deg); transition: transform .2s; }
.route-group[open] summary::after { transform: rotate(225deg); }
.route-from { flex-basis: 100%; font-size: 13.5px; font-weight: 400; color: var(--muted); }
.route-from b { color: var(--text); }
.route-group ol { padding: 0 8px 8px !important; }
.route-group li + li { border-top: 1px solid var(--line); }
.place { display: grid !important; grid-template-columns: 12px 1fr; align-items: center; gap: 0 10px; }
.place .dot { grid-row: span 2; width: 10px; height: 10px; border-radius: 50%; }
.place .name { font-weight: 700; }
.place .sep { display: none; }
.place .meta { grid-column: 2; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Trip */
#detail:empty { display: none; }
#detail { margin-bottom: 16px; }
#detail > h2 { margin: 2px 0 6px; font: 900 36px/1 var(--display); font-stretch: 72%; text-wrap: balance; outline: none; }
#detail > h2 + p { margin: 0 0 12px; font-weight: 700; color: var(--muted); }
#detail > button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 50px; margin-top: 8px; border: 0; border-radius: 14px; background: var(--text); color: var(--surface); font-weight: 700; }
.live, .buses, .bus-refresh, .live-leg { font-size: 13.5px; color: var(--muted); }
.live-check { font-weight: 700; padding: 9px 12px; border-radius: 12px; }
.live-check.on_track { color: var(--ok); background-color: var(--ok-bg); }
.live-check.at_risk { color: var(--warn); background-color: var(--warn-bg); }
.live-check.missed { color: var(--bad); background-color: var(--bad-bg); }
.notice { color: var(--warn); background-color: var(--warn-bg); border-left: 4px solid #E69F00; padding: 0.4rem 0.6rem; border-radius: 6px; }
.hour ~ .deadline { display: none; }
.deadline { padding: 10px 12px; border-radius: 12px; background: var(--frog-tint); color: var(--frog-deep); font-weight: 700; }

/* Hopper hour */
.hour { padding: 14px; border-radius: 18px; background: var(--frog-tint); margin: 0 0 18px; }
.hour-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hour-head h3 { margin: 0; font: 800 17px var(--display); font-stretch: 85%; color: var(--frog-deep); }
.hour-head span { font-family: var(--mono); font-weight: 600; font-size: 13px; color: var(--frog-deep); }
.hour-bar { position: relative; height: 14px; margin: 34px 0 8px; border-radius: 7px; background: var(--surface); }
.hour-bar .hseg { position: absolute; top: 0; bottom: 0; border-radius: 7px; }
.hour-bar .hseg.ride { background: var(--bus); }
.hour-bar .hseg.wait { background: repeating-linear-gradient(135deg, var(--muted) 0 3px, transparent 3px 6px); opacity: .6; }
.hour-bar .hseg.after { opacity: .35; }
.hour-bar .frogmark { position: absolute; bottom: 10px; width: 34px; height: 30px; transform: translateX(-50%); animation: hop 2.6s ease-in-out infinite; }
@keyframes hop { 0%, 70%, 100% { transform: translate(-50%, 0); } 78% { transform: translate(-50%, -7px); } 86% { transform: translate(-50%, 0); } }
.hour-bar .end { position: absolute; right: -2px; top: -6px; bottom: -6px; width: 3px; border-radius: 2px; background: var(--frog-deep); }
.hour-scale { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.hour p { margin: 10px 0 0; font-size: 14px; }

/* Timeline */
.timeline { list-style: none; margin: 0 0 12px; padding: 0; }
.timeline li { margin: 0; }
.timeline p { margin: 2px 0 4px; }
.timeline details summary { cursor: pointer; font-weight: 700; min-height: 36px; display: flex; align-items: center; }
.timeline details ol { margin: 0 0 6px; padding-left: 18px; color: var(--muted); font-size: 14px; }
.timeline .stops li:last-child { color: var(--text); font-weight: 700; }
.step { position: relative; display: grid; grid-template-columns: 50px 26px 1fr; column-gap: 8px; }
.step time { padding-top: 2px; font-family: var(--mono); font-weight: 600; font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.step .rail { position: relative; display: flex; justify-content: center; }
.step .rail::before { content: ""; position: absolute; top: 14px; bottom: -2px; width: 0; border-left: 3px dotted var(--muted); }
.step.ride .rail::before { top: 10px; bottom: 0; width: 6px; border: 0; border-radius: 3px; background: var(--bus); }
.step.end .rail::before { display: none; }
.step .node { position: relative; z-index: 1; width: 14px; height: 14px; margin-top: 4px; border-radius: 50%; background: var(--surface); border: 3px solid var(--muted); }
.step.ride .node { width: 18px; height: 18px; margin-top: 2px; border: 4px solid var(--bus); }
.step.end .node { border-radius: 4px; border-color: var(--blind); background: var(--blind); }
.step .body { min-width: 0; padding-bottom: 18px; }
.step h4 { margin: 0 0 2px; font-size: 15.5px; }
.step .sub { margin: 0; color: var(--muted); font-size: 14px; }
.step .blind { margin: 6px 0 6px; }
.miss { margin: 8px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 13.5px; }

/* About and credits */
#about { margin: 16px 0 8px; font-size: 14px; }
#about summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
footer { font-size: 12px; color: var(--muted); }
footer p { margin: 2px 0; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
