/* ===== DESIGN TOKENS ===== */
:root {
  --hue-primary: 25;
  --hue-secondary: 340;
  --hue-accent: 170;
  --hue-success: 145;
  --hue-warn: 45;
  --hue-error: 15;

  --bg: #0f0f1a;
  --bg-elevated: #1a1a2e;
  --bg-card: #1e1e35;
  --bg-hover: #2a2a45;
  --bg-input: #16162a;
  --text: #e8e6f0;
  --text-dim: #9896a8;
  --text-muted: #6a6880;
  --border: #2e2e4a;
  --border-light: #3a3a5a;
  --primary: hsl(var(--hue-primary), 75%, 65%);
  --primary-dim: hsl(var(--hue-primary), 60%, 50%);
  --secondary: hsl(var(--hue-secondary), 55%, 65%);
  --accent: hsl(var(--hue-accent), 55%, 55%);
  --success: hsl(var(--hue-success), 55%, 55%);
  --warn: hsl(var(--hue-warn), 70%, 60%);
  --error: hsl(var(--hue-error), 65%, 60%);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.4);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --transition: .2s cubic-bezier(.4,0,.2,1);
  --max-w: 1280px;
  --header-h: 64px;
}

[data-theme="light"] {
  --bg: #f5f3fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eeeaf5;
  --bg-input: #edeaf5;
  --text: #1a1830;
  --text-dim: #5a5870;
  --text-muted: #8a88a0;
  --border: #ddd8ea;
  --border-light: #ccc6de;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 4px 16px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: var(--text); }
img, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }

/* ===== SKIP LINK ===== */
.skip-link { position: absolute; top: -100%; left: 16px; background: var(--primary); color: #000; padding: 8px 16px; border-radius: var(--radius-sm); z-index: 9999; font-weight: 600; }
.skip-link:focus { top: 16px; }

/* ===== HEADER ===== */
.site-header { position: sticky; top: 0; z-index: 100; background: var(--bg-elevated); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px); height: var(--header-h); }
.header-inner { max-width: var(--max-w); margin: 0 auto; padding: 0 24px; height: 100%; display: flex; align-items: center; gap: 24px; }
.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-text { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }
.logo-text .accent { color: var(--primary); }
.main-nav { display: flex; gap: 4px; flex: 1; }
.nav-btn { padding: 8px 14px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500; color: var(--text-dim); transition: all var(--transition); }
.nav-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #000; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 600; transition: all var(--transition); white-space: nowrap; }
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-dim); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-outline { border: 1px solid var(--border-light); color: var(--text-dim); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.icon-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-dim); transition: all var(--transition); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: inherit; padding: 0; text-decoration: underline; }

