/* System font like on iOS; white surface; Moor, Rinde and Laub from the palette of the pollen clock */
:root {
  --surface: #ffffff;
  --soft: #f1f2f0;
  --text: #1e2a22; /* Moor, 14.8:1 on white */
  --text-2: #5e5c51; /* Rinde, 6.7:1 */
  --text-3: #625f54; /* 5.7:1 on --soft */
  --rule: #dfe2dd;
  --empty: #e6e8e4;
  --leaf: #3f6b4e; /* Laub, 6.1:1 */
  --error: #b42318;
  --focus: #1d6fe8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 28px rgba(0, 0, 0, 0.12);
  --shadow-small: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 14px rgba(0, 0, 0, 0.12);
  /* Frosted glass for small controls floating over the map; the panel stays solid
     because it carries coloured meters and long text */
  --glass: rgba(255, 255, 255, 0.78);
  --glass-edge: rgba(255, 255, 255, 0.6);
  --glass-blur: blur(20px) saturate(180%);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  --fill: rgba(30, 42, 34, 0.07); /* quiet filled surface for chips and buttons, like iOS */
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-optical-sizing: auto;
  color: var(--text);
  background: var(--surface);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
button, summary, .option { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* Press feedback on pointer-down, instant and small */
.chip, .btn, .locate { position: relative; transition: transform 100ms ease-out; }
.chip:active, .btn:active, .locate:active { transform: scale(0.97); }
a { color: inherit; text-underline-offset: 2px; }
::selection { background: rgba(63, 107, 78, 0.22); color: var(--text); }
input { caret-color: var(--leaf); }
/* Counts and meters line up digit for digit */
.days, .around-text b, .spot-summary b, .clock .face-day { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

#map { position: fixed; inset: 0; }

/* Panel: floating card on desktop, bottom sheet on phones */

.panel {
  position: fixed;
  z-index: 2;
  top: 16px;
  left: 16px;
  width: 400px;
  max-height: calc(100% - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 42, 34, 0.22) transparent;
}
.panel > section { padding: 16px 20px; border-top: 1px solid var(--rule); }

/* Liquid glass: the panel floats over the map as a thick, frosted layer with a lit rim.
   Opaque enough (about 80 %) that text keeps its contrast over the colourful map. */
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel {
    background:
      linear-gradient(165deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 38%),
      rgba(255, 255, 255, 0.84);
    -webkit-backdrop-filter: blur(30px) saturate(175%);
    backdrop-filter: blur(30px) saturate(175%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.9),
      inset 0 0 0 1px rgba(255, 255, 255, 0.45),
      inset 0 -1px 0 rgba(30, 42, 34, 0.06),
      0 1px 2px rgba(20, 30, 24, 0.08),
      0 24px 60px rgba(20, 30, 24, 0.24);
  }
  .panel > section { border-top-color: rgba(30, 42, 34, 0.1); }
  /* Controls inside the glass are tinted, not another layer of glass */
  .search-input { background-color: rgba(30, 42, 34, 0.07); }
  
}
.grip { display: none; }

/* Hero: the pollen clock with today's reading beside it */
/* The hero shares the sections' 20 px content edge; only the dial row is indented, to make room
   for the "Okt" label left of the clock */
.hero { padding: 28px 20px 16px; }
.hero-main { padding-left: 14px; display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 22px; align-items: center; }
.hero-copy { min-width: 0; container-type: inline-size; }
.dial { position: relative; width: 120px; aspect-ratio: 1; }
.clock { display: block; width: 100%; height: 100%; overflow: visible; }
.clock .track { stroke: var(--empty); }
.clock .tick { stroke: var(--text-3); stroke-width: 1; }
.clock .face-day { font: 600 32px var(--display); letter-spacing: -0.02em; text-anchor: middle; fill: var(--text); }
.clock .face-month { font: 500 12px var(--font); text-anchor: middle; fill: var(--text-2); }
.clock .hand { transform: rotate(var(--angle)); transition: transform 1200ms cubic-bezier(0.2, 0.7, 0.2, 1); }
.clock .hand.from-jan { transform: rotate(0deg); transition: none; }
.clock .hand path { stroke: var(--leaf); stroke-width: 2.4; stroke-linecap: round; }
.clock .hand circle, .clock .hub { fill: var(--leaf); }
.q { position: absolute; font-size: 11px; line-height: 1; color: var(--text-3); }
.q-jan { top: -14px; left: 50%; transform: translateX(-50%); }
.q-jul { bottom: -14px; left: 50%; transform: translateX(-50%); }
.q-okt { left: -24px; top: 50%; transform: translateY(-50%); }
.q-apr { right: -21px; top: 50%; transform: translateY(-50%); }
/* The title shrinks with its column so "Pollenpause" fits on one line; at large zoom levels
   long words hyphenate instead of pushing the panel sideways */
h1 { font-family: var(--display); font-size: min(34px, 14.5cqi); font-weight: 700; letter-spacing: -0.03em; line-height: 1.08; hyphens: auto; overflow-wrap: break-word; }
.level { margin-top: 4px; font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.25; color: var(--leaf); }
.hero-text { margin-top: 10px; font-size: 15px; letter-spacing: -0.006em; color: var(--text-2); }
.also { margin-top: 6px; font-size: 14px; color: var(--text-3); }
.spot-summary { display: none; }
h2 { font-family: var(--display); font-size: 20px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin-bottom: 14px; }

.meter { display: flex; gap: 3px; }
.meter i { flex: 1; height: 6px; border-radius: 3px; background: var(--empty); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 28px; }
.chips-label { flex-basis: 100%; font-size: 13px; font-weight: 500; color: var(--text-3); }
.chips-label + .chip, .chip + .chips-label { margin-top: 2px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 0;
  background: var(--fill);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); }
.chip[aria-pressed="true"] .shape path { fill: var(--surface); }
.shape { flex: none; }

/* Cells align at the top so every meter in a row sits on one line, even when a label wraps;
   the genus name is lifted to centre on the meters */
.days { display: grid; grid-template-columns: 96px repeat(3, 1fr); gap: 10px 10px; align-items: start; font-size: 14px; }
.days .head { font-family: var(--font); font-weight: 500; font-size: 14px; color: var(--text-3); }
.days .gen { display: flex; align-items: center; gap: 6px; margin-top: -6.5px; font-family: var(--font); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; line-height: 20px; }
.days small { display: block; margin-top: 4px; font-size: 12px; line-height: 1.25; color: var(--text-2); }

.meta { margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--text-3); }
.hint { font-size: 15px; color: var(--text-2); }
.error { font-size: 13px; color: var(--error); margin-bottom: 8px; }
/* Text button inside running text (retry, remove spot): underlined like a link, in the colour around it */
.text-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.retry-btn { margin-top: 10px; }

