/* attention.sh — "One Forward Pass" story page */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #4ade80;
  --accent-soft: #86efac;
  --link: #79c0ff;
  --border: #30363d;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* the 3D scene sits behind everything */
#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

/* minimal header */
.story-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.story-header a { color: var(--text-dim); text-decoration: none; }
.story-header a:hover { color: var(--accent); }
.story-header .brand { color: var(--text); font-weight: 700; }
.story-header .brand .prompt { color: var(--accent); margin-right: 0.4em; }

/* chapter progress dots */
.progress {
  position: fixed;
  right: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.progress { gap: 0.15rem; }
.progress button {
  /* 24px hit target around a 9px visual dot */
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.progress button::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  box-sizing: border-box;
}
.progress button.active::before {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.7);
}

/* scroll hint */
.scroll-hint {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  animation: hint-bob 2s ease-in-out infinite;
  transition: opacity 0.4s;
}
@keyframes hint-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(5px); }
}

/* chapters + copy panels */
.chapters { position: relative; z-index: 10; }

.chapter { height: 170vh; position: relative; }
.chapter.ch-0 { height: 150vh; }
.chapter.ch-1 { height: 210vh; }
.chapter.ch-5 { height: 200vh; }
.chapter.ch-6 { height: 230vh; }
.chapter.ch-9 { height: 150vh; }

.panel {
  position: sticky;
  top: 24vh;
  max-width: 33rem;
  margin: 0 auto 0 max(6vw, 1.25rem);
  background: rgba(22, 27, 34, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.4rem 1.6rem;
}
/* content is visible by default; the animated experience opts in once the
   renderer boots (body.js-anim), so a failed three.js load degrades readably */
body.js-anim .panel {
  opacity: 0;
  transform: translateY(14px);
  will-change: opacity, transform;
}
.chapter:nth-child(even) .panel { margin: 0 max(6vw, 1.25rem) 0 auto; }
/* explicit sides (the leak chapter shifted child parity) */
.chapter.ch-1 .panel, .chapter.ch-3 .panel, .chapter.ch-5 .panel, .chapter.ch-7 .panel {
  margin: 0 auto 0 max(6vw, 1.25rem);
}
.chapter.ch-2 .panel, .chapter.ch-4 .panel, .chapter.ch-6 .panel, .chapter.ch-8 .panel {
  margin: 0 max(6vw, 1.25rem) 0 auto;
}

.panel .stage {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  margin: 0 0 0.5rem;
}
.panel h2 { margin: 0 0 0.7rem; font-size: 1.45rem; line-height: 1.25; letter-spacing: -0.01em; }
.panel p { margin: 0.6rem 0; color: var(--text); }
.panel p.dim { color: var(--text-dim); font-size: 0.95rem; }
.panel strong { color: var(--accent-soft); }
.panel a { color: var(--link); }

/* typed command (chapter 0) */
.panel.hero-panel {
  background: transparent;
  border: none;
  backdrop-filter: none;
  max-width: 42rem;
  margin: 0 auto;
  text-align: center;
  top: 38vh;
}
.typed-line {
  font-family: var(--mono);
  font-size: clamp(1.2rem, 3.4vw, 2.1rem);
  color: var(--text);
}
.typed-line .ps1 { color: var(--accent); }
.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.15em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.hero-sub { color: var(--text-dim); margin-top: 1.2rem; font-size: 1rem; }

/* attention watermark (chapter 4) */
.watermark {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 7rem);
  color: rgba(74, 222, 128, 0.10);
  letter-spacing: -0.03em;
  opacity: 0;                 /* driven by JS */
}

/* per-chapter formula chip */
.formula {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 5.4rem;
  z-index: 25;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent-soft);
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.85rem;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
  overflow: hidden;
}
.formula sub, .formula sup { font-size: 0.68em; }
body.static .formula { display: none; }

/* chapter navigation — scroll without the toil */
.chap-nav {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: rgba(16, 21, 28, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.7rem;
}
.chap-nav button {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 0.6rem;
  cursor: pointer;
}
.chap-nav button:hover { border-color: var(--accent); }
.chap-nav button.on { background: rgba(74, 222, 128, 0.15); border-color: var(--accent); }
.chap-mid { text-align: center; min-width: 11rem; }
.chap-count { font-family: var(--mono); font-size: 0.65rem; color: var(--text-dim); }
.chap-title { font-family: var(--mono); font-size: 0.85rem; color: var(--text); }
body.static .chap-nav { display: none; }
@media (max-width: 700px) {
  .chap-mid { min-width: 7rem; }
  .chap-title { font-size: 0.72rem; }
}

/* multi-head labels (attention chapter) */
.head-tags {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.6rem;
  padding-bottom: 11vh;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 0.72rem;
}
.head-tags span {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  background: rgba(22, 27, 34, 0.7);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
}
.head-tags span.on { opacity: 1; transform: none; }

/* terminal output (final chapter) */
.panel.terminal-panel {
  font-family: var(--mono);
  font-size: 0.95rem;
  max-width: 36rem;
  margin: 0 auto;
  top: 34vh;
}
.terminal-panel .line { transition: opacity 0.45s, transform 0.45s; margin: 0.45rem 0; }
body.js-anim .terminal-panel .line { opacity: 0; transform: translateY(6px); }
body.js-anim .terminal-panel .line.show { opacity: 1; transform: none; }
.terminal-panel .line .ps1 { color: var(--accent); }
.terminal-panel .line .arrow { color: var(--text-dim); margin-right: 0.5em; }
.terminal-panel .line a { color: var(--link); text-decoration: none; }
.terminal-panel .line a:hover { color: var(--accent-soft); }

/* static fallback (no WebGL / reduced motion / failed three.js load) */
body.static #scene, body.static .scroll-hint, body.static .watermark,
body.static .progress, body.static .head-tags { display: none; }
body.static .chapter { height: auto; padding: 3.5rem 0; }
body.static .panel { position: static; }

/* visually hidden, available to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 700px) {
  .panel, .chapter:nth-child(even) .panel {
    margin: 0 auto;
    max-width: calc(100vw - 2.5rem);
  }
  .progress { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cursor, .scroll-hint { animation: none; }
}
