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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #0d1117;
  color: #e6edf3;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.site-nav {
  position: fixed;
  top: 8px;
  left: 12px;
  z-index: 100;
  display: flex;
  gap: 6px;
}

.site-nav a {
  font-size: 0.75rem;
  color: #58a6ff;
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #161b22;
  transition: all 0.15s;
}

.site-nav a:hover {
  color: #79c0ff;
  border-color: #58a6ff;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 580px;
  padding: 8px 0;
  position: relative;
}

.top-bar-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b949e;
}

.top-bar-icon {
  position: absolute;
  right: 0;
  font-size: 1rem;
  padding: 4px 8px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #161b22;
  color: #8b949e;
  cursor: pointer;
  transition: all 0.15s;
}

.top-bar-icon:hover {
  background: #21262d;
  color: #e6edf3;
}

/* ── Mode tabs ──────────────────────────────────────────── */

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 4px 16px;
  max-width: 840px;
  width: 100%;
}

.mode-tab {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 6px 10px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #161b22;
  color: #8b949e;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  position: relative;
}

.mode-tab:hover {
  background: #21262d;
  color: #e6edf3;
}

.mode-tab.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

/* ── Mode description (Dawkins quote) ──────────────────── */

#mode-description {
  font-size: 0.75rem;
  font-style: italic;
  color: #8b949e;
  text-align: center;
  max-width: 640px;
  padding: 2px 16px 4px;
  line-height: 1.4;
}

/* ── Settings bar (below quote) ────────────────────────── */

#settings-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 2px 16px 4px;
  max-width: 840px;
  width: 100%;
}

/* ── Action bar ────────────────────────────────────────── */

#action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 760px;
  padding: 0;
  gap: 12px;
}

.action-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.action-buttons button {
  font-size: 0.7rem;
  padding: 5px 10px;
  opacity: 0.8;
}

.action-buttons button:hover {
  opacity: 1;
}

.random-group {
  display: flex;
  gap: 0;
}

.random-group button {
  border-radius: 6px 0 0 6px;
}

.random-group select {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 5px 8px;
  border: 1px solid #30363d;
  border-radius: 0 6px 6px 0;
  border-left: none;
  background: #21262d;
  color: #e6edf3;
  cursor: pointer;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.setting-row label {
  font-size: 0.8rem;
  color: #8b949e;
}

.setting-row select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 3px 8px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #161b22;
  color: #e6edf3;
}

.setting-row input[type="checkbox"] {
  accent-color: #1f6feb;
}

/* ── Main layout ────────────────────────────────────────── */

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 16px 16px;
  width: 100%;
  max-width: 840px;
}

/* ── Parent card in grid ──────────────────────────────── */

.parent-card {
  position: relative;
  background: rgba(31, 111, 235, 0.06);
  border-radius: 6px;
}

.parent-card canvas {
  border-color: #58a6ff !important;
  cursor: default !important;
}

.parent-label {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  z-index: 2;
  font-size: 0.65rem;
  color: #58a6ff;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 0;
  pointer-events: auto;
}


/* ── Card icon overlays ────────────────────────────────── */

.card-icon {
  position: absolute;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(88, 166, 255, 0.4);
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.8);
  color: #58a6ff;
  font-size: 14px;
  line-height: 28px;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 2;
}

.card-icon:hover {
  background: rgba(31, 111, 235, 0.3);
  color: #fff;
}


/* ── Offspring card overlays ──────────────────────────── */

.offspring-card {
  position: relative;
}

.offspring-card canvas {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #30363d;
  border-radius: 6px;
  background: #161b22;
  cursor: pointer;
  transition: border-color 0.15s;
}

.offspring-card:hover canvas {
  border-color: #58a6ff;
}

.offspring-card.lost-ant canvas {
  border: 2px dashed #f0883e;
}

.offspring-number {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid #30363d;
  color: #8b949e;
  font-size: 0.65rem;
  line-height: 20px;
  text-align: center;
  pointer-events: none;
}

