:root {
  --bg-page: #f8f7f4;
  --bg-surface: #ffffff;
  --bg-subtle: #f1efe9;
  --bg-hover: #eae6dd;

  --text-primary: #17191e;
  --text-secondary: #464b56;
  --text-muted: #6c7280;

  --border-light: #e4e1d8;
  --border-strong: #c8c3b7;

  --c-control: #0a1f4d;
  --c-nonaprax: #1976d2;
  --c-aprax: #d32f2f;

  --fam-hand: #882255;
  --fam-hand-bg: #f9eef3;
  --fam-arm: #b87700;
  --fam-arm-bar: #e69f00;
  --fam-arm-bg: #fdf6e7;
  --fam-amp: #237c6d;
  --fam-amp-bar: #44aa99;
  --fam-amp-bg: #ecf7f5;
  --fam-mot: #5f6069;
  --fam-mot-bar: #7a7a84;
  --fam-mot-bg: #f1f1f3;

  --c-item: #7e6fb2;
  --c-positive: #1b6e44;
  --c-negative: #b92b27;

  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.035), 0 3px 10px rgba(20, 24, 33, 0.025);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.58;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "tnum";
}

.container {
  max-width: 1240px;
  margin: 0 auto;
}

/* Editorial Header */
.site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  padding: 3rem 1.5rem 2.25rem;
}

.site-header h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: clamp(1.9rem, 3.3vw, 2.7rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 0.85rem;
  max-width: 920px;
  color: var(--text-primary);
}

.authors-line {
  font-size: 0.96rem;
  color: var(--text-primary);
  margin: 0 0 0.35rem;
  font-weight: 500;
}

.affils-details {
  font-size: 0.81rem;
  color: var(--text-muted);
  margin: 0 0 1.25rem;
}

.affils-details summary {
  cursor: pointer;
  user-select: none;
  display: inline-block;
  color: var(--text-secondary);
}

.affils-details summary:hover {
  color: var(--text-primary);
}

.affils-list {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
  line-height: 1.5;
}

.lead-summary {
  max-width: 800px;
  font-size: 1.04rem;
  color: var(--text-secondary);
  margin: 0 0 1.35rem;
  line-height: 1.62;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.48rem 0.92rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  font-family: var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: #9e988c;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--c-control);
  border-color: var(--c-control);
  color: #ffffff;
}

.btn-primary:hover {
  background: #143273;
  border-color: #143273;
}

.btn-sm {
  padding: 0.3rem 0.62rem;
  font-size: 0.76rem;
}

/* Sticky Navigation */
.sticky-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(248, 247, 244, 0.93);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-light);
}

.nav-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  overflow-x: auto;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  padding: 0.38rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-link:hover,
.nav-link.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.compute-status {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Narrative Sections */
main {
  padding: 2.25rem 1.5rem 4rem;
}

.section-block {
  margin-bottom: 3.5rem;
  scroll-margin-top: 4.2rem;
}

.chapter-kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.section-head {
  margin-bottom: 1.15rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.section-head h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.65rem;
  letter-spacing: -0.015em;
  margin: 0 0 0.3rem;
  color: var(--text-primary);
}

.section-prose {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 790px;
  line-height: 1.6;
}

.surface-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}

/* Compact Architecture Diagram Strip */
.pipeline-strip {
  display: grid;
  grid-template-columns: 1fr auto 1.35fr auto 1fr;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 1.25rem;
}

@media (max-width: 920px) {
  .pipeline-strip {
    grid-template-columns: 1fr;
  }
  .pipeline-arrow {
    display: none;
  }
}

.pipeline-step {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.pipeline-step-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.pipeline-step-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.pipeline-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

@media (max-width: 600px) {
  .pipeline-dual {
    grid-template-columns: 1fr;
  }
}

.pipeline-subbox {
  background: var(--bg-page);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}

.pipeline-arrow {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  font-size: 1.15rem;
  font-family: var(--font-mono);
}

/* Presets & Chips */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
  align-items: center;
}

.preset-label {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-right: 0.2rem;
}

.preset-chip {
  padding: 0.35rem 0.72rem;
  border-radius: 999px;
  font-size: 0.79rem;
  font-weight: 500;
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.13s ease;
}

.preset-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.preset-chip.active {
  background: var(--c-control);
  border-color: var(--c-control);
  color: #ffffff;
}

/* Sandbox Layout */
.sandbox-layout {
  display: grid;
  grid-template-columns: 375px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1040px) {
  .sandbox-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.controls-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-group-title {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.55rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  gap: 2px;
}

.segmented.segmented-2 {
  grid-template-columns: repeat(2, 1fr);
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 0.42rem 0.3rem;
  font-size: 0.77rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.13s ease;
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.slider-row {
  margin-top: 0.85rem;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--c-control);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--c-control);
  cursor: pointer;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.08rem;
}

.adv-details {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.78rem;
}

.adv-details summary {
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  user-select: none;
}

.adv-details summary:hover {
  color: var(--text-primary);
}

