/* One Origin — styles for the four interactive origin modules
   (05 lineage map, 06 shared-DNA counter, 07 kinship distance, 08 heritage grid)
   and for the site features modal.

   Everything here is driven by the shared theme variables from theme.css, so both
   the light and dark palettes work without duplicated rules. Animations are
   disabled wholesale under `prefers-reduced-motion: reduce` at the bottom. */

.inner--wide { max-width: 1020px; }

/* ---------- shared module controls ---------- */
.mod-controls {
  display: flex; flex-wrap: wrap; gap: .6em; align-items: center;
  margin: 1.5em 0 0 0;
}
.mod-controls .label {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--sand-dim);
}
.chip {
  font-family: var(--mono); font-size: .74rem; line-height: 1.1;
  padding: .5em .9em; border: 1px solid var(--hair); border-radius: 999px;
  background: transparent; color: var(--sand-dim); cursor: pointer;
  transition: border-color .2s ease, color .2s ease, background-color .2s ease, transform .2s ease;
}
.chip:hover { border-color: var(--clay); color: var(--sand); transform: translateY(-1px); }
.chip[aria-pressed="true"], .chip.is-active {
  border-color: var(--gold); color: var(--gold); background: rgba(184, 94, 55, .1);
}
.chip:disabled { opacity: .45; cursor: default; transform: none; }
.mod-field { display: flex; align-items: baseline; gap: .5em; flex-wrap: wrap; }
.mod-field label { font-family: var(--mono); font-size: .7rem; color: var(--sand-dim); text-transform: uppercase; letter-spacing: .08em; }
.mod-input, .mod-select {
  font-family: var(--mono); font-size: .86rem; color: var(--sand);
  padding: .5em .7em; border: 1px solid var(--hair); border-radius: 6px;
  background: var(--void-2); min-width: 12ch;
}
.mod-input:focus-visible, .mod-select:focus-visible { border-color: var(--gold); }
.mod-input.is-invalid { border-color: var(--crimson); }
.stage {
  width: 100%; margin: 1.4em 0 .4em 0; background: var(--void-2);
  border: 1px solid var(--hair); border-radius: 4px; overflow: hidden;
}
.stage svg { display: block; width: 100%; height: auto; }
.mod-note {
  font-family: var(--mono); font-size: .7rem; color: var(--sand-dim);
  margin-top: .7em; line-height: 1.5;
}

