:root {
  --paper: #f1eee6;
  --paper-deep: #e4dfd3;
  --ink: #171714;
  --muted: #6c685f;
  --line: #bab3a6;
  --accent: #e85d35;
  --accent-soft: #f3c7b8;
  --panel: rgba(255, 253, 247, 0.66);
  --mark: #ffd56a;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --content: 790px;
}

html[data-theme="night"] {
  --paper: #141411;
  --paper-deep: #1c1c18;
  --ink: #f1eee4;
  --muted: #a7a298;
  --line: #44423b;
  --accent: #ff7046;
  --accent-soft: #672f20;
  --panel: rgba(28, 28, 24, 0.72);
  --mark: #7a5212;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 4%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 24rem),
    repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), color-mix(in srgb, var(--line) 22%, transparent) 25%),
    var(--paper);
  font-family: var(--sans);
  text-rendering: optimizeLegibility;
  transition: color .25s ease, background-color .25s ease;
}

::selection { color: var(--paper); background: var(--accent); }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: .22em; }
button, input { font: inherit; }
button { color: inherit; }

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  padding: .7rem 1rem;
  color: var(--paper);
  background: var(--ink);
  transform: translateY(-180%);
}
.skip-link:focus { transform: translateY(0); }

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 90;
  height: 3px;
  background: transparent;
}
.reading-progress span { display: block; width: 0; height: 100%; background: var(--accent); }

.masthead { border-bottom: 1px solid var(--line); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 76px;
  padding: 0 clamp(1.2rem, 4vw, 4.5rem);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  display: flex;
  align-items: baseline;
  gap: .8rem;
  font-family: var(--mono);
  text-decoration: none;
  letter-spacing: .08em;
}
.wordmark span { font-size: .72rem; }
.wordmark b { color: var(--accent); font-size: .95rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.icon-button, .text-button {
  min-height: 38px;
  padding: .55rem .8rem;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  text-decoration: none;
  font-family: var(--mono);
  font-size: .72rem;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.icon-button:hover, .text-button:hover { border-color: var(--accent); transform: translateY(-2px); }
.icon-button { width: 38px; padding-inline: 0; font-size: 1rem; }

.hero {
  position: relative;
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(4rem, 9vw, 9rem) clamp(1.2rem, 7vw, 7.5rem) clamp(3rem, 7vw, 6rem);
  overflow: hidden;
}
.hero::after {
  content: "@";
  position: absolute;
  z-index: -1;
  right: -2vw;
  top: -8rem;
  color: color-mix(in srgb, var(--accent) 11%, transparent);
  font-family: var(--serif);
  font-size: clamp(24rem, 48vw, 48rem);
  line-height: 1;
  transform: rotate(-9deg);
}
.hero-kicker {
  margin-bottom: 1.8rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: clamp(.7rem, 1.2vw, .82rem);
  font-weight: 700;
  letter-spacing: .13em;
}
.hero h1 {
  max-width: 1050px;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.1rem, 8.4vw, 8.7rem);
  font-weight: 700;
  letter-spacing: -.065em;
  line-height: .94;
}
.hero h1 span { color: var(--accent); }
.hero h1 em { color: var(--accent); font-style: normal; }
.hero-deck {
  max-width: 700px;
  margin: 2.6rem 0 0 clamp(0px, 16vw, 210px);
  padding-left: 1.5rem;
  border-left: 4px solid var(--accent);
  font-family: var(--serif);
  font-size: clamp(1.1rem, 2vw, 1.55rem);
  line-height: 1.75;
}
.signal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 1.6fr;
  margin-top: clamp(3.5rem, 7vw, 7rem);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
.signal {
  min-height: 128px;
  padding: 1.2rem;
  border-right: 1px solid var(--line);
}
.signal:last-child { border-right: 0; }
.signal strong {
  display: block;
  margin-bottom: .65rem;
  color: var(--accent);
  font-family: var(--serif);
  font-size: clamp(1.8rem, 3.1vw, 3rem);
  line-height: 1;
}
.signal span { color: var(--muted); font-size: .8rem; line-height: 1.55; }
.signal-wide strong { color: var(--ink); font-size: clamp(1.5rem, 2.5vw, 2.45rem); }

.reveal { animation: reveal .7s cubic-bezier(.2,.7,.2,1) both; }
.reveal-2 { animation-delay: .08s; }
.reveal-3 { animation-delay: .16s; }
.reveal-4 { animation-delay: .24s; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.control-dock {
  position: sticky;
  top: 3px;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 4.5rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 89%, transparent);
  backdrop-filter: blur(18px);
}
.view-tabs { display: flex; }
.view-tab {
  padding: 1rem 1.4rem;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}
.view-tab:first-child { border-left: 1px solid var(--line); }
.view-tab span { margin-right: .65rem; color: var(--muted); font-family: var(--mono); font-size: .7rem; }
.view-tab.is-active { color: var(--paper); background: var(--ink); }
.view-tab.is-active span { color: var(--accent); }
.search-box {
  display: flex;
  align-items: center;
  width: min(360px, 38vw);
  gap: .6rem;
  border-inline: 1px solid var(--line);
  padding-inline: 1rem;
}
.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: .85rem;
}
.search-box output { min-width: 2.5rem; color: var(--accent); font-family: var(--mono); font-size: .72rem; text-align: right; }