.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 999px; border: 0; background: var(--fill); font-family: var(--font); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; cursor: pointer; }
.btn.primary { background: var(--text); color: var(--surface); }
.icon { width: 14px; height: 14px; flex: none; fill: currentColor; }
.around-text { font-size: 15px; line-height: 1.65; color: var(--text-2); }
.around-text b { color: var(--text); font-weight: 650; }
.clear-spot { margin-top: 8px; font-size: 14px; color: var(--text-2); }
.tally { white-space: nowrap; }
.tally .shape { vertical-align: -2px; margin-right: 3px; }

.panel details summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; margin: -14px 0; padding: 14px 0; }
.panel details summary::-webkit-details-marker { display: none; }
.panel details summary h2 { margin: 0; }
.panel details summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg) translate(-2px, -2px); transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1); }
.panel details[open] summary::after { transform: rotate(225deg) translate(-2px, -2px); }

.about { margin-top: 14px; font-size: 14px; color: var(--text-2); display: grid; gap: 10px; }
.about ul { padding-left: 18px; display: grid; gap: 4px; }

/* Address search */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.search { position: relative; padding: 16px 20px 0; }
.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 0;
  border-radius: 12px;
  background: var(--fill) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23625f54' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='6.8' cy='6.8' r='4.8'/%3E%3Cpath d='m10.4 10.4 3.6 3.6'/%3E%3C/svg%3E") no-repeat 13px 50% / 16px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { outline: 2px solid var(--focus); outline-offset: 0; background-color: var(--surface); }
.search-results {
  position: absolute;
  z-index: 5;
  left: 20px;
  right: 20px;
  top: calc(100% + 4px);
  max-height: 50vh;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.search-results .option { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; font-size: 14px; cursor: pointer; }
.search-results .option small { color: var(--text-3); font-size: 12px; }
.search-results .option:hover, .search-results .option[aria-selected="true"] { background: var(--fill); }
.search-results .message { padding: 10px 14px; font-size: 14px; color: var(--text-2); }

/* Map overlays */

.locate {
  position: fixed;
  z-index: 2;
  top: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-small);
  cursor: pointer;
}

.density {
  position: fixed;
  z-index: 2;
  right: 56px; /* clear of the zoom buttons */
  bottom: 24px;
  width: 210px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-small);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  transition: opacity 0.2s;
}
.density strong { display: block; margin-bottom: 6px; font-family: var(--font); font-size: 14px; font-weight: 600; color: var(--text); }
.density.is-hidden, .density.no-trees { opacity: 0; }
/* Same stops as DENSITY_STOPS in config.js */
.ramp { height: 8px; border-radius: 3px; background: linear-gradient(90deg, rgba(63, 107, 78, 0.22), rgba(63, 107, 78, 0.45) 40%, rgba(63, 107, 78, 0.7) 75%, var(--leaf)); }
.ramp-labels { display: flex; justify-content: space-between; margin-top: 4px; }

