* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1e2a24;
  --bg-elevated: #253028;
  --bg-hover: #2e3a30;
  --border: #3e4e40;
  --text: #d8d8c8;
  --text-muted: #a0a890;
  --text-dim: #687860;
  --accent: #d0d0c0;
  --warning: #c8b060;
  --danger: #c07070;
  --font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
  --mono: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(30,50,40,0.4) 0%, transparent 70%),
    radial-gradient(ellipse at 80% 50%, rgba(40,55,45,0.3) 0%, transparent 70%);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #b8c0a8;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---- Disclaimer banner ---- */

.disclaimer {
  background: #253028;
  border-bottom: 1px solid #3e4e40;
  padding: 0.6rem 2rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

/* ---- Layout ---- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

/* ---- Header ---- */

header {
  padding: 3rem 0 2rem;
}

header h1 {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
  text-decoration: underline;
  text-underline-offset: 6px;
  text-decoration-thickness: 1px;
  text-decoration-color: #687860;
}

header .subtitle {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  max-width: 600px;
}

header .intro {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 700px;
  line-height: 1.7;
}

/* ---- Tab Navigation ---- */

.tab-nav {
  display: flex;
  gap: 0;
  margin-top: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab-nav .tab {
  font-family: var(--font-display);
  color: var(--text-muted);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1.25rem;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  margin-bottom: -1px;
}
.tab-nav .tab:hover {
  color: var(--text);
  text-decoration: none;
}
.tab-nav .tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ---- Tab Content ---- */

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* All sections visible before JS runs (SEO/crawlers see all content) */
html:not(.js-ready) .tab-content {
  display: block;
}

/* ---- Graph Section ---- */

#family-tree {
  padding: 1rem 0 0;
}

#family-tree > .container {
  max-width: none;
  padding: 0;
}

#controls {
  padding: 0 2rem;
}

#graph-wrapper {
  display: flex;
  gap: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg-elevated);
}

#graph {
  flex: 1;
  height: calc(100vh - 160px);
  min-height: 500px;
  position: relative;
  cursor: grab;
}
#graph:active {
  cursor: grabbing;
}

#graph svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- Controls ---- */

#controls {
  display: flex;
  gap: 2rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.filter-group h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  transition: all 0.15s;
  user-select: none;
}
.filter-check:hover {
  border-color: var(--text-dim);
  color: var(--text);
}
.filter-check.active {
  border-color: var(--accent);
  color: var(--text);
}
.filter-check .swatch-line {
  flex-shrink: 0;
}

.confidence-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.confidence-control input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

.confidence-control .value {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--mono);
  min-width: 2.5rem;
}

/* ---- Detail Panel ---- */

#detail-panel {
  width: 340px;
  min-width: 340px;
  border-left: 1px solid var(--border);
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
  background: var(--bg);
}

#detail-panel .panel-placeholder {
  color: var(--text-dim);
  font-size: 0.875rem;
  font-style: italic;
  padding-top: 2rem;
  text-align: center;
}

#detail-panel h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

#detail-panel .org-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

#detail-panel .year {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

#detail-panel .description {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1rem;
}

#detail-panel .citation-link {
  font-size: 0.8rem;
  display: block;
  margin-bottom: 1.5rem;
  word-break: break-word;
}

#detail-panel .relationships-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

#detail-panel .relationship-item {
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.825rem;
  cursor: pointer;
  transition: background 0.15s;
}
#detail-panel .relationship-item:hover {
  background: var(--bg-hover);
  margin: 0 -1.5rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

#detail-panel .rel-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

#detail-panel .rel-model {
  color: var(--text);
  font-weight: 500;
}

.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-weight: 500;
}
.confidence-badge.high {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}
.confidence-badge.medium {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}
.confidence-badge.low {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Edge detail panel */
#detail-panel .edge-detail .edge-models {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
#detail-panel .edge-detail .edge-type-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
#detail-panel .edge-detail .explanation {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1rem;
}

/* ---- Graph Nodes ---- */

.node circle {
  stroke-width: 2px;
  cursor: pointer;
  transition: r 0.15s;
}
.node:hover circle {
  r: 22;
}
.node.selected circle {
  stroke: #fff;
  stroke-width: 3px;
}

.node text {
  font-size: 10px;
  fill: var(--text-muted);
  pointer-events: none;
  font-family: var(--font);
}

.node .org-mark {
  pointer-events: none;
}

.node .org-label {
  pointer-events: none;
}

.node .label-bg {
  fill: var(--bg-elevated);
  opacity: 0.85;
}

/* ---- Graph Edges ---- */

.edge {
  stroke-width: 1.5;
  cursor: pointer;
  transition: stroke-width 0.15s;
}
.edge:hover {
  stroke-width: 3;
}
.edge.selected {
  stroke-width: 3;
}
.edge.dimmed {
  opacity: 0.08 !important;
}
.node.dimmed circle {
  opacity: 0.15;
}
.node.dimmed text {
  opacity: 0.1;
}

/* Low confidence indicator */
.edge.low-confidence {
  animation: pulse-opacity 2s ease-in-out infinite;
}
@keyframes pulse-opacity {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

/* ---- Content Sections ---- */

#why-this-matters,
#methodology {
  padding: 2rem 0 4rem;
}

