/* ─── Tokens ─────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #F9FAFB;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --border-2:     #D1D5DB;
  --text:         #111827;
  --text-muted:   #6B7280;
  --text-subtle:  #9CA3AF;
  --red:          #EF4444;
  --red-bg:       #FEF2F2;
  --blue:         #3B82F6;
  --blue-bg:      #EFF6FF;
  --green:        #22C55E;
  --green-bg:     #F0FDF4;
  --indigo:       #6366F1;
  --indigo-bg:    #EEF2FF;
  --amber:        #F59E0B;
  --amber-bg:     #FFFBEB;
  --radius:       10px;
  --radius-sm:    7px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 4px 12px rgba(0,0,0,0.07);
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  display: flex;
  align-items: flex-start;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-icon { font-size: 1.6rem; flex-shrink: 0; margin-top: 2px; }

.header-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-text p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 640px;
  line-height: 1.5;
}

/* ─── About Banner ───────────────────────────────────────────────────────────── */

.about-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 28px;
}

.about-grid {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 28px;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}

.about-divider { background: var(--border); }

.about-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  margin-bottom: 8px;
  display: block;
}

.about-text {
  font-size: 0.79rem;
  color: var(--text-muted);
  line-height: 1.75;
}

.about-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.about-list li {
  font-size: 0.77rem;
  color: var(--text-muted);
  line-height: 1.55;
  padding-left: 14px;
  position: relative;
}

.about-list li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--text-subtle);
  font-size: 0.7rem;
  top: 1px;
}

.about-list strong { color: var(--text); font-weight: 600; }

/* ─── App Body ───────────────────────────────────────────────────────────────── */

.app-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}

/* ─── Controls Panel ─────────────────────────────────────────────────────────── */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: sticky;
  top: 74px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.controls-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  margin-bottom: 14px;
}

/* ─── Wheel ──────────────────────────────────────────────────────────────────── */

.wheel-wrapper {
  text-align: center;
  padding: 4px 0 16px;
}

.wheel-disc {
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 3px solid var(--indigo);
  background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12), var(--shadow);
  transition: box-shadow 0.2s;
}

.wheel-disc.spinning {
  animation: wheelSpin 1.1s cubic-bezier(0.17, 0.67, 0.32, 1) forwards;
}

@keyframes wheelSpin {
  0%   { transform: rotate(0deg); }
  25%  { transform: rotate(300deg); }
  60%  { transform: rotate(660deg); }
  85%  { transform: rotate(710deg); }
  100% { transform: rotate(720deg); }
}

.wheel-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: #4338CA;
  text-align: center;
  line-height: 1.3;
  font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 0 8px;
}

.wheel-label {
  font-size: 0.63rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
}

/* ─── Controls Groups ────────────────────────────────────────────────────────── */

.ctrl-group { margin-bottom: 16px; }

.ctrl-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.ctrl-name { font-size: 0.78rem; font-weight: 500; color: var(--text-muted); }

.ctrl-val {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  font-family: 'SF Mono', monospace;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--border-2);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--indigo);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  cursor: pointer;
  transition: transform 0.15s;
}

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

.ctrl-divider { height: 1px; background: var(--border); margin: 14px 0; }

/* Toggle */
.toggle-group { display: flex; align-items: center; margin-bottom: 14px; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--indigo);
  cursor: pointer;
}

/* Buttons */
.ctrl-buttons { display: flex; flex-direction: column; gap: 7px; }

.btn {
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
  text-align: center;
  font-family: inherit;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-spin {
  background: var(--indigo);
  color: #fff;
  border-color: #4F46E5;
  font-size: 0.85rem;
}
.btn-spin:hover:not(:disabled) { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-2); }

/* Legend */
.legend {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-line {
  width: 22px;
  height: 2.5px;
  border-radius: 1px;
  flex-shrink: 0;
}

.legend-dashed {
  height: 0;
  border-top: 2.5px dashed #22C55E;
}

.legend-bar {
  width: 14px;
  height: 11px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── Viz Panel ──────────────────────────────────────────────────────────────── */

.viz-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.stat-pill-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  display: block;
  margin-bottom: 4px;
}

.stat-pill-val {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: -0.01em;
}

.stat-pill-val.red-val   { color: var(--red); }
.stat-pill-val.blue-val  { color: var(--blue); }
.stat-pill-val.green-val { color: var(--green); }

/* Chart cards */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  box-shadow: var(--shadow-sm);
}

.chart-card-title {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.chart-container      { position: relative; height: 280px; width: 100%; }
.chart-container-tall { position: relative; height: 300px; width: 100%; }

/* D3 axis styling */
.tick text {
  font-size: 10px;
  fill: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.tick line, .domain { stroke: var(--border-2); }

/* Insight box */
.insight-box {
  background: var(--indigo-bg);
  border: 1px solid #C7D2FE;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 0.82rem;
  color: #312E81;
  line-height: 1.7;
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .app-body { grid-template-columns: 230px 1fr; }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 820px) {
  .app-body { grid-template-columns: 1fr; }
  .controls { position: static; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .about-grid { grid-template-columns: 1fr; }
  .about-divider { height: 1px; width: 100%; }
  .about-banner { padding: 16px; }
}

@media (max-width: 480px) {
  .app-header { padding: 14px 16px; }
  .app-body { padding: 12px; gap: 12px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}
