/*
 * Kartta on sovellus, ei kuvituskuva: se täyttää ruudun ja hallinta kelluu sen
 * päällä. Metsässä katsotaan karttaa, ei lomaketta.
 *
 * Tumma on oletus eikä vaihtoehto. Kartan omat sävyt ovat vaaleita ja
 * kylläisiä, ja tumma kehys jättää ne kirkkaimmaksi asiaksi ruudulla — vaalea
 * paneeli kilpailisi niiden kanssa. Vaalea tila on silti tuettu, koska
 * kirkkaassa auringossa se on ainoa luettava.
 */

:root {
  --bg: #0b120e;
  --panel: rgba(18, 28, 22, 0.82);
  --panel-solid: #121c16;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --ink: #eef2ed;
  --muted: #9aa79d;
  --accent: #6fcf7f;
  --accent-ink: #0b120e;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0ea;
    --panel: rgba(255, 255, 255, 0.86);
    --panel-solid: #ffffff;
    --line: rgba(20, 30, 24, 0.12);
    --line-strong: rgba(20, 30, 24, 0.22);
    --ink: #16201a;
    --muted: #5f6b62;
    --accent: #2f7a3c;
    --accent-ink: #ffffff;
    --shadow: 0 10px 30px rgba(20, 30, 24, 0.18);
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* Leafletin oletusruudut ovat kirkkaan valkoisia; tumma pohja himmentää
   saumakohdat niin ettei tyhjä alue välähdä silmille. */
.leaflet-container {
  background: var(--bg);
  font: inherit;
}

/* Alalaidan säätimet kahvan yläpuolelle, muuten attribuutio jää sen alle.
   Auki olevan paneelin alle jääminen on hyväksyttävää — se on hetkellistä. */
.leaflet-bottom {
  bottom: 96px;
}

/* Lyhyet lähdemerkinnät mahtuvat yhdelle riville; täysi teksti on paneelin
   alaviitteessä, jossa sille on tilaa. Kahdelle riville kietoutuva merkintä
   muodosti tumman palkin kartan poikki. */
.leaflet-control-attribution {
  max-width: 62vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--panel) !important;
  color: var(--muted) !important;
  backdrop-filter: blur(10px);
  border-radius: 10px 0 0 0;
  font-size: 10.5px !important;
  padding: 2px 8px !important;
}

.leaflet-control-attribution a {
  color: var(--muted) !important;
}

/* ---------- yläpalkki ---------- */

.topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

/* Sama aihe kuin ikonissa: kasvupaikka-asteikko karusta rehevään. */
.brand__mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  flex: none;
  background: linear-gradient(
    170deg,
    #1a3c22 0%,
    #22542b 22%,
    #2e6e34 44%,
    #569648 66%,
    #8cba68 82%,
    #2a4a84 82%,
    #2a4a84 100%
  );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.brand__name {
  font-weight: 620;
  letter-spacing: -0.015em;
  font-size: 15.5px;
  white-space: nowrap;
}

.year {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
}

.year__label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.year select {
  appearance: none;
  padding: 7px 26px 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 51%, calc(100% - 9px) 51%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.year select option {
  background: var(--panel-solid);
  color: var(--ink);
}

/* ---------- oikean reunan napit ---------- */

.rail {
  position: fixed;
  right: 12px;
  top: calc(max(10px, env(safe-area-inset-top)) + 68px);
  z-index: 500;
  display: grid;
  gap: 8px;
}

.rail__btn {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.rail__btn:active {
  transform: scale(0.94);
}

.rail__btn[data-busy="1"] {
  border-color: var(--accent);
}

.rail__group {
  display: grid;
  gap: 1px;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.rail__group .rail__btn {
  border-radius: 0;
  box-shadow: none;
  height: 42px;
}

.rail__group .rail__btn:first-child {
  border-radius: 15px 15px 0 0;
}

.rail__group .rail__btn:last-child {
  border-radius: 0 0 15px 15px;
}

.rail__btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
}

/* ---------- tila ---------- */

.status {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 62px);
  left: 12px;
  z-index: 500;
  margin: 0;
  max-width: min(62vw, 340px);
  padding: 7px 12px;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: rise 0.24s ease both;
}

.status:empty {
  display: none;
}

/* ---------- alapaneeli ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 600;
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  max-height: min(54dvh, 560px);
  transition: max-height 0.22s ease;
}

/* Suljettuna paneeli on pelkkä kahva: kartta on sovellus, ja puhelimen
   pystytila loppuu ensin. Kasvupaikka on jo päällä, joten suljettunakin
   ruudulla näkyy se mitä sovellus tekee. */
.sheet[data-collapsed="1"] {
  max-height: 92px;
}

.sheet__grip {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 10px 16px 6px;
  display: grid;
  justify-items: center;
  gap: 6px;
  cursor: pointer;
  font: inherit;
  flex: none;
}

.sheet__grip-bar {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: var(--line-strong);
}

.sheet__grip-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.sheet__grip-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 99px;
  padding: 1px 7px;
  font-weight: 600;
}

.sheet__grip-count:empty {
  display: none;
}

.sheet__chev {
  width: 15px;
  height: 15px;
  stroke: var(--muted);
  transition: transform 0.22s ease;
}

/* Kiinni: nuoli ylös, koska se on kutsu avata. Auki: alas, koska se sulkee.
   Väärinpäin tämä lupaisi joka kerta päinvastaista kuin napautus tekee. */
.sheet:not([data-collapsed="1"]) .sheet__chev {
  transform: rotate(180deg);
}

.sheet__grip-text {
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}

.sheet[data-collapsed="1"] .sheet__body {
  display: none;
}

