/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --accent: #7c3aed;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-light: #94a3b8;
  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --bg-demo: #f0f4ff;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-lg: 12px;

  /* classification colors */
  --in-dist: #059669;
  --in-dist-bg: #ecfdf5;
  --visual: #d97706;
  --visual-bg: #fffbeb;
  --behavioral: #2563eb;
  --behavioral-bg: #eff6ff;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  font-size: 16px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ─── Layout ────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

.container.narrow {
  max-width: 760px;
}

.section {
  padding: 48px 0;
}

.section-alt {
  background: var(--bg-alt);
}

/* ─── Nav ───────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

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

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.nav-links {
  display: flex;
  gap: 28px;
}

.nav-links a {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.nav-links a:hover {
  color: var(--text);
  text-decoration: none;
}

/* ─── Hero ──────────────────────────────────────────────────── */
.hero {
  padding: 52px 0 40px;
  text-align: center;
  background: linear-gradient(180deg, #eef2ff 0%, #ffffff 100%);
  border-bottom: 1px solid var(--border);
}

.hero .title {
  font-size: clamp(1.4rem, 2.8vw, 2.1rem);
  font-weight: 700;
  line-height: 1.25;
  max-width: 820px;
  margin: 0 auto 20px;
  color: var(--text);
}

.hero .authors {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.hero .authors a {
  color: var(--text);
  font-weight: 500;
}

.hero .authors sup {
  font-size: 0.7em;
  color: var(--primary);
}

.hero .affiliations {
  font-size: 0.88rem;
  color: var(--text-light);
  margin-bottom: 20px;
}

.hero .affiliations sup {
  font-size: 0.75em;
  color: var(--primary);
}

.hero-links {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: #1d3a9f; border-color: #1d3a9f; color: white; }

.btn-secondary {
  background: white;
  color: var(--primary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--primary-light); color: var(--primary); }

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-accent:hover { background: #6d28d9; border-color: #6d28d9; color: white; }

.btn[disabled], .btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.82rem;
}

/* ─── Section Headers ───────────────────────────────────────── */
h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 8px;
}

.section > .container > h2,
.section > .container > .section-label {
  text-align: center;
}

.section-intro {
  color: var(--text-secondary);
  max-width: 700px;
  margin: 0 auto 28px;
  text-align: center;
  font-size: 1.02rem;
}

/* ─── Figures ───────────────────────────────────────────────── */
figure {
  margin: 0 0 24px;
}

figure img {
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
}

figcaption {
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

figcaption strong {
  color: var(--text);
}

.figure-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.figure-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 40px;
}

.figure-stack figure {
  margin-bottom: 0;
}

.perturb-dists-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.perturb-dists-stack img {
  display: block;
  border-radius: 0;
  box-shadow: none;
}


/* ─── Method Columns ────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-top: 24px;
}

.two-col p {
  color: var(--text-secondary);
  font-size: 0.97rem;
}

/* ─── Call-out boxes ────────────────────────────────────────── */
.callout {
  background: var(--bg-alt);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 16px 20px;
  margin: 24px 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* ─── Tables ────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead tr {
  background: var(--bg-alt);
}

th {
  text-align: center;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

th.left, td.left { text-align: left; }

td {
  text-align: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

tr:hover td { background: #fafafa; }

td.bold, td strong { font-weight: 700; }

.table-task-header td {
  background: var(--bg-alt);
  font-style: italic;
  font-weight: 600;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ─── Abstract ──────────────────────────────────────────────── */
#abstract p {
  font-size: 1.02rem;
  color: var(--text-secondary);
  line-height: 1.75;
}


/* ─── Citation ──────────────────────────────────────────────── */
.citation-block {
  background: var(--text);
  color: #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 24px;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}

/* ─── Demo Section ──────────────────────────────────────────── */
#demo {
  background: var(--bg-demo);
}

.demo-wrapper {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  margin-top: 32px;
}

/* Query Panel */
.demo-query-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.demo-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.demo-tab {
  flex: 1;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.demo-tab.active {
  color: var(--primary);
  background: var(--bg-alt);
  border-bottom: 2px solid var(--primary);
}

.demo-tab-content {
  display: none;
  padding: 20px;
}

.demo-tab-content.active {
  display: block;
}

/* Examples grid */
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  min-height: 180px;
}

.examples-placeholder {
  grid-column: 1/-1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--text-light);
  text-align: center;
  gap: 8px;
}

.examples-placeholder svg {
  opacity: 0.4;
}

.example-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-alt);
}

.example-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.example-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.example-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.example-card-label {
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary-light);
  background: #f0f4ff;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  text-align: center;
  padding: 24px;
}

.upload-placeholder svg {
  opacity: 0.5;
}

.upload-placeholder span {
  font-size: 0.88rem;
}

.upload-placeholder .upload-link {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  text-decoration: underline;
}

#upload-preview {
  max-height: 220px;
  width: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.upload-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}

/* Instruction row */
.instruction-row {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.instruction-row label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.instruction-row input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s;
}

.instruction-row input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Settings Panel */
.demo-settings-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.settings-card h3 {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.setting-row {
  margin-bottom: 12px;
}

.setting-row label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.setting-row input,
.setting-row select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}

.setting-row input:focus,
.setting-row select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 4px;
  line-height: 1.4;
}