.offspring-card .card-icon,
.offspring-card .card-icon-animate {
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.offspring-card:hover .card-icon,
.offspring-card:hover .card-icon-animate {
  opacity: 1;
}

.card-icon-animate {
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}

.card-icon-animate.animating {
  color: #f85149;
  border-color: rgba(248, 81, 73, 0.4);
}

.card-icon-animate.animating:hover {
  background: rgba(248, 81, 73, 0.2);
}

.card-icon-save {
  bottom: 6px;
  left: 6px;
}

.card-icon-link {
  bottom: 6px;
  right: 6px;
}


/* ── Genome table ──────────────────────────────────────── */

#genome-table {
  font-size: 0.75rem;
  color: #8b949e;
}

.genome-group-header {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #58a6ff;
  background: #161b22;
  padding: 4px 8px 2px;
  border-top: 1px solid #21262d;
}

.genome-group-header:first-child {
  border-top: none;
}

.genome-row {
  display: grid;
  grid-template-columns: 58px 32px 1fr;
  align-items: baseline;
  padding: 1px 8px;
  gap: 6px;
}

.genome-row:hover {
  background: #161b22;
}

.genome-label {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  color: #e6edf3;
}

.genome-value {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  color: #58a6ff;
  text-align: right;
}

.genome-desc {
  font-size: 0.65rem;
  color: #6e7681;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.genome-value.genome-color {
  color: #a8b4ff;
}

#offspring-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 580px;
}

/* offspring canvas styles moved to .offspring-card rules above */

button {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 6px 16px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #21262d;
  color: #e6edf3;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: #30363d;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

#generation-counter {
  color: #8b949e;
}

#link-3d {
  color: #58a6ff;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

#link-3d:hover {
  color: #79c0ff;
  text-decoration: underline;
}

/* ── Gene chips with tooltips (F6) ─────────────────────── */

.gene-chip {
  display: inline-block;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  padding: 2px 6px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #8b949e;
  position: relative;
  cursor: default;
}

.gene-chip[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #e6edf3;
  font-family: -apple-system, sans-serif;
  font-size: 0.7rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}

.gene-chip[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #30363d;
  z-index: 10;
}

.gene-chip.gene-changed {
  background: #1f3d1f;
  border-color: #3fb950;
  color: #3fb950;
}

.gene-chip.gene-color {
  background: #1f1f3d;
  color: #a8b4ff;
}

/* ── Collapsible panels ────────────────────────────────── */

.collapsible-panel {
  width: 100%;
  max-width: 840px;
  margin: 4px auto;
}

.panel-toggle {
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  font-size: 0.8rem;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #161b22;
  color: #8b949e;
  cursor: pointer;
  transition: all 0.15s;
}

.panel-toggle::before {
  content: '\25B6  ';
  font-size: 0.6rem;
}

.panel-toggle.open {
  border-radius: 6px 6px 0 0;
}

.panel-toggle.open::before {
  content: '\25BC  ';
}

.panel-toggle:hover {
  background: #21262d;
  color: #e6edf3;
}

.panel-content {
  border: 1px solid #30363d;
  border-top: none;
  border-radius: 0 0 6px 6px;
  background: #0d1117;
  padding: 12px;
}

/* ── Gallery (F2) ──────────────────────────────────────── */

#gallery-content {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.gallery-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
}

.gallery-card-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #30363d;
  color: #8b949e;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  z-index: 1;
}

.gallery-card-delete:hover {
  background: #f85149;
  color: #fff;
}

.gallery-card img {
  width: 80px;
  height: 80px;
  border-radius: 4px;
  background: #0d1117;
}

.gallery-name {
  width: 100%;
  font-family: inherit;
  font-size: 0.7rem;
  padding: 2px 4px;
  border: 1px solid #30363d;
  border-radius: 3px;
  background: #0d1117;
  color: #e6edf3;
  text-align: center;
}

.gallery-info {
  font-size: 0.6rem;
  color: #8b949e;
}

.gallery-actions {
  display: flex;
  gap: 4px;
}

