/* ============================================
   ORBITAL CAPITAL — Site Styles
   A long-form essay site inspired by
   situational-awareness.ai
   ============================================ */

/* --- CSS Variables / Theming --- */
:root {
  /* Light mode (default) */
  --bg: #faf9f6;
  --bg-secondary: #f0efe9;
  --text: #1a1a1a;
  --text-secondary: #555;
  --text-tertiary: #888;
  --accent: #2d5a9e;
  --accent-hover: #1e3f6f;
  --border: #ddd;
  --border-light: #e8e8e8;
  --highlight: #fffbeb;
  --code-bg: #f5f5f0;
  --sidebar-bg: #faf9f6;
  --sidebar-border: #e0ddd5;
  --footnote-bg: #f7f6f0;
  --shadow: rgba(0,0,0,0.06);
  --progress-bar: #2d5a9e;
  --blockquote-border: #2d5a9e;
  --serif: 'Newsreader', 'Georgia', 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

[data-theme="dark"] {
  --bg: #111111;
  --bg-secondary: #1a1a1a;
  --text: #e0ddd5;
  --text-secondary: #a0a0a0;
  --text-tertiary: #707070;
  --accent: #6fa3e8;
  --accent-hover: #8db8f0;
  --border: #2a2a2a;
  --border-light: #222;
  --highlight: #1e1e10;
  --code-bg: #1a1a1a;
  --sidebar-bg: #111111;
  --sidebar-border: #2a2a2a;
  --footnote-bg: #1a1a18;
  --shadow: rgba(0,0,0,0.3);
  --progress-bar: #6fa3e8;
  --blockquote-border: #6fa3e8;
}

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

html {
  scroll-behavior: smooth;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  transition: background 0.3s ease, color 0.3s ease;
}

/* --- Reading Progress Bar --- */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--progress-bar);
  z-index: 1000;
  transition: width 0.1s linear;
  width: 0%;
}

/* --- Top Navigation --- */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--bg);
  border-bottom: 1px solid var(--border-light);
  padding: 0.6rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--sans);
  font-size: 0.8rem;
  backdrop-filter: blur(10px);
  transition: background 0.3s ease;
}

.top-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.top-nav a:hover {
  color: var(--accent);
}

.nav-title {
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--text);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Layout --- */
.page-wrapper {
  display: flex;
  margin-top: 48px;
}

/* --- Sidebar / Table of Contents --- */
.sidebar {
  position: fixed;
  top: 48px;
  left: 0;
  width: 280px;
  height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 2rem 1.5rem;
  border-right: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  font-family: var(--sans);
  font-size: 0.78rem;
  z-index: 800;
  transition: transform 0.3s ease, background 0.3s ease;
}

.sidebar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
  font-weight: 600;
}

.sidebar ol {
  list-style: none;
  counter-reset: chapter;
}

.sidebar li {
  counter-increment: chapter;
  margin-bottom: 0.5rem;
}

.sidebar li a {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1.4;
}

.sidebar li a::before {
  content: counter(chapter, upper-roman) ".";
  font-weight: 600;
  color: var(--text-tertiary);
  font-size: 0.7rem;
  min-width: 2rem;
  flex-shrink: 0;
}

.sidebar li a:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.sidebar li a.active {
  background: var(--bg-secondary);
  color: var(--accent);
  font-weight: 500;
}

.sidebar li a.active::before {
  color: var(--accent);
}

/* --- Main Content Area --- */
.main-content {
  margin-left: 280px;
  flex: 1;
  min-height: 100vh;
}

.content-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 3rem 2rem 6rem;
}

/* --- Hero / Landing Page --- */
.hero {
  min-height: 85vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 0;
}

.hero-eyebrow {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-tertiary);
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: 3.2rem;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 1.5rem;
  letter-spacing: -0.02em;
  max-width: 600px;
}

.hero .subtitle {
  font-size: 1.25rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 540px;
  margin-bottom: 2.5rem;
}