/* Results */
.demo-results {
  margin-top: 20px;
}

.demo-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.results-count {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.result-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}

.result-card:hover {
  box-shadow: var(--shadow-md);
}

.result-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: var(--bg-alt);
}

.result-card-body {
  padding: 10px;
}

.result-card-instruction {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.35;
  margin-bottom: 6px;
}

.result-card-meta {
  font-size: 0.72rem;
  color: var(--text-light);
}

/* Classification badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-indist {
  background: var(--in-dist-bg);
  color: var(--in-dist);
}

.badge-visual {
  background: var(--visual-bg);
  color: var(--visual);
}

.badge-behavioral {
  background: var(--behavioral-bg);
  color: var(--behavioral);
}

/* Analysis section */
.analysis-trigger {
  margin-top: 20px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.analysis-trigger p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  flex: 1;
}

.analysis-section {
  margin-top: 20px;
}

.overall-verdict {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.verdict-icon {
  font-size: 2.5rem;
  flex-shrink: 0;
}

.verdict-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.verdict-classification {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.verdict-classification.indist { color: var(--in-dist); }
.verdict-classification.visual { color: var(--visual); }
.verdict-classification.behavioral { color: var(--behavioral); }

.verdict-reasoning {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.analysis-examples {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.analysis-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.analysis-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.analysis-card-header:hover {
  background: var(--bg-alt);
}

.analysis-card-thumb {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg-alt);
}

.analysis-card-instruction {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.analysis-card-toggle {
  font-size: 0.75rem;
  color: var(--text-light);
  transition: transform 0.2s;
}

.analysis-card.open .analysis-card-toggle {
  transform: rotate(180deg);
}

.analysis-card-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.analysis-card.open .analysis-card-body {
  display: block;
}

.axes-table {
  width: 100%;
  font-size: 0.8rem;
  margin-top: 12px;
}

.axes-table th {
  font-size: 0.75rem;
  padding: 7px 10px;
}

.axes-table td {
  padding: 7px 10px;
  font-size: 0.8rem;
}

.axis-indist { color: var(--in-dist); font-weight: 600; }
.axis-ood { color: #dc2626; font-weight: 600; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

.spinner-dark {
  border-color: rgba(30,64,175,0.2);
  border-top-color: var(--primary);
}

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

/* Status messages */
.status-msg {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-top: 12px;
}

.status-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
}

.status-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #059669;
}

.status-info {
  background: var(--behavioral-bg);
  border: 1px solid #bfdbfe;
  color: var(--primary);
}

/* Hidden utility */
.hidden { display: none !important; }

/* ─── Footer ────────────────────────────────────────────────── */
footer {
  padding: 32px 24px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .demo-wrapper {
    grid-template-columns: 1fr;
  }

  .demo-settings-panel {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .settings-card {
    flex: 1;
    min-width: 240px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .figure-row {
    grid-template-columns: 1fr;
  }


}

@media (max-width: 640px) {
  .nav-links { display: none; }
  .hero { padding: 32px 0 28px; }
  .section { padding: 32px 0; }
  h2 { font-size: 1.4rem; }
  .results-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
