/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #1a1a1a;
  --paper: #faf9f6;
  --accent: #8b2500;
  --accent-light: #c4512a;
  --gray-100: #f5f4f1;
  --gray-200: #e8e6e1;
  --gray-300: #d1cec7;
  --gray-500: #8a8580;
  --gray-700: #4a4640;
  --serif: 'Crimson Pro', 'Georgia', serif;
  --sans: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

html { font-size: 16px; }
body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--gray-100);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--gray-200);
  box-shadow: 4px 0 24px rgba(0,0,0,0.08);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
}

.sidebar-close {
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--gray-500);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-close:hover { background: var(--gray-100); color: var(--ink); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.sidebar-empty {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--gray-500);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
}

.sidebar-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.1s;
}

.sidebar-item:hover { background: var(--gray-100); }

.sidebar-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid var(--gray-200);
}

.sidebar-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sidebar-title {
  font-family: var(--serif);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.sidebar-date {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--gray-500);
  margin-top: 0.2rem;
}

.sidebar-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 999;
  width: 40px;
  height: 40px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 1.1rem;
  color: var(--gray-700);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: all 0.15s;
}

.sidebar-toggle:hover { border-color: var(--gray-500); background: var(--gray-100); }

/* ===== LANDING ===== */
.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.landing-content {
  text-align: center;
  max-width: 560px;
}

.logo-mark {
  font-size: 3rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  opacity: 0.85;
}

.landing h1 {
  font-family: var(--serif);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.subtitle {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gray-500);
  margin-bottom: 1.5rem;
}

.tagline {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-style: italic;
  color: var(--gray-700);
  margin-bottom: 2.5rem;
}

/* ===== DROPZONE ===== */
.dropzone {
  border: 2px dashed var(--gray-300);
  border-radius: 12px;
  padding: 3rem 2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #fdf6f3;
}

.dropzone.dragover { transform: scale(1.01); }

.dropzone-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }

.dropzone-text {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.dropzone-subtext {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--gray-500);
}

/* ===== PREVIEW ===== */
.preview-area { margin-top: 2rem; }

.preview-area img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  margin-bottom: 1.25rem;
}

.preview-controls { display: flex; gap: 0.75rem; justify-content: center; }

.btn-analyze {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.75rem 2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-analyze:hover { background: var(--accent-light); }

.btn-clear {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.75rem 1.5rem;
  background: transparent;
  color: var(--gray-500);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-clear:hover { border-color: var(--gray-500); color: var(--ink); }

.disclaimer {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--gray-500);
  margin-top: 3rem;
  letter-spacing: 0.02em;
}

/* ===== LOADING ===== */
.loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.5rem;
}

.spinner-sm {
  width: 24px;
  height: 24px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}

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

.loading h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.loading-status {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--gray-500);
  font-style: italic;
}

/* ===== OUTPUT ===== */
.output {
  min-height: 100vh;
  background: var(--gray-100);
  padding: 1.5rem;
}

