@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  --text-main: #33404F;
  --text-muted: rgba(51, 64, 79, 0.6);
  --bg-color: #FAFAFA;
  --accent-color: rgba(51, 64, 79, 0.1);
  --border-color: rgba(51, 64, 79, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-color);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

body.page-secondary {
  align-items: flex-start;
  padding-top: 12vh;
}

.container {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 20px;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-main);
  text-align: left;
}

p {
  color: var(--text-muted);
  margin-bottom: 20px;
  text-align: justify;
}

p strong {
  color: var(--text-main);
  font-weight: 500;
}

a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--text-main);
}

.arc-link {
  font-weight: 600;
  color: var(--text-main);
}

.arc-link:hover {
  color: var(--text-main);
}

/* Social Links */
.social-links {
  display: flex;
  gap: 24px;
  margin: 28px 0 48px 0;
  font-size: 14px;
}

.social-link {
  display: flex;
  align-items: center;
  gap: 6px;
}

.social-arrow {
  display: inline-block;
  transform: rotate(-45deg);
  font-size: 16px;
  line-height: 1;
}

/* Sections */
.section {
  margin-bottom: 36px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 20px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  text-align: left;
}

.see-more {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.see-more:hover {
  color: var(--text-main);
}

/* Lists (Work and Portfolio Investments) */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
}

.item-title {
  font-weight: 500;
  color: var(--text-main);
  text-align: left;
}

.item-desc {
  color: var(--text-muted);
  font-weight: 400;
  text-align: left;
}

.item-link {
  text-decoration: none;
  border-radius: 4px;
  transition: opacity 0.2s ease;
}

.item-link:hover {
  opacity: 0.7;
}

/* Utility for Secondary Pages */
.back-link {
  display: inline-block;
  margin-bottom: 32px;
  font-size: 14px;
  color: var(--text-muted);
}

.back-link:hover {
  color: var(--text-main);
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: left;
}

.page-desc {
  font-size: 15px;
  color: var(--text-muted);
  text-align: justify;
}

/* Coming Soon */
.coming-soon-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 0;
}

.coming-soon-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 8px;
  text-align: left;
}

.coming-soon-desc {
  font-size: 15px;
  color: var(--text-muted);
  text-align: justify;
}

/* Animation */
.fade-in {
  opacity: 0;
  animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────────────────────────────────────────────────
   RESEARCH PAGES
   ───────────────────────────────────────────────────────────────── */

/* Wider container for research layout */
.research-container {
  max-width: 860px;
}

/* Two-column layout: sidebar + content */
.research-layout {
  display: flex;
  gap: 56px;
  align-items: flex-start;
}

/* ── Left sidebar navigation ── */
.research-nav {
  width: 192px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 48px;
}

.research-nav .back-link {
  margin-bottom: 20px;
}

/* Chapter toggle button */
.chapter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  margin-bottom: 10px;
}

.chapter-active .chapter-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.chapter-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.chapter-toggle[aria-expanded="true"] .chapter-chevron {
  transform: rotate(90deg);
}

.subchapter-list {
  list-style: none;
  padding-left: 14px;
  border-left: 2px solid var(--border-color);
  margin-bottom: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: max-height 220ms ease, opacity 160ms ease, transform 160ms ease, visibility 0s linear 220ms;
  will-change: max-height, opacity, transform;
}

.subchapter-list.is-open {
  max-height: 240px;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
}

.subchapter-list li {
  margin-bottom: 8px;
}

.subchapter-list li:last-child {
  margin-bottom: 0;
}

.subchapter-link {
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.18s ease;
  display: block;
  line-height: 1.4;
}

.subchapter-link:hover,
.subchapter-link.active {
  color: var(--text-main);
}

.nav-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 22px 0;
}

.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: color 0.18s ease;
}

.repo-link:hover {
  color: var(--text-main);
}

/* ── Research content area ── */
.research-content {
  flex: 1;
  min-width: 0;
}

