/* style.css — The Turning of the Soul
   Design tokens + component styles */

/* ============ TYPE SCALE ============ */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 5rem);
  --text-hero: clamp(2.75rem, 0.5rem + 6.5vw, 7rem);

  /* ============ SPACING (4px system) ============ */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  --radius-sm: 0.25rem;
  --radius-md: 0.4rem;
  --radius-lg: 0.6rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  --content-narrow: 640px;
  --content-default: 780px;
  --content-wide: 1180px;
  --content-full: 100%;

  --font-display: 'Boska', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
}

/* ============ COLOR — LIGHT (default) ============ */
:root,
[data-theme='light'] {
  --color-bg: #f6f1e7;
  --color-surface: #fbf8f1;
  --color-surface-2: #fefdfa;
  --color-surface-offset: #efe6d5;
  --color-surface-offset-2: #e6d9c0;
  --color-surface-dynamic: #dccdab;
  --color-divider: #ddd0b3;
  --color-border: #cfbd97;

  --color-text: #2a2117;
  --color-text-muted: #6b5d48;
  --color-text-faint: #a4926e;
  --color-text-inverse: #f6f1e7;

  --color-primary: #93641c;
  --color-primary-hover: #744e15;
  --color-primary-active: #573b10;
  --color-primary-highlight: #e9dbb8;

  --color-error: #8a3230;
  --color-error-highlight: #e6d2cf;

  /* thread colors */
  --thread-spectrum-warm: #a9791e; /* contemplative pole */
  --thread-spectrum-cool: #3e6e8e; /* utilitarian pole */
  --thread-restoration: #a8586e;
  --thread-dominion: #a6501f;

  --shadow-sm: 0 1px 2px oklch(0.25 0.03 60 / 0.08);
  --shadow-md: 0 4px 14px oklch(0.25 0.03 60 / 0.10);
  --shadow-lg: 0 16px 40px oklch(0.25 0.03 60 / 0.16);
}

[data-theme='dark'] {
  --color-bg: #15120d;
  --color-surface: #1a1610;
  --color-surface-2: #1f1a13;
  --color-surface-offset: #211c14;
  --color-surface-offset-2: #292219;
  --color-surface-dynamic: #362d1f;
  --color-divider: #2c2519;
  --color-border: #423624;

  --color-text: #e9dfc7;
  --color-text-muted: #a89876;
  --color-text-faint: #6e6047;
  --color-text-inverse: #1f1a13;

  --color-primary: #d3a64a;
  --color-primary-hover: #e0bb6a;
  --color-primary-active: #edcd8c;
  --color-primary-highlight: #392c17;

  --color-error: #d17a72;
  --color-error-highlight: #3a2620;

  --thread-spectrum-warm: #d3a64a;
  --thread-spectrum-cool: #6fa8c9;
  --thread-restoration: #d08ba0;
  --thread-dominion: #d6812f;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.35);
  --shadow-md: 0 4px 14px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 20px 44px oklch(0 0 0 / 0.5);
}

/* ============ GLOBAL ELEMENTS ============ */
body {
  background-color: var(--color-bg);
  background-image:
    radial-gradient(oklch(from var(--color-primary) l c h / 0.05) 0%, transparent 60%);
  background-repeat: no-repeat;
  background-position: top center;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--color-text);
}

a {
  color: var(--color-primary);
  text-decoration-color: oklch(from var(--color-primary) l c h / 0.4);
  text-underline-offset: 0.15em;
}
a:hover {
  color: var(--color-primary-hover);
  text-decoration-color: currentColor;
}

.container {
  max-width: var(--content-default);
  margin-inline: auto;
  padding-inline: var(--space-5);
}
.container--wide {
  max-width: var(--content-wide);
}

p, li {
  max-width: 68ch;
}

.eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* skip link */
.skip-link {
  position: absolute;
  left: -999px;
  top: var(--space-2);
  z-index: 200;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
}
.skip-link:focus {
  left: var(--space-2);
}