/* Loading hint over the map, centred in the area next to the panel */
.map-status {
  position: fixed;
  z-index: 2;
  top: 16px;
  left: calc(432px + (100% - 432px) / 2);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.map-status[hidden] { display: none; }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .locate, .density, .map-status {
    background: var(--glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    box-shadow: inset 0 1px 0 var(--glass-edge), var(--shadow-small);
  }
  /* Over glass, secondary grey is too weak: use full ink */
  .density { color: var(--text); }
}

.maplibregl-popup-content { font: 14px/1.45 var(--font); color: var(--text); background: var(--surface); border-radius: 10px; padding: 10px 12px; }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-content span { color: var(--text-2); }

@media (max-width: 640px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 36vh;
    border-radius: 28px 28px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transition: max-height 0.45s cubic-bezier(0.32, 0.72, 0, 1); /* iOS sheet curve: fast start, long soft landing */
  }
  .panel.is-open { max-height: 85vh; }
  /* 44 px tall hit area; it overlaps the top of the (non-interactive) clock labels */
  .grip { display: block; position: relative; z-index: 1; width: 100%; height: 44px; margin-bottom: -26px; padding: 10px 0 0; background: none; border: 0; cursor: grab; touch-action: none; }
  .grip::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: rgba(30, 42, 34, 0.18); margin: 0 auto; }
  /* Folded, the sheet shows its top and does not scroll; drag or tap the grip to open it */
  .panel:not(.is-open) { overflow-y: hidden; }
  .hero { padding: 30px 20px 12px; }
  .hero-main { padding-left: 20px; grid-template-columns: 112px minmax(0, 1fr); gap: 30px; }
  .dial { width: 112px; }

  /* All chips stay visible: trees in the first rows, herbs after a line break. The group labels
     are only read by screen readers here; a full-width, zero-height label forces the break. */
  .chips { gap: 6px; margin-top: 22px; }
  .chip { padding: 6px 10px; font-size: 14.5px; }
  .chips-label { flex-basis: 100%; height: 0; margin: -3px 0; overflow: hidden; color: transparent; }
  .chips-label:first-child { position: absolute; width: 1px; height: 1px; margin: 0; clip: rect(0 0 0 0); }
  .spot-summary:not([hidden]) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--soft);
    font-size: 13px;
  }
  .spot-summary b { font-weight: 700; }
  .spot-summary span { display: inline-flex; align-items: center; gap: 4px; }
  .search { position: fixed; z-index: 3; top: 12px; left: 12px; right: 12px; padding: 0; }
  .search-input { min-height: 44px; background-color: var(--surface); box-shadow: var(--shadow-small); padding-right: 14px; }
  .search-results { left: 0; right: 0; }
  h1 { font-size: min(32px, 14.5cqi); }
  .level { font-size: 18px; }
  .hero-text { margin-top: 6px; font-size: 15px; }
  .locate { top: 64px; right: 12px; padding: 8px 12px; font-size: 13px; }
  /* One slim line on phones: title, ramp, nothing else; the ramp runs from light (few) to dark (many) */
  .density { top: 64px; left: 12px; right: auto; bottom: auto; width: auto; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 999px; }
  .density .ramp { width: 52px; height: 6px; }
  .density .ramp-labels { display: none; }
  /* The open sheet covers the map: the legend and the zoom buttons would only peek out under it */
  body:has(.panel.is-open) .density { opacity: 0; }
  .maplibregl-ctrl-bottom-right { bottom: calc(36vh + 4px); transition: opacity 0.2s; }
  body:has(.panel.is-open) .maplibregl-ctrl-bottom-right { opacity: 0; pointer-events: none; }
  .density strong { margin: 0; font-size: 12px; }
  .map-status { top: auto; bottom: calc(36vh + 12px); left: 50%; }
  .panel.is-open ~ .map-status { display: none; }

  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    /* Solid again while typing, so the results list below never sits on glass */
    .search-input:not(:focus) {
      background-color: var(--glass);
      -webkit-backdrop-filter: var(--glass-blur);
      backdrop-filter: var(--glass-blur);
      box-shadow: inset 0 1px 0 var(--glass-edge), var(--shadow-small);
    }
    .search-input:not(:focus)::placeholder { color: var(--text-2); }
  }
}

/* Desktop: the panel has its own "Mein Standort" button; the floating one is for the folded phone sheet */
@media (min-width: 641px) {
  .locate { display: none; }
}

/* Touch screens: every control gets a 44 px hit area, without growing visually */
@media (pointer: coarse) {
  .maplibregl-ctrl-group button { width: 44px; height: 44px; }
  .chip::after, .btn::after, .locate::after { content: ""; position: absolute; inset: -4px -3px; }
  .locate::after { inset: -5px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .density, .clock .hand { transition: none; }
  /* Gentler press feedback without movement */
  .chip, .btn, .locate { transition: opacity 100ms ease-out; }
  .chip:active, .btn:active, .locate:active { transform: none; opacity: 0.7; }
}

/* Glass becomes solid when people ask for less transparency or more contrast */
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .panel { background: var(--surface) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
  .search-input { background-color: var(--soft) !important; }
  .locate, .density, .map-status { background: var(--surface) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
@media (prefers-reduced-transparency: reduce) and (max-width: 640px), (prefers-contrast: more) and (max-width: 640px) {
  .search-input:not(:focus) { background-color: var(--surface) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
@media (prefers-contrast: more) {
  :root { --text-2: #3d3b33; --text-3: #48463d; --rule: #84877e; }
  .locate, .density, .map-status, .panel { border: 1px solid var(--text-2); }
}
