:root {
  --ink: #17202b;
  --muted: #586374;
  --paper: #ffffff;
  --wash: #eef1f5;
  --rule: #d6dbe3;
  --sign: #1f4fa3;        /* bleu des panneaux routiers belges */
  --sign-ink: #ffffff;
  --origin: #ffd23f;
  --font: "Atkinson Hyperlegible", system-ui, sans-serif;
  --panel-w: 360px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8ecf2; --muted: #a3adbb; --paper: #18202b; --wash: #222c39; --rule: #33404f;
    --sign: #6f9cf0; --sign-ink: #0f1620; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 var(--font); color: var(--ink); background: var(--wash); overflow: hidden; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#map, #warp { position: fixed; inset: 0; width: 100%; height: 100%; }
#warp { background: var(--wash); cursor: default; }

/* ---------------------------------------------------------------- panneau */
#panel {
  position: fixed; top: 16px; left: 16px; bottom: 16px; width: var(--panel-w);
  background: var(--paper); border-radius: 14px; box-shadow: 0 2px 4px rgba(15, 25, 40, .08), 0 12px 32px rgba(15, 25, 40, .14);
  overflow-y: auto; overscroll-behavior: contain; z-index: 5;
  padding: 20px 22px 18px;
}
#sheet-handle { display: none; }

header h1 {
  margin: 14px 0 6px; font-size: 2.05rem; line-height: 1.05; font-weight: 700; letter-spacing: -0.01em;
}
.lede { margin: 0 0 6px; color: var(--muted); font-size: .95rem; max-width: 34ch; }

#detail {
  display: inline-block; margin: 8px 0 0; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: var(--paper); border: 1.5px solid var(--rule); color: var(--muted);
}
#detail[data-scope="bruxelles"] { border-color: var(--sign); color: var(--sign); }

.block { border-top: 1px solid var(--rule); padding: 14px 0 12px; }
.block h2 { margin: 0 0 8px; font-size: .95rem; font-weight: 700; }

.search { display: flex; gap: 6px; }
.search input {
  flex: 1; min-width: 0; padding: 9px 11px; border: 1.5px solid var(--rule); border-radius: 8px; background: var(--paper);
}
.search button, #share {
  border: 1.5px solid var(--rule); background: var(--paper); border-radius: 8px; padding: 8px 10px; cursor: pointer; white-space: nowrap;
}
.search button:hover, #share:hover { border-color: var(--sign); }
#results { list-style: none; margin: 6px 0 0; padding: 0; border: 1.5px solid var(--rule); border-radius: 8px; overflow: hidden; }
#results li { padding: 8px 11px; cursor: pointer; }
#results li small { display: block; color: var(--muted); }
#results li:hover, #results li[aria-selected="true"] { background: var(--wash); }
.origin { margin: 8px 0 0; display: flex; align-items: center; gap: 8px; font-weight: 700; }
.origin::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--origin); border: 3px solid var(--ink); flex: none; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--sign); border-radius: 9px; overflow: hidden; }
.segmented button { border: 0; background: none; padding: 8px 6px; cursor: pointer; color: var(--sign); font-weight: 700; }
.segmented button + button { border-left: 1.5px solid var(--sign); }
.segmented button[aria-checked="true"] { background: var(--sign); color: var(--sign-ink); }
.segmented button:disabled { color: var(--muted); cursor: not-allowed; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; border: 1.5px solid var(--rule); border-radius: 999px;
  padding: 5px 12px 5px 8px; cursor: pointer; background: var(--paper); user-select: none;
}
.chip .dot { width: 12px; height: 12px; border-radius: 3px; background: var(--c); opacity: .35; }
.chip[aria-pressed="true"] { border-color: var(--ink); }
.chip[aria-pressed="true"] .dot { opacity: 1; }
.chip[aria-pressed="false"] { color: var(--muted); }

