:root {
  --bg: #0e0d0b;
  --bg-card: #171512;
  --bg-card-hover: #1f1c18;
  --bg-subtle: #1a1814;
  --ink: #f2ece1;
  --ink-soft: #a89f91;
  --ink-muted: #6e665a;
  --gold: #d4a34b;
  --gold-glow: rgba(212, 163, 75, 0.18);
  --gold-dim: #8c6a2e;
  --crimson: #df5842;
  --crimson-glow: rgba(223, 88, 66, 0.2);
  --teal: #38bdf8;
  --teal-dim: #0369a1;
  --border: rgba(242, 236, 225, 0.1);
  --border-strong: rgba(242, 236, 225, 0.22);
  
  --font-serif: "Newsreader", "Charter", "Georgia", serif;
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

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

html {
  font-size: 16px;
  background-color: var(--bg);
  color: var(--ink);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--bg);
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(212, 163, 75, 0.06) 0%, transparent 60%),
    radial-gradient(circle at 10% 40%, rgba(223, 88, 66, 0.03) 0%, transparent 40%);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Accessibility */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.visually-hidden:focus {
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: auto;
  height: auto;
  padding: 0.75rem 1.25rem;
  background: var(--gold);
  color: #000;
  font-family: var(--font-sans);
  font-weight: 700;
  z-index: 1000;
  clip: auto;
  border-radius: 4px;
}

/* Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.brand {
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: color 0.2s;
}

.brand:hover {
  color: var(--gold);
}

.langsw {
  color: var(--ink-muted);
}

.langsw a {
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  transition: all 0.2s;
}

.langsw a[aria-current="page"] {
  color: var(--gold);
  background: var(--gold-glow);
}

.langsw a:hover:not([aria-current="page"]) {
  color: var(--ink);
}

/* Shell Layouts */
.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.shell-wide {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Typography & Content */
.hero {
  padding: 4.5rem 0 3rem;
  text-align: left;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 1rem;
  display: inline-block;
  border-bottom: 1px solid var(--gold-dim);
  padding-bottom: 0.25rem;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  font-weight: 500;
  line-height: 1.15;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}

.standfirst {
  font-size: clamp(1.2rem, 2.4vw, 1.4rem);
  line-height: 1.6;
  color: var(--ink-soft);
  margin-bottom: 2.5rem;
  font-style: italic;
  font-weight: 300;
}

/* Ledgerline - Key Stats Bar */
.ledgerline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin: 2.5rem 0;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.ledger-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ledger-num {
  font-family: var(--font-mono);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}

.ledger-item:nth-child(2) .ledger-num {
  color: var(--teal);
}

.ledger-item:nth-child(3) .ledger-num {
  color: var(--crimson);
}

.ledger-item:nth-child(4) .ledger-num {
  color: var(--ink);
}

.ledger-lbl {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

/* Prose Sections */
.prose {
  margin: 2.5rem 0;
}

.prose h2 {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 3.5vw, 2.2rem);
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink);
  margin: 3rem 0 1.25rem;
  letter-spacing: -0.01em;
}

.prose p {
  margin-bottom: 1.4rem;
  color: var(--ink);
}

.prose strong {
  color: #fff;
  font-weight: 600;
}

.prose em {
  color: var(--gold);
  font-style: italic;
}

/* Spindle & Interactive Instrument */
.instrument-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 2rem;
  margin: 3rem 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.instrument-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.instrument-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--ink);
}

.instrument-subtitle {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Preset Epoch Buttons */
.presets-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.75rem;
}

.preset-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-btn:hover {
  background: var(--bg-card-hover);
  color: var(--ink);
  border-color: var(--gold-dim);
}

.preset-btn.active {
  background: var(--gold-glow);
  color: var(--gold);
  border-color: var(--gold);
}

/* Control Row */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
  background: var(--bg-subtle);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

@media (max-width: 700px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-label {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
}

.control-value-badge {
  font-family: var(--font-mono);
  color: var(--gold);
  font-size: 0.9rem;
}

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  background: #2a2620;
  border-radius: 4px;
  outline: none;
  margin: 0.5rem 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(212, 163, 75, 0.5);
  border: 2px solid #000;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(212, 163, 75, 0.5);
  border: 2px solid #000;
}

/* Segmented Buttons for Mobility */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: #100f0d;
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.segmented-control button {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.5rem 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.segmented-control button:hover {
  color: var(--ink);
}

.segmented-control button.active {
  background: var(--bg-card);
  color: var(--gold);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Visualizer Container & SVG */
.visualizer-wrapper {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 960px) {
  .visualizer-wrapper {
    grid-template-columns: 1fr;
  }
}

.canvas-container {
  background: #090807;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  position: relative;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spindle-svg {
  width: 100%;
  height: 440px;
  overflow: visible;
}

/* Live Analytics Panel */
.stats-readout {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.readout-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.15rem;
}

.readout-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
}

.readout-val {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.readout-val.gold { color: var(--gold); }
.readout-val.crimson { color: var(--crimson); }
.readout-val.teal { color: var(--teal); }

.readout-desc {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.35rem;
  line-height: 1.35;
}

/* Progress bar inside readout */
.collapse-meter {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.collapse-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--crimson));
  width: 0%;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Legend */
.spindle-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--ink-soft);
  justify-content: center;
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.gold { background: var(--gold); }
.legend-dot.crimson { background: var(--crimson); }
.legend-dot.teal { background: var(--teal); }

/* Static Fallback Table (No-JS / Accessible) */
.data-table-container {
  overflow-x: auto;
  margin: 2.5rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.data-table tr:hover {
  background: var(--bg-subtle);
}

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

/* Methodology & Footer */
.methodology {
  border-top: 1px solid var(--border);
  padding: 3rem 0;
  margin-top: 4rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.methodology h3 {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 1.25rem;
}

.methodology p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

.sources-list {
  list-style: none;
  margin: 1.5rem 0;
}

.sources-list li {
  margin-bottom: 0.75rem;
  padding-left: 1rem;
  border-left: 2px solid var(--gold-dim);
  font-size: 0.85rem;
}

.sources-list a {
  color: var(--gold);
  text-decoration: none;
}

.sources-list a:hover {
  text-decoration: underline;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 2.5rem 0;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.site-footer a {
  color: var(--ink-soft);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--gold);
}

/* Back to Top Button */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  z-index: 90;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: var(--gold);
  color: #000;
  transform: translateY(-2px);
}

.back-to-top svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