/* ============ HEADER ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: oklch(from var(--color-bg) l c h / 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid oklch(from var(--color-text) l c h / 0.08);
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out);
}
.site-header--hidden {
  transform: translateY(-100%);
}
.site-header--scrolled {
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
  text-decoration: none;
}
.brand:hover { color: var(--color-text); }
.brand-mark {
  width: 30px;
  height: 30px;
  color: var(--color-primary);
  flex-shrink: 0;
}
.brand-word {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}
.act-nav {
  display: none;
  gap: var(--space-4);
  list-style: none;
}
.act-nav a {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
}
.act-nav a:hover { color: var(--color-primary); }
@media (min-width: 900px) {
  .act-nav { display: flex; }
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
}
.theme-toggle:hover {
  color: var(--color-primary);
  background: var(--color-surface-offset);
}
.theme-toggle svg { width: 19px; height: 19px; }

/* scroll progress bar */
.scroll-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2.5px;
  width: 100%;
  z-index: 70;
  background: linear-gradient(in oklab to right, var(--thread-spectrum-warm), var(--thread-spectrum-cool));
  transform-origin: left;
  transform: scaleX(0);
}

/* ============ HERO ============ */
.hero {
  position: relative;
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-16) var(--space-5) var(--space-24);
  overflow: hidden;
}
.hero-inner {
  max-width: var(--content-wide);
  margin-inline: auto;
  width: 100%;
  position: relative;
  z-index: 2;
}
.hero .eyebrow { margin-bottom: var(--space-4); }
.hero h1 {
  font-size: var(--text-hero);
  line-height: 1.02;
  max-width: 15ch;
  color: var(--color-text);
}
.hero h1 em {
  font-style: italic;
  color: var(--color-primary);
}
.hero-sub {
  margin-top: var(--space-6);
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  max-width: 46ch;
  font-family: var(--font-body);
}

.hero-legend {
  margin-top: var(--space-12);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}
.legend-swatch {
  width: 22px;
  height: 3px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.legend-swatch--spectrum { background: linear-gradient(in oklab to right, var(--thread-spectrum-warm), var(--thread-spectrum-cool)); }
.legend-swatch--restoration { background: var(--thread-restoration); }
.legend-swatch--dominion { background: var(--thread-dominion); }

.scroll-cue {
  position: absolute;
  bottom: var(--space-10);
  left: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.scroll-cue svg {
  width: 14px; height: 14px;
  animation: cue-bob 2.2s ease-in-out infinite;
}
@keyframes cue-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

.hero-svg {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0.55;
}
[data-theme='dark'] .hero-svg { opacity: 0.4; }

/* ============ PAGE LAYOUT WITH SPINE RAIL ============ */
.scroll-frame {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
}
@media (min-width: 1180px) {
  .scroll-frame {
    grid-template-columns: 64px minmax(0, 1fr);
    column-gap: var(--space-6);
    max-width: calc(var(--content-default) + 64px + var(--space-6));
    margin-inline: auto;
    padding-inline: var(--space-5);
  }
}

.spine-rail {
  display: none;
  position: relative;
}
@media (min-width: 1180px) {
  .spine-rail { display: block; }
}
.spine-rail svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 64px;
  overflow: visible;
}

.spine-rail-mobile {
  display: block;
  position: sticky;
  top: 57px;
  z-index: 40;
  height: 34px;
  margin-bottom: var(--space-2);
  background: oklch(from var(--color-bg) l c h / 0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid oklch(from var(--color-text) l c h / 0.07);
}
@media (min-width: 1180px) {
  .spine-rail-mobile { display: none; }
}
.spine-rail-mobile svg { width: 100%; height: 34px; display: block; }

.content-col {
  min-width: 0;
}

/* ============ ACT SECTIONS ============ */
.act {
  padding-block: clamp(var(--space-16), 9vw, var(--space-24));
  border-top: 1px solid var(--color-divider);
}
.act:first-of-type { border-top: none; }

.act-head {
  margin-bottom: var(--space-10);
}
.act-number {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  color: var(--color-primary);
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}
.act-head h2 {
  font-size: var(--text-2xl);
  max-width: 20ch;
}
.act-dek {
  margin-top: var(--space-4);
  font-size: var(--text-base);
  color: var(--color-text-muted);
  max-width: 62ch;
}
.act-companion-note {
  margin-top: var(--space-5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.companion-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  background: var(--color-surface);
}
.companion-tag .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--restoration { background: var(--thread-restoration); }
.dot--dominion { background: var(--thread-dominion); }

/* ============ PROLOGUE CARD ============ */
.prologue {
  padding-block: clamp(var(--space-10), 6vw, var(--space-16));
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}
.prologue-inner {
  display: grid;
  gap: var(--space-4);
  border-left: none;
}
.prologue .eyebrow { color: var(--thread-dominion); }
.prologue h3 {
  font-size: var(--text-xl);
  max-width: 30ch;
}
.prologue p { color: var(--color-text-muted); }
.prologue-quote {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lg);
  color: var(--color-text);
  margin-block: var(--space-2);
}

/* ============ ENTRY CARDS ============ */
.entries {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-10), 6vw, var(--space-16));
}