.gallery-actions button {
  font-size: 0.65rem;
  padding: 2px 8px;
}

.btn-breed {
  color: #d2a8ff !important;
  border-color: #d2a8ff !important;
}

.btn-breed:hover {
  background: rgba(210, 168, 255, 0.15) !important;
}

.btn-danger {
  color: #f85149 !important;
  border-color: #f85149 !important;
}

.btn-danger:hover {
  background: rgba(248, 81, 73, 0.15) !important;
}

.gallery-collection-bar {
  margin-bottom: 10px;
}

.gallery-collection-bar label {
  font-size: 0.8rem;
  color: #8b949e;
}

.gallery-collection-bar select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 3px 8px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #161b22;
  color: #e6edf3;
}

.gallery-name-label {
  width: 100%;
  font-size: 0.7rem;
  padding: 2px 4px;
  color: #e6edf3;
  text-align: center;
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.8rem;
  color: #8b949e;
  padding: 16px;
}

/* ── Genealogy (F8) ────────────────────────────────────── */

#genealogy-panel .panel-content {
  overflow: auto;
  max-height: 500px;
}

#genealogy-canvas {
  display: block;
  cursor: pointer;
}

.genealogy-hint {
  text-align: center;
  font-size: 0.8rem;
  font-style: italic;
  color: #8b949e;
  padding: 8px 16px;
}

/* ── Comparison modal (F7) ─────────────────────────────── */

#comparison-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.comparison-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
}

.comparison-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.comparison-side h3 {
  font-size: 0.9rem;
  color: #58a6ff;
  font-weight: 500;
}

.comparison-side canvas {
  border: 2px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
}

.comparison-genes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  max-width: 300px;
}

.comparison-actions {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* ── Breed modal ───────────────────────────────────────── */

#breed-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.breed-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 780px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.breed-parents {
  display: flex;
  align-items: center;
  gap: 16px;
}

.breed-parent-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.breed-parent-side h3 {
  font-size: 0.9rem;
  color: #58a6ff;
  font-weight: 500;
}

.breed-parent-side canvas {
  border: 2px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
}

.breed-x {
  font-size: 2rem;
  color: #d2a8ff;
  font-weight: 300;
  line-height: 1;
  margin-top: 20px;
}

.breed-offspring-grid {
  display: grid;
  grid-template-columns: repeat(4, 140px);
  gap: 8px;
  justify-content: center;
}

.breed-offspring-grid canvas {
  width: 140px;
  height: 140px;
  border: 2px solid #30363d;
  border-radius: 6px;
  background: #161b22;
  cursor: pointer;
  transition: border-color 0.15s;
}

.breed-offspring-grid canvas:hover {
  border-color: #d2a8ff;
}

.breed-gene-comparison {
  width: 100%;
  flex-shrink: 0;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #30363d #0d1117;
}

.breed-gene-row {
  display: grid;
  grid-template-columns: 55px 160px repeat(10, 60px);
  align-items: center;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  color: #8b949e;
}

.breed-gene-row > span {
  padding: 3px 6px;
}

.breed-gene-row > span:nth-child(n+3) {
  text-align: center;
}

/* Sticky gene label + description */
.breed-gene-row > span:first-child,
.breed-gene-row > span:nth-child(2) {
  position: sticky;
  background: #0d1117;
}

.breed-gene-row > span:first-child {
  left: 0;
  z-index: 2;
  padding-left: 10px;
}

.breed-gene-row > span:nth-child(2) {
  left: 55px;
  z-index: 1;
}

.breed-gene-differs > span:first-child,
.breed-gene-differs > span:nth-child(2) {
  background: #1c2333;
}

.breed-gene-header {
  text-transform: uppercase;
  font-size: 0.6rem;
  color: #484f58;
  border-bottom: 1px solid #21262d;
  font-family: -apple-system, sans-serif;
  letter-spacing: 0.05em;
}

.breed-gene-header > span {
  padding: 5px 6px;
}

.breed-gene-header > span:first-child {
  padding-left: 10px;
}

