/* ============================================================
   GHOSTWRITER IN THE MACHINE — jasonnitti.com/ghostwriterinthemachine
   Hand-rolled. No frameworks.
   Aesthetic: elegant terminal — Spectral for the prose,
   IBM Plex Mono for the machine's marginalia, phosphor green accent.
   ============================================================ */

:root {
  --bg: #0a0d0f;
  --bg-raise: #0e1316;
  --line: #1d2529;
  --ink: #cdd5d0;
  --ink-bright: #eef3ef;
  --ink-dim: #71807a;
  --phos: #34f5b2;
  --phos-dim: rgba(52, 245, 178, .55);
  --phos-faint: rgba(52, 245, 178, .14);
  --glitch-m: rgba(255, 66, 214, .45);
  --glitch-c: rgba(64, 220, 255, .45);
  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --col: 680px;
  --noise: 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.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
::selection { background: var(--phos); color: #06110c; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--phos); color: #06110c; font-family: var(--mono);
  font-size: 12px; padding: 8px 14px; text-decoration: none;
}
.skip:focus { left: 12px; top: 12px; }

/* ---------- progress bar ---------- */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  z-index: 120; background: transparent; pointer-events: none;
}
.progress-fill {
  height: 100%; width: 100%;
  background: var(--phos);
  box-shadow: 0 0 12px var(--phos-dim);
  transform: scaleX(0); transform-origin: 0 50%;
}

/* ---------- top bar ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
  color: var(--ink-dim);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar a { text-decoration: none; color: var(--ink-dim); transition: color .2s ease, text-shadow .2s ease; }
.bar a:hover { color: var(--phos); text-shadow: 0 0 10px var(--phos-faint); }
.bar-home { font-weight: 600; color: var(--ink-bright); }
.bar a.bar-series { color: var(--phos-dim); cursor: pointer; }
.bar a.bar-series:hover { color: var(--phos); text-shadow: 0 0 10px var(--phos-dim); }
.bar-index::before { content: "//: "; color: var(--ink-dim); }

/* ---------- chapter rail ---------- */
.rail {
  position: fixed; right: 26px; top: 50%; transform: translateY(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 18px;
}
.rail a {
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--ink-dim); text-decoration: none;
  display: flex; align-items: center; gap: 8px;
  transition: color .25s ease;
}
.rail a::before {
  content: ""; display: block; width: 14px; height: 1px;
  background: var(--line); transition: background .25s ease, width .25s ease;
}
.rail a:hover { color: var(--ink-bright); }
.rail a.active { color: var(--phos); text-shadow: 0 0 10px var(--phos-faint); }
.rail a.active::before { background: var(--phos); width: 22px; box-shadow: 0 0 8px var(--phos-dim); }

/* ---------- hero ---------- */
.hero {
  position: relative;
  min-height: 100svh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; overflow: hidden;
  padding: 120px 22px 90px;
  border-bottom: 1px solid var(--line);
}
.hero::before {
  /* dead-channel static + vignette */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--noise);
  opacity: .05;
}
.hero::after {
  /* scanlines */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent 2px,
    rgba(0, 0, 0, .22) 3px, transparent 4px
  );
  opacity: .5;
}
.hero-sweep {
  position: absolute; left: 0; right: 0; top: -2px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--phos-dim), transparent);
  opacity: .18; pointer-events: none;
  animation: sweep 9s linear infinite;
}
@keyframes sweep { to { transform: translateY(100vh); } }

.hero-inner { position: relative; z-index: 2; max-width: 900px; }
.hero-eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: .3em;
  color: var(--phos); margin: 0 0 34px;
  text-shadow: 0 0 14px var(--phos-faint);
}
.hero-title {
  margin: 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(34px, 6.6vw, 82px);
  line-height: 1.14;
  letter-spacing: .045em;
  color: var(--ink-bright);
  text-shadow: 0 0 34px rgba(52, 245, 178, .12);
}
.cursor {
  color: var(--phos);
  animation: blink 1.05s steps(1) infinite;
  text-shadow: 0 0 12px var(--phos-dim);
}
@keyframes blink { 50% { opacity: 0; } }

.hero-dek {
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: clamp(18px, 2.4vw, 23px); line-height: 1.6;
  color: var(--ink); max-width: 560px; margin: 36px auto 0;
}
.hero-byline {
  font-family: var(--mono); font-size: 11px; letter-spacing: .22em;
  color: var(--ink-dim); margin: 26px 0 0;
}

.hero-epigraph {
  position: relative; z-index: 2;
  margin: 72px 0 0; padding: 0 22px;
  max-width: 460px;
}
.hero-epigraph p {
  margin: 0; font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 15.5px; line-height: 1.65; color: var(--ink-dim);
}
.hero-epigraph cite {
  display: block; margin-top: 12px;
  font-family: var(--mono); font-style: normal; font-size: 10px;
  letter-spacing: .24em; color: var(--phos-dim);
}

.hero-scroll {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  z-index: 2; font-family: var(--mono); font-size: 12px;
  color: var(--ink-dim); text-decoration: none;
  animation: drift 2.6s ease-in-out infinite;
}
.hero-scroll:hover { color: var(--phos); }
@keyframes drift { 50% { transform: translate(-50%, 6px); } }