/* Feature & Tool Selector */
.selector-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 0.7rem;
  gap: 0.85rem;
}

.sel-tab {
  border: none;
  background: none;
  padding: 0.4rem 0.15rem;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.sel-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--c-control);
}

.search-input {
  width: 100%;
  padding: 0.42rem 0.65rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.81rem;
  font-family: var(--font-sans);
  background: var(--bg-page);
  margin-bottom: 0.6rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--c-control);
  background: var(--bg-surface);
}

.family-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.fam-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.24rem 0.52rem;
  border-radius: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--border-light);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.14s ease;
}

.fam-toggle.off {
  opacity: 0.4;
}

.fam-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.scroll-list {
  max-height: 390px;
  overflow-y: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  padding: 0.28rem;
}

.feat-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 62px;
  align-items: center;
  gap: 0.45rem;
  padding: 0.34rem 0.42rem;
  border-radius: 5px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.1s ease;
}

.feat-item:hover {
  background: var(--bg-surface);
}

.feat-item input[type="checkbox"] {
  margin: 0;
  accent-color: var(--c-control);
  cursor: pointer;
}

.feat-name-wrap {
  min-width: 0;
}

.feat-name {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  min-width: 0;
  font-weight: 500;
}

.feat-title-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.badge-top8 {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 0.04rem 0.3rem;
  border-radius: 3px;
  background: #ede9f6;
  color: #483575;
  font-weight: 600;
  flex-shrink: 0;
}

.feat-bar-track {
  height: 3.5px;
  background: #e5e2da;
  border-radius: 2px;
  margin-top: 3px;
  overflow: hidden;
}

.feat-bar-fill {
  height: 100%;
  border-radius: 2px;
}

.feat-weight-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-align: right;
  color: var(--text-secondary);
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 1rem;
}

@media (max-width: 820px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.8rem 0.9rem;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  margin-top: 0.22rem;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.42rem;
  font-weight: 600;
  color: var(--text-primary);
}

.kpi-delta {
  font-family: var(--font-mono);
  font-size: 0.71rem;
  font-weight: 600;
  padding: 0.08rem 0.32rem;
  border-radius: 4px;
}

.kpi-delta.neutral {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.kpi-delta.good {
  background: #e6f4ec;
  color: var(--c-positive);
}

.kpi-delta.warn {
  background: #fdeceb;
  color: var(--c-negative);
}

.kpi-sub {
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 0.16rem;
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1rem;
}

@media (max-width: 900px) {
  .charts-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 0 0 0.65rem;
}

.svg-wrap {
  width: 100%;
  position: relative;
}

.svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.legend-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.legend-swatch {
  width: 9.5px;
  height: 9.5px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.3);
}

/* Participant Inspector */
.inspector-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.2rem;
}

@media (max-width: 960px) {
  .inspector-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.participant-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  border: 1px solid var(--border-light);
}

.participant-bar > div {
  min-width: 0;
  max-width: 100%;
}

.select-box {
  padding: 0.38rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  font-family: var(--font-sans);
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 100%;
}

.part-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.part-stat {
  background: var(--bg-surface);
  padding: 0.28rem 0.62rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.part-stat strong {
  font-family: var(--font-mono);
}

/* 3D Viewer */
.traces-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.traces-3col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

@media (max-width: 900px) {
  .traces-3col {
    grid-template-columns: minmax(0, 1fr);
  }
}

.trace-col-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  background: var(--bg-page);
}

.trace-col-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.trace-canvas {
  width: 100%;
  height: 235px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: grab;
  display: block;
}

.trace-canvas:active {
  cursor: grabbing;
}

.scrub-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.9rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

/* Tool Atlas */
.atlas-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
}

@media (max-width: 1040px) {
  .atlas-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.table-scroll {
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.atlas-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.atlas-table th {
  position: sticky;
  top: 0;
  background: var(--bg-subtle);
  text-align: left;
  padding: 0.55rem 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.atlas-table td {
  padding: 0.48rem 0.65rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.atlas-table tr:hover td {
  background: var(--bg-page);
}

.num-col {
  font-family: var(--font-mono);
  text-align: right;
}

/* Collapsible Figures & Code Footer Section */
.figures-drawer {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.figures-drawer > summary {
  padding: 1rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  user-select: none;
}

.figures-drawer > summary::-webkit-details-marker {
  display: none;
}

.figures-drawer-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border-light);
}

.fig-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 1rem 0;
}

.fig-viewer {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  text-align: center;
}

.fig-viewer img {
  max-width: 100%;
  height: auto;
  max-height: 800px;
  object-fit: contain;
}

.code-card {
  background: #181a1f;
  color: #f1efe9;
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
  margin-top: 1rem;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  background: rgba(23, 25, 30, 0.95);
  color: #ffffff;
  padding: 0.52rem 0.72rem;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  line-height: 1.45;
  max-width: 300px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.site-footer {
  border-top: 1px solid var(--border-light);
  padding: 1.75rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.81rem;
  background: var(--bg-surface);
}
