:root {
  color-scheme: light;
  --bg: #d8edf8;
  --panel: rgba(244, 251, 255, 0.9);
  --panel-strong: rgba(249, 253, 255, 0.96);
  --ink: #13313d;
  --muted: #5f7e89;
  --line: rgba(76, 125, 145, 0.18);
  --accent: #1597c3;
  --accent-strong: #0e6f90;
  --accent-soft: #c6eef8;
  --frost: #eefbff;
  --grade-a: #76d954;
  --grade-b: #ffd166;
  --grade-c: #f79d65;
  --grade-d: #ef476f;
  --shadow: 0 18px 40px rgba(21, 76, 104, 0.14);
  --radius: 1.35rem;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(214, 247, 255, 0.95), transparent 24rem),
    radial-gradient(circle at top right, rgba(255, 225, 235, 0.48), transparent 22rem),
    linear-gradient(180deg, #eef9ff 0, var(--bg) 100%);
  color: var(--ink);
  font: 16px/1.45 Georgia, "Times New Roman", serif;
}

body {
  overflow: hidden;
}

.app-shell,
.map-stage {
  position: relative;
  min-height: 100vh;
}

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

.topbar {
  position: absolute;
  inset: var(--safe-top) 12px auto 12px;
  z-index: 20;
  display: grid;
  gap: 0.65rem;
}

.brandbar,
.searchbar,
.filters-panel,
.bottom-sheet {
  backdrop-filter: blur(12px);
}

.brandbar,
.searchbar,
.filters-panel,
.bottom-sheet {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brandbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: calc(var(--radius) + 0.2rem);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 206, 229, 0.55), transparent 5rem),
    radial-gradient(circle at 28% 0%, rgba(214, 247, 255, 0.92), transparent 8rem),
    linear-gradient(145deg, rgba(247, 253, 255, 0.96), rgba(234, 249, 255, 0.9));
  overflow: hidden;
}

/* Softened and pushed further into the corner: with a coloured cone mark and a
   gradient wordmark now carrying the header, the blob was competing rather than
   accenting. */
.brandbar::after {
  content: "";
  position: absolute;
  right: -2.2rem;
  top: -2.4rem;
  width: 6.5rem;
  height: 6.5rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 244, 250, 0.9), rgba(255, 205, 226, 0.6) 54%, transparent 55%);
  opacity: 0.55;
  pointer-events: none;
}

/* Must sit above .brandbar::after, or the decorative blob paints over the tail of
   the title. .brand-actions already does this; the title was the one thing left
   underneath it. */
.brand-copy {
  position: relative;
  z-index: 1;
  flex: 1 1 12rem;
  min-width: 0;
}

.brand-actions {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--accent);
  font: 700 0.76rem/1.2 Arial, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Arial Narrow", Arial, sans-serif;
  letter-spacing: 0.02em;
}

/* Icon and wordmark read as one lockup, with the cone sized off the cap height so
   the two scale together. */