/* ---------- 05 · lineage map ---------- */
#lineage-stage { max-width: 1020px; margin-left: auto; margin-right: auto; }
.lg-axis-label { font-family: var(--mono); font-size: 9px; fill: var(--sand-dim); }
.lg-lane-label { font-family: var(--mono); font-size: 11px; fill: var(--sand); letter-spacing: .04em; }
.lg-lane-sub { font-family: var(--mono); font-size: 8px; fill: var(--sand-dim); }
.lg-edge { fill: none; stroke: var(--sand-dim); stroke-opacity: .55; stroke-width: 1; transition: stroke .3s ease, opacity .6s ease; }
.lg-edge.is-hidden { opacity: 0; pointer-events: none; }
.lg-arc.is-hidden, .lg-place.is-hidden { opacity: 0; pointer-events: none; }
.lg-arc { transition: opacity .5s ease, stroke .25s ease; }
.lg-place { transition: opacity .5s ease, fill .25s ease; }
.lg-edge.is-hot { stroke: var(--gold); stroke-opacity: 1; stroke-width: 1.6; }
.lg-node { cursor: pointer; transition: opacity .5s ease; }
.lg-node circle.dot { transition: r .2s ease, fill .2s ease; }
.lg-node:hover circle.dot, .lg-node:focus-visible circle.dot { fill: var(--clay); }
.lg-node:focus { outline: none; }
.lg-node:focus-visible circle.dot { stroke: var(--gold); stroke-width: 2; }
.lg-node.is-selected circle.dot { fill: var(--gold); }
.lg-node.is-hidden { opacity: 0; pointer-events: none; }
.lg-label { font-family: var(--mono); font-size: 9.5px; fill: var(--sand-dim); pointer-events: none; }
.lg-node.is-selected .lg-label { fill: var(--sand); }
.lg-playhead { stroke: var(--clay); stroke-width: 1; stroke-dasharray: 2 3; opacity: .8; }
.lg-globe-line { stroke: var(--hair); stroke-width: 1; }
.lg-globe-tick { stroke: var(--hair); stroke-width: .5; }
.lg-globe-label { font-family: var(--mono); font-size: 8px; fill: var(--sand-dim); }
.lg-arc { fill: none; stroke: var(--sand-dim); stroke-opacity: .45; stroke-width: 1; }
.lg-arc.is-hot { stroke: var(--clay); stroke-opacity: 1; stroke-width: 1.6; }
.lg-place { fill: var(--sand-dim); }
.lg-place.is-hot { fill: var(--clay); }
.detail {
  margin-top: 1.4em; border-left: 2px solid var(--gold); padding: 0 0 0 1em;
  min-height: 8em;
}
.detail h3 { font-size: 1.05rem; margin-bottom: .1em; }
.detail .detail-age { font-family: var(--mono); font-size: .76rem; color: var(--gold); }
.detail .detail-region { font-family: var(--mono); font-size: .72rem; color: var(--sand-dim); margin-top: .1em; }
.detail p { margin-top: .7em; font-size: .9rem; opacity: .9; max-width: 62ch; }
.detail .detail-today { font-size: .84rem; color: var(--verdant); }
.detail .detail-source { font-family: var(--mono); font-size: .68rem; color: var(--sand-dim); margin-top: .8em; }
.diversity-bar { margin-top: .9em; }
.diversity-track { height: 6px; background: var(--hair); border-radius: 4px; overflow: hidden; max-width: 340px; }
.diversity-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--verdant), var(--gold)); transition: width .7s ease; }
.diversity-label { font-family: var(--mono); font-size: .66rem; color: var(--sand-dim); margin-top: .4em; }

/* ---------- 06 · shared-DNA counter ---------- */
.readout-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 10px; margin-top: 1.6em; }
.stat-card {
  border: 1px solid var(--hair); border-radius: 8px; padding: .9em 1em;
  background: var(--void-2); transition: border-color .25s ease, transform .25s ease;
}
.stat-card:hover { border-color: var(--gold); transform: translateY(-1px); }
.stat-card .sc-label { font-family: var(--mono); font-size: .64rem; text-transform: uppercase; letter-spacing: .1em; color: var(--sand-dim); }
.stat-card .sc-value { font-family: var(--mono); font-size: 1.35rem; color: var(--gold); margin-top: .3em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-card .sc-sub { font-size: .78rem; color: var(--sand-dim); margin-top: .35em; line-height: 1.45; }
.stat-card.is-lead .sc-value { color: var(--clay); font-size: 1.6rem; }
#coalescent-stage { max-width: 760px; margin-left: auto; margin-right: auto; }
.co-tip { stroke: var(--sand-dim); stroke-opacity: .5; }
.co-tip.is-hot { stroke: var(--verdant); stroke-opacity: .9; }
.co-line { stroke: var(--sand-dim); stroke-opacity: .45; stroke-width: 1; fill: none; }
.co-line.is-hot { stroke: var(--gold); stroke-opacity: 1; stroke-width: 1.4; }
.co-label { font-family: var(--mono); font-size: 9px; fill: var(--sand-dim); }
.co-root { fill: var(--gold); }
.co-root-label { font-family: var(--mono); font-size: 9.5px; fill: var(--gold); }
.ladder { margin-top: 1.6em; }
.ladder-row { display: grid; grid-template-columns: 130px 1fr 110px; align-items: center; gap: .8em; margin: .45em 0; }
.ladder-label { font-family: var(--mono); font-size: .72rem; color: var(--sand-dim); }
.ladder-track { height: 12px; background: var(--hair); border-radius: 2px; overflow: hidden; }
.ladder-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--clay), var(--gold)); transition: width .6s ease; }
.ladder-value { font-family: var(--mono); font-size: .72rem; color: var(--sand); text-align: right; font-variant-numeric: tabular-nums; }
.ladder-row.is-current .ladder-label { color: var(--gold); }
.ladder-row.is-current .ladder-value { color: var(--gold); }

