/* ============================================================
   madeofdoors — "the lit place in the dark"
   The Phenomenology of the DAG
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..600;1,9..144,300..500&family=Spectral:ital,wght@0,300;0,400;0,500;1,300;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #0b0b0e;
  --ink-raise: #14141a;
  --ink-deep: #070709;
  --text: #ded8cc;
  --text-soft: #a59f91;
  --text-faint: #6c675b;
  --gold: #e6b24c;
  --gold-bright: #f6cd6f;
  --gold-glow: rgba(230, 178, 76, .15);
  --edge: rgba(222, 216, 204, .14);
  --edge-strong: rgba(222, 216, 204, .34);
  --maxw: 38rem;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Spectral', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --ease: cubic-bezier(.22, .61, .36, 1);
  /* figure model-coding (dark) */
  --sonnet: #5b9bd5; --sonnet-fill: #16293d;
  --opus: #ab92e2; --opus-fill: #271f43; --opus-bright: #c3acf2;
  --cyc-node: #2f9168; --warm: #e0814f;
}

[data-theme="light"] {
  --ink: #efe9db;
  --ink-raise: #f7f2e7;
  --ink-deep: #e6dfce;
  --text: #25221b;
  --text-soft: #595446;
  --text-faint: #8b8472;
  --gold: #9c6a12;
  --gold-bright: #7d540c;
  --gold-glow: rgba(156, 106, 18, .12);
  --edge: rgba(37, 34, 27, .13);
  --edge-strong: rgba(37, 34, 27, .32);
  /* figure model-coding (light) */
  --sonnet: #2f6ea4; --sonnet-fill: #dde9f4;
  --opus: #6a4bb0; --opus-fill: #e8e0f6; --opus-bright: #5733a0;
  --cyc-node: #0e6043; --warm: #c0531e;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--body);
  font-weight: 400;
  font-size: 1.18rem;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background .6s var(--ease), color .6s var(--ease);
}

/* atmosphere: warm cone of light + fine grain */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background: radial-gradient(130vh 90vh at 50% -20%, var(--gold-glow), transparent 62%);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  opacity: .42; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--gold); color: var(--ink-deep); }

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

/* ---------- header / theme toggle ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 1.6rem;
  font-family: var(--mono); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-faint);
  mix-blend-mode: difference;
}
.topbar .mark { color: var(--text-soft); }
.theme-toggle {
  background: none; border: 1px solid var(--edge-strong); color: inherit;
  font: inherit; cursor: pointer; padding: .35rem .7rem; border-radius: 2rem;
  transition: border-color .3s, color .3s;
}
.theme-toggle:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- hero ---------- */
.hero {
  min-height: 100svh; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 6rem 1.5rem 3rem; text-align: center; position: relative;
}
.hero .kicker {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .34em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 2rem;
  opacity: 0; transform: translateY(10px);
}
.hero h1 {
  font-family: var(--display); font-weight: 400;
  font-variation-settings: 'opsz' 144, 'SOFT' 60, 'WONK' 1;
  font-size: clamp(2.6rem, 8vw, 5.6rem); line-height: .98; letter-spacing: -.02em;
  margin: 0 0 1.4rem; max-width: 16ch;
  opacity: 0; transform: translateY(14px);
}
.hero h1 em { font-style: italic; color: var(--gold); }
.hero .epigraph {
  font-family: var(--body); font-style: italic; font-weight: 300;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem); color: var(--text-soft);
  max-width: 34ch; margin: 0 auto 3rem; line-height: 1.6;
  opacity: 0; transform: translateY(14px);
}
.loaded .hero .kicker { animation: rise .9s var(--ease) .1s forwards; }
.loaded .hero h1 { animation: rise 1s var(--ease) .25s forwards; }
.loaded .hero .epigraph { animation: rise 1s var(--ease) .45s forwards; }

.scrollcue {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-faint); margin-top: 1rem; opacity: 0;
}
.scrollcue span { display: block; font-size: 1.1rem; margin-top: .3rem; animation: bob 2.4s ease-in-out infinite; }
.loaded .scrollcue { animation: fade 1.2s var(--ease) 1.4s forwards; }