.breed-gene-differs {
  background: #1c2333;
}

.breed-gene-pval {
  color: #58a6ff;
}

.breed-gene-mval {
  color: #d2a8ff;
}

.breed-gene-from-parent {
  color: #58a6ff;
}

.breed-gene-from-mate {
  color: #d2a8ff;
}

.breed-gene-mutated-val {
  color: #3fb950;
}

.breed-col-highlight {
  background: rgba(255, 255, 255, 0.07);
}

.breed-gene-desc {
  font-family: -apple-system, sans-serif;
  font-size: 0.65rem;
  color: #6e7681;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breed-detail-strip {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 28px;
  align-items: center;
}

.breed-detail-hint {
  font-size: 0.7rem;
  font-style: italic;
  color: #484f58;
}

.gene-chip.breed-gene-parent {
  background: rgba(88, 166, 255, 0.1);
  border-color: #58a6ff;
  color: #58a6ff;
}

.gene-chip.breed-gene-mate {
  background: rgba(210, 168, 255, 0.1);
  border-color: #d2a8ff;
  color: #d2a8ff;
}

.gene-chip.breed-gene-mutated {
  border-color: #3fb950;
  box-shadow: 0 0 4px rgba(63, 185, 80, 0.4);
}

.breed-actions {
  display: flex;
  justify-content: center;
}

/* ── Mutation select (F5) ──────────────────────────────── */

.mutation-label {
  font-size: 0.8rem;
  color: #8b949e;
}

.mutation-label select {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 4px 8px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #161b22;
  color: #e6edf3;
}

/* ── Mate picker modal ─────────────────────────────────── */

#mate-picker-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.mate-picker-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.mate-picker-content h3 {
  font-size: 1rem;
  font-weight: 500;
  color: #e6edf3;
}

.mate-picker-hint {
  font-size: 0.75rem;
  color: #8b949e;
  font-style: italic;
  text-align: center;
}

#mate-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  width: 100%;
}

.mate-picker-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: #0d1117;
  border: 2px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mate-picker-card:hover {
  border-color: #8b949e;
}

.mate-picker-card.selected {
  border-color: #d2a8ff;
  background: rgba(210, 168, 255, 0.08);
}

.mate-picker-card img {
  width: 72px;
  height: 72px;
  border-radius: 4px;
  background: #161b22;
}

.mate-picker-card .mate-name {
  font-size: 0.65rem;
  color: #8b949e;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.mate-picker-card.selected .mate-name {
  color: #d2a8ff;
}

.mate-picker-actions {
  display: flex;
  gap: 12px;
}

.mate-picker-empty {
  font-size: 0.8rem;
  color: #8b949e;
  padding: 16px;
  text-align: center;
}

/* ── About modal ──────────────────────────────────────── */

#about-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.about-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 32px;
  max-width: 400px;
  width: 90vw;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.about-content h2 { font-size: 1.4rem; }
.about-subtitle { font-size: 0.85rem; color: #8b949e; font-style: italic; }
.about-version { font-size: 0.7rem; color: #484f58; }
.about-content h3 { font-size: 0.9rem; color: #58a6ff; margin-top: 8px; }
.about-content ul { text-align: left; font-size: 0.8rem; color: #8b949e; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.about-content kbd { background: #21262d; border: 1px solid #30363d; border-radius: 3px; padding: 1px 5px; font-size: 0.75rem; font-family: inherit; }
.about-credit { font-size: 0.75rem; color: #6e7681; margin-top: 4px; }

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 600px) {
  #settings-bar {
    flex-direction: column;
    align-items: center;
  }
  #action-bar {
    flex-direction: column;
    align-items: center;
  }
  #offspring-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .offspring-card .card-icon,
  .offspring-card .card-icon-animate {
    opacity: 1;
  }
  .mode-tabs {
    gap: 3px;
  }
  .mode-tab {
    font-size: 0.65rem;
    padding: 5px 8px;
  }
  .comparison-side canvas {
    width: 140px;
    height: 140px;
  }
}
