:root {
  color-scheme: dark;
  --bg: #060606;
  --panel: #111113;
  --panel-strong: #18181b;
  --border: #27272a;
  --border-bright: #3f3f46;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --dim: #71717a;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.18);
  --paper: #e6dcc6;
  --ink: #1f1a14;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 8%, rgba(56, 189, 248, 0.13), transparent 28rem),
    linear-gradient(180deg, #09090b 0%, var(--bg) 42rem);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 20px;
  background: rgba(6, 6, 6, 0.82);
  border-bottom: 1px solid rgba(63, 63, 70, 0.72);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0;
}

.brand span span {
  color: var(--accent);
}

.brand-mark {
  width: 24px;
  height: 24px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 47%, var(--accent) 47% 53%, transparent 53%),
    linear-gradient(0deg, transparent 47%, var(--accent) 47% 53%, transparent 53%);
  box-shadow: 0 0 26px var(--accent-soft);
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.top-actions {
  display: inline-flex;
  gap: 8px;
}

/* Positioning only — the share bar styles itself (tool-share.js). */
.story-share {
  margin-top: 22px;
}

@media (max-width: 860px) {
  .header-actions {
    gap: 8px;
  }
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(24, 24, 27, 0.75);
  cursor: pointer;
}

.icon-button:hover,
.icon-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.story-rail {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  overflow: auto;
  padding: 22px 14px 28px 20px;
  border-right: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.74);
}

.rail-head h1 {
  margin: 6px 0 16px;
  max-width: 12ch;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.stat {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(24, 24, 27, 0.68);
}

.stat strong,
.stat span {
  display: block;
}

.stat strong {
  font-size: 1.15rem;
}

.stat span {
  margin-top: 2px;
  color: var(--dim);
  font-size: 0.72rem;
}

.search-box {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  height: 42px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f0f11;
  padding: 0 12px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.theme-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.theme-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.theme-chip.active,
.theme-chip:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.story-list {
  display: grid;
  gap: 10px;
}

.story-card {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-height: 96px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(24, 24, 27, 0.62);
  padding: 9px;
  cursor: pointer;
}

.story-card:hover,
.story-card.active {
  border-color: var(--accent);
  background: rgba(24, 24, 27, 0.92);
}

.story-card img {
  width: 68px;
  height: 86px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--panel-strong);
}

.story-card h2 {
  margin: 0;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.16;
}

.story-card p {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 0.73rem;
  line-height: 1.35;
}

.reader-pane {
  min-width: 0;
  padding: 24px;
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: stretch;
}

.story-context,
.progress-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.82);
}

.story-context {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  min-height: 420px;
  overflow: hidden;
}

.cover-wrap {
  position: relative;
  min-height: 420px;
  background: #121214;
}

.cover-wrap img {
  width: 100%;
  height: 100%;
  min-height: 420px;
  object-fit: cover;
  display: block;
}

.cover-sheen {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(6, 6, 6, 0.26), transparent 28%),
    linear-gradient(180deg, transparent 58%, rgba(6, 6, 6, 0.42));
  pointer-events: none;
}

.context-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: clamp(24px, 4vw, 52px);
}

.context-copy h2 {
  margin: 10px 0 14px;
  max-width: 15ch;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: clamp(2.15rem, 5vw, 4.85rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.context-copy p {
  max-width: 72ch;
  color: #d4d4d8;
  font-size: 1rem;
  line-height: 1.75;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0 0;
}

.fact-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(6, 6, 6, 0.34);
}

.fact-grid dt {
  color: var(--dim);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.fact-grid dd {
  margin: 6px 0 0;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.35;
}

.progress-panel {
  position: sticky;
  top: 88px;
  align-self: start;
  padding: 14px;
}

.year-card {
  display: grid;
  gap: 4px;
  padding: 15px;
  border-radius: 8px;
  background: var(--accent-soft);
}

.year-card span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.year-card strong {
  font-size: 2rem;
}

.chapter-nav {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.chapter-dot {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.chapter-dot span:first-child {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border-bright);
  color: var(--dim);
  font-size: 0.72rem;
}

.chapter-dot span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

.chapter-dot.active,
.chapter-dot:hover {
  color: var(--text);
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.chapter-dot.active span:first-child {
  border-color: var(--accent);
  color: var(--accent);
}

.timeline-stage {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.baseline-rail {
  position: sticky;
  top: 88px;
  min-height: 360px;
  border: 1px solid rgba(230, 220, 198, 0.25);
  border-radius: 8px;
  background:
    linear-gradient(rgba(230, 220, 198, 0.86), rgba(230, 220, 198, 0.82)),
    repeating-linear-gradient(90deg, transparent 0 12px, rgba(31, 26, 20, 0.04) 12px 13px);
  color: var(--ink);
  padding: 18px;
  box-shadow: inset 0 0 50px rgba(31, 26, 20, 0.09);
}

.rail-label {
  display: inline-flex;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--ink);
  font-family: "Libre Baskerville", Georgia, serif;
  font-weight: 700;
}

.baseline-rail p {
  margin: 0;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.7;
}

.chapter-stack {
  display: grid;
  gap: 22px;
}

.chapter-card {
  display: grid;
  grid-template-columns: minmax(260px, 46%) minmax(0, 1fr);
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.86);
  scroll-margin-top: 86px;
}

.chapter-card.active {
  border-color: rgba(56, 189, 248, 0.75);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.22), 0 24px 70px rgba(0, 0, 0, 0.28);
}

.chapter-art {
  position: relative;
  min-height: 520px;
  background: #151517;
}

.chapter-art img {
  width: 100%;
  height: 100%;
  min-height: 520px;
  object-fit: cover;
  display: block;
}

.chapter-number {
  position: absolute;
  left: 14px;
  top: 14px;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(244, 244, 245, 0.28);
  border-radius: 50%;
  background: rgba(6, 6, 6, 0.56);
  color: var(--text);
  font-weight: 800;
}

.chapter-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: clamp(24px, 4vw, 50px);
}

.chapter-year {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chapter-copy h3 {
  margin: 10px 0 16px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: clamp(1.8rem, 3.4vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.chapter-copy p {
  margin: 0;
  color: #d4d4d8;
  font-size: 1.02rem;
  line-height: 1.78;
}

.compact-text .chapter-copy p,
.compact-text .context-copy p {
  font-size: 0.92rem;
  line-height: 1.55;
}

.baseline-hidden .timeline-stage {
  grid-template-columns: minmax(0, 1fr);
}

.baseline-hidden .baseline-rail {
  display: none;
}

.noscript {
  padding: 2rem;
  color: var(--text);
  background: var(--bg);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .story-rail {
    position: relative;
    top: 0;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .rail-head h1 {
    max-width: none;
  }

  .story-list {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 860px) {
  .app-header {
    padding: 0 12px;
  }

  /* The tool-level share bar wraps to a second row beside the brand and overlaps
     on phones. Drop it here; the per-story share (in the reader panel) remains. */
  .header-actions .tool-share {
    display: none;
  }

  .reader-pane {
    padding: 14px;
  }

  .theme-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .theme-chip {
    flex: 0 0 auto;
  }

  .reader-grid,
  .story-context,
  .timeline-stage,
  .chapter-card,
  .fact-grid {
    grid-template-columns: 1fr;
  }

  .progress-panel,
  .baseline-rail {
    position: relative;
    top: 0;
  }

  .cover-wrap,
  .cover-wrap img,
  .chapter-art,
  .chapter-art img {
    min-height: 320px;
  }

  .chapter-card {
    min-height: 0;
  }
}
