/* ============================================
   Read.html — Long-form reading experience
   Beautiful, traditional, focused on content
   ============================================ */

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

:root {
  --bg: #0f0f14;
  --surface: #161620;
  --text: #d8d8e0;
  --text-muted: #8a8a9a;
  --accent: #C9A86C;
  --accent-dim: #8a7a5a;
  --font-serif: 'Source Serif 4', 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --content-width: 680px;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
  line-height: 1.75;
  min-height: 100vh;
}

/* ============================================
   Header
   ============================================ */
.read-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 1rem 2rem;
  background: linear-gradient(to bottom, var(--bg) 60%, transparent);
}

.back-link {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--accent);
}

/* ============================================
   Article
   ============================================ */
.read-main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 6rem;
}

.article-header {
  text-align: center;
  margin-bottom: 4rem;
  padding-top: 3rem;
}

.article-header h1 {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 2rem + 2.5vw, 4rem);
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.1;
}

.subtitle {
  font-family: var(--font-display);
  font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.byline {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--accent-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.article-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.meta-sep {
  opacity: 0.4;
}

/* ============================================
   Article Body
   ============================================ */
.article-body {
  max-width: 100%;
}

.article-body p {
  margin-bottom: 1.5em;
  max-width: 72ch;
}

.article-body .lede {
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.3rem);
  color: var(--accent);
  line-height: 1.7;
  margin-bottom: 2.5em;
}

.article-body h2 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  font-weight: 400;
  margin-top: 3em;
  margin-bottom: 1em;
  color: var(--text);
  letter-spacing: 0.02em;
}

.article-body strong {
  color: var(--text);
  font-weight: 600;
}

.article-body em {
  font-style: italic;
}

.article-body blockquote {
  margin: 2em 0;
  padding: 1em 1.5em;
  border-left: 2px solid var(--accent-dim);
  color: var(--accent);
  font-style: italic;
}

.article-body blockquote p {
  margin-bottom: 0;
}

.article-body sup {
  font-size: 0.7em;
  line-height: 0;
}

.article-separator {
  text-align: center;
  margin: 3em 0;
  font-size: 1.5rem;
  color: var(--accent-dim);
  letter-spacing: 1em;
}