/* ---------- index / toc ---------- */
.toc {
  max-width: 760px; margin: 0 auto; padding: 110px 22px 96px;
}
.toc-title {
  font-family: var(--mono); font-weight: 500; font-size: 12px;
  letter-spacing: .3em; color: var(--phos); margin: 0 0 30px;
}
.toc-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.toc-list li { border-bottom: 1px solid var(--line); }
.toc-list a {
  display: flex; align-items: baseline; gap: 26px;
  padding: 26px 10px; text-decoration: none;
  transition: background .25s ease;
}
.toc-list a:hover { background: var(--bg-raise); }
.toc-num {
  font-family: var(--mono); font-size: 13px; color: var(--phos-dim);
  min-width: 30px; transition: color .2s ease;
}
.toc-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.toc-name {
  font-family: var(--serif); font-weight: 500; font-size: 23px;
  line-height: 1.3; color: var(--ink-bright);
  transition: color .2s ease, text-shadow .2s ease;
}
.toc-dek {
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 15.5px; color: var(--ink-dim); line-height: 1.5;
}
.toc-time {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  color: var(--ink-dim); white-space: nowrap;
}
.toc-list a:hover .toc-num { color: var(--phos); }
.toc-list a:hover .toc-name {
  color: var(--phos);
  text-shadow: 1px 0 var(--glitch-m), -1px 0 var(--glitch-c);
}

/* ---------- chapters ---------- */
.chapter { max-width: var(--col); margin: 0 auto; padding: 96px 22px 30px; }
.ch-head { margin-bottom: 54px; }
.ch-eyebrow {
  display: flex; gap: 12px; align-items: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: .2em;
  color: var(--ink-dim); margin: 0 0 22px;
}
.ch-num { color: var(--phos); text-shadow: 0 0 12px var(--phos-faint); }
.ch-sep { color: var(--line); }
.ch-title {
  margin: 0;
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(31px, 5vw, 46px); line-height: 1.16;
  letter-spacing: -.01em; color: var(--ink-bright);
}
.ch-dek {
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 20px; line-height: 1.55; color: var(--ink-dim);
  margin: 18px 0 0;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--line);
}

.ch-body p { margin: 0 0 1.45em; }
.ch-body em { font-style: italic; }

.ch-body h3 {
  font-family: var(--mono); font-weight: 500; font-size: 12.5px;
  letter-spacing: .22em; text-transform: uppercase;
  color: var(--ink-bright);
  margin: 3.2em 0 1.6em;
}
.ch-body h3 .slash { color: var(--phos); margin-right: 10px; }

.ch-body blockquote {
  margin: 2.2em 0; padding: 4px 0 4px 24px;
  border-left: 2px solid var(--phos);
}
.ch-body blockquote p {
  margin: 0; font-style: italic; font-weight: 300;
  font-size: 20px; line-height: 1.65; color: var(--ink-bright);
}

.pull {
  font-size: 23.5px; line-height: 1.5; font-weight: 500;
  color: var(--ink-bright);
  margin: 2em 0 !important; padding-left: 24px;
  border-left: 2px solid var(--phos);
  box-shadow: inset 0 0 0 0 transparent; /* keeps border crisp on subpixel */
}

.src {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  color: var(--ink-dim); margin-top: -0.6em !important;
}

.term {
  position: relative; margin: 2.1em 0;
  background: var(--bg-raise);
  border: 1px solid var(--line); border-radius: 2px;
  padding: 20px 22px 16px;
  font-family: var(--mono); font-size: 14px; line-height: 1.8;
  color: var(--phos);
  overflow-x: auto;
}
.term::before {
  content: attr(data-label);
  display: block; margin-bottom: 8px;
  font-size: 9.5px; letter-spacing: .26em; color: var(--ink-dim);
}
.term p { margin: 0; white-space: nowrap; }
.term-dim { color: var(--ink-dim); }

/* ---------- dividers ---------- */
.divider {
  display: flex; align-items: center; gap: 20px;
  max-width: var(--col); margin: 66px auto; padding: 0 22px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.divider span { color: var(--phos-dim); font-family: var(--mono); font-size: 12px; }

/* ---------- end / footer ---------- */
.end {
  position: relative;
  margin-top: 90px; padding: 96px 22px 60px;
  border-top: 1px solid var(--line);
  text-align: center; overflow: hidden;
}
.end::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--noise); opacity: .04;
}
.end-mark {
  font-family: var(--mono); font-size: 13px; letter-spacing: .3em;
  color: var(--phos); margin: 0 0 30px;
  text-shadow: 0 0 14px var(--phos-faint);
}
.end-colophon {
  max-width: 470px; margin: 0 auto 34px;
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 15px; line-height: 1.7; color: var(--ink-dim);
}
.end-links {
  display: flex; gap: 14px; justify-content: center; align-items: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: .16em;
  color: var(--ink-dim);
}
.end-links a { color: var(--ink-dim); text-decoration: none; transition: color .2s ease; }
.end-links a:hover { color: var(--phos); }
.end-copy {
  font-family: var(--mono); font-size: 10px; letter-spacing: .2em;
  color: var(--ink-dim); opacity: .6; margin: 40px 0 0;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .rail { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 17.5px; }
  .bar-series { display: none; }
  .toc-list a { gap: 16px; padding: 22px 4px; }
  .toc-name { font-size: 20px; }
  .toc-time { display: none; }
  .chapter { padding-top: 76px; }
  .ch-dek { font-size: 18px; }
  .pull { font-size: 20.5px; }
  .hero { padding-top: 100px; }
  .hero-epigraph { margin-top: 54px; }
}

/* ---------- motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cursor, .hero-scroll, .hero-sweep { animation: none; }
  .hero-sweep { display: none; }
}
