/* ═══════════════════════════════════════════════════════════
   antifold — Research Lab Design System
   Light + Dark, lattice-inspired, startup-grade
   ═══════════════════════════════════════════════════════════ */

/* ── Dark theme (default) ────────────────────────────────── */
:root {
  --bg:        #0a0a0a;
  --bg-2:      #111111;
  --bg-3:      #181818;
  --bg-card:   #0f0f0f;
  --border:    rgba(255,255,255,0.06);
  --border-2:  rgba(255,255,255,0.10);
  --fg:        #eaeaea;
  --fg-muted:  #999;
  --fg-dim:    #555;
  --accent:    #6aa9ff;
  --violet:    #9b7cff;
  --green:     #7cffc4;
  --accent-bg: rgba(106,169,255,0.06);
  --violet-bg: rgba(155,124,255,0.06);
  --green-bg:  rgba(124,255,196,0.06);

  /* canvas vars (JS reads these) */
  --canvas-bg:   #0a0a0a;
  --canvas-dot:  rgba(255,255,255,0.18);
  --canvas-dot-bright: rgba(255,255,255,0.40);
  --canvas-line: rgba(106,169,255,0.10);
  --canvas-line-hot: rgba(106,169,255,0.25);
  --canvas-flow: rgba(155,124,255,0.06);
  --canvas-ascii: rgba(255,255,255,0.035);
  --canvas-trail: rgba(10,10,10,0.12);

  --nav-bg:    rgba(10,10,10,0.85);

  --font-heading: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
  --font-body:    'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;

  --content-w: 720px;
  --wide-w:    1100px;
  --radius:    4px;
}

/* ── Light theme ─────────────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f8f7f4;
  --bg-2:      #f0eeea;
  --bg-3:      #e8e5e0;
  --bg-card:   #ffffff;
  --border:    rgba(0,0,0,0.07);
  --border-2:  rgba(0,0,0,0.12);
  --fg:        #1a1a1a;
  --fg-muted:  #555;
  --fg-dim:    #999;
  --accent:    #3b7dd8;
  --violet:    #7c5cbf;
  --green:     #1a9a6c;
  --accent-bg: rgba(59,125,216,0.06);
  --violet-bg: rgba(124,92,191,0.06);
  --green-bg:  rgba(26,154,108,0.06);

  --canvas-bg:   #f8f7f4;
  --canvas-dot:  rgba(0,0,0,0.12);
  --canvas-dot-bright: rgba(0,0,0,0.28);
  --canvas-line: rgba(59,125,216,0.08);
  --canvas-line-hot: rgba(59,125,216,0.20);
  --canvas-flow: rgba(124,92,191,0.06);
  --canvas-ascii: rgba(0,0,0,0.035);
  --canvas-trail: rgba(248,247,244,0.12);

  --nav-bg:    rgba(248,247,244,0.85);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}
a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--violet); }
img { max-width: 100%; display: block; }

/* ── Canvas background ───────────────────────────────────── */
#lab-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* ── Layout ──────────────────────────────────────────────── */
.lab-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}
.lab-narrow {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 0 24px;
}
.lab-wide {
  max-width: var(--wide-w);
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Navigation ──────────────────────────────────────────── */
.lab-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background 0.4s ease, border-color 0.4s ease;
}
.lab-nav-logo {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--fg);
}
.lab-nav-logo a { color: var(--fg); }
.lab-nav-logo a:hover { color: var(--accent); }
.lab-nav-links {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 13px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.lab-nav-links a { color: var(--fg-muted); transition: color 0.2s; }
.lab-nav-links a:hover { color: var(--fg); }
.lab-nav-links a.active { color: var(--accent); }

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 5px 8px;
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1;
  transition: color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
}
.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--accent);
}
.theme-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; }

