/* Life's Tree Blooms — Main Stylesheet */

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #0a0e1a;
  color: #e0e0e0;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ===== Layout Grid ===== */

#app {
  display: grid;
  grid-template-rows: 48px 1fr 96px;
  grid-template-columns: 1fr 280px;
  grid-template-areas:
    "toolbar  toolbar"
    "viz      sidebar"
    "controls controls";
  height: 100vh;
  width: 100vw;
}

/* ===== Toolbar ===== */

#toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: #111628;
  border-bottom: 1px solid #1e2540;
  z-index: 10;
}

#app-title {
  font-size: 16px;
  font-weight: 600;
  color: #b8c4e0;
  white-space: nowrap;
}

#era-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: #333;
  transition: background-color 0.5s ease;
}

#era-name {
  color: #fff;
}

.layer-toggle {
  margin-left: auto;
  display: flex;
  gap: 2px;
  background: #1a1e30;
  border-radius: 6px;
  padding: 2px;
}

.view-toggle {
  display: flex;
  gap: 2px;
  background: #1a1e30;
  border-radius: 6px;
  padding: 2px;
}

.toggle-btn {
  padding: 4px 12px;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: #2a3050;
  color: #e0e0e0;
}

.toggle-btn:hover:not(.active) {
  color: #bbb;
}

/* ===== Visualization Container ===== */

#viz-container {
  grid-area: viz;
  position: relative;
  overflow: hidden;
  background: #061e38;
}

#canvas2d {
  display: block;
  width: 100%;
  height: 100%;
}

#globe-container {
  display: none;
  width: 100%;
  height: 100%;
}

#globe-container canvas {
  display: block;
}

/* Time overlay */
#time-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
}

#time-period-label {
  font-size: 18px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

#time-ma-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Extinction overlay */
#extinction-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.3s ease;
}

#extinction-overlay.hidden {
  opacity: 0;
}

#extinction-overlay.active {
  opacity: 1;
  background: radial-gradient(ellipse at center, rgba(180, 0, 0, 0.15) 0%, rgba(100, 0, 0, 0.3) 100%);
}

#extinction-text {
  font-size: 28px;
  font-weight: 800;
  color: #ff4444;
  text-shadow: 0 0 20px rgba(255, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.8);
  text-align: center;
  padding: 0 20px;
}

#extinction-subtext {
  font-size: 16px;
  color: rgba(255, 150, 150, 0.9);
  margin-top: 8px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

/* Milestone overlay — top-center toast */
#milestone-overlay {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 540px;
  padding: 12px 18px;
  background: rgba(15, 22, 40, 0.85);
  border-left: 3px solid #88aacc;
  border-radius: 6px;
  pointer-events: none;
  z-index: 6;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

#milestone-overlay.hidden {
  opacity: 0;
  transform: translate(-50%, -10px);
}

#milestone-overlay.active {
  opacity: 1;
  transform: translate(-50%, 0);
}

#milestone-title {
  font-size: 15px;
  font-weight: 700;
  color: #88aacc;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

#milestone-body {
  font-size: 12px;
  color: #c8d4e8;
  line-height: 1.45;
}

/* ===== Legend panel ===== */
#legend-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 220px;
  max-height: calc(100% - 36px);
  overflow-y: auto;
  padding: 12px 14px;
  background: rgba(15, 22, 40, 0.92);
  border: 1px solid #2a3050;
  border-radius: 6px;
  z-index: 8;
  transition: opacity 0.2s ease;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

#legend-panel.hidden {
  display: none;
}

.legend-section {
  margin-bottom: 10px;
}

.legend-section:last-child {
  margin-bottom: 0;
}

.legend-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #667;
  margin-bottom: 6px;
  font-weight: 600;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 11px;
  color: #c8d4e8;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-line {
  width: 22px;
  height: 2px;
  flex-shrink: 0;
}

.legend-line-divergent {
  background-image: repeating-linear-gradient(to right, currentColor 0 6px, transparent 6px 10px);
}

.legend-line-transform {
  background-image: repeating-linear-gradient(to right, currentColor 0 3px, transparent 3px 6px);
}

.legend-tip {
  font-size: 11px;
  color: #99a;
  line-height: 1.4;
  padding: 2px 0;
}

.legend-tip.hidden { display: none; }