/* ---------- tasovalinta ---------- */

.picker {
  display: grid;
  gap: 8px;
}

.pick {
  display: block;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.pick:has(input:checked) {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.pick input {
  appearance: none;
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: none;
  border: 1.6px solid var(--line-strong);
  border-radius: 7px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.pick input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.pick input:checked::after {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2.2px solid var(--accent-ink);
  border-bottom: 2.2px solid var(--accent-ink);
  transform: rotate(-45deg) translate(1px, -1px);
}

.pick input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pick__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.pick__text strong {
  font-weight: 580;
  font-size: 14.5px;
}

.pick__text small {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.42;
}

/* ---------- päällä olevat tasot ---------- */

.pick__main {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
}

/* Peittävyys näkyy vasta kun taso on päällä: sammutetun tason säädin olisi
   kontrolli jolla ei ole kohdetta. */
.pick__opacity {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 10px 0 1px 31px;
}

.pick[data-on="1"] .pick__opacity {
  display: flex;
}

.pick__opacity input {
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 99px;
  background: var(--line-strong);
  cursor: pointer;
}

.pick__opacity input::-webkit-slider-thumb {
  appearance: none;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--panel-solid);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

.pick__opacity input::-moz-range-thumb {
  width: 19px;
  height: 19px;
  border: 2.5px solid var(--panel-solid);
  border-radius: 50%;
  background: var(--accent);
}

.pick__pct {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}


/* ---------- alaviite ---------- */

.credits {
  border-top: 1px solid var(--line);
  padding-top: 11px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.credits p {
  margin: 0 0 5px;
}

.credits strong {
  color: var(--ink);
  font-weight: 560;
}

.credits__note {
  opacity: 0.85;
}

/* ---------- päivitysilmoitus ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: rise 0.26s ease both;
}

.toast[hidden] {
  display: none;
}

.toast button {
  border: 0;
  border-radius: 999px;
  padding: 7px 15px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 580;
  cursor: pointer;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast {
  animation-name: rise-center;
}

@keyframes rise-center {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Leveällä ruudulla paneeli siirtyy sivuun: kartta on tärkein, ja pystysuora
   tila on työpöydällä se joka loppuu ensin. */
@media (min-width: 860px) {
  .sheet {
    left: auto;
    right: 12px;
    bottom: 12px;
    top: calc(max(10px, env(safe-area-inset-top)) + 68px);
    width: 380px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    max-height: none;
  }

  .sheet__grip {
    display: none;
  }

  .sheet[data-collapsed="1"] .sheet__body {
    display: grid;
  }

  .sheet[data-collapsed="1"] {
    max-height: none;
  }

  .rail {
    right: 408px;
  }

  .leaflet-bottom {
    bottom: 0;
  }

  .toast {
    left: auto;
    right: 408px;
    transform: none;
    animation-name: rise;
  }
}

/* ---------- taustakartan valitsin ---------- */

.basemap {
  position: fixed;
  right: 68px;
  top: calc(max(10px, env(safe-area-inset-top)) + 122px);
  z-index: 620;
  display: grid;
  gap: 2px;
  padding: 6px;
  min-width: 168px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: rise 0.16s ease both;
}

.basemap[hidden] {
  display: none;
}

.basemap__item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.basemap__item:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.basemap__item[aria-checked="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  font-weight: 560;
}

.basemap__dot {
  width: 15px;
  height: 15px;
  flex: none;
  border-radius: 50%;
  border: 1.6px solid var(--line-strong);
  display: grid;
  place-items: center;
}

.basemap__item[aria-checked="true"] .basemap__dot {
  border-color: var(--accent);
}

.basemap__item[aria-checked="true"] .basemap__dot::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- selite kartan päällä ---------- */

.legend {
  position: fixed;
  left: 12px;
  bottom: 104px;
  z-index: 550;
  width: min(230px, 62vw);
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.2s ease both;
}

.legend[hidden] {
  display: none;
}

.legend__head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.legend__title {
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend__chev {
  width: 14px;
  height: 14px;
  flex: none;
  stroke: var(--muted);
  transition: transform 0.2s ease;
}

.legend[data-collapsed="1"] .legend__chev {
  transform: rotate(180deg);
}

.legend[data-collapsed="1"] .legend__body {
  display: none;
}

.legend__body {
  /* Kasvupaikassa on 12 luokkaa; puhelimessa ne eivät mahdu kerralla, joten
     lista vierii itsessään eikä kasva kartan päälle. */
  max-height: min(38dvh, 300px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 11px 10px;
  display: grid;
  gap: 6px;
}

.legend__group + .legend__group {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.legend__group-name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 5px;
}

.legend__row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink);
}

.legend__swatch {
  width: 13px;
  height: 13px;
  flex: none;
  margin-top: 1px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.legend__empty {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
}

@media (min-width: 860px) {
  .legend {
    bottom: 12px;
    width: 250px;
  }

  .basemap {
    right: 464px;
  }
}

/* ---------- pistekyselyn vastaus ---------- */

.id-popup .leaflet-popup-content-wrapper {
  background: var(--panel-solid);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.id-popup .leaflet-popup-content {
  margin: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.id-popup .leaflet-popup-tip {
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
}

.id-popup .leaflet-popup-close-button {
  color: var(--muted) !important;
}

.id-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
}

.id-list dt {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.id-list dd {
  margin: 0;
  font-weight: 560;
}

.leaflet-control-scale-line {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border-color: var(--line-strong) !important;
  backdrop-filter: blur(10px);
  border-radius: 4px;
  font-size: 10.5px !important;
}