.entry {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  padding-block: var(--space-2);
}
@media (min-width: 720px) {
  .entry {
    grid-template-columns: 200px minmax(0,1fr);
    gap: var(--space-8);
  }
}

.entry-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.entry-index {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-text-faint);
  line-height: 1;
}
.entry-dates {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.03em;
}

.score-dial {
  margin-top: var(--space-2);
}
.score-track {
  position: relative;
  height: 4px;
  border-radius: var(--radius-full);
  background: linear-gradient(in oklab to right, var(--thread-spectrum-warm), var(--thread-spectrum-cool));
}
.score-marker {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-surface-2);
  border: 2px solid var(--color-text);
  transform: translate(-50%, -50%);
}
.score-labels {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-1);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.entry-body h3 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-1);
}
.entry-role {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: var(--space-4);
}

.entry-quote {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lg);
  line-height: 1.35;
  color: var(--color-text);
  border-left: none;
  padding: 0;
  margin-block: var(--space-4);
  max-width: 58ch;
  position: relative;
}
.entry-quote {
  border-left: 2px solid var(--color-primary);
  padding-left: var(--space-4);
}

.entry-purpose {
  color: var(--color-text-muted);
  max-width: 65ch;
}
.entry-purpose a { font-weight: 500; }

.entry-links {
  margin-top: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.entry-links span.label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
}

.entry-forward {
  margin-top: var(--space-5);
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-4);
}
.entry-forward svg {
  width: 15px; height: 15px;
  margin-top: 0.2em;
  color: var(--color-primary);
  flex-shrink: 0;
}

.entry-sidenote {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 60ch;
}
.entry-sidenote strong { color: var(--color-text); }

.companion-flag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
}
.companion-flag .dot { width: 8px; height: 8px; border-radius: 50%; }
.companion-flag--restoration { color: var(--thread-restoration); }
.companion-flag--dominion { color: var(--thread-dominion); }
.companion-flag--restoration .dot { background: var(--thread-restoration); }
.companion-flag--dominion .dot { background: var(--thread-dominion); }