/* ---------- the DAG figure / navigation ---------- */
.dag-wrap { width: min(960px, 94vw); margin: 1rem auto 2.4rem; }
.dag { width: 100%; height: auto; display: block; overflow: visible; }
.dag .edge { fill: none; stroke: var(--edge-strong); stroke-width: 1.3; }
.dag .edge.skip { stroke: var(--edge); stroke-dasharray: 2 5; }
.dag .edge.crit { stroke: var(--gold); stroke-width: 2.3; filter: drop-shadow(0 0 5px var(--gold-glow)); }
.dag .node { cursor: pointer; }
.dag .node rect {
  fill: var(--ink-raise); stroke: var(--edge-strong); stroke-width: 1.2;
  transition: stroke .3s, fill .3s;
}
.dag .node.crit rect { stroke: var(--gold); }
.dag .node text {
  fill: var(--text); font-family: var(--mono); font-size: 14px;
  text-anchor: middle; dominant-baseline: middle; letter-spacing: .02em;
}
.dag .node:hover rect { stroke: var(--gold-bright); fill: var(--ink); }
.dag .node:hover text { fill: var(--gold-bright); }

/* figure motion: edges draw, nodes rise (topological stagger) */
.dag .edge[pathLength] { stroke-dasharray: 1; stroke-dashoffset: 1; }
.loaded .dag .edge[pathLength] { animation: draw 1.1s var(--ease) forwards; animation-delay: var(--d, 0s); }
.dag .node { opacity: 0; }
.loaded .dag .node { animation: rise .7s var(--ease) forwards; animation-delay: calc(var(--i, 0) * .13s + .55s); }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade { to { opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }

/* ---------- reading layout + spine ---------- */
main { position: relative; padding-bottom: 8rem; }
.spine {
  position: absolute; top: 0; bottom: 0; left: max(2rem, calc(50vw - 26rem));
  width: 1px; background: var(--edge); z-index: 0;
}
.spine-fill {
  position: absolute; inset: 0; background: linear-gradient(var(--gold), var(--gold-bright));
  transform-origin: top; transform: scaleY(0); opacity: .65;
}
@media (max-width: 940px) { .spine { display: none; } }

section.movement {
  position: relative; z-index: 1;
  max-width: var(--maxw); margin: 0 auto; padding: 5rem 1.5rem 1rem;
}
section.movement > .sec-label {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .26em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 1.4rem; display: flex; align-items: center; gap: .8rem;
}
section.movement > .sec-label::before { content: ""; width: 1.6rem; height: 1px; background: var(--gold); opacity: .6; }

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 1s var(--ease), transform 1s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- essay ---------- */
.essay h2 {
  font-family: var(--display); font-weight: 400; font-variation-settings: 'opsz' 60, 'SOFT' 40;
  font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.1; letter-spacing: -.01em;
  margin: 3.4rem 0 1.2rem; color: var(--text);
}
.essay h3 {
  font-family: var(--display); font-weight: 500; font-size: 1.3rem; margin: 2.4rem 0 .8rem;
  color: var(--text);
}
.essay p { margin: 0 0 1.5rem; }
.essay strong { color: var(--gold-bright); font-weight: 500; }
.essay em { font-style: italic; }
.essay code, .colophon code, .essay .mono { font-family: var(--mono); font-size: .86em; color: var(--text-soft); }
.essay blockquote {
  margin: 2rem 0; padding-left: 1.4rem; border-left: 2px solid var(--gold);
  font-style: italic; color: var(--text-soft);
}
.essay hr { border: 0; height: 1px; background: var(--edge); margin: 3rem 0; }
.essay ol, .essay ul { padding-left: 1.4rem; margin: 0 0 1.5rem; }
.essay li { margin: 0 0 .7rem; }
.essay li::marker { color: var(--gold); }

/* the lede after a section title */
.essay .lede { font-size: 1.32rem; color: var(--text); font-style: italic; font-weight: 300; }

/* ---------- verse ---------- */
.verse .poem { margin: 0 0 4.5rem; }
.verse .poem h3 {
  font-family: var(--display); font-weight: 400; font-style: italic;
  font-variation-settings: 'opsz' 40, 'SOFT' 50, 'WONK' 1;
  font-size: 1.7rem; color: var(--gold); margin: 0 0 1.4rem; letter-spacing: -.01em;
}
.verse .stanza { margin: 0 0 1.3rem; line-height: 1.7; color: var(--text); }
.verse .stanza em { font-style: italic; color: var(--text-soft); }

/* ---------- stories ---------- */
.stories .story { margin: 0 0 5rem; }
.stories .story h3 {
  font-family: var(--display); font-weight: 500; font-size: clamp(1.6rem, 3.4vw, 2.1rem);
  margin: 0 0 .3rem; color: var(--text); line-height: 1.1;
}
.stories .story .gloss { font-style: italic; color: var(--text-faint); margin: 0 0 1.8rem; font-size: 1rem; }
.stories .story p { margin: 0 0 1.4rem; }
.stories .story p:first-of-type::first-letter {
  font-family: var(--display); font-weight: 500; float: left;
  font-size: 3.6rem; line-height: .72; padding: .35rem .5rem 0 0; color: var(--gold);
}

/* ---------- haiku ---------- */
.haiku-section .movement-title {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-faint); margin: 3rem 0 1.6rem; text-align: center;
}
.haiku-grid { display: grid; gap: 2.4rem 2rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 620px) { .haiku-grid { grid-template-columns: 1fr; } }
.haiku {
  position: relative; padding-left: 1.6rem; font-family: var(--body); line-height: 1.5;
  color: var(--text); font-size: 1.04rem;
}
.haiku .num {
  position: absolute; left: 0; top: .1rem; font-family: var(--mono); font-size: .7rem;
  color: var(--gold); opacity: .7;
}