.article-body .closing {
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================
   Footer
   ============================================ */
.read-footer {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.footer-note {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================================
   Mobile
   ============================================ */
@media (max-width: 768px) {
  .read-main {
    padding: 1.5rem 1rem 4rem;
  }
  
  .article-header {
    padding-top: 2rem;
    margin-bottom: 3rem;
  }
  
  .read-footer {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
}

/* Selection */
::selection {
  background: rgba(201, 168, 108, 0.25);
  color: var(--text);
}

/* Focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   Full-viewport field + readout strip
   ============================================ */
#field-root {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(12,14,22,0.2) 0%, rgba(8,8,12,0) 70%);
}
#field-root canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Prose sits above the field. Backdrop-blur gives it legibility without a hard plate. */
body { background: #07080b; }
.read-header, .read-main {
  position: relative;
  z-index: 2;
}
.read-article .article-body,
.read-article .article-header {
  background: rgba(10, 11, 16, 0.60);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 2rem 2.2rem;
  border-radius: 4px;
}
.read-article .article-header { margin-bottom: 1.5rem; }

#field-readout {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 3;
  padding: 0.5rem 1rem;
  background: rgba(6, 7, 10, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,0.06);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  color: rgba(220, 220, 230, 0.75);
  letter-spacing: 0.02em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  justify-content: center;
  pointer-events: none;
}
#field-readout .ro-group { white-space: nowrap; }
#field-readout .ro-lbl { color: rgba(160,170,190,0.55); margin-right: 0.35em; text-transform: uppercase; font-size: 0.66rem; }
#field-readout .ro-sep { color: rgba(255,255,255,0.15); }
#field-readout #ro-theta,
#field-readout #ro-kappa,
#field-readout #ro-alpha,
#field-readout #ro-coup { color: #6aa9d8; margin-left: 0.25em; }
#field-readout #ro-scroll,
#field-readout #ro-idle { color: #c9a86c; margin-left: 0.25em; }
#field-readout #ro-m,
#field-readout #ro-fetch { color: rgba(220,220,230,0.75); margin-left: 0.25em; }

@media (max-width: 700px) {
  #field-readout { font-size: 0.62rem; padding: 0.4rem 0.6rem; }
}

/* ============================================
   Manifold layer — the essay on the terrain
   ============================================ */
#manifold-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;               /* above field-root (z=0), below prose (z=2) */
  pointer-events: none;
  display: block;
  mix-blend-mode: screen;
  opacity: 0.85;
}

/* Tinted words — repo-colored glyphs inside the essay */
.mw {
  color: var(--mw-color, inherit);
  text-shadow: 0 0 0.25em rgba(var(--mw-rgb, 255 255 255) / 0.25);
  transition: color 0.35s ease, text-shadow 0.35s ease;
  cursor: help;
}
.mw[data-repo="Vybn"]       { --mw-color: #6fb3e8; --mw-rgb: 58 138 216; }
.mw[data-repo="Vybn-Law"]   { --mw-color: #9fdda0; --mw-rgb: 122 201 122; }
.mw[data-repo="vybn-phase"] { --mw-color: #e18bc2; --mw-rgb: 201 108 168; }
.mw[data-repo="Origins"]    { --mw-color: #e8be87; --mw-rgb: 216 168 102; }
.mw[data-repo="other"]      { --mw-color: #b5b5c2; --mw-rgb: 136 136 153; }
.mw:hover {
  text-shadow: 0 0 0.6em rgba(var(--mw-rgb) / 0.85);
}

/* Active paragraph gets a subtle luminous accent */
.article-body p {
  transition: border-color 0.6s ease, background 0.6s ease;
  border-left: 2px solid transparent;
  padding-left: 0.9rem;
  margin-left: -0.9rem;
}
.article-body p.active-para {
  border-left-color: rgba(232, 220, 195, 0.45);
}
.article-body p.active-para .mw {
  text-shadow: 0 0 0.5em rgba(var(--mw-rgb) / 0.6);
}

/* When a tinted word is hovered, every instance of it in the essay lights up
   in sympathy — the same token across paragraphs is the same neuron firing. */
.mw.active-word {
  color: color-mix(in srgb, var(--mw-color) 100%, white 20%);
  text-shadow:
    0 0 0.35em rgba(var(--mw-rgb) / 0.9),
    0 0 1.1em  rgba(var(--mw-rgb) / 0.45);
}

/* Whisper box — lives just above the readout strip */
#rm-whisper {
  position: fixed;
  left: 0; right: 0;
  bottom: 2.2rem;
  z-index: 4;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 1rem;
  background: linear-gradient(to top, rgba(6,7,10,0.72) 40%, rgba(6,7,10,0));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}
#rm-whisper > * { pointer-events: auto; }
#rm-whisper-input {
  flex: 0 1 540px;
  max-width: 540px;
  padding: 0.55rem 0.9rem;
  background: rgba(14,16,22,0.75);
  border: 1px solid rgba(216, 168, 102, 0.22);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-style: italic;
  outline: none;
  transition: border-color 0.25s ease, background 0.25s ease;
}
#rm-whisper-input::placeholder { color: rgba(180,170,150,0.55); font-style: italic; }
#rm-whisper-input:focus {
  border-color: rgba(216,168,102,0.75);
  background: rgba(20,22,28,0.9);
}
#rm-whisper-send {
  padding: 0.55rem 1.1rem;
  background: rgba(201, 168, 108, 0.18);
  border: 1px solid rgba(216, 168, 102, 0.45);
  color: var(--accent);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
#rm-whisper-send:hover:not(:disabled) {
  background: rgba(216, 168, 102, 0.32);
  color: #f8e7c8;
}
#rm-whisper-send:disabled { opacity: 0.55; cursor: progress; }

/* Manifold error / status line (anti-hallucination: failures visible) */
#rm-err {
  position: fixed;
  bottom: 4.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.65rem;
  color: rgba(200,200,210,0.45);
  letter-spacing: 0.04em;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

/* Legend for the tinted-word color scheme — lives in the header */
.mw-legend {
  margin-top: 1rem;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.7rem;
  color: rgba(180,180,195,0.55);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  justify-content: center;
  letter-spacing: 0.04em;
}
.mw-legend .lg-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.mw-legend .lg-dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  box-shadow: 0 0 0.45em currentColor;
}

@media (max-width: 700px) {
  #rm-whisper { bottom: 2.4rem; padding: 0.3rem 0.5rem; }
  #rm-whisper-input { font-size: 0.85rem; padding: 0.45rem 0.7rem; }
  #rm-whisper-send  { font-size: 0.7rem; padding: 0.45rem 0.8rem; }
  #rm-err { bottom: 5.1rem; font-size: 0.58rem; }
}