/* ---------- 07 · kinship distance ---------- */
.distance-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 1.6em; align-items: start; margin-top: 1.4em; }
@media (max-width: 860px) { .distance-layout { grid-template-columns: 1fr; } }
.dg-node { cursor: pointer; transition: opacity .4s ease; }
.dg-node circle { transition: fill .2s ease, r .2s ease; }
.dg-node:hover circle { fill: var(--clay); }
.dg-node:focus { outline: none; }
.dg-node:focus-visible circle { stroke: var(--gold); stroke-width: 2; }
.dg-node.is-end circle { fill: var(--clay); }
.dg-label { font-family: var(--mono); font-size: 9px; fill: var(--sand-dim); pointer-events: none; }
.dg-node.is-end .dg-label { fill: var(--sand); }
.dg-arc { fill: none; stroke: var(--clay); stroke-width: 1.8; stroke-linecap: round; }
.dg-hop { fill: var(--gold); }
.dg-pulse { fill: none; stroke: var(--gold); }
.chain-readout { font-family: var(--mono); font-size: .8rem; color: var(--sand); line-height: 1.6; }
.chain-readout b { color: var(--gold); font-size: 1.5rem; font-weight: 500; }
.matrix { display: grid; gap: 2px; margin-top: .8em; }
.matrix-cell {
  aspect-ratio: 1 / 1; border-radius: 2px; border: 0; padding: 0; cursor: pointer;
  background: var(--sand-dim); transition: transform .15s ease, outline-color .15s ease;
  outline: 1px solid transparent; outline-offset: 1px;
}
.matrix-cell:hover, .matrix-cell:focus-visible { transform: scale(1.35); outline-color: var(--gold); z-index: 2; position: relative; }
.matrix-cell.is-active { outline-color: var(--clay); }
.matrix-cell.is-diagonal { background: transparent; cursor: default; }
.matrix-cell.is-diagonal:hover { transform: none; outline-color: transparent; }
.matrix-axis { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .62rem; color: var(--sand-dim); margin-top: .3em; }
#distance-chart { max-width: 720px; margin: 1.8em auto 0 auto; }
.dc-axis { stroke: var(--hair); }
.dc-line { fill: none; stroke: var(--gold); stroke-width: 1.6; }
.dc-line.is-ancestral { stroke: var(--verdant); stroke-dasharray: 4 3; }
.dc-ceiling { stroke: var(--crimson); stroke-width: 1; stroke-dasharray: 5 4; }
.dc-label { font-family: var(--mono); font-size: 9px; fill: var(--sand-dim); }
.dc-point { fill: var(--clay); }
.dc-caption { font-family: var(--mono); font-size: 9px; fill: var(--crimson); }