/* ── Hero ────────────────────────────────────────────────── */
.lab-hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 120px 24px 80px;
  max-width: var(--wide-w);
  margin: 0 auto;
  position: relative;
}
/* Hero glow */
.lab-hero::before {
  content: '';
  position: absolute;
  top: 30%;
  left: -10%;
  width: 50%;
  height: 40%;
  background: radial-gradient(ellipse, var(--accent-bg) 0%, transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  opacity: 0.6;
}
.lab-hero h1 {
  font-family: var(--font-heading);
  font-size: clamp(2.8rem, 6vw, 5rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.03em;
  color: var(--fg);
  max-width: 14ch;
  margin-bottom: 32px;
}
.lab-hero h1 .accent {
  background: linear-gradient(135deg, var(--accent) 0%, var(--violet) 50%, var(--green) 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 6s ease-in-out infinite;
}
.lab-hero h1 .violet { color: var(--violet); }
.lab-hero-sub {
  font-size: 18px;
  line-height: 1.65;
  color: var(--fg-muted);
  max-width: 52ch;
  margin-bottom: 48px;
}
.lab-hero-cta {
  display: inline-flex;
  gap: 24px;
  font-family: var(--font-mono);
  font-size: 14px;
}
.lab-hero-cta a {
  padding: 10px 24px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--fg-muted);
  transition: all 0.3s ease;
}
.lab-hero-cta a:hover {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--accent-bg);
}
.lab-hero-cta a.primary {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--accent-bg);
}
.lab-hero-cta a.primary:hover {
  background: rgba(106,169,255,0.12);
}

/* ── Hero decorative elements ───────────────────────────── */
.hero-line {
  width: 48px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent);
  margin-bottom: 24px;
  animation: fadeSlideUp 1s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 0.1s;
}
.canvas-active .hero-line { animation-delay: 1.9s; }
.hero-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  margin-bottom: 20px;
  animation: fadeSlideUp 1s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 0.15s;
}
.canvas-active .hero-status { animation-delay: 2.0s; }
.hero-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: gentlePulse 2.5s ease-in-out infinite;
}
.hero-divider {
  width: 100%;
  max-width: 120px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--violet) 50%, transparent 100%);
  margin: 40px 0;
  opacity: 0.4;
}
/* Scroll indicator */
.hero-scroll {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: fadeSlideUp 1s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 1.2s;
  opacity: 0.5;
  transition: opacity 0.3s;
}
.canvas-active .hero-scroll { animation-delay: 3s; }
.hero-scroll:hover { opacity: 0.8; }
@keyframes scrollBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(4px); }
}
.hero-scroll svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  animation: scrollBounce 2s ease-in-out infinite;
}

/* ── Hero entrance animation (CSS-only, SEO-safe) ────────── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes gentlePulse {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.hero-reveal {
  animation: fadeSlideUp 1s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.hero-reveal.delay-1 { animation-delay: 0.3s; }
.hero-reveal.delay-2 { animation-delay: 0.6s; }
.hero-reveal.delay-3 { animation-delay: 0.9s; }
/* When JS canvas is active, re-delay to sync with lattice intro */
.canvas-active .hero-reveal { animation-delay: 2.0s; }
.canvas-active .hero-reveal.delay-1 { animation-delay: 2.15s; }
.canvas-active .hero-reveal.delay-2 { animation-delay: 2.35s; }
.canvas-active .hero-reveal.delay-3 { animation-delay: 2.55s; }

/* ── Scroll-triggered section reveals ────────────────────── */
.lab-section,
.lab-section-narrow {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}
.lab-section.visible,
.lab-section-narrow.visible {
  opacity: 1;
  transform: none;
}

/* ── Section ─────────────────────────────────────────────── */
.lab-section {
  padding: 120px 24px;
  max-width: var(--wide-w);
  margin: 0 auto;
}
.lab-section-narrow {
  padding: 100px 24px;
  max-width: var(--content-w);
  margin: 0 auto;
}
.lab-section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.lab-section-label::before {
  content: '';
  width: 12px;
  height: 1px;
  background: var(--accent);
  opacity: 0.5;
}
.lab-section h2 {
  font-family: var(--font-heading);
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--fg);
  margin-bottom: 24px;
}
.lab-section h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 12px;
}

/* ── Prose ────────────────────────────────────────────────── */
.lab-prose p {
  color: var(--fg-muted);
  margin-bottom: 20px;
  max-width: 65ch;
}
.lab-prose p strong { color: var(--fg); font-weight: 500; }
.lab-prose h2 {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--fg);
  margin: 56px 0 16px;
  letter-spacing: -0.01em;
}
.lab-prose h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--fg);
  margin: 40px 0 12px;
}
.lab-prose blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 20px;
  margin: 32px 0;
  color: var(--fg-muted);
  font-style: italic;
}
.lab-prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
}

/* ── Cards grid ──────────────────────────────────────────── */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}
.lab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
.lab-card:hover {
  border-color: var(--border-2);
  background: var(--bg-2);
  box-shadow: 0 4px 24px var(--accent-bg);
  transform: translateY(-2px);
}
.lab-card canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}
.lab-card:hover canvas { opacity: 1; }
.lab-card-icon {
  margin-bottom: 14px;
  color: var(--accent);
  opacity: 0.5;
  transition: opacity 0.3s, transform 0.3s;
}
.lab-card:hover .lab-card-icon { opacity: 0.9; transform: scale(1.1); }
.lab-card-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.lab-card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 10px;
}
.lab-card-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg-muted);
}
.lab-card-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