/* --- Legend tree-of-life --- */
.legend-tree {
  font-size: 11px;
  color: #c8d4e8;
}
.legend-tree details {
  margin-left: 4px;
}
.legend-tree > details {
  margin-left: 0;
}
.legend-tree summary {
  cursor: pointer;
  padding: 2px 0;
  list-style: none;
  user-select: none;
  font-weight: 600;
  color: #c8d4e8;
}
.legend-tree summary::-webkit-details-marker { display: none; }
.legend-tree summary::before {
  content: '▸';
  display: inline-block;
  width: 11px;
  color: #667;
  transition: transform 0.12s ease;
  font-size: 9px;
}
.legend-tree details[open] > summary::before {
  transform: rotate(90deg);
}
.legend-tree-domain > summary { font-size: 11px; color: #a9b8d0; }
.legend-tree-kingdom > summary { font-size: 11px; color: #a9b8d0; padding-left: 4px; }
.legend-tree-kingdom { padding-left: 10px; border-left: 1px solid #1f2540; }
.legend-tree-class > summary { font-size: 10px; color: #8898b8; font-weight: 500; padding-left: 4px; }
.legend-tree-class { padding-left: 10px; border-left: 1px solid #1f2540; }
.legend-tree-leaf {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px 2px 16px;
  cursor: pointer;
  border-radius: 3px;
  font-weight: 400;
  color: #c8d4e8;
}
.legend-tree-leaf:hover { background: rgba(255, 255, 255, 0.05); }
.legend-tree-leaf-name {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Species popup ===== */
#species-popup {
  position: fixed;
  max-width: 280px;
  padding: 10px 14px;
  background: rgba(15, 22, 40, 0.95);
  border-left: 3px solid #88aacc;
  border-radius: 6px;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  transition: opacity 0.15s ease;
}

#species-popup.hidden {
  opacity: 0;
  pointer-events: none;
}

#species-popup-title {
  font-size: 14px;
  font-weight: 700;
  color: #88aacc;
  margin-bottom: 2px;
}

#species-popup-sci {
  font-size: 10px;
  font-style: italic;
  color: #778;
  margin-bottom: 4px;
}

#species-popup-meta {
  font-size: 10px;
  color: #99a;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

#species-popup-lineage {
  font-size: 10px;
  color: #778;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#species-popup-lineage .self {
  font-weight: 700;
}
#species-popup-lineage .sep {
  color: #556;
  margin: 0 4px;
}

#species-popup-body {
  font-size: 12px;
  color: #c8d4e8;
  line-height: 1.45;
}

/* ===== Species modal (click a sidebar entry to open) ===== */
#species-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 101;
  opacity: 1;
  transition: opacity 0.18s ease;
}

#species-modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

#species-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 24px 22px;
  background: #0f1628;
  border-left: 3px solid #88aacc;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.75);
  z-index: 102;
  opacity: 1;
  transition: opacity 0.18s ease;
}

#species-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

#species-modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: #99a;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

#species-modal-close:hover {
  color: #e0e8f5;
}

#species-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: #88aacc;
  margin: 0 0 4px;
}

#species-modal-sci {
  font-size: 12px;
  font-style: italic;
  color: #778;
  margin-bottom: 6px;
}

#species-modal-meta {
  font-size: 11px;
  color: #99a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

#species-modal-lineage {
  list-style: none;
  margin: 0 0 14px;
  padding: 2px 0 2px 8px;
  border-left: 1px solid #2a3050;
}
#species-modal-lineage li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 8px 3px 10px;
  position: relative;
  border-radius: 3px;
}
#species-modal-lineage li::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  width: 6px; height: 1px;
  background: #2a3050;
}
#species-modal-lineage .rank-label {
  flex: 0 0 90px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #667;
  font-weight: 600;
}
#species-modal-lineage .rank-value {
  font-size: 13px;
  color: #c8d4e8;
  font-variant-numeric: tabular-nums;
}
#species-modal-lineage li.self {
  background: rgba(255, 255, 255, 0.045);
}
#species-modal-lineage li.self .rank-value {
  font-weight: 700;
}

#species-modal-body {
  font-size: 13px;
  color: #c8d4e8;
  line-height: 1.55;
  margin: 0 0 16px;
}

.species-modal-section {
  font-size: 11px;
  font-weight: 600;
  color: #667;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 8px 0 8px;
}

#species-modal-relatives {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.species-modal-relative {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: background 0.12s ease;
}

.species-modal-relative:hover {
  background: rgba(255, 255, 255, 0.08);
}

.species-modal-relative-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.species-modal-relative-name {
  font-size: 13px;
  color: #c8d4e8;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.species-modal-relative-live {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6cc080;
  padding: 1px 5px;
  border: 1px solid rgba(108, 192, 128, 0.4);
  border-radius: 3px;
}

.species-modal-relative-range {
  font-size: 10px;
  color: #778;
  font-variant-numeric: tabular-nums;
}

.species-modal-empty {
  font-size: 12px;
  color: #667;
  font-style: italic;
  padding: 4px 10px;
}

/* ===== Sidebar ===== */

#sidebar {
  grid-area: sidebar;
  background: #0d1220;
  border-left: 1px solid #1e2540;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Atmosphere panel */
#atmosphere-panel {
  padding: 10px 16px;
  border-bottom: 1px solid #1e2540;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  background: #0f1628;
}

.atmo-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.atmo-label {
  font-size: 10px;
  font-weight: 600;
  color: #667;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.atmo-value {
  font-size: 13px;
  font-weight: 700;
  color: #c8d4e8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sidebar-header {
  padding: 12px 16px 8px;
  border-bottom: 1px solid #1e2540;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: #b8c4e0;
}

