:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #657169;
  --line: #cfd8d1;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --moss: #315f47;
  --moss-2: #e7f0e4;
  --water: #316a7a;
  --amber: #b46b18;
  --shadow: 0 10px 22px rgba(22, 33, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px 12px;
  background: rgba(247, 248, 244, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--moss);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.4vw, 2.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.deck-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.deck-stats span {
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.deck-stats strong {
  color: var(--ink);
}

main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 14px 18px 32px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(210px, 320px) 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.search input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.94rem;
  outline: none;
}

.search input:focus {
  border-color: var(--moss);
  box-shadow: 0 0 0 3px rgba(49, 95, 71, 0.14);
}

.segmented {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.segmented button,
.toggle {
  min-height: 40px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 750;
}

.segmented button {
  padding: 0 11px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--moss);
  color: white;
  border-color: var(--moss);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--moss);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.species-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.image-wrap {
  position: relative;
  height: 190px;
  background: #dfe7df;
  border-bottom: 1px solid var(--line);
}

.image-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-wrap.placeholder {
  display: grid;
  place-items: center;
  padding: 14px;
  color: #466052;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.image-wrap.placeholder::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(70, 96, 82, 0.45);
  border-radius: 7px;
}

.card-body {
  padding: 13px;
}

.card-kicker {
  display: inline-flex;
  max-width: 100%;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--moss-2);
  color: var(--moss);
  font-size: 0.64rem;
  font-weight: 850;
}

h2 {
  margin: 8px 0 2px;
  font-size: 1.24rem;
  line-height: 1.08;
  letter-spacing: 0;
}

.scientific {
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.2;
}

.stats {
  display: grid;
  grid-template-columns: 0.82fr 0.82fr 1.36fr;
  gap: 8px;
}

.stat-bubble {
  min-height: 48px;
  padding: 7px 8px;
  border: 1px solid #d5decd;
  border-radius: 8px;
  background: #fbfaf3;
}

.stat-bubble span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 850;
  text-transform: uppercase;
}

.stat-bubble strong {
  display: block;
  min-width: 0;
  color: var(--ink);
  font-size: 0.8rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.habitat-ribbon {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #c8d8dd;
  border-left: 5px solid var(--water);
  border-radius: 8px;
  background: #edf6f7;
}

.habitat-ribbon span {
  color: var(--water);
  font-size: 0.6rem;
  font-weight: 950;
  text-transform: uppercase;
}

.habitat-ribbon strong {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 820;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.facts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 10px;
}

.fact-bubble {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: start;
  gap: 7px;
  min-height: 30px;
  padding: 6px 8px;
  border: 1px solid var(--fact-border, #d8e3dc);
  border-left: 4px solid var(--fact-accent, #9fbea7);
  border-radius: 8px;
  background: var(--fact-bg, #eef5ed);
}

.fact-bubble span {
  color: var(--fact-label, var(--moss));
  font-size: 0.52rem;
  font-weight: 900;
  line-height: 1.15;
  text-transform: uppercase;
}

.fact-bubble strong {
  min-width: 0;
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 750;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.fact-bubble:nth-child(1) {
  --fact-bg: #eef6e8;
  --fact-border: #d8e8cf;
  --fact-accent: #93b56f;
  --fact-label: #527231;
}

.fact-bubble:nth-child(2) {
  --fact-bg: #f6f2df;
  --fact-border: #e7deb3;
  --fact-accent: #c7a94f;
  --fact-label: #745f16;
}

.fact-bubble:nth-child(3) {
  --fact-bg: #f7eee6;
  --fact-border: #ead6c7;
  --fact-accent: #c98e63;
  --fact-label: #7c4a2b;
}

.fact-bubble:nth-child(4) {
  --fact-bg: #f4ecef;
  --fact-border: #e5ccd4;
  --fact-accent: #bd7d91;
  --fact-label: #744052;
}

.fact-bubble:nth-child(5) {
  --fact-bg: #eef1f8;
  --fact-border: #d2d9ec;
  --fact-accent: #7d91c0;
  --fact-label: #40557d;
}

.fact-bubble:nth-child(6) {
  --fact-bg: #edf5f5;
  --fact-border: #cfe3e2;
  --fact-accent: #6fa9a5;
  --fact-label: #356d69;
}

.fact-bubble:nth-child(7) {
  --fact-bg: #eff1ea;
  --fact-border: #d9ddcf;
  --fact-accent: #93a16d;
  --fact-label: #566235;
}

.card-note {
  margin: 10px 0 0;
  color: #39453d;
  display: -webkit-box;
  font-size: 0.76rem;
  line-height: 1.32;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.source-link {
  display: inline-flex;
  margin-top: 8px;
  color: var(--water);
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.source-link[hidden] {
  display: none;
}

.empty {
  grid-column: 1 / -1;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    display: grid;
    padding: 14px;
  }

  .deck-stats {
    justify-content: flex-start;
  }

  main {
    padding: 12px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

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

  .image-wrap {
    height: 220px;
  }

  .stats {
    grid-template-columns: 0.82fr 0.82fr 1.36fr;
  }

  .stat-bubble {
    min-height: 46px;
    padding: 6px 7px;
  }

  .stat-bubble strong {
    font-size: 0.82rem;
  }

  .habitat-ribbon {
    grid-template-columns: 66px 1fr;
  }

  .fact-bubble {
    grid-template-columns: 74px 1fr;
  }
}