.research-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
  text-align: left;
}

.research-meta {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 40px;
  text-align: left;
}

.research-section {
  margin-bottom: 52px;
  scroll-margin-top: 40px;
}

.section-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 16px;
  text-align: left;
}

.strategy-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin: 28px 0 10px;
  text-align: left;
}

/* ── Equation blocks ── */
.equation {
  background: rgba(51, 64, 79, 0.035);
  border-left: 2px solid rgba(51, 64, 79, 0.18);
  padding: 13px 18px;
  margin: 14px 0 18px;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Menlo, Monaco, monospace;
  font-size: 13px;
  line-height: 1.85;
  color: var(--text-main);
  border-radius: 0 4px 4px 0;
  overflow-x: auto;
}

/* ── Inactive chapter navigation link ── */
.chapter-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.18s ease;
}

.chapter-item + .chapter-item {
  margin-top: 8px;
}

.chapter-link {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
  padding: 0;
  margin-bottom: 0;
  transition: color 0.18s ease;
}

.chapter-link:hover {
  color: var(--text-main);
}

.chapter-link .chapter-chevron {
  transform: rotate(90deg);
  color: var(--text-muted);
  opacity: 0.5;
  flex-shrink: 0;
  transition: color 0.18s ease;
}

.chapter-link:hover .chapter-chevron {
  color: var(--text-main);
}

/* ── Interactive blocks ── */
.interactive-block {
  margin: 28px 0 32px;
  background: rgba(51, 64, 79, 0.025);
  border: 1px solid rgba(51, 64, 79, 0.1);
  border-radius: 8px;
  padding: 20px 22px 22px;
}

.interactive-block-title {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.interactive-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  margin-bottom: 16px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.control-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  min-width: 40px;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

.control-group input[type="range"] {
  width: 100px;
  accent-color: var(--text-main);
  cursor: pointer;
}

.interactive-canvas-wrap {
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(51, 64, 79, 0.018);
}

.interactive-canvas-wrap canvas {
  width: 100%;
  display: block;
}

.interactive-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  margin-bottom: 0;
  text-align: left;
}

/* ── Strategy explorer chips ── */
.strategy-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.strategy-chip {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid rgba(51, 64, 79, 0.2);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.strategy-chip:hover,
.strategy-chip.active {
  background: rgba(51, 64, 79, 0.08);
  color: var(--text-main);
  border-color: rgba(51, 64, 79, 0.35);
}

.strategy-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  padding-top: 14px;
  border-top: 1px solid rgba(51, 64, 79, 0.09);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 13px;
  color: var(--text-main);
}

/* ── Merger arb result ── */
.merger-result {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(51, 64, 79, 0.09);
  margin-top: 2px;
}

.merger-result-label {
  font-size: 13px;
  color: var(--text-muted);
}

.merger-result-val {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  transition: color 0.2s ease;
}

/* ── Code blocks ── */
.code-block {
  background: rgba(51, 64, 79, 0.04);
  border: 1px solid rgba(51, 64, 79, 0.1);
  border-radius: 6px;
  padding: 16px 18px;
  margin: 14px 0 18px;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Menlo, Monaco, monospace;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text-main);
  overflow-x: auto;
  white-space: pre;
}

.code-comment {
  color: var(--text-muted);
}

/* ── Exercise callouts ── */
.exercise-callout {
  background: rgba(51, 64, 79, 0.03);
  border: 1px solid rgba(51, 64, 79, 0.1);
  border-radius: 6px;
  padding: 14px 16px 10px;
  margin: 18px 0 22px;
}

.exercise-callout-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.exercise-callout p {
  margin-bottom: 8px;
  font-size: 13.5px;
}

.exercise-callout p:last-child {
  margin-bottom: 0;
}

/* ── Z-score bar visualization ── */
.zscore-bar-wrap {
  margin: 2px 0 14px;
}

