:root {
  --bg: #ffffff; --fg: #1f2937; --muted: #6b7280; --line: #e5e7eb; --accent: #1d4ed8;
  --shadow: 0 2px 12px rgba(0, 0, 0, .15);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* the attribute must win over .controls' display */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
#map { position: absolute; inset: 0; }
#panel { position: absolute; top: 10px; left: 10px; width: 320px; max-height: calc(100% - 20px);
  overflow: auto; background: var(--bg); border-radius: 8px; box-shadow: var(--shadow); padding: 12px; }
#panel header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#panel h1 { font-size: 16px; margin: 0; }
.search { position: relative; margin: 10px 0; }
.search input, .search select { width: 100%; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; font: inherit; background: var(--bg); color: var(--fg); }
.search select { margin-top: 6px; }
#street-list { position: absolute; z-index: 2; left: 0; right: 0; margin: 2px 0 0; padding: 0;
  list-style: none; background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
#street-list li { padding: 7px 9px; cursor: pointer; }
#street-list li:hover { background: #f3f4f6; }
.controls { display: grid; gap: 6px; margin-top: 6px; }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tabs button { flex: 1; padding: 7px 6px; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; color: var(--fg); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--fg); color: #fff; border-color: var(--fg); }
.field { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 4px 8px;
  font-size: 13px; }
.field input[type=date] { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; }
.field input[type=range] { grid-column: 1 / -1; width: 100%; }
.now { padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: transparent;
  font: inherit; cursor: pointer; }
.lapse-row { display: flex; gap: 6px; } .lapse-row .now { min-width: 44px; }
.lapse-row .seg { flex: 1; }
#lapse-label { grid-column: 1 / -1; font-weight: 600; }
#legend i.dash { background: repeating-linear-gradient(90deg, #e31a1c 0 5px, transparent 5px 8px); }
.events { list-style: none; padding: 0; margin: 4px 0; font-size: 13px; }
.events li { padding: 3px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.events li.active { font-weight: 600; }
.off { color: #b91c1c; font-weight: 600; } .on-ok { color: #15803d; font-weight: 600; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; padding: 6px 4px; border: 0; background: transparent; color: var(--fg);
  font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.seg.disabled { opacity: .4; pointer-events: none; }
.toggle { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: 13px; cursor: pointer; }
#legend { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
#legend .legend-title { width: 100%; color: var(--muted); }
#legend i { display: inline-block; width: 16px; height: 6px; border-radius: 3px; margin-right: 4px;
  vertical-align: middle; }
#footer { margin-top: 10px; color: var(--muted); font-size: 12px; }
#card { position: absolute; top: 10px; right: 10px; width: 340px; max-height: calc(100% - 20px);
  overflow: auto; background: var(--bg); border-radius: 8px; box-shadow: var(--shadow);
  padding: 12px 14px; }
#card h2 { font-size: 16px; margin: 0 28px 6px 0; }
#card h3 { font-size: 13px; margin: 12px 0 4px; color: var(--muted); font-weight: 600; }
#card .close { position: absolute; top: 6px; right: 8px; border: 0; background: none;
  font-size: 22px; cursor: pointer; color: var(--muted); }
