:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1c1d1a;
  --ink-2: #55574f;
  --ink-3: #6c6f65;
  --line: #e1ded4;
  --grid: #eae7de;
  --accent: #266b4e;
  --accent-ink: #ffffff;
  --male: #2b6cb0;
  --female: #b84276;
  --extinct: #8a5a2b;
  --shadow: 0 1px 2px rgba(25, 35, 25, .06), 0 4px 16px rgba(25, 35, 25, .05);
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #131512; --surface: #1b1e1a; --surface-2: #242822; --ink: #eef0ea; --ink-2: #b5bab0;
  --ink-3: #92988c; --line: #31362e; --grid: #252923; --accent: #4aa87f; --male: #6ea4e6;
  --female: #e77fab; --extinct: #d29457;
  --shadow: 0 1px 2px rgba(0,0,0,.35); color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131512; --surface: #1b1e1a; --surface-2: #242822; --ink: #eef0ea; --ink-2: #b5bab0;
    --ink-3: #92988c; --line: #31362e; --grid: #252923; --accent: #4aa87f; --male: #6ea4e6;
    --female: #e77fab; --extinct: #d29457;
    --shadow: 0 1px 2px rgba(0,0,0,.35); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--ink-3); font-weight: 500; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: none; color: var(--accent); }
.brand svg { width: 22px; height: 22px; fill: var(--accent); flex: none; }
.nav-search { position: relative; flex: 1 1 200px; max-width: 300px; }
.nav-search input { width: 100%; padding: 7px 12px 7px 34px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13.5px; outline: none; }
.nav-search input:focus { border-color: var(--accent); }
.topnav { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.topnav a { color: var(--ink-2); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: 8px; text-decoration: none; }
.topnav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topnav a.nav-cta { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.topnav a.nav-cta:hover { filter: brightness(1.06); }
.theme-btn { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; display: grid; place-items: center; color: var(--ink-2); }
.theme-btn:hover { border-color: var(--ink-3); color: var(--ink); }

.site-header { padding: 32px 0 18px; }
.site-header h1 { font-family: var(--font-display); font-size: clamp(28px, 4.2vw, 44px); line-height: 1.1; margin: 0 0 8px; letter-spacing: -.01em; }
.lede { margin: 0; color: var(--ink-2); max-width: 700px; font-size: 16px; }

.panel, .card, .stage-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 16px; margin-bottom: 16px; }
.card { padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

/* Search & presets */
.add-row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.search-box { position: relative; flex: 1 1 300px; }
.search-icon { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); fill: var(--ink-3); pointer-events: none; }
#quick-search { width: 100%; padding: 11px 14px 11px 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); outline: none; }
#quick-search:focus { border-color: var(--accent); background: var(--surface); }
.quick-results { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.14); max-height: 340px; overflow: auto; }
.quick-results li { padding: 8px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.quick-results li[aria-selected="true"], .quick-results li:hover { background: var(--surface-2); }
.quick-results small { color: var(--ink-3); white-space: nowrap; font-size: 12px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button, .btn-ghost { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.presets button:hover, .btn-ghost:hover { border-color: var(--ink-3); color: var(--ink); }
.btn { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 9px 16px; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Chips */
.chips { list-style: none; margin: 14px 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: flex; align-items: center; gap: 7px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); font-size: 13.5px; }
.chip .num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; flex: none; }
.chip .name { font-weight: 600; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .pill-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 9px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chip .pill-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip .mini-seg { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.chip .mini-seg button { border: 0; background: transparent; padding: 0 8px; min-width: 26px; min-height: 26px; cursor: pointer; font-size: 12px; color: var(--ink-3); }
.chip .mini-seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.chip .x { border: 0; background: transparent; cursor: pointer; width: 26px; height: 26px; border-radius: 50%; color: var(--ink-3); font-size: 16px; line-height: 1; }
.chip .x:hover { background: var(--line); color: var(--ink); }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 14px 20px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.control { display: flex; flex-direction: column; gap: 6px; }
.control-label { font-size: 11.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.ref-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ref-ctl select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.ref-ctl input[type=range] { width: 110px; accent-color: var(--accent); }
.ref-ctl output { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 72px; }

/* Stage */
.stage-card { padding: 14px 16px 16px; margin-bottom: 16px; overflow: hidden; }
.stage-meta { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); }
.stage-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
#stage-svg { display: block; width: 100%; min-width: 680px; height: auto; }
.stage-legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.badge-extinct { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--extinct) 16%, transparent); color: var(--extinct); margin-left: 6px; vertical-align: middle; }

/* Weight ratio bar */
.ratio-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.ratio-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.ratio-big { font-family: var(--font-display); font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.ratio-sub { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

/* Data tables */
.table-wrap { overflow-x: auto; }
table.specs { width: 100%; border-collapse: collapse; font-size: 14px; }
table.specs th, table.specs td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); }
table.specs th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 650; }
table.specs td.num-col { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Speed Race */
.race-controls { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; margin-bottom: 16px; }
.race-selects { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.race-selects label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.race-selects select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.race-bench { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 14px; font-size: 13.5px; color: var(--ink-2); }
.race-bench label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.race-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.race-clock { font-variant-numeric: tabular-nums; font-family: var(--font-display); font-size: 22px; font-weight: 700; min-width: 90px; }
.lanes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lane { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.lane-ref { border-style: dashed; }
.lane-lbl { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.lane-v { font-size: 13px; color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.lane-track { position: relative; height: 42px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lane-track::after { content: ""; position: absolute; right: 44px; top: 0; bottom: 0; border-right: 2px dashed var(--line); }
.runner { position: absolute; left: 8px; top: 50%; transform: translate(calc(var(--x, 0) * 1px), -50%); display: flex; align-items: center; will-change: transform; }
.runner svg { height: 32px; width: auto; max-width: 64px; }
.lane-time { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--accent); background: var(--surface); padding: 2px 6px; border-radius: 6px; }
.race-result { margin-top: 14px; font-size: 14px; color: var(--ink-2); }

/* Directory / Profile / Compare cards */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.animal-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s; }
.animal-card:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.animal-card .thumb { height: 84px; display: flex; align-items: flex-end; justify-content: center; background: var(--surface-2); border-radius: 10px; padding: 10px; }
.animal-card .thumb svg { max-height: 64px; max-width: 100%; }
.animal-card h3 { margin: 0; font-size: 15.5px; }
.animal-card .meta { font-size: 12.5px; color: var(--ink-3); }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 14px 0; }
.fact-tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.fact-tile .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 650; }
.fact-tile .v { font-size: 17px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.filter-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-pills button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 13px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.filter-pills button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Footer */
.site-footer { margin-top: 40px; padding: 26px 0 40px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 13.5px; }
.footer-in { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--ink-2); }

@media (max-width: 680px) {
  .nav-search { order: 3; flex: 1 1 100%; max-width: none; }
  .site-header { padding: 20px 0 14px; }
}
