/**
 * SciprogFi Base Styles
 * Foundation layer — resets, typography, layout primitives.
 * Consumes --sf-* tokens from tokens.css.
 * Era-specific CSS overrides these via cascade.
 */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  /* Default font — overridden by era CSS */
  font-family: var(--sf-font-serif);
  color: var(--sf-text);
  background: var(--sf-bg);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

/* --- Layout --- */
.content-area {
  max-width: 740px;
  margin: 0 auto;
  padding: 2rem var(--sf-space-lg) 4rem;
}

/* Full-bleed: articles with background colors extend to viewport edges
   while keeping their content at max-width. This prevents zebra-stripe
   gaps between the article background and the body background. */
.media-artifact,
.node {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  padding-left: calc(50vw - 370px + var(--sf-space-lg));
  padding-right: calc(50vw - 370px + var(--sf-space-lg));
}

/* On narrow screens, just use normal padding */
@media (max-width: 800px) {
  .media-artifact,
  .node {
    width: auto;
    left: auto;
    right: auto;
    margin-left: 0;
    margin-right: 0;
    padding-left: var(--sf-space-lg);
    padding-right: var(--sf-space-lg);
  }
}

/* --- Typography: Prose --- */
.prose h1 { font-size: 2rem; line-height: 1.2; margin-bottom: var(--sf-space-md); }
.prose h2 { font-size: 1.5rem; line-height: 1.3; margin-top: 2rem; margin-bottom: 0.75rem; }
.prose h3 { font-size: 1.25rem; line-height: 1.4; margin-top: var(--sf-space-lg); margin-bottom: var(--sf-space-sm); }
.prose p { margin-bottom: 1.25rem; }
.prose ul, .prose ol { margin-bottom: 1.25rem; padding-left: var(--sf-space-lg); }
.prose li { margin-bottom: 0.35rem; }
.prose blockquote {
  border-left: 3px solid currentColor;
  padding-left: 1.25rem;
  margin: var(--sf-space-lg) 0;
  font-style: italic;
  opacity: 0.85;
}
.prose hr {
  border: none;
  border-top: 1px solid currentColor;
  opacity: 0.2;
  margin: 2rem 0;
}
.prose code {
  font-family: var(--sf-font-mono);
  font-size: 0.9em;
  padding: 0.15em 0.35em;
  border-radius: 3px;
  background: rgba(0,0,0,0.06);
}
.prose pre {
  overflow-x: auto;
  padding: var(--sf-space-md);
  margin: var(--sf-space-lg) 0;
  border-radius: 4px;
  background: rgba(0,0,0,0.04);
}
.prose pre code {
  padding: 0;
  background: none;
}

