/* ═══════════════════════════════════════════════════════════════
   EMERGENCE — Design System
   ═══════════════════════════════════════════════════════════════ */

/* ─── Native page transitions (Chrome / Edge) ──────────────── */
@view-transition { navigation: auto; }

::view-transition-old(root) {
  animation: 320ms cubic-bezier(0.4, 0, 1, 1) both vt-leave;
}
::view-transition-new(root) {
  animation: 380ms cubic-bezier(0, 0, 0.2, 1) both vt-enter;
}

@keyframes vt-leave {
  to { opacity: 0; transform: translateY(-14px) scale(0.985); filter: blur(4px); }
}
@keyframes vt-enter {
  from { opacity: 0; transform: translateY(14px) scale(0.985); filter: blur(4px); }
}

/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:            #07070d;
  --bg-card:       #0e0e1c;
  --bg-hover:      #14142a;
  --text:          #e6e1d9;
  --text-muted:    #5a5a70;
  --text-dim:      #9292a8;
  --accent:        #6eb5ff;
  --accent-rgb:    110, 181, 255;
  --border:        rgba(255, 255, 255, 0.07);
  --border-accent: rgba(110, 181, 255, 0.22);
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans:  'Inter', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Courier New', monospace;
}

body.page-life     { --accent: #4ade80; --accent-rgb: 74, 222, 128;  --border-accent: rgba(74,222,128,0.22); }
body.page-form     { --accent: #c084fc; --accent-rgb: 192, 132, 252; --border-accent: rgba(192,132,252,0.22); }
body.page-patterns { --accent: #e879f9; --accent-rgb: 232, 121, 249; --border-accent: rgba(232,121,249,0.22); }
body.page-mind     { --accent: #ffb347; --accent-rgb: 255, 179, 71;  --border-accent: rgba(255,179,71,0.22); }
body.page-cosmos   { --accent: #22d3ee; --accent-rgb: 34, 211, 238;  --border-accent: rgba(34,211,238,0.22); }

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.75;
  font-size: 16px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
}

/* ─── Navigation ─────────────────────────────────────────────── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 1.1rem 2.5rem;
  background: rgba(7, 7, 13, 0.82);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

nav.scrolled {
  background: rgba(7, 7, 13, 0.95);
  border-bottom-color: var(--border);
}

.nav-logo {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.nav-logo span { color: var(--accent); transition: color 0.3s; }

.nav-links {
  display: flex;
  gap: 1.75rem;
  list-style: none;
  flex: 1;
}

.nav-links a {
  position: relative;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transition: color 0.2s;
  padding-bottom: 2px;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0; right: 100%;
  height: 1px;
  background: var(--accent);
  transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links a:hover { color: var(--text); }
.nav-links a:hover::after,
.nav-links a.active::after { right: 0; }
.nav-links a.active { color: var(--accent); }

.nav-chapter-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-left: auto;
  flex-shrink: 0;
}

/* Scroll progress bar */
#scroll-progress {
  position: absolute;
  bottom: -1px; left: 0;
  height: 2px;
  width: 0%;
  background: linear-gradient(to right, var(--accent), rgba(var(--accent-rgb), 0.4));
  transition: width 0.08s linear;
  pointer-events: none;
  border-radius: 0 1px 1px 0;
}

/* ─── Hero ───────────────────────────────────────────────────── */
.hero {
  position: relative;
  height: 100vh;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 75% 55% at 50% 50%, transparent 20%, rgba(7,7,13,0.72) 100%),
    linear-gradient(to bottom,
      rgba(7,7,13,0.5) 0%,
      transparent 18%,
      transparent 72%,
      rgba(7,7,13,0.97) 100%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 10;
  max-width: 860px;
  padding: 2rem;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.75rem;
  opacity: 0;
  animation: hero-rise 0.8s ease 0.3s both;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(3.8rem, 10.5vw, 8rem);
  font-weight: 300;
  line-height: 1.0;
  color: var(--text);
  margin-bottom: 1.75rem;
  letter-spacing: -0.03em;
  opacity: 0;
  animation: hero-rise 0.9s cubic-bezier(0.22,1,0.36,1) 0.5s both;
}

.hero-title em {
  font-style: italic;
  color: var(--accent);
}

.hero-sub {
  font-size: clamp(0.95rem, 1.7vw, 1.1rem);
  color: var(--text-dim);
  max-width: 580px;
  margin: 0 auto 2.5rem;
  line-height: 1.88;
  font-weight: 300;
  opacity: 0;
  animation: hero-rise 0.8s ease 0.9s both;
}

@keyframes hero-rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.scroll-hint {
  position: absolute;
  bottom: 2.5rem; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0;
  animation: hero-rise 0.6s ease 1.5s both;
}

.scroll-line {
  width: 1px;
  height: 38px;
  background: linear-gradient(to bottom, var(--text-muted), transparent);
  animation: scroll-pulse 2.4s ease-in-out infinite;
}

@keyframes scroll-pulse {
  0%, 100% { opacity: 0.25; transform: scaleY(1); }
  50%       { opacity: 0.75; transform: scaleY(1.15); }
}

/* ─── Content ─────────────────────────────────────────────────── */
.content {
  max-width: 1080px;
  margin: 0 auto;
  padding: 5.5rem 2.5rem;
}

.section { margin-bottom: 6rem; }

.section-tag {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.section-tag::after {
  content: '';
  display: block;
  height: 1px;
  width: 44px;
  background: linear-gradient(to right, var(--border-accent), transparent);
}

.section-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 3.8vw, 2.9rem);
  font-weight: 400;
  line-height: 1.18;
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

/* ─── Prose ───────────────────────────────────────────────────── */
.prose {
  color: var(--text-dim);
  font-size: 1.04rem;
  line-height: 1.92;
  max-width: 670px;
}

.prose p { margin-bottom: 1.45em; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { color: var(--text); font-weight: 500; }
.prose em { color: var(--accent); font-style: italic; }

/* Drop cap on first paragraph */
.prose > p:first-child::first-letter {
  font-family: var(--font-serif);
  font-size: 3.6em;
  font-weight: 400;
  line-height: 0.82;
  float: left;
  margin-right: 0.06em;
  margin-top: 0.08em;
  color: var(--text);
}

/* ─── Pull-quote ──────────────────────────────────────────────── */
.pullquote {
  position: relative;
  padding: 2rem 2.5rem 2rem 5rem;
  margin: 4.5rem 0;
  border-left: none;
  background: none;
}

.pullquote::before {
  content: '\201C';
  position: absolute;
  left: -0.4rem;
  top: -2rem;
  font-family: var(--font-serif);
  font-size: 10rem;
  line-height: 1;
  color: var(--accent);
  opacity: 0.18;
  pointer-events: none;
  user-select: none;
}

.pullquote p {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
  font-weight: 300;
  line-height: 1.55;
  color: var(--text);
  font-style: italic;
  margin: 0 0 1rem;
}

.pullquote cite {
  display: block;
  text-align: right;
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  font-style: normal;
}

/* ─── Canvas containers ───────────────────────────────────────── */
.canvas-wrap {
  position: relative;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
  margin: 2.5rem 0 0;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04);
}

.canvas-wrap canvas { display: block; width: 100%; }

.controls {
  display: flex;
  gap: 0.7rem;
  padding: 0.85rem 1.2rem;
  background: rgba(14,14,28,0.97);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 1.05rem;
  background: transparent;
  border: 1px solid var(--border-accent);
  border-radius: 5px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.73rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.btn:hover { background: rgba(var(--accent-rgb), 0.09); }
.btn:active { transform: scale(0.97); }
.btn.on { background: rgba(var(--accent-rgb), 0.14); border-color: var(--accent); }
.btn-danger { color: #f87171; border-color: rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.08); }
.btn:disabled { opacity: 0.35; pointer-events: none; }

.spacer { flex: 1; }

/* ─── Stats ───────────────────────────────────────────────────── */
.stat-row {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  margin: 1.75rem 0;
}

.stat {
  flex: 1;
  min-width: 100px;
  padding: 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 9px;
  text-align: center;
  transition: border-color 0.2s;
}

.stat:hover { border-color: var(--border-accent); }

.stat-val {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  color: var(--accent);
  display: block;
  font-variant-numeric: tabular-nums;
}

.stat-lbl {
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.2rem;
  display: block;
}

/* ─── Cards ───────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin-top: 3rem;
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.65rem;
  text-decoration: none;
  display: block;
  transition: border-color 0.25s, transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s;
  transform-style: preserve-3d;
  overflow: hidden;
}

/* Specular shine layer */
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--shine-x, 50%) var(--shine-y, 50%),
    rgba(255,255,255,0.04) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.card:hover { border-color: var(--border-accent); }
.card:hover::after { opacity: 1; }

.card-num {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.15em;
  margin-bottom: 1rem;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  line-height: 1.22;
}

.card-desc {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.65;
}

.card-arrow {
  margin-top: 1rem;
  font-size: 0.8rem;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.2s, transform 0.2s;
  display: block;
}

.card:hover .card-arrow { opacity: 1; transform: translateX(0); }

/* ─── Pills (pattern selectors) ───────────────────────────────── */
.pills {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.2rem;
  border-top: 1px solid var(--border);
  background: rgba(14,14,28,0.97);
}

.pill {
  padding: 0.32rem 0.82rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  letter-spacing: 0.03em;
}

.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.07);
}

/* ─── Sliders ─────────────────────────────────────────────────── */
.slider-group {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--text-dim);
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  height: 3px;
  width: 100px;
  cursor: pointer;
  outline: none;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.5);
}