.zscore-bar {
  height: 5px;
  background: linear-gradient(to right,
    rgba(51,64,79,0.22) 0%, rgba(51,64,79,0.22) 16.67%,
    rgba(51,64,79,0.07) 16.67%, rgba(51,64,79,0.07) 83.33%,
    rgba(51,64,79,0.22) 83.33%, rgba(51,64,79,0.22) 100%
  );
  border-radius: 3px;
  position: relative;
  margin-bottom: 8px;
}

.zscore-needle {
  position: absolute;
  top: -5px;
  width: 2px;
  height: 15px;
  background: var(--text-main);
  border-radius: 1px;
  transform: translateX(-50%);
  transition: left 0.1s ease;
}

.zscore-tick-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}

.zscore-signal-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(51,64,79,0.09);
}

.zscore-signal-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.zscore-signal-val {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

/* ── Stat grid (2×2 key numbers) ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: rgba(51,64,79,0.1);
  border: 1px solid rgba(51,64,79,0.1);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 4px;
}

.stat-item {
  background: var(--bg-color);
  padding: 12px 14px;
}

.stat-item.stat-highlight {
  background: rgba(51,64,79,0.03);
}

.stat-item-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 5px;
}

.stat-item-val {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

/* ── Scenario grid (3-col comparison table) ── */
.scenario-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: rgba(51,64,79,0.1);
  border: 1px solid rgba(51,64,79,0.1);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 14px;
}

.scenario-item {
  background: var(--bg-color);
  padding: 12px 10px;
  text-align: center;
}

.scenario-item.scenario-current {
  background: rgba(51,64,79,0.03);
}

.scenario-rho {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-bottom: 5px;
}

.scenario-sig {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  margin-bottom: 3px;
}