.reading-shell {
  display: grid;
  grid-template-columns: minmax(210px, 285px) minmax(0, 1fr);
  max-width: 1280px;
  min-height: 80vh;
  margin: 0 auto;
  border-inline: 1px solid var(--line);
}
.toc-rail {
  align-self: stretch;
  padding: 3rem 1.5rem;
  border-right: 1px solid var(--line);
}
.toc-rail > * { position: sticky; }
.toc-label {
  top: 94px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .15em;
}
#dynamic-toc { top: 125px; max-height: calc(100vh - 250px); overflow-y: auto; scrollbar-width: thin; }
#dynamic-toc a {
  display: block;
  padding: .5rem 0 .5rem 1rem;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.45;
  text-decoration: none;
  transition: color .18s, border-color .18s, transform .18s;
}
#dynamic-toc a:hover, #dynamic-toc a.is-current { color: var(--ink); border-left-color: var(--accent); transform: translateX(3px); }
.download-links { top: calc(100vh - 120px); display: flex; flex-wrap: wrap; gap: .4rem .7rem; font-family: var(--mono); font-size: .65rem; }
.download-links span { width: 100%; color: var(--muted); }
.download-links a { color: var(--accent); }

.content-stage { min-width: 0; padding: clamp(3rem, 7vw, 7rem) clamp(1.3rem, 8vw, 7.5rem) 7rem; }
.content-panel { max-width: var(--content); margin: 0 auto; }
.content-panel:not(.is-active) { display: none; }
.prose { font-family: var(--serif); font-size: clamp(1rem, 1.3vw, 1.12rem); line-height: 1.95; }
.prose > h1 {
  margin: 0 0 3.5rem;
  padding-bottom: 2rem;
  border-bottom: 5px solid var(--ink);
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  line-height: 1.14;
  letter-spacing: -.045em;
}
.prose h2 {
  position: relative;
  margin: 5rem 0 1.8rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.65rem, 3vw, 2.5rem);
  line-height: 1.35;
  letter-spacing: -.025em;
  scroll-margin-top: 90px;
}
.prose h2::before {
  content: "§";
  position: absolute;
  right: calc(100% + 1rem);
  top: 1.35rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: .8rem;
}
.prose h3 {
  margin: 3rem 0 1rem;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 1.15rem;
  letter-spacing: .02em;
}
.prose p { margin: 1.15rem 0; }
.prose strong { font-family: var(--sans); font-weight: 700; }
.prose em { color: var(--accent); }
.prose blockquote {
  margin: 2.3rem 0;
  padding: 1.5rem 1.8rem;
  border: 0;
  border-left: 6px solid var(--accent);
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--paper-deep);
  font-size: 1.15em;
  line-height: 1.8;
}
.prose ul, .prose ol { padding-left: 1.5rem; }
.prose li { margin: .55rem 0; padding-left: .25rem; }
.prose li::marker { color: var(--accent); font-family: var(--mono); }
.prose code {
  padding: .12rem .32rem;
  color: var(--accent);
  background: var(--paper-deep);
  font-family: var(--mono);
  font-size: .86em;
}
.prose table { display: block; width: 100%; margin: 2.2rem 0; border-collapse: collapse; overflow-x: auto; font-family: var(--sans); font-size: .8rem; line-height: 1.55; }
.prose th, .prose td { min-width: 130px; padding: .85rem .9rem; border: 1px solid var(--line); vertical-align: top; }
.prose th { color: var(--paper); background: var(--ink); text-align: left; }
.prose hr { margin: 4rem 0; border: 0; border-top: 1px solid var(--line); }
.prose a:hover { color: var(--accent); }