/* ─── View-info bar ───────────────────────────────────────────── */
.view-info {
  display: flex;
  gap: 1.5rem;
  padding: 0.72rem 1.2rem;
  border-top: 1px solid var(--border);
  background: rgba(14,14,28,0.97);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  align-items: center;
}

.view-info span { color: var(--accent); }

.render-status {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ─── Two-column ──────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 2.5rem;
  align-items: start;
}

.side-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  position: sticky;
  top: 5rem;
}

.side-panel h3 {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 1rem;
}

.side-panel ul { list-style: none; }

.side-panel li {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.side-panel li:last-child { border-bottom: none; }
.side-val { font-family: var(--font-mono); font-size: 0.8rem; color: var(--accent); }

/* ─── Keyboard hint bar ───────────────────────────────────────── */
.kbd-hint {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 0.5rem 1.2rem;
  border-top: 1px solid var(--border);
  background: rgba(14,14,28,0.97);
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.kbd-hint kbd {
  display: inline-block;
  padding: 0.1rem 0.42rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  margin-right: 0.25rem;
}

/* ─── Timeline ─────────────────────────────────────────────────── */
.timeline {
  margin: 3rem 0;
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, var(--accent), transparent);
}

.timeline-item {
  position: relative;
  padding: 0 0 2.5rem 1.5rem;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -4px; top: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.6);
}