.big { margin: 0; font-size: 3.4rem; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.big .unit { font-size: 1.1rem; margin-left: 6px; color: var(--muted); letter-spacing: 0; }
#legs { list-style: none; padding: 0; margin: 12px 0 6px; }
#legs li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: start; padding: 5px 0; font-size: .93rem; }
#legs .ico { width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; border: 2px solid var(--muted); }
#legs .ride .ico { border-radius: 3px; border: 0; background: var(--c); }
#legs .badge { display: inline-block; min-width: 26px; padding: 0 6px; border-radius: 4px; background: var(--c); color: #fff; font-weight: 700; text-align: center; margin-right: 4px; }
#legs .min { color: var(--muted); font-variant-numeric: tabular-nums; }
.link { border: 0; background: none; padding: 0; color: var(--sign); text-decoration: underline; cursor: pointer; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }

.slider { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: .93rem; }
.slider input { flex: 1; accent-color: var(--sign); }
.iso-row { margin-top: 12px; font-size: .93rem; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pills button {
  border: 1.5px solid var(--rule); background: var(--paper); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.pills button[aria-checked="true"] { border-color: var(--sign); background: var(--sign); color: var(--sign-ink); font-weight: 700; }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: .93rem; }
.toggles input { accent-color: var(--sign); }

#legend .bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; }
#legend .bar span { flex: 1; }
#legend .ticks { position: relative; height: 20px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#legend .ticks span { white-space: nowrap; position: absolute; transform: translateX(-50%); top: 3px; }
#legend .ticks span:first-child { transform: none; }
#legend .ticks span:last-child { transform: translateX(-100%); }
#legend .none { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); margin-top: 2px; }
#legend .none i { width: 14px; height: 14px; border: 1px dashed var(--muted); border-radius: 3px; }

details summary { cursor: pointer; font-weight: 700; font-size: .95rem; }
#method { font-size: .9rem; color: var(--muted); }
#method p { margin: 8px 0; }
footer { border-top: 1px solid var(--rule); padding-top: 12px; }
#credits { font-size: .78rem; color: var(--muted); margin: 10px 0 0; }
#credits a { color: inherit; }

/* ---------------------------------------------------------------- carte */
#hover {
  position: fixed; z-index: 4; pointer-events: none; transform: translate(14px, -50%);
  background: var(--ink); color: var(--paper); border-radius: 6px; padding: 3px 8px; font-weight: 700; font-size: .95rem;
  font-variant-numeric: tabular-nums;
}
#status {
  position: fixed; z-index: 6; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 8px; font-size: .93rem;
}
.marker-origin {
  width: 26px; height: 26px; border-radius: 50%; background: var(--origin); border: 4px solid #17202b; cursor: grab;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .85);
}
.marker-dest { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 4px solid #17202b; box-shadow: 0 0 0 3px rgba(255,255,255,.85); }
.maplibregl-ctrl-attrib { font-family: var(--font); }

/* ---------------------------------------------------------------- ce que le doigt déplace */
.finger {
  position: fixed; z-index: 4; top: 16px; right: 16px; display: flex; padding: 4px; gap: 2px;
  background: var(--paper); border-radius: 999px; box-shadow: 0 2px 4px rgba(15,25,40,.08), 0 8px 24px rgba(15,25,40,.14);
}
.finger button {
  display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; cursor: pointer;
  padding: 8px 14px; border-radius: 999px; font-weight: 700; color: var(--muted);
}
.finger button[aria-checked="true"] { background: var(--sign); color: var(--sign-ink); }
.finger i { width: 12px; height: 12px; border-radius: 50%; border: 3px solid #17202b; }
.finger .dot-origin { background: var(--origin); }
.finger .dot-dest { background: #fff; }
body:has(#warp:not([hidden])) .finger { display: none; }

/* ---------------------------------------------------------------- mobile : panneau en tiroir */
/* ---------------------------------------------------------------- légende sur la carte */
#map-legend {
  position: fixed; z-index: 4; bottom: 16px; left: calc(var(--panel-w) + 40px); width: min(360px, calc(100vw - var(--panel-w) - 120px));
  background: color-mix(in srgb, var(--paper) 92%, transparent); border-radius: 12px; padding: 9px 14px 7px;
  box-shadow: 0 2px 4px rgba(15, 25, 40, .08), 0 8px 24px rgba(15, 25, 40, .14); pointer-events: none;
}
.legend-title { font-size: .8rem; font-weight: 700; margin-bottom: 5px; }
#menu-btn, #scrim { display: none; }
#base-pills { flex-wrap: wrap; }

@media (max-width: 720px) {
  /* Menu hamburger : le panneau est un tiroir qui arrive par la gauche, la carte reste plein écran. */
  #menu-btn {
    display: flex; flex-direction: column; justify-content: center; gap: 5px; align-items: center;
    position: fixed; z-index: 6; top: calc(12px + env(safe-area-inset-top)); left: 12px; width: 48px; height: 48px;
    border: 0; border-radius: 12px; background: var(--paper); cursor: pointer;
    box-shadow: 0 2px 4px rgba(15, 25, 40, .1), 0 6px 18px rgba(15, 25, 40, .18);
  }
  #menu-btn span { display: block; width: 22px; height: 3px; border-radius: 2px; background: var(--ink); }
  #scrim { display: block; position: fixed; inset: 0; z-index: 7; background: rgba(15, 25, 40, .45); }
  #panel {
    top: 0; bottom: 0; left: 0; right: auto; width: min(88vw, 380px); border-radius: 0 16px 16px 0; z-index: 8;
    padding: calc(8px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
    touch-action: pan-y; -webkit-overflow-scrolling: touch;
    transition: transform .25s ease; transform: none;
  }
  #panel.collapsed { transform: translateX(-105%); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; }
  #sheet-handle {
    display: block; margin: 0 0 0 auto; border: 1.5px solid var(--rule); background: var(--paper); border-radius: 8px;
    padding: 8px 12px; cursor: pointer; font-weight: 700;
  }
  header h1 { font-size: 1.5rem; margin: 10px 0 0; }
  .lede { display: none; }
  .finger { top: calc(12px + env(safe-area-inset-top)); right: 12px; left: 68px; justify-content: space-between; }
  .finger button { flex: 1; justify-content: center; padding: 12px 8px; }
  #map-legend { left: 12px; right: 12px; width: auto; bottom: calc(12px + env(safe-area-inset-bottom)); padding: 7px 12px 4px; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: calc(92px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.cap-row {
  display: grid; grid-template-columns: 36px 1fr auto; grid-template-areas: "l l v" "m r p"; align-items: center; gap: 6px 8px; margin: 14px 0 4px;
}
.cap-row #h-cap { grid-area: l; font-weight: 700; }
.cap-row output { grid-area: v; white-space: nowrap; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.cap-row #cap-minus { grid-area: m; } .cap-row #cap-plus { grid-area: p; justify-self: end; } .cap-row input { grid-area: r; min-width: 0; width: 100%; }
.cap-row button { width: 36px; height: 36px; border: 1.5px solid var(--sign); background: var(--paper); color: var(--sign); border-radius: 8px; font-size: 1.3rem; line-height: 1; cursor: pointer; font-weight: 700; }
.cap-row button:disabled { opacity: .35; cursor: not-allowed; }
