:root {
  --topbar-h: 3.4rem;
  --timebar-h: 3rem;
  --app-height: 100svh;
  --app-max-w: 1280px;
  --app-pad: 1.5rem;

  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --map-bg: #c6c1b5;
  --line: #d9d7d0;
  --line-strong: #c4c1b8;
  --ink: #16171a;
  --muted: #6b6f76;
  --accent: #d0021b;
  --accent-soft: rgba(208, 2, 27, 0.1);
  --water: #cfe1ef;
  --water-stroke: #a7c6df;
  --shadow: 0 18px 50px rgba(20, 22, 28, 0.14);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

/* the [hidden] attribute must win over component display rules */
[hidden] { display: none !important; }

body {
  margin: 0;
  height: var(--app-height);
  overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, Arial, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input { font: inherit; }

/* ── shell ── */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: var(--app-height);
}

/* ── canvas panel ── */
.canvas-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  grid-column: 1;
  grid-row: 1;
}

/* ── top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  height: var(--topbar-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: relative;
  z-index: 10;
}

/* ── icon button ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 140ms ease;
}

.icon-btn svg { width: 1rem; height: 1rem; }

.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
  outline: none;
}

/* ── dataset selector ── */
.ds-selector {
  flex: 1;
  min-width: 0;
  max-width: 30rem;
  position: relative;
}

/* ── custom searchable dropdown ── */
.ds-dropdown { position: relative; width: 100%; }

.ds-dropdown__trigger { position: relative; display: flex; align-items: center; }

.ds-dropdown__input {
  width: 100%;
  padding: 0.5rem 3.2rem 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/* Always-visible count badge: signals that the field is a picker holding
   many datasets, not just a static title. */
.ds-dropdown__count {
  position: absolute;
  left: 0.45rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 1.5rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}
.ds-dropdown__count svg { width: 0.8rem; height: 0.8rem; }
.ds-dropdown__count[hidden] { display: none; }
.ds-dropdown__trigger.has-count .ds-dropdown__input { padding-left: 4rem; }

.ds-dropdown__hint {
  position: sticky;
  top: 0;
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.ds-dropdown__input::placeholder { color: var(--muted); }
.ds-dropdown__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  cursor: text;
}
.ds-dropdown__input:disabled { opacity: 0.5; cursor: default; }

.ds-dropdown__arrow {
  position: absolute;
  right: 0.65rem;
  width: 1rem;
  height: 1rem;
  color: var(--muted);
  pointer-events: none;
  transition: transform 180ms ease;
  flex-shrink: 0;
}

.ds-dropdown.is-open .ds-dropdown__arrow { transform: rotate(180deg); }

.ds-dropdown__clear {
  position: absolute;
  right: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.ds-dropdown__clear svg { width: 0.8rem; height: 0.8rem; }

.ds-dropdown__clear:hover,
.ds-dropdown__clear:focus-visible {
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
}

.ds-dropdown__clear[hidden] { display: none; }

.ds-dropdown__panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  z-index: 100;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  max-height: 16rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.ds-dropdown__list {
  list-style: none;
  margin: 0;
  padding: 0.3rem;
}

.ds-dropdown__option {
  padding: 0.5rem 0.75rem;
  border-radius: 5px;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  line-height: 1.3;
}

.ds-dropdown__option:hover,
.ds-dropdown__option.is-focused {
  background: var(--accent-soft);
  color: var(--accent);
}

.ds-dropdown__option.is-selected { color: var(--accent); font-weight: 600; }

.ds-dropdown__empty {
  padding: 0.75rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── level toggle ── */
.level-toggle {
  display: inline-flex;
  flex-shrink: 0;
  padding: 0.18rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.seg-btn {
  padding: 0.3rem 0.7rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 140ms ease, color 140ms ease;
}

.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ── selected dataset caption (full name, since the picker truncates) ── */
.map-caption {
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  line-height: 1.3;
}
.map-caption[hidden] { display: none; }
.map-caption__label {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}
.map-caption strong {
  min-width: 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
}
.map-caption__time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.map-caption__time:not(:empty)::before { content: "· "; }

/* ── map frame ── */
.canvas-frame {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--map-bg);
}

#heatmap { width: 100%; height: 100%; display: block; }

/* ── empty state ── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--line-strong);
  pointer-events: none;
  transition: opacity 200ms ease;
}

.empty-state svg { width: 3.5rem; height: 3.5rem; }
.empty-state p { margin: 0; font-size: 0.9rem; text-align: center; color: var(--muted); }
.empty-state.is-hidden { opacity: 0; }

/* ── loading overlay ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 160ms ease;
  pointer-events: none;
}

.loading-overlay.is-visible { opacity: 1; visibility: visible; pointer-events: auto; }

.loading-overlay__panel {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.loading-overlay__spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── tooltip ── */
.tooltip {
  position: absolute;
  z-index: 20;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.83rem;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  max-width: 13rem;
}

.tooltip strong { color: var(--ink); font-size: 0.88rem; }
.tooltip span { color: var(--muted); }

/* ── mini legend ── */
.mini-legend {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  z-index: 8;
  display: grid;
  gap: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(20, 22, 28, 0.08);
  width: auto;
  min-width: 9rem;
  max-width: 15rem;
}

.mini-legend__bar {
  height: 0.45rem;
  border-radius: 2px;
  background: linear-gradient(to right,
    rgb(255, 245, 240), rgb(252, 174, 145),
    rgb(251, 106, 74), rgb(203, 24, 29), rgb(103, 0, 13)
  );
}

.mini-legend__labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
}

.mini-legend__measure {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--ink);
  font-weight: 600;
}
.mini-legend__measure:empty { display: none; }

/* ── map footer: source credit + brand watermark, bottom-right ── */
.map-footer {
  position: absolute;
  bottom: clamp(0.75rem, 2vw, 1.1rem);
  right: clamp(0.75rem, 2vw, 1.1rem);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.map-credit {
  max-width: 9.5rem;
  text-align: right;
  padding: 0.22rem 0.5rem;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.25;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(20, 22, 28, 0.08);
  transition: color 140ms ease;
}
.map-credit:hover, .map-credit:focus-visible {
  color: var(--accent);
  outline: none;
}

/* ── brand watermark (replaces the old home button) — shared malte.wintner.ch mark ── */
.site-logo {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.4rem;
  height: 3.4rem;
  opacity: 1;
  text-decoration: none;
  transition: filter 180ms ease, transform 180ms ease;
}
.site-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.28))
          drop-shadow(0 0 10px rgba(212, 160, 60, 0.55))
          saturate(1.25) brightness(1.08);
}
.site-logo:hover, .site-logo:focus-visible {
  transform: translateY(-1px);
  outline: none;
}
.site-logo:hover img, .site-logo:focus-visible img {
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.28))
          drop-shadow(0 0 16px rgba(212, 160, 60, 0.8))
          saturate(1.35) brightness(1.14);
}
.site-logo:active { transform: translateY(0) scale(0.96); }