/* ============ BACON — THE HINGE ============ */
.hinge-entry {
  position: relative;
  border-radius: var(--radius-xl);
  padding: clamp(var(--space-8), 5vw, var(--space-12));
  background:
    radial-gradient(circle at 18% 20%, oklch(from var(--color-primary) l c h / 0.14), transparent 55%),
    var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  margin-block: var(--space-4);
}
.hinge-entry .entry { grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .hinge-entry .entry { grid-template-columns: 220px minmax(0,1fr); }
}
.hinge-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-primary);
  font-weight: 700;
  margin-bottom: var(--space-4);
}
.hinge-entry .entry-quote {
  font-size: var(--text-xl);
}
.hinge-converge {
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-divider);
  display: grid;
  gap: var(--space-6);
}
@media (min-width: 720px) {
  .hinge-converge { grid-template-columns: 170px 1fr; align-items: center; }
}
.hinge-converge svg { width: 100%; max-width: 160px; }
.hinge-converge p { color: var(--color-text-muted); font-size: var(--text-sm); }

/* ============ FORK SECTION ============ */
.fork-intro { margin-bottom: var(--space-8); }
.fork-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-10);
}
.fork-btn {
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 600;
}
.fork-btn:hover { border-color: var(--color-primary); color: var(--color-text); }
.fork-btn[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.fork-grid {
  display: grid;
  gap: var(--space-10);
}
@media (min-width: 900px) {
  .fork-grid { grid-template-columns: 1fr 1fr; gap: var(--space-8); }
}
.fork-strand {
  transition: opacity 0.35s var(--ease-out);
}
.fork-strand[data-dimmed="true"] { opacity: 0.35; }
.strand-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 2px solid var(--color-divider);
}
.strand-head .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.strand-head h3 {
  font-size: var(--text-lg);
  font-family: var(--font-body);
  font-weight: 700;
}
.strand-a .strand-head .dot,
.strand-a .strand-head { color: var(--thread-restoration); }
.strand-a .strand-head .dot { background: var(--thread-restoration); }
.strand-b .strand-head .dot { background: var(--thread-dominion); }
.strand-b .strand-head { color: var(--thread-dominion); }
.fork-strand .entries { gap: var(--space-10); }
.fork-strand .entry { grid-template-columns: 1fr; }
.fork-strand .entry-meta { flex-direction: row; align-items: baseline; gap: var(--space-3); }

/* ============ CLOSING CHAPTER ============ */
.closing {
  padding-block: clamp(var(--space-16), 10vw, var(--space-32));
  background: var(--color-surface-offset);
  border-top: 1px solid var(--color-divider);
}
.closing h2 {
  font-size: var(--text-2xl);
  max-width: 22ch;
}
.closing-lede {
  margin-top: var(--space-6);
  font-size: var(--text-lg);
  color: var(--color-text);
  max-width: 56ch;
  font-family: var(--font-body);
}
.closing p.body-text {
  margin-top: var(--space-5);
  color: var(--color-text-muted);
  max-width: 62ch;
}
.closing-examples {
  margin-top: var(--space-10);
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.closing-example {
  padding: var(--space-5);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.closing-example .eyebrow { color: var(--color-primary); margin-bottom: var(--space-2); }
.closing-example p { font-size: var(--text-sm); color: var(--color-text-muted); }

/* ============ NOTES ON THE RECORD ============ */
.notes {
  padding-block: clamp(var(--space-10), 6vw, var(--space-16));
  border-top: 1px solid var(--color-divider);
}
.notes h2 { font-size: var(--text-lg); }
.notes ul { margin-top: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); list-style: none; padding-left: 0; }
.notes li {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding-left: var(--space-5);
  position: relative;
}
.notes li::before {
  content: '';
  position: absolute;
  left: 0; top: 0.55em;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-text-faint);
}

/* ============ FOOTER ============ */
.site-footer {
  padding: var(--space-10) var(--space-5) var(--space-16);
  border-top: 1px solid var(--color-divider);
}
.footer-inner {
  max-width: var(--content-default);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.footer-inner .brand { margin-bottom: var(--space-2); }
.footer-note {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  max-width: 62ch;
}

/* ============ MISC UTILS ============ */
.text-balance { text-wrap: balance; }

@media (min-width: 720px) {
  .act-head h2 { font-size: var(--text-2xl); }
}