/* ---------- 08 · heritage grid ---------- */
.universal-bar { display: flex; flex-wrap: wrap; gap: .5em; margin-top: 1.5em; }
.universal-summary {
  margin-top: 1em; padding: .8em 1em; border: 1px solid var(--hair);
  border-left: 2px solid var(--verdant); border-radius: 4px; background: var(--void-2);
}
.universal-summary h3 { font-size: .95rem; color: var(--verdant); }
.universal-summary p { font-size: .86rem; margin-top: .5em; max-width: 68ch; opacity: .9; }
.universal-summary .src { font-family: var(--mono); font-size: .66rem; color: var(--sand-dim); margin-top: .6em; }
.heritage-wrap { margin-top: 1.4em; overflow-x: auto; border: 1px solid var(--hair); border-radius: 6px; background: var(--void-2); }
.heritage-grid { border-collapse: collapse; width: 100%; min-width: 860px; font-size: .78rem; }
.heritage-grid th, .heritage-grid td { padding: .6em .7em; border-bottom: 1px solid var(--hair); vertical-align: top; text-align: left; }
.heritage-grid thead th {
  position: sticky; top: 0; background: var(--void); z-index: 2;
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--sand-dim); font-weight: 500;
}
.heritage-grid thead th .dom-q { display: block; text-transform: none; letter-spacing: 0; font-size: .68rem; margin-top: .2em; opacity: .8; }
.heritage-grid .rowhead { min-width: 190px; max-width: 220px; }
.hg-name { font-family: var(--serif); font-size: .92rem; }
.hg-region { font-family: var(--mono); font-size: .62rem; color: var(--sand-dim); margin-top: .15em; }
.hg-cell { max-width: 250px; line-height: 1.45; transition: background-color .3s ease, opacity .3s ease; }
.heritage-grid tbody tr { transition: background-color .25s ease; }
.heritage-grid tbody tr:hover { background: rgba(184, 94, 55, .06); }
.heritage-grid tbody tr.is-compared { background: rgba(71, 116, 94, .1); }
.hg-cell.is-hit { background: rgba(71, 116, 94, .16); }
.hg-cell.is-hit::before { content: '✓ '; color: var(--verdant); font-weight: 700; }
.heritage-grid.is-filtered .hg-cell:not(.is-hit) { opacity: .45; }
.hg-flag {
  font-family: var(--mono); font-size: .62rem; margin-top: .5em; padding: .3em .5em;
  border: 1px solid var(--hair); border-radius: 999px; background: transparent;
  color: var(--sand-dim); cursor: pointer; transition: border-color .2s ease, color .2s ease;
}
.hg-flag:hover { border-color: var(--verdant); color: var(--verdant); }
.hg-flag[aria-pressed="true"] { border-color: var(--verdant); color: var(--verdant); background: rgba(71, 116, 94, .14); }
.compare-panel { margin-top: 1.4em; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.compare-card {
  border: 1px solid var(--hair); border-radius: 8px; padding: 1em; background: var(--void-2);
  animation: rise .4s ease both;
}
.compare-card h3 { font-size: 1rem; }
.compare-card .cc-meta { font-family: var(--mono); font-size: .64rem; color: var(--sand-dim); margin-top: .2em; line-height: 1.5; }
.compare-card dl { margin: .8em 0 0 0; }
.compare-card dt { font-family: var(--mono); font-size: .62rem; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); margin-top: .7em; }
.compare-card dd { margin: .2em 0 0 0; font-size: .82rem; line-height: 1.45; }
.compare-card .cc-note { font-size: .78rem; color: var(--sand-dim); margin-top: .9em; border-top: 1px solid var(--hair); padding-top: .6em; }
.compare-empty { font-family: var(--mono); font-size: .72rem; color: var(--sand-dim); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* staggered reveal for the modules, driven by IntersectionObserver in index.html */
.mod-reveal { opacity: 0; transform: translateY(10px); transition: opacity .6s ease, transform .6s ease; }
.mod-reveal.is-in { opacity: 1; transform: none; }

/* ---------- site features modal ---------- */
.features-fab {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 9000; display: inline-flex; align-items: center; gap: .5em;
  padding: .6em 1em; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--theme-toggle-border, var(--hair));
  background: var(--theme-toggle-bg, var(--void-2));
  color: var(--theme-toggle-fg, var(--sand));
  box-shadow: var(--theme-toggle-shadow, 0 6px 20px rgba(45, 51, 46, .16));
  font-family: var(--mono); font-size: .74rem;
  transition: transform .18s ease, border-color .18s ease;
}
.features-fab:hover { transform: translateY(-1px); border-color: var(--gold); }
.features-open {
  margin-top: 1.8em; display: inline-flex; align-items: center; gap: .55em;
  font-family: var(--mono); font-size: .8rem; padding: .6em 1.1em; cursor: pointer;
  border: 1px solid var(--hair); border-radius: 999px; background: transparent; color: var(--sand);
  transition: border-color .2s ease, transform .2s ease, background-color .2s ease;
}
.features-open:hover { border-color: var(--gold); transform: translateY(-1px); background: rgba(184, 94, 55, .08); }

