/* Kala-Onni – layout and design tokens.
   Palette roles follow a validated light/dark data-viz palette: the dark steps
   are chosen for the dark surface, not flipped automatically. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;          /* cards, chart surface */
  --surface-2: #f9f9f7;          /* page plane */
  --surface-3: #f1f1ed;          /* hover wash */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* Spot categories. Three categorical hues are the most that stay apart for
     every kind of colour vision as map markers in both themes, so "meri" is a
     deeper step of the water hue and every marker also carries its own icon. */
  --cat-oma: #eb6834;            /* your own places share the marked-spot hue,
                                    and are told apart by the star and a ring */
  --cat-merkitty: #eb6834;
  --cat-jarvi: #2a78d6;
  --cat-joki: #1baf7a;
  --cat-meri: #184f95;
  --cat-muu: #82807a;

  --accent: #2a78d6;             /* categorical slot 1 – water */
  --accent-soft: #cde2fb;
  --accent-ink: #184f95;
  --spot: #eb6834;               /* categorical slot 2 – marked fishing spot */
  --spot-soft: #fbe2d7;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --night-band: rgba(11, 11, 11, 0.055);
  --shadow-1: 0 1px 2px rgba(11, 11, 11, .07), 0 4px 16px rgba(11, 11, 11, .06);

  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --cat-oma: #d95926;
    --cat-merkitty: #d95926;
    --cat-jarvi: #3987e5;
    --cat-joki: #199e70;
    --cat-meri: #9ec5f4;
    --cat-muu: #9a988f;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #262625;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: #184f95;
    --accent-ink: #9ec5f4;
    --spot: #d95926;
    --spot-soft: #4a2415;
    --night-band: rgba(255, 255, 255, 0.055);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --cat-oma: #d95926;
  --cat-merkitty: #d95926;
  --cat-jarvi: #3987e5;
  --cat-joki: #199e70;
  --cat-meri: #9ec5f4;
  --cat-muu: #9a988f;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-3: #262625;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: #184f95;
  --accent-ink: #9ec5f4;
  --spot: #d95926;
  --spot-soft: #4a2415;
  --night-band: rgba(255, 255, 255, 0.055);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/* No blue flash on tap; :active states carry the feedback instead. */
button, a, select, input, .card, .tab { -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-primary);
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 1200;
  background: var(--surface-1); color: var(--text-primary);
  padding: 10px 14px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  min-height: var(--header-h);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 900;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

.search { position: relative; flex: 1 1 auto; display: flex; gap: 6px; max-width: 460px; }
.search input {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  font: inherit; font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.search input:focus-visible, .btn:focus-visible, select:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  max-height: 320px; overflow: auto; z-index: 1000;
}
.search-results li button {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-primary);
  font: inherit; font-size: 13.5px; cursor: pointer;
}
.search-results li button:hover { background: var(--surface-3); }
.search-results .hit-sub { display: block; font-size: 11.5px; color: var(--text-muted); }

.header-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-primary:hover { background: var(--accent-ink); color: #fff; }
.btn-icon { padding: 9px 11px; }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  min-height: 0;
}

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-3); }

.map-hint, .map-filters {
  position: absolute; z-index: 500;
  background: var(--surface-1); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; box-shadow: var(--shadow-1);
}
.map-hint {
  top: 12px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 28px); text-align: center;
  transition: opacity .4s ease, transform .4s ease;
}
.map-action {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 620;
  padding: 9px 16px; border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 0; box-shadow: var(--shadow-1);
  cursor: pointer; touch-action: manipulation;
}
.map-action[hidden] { display: none; }
.map-action:hover { background: var(--accent-ink); }

/* The locate button has three states: off, following, and following but
   left behind after the user panned the map. */
.fab[aria-pressed="true"] { box-shadow: var(--shadow-1), 0 0 0 3px var(--accent-soft); }
.fab.is-adrift { background: var(--surface-1); color: var(--text-primary); }

.map-hint.is-hidden { opacity: 0; transform: translateX(-50%) translateY(-6px); pointer-events: none; }
.map-filters {
  left: 12px; bottom: 22px; max-width: min(460px, calc(100% - 24px));
  padding: 6px; border-radius: var(--radius-sm);
}