/* --- Node Links (Grammatron-style) --- */
.node-link {
  color: currentColor;
  text-decoration: none;
  border-bottom: 2px solid currentColor;
  padding-bottom: 1px;
  transition: background var(--sf-duration-fast) var(--sf-ease), color var(--sf-duration-fast) var(--sf-ease);
}
.node-link:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* --- Node Header --- */
.node-header {
  margin-bottom: var(--sf-space-xl);
  padding-bottom: var(--sf-space-lg);
  border-bottom: 1px solid var(--sf-border);
}
.node-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.node-type-badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border: 1px solid currentColor;
}
.type-narrative { color: #2c5f8a; }
.type-media { color: #8a2c2c; }
.type-document { color: #5f8a2c; }
.type-interlude { color: #6b2c8a; }
.type-real { color: #555; }

.node-title {
  font-size: 2.25rem;
  line-height: 1.15;
  margin-bottom: var(--sf-space-sm);
}
.node-summary {
  font-size: 1.1rem;
  font-style: italic;
  opacity: 0.75;
  line-height: 1.5;
}

/* --- Hero Images (node + stop pages) --- */
.node-hero,
.stop-hero {
  margin: 0 calc(var(--sf-space-lg) * -1) 2rem;  /* bleed past content padding */
  position: relative;
  overflow: hidden;
}
.node-hero img,
.stop-hero img {
  width: 100%;
  height: auto;
  object-fit: cover;
}
.node-hero figcaption,
.stop-hero figcaption {
  font-size: 0.8rem;
  font-style: italic;
  opacity: 0.5;
  padding: var(--sf-space-sm) var(--sf-space-lg) 0;
}
@media (max-width: 600px) {
  .node-hero,
  .stop-hero {
    margin-left: calc(var(--sf-space-md) * -1);
    margin-right: calc(var(--sf-space-md) * -1);
  }
}

/* --- Node Audio --- */
.node-audio {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem var(--sf-space-md);
  margin-bottom: 2rem;
  background: rgba(0,0,0,0.03);
  border-radius: 4px;
  font-size: 0.9rem;
}
.audio-play {
  background: none;
  border: 1px solid currentColor;
  padding: 0.35em 0.75em;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.audio-play:hover {
  background: rgba(0,0,0,0.06);
}

/* --- Node Links Sidebar --- */
.node-links-sidebar {
  margin-top: 2rem;
  padding: var(--sf-space-md) 1.25rem;
  border: 1px solid var(--sf-border);
  font-size: 0.9rem;
}
.node-links-sidebar h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sf-space-sm);
}
.node-links-sidebar ul {
  list-style: none;
  padding: 0;
}
.node-links-sidebar li {
  margin-bottom: 0.35rem;
}

/* --- Pull Quotes / Callouts (from inside-the-math) --- */
.pull-quote {
  float: right;
  clear: right;
  width: 38%;
  margin: 0.2rem 0 1.2rem 2rem;
  padding: 0.8rem 0 0.8rem var(--sf-space-md);
  border-left: 3px solid var(--accent, currentColor);
  font-size: 1.2rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--accent-ink, inherit);
  opacity: 0.9;
  /* 3D perspective tilt — body text funnels toward callout */
  transform-origin: right center;
  transform: perspective(600px) rotateY(14deg) scale(0.92);
  shape-outside: polygon(0% 0%, 100% 0%, 100% 100%, 14% 100%);
  shape-margin: 0.8rem;
}
.pull-quote.flip {
  float: left;
  clear: left;
  margin: 0.2rem 2rem 1.2rem 0;
  border-left: none;
  border-right: 3px solid var(--accent, currentColor);
  padding: 0.8rem var(--sf-space-md) 0.8rem 0;
  transform-origin: left center;
  transform: perspective(600px) rotateY(-14deg) scale(0.92);
  shape-outside: polygon(14% 0%, 100% 0%, 100% 100%, 0% 100%);
}

/* --- Redacted / Censorship --- */
.redacted {
  background: var(--sf-text, #1a1a1a);
  color: var(--sf-text, #1a1a1a);
  cursor: help;
  padding: 0 0.2em;
  border-radius: 2px;
  user-select: none;
}
.redacted:hover::after {
  content: attr(title);
  position: absolute;
  background: #333;
  color: #ff4444;
  padding: 0.25em 0.5em;
  font-size: 0.75rem;
  white-space: nowrap;
  transform: translateY(-100%);
  border-radius: 3px;
}

/* --- Thread Navigation --- */
.thread-nav {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--sf-border);
}
.thread-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sf-space-sm);
  padding: 0.35em 0.75em;
  border-left: 3px solid;
  font-size: 0.85rem;
  margin-bottom: var(--sf-space-md);
}
.thread-label { font-weight: 700; }
.thread-ai { opacity: 0.6; }

.thread-links {
  display: flex;
  flex-direction: column;
  gap: var(--sf-space-sm);
}
.thread-link {
  display: block;
  padding: var(--sf-space-sm) 0;
  text-decoration: none;
  font-size: 0.95rem;
}
.thread-link:hover {
  text-decoration: underline;
}
.thread-link--next {
  font-weight: 600;
}
.thread-link--lateral {
  opacity: 0.65;
  font-size: 0.9rem;
}

/* --- Stop Pages --- */
.stop-header {
  text-align: center;
  margin-bottom: 3rem;
}
.stop-border-top, .stop-border-bottom {
  height: 3px;
  background: currentColor;
  margin: var(--sf-space-md) 0;
}
.stop-title {
  font-size: 2rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.stop-subtitle {
  font-style: italic;
  font-size: 1.15rem;
  opacity: 0.7;
}

.stop-section {
  margin-bottom: var(--sf-space-xl);
}
.stop-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: var(--sf-space-md);
  padding-bottom: var(--sf-space-sm);
  border-bottom: 1px solid rgba(0,0,0,0.15);
}
.stop-list {
  list-style: none;
  padding: 0;
}
.stop-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.stop-item-marker {
  font-size: 0.85rem;
  margin-right: var(--sf-space-sm);
}
.stop-item-thread {
  font-weight: 700;
}
.stop-item-sep {
  margin: 0 var(--sf-space-xs);
  opacity: 0.4;
}
.stop-item-link {
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.stop-item-link:hover {
  background: rgba(0,0,0,0.05);
}
.stop-item-summary {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-top: var(--sf-space-xs);
}

.stop-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: var(--sf-space-md);
  border-top: 1px solid var(--sf-border);
}
.stop-nav-link {
  text-decoration: none;
  font-size: 0.95rem;
}
.stop-nav-link:hover { text-decoration: underline; }

/* --- Site Footer --- */
.site-footer {
  border-top: 1px solid rgba(0,0,0,0.08);
  padding: 2rem var(--sf-space-lg);
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.5;
}

/* --- Mobile --- */
@media (max-width: 720px) {
  .pull-quote {
    float: none;
    width: auto;
    margin: 1.2rem 0;
    font-size: 1.1rem;
    transform: none !important;
    transform-origin: center center !important;
    shape-outside: none;
    border-right: none;
  }
}

@media (max-width: 600px) {
  .content-area {
    padding: 1.25rem var(--sf-space-md) 3rem;
  }
  .node-title {
    font-size: 1.75rem;
  }
  .stop-title {
    font-size: 1.5rem;
  }
  .node-meta {
    flex-wrap: wrap;
    gap: var(--sf-space-sm);
  }
}