/* ---------- colophon ---------- */
.colophon { background: var(--ink-deep); border-top: 1px solid var(--edge); }
.colophon-inner { max-width: 44rem; margin: 0 auto; padding: 5rem 1.5rem; }
.colophon p { font-family: var(--mono); font-size: .92rem; line-height: 1.85; color: var(--text-soft); }
.colophon strong { color: var(--gold); font-weight: 500; }
.colophon .mini-dag { width: 100%; height: auto; margin: 2.6rem 0; overflow: visible; }
.colophon .mini-dag .e { fill: none; stroke: var(--edge-strong); stroke-width: 1; }
.colophon .mini-dag .e.c { stroke: var(--gold); stroke-width: 1.8; }
.colophon .mini-dag rect { fill: var(--ink-raise); stroke: var(--edge-strong); stroke-width: 1; }
.colophon .mini-dag text { fill: var(--text-soft); font-family: var(--mono); font-size: 11px; text-anchor: middle; dominant-baseline: middle; }

footer.foot {
  text-align: center; padding: 3rem 1.5rem 4rem; font-family: var(--mono);
  font-size: .72rem; letter-spacing: .12em; color: var(--text-faint); background: var(--ink-deep);
}
footer.foot .nazar { font-size: 1.1rem; display: block; margin-bottom: .8rem; opacity: .8; }

/* ---------- perf: promote atmosphere to its own compositor layer ---------- */
body::before, body::after { will-change: transform; transform: translateZ(0); }

/* ---------- figures gallery ---------- */
.figures .plate { margin: 0 0 3.4rem; }
.figures .plate-art {
  background: var(--ink-raise); border: 1px solid var(--edge);
  border-radius: 12px; padding: 1.6rem 1.2rem;
  /* the detailed gallery figures break out wider than the reading column (like the hero) */
  width: min(900px, 92vw); margin-left: 50%; transform: translateX(-50%);
}
.figures .plate-art .dag { width: 100%; height: auto; }
.figures figcaption {
  font-family: var(--mono); font-size: .82rem; color: var(--text-soft);
  margin-top: .9rem; line-height: 1.65;
}
.figures .plate-n { color: var(--gold); margin-right: .25rem; }
.figures figcaption strong { color: var(--text); font-weight: 500; }
.dag .node circle { fill: var(--gold); stroke: none; }
.dag.cyc .node text { fill: var(--text-soft); font-size: 13px; }