.hero .author-line {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.hero .date-line {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

.hero .read-time {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: 0.3rem;
}

.begin-reading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  margin-top: 2.5rem;
  padding: 0.7rem 1.4rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  transition: all 0.2s;
  font-weight: 500;
}

.begin-reading:hover {
  background: var(--accent);
  color: #fff;
}

/* --- Chapter Styles --- */
.chapter-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-light);
}

.chapter-number {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-tertiary);
  margin-bottom: 0.8rem;
}

.chapter-header h1 {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin-bottom: 0.8rem;
}

.chapter-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.5;
}

/* --- Typography --- */
.prose h2 {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 3rem;
  margin-bottom: 1rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.prose h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
  line-height: 1.35;
}

.prose p {
  margin-bottom: 1.25rem;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(45, 90, 158, 0.3);
  transition: text-decoration-color 0.2s;
}

.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose strong {
  font-weight: 600;
}

.prose em {
  font-style: italic;
}

/* --- Blockquotes --- */
.prose blockquote {
  border-left: 3px solid var(--blockquote-border);
  margin: 2rem 0;
  padding: 0.8rem 1.5rem;
  color: var(--text-secondary);
  font-style: italic;
  background: var(--footnote-bg);
  border-radius: 0 6px 6px 0;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

/* --- Callout Boxes --- */
.callout {
  background: var(--highlight);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 2rem 0;
  font-size: 0.95rem;
}

.callout-label {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

/* --- Figures / Images --- */
.prose figure {
  margin: 2.5rem 0;
}

.prose figure img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.prose figcaption {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.6rem;
  text-align: center;
}

/* --- Footnotes --- */
.footnote-ref {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--accent);
  cursor: pointer;
  vertical-align: super;
  line-height: 0;
  padding: 0 2px;
  font-weight: 600;
}

.footnote-ref:hover {
  text-decoration: underline;
}

.footnotes-section {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-light);
}

.footnotes-section h3 {
  font-family: var(--sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

.footnote-item {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.footnote-number {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--accent);
  font-size: 0.75rem;
  min-width: 1.5rem;
  flex-shrink: 0;
  padding-top: 0.15rem;
}

/* --- Chapter Navigation (bottom of each chapter) --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-light);
  font-family: var(--sans);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s;
  max-width: 48%;
}

.chapter-nav a:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

.chapter-nav .nav-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 0.3rem;
}

.chapter-nav .nav-chapter-title {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
  line-height: 1.3;
}

.chapter-nav .next {
  text-align: right;
  margin-left: auto;
}

/* --- Inline Sidenote (for wider screens) --- */
.sidenote {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.45;
  margin-top: 0.2rem;
}

/* --- Tables --- */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.9rem;
}

.prose th {
  font-family: var(--sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  text-align: left;
  padding: 0.8rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
}

.prose td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border-light);
}

/* --- Code --- */
.prose code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* --- Statistics / Key Numbers --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin: 2.5rem 0;
}

.stat-card {
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--border-light);
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
  font-family: var(--sans);
}

.stat-label {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Pull Quote --- */
.pull-quote {
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--accent);
  margin: 3rem 0;
  padding: 0 1rem;
  text-align: center;
  letter-spacing: -0.01em;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px var(--shadow);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: block !important;
  }
}

@media (max-width: 640px) {
  html {
    font-size: 16px;
  }

  .hero h1 {
    font-size: 2.2rem;
  }

  .content-container {
    padding: 2rem 1.2rem 4rem;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .chapter-nav {
    flex-direction: column;
    gap: 1rem;
  }

  .chapter-nav a {
    max-width: 100%;
  }
}

/* --- Menu Toggle (mobile) --- */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.2rem;
  padding: 0.3rem;
}

/* --- Overlay --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 799;
}

.sidebar-overlay.visible {
  display: block;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* --- Selection --- */
::selection {
  background: rgba(45, 90, 158, 0.15);
}

/* --- Print --- */
@media print {
  .top-nav, .sidebar, #progress-bar, .chapter-nav, .theme-toggle {
    display: none !important;
  }
  .main-content {
    margin-left: 0;
  }
  body {
    font-size: 12pt;
  }
}