.content-body h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}

.content-body h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.content-body {
  max-width: 700px;
}

.content-body p {
  margin-bottom: 1rem;
  color: var(--text-muted);
  line-height: 1.75;
}

.content-body strong {
  color: var(--text);
  font-weight: 600;
}

.content-body ul {
  margin: 0.5rem 0 1rem 1.5rem;
  color: var(--text-muted);
}
.content-body li {
  margin-bottom: 0.4rem;
  line-height: 1.6;
}

.content-body h2, .content-body h3 {
  font-family: var(--font-display);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  text-decoration-color: #4e5e48;
  font-weight: 400;
}

.callout {
  border-left: 3px solid #a0a890;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  background: rgba(160,168,144,0.06);
  border-radius: 0 6px 6px 0;
}
.callout p {
  margin-bottom: 0;
  color: var(--text);
  font-size: 0.95rem;
}

/* ---- Confidence Legend ---- */

.confidence-scale {
  display: flex;
  gap: 1.5rem;
  margin: 1rem 0;
}
.confidence-scale .level {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.confidence-scale .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* ---- Footer ---- */

footer {
  padding: 3rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.875rem;
}
footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
footer .footer-left p {
  margin-bottom: 0.25rem;
}

.report-error-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: all 0.2s;
}
.report-error-btn:hover {
  border-color: #c07070;
  color: #c07070;
  text-decoration: none;
}

.score-section h3, .filter-group h3,
#detail-panel .relationships-title {
  font-family: var(--font-display);
}

/* ---- Score Sections ---- */

.score-section {
  margin-top: 2.5rem;
}
.score-section h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.score-section > p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  max-width: 700px;
}

/* Heatmap */
.heatmap-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.75rem;
}
.heatmap-table {
  border-collapse: collapse;
  font-size: 0.75rem;
  font-family: var(--mono);
}
.heatmap-table th,
.heatmap-table td {
  padding: 0;
  text-align: center;
  vertical-align: middle;
}
.heatmap-corner {
  width: 110px;
  min-width: 110px;
}
.heatmap-col-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 0.4rem 0.25rem;
  font-size: 0.7rem;
  font-family: var(--font);
  font-weight: 500;
  white-space: nowrap;
}
.heatmap-row-label {
  text-align: right !important;
  padding-right: 0.6rem !important;
  font-family: var(--font);
  font-weight: 500;
  font-size: 0.75rem;
  white-space: nowrap;
  width: 110px;
  min-width: 110px;
}
.heatmap-cell {
  width: 42px;
  min-width: 42px;
  height: 36px;
  color: rgba(255,255,255,0.85);
  font-weight: 600;
  cursor: default;
  border: 1px solid var(--bg);
  transition: transform 0.1s;
}
.heatmap-cell:hover:not(.self) {
  outline: 2px solid var(--text);
  z-index: 1;
  position: relative;
}
.heatmap-cell.self {
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-weight: 400;
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.heatmap-gradient {
  flex: 1;
  max-width: 200px;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, hsl(0,70%,28%), hsl(40,70%,32%), hsl(80,70%,36%), hsl(120,70%,40%));
}

/* Inbreeding chart */
.inbreeding-list {
  max-width: 700px;
}
.inbreeding-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0;
  opacity: 0.45;
}
.inbreeding-row.frontier {
  opacity: 1;
}
.inbreeding-label {
  width: 180px;
  min-width: 180px;
  text-align: right;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.inbreeding-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
}
.inbreeding-org {
  font-size: 0.65rem;
}
.inbreeding-track {
  flex: 1;
  height: 14px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}
.inbreeding-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.inbreeding-val {
  width: 36px;
  min-width: 36px;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text-muted);
  text-align: right;
}

/* Optimizer */
.opt-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.opt-controls label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.opt-controls select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
}
.opt-controls select:focus {
  outline: none;
  border-color: var(--accent);
}
.panel-card {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: var(--bg-elevated);
}
.panel-rank {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 2rem;
  padding-top: 0.15rem;
}
.panel-body {
  flex: 1;
}
.panel-models {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.panel-model {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.pm-name {
  font-weight: 600;
  font-size: 0.85rem;
}
.pm-org {
  font-size: 0.7rem;
}
.pm-score {
  font-size: 0.7rem;
  font-family: var(--mono);
}
.panel-meta {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.panel-meta strong {
  font-family: var(--mono);
  margin-left: 0.25rem;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
  #graph-wrapper {
    flex-direction: column;
  }
  #detail-panel {
    width: 100%;
    min-width: 100%;
    max-height: 300px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  #graph {
    height: 500px;
  }
  header h1 {
    font-size: 2rem;
  }
  #controls {
    flex-direction: column;
    gap: 1rem;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 0 1rem;
  }
  header {
    padding: 2rem 0 1.5rem;
  }
  #graph {
    height: 400px;
  }
  #detail-panel {
    padding: 1rem;
  }
  .filter-checks {
    gap: 0.25rem;
  }
  .filter-check {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }
}