/* ── Experiment blocks ───────────────────────────────────── */
.lab-experiment {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
  transition: border-color 0.3s, background 0.3s;
}
.lab-experiment canvas {
  position: absolute;
  top: 0; right: 0;
  width: 240px; height: 100%;
  pointer-events: none;
}
.lab-experiment-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.lab-experiment h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 16px;
}
.lab-experiment-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 12px;
}
.lab-experiment-row dt {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: 6px;
}
.lab-experiment-row dd {
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.6;
}

/* ── Essay list ──────────────────────────────────────────── */
.lab-essay-item {
  display: block;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
  transition: padding-left 0.3s ease, border-color 0.3s ease;
}
.lab-essay-item:first-child { border-top: 1px solid var(--border); }
.lab-essay-item:hover { padding-left: 12px; border-color: var(--accent); }
.lab-essay-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 6px;
  transition: color 0.2s;
}
.lab-essay-item:hover .lab-essay-title { color: var(--accent); }
.lab-essay-excerpt {
  font-size: 14px;
  color: var(--fg-muted);
  max-width: 60ch;
}

/* ── Principles list ─────────────────────────────────────── */
.lab-principles {
  list-style: none;
  counter-reset: principle;
}
.lab-principles li {
  counter-increment: principle;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 20px;
  align-items: baseline;
}
.lab-principles li::before {
  content: counter(principle, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-dim);
  flex-shrink: 0;
  width: 24px;
}
.lab-principle-text {
  font-size: 15px;
  color: var(--fg-muted);
  line-height: 1.6;
}
.lab-principle-text strong {
  display: block;
  color: var(--fg);
  font-weight: 500;
  margin-bottom: 4px;
}

/* ── Contact ─────────────────────────────────────────────── */
.lab-contact-form {
  margin-top: 32px;
}
.lab-contact-form input[type="email"] {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--fg);
  width: 100%;
  max-width: 400px;
  outline: none;
  transition: border-color 0.3s, background 0.3s;
}
.lab-contact-form input[type="email"]::placeholder { color: var(--fg-dim); }
.lab-contact-form input[type="email"]:focus { border-color: var(--accent); }
.lab-contact-form button {
  margin-top: 12px;
  display: block;
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 10px 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.3s;
}
.lab-contact-form button:hover {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--accent-bg);
}

/* ── Divider ─────────────────────────────────────────────── */
.lab-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

/* ── Footer ──────────────────────────────────────────────── */
.lab-footer {
  padding: 48px 24px;
  text-align: center;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--fg-dim);
  border-top: 1px solid var(--border);
  transition: border-color 0.4s;
}

/* ── Education section cards ─────────────────────────────── */
.edu-section-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--fg);
  margin: 48px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.edu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.edu-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.3s, background 0.3s, transform 0.3s, box-shadow 0.3s;
}
.edu-card:hover {
  border-color: var(--border-2);
  background: var(--bg-2);
  transform: translateY(-1px);
  box-shadow: 0 2px 12px var(--accent-bg);
}
.edu-card-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 8px;
}
.edu-card-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 6px;
}
.edu-card-desc {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.5;
}
.edu-card-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 10px;
}

/* ── ASCII overlay (decorative) ──────────────────────────── */
.ascii-overlay {
  position: fixed;
  bottom: 24px;
  right: 24px;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.3;
  color: var(--fg-dim);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
  white-space: pre;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .lab-nav { padding: 12px 16px; }
  .lab-nav-links { gap: 14px; font-size: 12px; }
  .lab-hero { padding: 100px 20px 60px; min-height: auto; }
  .lab-hero h1 { font-size: 2.2rem; }
  .lab-hero::before { display: none; }
  .hero-scroll { display: none; }
  .lab-section { padding: 80px 20px; }
  .lab-section-narrow { padding: 60px 20px; }
  .lab-grid { grid-template-columns: 1fr; }
  .lab-experiment-row { grid-template-columns: 1fr; }
  .lab-experiment canvas { display: none; }
  .ascii-overlay { display: none; }
}
@media (max-width: 480px) {
  .lab-nav-links { gap: 10px; }
  .lab-nav-links a { font-size: 11px; }
  .lab-hero h1 { font-size: 1.8rem; }
}