#card .big { font-size: 15px; margin: 4px 0; }
#card .muted, #card .muted-inline { color: var(--muted); }
#card p { margin: 4px 0; }
.trend-1 { color: #b91c1c; } .trend--1 { color: #15803d; } .trend-0 { color: var(--muted); }
.bars .bar { display: grid; grid-template-columns: 44px 1fr 32px; align-items: center; gap: 6px;
  font-size: 12px; }
.bars .bar i { display: block; height: 8px; background: #fd8d3c; border-radius: 4px; min-width: 1px; }
.bars .bar b { font-weight: 500; text-align: right; }
.dates { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.dates li { padding: 2px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dates .year { font-weight: 600; margin-top: 6px; }
.badge { font-size: 11px; padding: 0 6px; border-radius: 8px; background: #f3f4f6; }
.badge.street { background: #fef3c7; }
.badge.ahead { background: #dbeafe; }
#card .more { margin-top: 6px; border: 1px solid var(--line); background: none; border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font: inherit; }
.filters-toggle, .filters-done, #card .grab { display: none; }   /* phone only */

/* The splash covers the page until the first finished picture; then it fades out. */
#splash { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center;
  justify-content: center; background: var(--bg); transition: opacity .3s ease; }
#splash.done { opacity: 0; pointer-events: none; }
.splash-box { display: grid; justify-items: center; gap: 12px; padding: 24px; text-align: center;
  max-width: 320px; }
#splash-text { margin: 0; color: var(--muted); }
#splash.failed #splash-text { color: var(--fg); }
#splash.failed .spinner { display: none; }
#splash-retry { padding: 8px 18px; border: 0; border-radius: 6px; background: var(--accent);
  color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line);
  border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* A thin bar on top while a data file downloads later on (history, a month of events, …). */
#loadbar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 15; display: none;
  overflow: hidden; }
body.loading #loadbar { display: block; }
#loadbar::before { content: ""; position: absolute; top: 0; bottom: 0; width: 35%;
  background: var(--accent); animation: loadbar 1.1s ease-in-out infinite; }
@keyframes loadbar { from { left: -35%; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .spinner, #loadbar::before { animation-duration: 3s; }
}

/* Phone: a compact bar on top (tabs and language, search, a one-line filter summary that opens
   the filters), the legend as a strip on the map, the place card as a bottom sheet that opens
   at about 40 % of the screen and expands, the time-lapse as a player at the bottom. app.js
   keeps the body classes: filters-open, card-open, lapse-on. */
@media (max-width: 640px) {
  html, body { font-size: 15px; }
  #panel { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; width: auto;
    max-height: none; overflow: visible; padding: 8px; display: grid;
    grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
  #panel header { grid-column: 2; grid-row: 1; }
  #panel h1 { display: none; }
  #lang { height: 38px; font-size: 16px; }
  .tabs { grid-column: 1; grid-row: 1; margin: 0; }
  .tabs button { min-height: 38px; padding: 6px 4px; font-size: 14px; }
  .search { grid-column: 1 / -1; margin: 0; }
  /* 16 px keeps iOS from zooming the page when a field gets focus */
  .search input, .search select, .field input[type=date] { font-size: 16px; min-height: 40px; }
  #street-list { max-height: 50dvh; }
  #street-list li { padding: 11px 10px; }
  .filters-toggle { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px;
    min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
    background: #f9fafb; color: var(--fg); font: inherit; font-size: 14px; text-align: left;
    cursor: pointer; }
  #filters-summary { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .filters-toggle .chev { color: var(--muted); }
  #filters, #footer, .filters-done { grid-column: 1 / -1; }
  #filters { display: none; }
  body.filters-open #filters { display: block; }
  body.filters-open .filters-toggle .chev { transform: rotate(180deg); }
  body.filters-open #panel { max-height: calc(100dvh - 16px - env(safe-area-inset-top)
    - env(safe-area-inset-bottom)); overflow: auto; }
  #footer { display: none; margin-top: 4px; }
  body.filters-open #footer { display: block; }
  body.filters-open .filters-done { display: block; min-height: 42px; border: 0; border-radius: 6px;
    background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
  .seg button, .now { min-height: 40px; }
  .field { grid-template-columns: 70px 1fr; }
  .field input[type=range] { height: 32px; }
  .toggle { min-height: 36px; }
  .toggle input { width: 20px; height: 20px; }

  /* the legend: a strip at the bottom left of the map; hidden under an open card */
  #legend { position: fixed; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
    max-width: calc(100% - 96px); margin: 0; padding: 6px 8px; background: var(--bg);
    border-radius: 8px; box-shadow: var(--shadow); font-size: 12px; z-index: 1; }
  body.filters-open #legend, body.card-open #legend { display: none; }
  body[data-tab=status] #legend .legend-title { display: none; }   /* the summary has the moment */

  /* the time-lapse while the filters are folded: a player bar at the bottom */
  body:not(.filters-open).lapse-on #filters { display: block; }
  body:not(.filters-open).lapse-on #filters > :not(#history-controls),
  body:not(.filters-open).lapse-on #history-controls > :not(#lapse-controls),
  body:not(.filters-open).lapse-on #lstep { display: none; }
  body:not(.filters-open).lapse-on #history-controls { position: fixed; left: 8px; right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom)); margin: 0; padding: 8px 10px;
    background: var(--bg); border-radius: 8px; box-shadow: var(--shadow); z-index: 3; }
  body:not(.filters-open).lapse-on #legend .legend-title { display: none; }   /* the bar has the dates */
  body.card-open:not(.filters-open).lapse-on #history-controls { visibility: hidden; }

  /* the place card: a bottom sheet, folded to ~40 % of the screen or expanded */
  #card { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 40dvh; padding: 20px 16px calc(14px + env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0; z-index: 2; transition: max-height .2s ease; }
  #card.expanded { max-height: 88dvh; }
  body.filters-open #card { display: none; }   /* back when the filters fold */
  #card .grab { display: block; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 72px; height: 22px; padding: 0; border: 0; background: none; cursor: pointer; }
  #card .grab::before { content: ""; display: block; width: 40px; height: 5px; margin: 8px auto 0;
    border-radius: 3px; background: #d1d5db; }
  #card h2 { cursor: pointer; }
  #card .close { top: 8px; right: 10px; font-size: 26px; padding: 0 6px; }

  /* pinch zooms; the + / − buttons only take room */
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { display: none; }
}
