:root {
    --cs-sand: #f5f0e8;
    --cs-cream: #faf7f2;
    --cs-warm-white: #fefcf9;
    --cs-earth: #3d3229;
    --cs-earth-mid: #6b5d50;
    --cs-earth-light: #9a8d80;
    --cs-clay: #c4a882;
    --cs-terracotta: #c45d3e;
    --cs-forest: #2d6a4f;
    --cs-forest-light: #52b788;
    --cs-ocean: #1b6b93;
    --cs-ocean-light: #4da8c4;
    --cs-amber: #d4860b;
    --cs-rose: #b5485d;
    --cs-accent: #c45d3e;
  }

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

  .cs-wrapper {
    background: var(--cs-cream);
    background-image:
      radial-gradient(ellipse at 20% 0%, rgba(196,93,62,0.04) 0%, transparent 60%),
      radial-gradient(ellipse at 80% 100%, rgba(45,106,79,0.04) 0%, transparent 60%);
    color: var(--cs-earth);
    font-family: 'Source Sans 3', sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
  }

  /* ── Subtle texture overlay ── */
  /* .cs-wrapper::before {
    content: '';
    position: fixed; inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.015'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
  } */

  #cs-header {
    text-align: center;
    padding: 36px 20px 6px;
    position: relative;
    z-index: 1;
  }
  #cs-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(24px, 4vw, 44px);
    font-weight: 900;
    color: var(--cs-earth);
    letter-spacing: -0.5px;
    line-height: 1.1;
  }
  #cs-header h1 em {
    font-style: italic;
    color: var(--cs-terracotta);
    font-weight: 400;
  }
  #cs-header p {
    font-family: 'Source Sans 3', sans-serif;
    font-size: 14px;
    font-weight: 300;
    color: var(--cs-earth-light);
    margin-top: 8px;
    max-width: 560px;
    margin-left: auto; margin-right: auto;
    line-height: 1.5;
  }

  /* ── Metric toggle ── */
  #cs-metric-toggle {
    display: flex;
    justify-content: center;
    padding: 14px 20px 4px;
    gap: 0;
    position: relative;
    z-index: 1;
  }
  .cs-metric-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 8px 22px;
    border: 1.5px solid var(--cs-clay);
    background: transparent;
    color: var(--cs-earth-light);
    cursor: pointer;
    transition: all 0.3s;
  }
  .cs-metric-btn:first-child { border-radius: 20px 0 0 20px; border-right: none; }
  .cs-metric-btn:last-child  { border-radius: 0 20px 20px 0; }
  .cs-metric-btn.active {
    background: var(--cs-earth);
    color: var(--cs-cream);
    border-color: var(--cs-earth);
  }
  .cs-metric-btn:hover:not(.active) {
    background: rgba(61,50,41,0.06);
  }

  /* ── Controls — see css/timeline_slider.css for .tl-* rules ── */

  /* ── Legend ── */
  #cs-legend {
    display: flex;
    justify-content: center;
    gap: 18px;
    padding: 8px 20px 30px;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
  }
  .cs-legend-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 11px;
    font-weight: 400;
    color: var(--cs-earth-light);
    letter-spacing: 0.2px;
  }
  .cs-legend-dot {
    width: 10px; height: 10px; border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  }

  /* ── Viz ── */
  #cs-viz-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    z-index: 1;
  }
  #cs-viz { display: block; width: 100%; }

  /* ── Tooltip ── */
  #cs-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--cs-warm-white);
    border: 1px solid rgba(61,50,41,0.12);
    border-radius: 10px;
    padding: 14px 18px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 500;
    max-width: 260px;
    box-shadow: 0 4px 20px rgba(61,50,41,0.1), 0 1px 3px rgba(61,50,41,0.06);
  }
  #cs-tooltip .cs-tt-name {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 6px;
    color: var(--cs-earth);
  }
  #cs-tooltip .cs-tt-row { margin: 3px 0; color: var(--cs-earth-light); }
  #cs-tooltip .cs-tt-val { color: var(--cs-earth); font-weight: 600; }
  #cs-tooltip .cs-tt-click {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(61,50,41,0.08);
    color: var(--cs-terracotta);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
  }

  /* ── Detail panel ── */
  #cs-detail-overlay {
    position: fixed; inset: 0;
    background: rgba(61,50,41,0.2);
    backdrop-filter: blur(4px);
    z-index: 600;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
  }
  #cs-detail-overlay.open { opacity: 1; pointer-events: all; }

  #cs-detail-panel {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: min(480px, 92vw);
    max-height: 90vh;
    background: var(--cs-warm-white);
    border: 1px solid rgba(61,50,41,0.1);
    border-radius: 16px;
    z-index: 700;
    padding: 32px;
    opacity: 0; pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(61,50,41,0.12), 0 2px 8px rgba(61,50,41,0.06);
  }
  #cs-detail-panel.open {
    opacity: 1; pointer-events: all;
    transform: translate(-50%, -50%) scale(1);
  }
  #cs-detail-panel .cs-close-btn {
    position: absolute; top: 16px; right: 16px;
    background: none; border: none;
    color: var(--cs-earth-light); font-size: 22px; cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
  }
  #cs-detail-panel .cs-close-btn:hover { color: var(--cs-earth); }
  #cs-detail-panel h2 {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 2px;
  }
  .cs-detail-sub {
    color: var(--cs-earth-light);
    font-size: 13px;
    font-weight: 300;
    margin-bottom: 10px;
  }
  #cs-detail-metric-toggle {
    display: flex; gap: 0; margin-bottom: 16px;
  }
  .cs-detail-mbtn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px; font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 5px 14px;
    border: 1.5px solid var(--cs-clay);
    background: transparent;
    color: var(--cs-earth-light); cursor: pointer; transition: all 0.2s;
  }
  .cs-detail-mbtn:first-child { border-radius: 14px 0 0 14px; border-right: none; }
  .cs-detail-mbtn:last-child  { border-radius: 0 14px 14px 0; }
  .cs-detail-mbtn.active {
    background: var(--cs-earth); color: var(--cs-cream);
    border-color: var(--cs-earth);
  }
  #cs-detail-chart { width: 100%; }
