:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-soft: #111821;
  --panel: #111821;
  --panel-strong: #161f2b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --muted-strong: #cbd5e1;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.28);
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --sans: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: "SFMono-Regular", "Menlo", "Monaco", "Courier New", monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-soft: #eef3f9;
  --panel: #ffffff;
  --panel-strong: #f7f9fc;
  --text: #0f172a;
  --muted: #475569;
  --muted-strong: #1e293b;
  --line: rgba(15, 23, 42, 0.10);
  --line-strong: rgba(15, 23, 42, 0.18);
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0b0f14 0%, #0d131b 100%);
  color: var(--text);
  font-family: var(--sans);
}

:root[data-theme="light"] body {
  background: linear-gradient(180deg, #f4f7fb 0%, #edf2f8 100%);
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.site-header,
.portal-shell,
.page-shell {
  width: min(1520px, calc(100vw - 32px));
  margin: 0 auto;
}

.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  padding: 20px 0 14px;
}

.brand-lockup {
  display: block;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.site-header h1,
.hero-copy h2,
.constellation-copy h3,
.section-heading h3,
.doc-header-copy h2,
.page-hero h2,
.media-card h3,
.featured-card h4,
.panel-intro h2,
.article-stage h1,
.article-stage h2,
.article-stage h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-header h1 {
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 1.04;
}

.site-subtitle,
.helper-copy,
.panel-intro p,
.hero-copy p,
.constellation-copy p,
.doc-summary,
.library-card-summary,
.featured-card p,
.article-stage p,
.article-stage li,
.article-stage blockquote,
.metric-label,
.media-card p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.site-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-shell {
  display: grid;
  gap: 4px;
}

.search-label {
  color: var(--muted);
  font-size: 12px;
}

.search-shell input,
.ghost-button,
.library-card,
.featured-card,
.start-card,
.media-card,
.metric-card,
.hero-card,
.constellation-card,
.doc-header-card,
.article-shell,
.insight-shell,
.library-panel,
.page-hero {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.search-shell input {
  width: min(320px, 42vw);
  height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: var(--panel-strong);
  border-color: var(--line-strong);
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  color: var(--muted-strong);
  background: var(--panel-strong);
  border-color: var(--line-strong);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.ghost-button:hover,
.library-card:hover,
.featured-card:hover,
.start-card:hover,
.section-nav button:hover {
  border-color: rgba(59, 130, 246, 0.38);
  background: rgba(22, 31, 43, 0.98);
  color: var(--text);
}

:root[data-theme="light"] .ghost-button:hover,
:root[data-theme="light"] .library-card:hover,
:root[data-theme="light"] .featured-card:hover,
:root[data-theme="light"] .start-card:hover,
:root[data-theme="light"] .section-nav button:hover {
  border-color: rgba(37, 99, 235, 0.30);
  background: rgba(37, 99, 235, 0.06);
  color: var(--text);
}

.progress-rail {
  position: sticky;
  top: 0;
  z-index: 8;
  height: 3px;
  background: rgba(148, 163, 184, 0.08);
}

.reading-progress {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 100ms linear;
}

.portal-shell {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  gap: 16px;
  padding: 14px 0 28px;
}

.library-panel {
  position: sticky;
  top: 16px;
  align-self: start;
  height: calc(100vh - 32px);
  overflow: auto;
  padding: 14px;
  z-index: 3;
}

.panel-intro {
  margin-bottom: 12px;
}

.panel-intro h2 {
  font-size: 20px;
  line-height: 1.15;
}

.library-groups {
  display: grid;
  gap: 12px;
}

.library-group {
  display: grid;
  gap: 8px;
}

.group-title {
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.library-card {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.library-card.active {
  border-color: rgba(59, 130, 246, 0.42);
  background: rgba(59, 130, 246, 0.08);
}

.library-card-category {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.library-card-title {
  font-size: 14px;
  line-height: 1.3;
}

.library-card-summary {
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.reading-stage {
  min-width: 0;
  position: relative;
  z-index: 1;
}

.hero-card,
.constellation-card,
.doc-header-card,
.page-hero {
  padding: 18px;
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 280px;
  gap: 16px;
}

.hero-copy h2 {
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.04;
  max-width: 12ch;
}

.hero-metrics {
  display: grid;
  gap: 10px;
}

.metric-card {
  padding: 12px 14px;
}

.metric-value {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 24px;
}

.start-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}

.start-card,
.featured-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.start-card strong,
.featured-card h4 {
  font-size: 18px;
  line-height: 1.2;
}

.constellation-card {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  overflow: hidden;
}

.constellation-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.constellation-controls .ghost-button {
  min-height: 34px;
  padding: 0 12px;
}

.doc-constellation-viewport {
  position: relative;
  min-height: 360px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(90deg, rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    var(--panel-strong);
  background-size: 32px 32px, 32px 32px, auto;
}

.doc-constellation-stage {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.constellation-copy h3,
.section-heading h3,
.page-hero h2,
.media-card h3 {
  font-size: 24px;
  line-height: 1.08;
}

.doc-constellation {
  position: relative;
  min-height: 340px;
  min-width: 680px;
  overflow: visible;
}

.constellation-center {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 999px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  background: var(--panel-strong);
  color: var(--muted-strong);
  font-family: var(--serif);
  font-size: 16px;
  text-align: center;
}

.constellation-center-label,
.constellation-summary-label {
  display: block;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.constellation-center strong,
.constellation-category-summary strong {
  display: block;
  margin: 4px 0;
  color: var(--text);
}

.constellation-line {
  position: absolute;
  inset: 50% auto auto 50%;
  transform-origin: left center;
  height: 1px;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.3), transparent);
  pointer-events: none;
}

.constellation-line-file {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.26), transparent);
}

.constellation-node {
  position: absolute;
  min-width: 130px;
  max-width: 170px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.constellation-node-label,
.constellation-node-meta {
  display: block;
}

.constellation-node-label {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

.constellation-node-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.constellation-category-node {
  min-width: 144px;
  background: rgba(59, 130, 246, 0.08);
}

.constellation-category-node.active {
  border-color: rgba(59, 130, 246, 0.48);
  background: rgba(59, 130, 246, 0.16);
}

.constellation-file-node {
  min-width: 138px;
  max-width: 182px;
  border-style: dashed;
}

.constellation-file-node.active {
  border-color: rgba(59, 130, 246, 0.44);
  background: rgba(59, 130, 246, 0.10);
}

.constellation-category-summary {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: 220px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(17, 24, 33, 0.92);
  color: var(--muted-strong);
  box-shadow: var(--shadow);
}

:root[data-theme="light"] .constellation-category-summary {
  background: rgba(255, 255, 255, 0.94);
}

.section-heading {
  margin: 18px 0 10px;
}

.featured-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.doc-header-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.doc-header-copy h2 {
  font-size: clamp(30px, 3.8vw, 40px);
  line-height: 1.05;
}

.doc-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.doc-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 12px;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 216px;
  gap: 16px;
  align-items: start;
}

.article-shell {
  padding: 18px 20px;
}

.article-stage {
  font-family: var(--serif);
}

.article-stage > :first-child {
  margin-top: 0;
}

.article-stage h1,
.article-stage h2,
.article-stage h3 {
  color: var(--text);
  scroll-margin-top: 80px;
}

.article-stage h1 {
  font-size: clamp(34px, 4vw, 48px);
  margin-bottom: 14px;
  line-height: 1.04;
}

.article-stage h2 {
  margin: 28px 0 10px;
  font-size: clamp(24px, 2.2vw, 30px);
  line-height: 1.08;
}

.article-stage h3 {
  margin: 22px 0 8px;
  font-size: 20px;
  line-height: 1.16;
}

.article-stage p,
.article-stage li,
.article-stage blockquote,
.article-stage pre,
.article-stage code {
  font-size: 16px;
}

.article-stage ul,
.article-stage ol {
  padding-left: 22px;
}

.article-stage hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

.article-stage blockquote {
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 2px solid var(--accent);
  background: rgba(59, 130, 246, 0.08);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.article-stage pre {
  overflow: auto;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #0f1722;
  color: #dbe4ee;
  font-family: var(--mono);
}

:root[data-theme="light"] .article-stage pre {
  background: #e8eef6;
  color: #0f172a;
}

.article-stage code {
  font-family: var(--mono);
}

.article-stage p code,
.article-stage li code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(59, 130, 246, 0.08);
  color: #bfdbfe;
}

:root[data-theme="light"] .article-stage p code,
:root[data-theme="light"] .article-stage li code {
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
}

.article-stage a {
  color: #93c5fd;
}

:root[data-theme="light"] .article-stage a {
  color: #1d4ed8;
}

.article-stage .reveal,
.article-stage .reveal.visible {
  opacity: 1;
  transform: none;
  transition: none;
}

.insight-rail {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
}

.insight-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px;
}

.insight-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.jump-list-container {
  flex: 1;
  overflow-y: auto;
  padding-top: 10px;
  padding-right: 6px;
}

.section-nav {
  display: grid;
  gap: 6px;
}

.section-nav button {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--muted-strong);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.section-nav button.active {
  border-color: rgba(59, 130, 246, 0.42);
  background: rgba(59, 130, 246, 0.12);
  color: var(--text);
}

.focus-mode.reader-mode .library-panel,
.focus-mode.reader-mode .insight-rail {
  opacity: 0.34;
}

.focus-mode.reader-mode .library-panel:hover,
.focus-mode.reader-mode .insight-rail:hover {
  opacity: 1;
}

.reader-mode .site-header {
  padding-top: 14px;
  padding-bottom: 10px;
}

.reader-mode .site-subtitle {
  max-width: 42rem;
}

.page-shell {
  padding: 18px 0 28px;
}

.page-hero {
  margin-bottom: 16px;
}

.media-stage {
  display: grid;
  gap: 16px;
}

.media-card {
  padding: 16px;
}

.embed-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.embed-panel {
  display: grid;
  gap: 8px;
}

.embed-panel h4 {
  margin: 0;
  color: var(--muted-strong);
  font-size: 14px;
}

.embed-frame {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: #0f1722;
}

.embed-frame.youtube {
  aspect-ratio: 16 / 9;
  min-height: 320px;
}

.embed-frame.spotify {
  height: 352px;
  min-height: 352px;
}

.support-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 1180px) {
  .site-header,
  .hero-card,
  .constellation-card,
  .doc-header-card,
  .reader-layout,
  .embed-grid {
    grid-template-columns: 1fr;
  }

  .portal-shell {
    grid-template-columns: 1fr;
  }

  .library-panel,
  .insight-rail {
    position: static;
    height: auto;
  }
}

@media (max-width: 860px) {
  .start-grid,
  .featured-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .site-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .site-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-shell {
    width: 100%;
  }

  .search-shell input {
    width: 100%;
  }

  .site-header,
  .portal-shell,
  .page-shell {
    width: min(100vw - 20px, 1520px);
  }
}