.modal { position: fixed; inset: 0; z-index: 10001; display: none; }
.modal.is-open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 18, 12, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .25s ease both; }
.modal-panel {
  position: relative; margin: 0 auto; top: 50%; transform: translateY(-50%);
  width: min(920px, 92vw); max-height: min(84vh, 900px); display: flex; flex-direction: column;
  border: 1px solid var(--hair); border-radius: 12px; background: var(--void-2);
  box-shadow: 0 30px 80px rgba(20, 18, 12, .35); animation: pop .3s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(.985); } to { opacity: 1; transform: translateY(-50%) scale(1); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1em; padding: 1.1em 1.3em .8em 1.3em; border-bottom: 1px solid var(--hair); }
.modal-head h2 { font-size: 1.25rem; }
.modal-head p { font-family: var(--mono); font-size: .68rem; color: var(--sand-dim); margin-top: .35em; }
.modal-close {
  flex: none; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--hair); background: transparent; color: var(--sand-dim);
  font-size: .95rem; line-height: 1; transition: border-color .2s ease, color .2s ease, transform .2s ease;
}
.modal-close:hover { border-color: var(--clay); color: var(--clay); transform: rotate(90deg); }
.modal-body { padding: 1em 1.3em 1.4em 1.3em; overflow-y: auto; }
.feature-group { margin-top: 1.2em; }
.feature-group:first-child { margin-top: 0; }
.feature-group h3 {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--gold); font-weight: 500; margin-bottom: .6em;
}
.feature-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 8px; }
.feature-item {
  display: block; width: 100%; text-align: left; cursor: pointer; text-decoration: none;
  padding: .7em .85em; border: 1px solid var(--hair); border-radius: 8px;
  background: transparent; color: var(--sand); font: inherit;
  transition: border-color .2s ease, transform .2s ease, background-color .2s ease;
}
.feature-item:hover, .feature-item:focus-visible { border-color: var(--gold); transform: translateY(-1px); background: rgba(184, 94, 55, .07); }
.feature-item .fi-name { display: block; font-size: .88rem; }
.feature-item .fi-desc { display: block; font-size: .76rem; color: var(--sand-dim); margin-top: .2em; line-height: 1.4; }
.feature-item .fi-tag { font-family: var(--mono); font-size: .6rem; color: var(--gold); letter-spacing: .08em; }
.modal-foot { padding: .8em 1.3em; border-top: 1px solid var(--hair); font-family: var(--mono); font-size: .66rem; color: var(--sand-dim); }
body.is-modal-open { overflow: hidden; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .chip, .stat-card, .matrix-cell, .feature-item, .features-fab, .features-open,
  .modal-close, .lg-node, .dg-node, .hg-flag { transition: none; }
  .mod-reveal { opacity: 1; transform: none; transition: none; }
  .modal-backdrop, .modal-panel, .compare-card { animation: none; }
  .compare-card { opacity: 1; }
  .ladder-fill, .diversity-fill, .lg-edge, .co-line, .co-tip, .hg-cell,
  .lg-arc, .lg-place { transition: none; }
  .dg-hop { transition: none !important; }
  .matrix-cell:hover, .matrix-cell:focus-visible { transform: none; }
}

/* Table rows only fade; transforming them is inconsistent across browsers. */
tr.mod-reveal { transform: none; }