/* Filter chips: an icon on the category colour, its name and how many. */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters[hidden] { display: none; }
.panel-filters { margin: -2px 0 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-1);
  font: inherit; font-size: 12px; font-weight: 550; color: var(--text-primary);
  cursor: pointer; touch-action: manipulation;
}
.chip:hover { background: var(--surface-3); }
.chip-mark {
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; line-height: 1;
  background: var(--chip-color, var(--accent));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}
.chip-count { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="false"] { opacity: .55; }
.chip[aria-pressed="false"] .chip-mark { filter: grayscale(1) contrast(.5); }
.chip[aria-pressed="false"] .chip-label { text-decoration: line-through; }

/* ---------- panel ---------- */

.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
}

.place-bar { padding: 12px 16px 10px; border-bottom: 1px solid var(--border); }
.place-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.place-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.place-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn-small { padding: 6px 11px; font-size: 12.5px; }

/* ---------- forms ---------- */

.form-card {
  background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.form-card h3 { margin: 0 0 4px; font-size: 14px; }
.form-card .form-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--text-secondary); font-weight: 550; }
.field input, .field select, .field textarea {
  font: inherit; font-size: 14px; padding: 9px 10px;
  color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  min-height: 42px;
}
.field textarea { min-height: 62px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }
.form-actions .btn { flex: 1; }
.form-note { font-size: 11.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.45; }

/* ---------- journal ---------- */

.stat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.journal-entry { display: flex; gap: 10px; align-items: flex-start; }
.journal-when {
  flex: none; width: 52px; text-align: center;
  font-size: 11px; color: var(--text-muted); line-height: 1.25;
  font-variant-numeric: tabular-nums;
}
.journal-when b { display: block; font-size: 15px; color: var(--text-primary); }
.journal-main { flex: 1; min-width: 0; }
.journal-title { font-size: 14px; font-weight: 600; }
.journal-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.journal-remove {
  flex: none; background: none; border: 0; cursor: pointer;
  color: var(--text-muted); font-size: 16px; line-height: 1; padding: 4px 6px;
  border-radius: 6px;
}
.journal-remove:hover { background: var(--surface-3); color: var(--critical); }

.catch-hint {
  margin-top: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.5;
  background: var(--surface-2); border-left: 3px solid var(--cat-oma);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.catch-hint b { color: var(--text-primary); }

.tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 9px 8px; cursor: pointer;
  background: transparent; color: var(--text-secondary);
  border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0;
}
.tab:hover { background: var(--surface-3); }
.tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); }

