/* ========================================
   tAIatlas — Global Styles
   Dark scientific aesthetic
   ======================================== */

/* --- CSS Variables --- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --bg-card-hover: #fcfcfc;
  --border-glass: #e5e7eb;
  --border-glass-hover: #d1d5db;
  --accent: #8b0000;
  --accent-secondary: #a52a2a;
  --accent-gradient: linear-gradient(135deg, #8b0000 0%, #a52a2a 100%);
  --accent-gradient-text: #8b0000;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --success: #059669;
  --warning: #d97706;
  --font-serif: 'Georgia', 'Merriweather', 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.12);
  --shadow-glow: 0 8px 24px rgba(0,0,0,0.08);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --max-width: 1800px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  pointer-events: none;
  z-index: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: #33ddff;
}

img { max-width: 100%; }

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.4rem, 2.5vw, 1.8rem); }
h3 { font-size: clamp(1.1rem, 2vw, 1.3rem); }

.gradient-text {
  color: var(--accent);
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 1;
}

.section {
  padding: 40px 0;
}

.section-header {
  text-align: center;
  margin-bottom: 48px;
}

.section-header p {
  color: var(--text-secondary);
  margin-top: 12px;
  font-size: 1.1rem;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* --- Navigation --- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff5f5;
  border-bottom: 1px solid #ffe0e0;
  transition: background var(--transition);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.03em;
}

.nav-brand .logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 900;
  color: #ffffff;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.nav-links a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: #000000;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text-primary);
  background: rgba(139, 0, 0, 0.05);
}

.nav-links a.active {
  color: var(--accent);
}

/* Mobile hamburger */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
}

.nav-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: currentColor;
  margin: 5px 0;
  transition: var(--transition);
}

/* --- Glass Card --- */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-glass-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius-xl);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  font-family: var(--font-sans);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: #ffffff;
  background: var(--accent-secondary);
}

.btn-secondary {
  background: rgba(139, 0, 0, 0.05);
  color: var(--accent);
  border: 1px solid rgba(139, 0, 0, 0.2);
}

.btn-secondary:hover {
  background: rgba(139, 0, 0, 0.1);
  border-color: rgba(139, 0, 0, 0.4);
  color: var(--accent);
}

/* --- Hero Section --- */
.hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding-top: 64px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  display: none;
}

.hero-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 60px;
}

.hero-stats {
  flex: 1;
}

.hero-stats .stats-grid {
  grid-template-columns: repeat(2, 1fr);
}

.hero-content {
  flex: 1;
  max-width: 600px;
  position: relative;
  z-index: 1;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 100px;
  background: rgba(139, 0, 0, 0.05);
  border: 1px solid rgba(139, 0, 0, 0.15);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 24px;
  animation: fadeInDown 0.8s ease;
}

.hero-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s infinite;
}

.hero h1 {
  margin-bottom: 20px;
  animation: fadeInUp 0.8s ease 0.1s both;
}

.hero-tagline {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  animation: fadeInUp 0.8s ease 0.2s both;
}

.hero-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  animation: fadeInUp 0.8s ease 0.3s both;
}

/* --- Hero Search --- */
.hero-search {
  margin-top: 40px;
  animation: fadeInUp 0.8s ease 0.4s both;
}

.search-container {
  position: relative;
  max-width: 560px;
}

.search-input {
  width: 100%;
  padding: 16px 24px 16px 52px;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font-sans);
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1), var(--shadow-glow);
}

.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

.search-results.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

.search-result-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: rgba(139, 0, 0, 0.05);
}

.search-result-item .species-name {
  font-style: italic;
  font-weight: 500;
}

.search-result-item .species-name mark {
  background: rgba(139, 0, 0, 0.1);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}

.search-result-item .species-group {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 2px 10px;
  border-radius: 100px;
  background: rgba(0,0,0,0.05);
}

/* --- Stats Section --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-card {
  text-align: center;
  padding: 28px 20px;
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 8px;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

/* --- About tAI Section --- */
.about-tai-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}

.about-tai-text p {
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.about-tai-text p:first-of-type {
  font-size: 1.1rem;
  color: var(--text-primary);
}

.formula-card {
  padding: 28px;
  text-align: center;
}

.formula-card .formula {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--accent);
  padding: 20px;
  border-radius: var(--radius-md);
  background: rgba(139, 0, 0, 0.03);
  border: 1px solid rgba(139, 0, 0, 0.1);
  margin-bottom: 16px;
  overflow-x: auto;
}

.formula-card .formula-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- Explorer Table --- */
.explorer-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: center;
}

.explorer-controls .search-container {
  flex: 1;
  min-width: 260px;
}