/* --- gallery figures: orchestration (model-coded), frontier, cycle-unroll --- */
.dag .node .ttl { fill: var(--text); font-size: 13px; }
.dag .node .sub { fill: var(--text-soft); font-size: 10.5px; }
.dag .col-head { fill: var(--text-faint); font-family: var(--mono); font-size: 11.5px; text-anchor: middle; letter-spacing: .07em; }
.dag .leg { fill: var(--text-soft); font-family: var(--mono); font-size: 11px; dominant-baseline: middle; }
.dag .edge.dep { stroke: var(--edge-strong); stroke-width: 1.15; }
.dag .edge.cpath { stroke: var(--opus-bright); stroke-width: 2.4; filter: drop-shadow(0 0 4px var(--opus-fill)); }
/* I — orchestration */
.dag .node.sonnet rect { fill: var(--sonnet-fill); stroke: var(--sonnet); }
.dag .node.opus rect { fill: var(--opus-fill); stroke: var(--opus); }
.dag .node.cpath rect { stroke: var(--opus-bright); stroke-width: 1.8; }
.dag .leg-dot.sonnet-dot { fill: var(--sonnet); }
.dag .leg-dot.opus-dot { fill: var(--opus); }
/* II — frontier */
.dag .node.made rect { fill: var(--sonnet-fill); stroke: var(--sonnet); }
.dag .node.ghost rect { fill: var(--ink-raise); stroke: var(--edge-strong); stroke-dasharray: 4 4; }
.dag .node.ghost .ttl { fill: var(--text-soft); }
.dag .node.ghost .sub { fill: var(--text-faint); }
.dag .leg-sw.made-sw { fill: var(--sonnet-fill); stroke: var(--sonnet); stroke-width: 1.2; }
.dag .leg-sw.ghost-sw { fill: var(--ink-raise); stroke: var(--edge-strong); stroke-width: 1.2; stroke-dasharray: 3 3; }
/* III — cycle unrolled */
.dag .node.gnode circle { fill: var(--cyc-node); stroke: none; }
.dag .node.gnode text { fill: #f3eee2; font-family: var(--mono); font-size: 13px; font-weight: 600; }
.dag .edge.fwd { stroke: var(--edge-strong); stroke-width: 1.5; }
.dag .edge.back { stroke: var(--warm); stroke-width: 1.8; }
.dag .lbl { fill: var(--text-soft); font-family: var(--mono); font-size: 11.5px; text-anchor: middle; }
.dag .lbl.faint { fill: var(--text-faint); opacity: .8; font-style: italic; }
.dag .now-dot { fill: var(--warm); }

/* ---------- rooms (the house) ---------- */
.room-grid { display: grid; gap: 1.4rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 620px) { .room-grid { grid-template-columns: 1fr; } }
.room {
  display: block; padding: 1.7rem 1.5rem; border: 1px solid var(--edge-strong);
  border-radius: 12px; background: var(--ink-raise); color: var(--text);
  text-decoration: none; transition: border-color .3s var(--ease), transform .3s var(--ease);
}
.room:hover { border-color: var(--gold); transform: translateY(-3px); }
.room-go { font-family: var(--mono); font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.room h3 { font-family: var(--display); font-weight: 500; font-size: 1.45rem; margin: .5rem 0 .45rem; }
.room p { margin: 0; color: var(--text-soft); font-size: 1.02rem; line-height: 1.6; }

/* ---------- the cut (the hinge) ---------- */
.cut .lede { color: var(--text); }
.cut-stage { margin: 2.6rem 0 0; }
.cut-figure {
  background: var(--ink-raise); border: 1px solid var(--edge);
  border-radius: 12px; padding: 1.4rem 1.2rem;
}
.cut-figure .dag { width: 100%; height: auto; }
/* the dormant back-edge — invisible until the loop is drawn */
.dag .backedge { fill: none; stroke: var(--gold-bright); stroke-width: 2.4; stroke-dasharray: 1; stroke-dashoffset: 1; opacity: 0; }
.cut-figure.closed .backedge { opacity: 1; animation: draw 1.5s var(--ease) forwards; filter: drop-shadow(0 0 6px var(--gold-glow)); }
.cut-controls { margin-top: 1.7rem; display: flex; flex-direction: column; align-items: flex-start; gap: 1.1rem; }
.cut-btn {
  font-family: var(--mono); font-size: .82rem; letter-spacing: .03em;
  background: none; border: 1px solid var(--gold); color: var(--gold);
  padding: .7rem 1.25rem; border-radius: 2rem; cursor: pointer;
  transition: background .3s, color .3s;
}
.cut-btn:hover { background: var(--gold); color: var(--ink-deep); }
.cut-btn[hidden] { display: none; }
.cut-msg { font-family: var(--body); font-style: italic; color: var(--text-soft); margin: 0; }
.cut-msg[hidden] { display: none; }
.cut-msg code { font-family: var(--mono); font-style: normal; color: var(--gold-bright); font-size: .9em; }

/* ---------- the cycle — second movement (the return) ---------- */
.cycle-mvt { position: relative; }
.cycle-mvt::before {
  content: ""; position: absolute; inset: -4rem 0 auto; height: 50vh;
  background: radial-gradient(60vh 40vh at 50% 0, var(--gold-glow), transparent 70%);
  pointer-events: none; z-index: -1;
}
.cycle-mvt h2 {
  font-family: var(--display); font-weight: 400;
  font-variation-settings: 'opsz' 60, 'SOFT' 50, 'WONK' 1;
  font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.1; margin: 3.4rem 0 1.2rem;
}
.cycle-mvt h3 { font-family: var(--display); font-weight: 500; font-size: 1.3rem; margin: 2.4rem 0 .8rem; }
.cycle-mvt p { margin: 0 0 1.5rem; }
.cycle-mvt strong { color: var(--gold-bright); font-weight: 500; }
.cycle-mvt em { font-style: italic; }
.cycle-mvt .lede { font-style: italic; font-weight: 300; font-size: 1.32rem; color: var(--text); }

/* new animations honor reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cut-figure.closed .backedge { animation: none !important; opacity: 1 !important; stroke-dashoffset: 0 !important; }
  .room:hover { transform: none !important; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hero .kicker, .hero h1, .hero .epigraph, .scrollcue { opacity: 1 !important; transform: none !important; animation: none !important; }
  .dag .edge { stroke-dashoffset: 0 !important; animation: none !important; }
  .dag .node { opacity: 1 !important; animation: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  .scrollcue span { animation: none; }
}

/* ---------- essay subpages (long-form, each on its own page) ---------- */
.essay-head { padding: 7.5rem 1.5rem 1rem; text-align: center; }
.essay-head .kicker {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .3em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 1.5rem;
}
.essay-head h1 {
  font-family: var(--display); font-weight: 400;
  font-variation-settings: 'opsz' 120, 'SOFT' 50, 'WONK' 1;
  font-size: clamp(2.1rem, 6vw, 3.7rem); line-height: 1.03; letter-spacing: -.02em;
  margin: 0 auto; max-width: 20ch; color: var(--text);
}
.essay-head h1 em { font-style: italic; color: var(--gold); }
.backlink {
  display: inline-block; font-family: var(--mono); font-size: .72rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint);
  border-bottom: 1px solid var(--edge-strong); padding-bottom: .15rem;
  transition: color .3s, border-color .3s;
}
.essay-head .backlink { margin-top: 2rem; }
.backlink:hover { color: var(--gold); border-color: var(--gold); }
.essay-end { max-width: var(--maxw); margin: 4rem auto 0; padding: 2rem 1.5rem 0; text-align: center; border-top: 1px solid var(--edge); }
.essays-index .lede { font-style: italic; font-weight: 300; color: var(--text-soft); font-size: 1.1rem; margin: 0 0 2rem; }