.wordmark {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-mark {
  flex: 0 0 auto;
  /* Height-driven, width auto: a cone is taller than it is wide, and squaring it
     would just add side padding. */
  height: clamp(2.3rem, 8.5vw, 3.5rem);
  width: auto;
  filter: drop-shadow(0 2px 3px rgba(15, 67, 89, 0.22));
}

h1 {
  font-size: clamp(1.35rem, 5vw, 2.45rem);
  line-height: 0.98;
  text-transform: uppercase;
  letter-spacing: 0.005em;
  background: linear-gradient(103deg, #0b4d63 8%, #1597c3 58%, #35b9d6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Gradient text drops the glyphs out entirely if background-clip is unsupported. */
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  h1 {
    background: none;
    color: #0b4d63;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

h1::before {
  content: "";
}

.locate-button,
.ghost-button {
  border: 0;
  border-radius: 999px;
  font: 700 0.92rem/1 Arial, sans-serif;
  cursor: pointer;
}

.locate-button {
  flex: 0 0 auto;
  min-width: 6.5rem;
  padding: 0.88rem 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}

/* The button is the only geolocation feedback now that the status pill is gone. */
.locate-button[data-state="loading"] {
  opacity: 0.75;
  cursor: progress;
}

.locate-button[data-state="active"] {
  background: linear-gradient(135deg, #29b673, #0f766e);
}

.locate-button[data-state="error"] {
  background: linear-gradient(135deg, #ef7d8f, #c94c63);
}

.searchbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  padding: 0.55rem;
  border-radius: 1.1rem;
  background: linear-gradient(180deg, rgba(252, 255, 255, 0.94), rgba(241, 250, 255, 0.96));
}

.searchbar input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  font: inherit;
}

.searchbar input {
  padding: 0.9rem 0.8rem;
  /* Sized so the full placeholder fits beside the Suodattimet button; ellipsis is
     the safety net for narrow phones, not the normal state. */
  font-size: 0.95rem;
  text-overflow: ellipsis;
}

.ghost-button {
  padding: 0 0.95rem;
  background: rgba(21, 151, 195, 0.12);
  color: var(--accent-strong);
}

.info-button {
  min-height: 2.7rem;
  padding: 0.7rem 0.95rem;
  white-space: nowrap;
}

.filters-panel {
  padding: 0.7rem 0.8rem;
  border-radius: 1.15rem;
  background: linear-gradient(180deg, rgba(245, 252, 255, 0.95), rgba(236, 248, 255, 0.9));
}

.filters-grid {
  display: grid;
  gap: 0.7rem;
}

.field label {
  display: block;
  margin: 0 0 0.3rem;
  color: var(--muted);
  font: 700 0.75rem/1.2 Arial, sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.field select {
  padding: 0.74rem 0.82rem;
}

/* A 2x2 grid rather than free wrapping: at the current panel width the four grades
   otherwise break 3 + 1 and leave "Huono" stranded on its own row. */
.legend-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.8rem;
  margin-top: 0.8rem;
}

.grade-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2rem;
  color: var(--muted);
  font: 700 0.84rem/1.2 Arial, sans-serif;
}

.grade-badge.compact {
  gap: 0.35rem;
  min-height: 1.8rem;
}

.grade-badge-icon {
  display: inline-flex;
  width: 1.9rem;
  height: 1.9rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  flex: 0 0 auto;
}

.grade-badge.compact .grade-badge-icon {
  width: 1.7rem;
  height: 1.7rem;
}

.grade-badge-icon img {
  display: block;
  width: 1rem;
  height: 1rem;
}

.grade-badge-label {
  white-space: nowrap;
}

.bottom-sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 25;
  display: grid;
  grid-template-rows: auto 1fr;
  max-height: min(72vh, 46rem);
  border-radius: 1.45rem 1.45rem 0 0;
  background: linear-gradient(180deg, rgba(249, 253, 255, 0.98), rgba(240, 249, 255, 0.96));
  overflow: hidden;
}

.bottom-sheet.is-peek {
  max-height: 11.5rem;
}

.sheet-handle {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem 0.8rem;
  width: 100%;
  padding: 0.55rem 1rem 0.8rem;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.handle-bar {
  grid-column: 1 / -1;
  justify-self: center;
  width: 3rem;
  height: 0.34rem;
  border-radius: 999px;
  background: rgba(73, 63, 49, 0.22);
}

.sheet-title {
  font: 800 1rem/1 Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sheet-count,
.muted {
  color: var(--muted);
}

.sheet-body {
  display: grid;
  gap: 0.8rem;
  min-height: 0;
  padding: 0 0.95rem calc(var(--safe-bottom) + 0.7rem);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.stat {
  padding: 0.8rem 0.72rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.76);
}

.stat strong {
  display: block;
  font: 800 1.55rem/1 Arial, sans-serif;
}

.stat span {
  display: block;
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.map-empty {
  display: none;
  gap: 0.2rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(243, 251, 255, 0.94);
}

.map-empty.visible {
  display: grid;
}

.results-panel {
  min-height: 0;
}

.results {
  display: grid;
  gap: 0.75rem;
  max-height: 100%;
  overflow: auto;
  padding-bottom: 0.2rem;
}

.result-card {
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(243, 251, 255, 0.84));
  cursor: pointer;
}

/* With the "Näytä kartalla" button gone, the card itself carries the affordance,
   so it needs a visible hover and a real focus ring. */
.result-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(21, 151, 195, 0.16);
}

.result-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.result-card h3 {
  font-size: 1.02rem;
  margin-bottom: 0.25rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.38rem;
  margin: 0.45rem 0 0.55rem;
}

.pill {
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  font: 700 0.73rem/1.2 Arial, sans-serif;
}

/* Softened: the location is a guess, and the chip should not look like a fact. */
.pill-soft {
  border-style: dashed;
  opacity: 0.85;
}

.pill-warn {
  border-color: rgba(196, 118, 62, 0.45);
  background: rgba(255, 240, 228, 0.9);
  color: #a35c2c;
}

.pill-distance {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* A stale grade stays legible but visibly recedes behind fresh ones. */
.result-card.is-stale {
  background: linear-gradient(180deg, rgba(252, 252, 250, 0.9), rgba(246, 247, 245, 0.86));
}

.result-card.is-stale h3 {
  color: #4a6570;
}

.notes {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-actions,
.popup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.mini-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.2rem;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent-strong);
  text-decoration: none;
  font: 700 0.8rem/1 Arial, sans-serif;
  cursor: pointer;
}

.mini-action-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}

.empty-state {
  padding: 0.8rem 0.2rem;
  color: var(--muted);
}

.maplibregl-popup-content {
  padding: 0.8rem 0.9rem;
  border-radius: 0.9rem;
  background: rgba(249, 253, 255, 0.97);
}

.popup-title {
  /* Leaves room for the close button, which MapLibre absolutely positions into
     the top-right corner and would otherwise land on the last word. */
  margin: 0 1.4rem 0.2rem 0;
  font: 700 0.98rem/1.3 Arial, sans-serif;
}

.maplibregl-popup-close-button {
  top: 0.15rem;
  right: 0.3rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.maplibregl-popup-close-button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.popup-body {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.popup-grade {
  margin-top: 0.45rem;
}

/* Kiosk points are drawn by MapLibre circle layers (see addMapLayers), so the
   old DOM-marker rules are gone. Only popup and list chrome lives here now. */

.popup-precision {
  font-weight: 700;
}

.popup-precision.is-vague {
  color: var(--accent-strong);
  font-weight: 400;
  font-style: italic;
}

.popup-date {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.popup-date.is-stale {
  color: #b0663a;
}

.info-dialog {
  width: min(34rem, calc(100vw - 1.5rem));
  padding: 0;
  border: 0;
  border-radius: 1.3rem;
  background: transparent;
  color: var(--ink);
}

.info-dialog::backdrop {
  background: rgba(19, 16, 11, 0.42);
  backdrop-filter: blur(6px);
}

.info-dialog-card {
  padding: 1rem 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 1.3rem;
  background: rgba(247, 252, 255, 0.98);
  box-shadow: 0 28px 60px rgba(17, 78, 103, 0.24);
}

.info-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.dialog-close {
  width: 2.3rem;
  height: 2.3rem;
  border: 0;
  border-radius: 999px;
  background: rgba(21, 151, 195, 0.12);
  color: var(--accent-strong);
  font: 700 1.35rem/1 Arial, sans-serif;
  cursor: pointer;
}

.info-copy {
  margin-top: 0.9rem;
  color: var(--muted);
}

.info-copy p {
  margin: 0 0 0.8rem;
}

.info-links {
  margin-top: 0.35rem;
}

.article-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.8rem;
  padding: 0.72rem 1rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  text-decoration: none;
  font: 700 0.92rem/1 Arial, sans-serif;
}

.maplibregl-ctrl-group {
  border: 1px solid rgba(76, 125, 145, 0.14);
  box-shadow: 0 10px 24px rgba(17, 78, 103, 0.14);
}

@media (min-width: 900px) {
  /* The desktop topbar is a 19rem column, which is not wide enough to hold the
     title and both buttons on one line. Forcing nowrap here collapsed .brand-copy
     to a few pixels and let the h1 overflow across the buttons, so the brandbar
     keeps the wrapping behaviour it has everywhere else. */
  .topbar {
    right: auto;
    /* 19rem left the search input around 150px against a ~230px placeholder, so
       the hint was always truncated on desktop. */
    width: min(22rem, calc(100vw - 2rem));
  }

  .filters-grid {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .bottom-sheet {
    top: 1rem;
    right: 1rem;
    bottom: 1rem;
    left: auto;
    width: min(31rem, calc(100vw - 2rem));
    max-height: none;
    border-radius: 1.45rem;
  }

  .bottom-sheet.is-peek {
    max-height: none;
  }

  .sheet-handle {
    cursor: default;
  }

  .handle-bar {
    display: none;
  }

  .legend-inline {
    gap: 0.4rem 0.65rem;
    margin-top: 0.65rem;
  }

  .grade-badge {
    font-size: 0.78rem;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: clamp(1.8rem, 11vw, 3rem);
  }

  .brandbar {
    align-items: flex-start;
    flex-direction: column;
  }

  /* In a column container flex-basis sizes the HEIGHT, so the row-oriented
     `flex: 1 1 12rem` / `flex: 1 1 100%` bases turned into a ~290px tall brandbar
     that shoved the buttons under the search field. Size these to content instead. */
  .brand-copy,
  .brand-actions {
    flex: 0 0 auto;
  }

  .brand-actions {
    width: 100%;
    justify-content: space-between;
  }

  .locate-button,
  .info-button {
    min-width: 0;
    flex: 1 1 0;
    justify-content: center;
    text-align: center;
    padding-inline: 0.9rem;
  }

  /* On a 375px phone the two buttons land within ~6px of their content width.
     Trimming the padding below that keeps the labels off each other. */
  @media (max-width: 390px) {
    .locate-button,
    .info-button {
      padding-inline: 0.62rem;
      font-size: 0.86rem;
    }
  }

  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }
}
