/* ─────────────────────────────────────────────────────────────────
   Beta — spatial explainer (CSS-grid layout, robust at any width)
   ───────────────────────────────────────────────────────────────── */

:root {
  --paper: #f7f2e8;
  --paper-deep: #efe7d6;
  --ink: #2a1d14;
  --ink-soft: #5b463a;
  --ink-faint: #8a7765;
  --rust: #a23e23;
  --rule: #d9cdb6;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;

  --t-edge: 700ms;
  --t-fade: 520ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 20% 10%, rgba(162,62,35,0.025), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(162,62,35,0.02), transparent 40%);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--rust); text-decoration: none; border-bottom: 1px solid currentColor; }
a:hover { color: var(--ink); }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }

/* ─── Masthead ─────────────────────────────────────────────────── */

.masthead {
  max-width: 38rem;
  margin: 0 auto;
  padding: 4rem 2rem 2rem;
  border-bottom: 1px solid var(--rule);
  text-align: center;
}
.masthead h1 {
  font-weight: 900;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
  font-style: italic;
}
.masthead .blurb {
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

/* ─── Homepage list ────────────────────────────────────────────── */

.topics { max-width: 38rem; margin: 0 auto; padding: 2rem 2rem 6rem; }
.topics .lede { font-style: italic; color: var(--ink-soft); margin: 0 0 2.5rem; font-size: 1.05rem; }
.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-list li { border-top: 1px solid var(--rule); }
.topic-list li:last-child { border-bottom: 1px solid var(--rule); }
.topic-list a {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 1rem; padding: 1.4rem 0.25rem; border: none; color: var(--ink);
  font-size: 1.4rem; font-weight: 600; letter-spacing: -0.01em;
  transition: color 180ms, padding 220ms;
}
.topic-list a:hover { color: var(--rust); padding-left: 0.9rem; }
.topic-list .arrow {
  font-family: var(--sans); font-size: 0.78rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--ink-faint); white-space: nowrap;
}
.topic-list a:hover .arrow { color: var(--rust); }

/* ─── Breadcrumb ───────────────────────────────────────────────── */

.breadcrumb {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  padding: 0.85rem 1.5rem;
  font-family: var(--sans); font-size: 0.78rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint);
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
}
.breadcrumb .home { color: var(--ink-faint); font-style: italic; text-transform: none; letter-spacing: 0.04em; }
.breadcrumb .home:hover { color: var(--rust); }
.breadcrumb .crumb { color: var(--ink-soft); cursor: pointer; }
.breadcrumb .crumb:hover { color: var(--rust); }
.breadcrumb .crumb.current { color: var(--ink); cursor: default; }
.breadcrumb .sep { color: var(--rule); font-size: 0.85rem; }

/* ─── Spatial canvas: 3-column grid ────────────────────────────── */
/*  [ incoming edge ] [ node card ] [ outgoing edges ]              */

.canvas {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: 0;
  padding: 3rem 2rem;
  min-height: calc(100vh - 60px);
  max-width: 1100px;
  margin: 0 auto;
}

/* ─── Incoming edge column ─────────────────────────────────────── */

.incoming-col {
  position: relative;
  align-self: stretch;
  min-height: 100%;
  min-width: 140px;
  padding-right: 2.5rem;
}
.incoming-col.is-back {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: inherit;
  padding-right: 2.5rem;
  transition: transform 240ms cubic-bezier(.2,.7,.2,1);
}
.incoming-col.is-back .label {
  transition: color 200ms;
}
.incoming-col.is-back .back-hint {
  position: absolute;
  top: calc(50% + 1.4rem);
  right: 2.5rem;
  transform: translateY(0);
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 200ms, transform 240ms cubic-bezier(.2,.7,.2,1);
  pointer-events: none;
}
.incoming-col.is-back:hover .label { color: var(--rust); }
.incoming-col.is-back:hover .back-hint {
  opacity: 1;
  transform: translateY(-2px);
}
.incoming-col.is-back:hover { transform: translateX(-4px); }
.incoming-col svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  overflow: visible;
  display: block;
}
.incoming-col .label {
  position: absolute;
  top: 50%;
  left: 0;
  right: 2.5rem;
  transform: translateY(-50%);
  font-family: var(--sans); font-size: 0.7rem;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--rust);
  text-align: right;
  pointer-events: none;
  line-height: 1.3;
}
.incoming-col .stroke {
  fill: none; stroke: var(--rust); stroke-width: 1.6;
  stroke-linecap: round;
}

