:root {
  color: #edf4ff;
  background: #0a1221;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  --ink: #edf4ff;
  --muted: #a8bad4;
  --edge: #2a3b55;
  --route: #7aa9ff;
  --best-route: #ff7489;
  --optimal-route: #78e6c0;
  --exploration: #bd9aff;
  --new: #ffad76;
  --water: #0d1a2d;
  --land: #182b45;
  --data: "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1560px; margin: auto; padding: 30px clamp(16px, 4vw, 64px) 38px; }
a { color: inherit; text-underline-offset: 3px; }
h1, h2, p, ul, dl, dd { margin: 0; }

.masthead { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
h1 { font-size: clamp(2.5rem, 6vw, 5.2rem); line-height: 0.97; letter-spacing: -0.057em; font-weight: 750; }
.masthead p { margin-top: 12px; color: var(--muted); font-size: clamp(.9rem, 1.5vw, 1.08rem); }
.run-controls { display: flex; align-items: center; justify-content: end; flex-wrap: wrap; gap: 9px 14px; padding-bottom: 3px; }
#source { font: .75rem var(--data); color: var(--muted); overflow-wrap: anywhere; }

button, select, .file-button {
  appearance: none;
  border: 1px solid #405776;
  border-radius: 5px;
  background-color: #111e32;
  color: var(--ink);
  padding: 8px 11px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, select:hover, .file-button:hover { background-color: #1b304d; }
button:focus-visible, select:focus-visible, input:focus-visible, .file-button:focus-within {
  outline: 2px solid var(--route);
  outline-offset: 3px;
}
.file-button { position: relative; }
.file-button input { opacity: 0; position: absolute; inset: 0; width: 100%; cursor: pointer; }
select {
  padding-right: 27px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 12px center, right 8px center;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.run-settings {
  margin-bottom: 14px; border: 1px solid var(--edge); border-radius: 8px; background: #111e32;
  padding: 9px 14px;
}
.run-settings summary { cursor: pointer; font-size: .88rem; font-weight: 700; }
.run-settings summary:focus-visible { outline: 2px solid var(--route); outline-offset: 4px; }
#run-variables { border: 0; padding: 0; margin: 0; min-width: 0; }
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 10px; margin-top: 14px;
}
.settings-grid fieldset {
  display: grid; align-content: start; gap: 7px; margin: 0; min-width: 0;
  padding: 9px 10px 11px; border: 1px solid var(--edge); border-radius: 6px;
}
.settings-grid legend { padding-inline: 5px; color: var(--route); font-size: .8rem; font-weight: 700; }
.settings-grid label {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(68px, 41%);
  align-items: center; gap: 8px; font-size: .77rem;
}
.settings-grid input {
  width: 100%; min-width: 0; padding: 6px 7px;
  border: 1px solid #405776; border-radius: 4px; background: #0d1a2d; color: var(--ink);
  font: .8rem var(--data);
}
.settings-grid input:disabled { opacity: .65; }
.settings-grid p, .settings-footer p { font-size: .72rem; color: var(--muted); line-height: 1.4; }
.settings-footer { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 10px; }

#error { color: var(--new); margin-bottom: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 325px);
  border: 1px solid #334a68;
  border-radius: 12px;
  overflow: hidden;
  background: #111e32;
}
.atlas {
  position: relative;
  background: var(--water);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
}
.map-top, .map-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 9px 15px;
  padding: 17px 20px;
}
.map-top { padding-bottom: 2px; }
.map-bottom { padding-top: 3px; }
h2 { font-size: .98rem; line-height: 1.2; font-weight: 750; letter-spacing: -.015em; }
#route-mode { font-size: .78rem; }
#discovered { color: #f3b892; font-size: .78rem; min-height: 1em; }
.map-bottom a { font-size: .68rem; color: var(--muted); }
.map-surface { position: relative; min-width: 0; min-height: 0; }
#map { display: block; width: 100%; height: 100%; min-height: 410px; }
#missing-rings { position: absolute; inset: 0; pointer-events: none; }
.missing-ring, .missing-ring-key { border: 1.5px solid #ffe17a; border-radius: 50%; }
.missing-ring-key { width: 11px; height: 11px; }
.missing-ring {
  position: absolute; width: 14px; height: 14px; transform: translate(-50%, -50%);
  box-shadow: 0 0 4px #ffe17a55;
}
.missing-ring::after {
  content: ""; position: absolute; inset: -1.5px; border: inherit; border-radius: inherit;
  animation: missing-pulse 1.8s ease-out infinite;
}
@keyframes missing-pulse {
  from { transform: scale(1); opacity: .75; }
  75%, to { transform: scale(1.9); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .missing-ring::after { display: none; }
}
.line.best-route { background: var(--best-route); }
.line.exploration { background: var(--exploration); }
#exploration-note { color: var(--muted); font-size: .7rem; }
.map-bottom label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.map-bottom input { margin: 0 1px 0 0; accent-color: var(--route); }
.legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 15px; }
.legend li { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .72rem; }
.legend i { display: inline-block; }
.line { width: 17px; height: 2px; border-radius: 2px; background: var(--route); }
.line.average { background: #b2a3e8; }
.dot { width: 8px; height: 8px; border: 1px solid #90a6c4; border-radius: 50%; background: var(--land); }
.dot.new { background: var(--new); border-color: var(--new); }

.log { padding: 18px 19px 16px; border-left: 1px solid #334a68; }
.generation p:first-of-type { margin-top: 5px; font: .86rem var(--data); color: var(--muted); }
#generation { font-size: 2.65rem; font-weight: 650; letter-spacing: -.09em; color: var(--ink); }
#record { font-size: .74rem; color: var(--muted); margin-top: 3px; }
.transport { display: flex; gap: 7px; margin-top: 13px; }
#play { min-width: 72px; background: var(--route); border-color: var(--route); color: #0a1221; }
#play:hover { background: #9cc1ff; }
#restart { padding-block: 5px; min-width: 34px; font-size: 1.1rem; line-height: 1; }
#speed { margin-left: auto; }
#timeline { accent-color: var(--route); width: 100%; margin: 13px 0 1px; cursor: ew-resize; }
.range-ends { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: .68rem; }
.metrics { margin: 15px 0 12px; border-block: 1px solid var(--edge); padding: 7px 0; }
.metrics div { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; padding: 5px 0; }
.metrics dt { font-size: .8rem; color: var(--muted); }
.metrics dd { font: 600 .97rem var(--data); text-align: right; }
.benchmark {
  border: 1px solid #345a63;
  padding: 10px 11px;
  border-radius: 6px;
  background: #102737;
}
.benchmark.reached { border-color: #78e6c0; }
.benchmark-numbers { display: flex; justify-content: space-between; gap: 8px; }
.benchmark-numbers div { display: grid; gap: 4px; }
.benchmark-numbers div:last-child { text-align: right; }
.benchmark span, .benchmark p { color: var(--muted); font-size: .72rem; }
.benchmark strong { font: 650 1rem var(--data); color: #a7f1d7; }
.benchmark p { margin-top: 6px; }
#optimal-generation { margin-top: 8px; color: #a7f1d7; border-color: #4f957f; padding: 5px 8px; }

.history { margin-top: 15px; }
.history + .history { border-top: 1px solid var(--edge); padding-top: 12px; }
.history-chart { width: 100%; height: 97px; display: block; cursor: crosshair; }
.chart-legend { margin-top: 2px; gap: 5px 11px; }
.chart-legend li { font-size: .67rem; }
.line.shortest { background: #78e6c0; }
.line.optimal { border-top: 2px dashed #9cebd7; background: transparent; }

.genome { margin-top: 13px; padding: 15px 19px 17px; border: 1px solid var(--edge); border-radius: 10px; background: #111e32; }
.genome-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px 18px; flex-wrap: wrap; }
#gene-detail { color: var(--muted); margin-top: 5px; font-size: .78rem; min-height: 1.2em; }
.tile { width: 10px; height: 10px; border-radius: 2px; background: #263a55; }
.coding { background: var(--route); }
.repeat { background: #593625; color: #ffd1ab; }
#genes { display: grid; grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)); gap: 4px; margin-top: 13px; }
.gene {
  border: 0; border-radius: 3px;
  display: grid; place-items: center;
  min-width: 0; padding: 0; height: 25px;
  font: 600 .67rem var(--data);
  background: #1c2d46; color: #abc0dd;
}
.gene.coding { background: var(--route); color: #0a1221; }
.gene.repeat { background: #593625; color: #ffd1ab; }
.gene.found, .gene.active { background: var(--new); color: #211508; }
.gene.active { outline: 2px solid var(--new); outline-offset: 2px; }

@media (max-width: 800px) {
  main { padding-top: 18px; }
  .overview { grid-template-columns: minmax(0, 1fr); }
  #map { min-height: 0; height: clamp(240px, 60vw, 470px); }
  .log { border-left: 0; border-top: 1px solid #334a68; }
  .masthead { align-items: start; flex-direction: column; gap: 12px; }
  .run-controls { width: 100%; justify-content: space-between; }
}
@media (max-width: 440px) {
  .map-top, .map-bottom, .log, .genome { padding-inline: 12px; }
  #genes { grid-template-columns: repeat(auto-fill, minmax(31px, 1fr)); }
}
[hidden] { display: none !important; }
#live { border-color: var(--route); color: var(--route); }
#live.running { border-color: var(--new); color: var(--new); }
#follow { color: var(--route); }
@media (max-width: 800px) {
  .run-controls { justify-content: start; flex-wrap: wrap; }
}

.population { margin-top: 24px; }
.population-heading {
  display: flex; flex-wrap: wrap; gap: 9px 18px;
  justify-content: space-between; align-items: center; margin-bottom: 10px;
}
.population-heading h2 { font-size: 1.12rem; }
#population-detail, #population-page { color: var(--muted); font-size: .77rem; }
#population-detail { margin-top: 4px; }
#population-page { font-family: var(--data); white-space: nowrap; }
#population-pages { display: flex; align-items: center; gap: 8px; }
button:disabled { opacity: .45; cursor: default; }
#population-cards {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
}
.population-card {
  padding: 10px 12px 12px; min-width: 0;
  border: 1px solid var(--edge); border-radius: 6px; background: #111e32;
}
.population-card header { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 7px; }
.population-card strong { font-size: .79rem; }
.population-card small { color: var(--muted); font: .7rem var(--data); }
.population-card ol { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 5px; padding: 0; margin: 0; list-style: none; }
.population-card li { color: #c4d8f5; font-size: .74rem; }
.population-card li:not(:last-child)::after { content: "→"; color: #7896bf; margin-left: 5px; }
.population-card p { color: var(--muted); font-size: .74rem; }

.genome-controls { display: flex; gap: 9px 15px; flex-wrap: wrap; align-items: center; }

#explain-birth { margin-top: 8px; color: #a7f1d7; border-color: #4f957f; }
.birth-inspector {
  margin-top: 14px; padding: 17px 19px;
  border: 1px solid #36576d; border-radius: 10px; background: #111e32;
  --unexpressed: #273952;
  --expressed: #86dbd6;
  --duplicate: #c3a8ef;
  --changed: #ffd183;
  --origin-a: #7aa9ff;
  --origin-b: #f09db0;
}
.birth-heading, .birth-heading nav, .birth-stages, .birth-jumps {
  display: flex; align-items: center; flex-wrap: wrap; gap: 7px;
}
.birth-heading { justify-content: space-between; gap: 12px; }
#birth-title { font-size: 1.2rem; }
#birth-caption { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.birth-stages { margin: 15px 0 8px; }
.birth-stages button[aria-pressed="true"] {
  color: #0d2234; background: var(--expressed); border-color: var(--expressed);
}
#birth-explanation, #birth-outcome, #birth-gene-detail { font-size: .81rem; line-height: 1.4; }
#birth-explanation { color: var(--muted); margin-bottom: 12px; }
.birth-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.birth-stat {
  padding: 7px 9px; border: 1px solid var(--edge); border-radius: 5px; background: #0d1a2d;
}
.birth-stat strong { display: block; font-size: .75rem; }
.birth-stat span { display: block; margin-top: 4px; color: var(--muted); font: .7rem/1.5 var(--data); }
.birth-guide { margin-top: 11px; color: var(--muted); font-size: .76rem; }
.birth-legend { margin: 5px 0 8px; }
.birth-inspector:not([data-stage="crossover"]) .birth-parent-key { display: none; }
.birth-key { width: 11px; height: 9px; border-radius: 2px; }
.birth-key.neutral, .birth-tile.neutral, .birth-segment.neutral { background: var(--unexpressed); }
.birth-key.expressed, .birth-tile.expressed, .birth-segment.expressed { background: var(--expressed); }
.birth-key.repeated, .birth-tile.repeated, .birth-segment.repeated { background: var(--duplicate); }
.birth-key.changed { border: 2px solid var(--changed); }
.birth-key.parent-a { border-bottom: 3px solid var(--origin-a); }
.birth-key.parent-b { border-bottom: 3px solid var(--origin-b); }
.birth-overview-row, .birth-row {
  display: grid; grid-template-columns: 5.4rem minmax(0, 1fr); align-items: center; gap: 5px;
}
.birth-overview-row + .birth-overview-row { margin-top: 2px; }
.birth-row-label { color: var(--muted); font-size: .73rem; }
.birth-overview-track { display: flex; height: 7px; overflow: hidden; border-radius: 2px; }
.birth-segment { flex: 1 1 0; min-width: 0; }
.birth-segment.changed { background: var(--changed); }
.birth-jumps { margin: 10px 0 6px; }
.birth-jumps button { padding: 5px 7px; font-size: .73rem; }
.birth-viewport { overflow-x: auto; border: 1px solid var(--edge); border-radius: 6px; padding: 4px 6px; }
.birth-viewport:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
.birth-row { grid-template-columns: 5.4rem auto; gap: 4px; width: max-content; }
.birth-row .birth-row-label {
  position: sticky; left: -6px; z-index: 1; height: 100%; display: flex; align-items: center;
  background: #111e32; padding-left: 8px;
}
.birth-track {
  display: grid; grid-auto-flow: column; grid-auto-columns: 2.15rem; gap: 3px;
  padding: 3px 0;
  background: linear-gradient(transparent 22%, #3d536b 23% 27%, transparent 28% 72%, #3d536b 73% 77%, transparent 78%);
}
.birth-tile {
  padding: 4px 1px; border: 1px solid transparent; border-radius: 3px;
  color: #dce9fa; font: 700 .65rem var(--data);
}
.birth-tile.expressed, .birth-tile.repeated { color: #152338; }
.birth-tile.parent-a { border-bottom: 3px solid var(--origin-a); }
.birth-tile.parent-b { border-bottom: 3px solid var(--origin-b); }
.birth-tile.changed { outline: 1px solid var(--changed); outline-offset: -1px; }
.birth-tile.cut { border-left: 2px solid #edf4ff; }
.birth-tile[aria-pressed="true"] { outline: 2px solid #fff; outline-offset: -1px; }
#birth-gene-detail { min-height: 1.2em; margin-top: 7px; color: var(--muted); }
#birth-outcome { margin-top: 10px; padding-left: 8px; border-left: 2px solid var(--expressed); }
@media (max-width: 580px) {
  .birth-inspector { padding-inline: 11px; }
  .birth-stat { padding-inline: 5px; }
  .birth-overview-row, .birth-row { grid-template-columns: 4.2rem minmax(0, 1fr); }
  .birth-row { grid-template-columns: 4.2rem auto; }
}