/* ===== HERO ===== */
.hero { position: relative; padding: 80px 24px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; z-index: 0; }
.hero-mesh { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-noise { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hero-content { position: relative; z-index: 1; max-width: 700px; margin: 0 auto; text-align: center; }
.hero h2 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin-bottom: 16px; }
.hero-baseline { font-size: 1.1rem; color: var(--text-dim); margin-bottom: 32px; max-width: 560px; margin-left: auto; margin-right: auto; }
.hero-ctas { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 48px; }
.hero-stats { display: flex; gap: 48px; justify-content: center; }
.stat { text-align: center; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ===== SECTIONS ===== */
.section { max-width: var(--max-w); margin: 0 auto; padding: 48px 24px; }
.section-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.section-header h2 { font-size: 1.5rem; font-weight: 700; }
.section-actions { display: flex; gap: 8px; }
.section-desc { color: var(--text-dim); margin-bottom: 24px; font-size: .95rem; }

/* ===== FILTERS ===== */
.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-wrap input { width: 100%; padding: 10px 12px 10px 38px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .875rem; transition: all var(--transition); }
.search-wrap input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px hsla(var(--hue-primary), 75%, 65%, .15); }
.filter-chips { display: flex; gap: 4px; }
.chip { padding: 6px 14px; border-radius: 100px; font-size: .8rem; font-weight: 500; border: 1px solid var(--border); color: var(--text-dim); transition: all var(--transition); }
.chip:hover { border-color: var(--border-light); color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #000; font-weight: 600; }
.select-sm { padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .8rem; cursor: pointer; }
.select-sm:focus { outline: none; border-color: var(--primary); }
.results-info { font-size: .85rem; color: var(--text-muted); margin-bottom: 16px; min-height: 1.4em; }

/* ===== DINO GRID ===== */
.dino-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.dino-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: all var(--transition); cursor: pointer; }
.dino-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-light); }
.dino-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dino-card-art { height: 140px; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.dino-card-art svg { width: 100%; height: 100%; }
.dino-card-body { padding: 16px; }
.dino-card-body h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.dino-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.tag-period { background: hsla(var(--hue-accent), 55%, 55%, .15); color: var(--accent); }
.tag-diet { background: hsla(var(--hue-primary), 75%, 65%, .15); color: var(--primary); }
.tag-clade { background: hsla(var(--hue-secondary), 55%, 65%, .15); color: var(--secondary); }
.dino-card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dino-stat { font-size: .78rem; }
.dino-stat-label { color: var(--text-muted); display: block; }
.dino-stat-val { font-weight: 600; font-family: var(--font-mono); }

/* ===== TIMELINE ===== */
.timeline-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 24px; overflow-x: auto; }
.timeline-bar { display: flex; height: 48px; border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 24px; min-width: 600px; }
.era { display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; text-align: center; color: #fff; line-height: 1.3; }
.era small { font-weight: 400; opacity: .8; font-size: .75rem; }
.era-triassic { background: linear-gradient(135deg, #8b5e3c, #a0714f); flex: 51; }
.era-jurassic { background: linear-gradient(135deg, #2d6a4f, #40916c); flex: 56; }
.era-cretaceous { background: linear-gradient(135deg, #495057, #6c757d); flex: 79; }
.timeline-species { position: relative; min-height: 200px; min-width: 600px; }
.tl-species { position: absolute; transform: translateX(-50%); cursor: pointer; transition: all var(--transition); }
.tl-species:hover { z-index: 10; }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; margin: 0 auto 4px; border: 2px solid var(--bg-card); box-shadow: 0 0 0 2px currentColor; }
.tl-name { font-size: .65rem; text-align: center; white-space: nowrap; color: var(--text-dim); max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.tl-species:hover .tl-name { color: var(--text); max-width: none; overflow: visible; background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; z-index: 10; position: relative; }

/* ===== METHODS ===== */
.methods-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.method-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.method-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.method-card h3 .icon { font-size: 1.3rem; }
.formula { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; font-family: var(--font-mono); font-size: .9rem; margin: 12px 0; overflow-x: auto; color: var(--primary); }
.method-card p { font-size: .875rem; color: var(--text-dim); margin-bottom: 8px; }
.key-insight { background: hsla(var(--hue-primary), 75%, 65%, .08); border-left: 3px solid var(--primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 12px 16px; margin-top: 12px; font-size: .85rem; }
.key-insight strong { color: var(--primary); }
.param-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.param-row label { font-size: .8rem; color: var(--text-dim); min-width: 80px; }
.param-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.param-val { font-family: var(--font-mono); font-size: .85rem; color: var(--primary); min-width: 48px; text-align: right; }

/* ===== COMPARATOR ===== */
.comparator-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.comp-selection { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; min-height: 40px; }
.comp-chart { min-height: 300px; }
.comp-bar-group { display: flex; flex-direction: column; gap: 16px; }
.comp-bar-item { display: flex; align-items: center; gap: 12px; }
.comp-bar-label { min-width: 140px; font-size: .85rem; font-weight: 600; text-align: right; }
.comp-bar-track { flex: 1; height: 28px; background: var(--bg-input); border-radius: var(--radius-sm); overflow: hidden; position: relative; }
.comp-bar-fill { height: 100%; border-radius: var(--radius-sm); transition: width .6s cubic-bezier(.4,0,.2,1); display: flex; align-items: center; padding-left: 10px; font-size: .75rem; font-weight: 600; color: #000; min-width: fit-content; }
.comp-bar-val { font-family: var(--font-mono); font-size: .8rem; color: var(--text-dim); min-width: 80px; }

/* ===== DOCS ===== */
.doc-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 24px; }
.doc-tab { padding: 8px 16px; border-radius: var(--radius-sm); font-size: .85rem; font-weight: 500; color: var(--text-dim); border: 1px solid var(--border); transition: all var(--transition); }
.doc-tab:hover { color: var(--text); border-color: var(--border-light); }
.doc-tab.active { background: var(--primary); border-color: var(--primary); color: #000; font-weight: 600; }
.doc-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; font-size: .925rem; line-height: 1.75; }
.doc-content h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.doc-content h2 { font-size: 1.25rem; font-weight: 700; margin: 28px 0 12px; color: var(--primary); }
.doc-content h3 { font-size: 1.05rem; font-weight: 600; margin: 20px 0 8px; }
.doc-content p { margin-bottom: 12px; color: var(--text-dim); }
.doc-content ul, .doc-content ol { margin: 8px 0 16px 24px; }
.doc-content li { margin-bottom: 6px; color: var(--text-dim); list-style: disc; }
.doc-content code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: .85em; color: var(--primary); }
.doc-content pre { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; overflow-x: auto; margin: 12px 0; }
.doc-content pre code { background: none; padding: 0; }
.doc-content blockquote { border-left: 3px solid var(--primary); padding: 8px 16px; margin: 12px 0; background: hsla(var(--hue-primary), 75%, 65%, .05); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.doc-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.doc-content th, .doc-content td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; font-size: .85rem; }
.doc-content th { background: var(--bg-input); font-weight: 600; }
.doc-content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ===== TESTS ===== */
.tests-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.test-suite { margin-bottom: 24px; }
.test-suite h3 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.test-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 4px; font-size: .85rem; }
.test-item.pass { background: hsla(var(--hue-success), 55%, 55%, .08); }
.test-item.fail { background: hsla(var(--hue-error), 65%, 60%, .08); }
.test-icon { flex-shrink: 0; font-size: 1rem; margin-top: 1px; }
.test-name { font-weight: 600; }
.test-detail { color: var(--text-muted); font-size: .8rem; margin-top: 2px; font-family: var(--font-mono); }
.test-summary { display: flex; gap: 16px; margin-bottom: 24px; padding: 16px; background: var(--bg-input); border-radius: var(--radius-sm); }
.test-summary-item { text-align: center; }
.test-summary-val { font-size: 1.4rem; font-weight: 800; }
.test-summary-label { font-size: .75rem; color: var(--text-muted); }
.test-summary-val.pass { color: var(--success); }
.test-summary-val.fail { color: var(--error); }

/* ===== MODAL ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); max-width: 720px; width: 100%; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn .25s ease; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1.2rem; font-weight: 700; }
.modal-close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-dim); font-size: 1.1rem; transition: all var(--transition); }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 24px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.detail-item { background: var(--bg-input); padding: 12px; border-radius: var(--radius-sm); }
.detail-item label { display: block; font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.detail-item value { font-family: var(--font-mono); font-size: .95rem; font-weight: 600; }
.detail-calc { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-top: 16px; }
.detail-calc h4 { font-size: .9rem; font-weight: 600; margin-bottom: 8px; color: var(--primary); }
.detail-calc-steps { font-family: var(--font-mono); font-size: .82rem; line-height: 1.8; color: var(--text-dim); }
.detail-calc-steps .step { display: flex; gap: 8px; }
.detail-calc-steps .step-num { color: var(--text-muted); min-width: 20px; text-align: right; }
.detail-calc-steps .step-val { color: var(--text); }
.detail-sources { margin-top: 16px; font-size: .8rem; color: var(--text-muted); }
.detail-sources a { color: var(--primary); }

/* ===== TOOLTIP ===== */
.tooltip { position: fixed; z-index: 300; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: .8rem; box-shadow: var(--shadow); pointer-events: none; max-width: 260px; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 20px; font-size: .85rem; box-shadow: var(--shadow-lg); animation: toastIn .3s ease; display: flex; align-items: center; gap: 8px; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ===== FOOTER ===== */
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 40px 24px; }
.footer-inner { max-width: var(--max-w); margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 32px; }
.footer-section h4 { font-size: .9rem; font-weight: 700; margin-bottom: 8px; }
.footer-section p, .footer-section li { font-size: .82rem; color: var(--text-muted); margin-bottom: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 12px; gap: 8px; }
  .main-nav { display: none; }
  .hero { padding: 48px 16px; }
  .hero-stats { gap: 24px; }
  .section { padding: 32px 16px; }
  .dino-grid { grid-template-columns: 1fr; }
  .methods-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .search-wrap { max-width: none; }
  .filter-chips { overflow-x: auto; }
}

/* ===== FOCUS ===== */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px; }

/* ===== CHARTS ===== */
.chart-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
.chart-container h4 { font-size: .9rem; font-weight: 600; margin-bottom: 12px; }
.chart-svg { width: 100%; overflow: visible; }
.bar-rect { transition: opacity var(--transition); }
.bar-rect:hover { opacity: .8; }
.axis-text { font-size: 10px; fill: var(--text-muted); }
.grid-line { stroke: var(--border); stroke-dasharray: 3 3; }