.filter-select {
  padding: 12px 20px;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  transition: all var(--transition);
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b95a8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.filter-select:focus {
  border-color: var(--accent);
}

.filter-select option {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.species-count {
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.data-table th {
  background: #f3f4f6;
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-glass);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--transition);
}

.data-table th:hover {
  color: var(--accent);
}

.data-table th .sort-arrow {
  margin-left: 4px;
  opacity: 0.3;
  font-size: 0.75rem;
}

.data-table th.sorted .sort-arrow {
  opacity: 1;
  color: var(--accent);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}

.data-table tbody tr:hover {
  background: rgba(139, 0, 0, 0.03);
}

.data-table tbody tr.selected {
  background: rgba(139, 0, 0, 0.08);
  border-left: 3px solid var(--accent);
}

.data-table .species-cell {
  font-style: italic;
  font-weight: 500;
  color: var(--text-primary);
}

.data-table .group-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 500;
}

.group-badge.mammal { background: rgba(255, 107, 107, 0.12); color: #ff6b6b; }
.group-badge.bird { background: rgba(255, 209, 102, 0.12); color: #ffd166; }
.group-badge.fish { background: rgba(72, 191, 227, 0.12); color: #48bfe3; }
.group-badge.reptile { background: rgba(6, 214, 160, 0.12); color: #06d6a0; }
.group-badge.amphibian { background: rgba(188, 143, 255, 0.12); color: #bc8fff; }
.group-badge.other { background: rgba(139, 149, 168, 0.12); color: #8b95a8; }

/* --- Species Detail Panel --- */
.species-detail {
  margin-top: 32px;
  display: none;
}

.species-detail.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

.species-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.species-detail-header h2 {
  font-style: italic;
}

.close-detail {
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.1);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}

.close-detail:hover {
  background: rgba(0,0,0,0.1);
  color: var(--text-primary);
}

.chart-container {
  height: 400px;
  position: relative;
  overflow: visible;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 320px;
  padding: 20px 0;
  width: 100%;
}

.bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  width: 0;
  height: 100%;
  justify-content: flex-end;
}

.bar {
  width: 100%;
  max-width: 16px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  min-height: 2px;
}

.bar:hover {
  filter: brightness(1.3);
  box-shadow: 0 0 10px rgba(139, 0, 0, 0.3);
}

.bar-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  transform: rotate(-60deg);
  white-space: nowrap;
  font-family: var(--font-mono);
  margin-top: 10px;
}

.bar-value {
  font-size: 0.55rem;
  color: var(--text-secondary);
  text-align: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.bar-wrapper:hover .bar-value {
  opacity: 1;
}

.chart-y-axis {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 60px;
  width: 50px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 0;
}

.chart-y-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  font-family: var(--font-mono);
}

/* --- Download Page --- */
.downloads-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
}

.download-card {
  display: flex;
  flex-direction: column;
}

.download-card h3 {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.download-card .file-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: rgba(139, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.download-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
  flex: 1;
}

.download-card .file-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.download-card .file-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Documentation Section --- */
.doc-section {
  margin-bottom: 40px;
}

.doc-section h3 {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.doc-table th,
.doc-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.doc-table th {
  color: var(--accent);
  font-weight: 600;
  background: rgba(139, 0, 0, 0.03);
}

.doc-table td {
  color: var(--text-secondary);
}

.doc-table code {
  font-family: var(--font-mono);
  background: rgba(139, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent);
}

/* --- About / Methodology --- */
.methodology-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.step-card {
  display: flex;
  gap: 16px;
  align-items: start;
}

.step-number {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--bg-primary);
  font-size: 1rem;
}

.step-content h4 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.step-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.citation-box {
  background: rgba(139, 0, 0, 0.03);
  border: 1px solid rgba(139, 0, 0, 0.1);
  border-left: 3px solid var(--accent);
  padding: 20px 24px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-top: 24px;
}

.citation-box p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

.citation-box .citation-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

/* --- Footer --- */
.footer {
  border-top: 1px solid var(--border-glass);
  padding: 40px 0;
  margin-top: 60px;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-links a {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-links a:hover {
  color: var(--accent);
}

/* --- Page Header --- */
.page-header {
  padding: 90px 0 30px;
  text-align: center;
}

.page-header h1 {
  margin-bottom: 12px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.3);
}

/* --- Loading Spinner --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-muted);
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(139, 0, 0, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: #ffffff;
    flex-direction: column;
    padding: 16px;
    border-bottom: 1px solid var(--border-glass);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: 12px 16px;
    width: 100%;
  }

  .hero-content {
    text-align: center;
  }

  .hero-actions {
    justify-content: center;
  }

  .about-tai-grid,
  .methodology-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .downloads-grid {
    grid-template-columns: 1fr;
  }

  .section {
    padding: 48px 0;
  }

  .glass-card {
    padding: 24px;
  }

  .explorer-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header {
    padding: 100px 0 40px;
  }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
  }

  .stat-number {
    font-size: 2rem;
  }
}