.scenario-sub {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Heading flash on subchapter click ── */
@keyframes headingFlash {
  0%   { color: var(--text-muted); }
  25%  { color: var(--text-main);  }
  100% { color: var(--text-main);  }
}

.section-heading.heading-flash {
  animation: headingFlash 0.7s ease-out forwards;
}

/* ─────────────────────────────────────────────────────────────────
   MOBILE  ( ≤ 640 px )
   ─────────────────────────────────────────────────────────────────
   Key changes vs desktop:
   • body stops flex-centering — content flows from the top
   • generous padding (52 / 24) for easy reading
   • social links become pill badges that wrap naturally
   • section labels shift to small-caps uppercase labels
   • item-list becomes a clean border-separated list
     with a left-accent stripe on tap / hover
   ───────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  html {
    overflow-x: hidden;
  }

  body {
    display: block;
    min-height: 100vh;
    overflow-x: hidden;
  }

  body.page-secondary {
    padding-top: 0;
  }

  .container {
    padding: 52px 24px 72px;
    max-width: 100%;
  }

  /* ── Typography ── */
  h1 {
    font-size: 22px;
    letter-spacing: -0.3px;
    margin-bottom: 18px;
  }

  p {
    text-align: justify;
    font-size: 15px;
    line-height: 1.75;
    margin-bottom: 16px;
  }

  /* ── Social links → pill badges ── */
  .social-links {
    flex-wrap: wrap;
    gap: 8px 10px;
    margin: 20px 0 44px;
    font-size: 13px;
  }

  .social-link {
    background: var(--accent-color);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 500;
    gap: 5px;
    color: var(--text-muted);
    transition: background 0.2s ease, color 0.2s ease;
  }

  .social-link:hover,
  .social-link:active {
    background: rgba(51, 64, 79, 0.18);
    color: var(--text-main);
  }

  .social-arrow {
    font-size: 13px;
  }

  /* ── Sections ── */
  .section {
    margin-bottom: 40px;
  }

  .section-header {
    margin-bottom: 12px;
    align-items: center;
  }

  /* Small-caps label style for section titles on mobile */
  .section-title {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .see-more {
    font-size: 13px;
  }

  /* ── Item list → bordered strip layout ── */
  .item-list {
    gap: 0;
    border-top: 1px solid var(--border-color);
  }

  .item {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2px;
    padding: 13px 0 13px 16px;
    border-bottom: 1px solid var(--border-color);
    border-left: 2.5px solid transparent;
    transition: border-color 0.18s ease;
  }

  .item-link:hover,
  .item-link:active {
    opacity: 1;
    border-left-color: var(--text-muted);
  }

  .item-title {
    font-size: 15px;
    line-height: 1.4;
  }

  .item-desc {
    font-size: 12.5px;
    color: var(--text-muted);
  }

  /* ── Back link ── */
  .back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 28px;
  }

  /* ── Page header ── */
  .page-header {
    margin-bottom: 28px;
  }

  .page-title {
    font-size: 22px;
    letter-spacing: -0.3px;
    margin-bottom: 8px;
  }

  .page-desc {
    text-align: left;
    font-size: 14px;
    line-height: 1.65;
  }

  /* ── Coming soon ── */
  .coming-soon-container {
    padding: 32px 0;
  }

  .coming-soon-title {
    font-size: 15px;
  }

  .coming-soon-desc {
    text-align: left;
    font-size: 14px;
    line-height: 1.65;
  }

  /* ── Research pages on mobile ── */
  .research-container {
    max-width: 100%;
    padding: 40px 20px 72px;
  }

  .research-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .research-content {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  /* Sidebar stacks above content */
  .research-nav {
    width: 100%;
    position: static;
    margin-bottom: 28px;
  }

  .research-nav .back-link {
    margin-bottom: 18px;
  }

  /* Full-width tap target for chapter toggles */
  .chapter-toggle {
    width: 100%;
    justify-content: space-between;
    padding: 4px 0;
    margin-bottom: 6px;
  }

  /* Keep subchapter list vertical, just remove the sidebar line */
  .subchapter-list {
    padding-left: 10px;
    border-left: none;
    border-top: none;
    padding-top: 0;
    transform: translateY(-4px);
  }

  .subchapter-list li {
    margin-bottom: 10px;
  }

  .subchapter-link {
    font-size: 13px;
  }

  .nav-divider {
    margin: 16px 0;
  }

  .research-title {
    font-size: 18px;
    letter-spacing: -0.2px;
  }

  .research-meta {
    font-size: 13px;
    margin-bottom: 28px;
  }

  .research-section {
    margin-bottom: 40px;
    scroll-margin-top: 20px;
  }

  .section-heading {
    font-size: 15px;
    margin-bottom: 12px;
  }

  .strategy-heading {
    font-size: 14px;
    margin: 22px 0 8px;
  }

  .equation {
    font-size: 12px;
    padding: 11px 14px;
    line-height: 1.9;
  }

  /* Interactive blocks: stack controls vertically, full-width sliders */
  .interactive-block {
    padding: 14px 14px 16px;
    margin: 20px 0 24px;
  }

  .interactive-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .control-group {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 8px;
    align-items: center;
  }

  .control-label {
    grid-column: 1;
    grid-row: 1;
    font-size: 12px;
  }

  .control-val {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    min-width: 44px;
  }

  .control-group input[type="range"] {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 100%;
  }

  .strategy-detail-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .code-block {
    font-size: 11.5px;
    padding: 12px 14px;
    line-height: 1.7;
  }

  .exercise-callout {
    padding: 12px 14px 8px;
  }

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

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

  .stat-item-val,
  .scenario-sig {
    font-size: 16px;
  }

  /* Z-score signal text wraps on narrow screens */
  .zscore-signal-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .zscore-signal-val {
    flex: 1;
    min-width: 0;
  }

  /* Merger result value */
  .merger-result-val {
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .subchapter-list {
    transition: none;
    transform: none;
    max-height: none;
    opacity: 1;
    visibility: visible;
  }
}

