:root {
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-2: #eef0e8;
  --text: #1f2a1f;
  --muted: #5d6b5d;
  --line: #dde1d5;
  --accent: #2f6b3a;
  --accent-text: #ffffff;
  --accent-soft: #e1eddf;
  --chip-on: #2f6b3a;
  --shadow: 0 1px 2px rgba(20, 40, 20, .06), 0 4px 14px rgba(20, 40, 20, .06);
  --gymno: #3f6e5a;
  --angio: #6f8a3a;
  --other: #7a6a4f;
  --radius: 10px;

  /* Hero over the forest photo */
  --hero-title: #173d22;
  --hero-sub: #2c4a33;
  --overlay: linear-gradient(180deg, rgba(255, 255, 255, .25) 0%, rgba(255, 255, 255, 0) 35%, rgba(10, 30, 15, .35) 100%);
  --glass: rgba(255, 255, 255, .84);
  --glass-line: rgba(255, 255, 255, .6);
  --panel: rgba(246, 245, 240, .97);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131813;
    --surface: #1b221b;
    --surface-2: #232c23;
    --text: #e4eae0;
    --muted: #9aa897;
    --line: #2f3a2e;
    --accent: #7fbf7f;
    --accent-text: #0e170e;
    --accent-soft: #243524;
    --chip-on: #7fbf7f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --gymno: #2c5245;
    --angio: #4c6229;
    --other: #5a4d38;
    --hero-title: #f2f6ef;
    --hero-sub: #d6e2d2;
    --overlay: linear-gradient(180deg, rgba(8, 14, 9, .55) 0%, rgba(8, 14, 9, .7) 100%);
    --glass: rgba(22, 30, 22, .82);
    --glass-line: rgba(255, 255, 255, .08);
    --panel: rgba(19, 24, 19, .97);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Fixed background photo (a pseudo-element, because background-attachment: fixed is unreliable on phones) */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background: var(--overlay), url("../assets/forest-bg.jpg") center 30% / cover no-repeat, #4b6b52;
}
button, input, select { font: inherit; color: inherit; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Hero: title, search, filters ---------- */
.hero { padding: 56px 16px 28px; }
.hero-inner { max-width: 880px; margin: 0 auto; text-align: center; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--hero-title); text-decoration: none;
  font-size: clamp(30px, 5vw, 44px); font-weight: 700; letter-spacing: -.01em;
  text-shadow: 0 1px 12px rgba(255, 255, 255, .35);
}
.brand svg { width: 1em; height: 1em; fill: currentColor; }
.tagline { margin: 4px 0 22px; color: var(--hero-sub); font-size: 17px; }

.search-box { position: relative; max-width: 680px; margin: 0 auto; }
.search-box svg { position: absolute; left: 18px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: var(--muted); }
.search-box input {
  width: 100%; padding: 15px 20px 15px 50px; font-size: 17px;
  border: 1px solid var(--glass-line); border-radius: 999px;
  background: var(--surface); box-shadow: 0 6px 24px rgba(10, 30, 15, .18);
}
.search-box input:focus { outline: 3px solid var(--accent); outline-offset: 2px; }

.filter-toggle {
  display: none; margin: 14px auto 0;
  border: 1px solid var(--glass-line); background: var(--glass); border-radius: 999px; padding: 8px 18px; cursor: pointer;
}

.filters {
  margin-top: 18px; text-align: left;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--glass-line); border-radius: 16px;
  padding: 18px 20px 14px;
  box-shadow: 0 6px 24px rgba(10, 30, 15, .15);
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 14px; }
.filter-group { margin: 0; min-width: 0; }
.select-group label, .facet-label {
  display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.select-group label { margin-bottom: 5px; }
.select-group select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.filter-group.chips {
  display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: start;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.facet-label { padding-top: 5px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 3px 11px; font-size: 13px; cursor: pointer;
}
.chip .n { color: var(--muted); font-size: 12px; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: var(--accent-text); }
.chip.on .n { color: inherit; opacity: .8; }
.chip.dim { opacity: .45; }

.filters-foot {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  border-top: 1px solid var(--line); padding-top: 10px;
}
.more-filters { flex: 1; }
.more-filters summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.more-filters[open] summary { margin-bottom: 4px; }
.more-filters .filter-group.chips:first-child { border-top: 0; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; white-space: nowrap; }

/* ---------- Results ---------- */
.results {
  max-width: 1400px; margin: 0 auto 48px;
  background: var(--panel); border-radius: 16px;
  padding: 18px 20px 28px;
  box-shadow: 0 6px 30px rgba(10, 30, 15, .2);
}
.results-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.count { margin: 0; color: var(--muted); }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sort select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.active-filters:empty { margin: 6px 0; }
.pill {
  border: 0; background: var(--accent-soft); color: var(--text); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.pill span { margin-left: 2px; font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; color: inherit; text-decoration: none; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-count {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); color: #fff;
  font-size: 12px; padding: 1px 7px; border-radius: 999px;
}
.placeholder {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--other); color: rgba(255, 255, 255, .85);
}
.placeholder svg { width: 42%; max-width: 90px; fill: rgba(255, 255, 255, .25); }
.placeholder.clade-gymnosperm { background: var(--gymno); }
.placeholder.clade-angiosperm { background: var(--angio); }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.card h3 { margin: 0; font-size: 16px; font-weight: 600; }
.common { margin: 0; }
.muted { color: var(--muted); font-style: italic; }
.meta { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag { background: var(--surface-2); border-radius: 4px; padding: 1px 6px; font-size: 12px; color: var(--muted); }
.empty, .load-error { padding: 40px 16px; text-align: center; color: var(--muted); }
.load-error { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--text); }

/* ---------- Detail dialog ---------- */
.detail {
  width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.detail::backdrop { background: rgba(10, 20, 10, .55); }
.detail-inner { padding: 12px 20px 24px; }
.detail-top { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.detail-top .pos { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.close { margin-left: auto; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.gallery .main-img { width: 100%; max-height: 460px; object-fit: contain; background: var(--surface-2); border-radius: var(--radius); display: block; }
.gallery.no-img .placeholder { aspect-ratio: 4 / 3; border-radius: var(--radius); }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumb-btn { padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; width: 64px; height: 64px; background: none; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-btn.on { border-color: var(--accent); }
.info h2 { margin: 0; font-size: 26px; font-weight: 600; }
.common.big { font-size: 17px; margin: 2px 0 12px; }
.desc { margin: 0 0 16px; }
.info dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.facet-link {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 0 8px; cursor: pointer; font-size: 13px;
}
.facet-link:hover { border-color: var(--accent); color: var(--accent); }
.note { color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .hero { padding: 32px 16px 20px; }
  .tagline { font-size: 15px; margin-bottom: 16px; }
  .search-box input { font-size: 16px; padding: 13px 16px 13px 46px; }
  .filter-toggle { display: inline-block; }
  .filters { display: none; padding: 14px; }
  body.filters-open .filters { display: block; }
  .filter-row { grid-template-columns: 1fr; }
  .filter-group.chips { grid-template-columns: 1fr; gap: 6px; }
  .facet-label { padding-top: 0; }
  .results { margin: 0 8px 32px; padding: 14px 12px 20px; border-radius: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-inner { padding: 10px 14px 20px; }
}