.output-toolbar {
  max-width: 820px;
  margin: 0 auto 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-back, .btn-print {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-back {
  background: transparent;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}

.btn-back:hover { border-color: var(--gray-500); }

.btn-print { background: var(--ink); color: white; border: none; }
.btn-print:hover { background: #333; }

/* ===== PAPER CONTAINER ===== */
.paper-container {
  max-width: 820px;
  margin: 0 auto;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  padding: 3rem 3.5rem;
}

.family-tree-wrapper:empty { display: none; }

/* ===== PAPER TYPOGRAPHIC STYLES ===== */
.paper .journal-header {
  text-align: center;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 1.75rem;
}

.paper .journal-header .journal-name {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.paper .journal-header .journal-issn {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--gray-500);
  margin-top: 0.15rem;
}

.paper .title {
  font-family: var(--serif);
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  margin-bottom: 0.75rem;
  color: var(--ink);
}

.paper .authors {
  font-family: var(--sans);
  font-size: 0.8rem;
  text-align: center;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.paper .affiliation {
  font-family: var(--sans);
  font-size: 0.72rem;
  text-align: center;
  color: var(--gray-500);
  font-style: italic;
  margin-bottom: 0.25rem;
}

.paper .meta {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 2rem;
}

.paper .abstract {
  background: var(--gray-100);
  border-left: 3px solid var(--accent);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.75rem;
  border-radius: 0 4px 4px 0;
}

.paper .abstract h2,
.paper .section h2 {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.paper .abstract p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--gray-700);
}

.paper .section { margin-bottom: 1.5rem; }

.paper .section p {
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 0.75rem;
  text-align: justify;
  hyphens: auto;
}

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

.paper blockquote {
  border-left: 2px solid var(--gray-300);
  padding: 0.5rem 0 0.5rem 1.25rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--gray-700);
  font-size: 0.92rem;
}

.paper blockquote cite {
  display: block;
  font-style: normal;
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 0.35rem;
}

/* Specimen Display */
.paper .specimen-display {
  text-align: center;
  margin: 1.5rem 0;
  padding: 1.25rem;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
}

.paper .specimen-display img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 4px;
  border: 1px solid var(--gray-300);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.paper .specimen-caption {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.75rem;
  font-style: italic;
}

/* Data Viz */
.paper .data-viz {
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.paper .data-viz h3 {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  margin-bottom: 0.75rem;
}

.paper .metric {
  display: inline-block;
  text-align: center;
  padding: 0.75rem 1.25rem;
  margin: 0.25rem;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
}

.paper .metric .metric-value {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.paper .metric .metric-label {
  font-family: var(--sans);
  font-size: 0.65rem;
  color: var(--gray-500);
  margin-top: 0.15rem;
}

.paper .bar-chart .bar-row { display: flex; align-items: center; margin-bottom: 0.4rem; }
.paper .bar-chart .bar-label { font-family: var(--sans); font-size: 0.72rem; width: 160px; flex-shrink: 0; color: var(--gray-700); }
.paper .bar-chart .bar-track { flex: 1; height: 18px; background: var(--gray-200); border-radius: 3px; overflow: hidden; }
.paper .bar-chart .bar-fill { height: 100%; background: var(--accent); border-radius: 3px; opacity: 0.85; }
.paper .bar-chart .bar-value { font-family: var(--mono); font-size: 0.7rem; color: var(--gray-500); margin-left: 0.5rem; width: 40px; }

/* Tufte Infographic */
.paper .tufte-viz {
  margin: 1.5rem 0;
  padding: 1.75rem 2rem;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 2px;
  position: relative;
}

.paper .tufte-viz .tufte-title { font-family: var(--serif); font-size: 0.85rem; font-weight: 600; color: var(--ink); margin-bottom: 1.25rem; letter-spacing: -0.01em; line-height: 1.3; }
.paper .tufte-viz .tufte-chart { position: relative; min-height: 120px; border-left: 1px solid var(--gray-300); border-bottom: 1px solid var(--gray-300); padding: 0.5rem 0.5rem 1.5rem 2.5rem; margin-bottom: 0.5rem; }
.paper .tufte-viz .tufte-bar { display: flex; align-items: center; margin-bottom: 0.4rem; }
.paper .tufte-viz .tufte-bar-label { font-family: var(--sans); font-size: 0.65rem; color: var(--gray-500); width: 100px; flex-shrink: 0; text-align: right; padding-right: 0.75rem; }
.paper .tufte-viz .tufte-bar-fill { height: 14px; border-radius: 1px; opacity: 0.7; }
.paper .tufte-viz .tufte-labels { display: flex; justify-content: space-between; padding: 0 0 0 2.5rem; }
.paper .tufte-viz .tufte-axis-label { font-family: var(--sans); font-size: 0.6rem; color: var(--gray-500); letter-spacing: 0.04em; }
.paper .tufte-viz .tufte-y-label { position: absolute; left: -0.25rem; top: 50%; transform: rotate(-90deg) translateX(-50%); transform-origin: left center; font-family: var(--sans); font-size: 0.6rem; color: var(--gray-500); letter-spacing: 0.04em; white-space: nowrap; }
.paper .tufte-viz .tufte-source { font-family: var(--sans); font-size: 0.58rem; color: var(--gray-500); margin-top: 0.75rem; text-align: right; font-style: italic; }
.paper .tufte-viz .tufte-annotation { font-family: var(--serif); font-size: 0.7rem; font-style: italic; color: var(--gray-500); margin-top: 0.5rem; line-height: 1.4; }
.paper .tufte-viz .tufte-legend { display: flex; gap: 1rem; margin-top: 0.5rem; flex-wrap: wrap; }
.paper .tufte-viz .tufte-legend-item { display: flex; align-items: center; gap: 0.35rem; font-family: var(--sans); font-size: 0.6rem; color: var(--gray-500); }
.paper .tufte-viz .tufte-legend-swatch { width: 10px; height: 10px; border-radius: 1px; }

/* References */
.paper .references { border-top: 1px solid var(--gray-200); padding-top: 1.25rem; margin-top: 1.75rem; }
.paper .references h2 { font-family: var(--sans); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); margin-bottom: 0.75rem; }
.paper .references ol { padding-left: 1.25rem; }
.paper .references li { font-size: 0.78rem; line-height: 1.5; color: var(--gray-700); margin-bottom: 0.35rem; }

/* Peer Review */
.paper .peer-review { background: #fef9e7; border: 1px solid #f0e6b8; border-radius: 6px; padding: 1.25rem; margin-top: 1.75rem; }
.paper .peer-review h2 { font-family: var(--sans); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: #b8860b; margin-bottom: 0.75rem; }
.paper .peer-review p { font-size: 0.82rem; line-height: 1.55; color: var(--gray-700); margin-bottom: 0.5rem; font-style: italic; }
.paper .peer-review p:last-child { margin-bottom: 0; }

/* Acknowledgments */
.paper .acknowledgments { font-size: 0.82rem; line-height: 1.55; color: var(--gray-700); font-style: italic; border-top: 1px solid var(--gray-200); padding-top: 1rem; margin-top: 1.5rem; }
.paper .acknowledgments h2 { font-family: var(--sans); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); margin-bottom: 0.6rem; font-style: normal; }

/* Author Bio */
.paper .author-bio { border-top: 1px solid var(--gray-200); padding-top: 1rem; margin-top: 1.5rem; font-size: 0.78rem; line-height: 1.5; color: var(--gray-500); font-style: italic; }

/* ===== FAMILY TREE ===== */
.family-tree-section h2 {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.tree-subtitle {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--gray-500);
  font-style: italic;
  margin-bottom: 1.5rem;
}

.tree-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
}

.tree-connector {
  width: 2px;
  height: 28px;
  background: var(--gray-300);
}

.tree-branch-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1rem;
  position: relative;
  padding: 0 1rem;
}

.tree-branch-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 160px);
  height: 2px;
  background: var(--gray-300);
}