/* ─── Node card ────────────────────────────────────────────────── */

.node {
  width: min(520px, 100%);
  height: min(540px, calc(100vh - 160px));
  background: var(--paper);
  border: 1px solid var(--ink-soft);
  padding: 1.8rem 2rem 2rem;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 2px 3px 0 var(--paper-deep), 4px 6px 0 rgba(42,29,20,0.06);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
.node::-webkit-scrollbar { width: 6px; }
.node::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 3px; }

.node .kicker {
  font-family: var(--sans); font-size: 0.7rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--rust);
  margin: 0 0 0.8rem;
  display: flex; align-items: center; gap: 0.6rem;
}
.node .kicker::before {
  content: ""; display: block; width: 1.4rem; height: 1px;
  background: var(--rust);
}

/* Markdown */
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 900; letter-spacing: -0.015em; line-height: 1.15;
  margin: 0 0 0.8rem; color: var(--ink);
}
.md h1 { font-size: 1.7rem; font-style: italic; }
.md h2 { font-size: 1.45rem; }
.md h3 { font-size: 1.18rem; }
.md h4 { font-size: 1rem; }
.md p { margin: 0 0 0.9rem; font-size: 1rem; line-height: 1.55; text-wrap: pretty; }
.md a { color: var(--rust); }
.md strong { color: var(--ink); }
.md em { color: var(--ink-soft); }
.md ul, .md ol { padding-left: 1.3rem; margin: 0 0 1rem; }
.md li { margin: 0.25rem 0; font-size: 0.96rem; line-height: 1.5; }
.md blockquote {
  margin: 1rem 0; padding: 0.1rem 0 0.1rem 1rem;
  border-left: 2px solid var(--rust); font-style: italic;
  font-size: 1.05rem; color: var(--ink-soft); line-height: 1.4;
}
.md img {
  display: block; width: 100%; height: auto; margin: 1rem 0 0.4rem;
  border: 1px solid var(--rule); filter: sepia(0.18) saturate(0.9);
}
.md code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--paper-deep); padding: 0.08em 0.32em; border-radius: 2px;
}
.md pre {
  background: var(--paper-deep); padding: 0.8rem 1rem; overflow-x: auto;
  border-left: 2px solid var(--ink-faint); font-size: 0.85rem; margin: 1rem 0;
}
.md pre code { background: none; padding: 0; }
.md hr { border: none; border-top: 1px solid var(--rule); margin: 1.4rem 0; }

/* ─── Outgoing edges column ────────────────────────────────────── */

.outgoing-col {
  position: relative;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem 0 1rem 0;
  min-height: 100%;
}
.outgoing-col {
  position: relative;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem 0 1rem 0;
  min-height: 100%;
  min-width: 0;
}
.outgoing-col .edge-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0;
  position: relative;
  cursor: pointer;
  padding: 0.4rem 0;
  width: 100%;
  text-align: left;
  transition: transform 240ms cubic-bezier(.2,.7,.2,1);
}
.outgoing-col .edge-row:hover { transform: translateX(6px); }

.outgoing-col .wire {
  flex-shrink: 0;
  width: clamp(40px, 8vw, 120px);
  height: 1px;
  background: var(--ink-soft);
  position: relative;
  transition: background 200ms;
}
.outgoing-col .edge-row:hover .wire { background: var(--rust); }

.outgoing-col .edge-label {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink);
  padding-left: 0.9rem;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  transition: color 180ms;
}
.outgoing-col .edge-row:hover .edge-label { color: var(--rust); }

.outgoing-col .edge-row .arrow {
  font-family: var(--sans);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-left: 0.6rem;
  margin-left: 0.4rem;
  flex-shrink: 0;
  white-space: nowrap;
  align-self: center;
  opacity: 0;
  transition: opacity 180ms;
}
.outgoing-col .edge-row:hover .arrow { opacity: 1; color: var(--rust); }