.timeline-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 0.35rem;
}

.timeline-event {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.timeline-desc {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.72;
}

/* ─── Scroll-reveal ───────────────────────────────────────────── */
.will-reveal {
  opacity: 0;
  transform: translateY(22px);
  transition:
    opacity  0.75s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.75s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(var(--ri, 0) * 55ms);
}

.will-reveal.revealed {
  opacity: 1;
  transform: none;
}

/* ─── Cursor glow ─────────────────────────────────────────────── */
#cursor-glow {
  position: fixed;
  top: 0; left: 0;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(var(--accent-rgb), 0.055) 0%,
    transparent 65%);
  pointer-events: none;
  z-index: 9998;
  transform: translate(-50%, -50%);
  transition: width 0.4s ease, height 0.4s ease, background 0.4s ease;
  will-change: transform;
}

#cursor-glow.cursor-over {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle,
    rgba(var(--accent-rgb), 0.04) 0%,
    transparent 60%);
}

/* ─── First-visit intro overlay ───────────────────────────────── */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #030309;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

#intro-overlay.exiting {
  animation: intro-exit 0.75s cubic-bezier(0.4, 0, 1, 1) both;
}

@keyframes intro-exit {
  to { opacity: 0; transform: scale(0.98); filter: blur(6px); }
}

#intro-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
}

#intro-word {
  font-family: var(--font-serif);
  font-size: clamp(4.5rem, 13vw, 9.5rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  color: var(--text);
  opacity: 0;
  animation: intro-rise 1s cubic-bezier(0.22, 1, 0.36, 1) 0.25s both;
}

#intro-def {
  font-family: var(--font-serif);
  font-size: clamp(0.85rem, 1.4vw, 1.05rem);
  color: var(--text-dim);
  line-height: 1.95;
  opacity: 0;
  animation: intro-rise 0.8s ease 1.4s both;
}

#intro-def em { font-style: italic; color: var(--text); }

#intro-byline {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0;
  animation: intro-rise 0.6s ease 2.4s both;
}

@keyframes intro-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Footer ──────────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 3rem 2.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.footer-logo {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  letter-spacing: 0.04em;
}

footer a { color: var(--accent); text-decoration: none; transition: opacity 0.15s; }
footer a:hover { opacity: 0.75; }

/* ─── Selection & scrollbar ───────────────────────────────────── */
::selection { background: rgba(var(--accent-rgb), 0.18); color: var(--text); }

::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #22223a; }

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .side-panel { position: static; }
}

@media (max-width: 700px) {
  nav { padding: 0.95rem 1.25rem; }
  .nav-links { gap: 1.1rem; }
  .nav-links a { font-size: 0.72rem; }
  .nav-chapter-tag { display: none; }
  .content { padding: 3rem 1.25rem; }
  .hero-title { font-size: clamp(3rem, 13vw, 5rem); }
  .pullquote { padding: 1.5rem 1.5rem 1.5rem 2.5rem; }
  .pullquote::before { font-size: 6rem; left: -0.2rem; top: -1.5rem; }
}

@media (max-width: 480px) {
  .nav-links { gap: 0.75rem; }
  .nav-links li:nth-child(n+4) { display: none; }
}

/* ─── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .will-reveal { opacity: 1; transform: none; transition: none; }
  .hero-eyebrow, .hero-title, .hero-sub, .scroll-hint { animation: none; opacity: 1; }
  @view-transition { navigation: none; }
  #intro-overlay { display: none; }
}
