:root {
  color-scheme: light;
  --bg: #f4f7f1;
  --surface: #ffffff;
  --surface-2: #eef3ea;
  --text: #1d2a20;
  --muted: #5d6b5f;
  --border: #d8e0d2;
  --accent: #2e7d4f;
  --accent-strong: #20603b;
  --accent-soft: #e2f0e6;
  --danger: #b23b3b;
  --danger-soft: #fbe6e6;
  --ok: #2e7d4f;
  --ok-soft: #e2f0e6;
  --shadow: 0 1px 3px rgba(20, 40, 25, .08), 0 8px 24px rgba(20, 40, 25, .06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12160f;
    --surface: #1b211a;
    --surface-2: #232b21;
    --text: #e8efe4;
    --muted: #9aa894;
    --border: #2f3a2c;
    --accent: #6bbf8b;
    --accent-strong: #8fd3a8;
    --accent-soft: #23331f;
    --danger: #ef8a8a;
    --danger-soft: #3a2222;
    --ok: #6bbf8b;
    --ok-soft: #22331f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a { color: var(--accent); }
img { max-width: 100%; display: block; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: .2px;
}
.brand-icon { width: 26px; height: 26px; fill: var(--accent); }

#nav { display: flex; gap: 6px; flex-wrap: wrap; }
#nav button {
  font: inherit;
  font-size: .92rem;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
#nav button:hover { background: var(--surface-2); color: var(--text); }
#nav button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

/* -------------------------------------------------------------------- main */
main {
  flex: 1;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 24px) 60px;
}

.loading { color: var(--muted); }
.muted { color: var(--muted); }

h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.25rem; margin: 0 0 6px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 24px; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ------------------------------------------------------------------- start */
.hero { text-align: center; padding: 12px 0 4px; }
.hero .badge {
  display: inline-block;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 12px;
  margin-bottom: 14px;
}
.hero p { max-width: 560px; margin: 0 auto 26px; color: var(--muted); }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 12px 20px;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .55; cursor: default; }

.hero .cats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 0 0 22px; }
.cats-hint { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }
.chip {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chip span { font-weight: 400; opacity: .7; }
.note {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .9rem;
  margin: 10px auto 0;
  max-width: 560px;
}

.badge.edibility {
  display: inline-block;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  border-radius: 999px;
  padding: 4px 11px;
  margin-left: 4px;
}
.badge.edibility.ok { background: var(--accent-soft); color: var(--accent-strong); }
.badge.edibility.warn { background: #fff2d6; color: #9a6b00; }
.badge.edibility.danger { background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .badge.edibility.warn { background: #3a2f16; color: #e3b15a; }
}

.section-title { margin: 34px 0 14px; font-size: 1.2rem; }

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 30px;
}
.fact { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; }
.fact b { display: block; font-size: 1.4rem; }
.fact span { color: var(--muted); font-size: .88rem; }

/* -------------------------------------------------------------------- quiz */
.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: .92rem;
  color: var(--muted);
}
.progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  flex: 1;
  max-width: 260px;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s ease;
}

.question-image {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  background: var(--surface-2);
  border-radius: 12px;
}
.q-caption { text-align: center; color: var(--muted); font-size: .9rem; margin: 10px 0 18px; }
.q-title { font-size: 1.25rem; font-weight: 700; text-align: center; margin: 0 0 16px; }

.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 560px) { .options { grid-template-columns: 1fr; } }

.option {
  font: inherit;
  text-align: left;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color .15s ease, background .15s ease;
}
.option:hover:not([disabled]) { border-color: var(--accent); }
.option .key {
  flex: none;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--surface-2);
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}
.option.correct { background: var(--ok-soft); border-color: var(--ok); }
.option.correct .key { background: var(--ok); color: #fff; }
.option.wrong { background: var(--danger-soft); border-color: var(--danger); }
.option.wrong .key { background: var(--danger); color: #fff; }
.option[disabled] { cursor: default; }

.quiz-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 12px; font-weight: 600; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--danger-soft); color: var(--danger); }
.feedback small { display: block; font-weight: 400; margin-top: 4px; color: var(--text); opacity: .85; }

/* ------------------------------------------------------------------ detail */
.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 4px; }
.detail-head h2 { margin: 0; }
.sci { font-style: italic; color: var(--muted); }
.family { color: var(--muted); font-size: .92rem; margin: 0 0 18px; }

.detail-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 680px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-image { width: 100%; border-radius: 12px; background: var(--surface-2); }

.habits { list-style: none; margin: 0 0 16px; padding: 0; }
.habits li { position: relative; padding-left: 26px; margin-bottom: 8px; }
.habits li::before {
  content: "";
  position: absolute; left: 4px; top: .55em;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.description { color: var(--text); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 18px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.gallery figcaption { font-size: .78rem; color: var(--muted); margin-top: 4px; }

.credits { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); font-size: .78rem; color: var(--muted); }
.credits li { margin-bottom: 3px; }

/* ------------------------------------------------------------------ browse */
.species-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.species-card {
  font: inherit;
  text-align: left;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .1s ease, border-color .15s ease;
}
.species-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.species-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.species-card .body { padding: 10px 12px 14px; }
.species-card b { display: block; }
.species-card span { font-size: .82rem; color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- result */
.result { text-align: center; }
.result .score { font-size: 3rem; font-weight: 800; color: var(--accent); line-height: 1; margin: 10px 0; }
.result .verdict { font-size: 1.15rem; margin-bottom: 24px; }

/* ---------------------------------------------------------------- footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px clamp(16px, 4vw, 40px);
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
}
.footer p { margin: 2px 0; }

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

.fade { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