.tree-branch-arm {
  display: none;
}

.tree-node {
  min-width: 150px;
  max-width: 200px;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  background: white;
  text-align: center;
  position: relative;
}

.tree-node.subject {
  border: 2px solid var(--accent);
  background: #fdf6f3;
  min-width: 180px;
}

.tree-node.theorized-border {
  border-style: dashed;
}

.tree-node-name {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.15rem;
}

.tree-node-year {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
}

.tree-node-desc {
  font-family: var(--serif);
  font-size: 0.7rem;
  color: var(--gray-700);
  line-height: 1.35;
  font-style: italic;
}

.tree-badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  margin-top: 0.35rem;
}

.tree-badge.confirmed {
  background: #e8f5e9;
  color: #2e7d32;
}

.tree-badge.theorized {
  background: #fff3e0;
  color: #e65100;
}

.tree-loading {
  text-align: center;
  padding: 2rem;
}

.tree-loading p {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--gray-500);
  font-style: italic;
}

.tree-unavailable {
  text-align: center;
  padding: 1.5rem;
}

.tree-unavailable p {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--gray-500);
  font-style: italic;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ===== PRINT ===== */
@media print {
  body { background: white; }
  .output { padding: 0; }
  .output-toolbar, .sidebar, .sidebar-toggle { display: none; }
  .paper-container {
    border: none;
    box-shadow: none;
    padding: 0;
    max-width: 100%;
  }
  .paper .peer-review { break-inside: avoid; }
  .family-tree-section { break-inside: avoid; }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .paper-container { padding: 1.5rem 1.25rem; }
  .tree-branch-row { flex-wrap: wrap; }
  .tree-node { min-width: 120px; max-width: 160px; }
}
