/* ============ RESET & BASE ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --bg-alt: #1a2332;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============ LAYOUT ============ */
.container { max-width: 1100px; margin: 0 auto; }
.section { padding: 80px 24px; }
.section-alt { background: var(--bg-alt); }

/* ============ TYPOGRAPHY ============ */
.section-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}
.section-desc {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 720px;
  margin-bottom: 20px;
  line-height: 1.7;
}
.section-desc strong { color: var(--text); }
.muted { color: var(--text-muted); font-size: 0.9rem; }
code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ============ HERO ============ */
#hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  position: relative;
  background: radial-gradient(ellipse at 50% 30%, rgba(59,130,246,0.08) 0%, transparent 70%);
}
.hero-content { max-width: 700px; }
#hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}
.hero-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 48px;
  line-height: 1.7;
}
.hero-stat { margin-bottom: 48px; }
.spread-number {
  font-size: clamp(4rem, 10vw, 7rem);
  font-weight: 900;
  background: linear-gradient(135deg, #3b82f6, #ef4444);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline;
  line-height: 1.1;
}
.spread-x {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ef4444, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-stat-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: 8px;
}
.scroll-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  animation: bounce 2s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(8px); }
}

/* ============ BUBBLE CHART ============ */
.chart-wrapper { margin: 32px 0 16px; }
#bubble-chart { width: 100%; min-height: 420px; position: relative; }
#bubble-chart svg { width: 100%; height: 100%; }

.bubble-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15,23,42,0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 280px;
}
.bubble-tooltip.visible { opacity: 1; }
.bubble-tooltip strong { color: var(--text); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  justify-content: center;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============ CALCULATOR ============ */
.calc-grid {
  display: flex;
  align-items: stretch;
  gap: 20px;
  margin: 32px 0 24px;
}
.calc-card {
  flex: 1;
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid var(--border);
}
.calc-card label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.calc-card select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  margin-bottom: 16px;
}
.calc-vs {
  display: flex;
  align-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 4px;
}
.calc-impact { position: relative; }
.calc-bar {
  height: 32px;
  border-radius: 6px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.calc-value {
  display: block;
  margin-top: 8px;
  font-size: 1.4rem;
  font-weight: 700;
}
.calc-comparison {
  text-align: center;
  font-size: 1.2rem;
  padding: 20px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.calc-comparison strong {
  color: #f59e0b;
  font-size: 1.4rem;
}

/* ============ BAR CHART ============ */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
}
.toggle-label { color: var(--text-muted); font-size: 0.9rem; }
#bar-chart-canvas { width: 100% !important; }

/* ============ BUTTONS ============ */
.btn {
  padding: 10px 24px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary.active { background: #22c55e; }

/* ============ DATA TABLE ============ */
.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--text-muted); color: var(--text); }
.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.search-input {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 200px;
  margin-left: auto;
}
.search-input::placeholder { color: var(--text-muted); }
.table-scroll { overflow-x: auto; }

#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
#data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  color: var(--text-muted);
  transition: color 0.15s;
}
#data-table th:hover { color: var(--text); }
#data-table th.sorted { color: var(--primary); }
#data-table th .sort-arrow { margin-left: 4px; font-size: 0.7rem; }
#data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(51,65,85,0.5);
  white-space: nowrap;
}
#data-table tbody tr { transition: background 0.1s; }
#data-table tbody tr:hover { background: rgba(59,130,246,0.08); }

.section-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: white;
}

/* ============ FIXED CONTROLS BAR ============ */
.sticky-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 0 24px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  pointer-events: none;
}
.sticky-controls.visible {
  transform: translateY(0);
  pointer-events: auto;
}
.sticky-inner {
  max-width: 1100px;
  margin: 0 auto;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 10px 20px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}
.ctrl-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.ctrl-val {
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
  min-width: 32px;
}
.ctrl-group select {
  padding: 4px 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.82rem;
}
.ctrl-group input[type="range"] {
  width: 90px;
  accent-color: var(--primary);
}
.ctrl-stats {
  margin-left: auto;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.ctrl-stats strong { color: var(--text); }

.hidden { display: none; }

/* Space at bottom of page so content isn't hidden behind fixed bar */
body { padding-bottom: 64px; }

@media (max-width: 700px) {
  .controls-row { gap: 8px; flex-wrap: wrap; }
  .ctrl-stats { margin-left: 0; width: 100%; }
  .ctrl-group input[type="range"] { width: 60px; }
}

/* ============ MATT'S BUCKETS ============ */
.bucket-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 24px 0;
}
.bucket-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px 14px;
  text-align: center;
  border: 1px solid var(--border);
  border-top: 4px solid transparent;
}
.bucket-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.bucket-range {
  font-size: 0.85rem;
  font-weight: 600;
}
.bucket-range-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.bucket-factor {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 6px;
}
.bucket-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.rationale-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid var(--border);
  margin-top: 24px;
}
.rationale-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.rationale-card p {
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.6;
}
.rationale-card p:last-child { margin-bottom: 0; }
.rationale-card strong { color: var(--text); }
.matt-action { text-align: center; margin-top: 28px; }
.btn-primary.matt-active { background: #22c55e; }

/* Disabled controls in Matt mode */
.ctrl-group input:disabled, .ctrl-group select:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ============ METHODOLOGY ============ */
.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 24px 0;
}
.method-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}
.method-card h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 8px; }
.method-card p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; }
.method-card strong { color: var(--text); }
.download-row { text-align: center; margin-top: 24px; }

/* ============ FOOTER ============ */
footer {
  text-align: center;
  padding: 32px 24px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ============ RESPONSIVE ============ */
@media (max-width: 700px) {
  .calc-grid { flex-direction: column; }
  .calc-vs { justify-content: center; padding: 4px 0; }
  .sim-results { flex-direction: column; }
  .sim-arrow { transform: rotate(90deg); }
  .section { padding: 48px 16px; }
  .section-title { font-size: 1.5rem; }
  .section-desc { font-size: 1rem; }
  .table-controls { flex-direction: column; align-items: stretch; }
  .search-input { margin-left: 0; }
}