.views { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; overflow-y: auto; padding: 12px 14px 28px; }
.view[hidden] { display: none; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: var(--text-secondary); }
.toolbar select {
  font: inherit; font-size: 13px; padding: 7px 8px;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.toolbar .btn { margin-left: auto; padding: 7px 10px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.card {
  width: 100%; text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  font: inherit; color: var(--text-primary);
  cursor: pointer;
}
.card:hover { background: var(--surface-3); }
.card[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card-top { display: flex; align-items: baseline; gap: 8px; }
.card-title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }
.card-dist { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  padding: 3px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.badge .swatch { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.badge .swatch { background: var(--chip-color, var(--accent)); }
.badge-good { color: var(--text-primary); border-color: var(--good); }
.badge-warn { color: var(--text-primary); border-color: var(--warning); }
.badge-crit { color: var(--text-primary); border-color: var(--critical); }

.note {
  font-size: 12.5px; line-height: 1.5; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px;
}
.note strong { color: var(--text-primary); }
.note a { color: var(--accent-ink); }

.empty { padding: 28px 12px; text-align: center; color: var(--text-muted); font-size: 13px; line-height: 1.6; }

.skeleton { height: 62px; border-radius: var(--radius); background: var(--surface-3); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* ---------- species ---------- */

.species-card { padding: 0; cursor: default; }
.card-main {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; border-radius: var(--radius);
  font: inherit; color: inherit; cursor: pointer;
  padding: 11px 12px;
}
.card-main:hover { background: var(--surface-3); }
.card-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.why { border-top: 1px solid var(--grid); }
.why summary {
  list-style: none; cursor: pointer;
  padding: 9px 12px; font-size: 12px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.why summary::-webkit-details-marker { display: none; }
.why summary::before { content: '▸'; color: var(--text-muted); font-size: 10px; }
.why[open] summary::before { content: '▾'; }
.why summary:hover { color: var(--text-primary); }
.why .factors { padding: 0 12px 12px; margin: 0; }

.explainer { margin-top: 8px; }
.explainer summary {
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--accent-ink);
  padding: 4px 0;
}
.explainer dl { margin: 8px 0 0; }
.explainer dt { font-weight: 650; color: var(--text-primary); margin-top: 6px; font-size: 12.5px; }
.explainer dd { margin: 2px 0 0; font-size: 12.5px; line-height: 1.5; }

.warn-line {
  margin: 8px 0 0; font-size: 12.5px; line-height: 1.5;
  color: var(--text-primary);
  border-left: 3px solid var(--warning); padding-left: 10px;
}

.species-head { display: flex; align-items: center; gap: 10px; }
.species-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 15px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.figure { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.figure-value { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.figure-label { font-size: 10px; color: var(--text-muted); letter-spacing: .02em; }

.species-now {
  margin-top: 8px; font-size: 12.5px; color: var(--text-secondary);
  padding-top: 8px; border-top: 1px solid var(--grid);
}
.species-now b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.species-body { margin-top: 8px; font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.species-body dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.species-body dt { color: var(--text-muted); }
.species-body dd { margin: 0; }
.latin { font-style: italic; color: var(--text-muted); font-size: 11.5px; }

.meter { height: 6px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- weather ---------- */

.hero {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.hero-label { font-size: 12px; color: var(--text-muted); }
.hero-row { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; }
.hero-value { font-size: 48px; font-weight: 680; line-height: 1.02; letter-spacing: -0.03em; }
.hero-unit { font-size: 14px; color: var(--text-muted); }
.hero-verdict { font-size: 15px; font-weight: 650; margin-top: 3px; letter-spacing: -0.01em; }
.hero-why { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; line-height: 1.5; }

.sun-line { margin: -6px 0 14px; font-size: 12px; color: var(--text-secondary); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 10px; }
.tile-label {
  font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 5px;
}
.tile-icon { width: 15px; height: 15px; flex: none; display: block; }
.tile-icon svg { width: 100%; height: 100%; display: block; }
.tile-value { font-size: 17px; font-weight: 620; letter-spacing: -0.01em; margin-top: 2px; white-space: nowrap; }
.tile-value.is-text { font-size: 14px; white-space: normal; line-height: 1.25; }
.tile-sub { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }

.section-title { font-size: 13px; font-weight: 650; margin: 16px 0 8px; display: flex; align-items: baseline; gap: 8px; }
.section-title .hint { font-weight: 400; font-size: 11.5px; color: var(--text-muted); }

.chart-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 8px 6px; }
.chart-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart-wrap { position: relative; }
.chart-readout {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  padding: 8px 6px 2px; font-size: 12px; color: var(--text-secondary);
  border-top: 1px solid var(--grid); margin-top: 6px;
}
.chart-readout b { color: var(--text-primary); font-weight: 600; }
.chart-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 6px 6px 0; font-size: 11.5px; color: var(--text-muted); }
.chart-foot .btn { margin-left: auto; padding: 5px 9px; font-size: 12px; }
.night-key { display: inline-flex; align-items: center; gap: 5px; }
.night-key i { width: 12px; height: 10px; background: var(--night-band); border: 1px solid var(--grid); display: inline-block; }

.tooltip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1); padding: 8px 10px; font-size: 12px; line-height: 1.5;
  min-width: 140px;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-title { font-weight: 650; margin-bottom: 3px; }
.tooltip dl { margin: 0; display: grid; grid-template-columns: auto auto; gap: 1px 10px; }
.tooltip dt { color: var(--text-muted); }
.tooltip dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

table.data { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
table.data th, table.data td { text-align: right; padding: 5px 6px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; font-variant-numeric: normal; }
table.data thead th { color: var(--text-muted); font-weight: 600; }

.window { display: flex; align-items: center; gap: 10px; }
.window-rank {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 650;
}
.window-main { flex: 1; min-width: 0; }
.window-time { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.window-why { font-size: 12px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.window-score { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }

.factors { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.factors li { display: flex; gap: 8px; align-items: baseline; color: var(--text-secondary); }
.factors .sign { font-variant-numeric: tabular-nums; font-weight: 650; min-width: 30px; text-align: right; }
.factors .sign.pos { color: var(--good); }
.factors .sign.neg { color: var(--critical); }

/* ---------- map markers ---------- */

.pin {
  position: relative;
  width: 26px; height: 26px; border-radius: 50% 50% 50% 4px;
  transform: rotate(45deg);
  display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  border: 2px solid var(--surface-1);
}
.pin > span { transform: rotate(-45deg); font-size: 12px; line-height: 1; }
.pin-cat-oma {
  background: var(--cat-oma);
  box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px var(--cat-oma), 0 1px 4px rgba(0, 0, 0, .35);
}
.pin-cat-merkitty { background: var(--cat-merkitty); }
.pin-cat-jarvi { background: var(--cat-jarvi); }
.pin-cat-joki { background: var(--cat-joki); }
.pin-cat-meri { background: var(--cat-meri); }
.pin-cat-muu { background: var(--cat-muu); }
.pin.is-active {
  transform: rotate(45deg) scale(1.28);
  border-color: var(--surface-1);
  box-shadow: 0 0 0 3px var(--accent-ink), 0 3px 10px rgba(0, 0, 0, .45);
}
/* A halo that fades outwards, so the eye finds the pin without hunting. */
.pin.is-active::after {
  content: '';
  position: absolute; inset: -9px;
  border-radius: 50%;
  border: 2px solid var(--accent-ink);
  animation: pin-halo 1.9s ease-out infinite;
}
@keyframes pin-halo {
  0% { transform: scale(.75); opacity: .85; }
  70%, 100% { transform: scale(1.5); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pin.is-active::after { animation: none; opacity: .5; }
}
.me-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-primary); border: 3px solid var(--surface-1);
  box-shadow: 0 0 0 1px var(--border);
}
.accuracy-ring { stroke: var(--accent); fill: var(--accent); fill-opacity: .07; }
.radius-ring { stroke: var(--axis); fill: none; stroke-dasharray: 4 5; }
.leaflet-popup-content { margin: 10px 12px; font-family: var(--font); font-size: 13px; }
.leaflet-popup-content b { display: block; margin-bottom: 2px; }
.leaflet-container { font-family: var(--font); }

/* ---------- mobile chrome: FAB, sheet handle, offline banner ---------- */

.map-fabs {
  position: absolute; right: 14px; z-index: 750;
  /* Sits just above the sheet, wherever the sheet currently is. */
  bottom: calc(var(--sheet-visible, 0px) + 16px + env(safe-area-inset-bottom));
  display: none; flex-direction: column; gap: 12px;
  transition: bottom .3s cubic-bezier(.22, .61, .36, 1), opacity .2s ease;
}
body.sheet-dragging .map-fabs,
body.sheet-dragging .leaflet-control-attribution { transition: none; }
body[data-sheet="full"] .map-fabs { opacity: 0; pointer-events: none; }

.fab {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px; line-height: 1;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  cursor: pointer; touch-action: manipulation;
}
.fab:active { transform: scale(.96); }
.fab.is-busy { opacity: .6; }
.fab-primary { background: var(--accent); color: #fff; border-color: transparent; }

.sheet-handle {
  display: none;
  width: 100%; min-height: 44px; padding: 0;      /* a real tap target, not just a grip */
  align-items: center; justify-content: center;
  background: transparent; border: 0; cursor: grab;
  touch-action: none;
}
.sheet-handle:active { cursor: grabbing; }
.sheet-grip {
  display: block; width: 44px; height: 5px; margin: 0 auto;
  border-radius: 999px; background: var(--axis);
}

.offline-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(var(--header-h) + 8px); z-index: 1150;
  max-width: min(420px, 92vw);
  padding: 8px 14px; font-size: 12.5px;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-1);
}
.offline-banner[hidden] { display: none; }

.chart-hit { touch-action: pan-y; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 1100; max-width: min(520px, 92vw);
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-1);
  padding: 10px 14px; font-size: 13px; line-height: 1.45;
}
.toast[hidden] { display: none; }
.toast.is-error { border-left-color: var(--critical); }

/* ---------- mobile: full-bleed map + draggable bottom sheet ---------- */

@media (max-width: 900px) {
  :root { --header-h: 52px; }

  /* dvh keeps the layout steady while mobile browser chrome slides away;
     vh first as a fallback for older iOS. */
  html, body { height: 100vh; height: 100dvh; overflow: hidden; }

  .app-header {
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 8px;
  }
  .brand-text { display: none; }
  .brand-mark { font-size: 24px; }
  .search { order: 0; flex: 1 1 auto; max-width: none; }
  .search button[type="submit"] { display: none; }
  .search input { min-height: 44px; font-size: 16px; }   /* 16px stops iOS zoom-on-focus */
  #locate-btn { display: none; }                          /* lives in the thumb zone instead */
  .header-actions { gap: 6px; }

  .layout {
    position: relative;
    grid-template-columns: 1fr;
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
  }

  .map-wrap { position: absolute; inset: 0; height: auto; min-height: 0; }
  #map { position: absolute; inset: 0; height: auto; }
  .map-fabs { display: flex; }
  .map-filters { display: none; }        /* the panel carries them on a phone */
  .map-hint { top: 10px; font-size: 11.5px; padding: 5px 10px; }
  .leaflet-control-zoom { display: none; }                /* pinch zoom is enough */
  /* Attribution must stay readable, so it rides above the sheet too.
     The descendant selector matches Leaflet's own margin rule's specificity
     and wins by load order. */
  .leaflet-bottom .leaflet-control-attribution {
    font-size: 9px;
    margin-bottom: calc(var(--sheet-visible, 0px) + 2px);
    transition: margin-bottom .3s cubic-bezier(.22, .61, .36, 1);
  }
  body[data-sheet="full"] .leaflet-bottom .leaflet-control-attribution { opacity: 0; }

  /* The panel is a sheet the thumb can drag between three heights. */
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    height: 94%;
    z-index: 700;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, .12), 0 -12px 40px rgba(0, 0, 0, .18);
    transform: translateY(var(--sheet-offset, calc(100% - 158px)));
    transition: transform .3s cubic-bezier(.22, .61, .36, 1);
    touch-action: none;
    overscroll-behavior: contain;
  }
  .panel.is-dragging { transition: none; }

  .sheet-handle { display: flex; }
  .place-bar { padding: 2px 16px 8px; }
  .place-name { font-size: 16px; }

  .tabs { padding: 4px 10px 0; }
  .tab { min-height: 48px; font-size: 14px; touch-action: manipulation; }

  .views { touch-action: pan-y; }
  .view {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
  }
  .panel[data-snap="peek"] .view { overflow: hidden; }

  /* Touch targets: nothing interactive below 44px. */
  .btn { min-height: 44px; padding: 11px 14px; touch-action: manipulation; }
  .btn-small { min-height: 44px; }
  .field-row { grid-template-columns: 1fr; }
  .why summary, .explainer summary { min-height: 44px; align-items: center; display: flex; }
  .chip { min-height: 44px; padding: 6px 14px 6px 6px; font-size: 13px; }
  .chip-mark { width: 24px; height: 24px; font-size: 13px; }
  .toolbar select { min-height: 44px; }
  .card { padding: 14px; border-radius: 14px; }
  .species-card { padding: 0; }
  .card-main { padding: 14px; }
  .list { gap: 10px; }
  .search-results li button { padding: 13px 12px; }

  .hero { padding: 16px; }
  .hero-value { font-size: 44px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  .chart-card { padding: 12px 6px 8px; }
  .chart-foot .btn { margin-left: 0; width: 100%; }
  .toast { bottom: calc(22px + env(safe-area-inset-bottom)); }
}

@media (max-width: 420px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .window-why { font-size: 11.5px; }
}

/* Landscape phones are too short for a bottom sheet: dock it to the side. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .panel {
    top: 0; bottom: 0; left: auto; height: 100%;
    width: min(56vw, 400px);
    border-radius: 16px 0 0 16px;
    padding-right: env(safe-area-inset-right);
    transform: none;
  }
  .sheet-handle { display: none; }
  .panel[data-snap="peek"] .view { overflow-y: auto; }
  .map-fabs { bottom: 16px; right: calc(min(56vw, 400px) + 14px); }
  /* Keep the attribution on the map, not under the docked panel. */
  .leaflet-bottom.leaflet-right { right: min(56vw, 400px); }
  .leaflet-bottom .leaflet-control-attribution { margin-bottom: 2px; }
}

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