.transcript > h2 { margin-top: 4.5rem; color: var(--accent); font-family: var(--mono); font-size: clamp(1.2rem, 2vw, 1.55rem); letter-spacing: 0; }
.transcript > h2::before { content: "TIMECODE"; top: -1.8rem; right: auto; left: 0; font-size: .58rem; letter-spacing: .1em; }
.transcript p:has(> strong:first-child) { margin: 2rem 0 .4rem; font-family: var(--sans); font-size: .78rem; line-height: 1.4; }
.transcript p:has(> strong:first-child) strong { display: inline-block; padding: .35rem .55rem; color: var(--paper); background: var(--ink); }
mark { color: inherit; background: var(--mark); outline: 2px solid var(--mark); }

.empty-search { max-width: var(--content); margin: 3rem auto; padding: 2rem; border: 1px dashed var(--accent); color: var(--muted); text-align: center; }
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding: 2.5rem clamp(1.2rem, 4vw, 4.5rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  line-height: 1.65;
}
.site-footer p { max-width: 520px; margin: 0; }
.site-footer div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 1rem; }

@media (max-width: 900px) {
  .signal-grid { grid-template-columns: repeat(2, 1fr); }
  .signal:nth-child(2) { border-right: 0; }
  .signal { border-bottom: 1px solid var(--line); }
  .signal-wide { grid-column: 1 / -1; border-bottom: 0; }
  .reading-shell { display: block; border: 0; }
  .toc-rail { padding: 1rem; border: 0; border-bottom: 1px solid var(--line); }
  .toc-label, .download-links { display: none; }
  #dynamic-toc { position: static; display: flex; max-height: none; gap: .35rem; overflow-x: auto; }
  #dynamic-toc a { flex: 0 0 auto; max-width: 240px; padding: .55rem .7rem; border: 1px solid var(--line); }
  .prose h2::before { display: none; }
}

@media (max-width: 640px) {
  .topbar { min-height: 62px; }
  .wordmark span, .print-button { display: none; }
  .topbar-actions .text-button:first-of-type { display: none; }
  .hero { padding-top: 4.5rem; }
  .hero h1 { font-size: clamp(3.1rem, 16vw, 5.2rem); }
  .hero-deck { margin-left: 0; }
  .signal { min-height: 110px; }
  .control-dock { align-items: stretch; padding: 0; gap: 0; }
  .view-tabs { flex: 1; }
  .view-tab { flex: 1; padding-inline: .65rem; font-size: .78rem; }
  .search-box { width: 52px; padding: 0 1rem; border-right: 0; transition: width .25s; }
  .search-box:focus-within { position: absolute; right: 0; width: 100%; height: 100%; background: var(--paper); }
  .search-box input { min-width: 0; }
  .search-box:not(:focus-within) input, .search-box:not(:focus-within) output { opacity: 0; }
  .content-stage { padding: 3.5rem 1.15rem 5rem; }
  .prose { line-height: 1.85; }
  .prose > h1 { font-size: 2.25rem; }
  .prose blockquote { margin-inline: 0; padding: 1.2rem; }
  .site-footer { flex-direction: column; }
  .site-footer div { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .topbar, .control-dock, .toc-rail, .reading-progress, .site-footer { display: none !important; }
  body { color: #111; background: #fff; }
  .reading-shell { display: block; border: 0; }
  .content-stage { padding: 0; }
  .content-panel:not(.is-active) { display: none; }
  .prose { max-width: none; font-size: 10.5pt; line-height: 1.65; }
  .prose h2 { break-after: avoid; }
  .prose p, .prose blockquote { orphans: 3; widows: 3; }
}