.leaf-cap {
  font-family: var(--sans); font-size: 0.72rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-faint);
  align-self: center;
  margin: auto;
}

/* ─── Animations ───────────────────────────────────────────────── */

.canvas .node {
  animation: nodein var(--t-fade) cubic-bezier(.2,.7,.2,1) both;
  animation-delay: 80ms;
}
.canvas .incoming-col .stroke {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: drawline var(--t-edge) cubic-bezier(.6,.05,.3,1) both;
  animation-delay: 120ms;
}
.canvas .incoming-col .label {
  animation: labelin 380ms cubic-bezier(.2,.7,.2,1) both;
  animation-delay: 180ms;
}
.canvas .outgoing-col .edge-row {
  animation: edgein 420ms cubic-bezier(.2,.7,.2,1) both;
  animation-delay: calc(220ms + var(--i, 0) * 70ms);
}

@keyframes nodein {
  from { opacity: 0; transform: translateX(48px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes drawline { to { stroke-dashoffset: 0; } }
@keyframes labelin {
  from { opacity: 0; transform: translateY(-50%) translateX(40px); }
  to   { opacity: 1; transform: translateY(-50%) translateX(0); }
}
@keyframes edgein {
  from { opacity: 0; transform: translateX(48px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Exit transition — slide everything left and fade out */
.canvas.exit-left {
  animation: canvasout 320ms cubic-bezier(.4,0,.6,1) forwards;
}
@keyframes canvasout {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(-60px); }
}

/* Back transition — slide everything right and fade out */
.canvas.exit-right {
  animation: canvasoutright 320ms cubic-bezier(.4,0,.6,1) forwards;
}
@keyframes canvasoutright {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(60px); }
}

/* When navigating back, entrance comes from the LEFT instead of right */
.canvas.enter-from-left .node {
  animation-name: nodein-fromleft;
}
.canvas.enter-from-left .incoming-col .label {
  animation-name: labelin-fromleft;
}
.canvas.enter-from-left .outgoing-col .edge-row {
  animation-name: edgein-fromleft;
}
@keyframes nodein-fromleft {
  from { opacity: 0; transform: translateX(-48px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes labelin-fromleft {
  from { opacity: 0; transform: translateY(-50%) translateX(-40px); }
  to   { opacity: 1; transform: translateY(-50%) translateX(0); }
}
@keyframes edgein-fromleft {
  from { opacity: 0; transform: translateX(-48px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Share button ─────────────────────────────────────────────── */

.share {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  font-family: var(--sans); font-size: 0.74rem;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.6rem 0.9rem;
  z-index: 40;
  transition: color 180ms, border-color 180ms;
}
.share:hover { color: var(--rust); border-color: var(--rust); }
.share.copied { color: var(--rust); border-color: var(--rust); }

/* ─── Reduced motion ───────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .canvas .node, .canvas .incoming-col .stroke,
  .canvas .incoming-col .label, .canvas .outgoing-col .edge-row {
    animation: none !important;
  }
  .canvas .incoming-col .stroke { stroke-dashoffset: 0; }
}

/* ─── Narrow viewport: stack vertically ────────────────────────── */

@media (max-width: 520px) {
  .canvas {
    grid-template-columns: 1fr;
    padding: 1.5rem 1rem 4rem;
    min-height: 0;
    gap: 1rem;
  }
  .incoming-col { min-height: 50px; }
  .incoming-col svg { display: none; }
  .incoming-col .label {
    position: static; transform: none;
    text-align: left; max-width: none;
    border-left: 2px solid var(--rust);
    padding: 0.4rem 0.8rem;
  }
  .incoming-col .label::before { content: "via "; opacity: 0.6; }
  .node { width: 100%; height: auto; max-height: none; overflow: visible; }
  .outgoing-col { min-height: 0; padding: 0; flex-direction: column; }
  .outgoing-col .edge-row {
    display: flex; width: 100%;
    border-top: 1px solid var(--rule); padding: 0.9rem 0;
  }
  .outgoing-col .wire { width: 24px; }
  .outgoing-col .edge-label { font-size: 1rem; }
  .outgoing-col .edge-row .arrow { opacity: 1; }
}