/* ── time bar ── */
.time-bar {
  display: flex;
  align-items: center;
  height: var(--timebar-h);
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.time-nav {
  flex-shrink: 0;
  width: 2.2rem;
  height: 100%;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.time-nav:last-child { border-right: 0; border-left: 1px solid var(--line); }
.time-nav:hover { background: var(--accent-soft); color: var(--accent); }
.time-nav:disabled { opacity: 0.3; cursor: default; }

.time-pills {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.6rem;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
}

.time-pills::-webkit-scrollbar { display: none; }

.time-pill {
  flex-shrink: 0;
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.time-pill:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }

.time-pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── SVG map paths ── */
/* Each Kreis/Quartier is one merged fill — no internal statzone seams. */
.zone-fill { stroke: none; cursor: pointer; }

/* Highlight outline sits under the fill, so the fill masks its inner half and
   every internal seam; only a crisp outer boundary shows on hover/selection. */
.zone-outline {
  fill: none;
  stroke: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

[data-key].is-hovered .zone-outline { stroke: var(--ink); }
[data-key].is-selected .zone-outline { stroke: var(--ink); stroke-width: 3; }

/* keyboard focus: outline lives on the under-fill stroke, not the <g> */
[data-key] { outline: none; }
[data-key]:focus-visible .zone-outline { stroke: var(--accent); stroke-width: 3.5; }

/* ── water (lake) ── */
.water-layer { pointer-events: none; }
.water-path {
  fill: var(--water);
  stroke: var(--water-stroke);
  stroke-width: 1;
  stroke-linejoin: round;
}
.water-label {
  fill: #5f7b92;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  font-style: italic;
  letter-spacing: 1.5px;
}

/* keep the toggles flush right once the selector stops growing */
.topbar #levelToggle { margin-left: auto; }

/* ── desktop: constrain width, center as a floating card ── */
@media (min-width: 1280px) {
  body { padding: var(--app-pad); }

  .shell {
    max-width: var(--app-max-w);
    height: 100%;
    margin-inline: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

/* ── respect users who ask for less motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
