/* ============================================================
   VIZ — shell for every interactive widget
   Structure built by js/viz/core.js:
     .viz > .viz-stage > canvas
          > .viz-panel > .viz-controls + .viz-readouts
          > .viz-caption
   Each widget sets --accent; everything below derives from it.
   ============================================================ */

.viz {
  --accent: var(--gold);
  margin-block: clamp(28px, 4vw, 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* ---------- Stage ---------- */
.viz-stage {
  position: relative;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--accent) 5%, var(--surface)),
      var(--surface));
  border-bottom: 1px solid var(--border);
}
.viz-canvas { width: 100%; touch-action: none; }
.viz-canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.viz-canvas.is-interactive { cursor: grab; }
.viz-canvas.is-grabbing { cursor: grabbing; }

/* ---------- Panel ---------- */
.viz-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px 28px;
  align-items: start;
  padding: 18px 22px;
}
.viz-panel:has(.viz-readouts:empty) { grid-template-columns: 1fr; }

/* ---------- Controls ---------- */
.viz-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 20px;
}
.viz-controls:empty { display: none; }

.viz-ctl-slider { min-width: 190px; flex: 1 1 190px; max-width: 280px; }
.viz-ctl-top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 7px;
}
.viz-ctl-label {
  font-family: var(--font-mono);
  font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-subtle); font-weight: 600;
}
.viz-ctl-value {
  font-family: var(--font-mono);
  font-size: .82rem; font-weight: 600;
  color: var(--accent-ink, var(--accent));
  font-variant-numeric: tabular-nums;
}

/* Range input — restyled in both themes, keeps a real focus ring */
.viz-ctl-slider input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
}
.viz-ctl-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 8px -1px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .18s var(--ease-out);
}
.viz-ctl-slider input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
.viz-ctl-slider input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); cursor: pointer;
}
.viz-ctl-slider input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 999px; background: var(--border-strong);
}

/* ---------- Buttons ---------- */
.viz-btn {
  font-family: var(--font-mono);
  font-size: .78rem; font-weight: 600; letter-spacing: .04em;
  padding: 9px 15px; border-radius: 10px;
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
  transition: border-color .2s, background .2s, color .2s, transform .2s;
}
.viz-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.viz-btn-primary {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}
.viz-btn-primary:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Readouts ---------- */
.viz-readouts {
  display: flex; flex-wrap: wrap; gap: 8px 22px;
  align-items: baseline; justify-content: flex-end;
}
.viz-readouts:empty { display: none; }
.viz-readout { display: flex; flex-direction: column; gap: 2px; min-width: 78px; }
.viz-readout-label {
  font-family: var(--font-mono);
  font-size: .66rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-subtle); font-weight: 600;
}
.viz-readout-value {
  font-family: var(--font-mono);
  font-size: 1.02rem; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color .25s;
}

/* ---------- Caption ---------- */
.viz-caption {
  padding: 0 22px 18px;
  margin: -4px 0 0;
  font-size: .9rem; line-height: 1.55;
  color: var(--text-muted);
}
.viz-caption b, .viz-caption strong { color: var(--accent); font-weight: 600; }
.viz-caption code {
  font-family: var(--font-mono); font-size: .84em;
  background: var(--grid-line); padding: 1px 5px; border-radius: 5px;
}

/* ---------- Playing state: a subtle accent rail ---------- */
.viz.is-playing .viz-stage::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: viz-scan 1.6s linear infinite;
}
@keyframes viz-scan { 0% { opacity: .3; } 50% { opacity: 1; } 100% { opacity: .3; } }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .viz-stage { overflow-x: auto; }
  .viz-canvas { min-width: 320px; }
  .viz-panel { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .viz-readouts { justify-content: flex-start; }
  .viz-ctl-slider { max-width: none; }
  .viz-caption { padding: 0 16px 16px; font-size: .86rem; }
}

@media (prefers-reduced-motion: reduce) {
  .viz.is-playing .viz-stage::after { animation: none; }
}