#species-count {
  font-size: 11px;
  color: #666;
}

#species-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

#species-list::-webkit-scrollbar {
  width: 6px;
}

#species-list::-webkit-scrollbar-track {
  background: transparent;
}

#species-list::-webkit-scrollbar-thumb {
  background: #2a3050;
  border-radius: 3px;
}

/* Species list items */
.species-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  transition: all 0.4s ease;
  border-left: 3px solid transparent;
}

.species-item.entering {
  animation: slideIn 0.4s ease forwards;
}

.species-item.exiting {
  animation: slideOut 0.4s ease forwards;
}

.species-item.highlight {
  background: rgba(255, 255, 255, 0.04);
}

.species-item.extinction-exit {
  animation: extinctionFade 0.6s ease forwards;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(-30px); max-height: 0; padding: 0 16px; }
}

@keyframes extinctionFade {
  0% { opacity: 1; background: transparent; }
  30% { background: rgba(255, 50, 50, 0.2); }
  100% { opacity: 0; transform: translateX(-20px); max-height: 0; padding: 0 16px; }
}

.species-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.species-info {
  flex: 1;
  min-width: 0;
}

.species-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #d0d0d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.species-desc {
  display: block;
  font-size: 10px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.species-item {
  cursor: pointer;
}

.sparkline-wrap {
  margin-top: 2px;
  line-height: 0;
}

.sparkline-canvas {
  display: block;
  opacity: 0.85;
}

#atmosphere-panel {
  flex-wrap: wrap;
}

.abundance-bar-container {
  width: 40px;
  height: 4px;
  background: #1a1e30;
  border-radius: 2px;
  flex-shrink: 0;
}

.abundance-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ===== Timeline Controls ===== */

#timeline-controls {
  grid-area: controls;
  background: #111628;
  border-top: 1px solid #1e2540;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#era-strip {
  height: 8px;
  border-radius: 4px;
  display: flex;
  overflow: hidden;
}

.era-segment {
  height: 100%;
  transition: opacity 0.3s;
}

.era-segment:hover {
  opacity: 0.8;
}

.scrubber-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-label-end {
  font-size: 10px;
  color: #666;
  white-space: nowrap;
}

#scrubber {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #1a2040;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5588cc;
  cursor: pointer;
  border: 2px solid #0a0e1a;
}

#scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5588cc;
  cursor: pointer;
  border: 2px solid #0a0e1a;
}

.transport-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.transport-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: #1a2040;
  color: #b8c4e0;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.transport-btn:hover {
  background: #2a3060;
}

.transport-btn.playing {
  background: #2a4060;
  color: #66aaff;
}

#speed-select {
  padding: 4px 8px;
  background: #1a2040;
  border: 1px solid #2a3050;
  border-radius: 4px;
  color: #b8c4e0;
  font-size: 12px;
  cursor: pointer;
}

#current-time-display {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: #b8c4e0;
  font-variant-numeric: tabular-nums;
}

/* ===== Responsive ===== */

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "toolbar"
      "viz"
      "controls";
  }

  #sidebar {
    position: fixed;
    right: -280px;
    top: 48px;
    bottom: 96px;
    width: 280px;
    z-index: 20;
    transition: right 0.3s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
  }

  #sidebar.open {
    right: 0;
  }
}

@media (max-width: 600px) {
  #toolbar {
    padding: 0 8px;
    gap: 8px;
  }

  #app-title {
    font-size: 13px;
  }

  .toggle-btn {
    font-size: 11px;
    padding: 3px 8px;
  }

  #extinction-text {
    font-size: 20px;
  }

  #extinction-subtext {
    font-size: 13px;
  }
}

/* ========================================================================== */
/* Capture mode — activated via ?capture=1 (see js/capture.js).               */
/* Hides chrome so external screen-recording scripts get a clean frame.       */
/* ========================================================================== */

body.capture-mode #toolbar,
body.capture-mode #timeline-controls,
body.capture-mode #sidebar,
body.capture-mode #legend-panel,
body.capture-mode #time-overlay,
body.capture-mode #species-popup,
body.capture-mode #species-modal,
body.capture-mode #species-modal-backdrop {
  display: none !important;
}

body.capture-mode #app {
  grid-template-rows: 1fr;
  grid-template-columns: 1fr;
  grid-template-areas: "viz";
}

body.capture-mode #viz-container {
  grid-area: viz;
}

/* Variant: keep the species sidebar visible (sequences highlighting life). */
body.capture-mode.capture-mode-with-sidebar #sidebar {
  display: flex !important;
}
body.capture-mode.capture-mode-with-sidebar #app {
  grid-template-columns: 1fr 280px;
  grid-template-areas: "viz sidebar";
}

/* Variant: keep the time/period overlay visible. */
body.capture-mode.capture-mode-with-clock #time-overlay {
  display: block !important;
}
