/* ───────────────────────────────────────────────────────────────────────────
   NativeScript 9.1 explainer visuals: "signal flow" theme.
   Rounded surfaces, curved connectors with flowing dashes, glowing orbs for
   traffic, sans-serif headings with mono reserved for code tokens.
   The render pass only writes data-state / data-tone; CSS owns the rest.
   ─────────────────────────────────────────────────────────────────────────── */
:root {
  --bg: #f4f6fc;
  --surface: #ffffff;
  --surface-2: #e8edf8;
  --surface-3: #dde4f3;
  --text: #0f1730;
  --text-muted: #5a6685;
  --text-faint: #9aa6c2;
  --line: #cfd8ea;
  --line-strong: #aab7d4;
  --glow-alpha: 55%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1f;
    --surface: #111a33;
    --surface-2: #182447;
    --surface-3: #1f2e58;
    --text: #e8eeff;
    --text-muted: #93a0c4;
    --text-faint: #5b6889;
    --line: #22305a;
    --line-strong: #34468a;
    --glow-alpha: 70%;
  }
}

.viz {
  --sans: ui-sans-serif, -apple-system, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --snap: cubic-bezier(0.2, 1.25, 0.35, 1);
  --tone-disk: #14b8a6; /* local file transport / ESM */
  --tone-http: #3b9cf6; /* HTTP module transport */
  --tone-ws: #e879f9; /* WebSocket protocol messages */
  --tone-policy: #8b5cf6; /* ns:module loader policy / evaluation policy */
  --tone-cjs: #f59e0b; /* CommonJS / interop */
  --tone-error: #fb7185;
  --tone-ok: #84cc16;
  --tone-neutral: var(--text-muted);
  --tone: var(--tone-neutral);
  width: 100%;
  height: auto;
  display: block;
  background: var(--bg);
  user-select: none;
  pointer-events: none;
  font-synthesis: none;
}
.viz [data-tone='disk'] {
  --tone: var(--tone-disk);
}
.viz [data-tone='http'] {
  --tone: var(--tone-http);
}
.viz [data-tone='ws'] {
  --tone: var(--tone-ws);
}
.viz [data-tone='policy'] {
  --tone: var(--tone-policy);
}
.viz [data-tone='cjs'] {
  --tone: var(--tone-cjs);
}
.viz [data-tone='error'] {
  --tone: var(--tone-error);
}
.viz [data-tone='ok'] {
  --tone: var(--tone-ok);
}
.viz [data-tone='neutral'] {
  --tone: var(--tone-neutral);
}
.viz [data-tone] {
  --tone-soft: color-mix(in srgb, var(--tone) 16%, var(--surface));
  --tone-softer: color-mix(in srgb, var(--tone) 8%, var(--surface));
  --tone-glow: color-mix(in srgb, var(--tone) var(--glow-alpha), transparent);
}

/* ── type ─────────────────────────────────────────────────────────────── */
.viz .label {
  fill: var(--text-muted);
  font: 600 10.5px var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.viz .label-strong {
  fill: var(--text);
  font: 700 12px var(--sans);
  letter-spacing: 0;
  text-transform: none;
}
.viz .caption {
  fill: var(--text);
  font: 500 12.5px var(--sans);
}
.viz .caption-layer {
  transition: opacity 0.45s ease, transform 0.55s var(--snap);
}
.viz .caption-layer[data-state='out'] {
  opacity: 0;
  transform: translateY(8px);
}
.viz .caption-layer[data-state='in'] {
  opacity: 1;
  transform: translateY(0);
}
.viz .pip {
  fill: var(--line-strong);
  transition: fill 0.3s, r 0.3s;
}
.viz .pip[data-state='done'] {
  fill: color-mix(in srgb, var(--tone-policy) 55%, var(--line-strong));
}
.viz .pip[data-state='active'] {
  fill: var(--tone-policy);
  filter: drop-shadow(0 0 4px var(--tone-policy));
}
.viz .caption-rule {
  stroke: var(--line);
  stroke-width: 1;
}

/* ── conduit (network band) ───────────────────────────────────────────── */
.viz .conduit {
  fill: color-mix(in srgb, var(--tone-http) 7%, transparent);
  stroke: color-mix(in srgb, var(--tone-http) 18%, transparent);
  stroke-width: 1;
}
.viz .conduit-core {
  stroke: color-mix(in srgb, var(--tone-http) 30%, transparent);
  stroke-width: 1.5;
  stroke-dasharray: 2 14;
  stroke-linecap: round;
  animation: viz-drift 6s linear infinite;
}
@keyframes viz-drift {
  to {
    stroke-dashoffset: -64;
  }
}

/* ── connectors ───────────────────────────────────────────────────────── */
.viz .edge {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.4s, stroke 0.4s;
}
.viz .edge-tip {
  fill: var(--line-strong);
  transition: opacity 0.4s, fill 0.4s, r 0.3s;
}
.viz .edge[data-state='hidden'],
.viz .edge-tip[data-state='hidden'] {
  opacity: 0;
}
.viz .edge[data-state='pending'] {
  opacity: 0.45;
  stroke-dasharray: 1 7;
}
.viz .edge[data-state='active'] {
  stroke: var(--tone);
  stroke-dasharray: 7 9;
  animation: viz-flow 0.8s linear infinite;
  filter: drop-shadow(0 0 3px var(--tone-glow));
}
.viz .edge-tip[data-state='active'] {
  fill: var(--tone);
  r: 4.5;
  filter: drop-shadow(0 0 4px var(--tone-glow));
}
.viz .edge[data-state='done'] {
  stroke: color-mix(in srgb, var(--tone) 70%, var(--line-strong));
}
.viz .edge-tip[data-state='done'] {
  fill: color-mix(in srgb, var(--tone) 70%, var(--line-strong));
}
@keyframes viz-flow {
  to {
    stroke-dashoffset: -32;
  }
}

/* ── cards ────────────────────────────────────────────────────────────── */
.viz .node {
  transition: opacity 0.4s ease;
}
.viz .node-inner {
  transition: transform 0.6s var(--snap);
  transform-origin: center;
  transform-box: fill-box;
}
.viz .node .frame {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.25;
  transition: fill 0.35s, stroke 0.35s, filter 0.35s;
}
.viz .node .glyph-bg {
  fill: var(--surface-2);
  stroke: var(--surface);
  stroke-width: 2;
  transition: fill 0.35s, stroke 0.35s;
  transform-box: fill-box;
  transform-origin: center;
}
.viz .node .glyph {
  fill: var(--text-muted);
  font: 700 10px var(--sans);
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.35s;
}
.viz .node .title {
  fill: var(--text);
  font: 650 11px var(--sans);
}
.viz .node .meta {
  fill: var(--text-muted);
  font: 500 9px var(--mono);
}
.viz .node .tag {
  fill: var(--tone);
  font: 700 8.5px var(--sans);
  letter-spacing: 0.04em;
}
.viz .node[data-state='hidden'] {
  opacity: 0;
}
.viz .node[data-state='hidden'] .node-inner {
  transform: scale(0.82);
}
.viz .node[data-state='pending'] {
  opacity: 0.55;
}
.viz .node[data-state='pending'] .frame {
  stroke-dasharray: 1 5;
}
.viz .node[data-state='reading'] .frame {
  stroke: var(--tone);
}
.viz .node[data-state='reading'] .glyph-bg {
  fill: var(--tone);
  animation: viz-breathe 0.7s ease-in-out infinite;
}
.viz .node[data-state='reading'] .glyph {
  fill: #fff;
}
.viz .node[data-state='active'] .frame {
  fill: var(--tone-soft);
  stroke: var(--tone);
  stroke-width: 1.75;
  filter: drop-shadow(0 0 9px var(--tone-glow));
}
.viz .node[data-state='active'] .glyph-bg,
.viz .node[data-state='done'] .glyph-bg {
  fill: var(--tone);
}
.viz .node[data-state='active'] .glyph,
.viz .node[data-state='done'] .glyph {
  fill: #fff;
}
.viz .node[data-state='done'] .frame {
  fill: var(--tone-softer);
  stroke: color-mix(in srgb, var(--tone) 70%, var(--line));
}
.viz .node[data-state='error'] .frame {
  fill: color-mix(in srgb, var(--tone-error) 12%, var(--surface));
  stroke: var(--tone-error);
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--tone-error) 60%, transparent));
}
.viz .node[data-state='error'] .glyph-bg {
  fill: var(--tone-error);
}
.viz .node[data-state='error'] .glyph {
  fill: #fff;
}
.viz .node[data-state='error'] .tag {
  fill: var(--tone-error);
}
.viz .node[data-state='evicted'] {
  opacity: 0.6;
}
.viz .node[data-state='evicted'] .frame {
  stroke: var(--tone-error);
  stroke-dasharray: 2 4;
}
.viz .node[data-state='evicted'] .title {
  text-decoration: line-through;
}
@keyframes viz-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.18);
  }
}

/* ── panels / rows ────────────────────────────────────────────────────── */
.viz .panel .frame {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.25;
}
.viz .panel .accent {
  fill: var(--tone);
}
.viz .panel .title {
  fill: var(--text);
  font: 700 12px var(--sans);
}
.viz .panel .subtitle {
  fill: var(--text-faint);
  font: 500 9.5px var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.viz .row {
  transition: opacity 0.35s ease;
}
.viz .row-inner {
  transition: transform 0.5s var(--snap);
}
.viz .row rect.bg {
  fill: transparent;
  transition: fill 0.3s;
}
.viz .row text.k {
  fill: var(--text-muted);
  font: 600 10px var(--mono);
  transition: fill 0.3s;
}
.viz .row text.v {
  fill: var(--text-faint);
  font: 500 9px var(--sans);
  transition: fill 0.3s;
}
.viz .row .dot {
  fill: var(--surface-3);
  transition: fill 0.3s, r 0.3s, filter 0.3s;
}
.viz .row[data-state='hidden'] {
  opacity: 0;
}
.viz .row[data-state='hidden'] .row-inner {
  transform: translateX(16px);
}
.viz .row[data-state='idle'] text.k {
  fill: var(--text-faint);
}
.viz .row[data-state='active'] rect.bg {
  fill: var(--tone-soft);
}
.viz .row[data-state='active'] text.k,
.viz .row[data-state='active'] text.v {
  fill: var(--text);
}
.viz .row[data-state='active'] .dot {
  fill: var(--tone);
  r: 4.5;
  filter: drop-shadow(0 0 5px var(--tone-glow));
}
.viz .row[data-state='done'] text.k {
  fill: var(--text);
}
.viz .row[data-state='done'] .dot {
  fill: var(--tone);
}
.viz .row[data-state='evicted'] text.k {
  fill: var(--text-faint);
  text-decoration: line-through;
}
.viz .row[data-state='evicted'] .dot {
  fill: var(--tone-error);
}
.viz .row[data-state='error'] text.k {
  fill: var(--tone-error);
}
.viz .row[data-state='error'] .dot {
  fill: var(--tone-error);
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--tone-error) 60%, transparent));
}

/* ── orbs (traffic) ───────────────────────────────────────────────────── */
.viz .orb[hidden] {
  display: none;
}
.viz .orb .core {
  fill: var(--tone);
  filter: drop-shadow(0 0 7px var(--tone-glow));
}
.viz .orb .halo {
  fill: color-mix(in srgb, var(--tone) 22%, transparent);
}
.viz .orb .tail {
  fill: var(--tone);
}
.viz .orb .ripple {
  fill: none;
  stroke: var(--tone);
  stroke-width: 1.5;
}
.viz .orb text {
  fill: var(--text);
  font: 600 9.5px var(--mono);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* ── badges ───────────────────────────────────────────────────────────── */
.viz .badge rect {
  fill: var(--tone-soft);
  stroke: color-mix(in srgb, var(--tone) 55%, transparent);
  stroke-width: 1;
  transition: fill 0.3s, stroke 0.3s, filter 0.3s;
}
.viz .badge text {
  fill: var(--text);
  font: 600 9.5px var(--mono);
  dominant-baseline: central;
  text-anchor: middle;
}
.viz .badge {
  transition: opacity 0.35s;
}
.viz .badge-inner {
  transition: transform 0.5s var(--snap);
  transform-origin: center;
  transform-box: fill-box;
}
.viz .badge[data-state='hidden'] {
  opacity: 0;
}
.viz .badge[data-state='hidden'] .badge-inner {
  transform: scale(0.9);
}
.viz .badge[data-state='idle'] {
  opacity: 0.42;
}
.viz .badge[data-state='idle'] rect {
  fill: transparent;
  stroke: var(--line);
}
.viz .badge[data-state='visible'] rect {
  filter: drop-shadow(0 0 6px var(--tone-glow));
}

/* ── rail (phase tracker) ─────────────────────────────────────────────── */
.viz .rail-track {
  stroke: var(--line);
  stroke-width: 2;
  stroke-linecap: round;
}
.viz .rail-fill {
  stroke: var(--tone);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s var(--snap);
}
.viz .rail-stop circle {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 2;
  transition: fill 0.3s, stroke 0.3s, r 0.3s, filter 0.3s;
}
.viz .rail-stop text {
  fill: var(--text-muted);
  font: 700 9.5px var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: fill 0.3s;
}
.viz .rail-stop[data-state='done'] circle {
  fill: var(--tone);
  stroke: var(--tone);
}
.viz .rail-stop[data-state='active'] circle {
  fill: var(--tone);
  stroke: var(--surface);
  r: 7;
  filter: drop-shadow(0 0 6px var(--tone-glow));
}
.viz .rail-stop[data-state='active'] text,
.viz .rail-stop[data-state='done'] text {
  fill: var(--text);
}

/* ── progress ring ────────────────────────────────────────────────────── */
.viz .ring-track {
  fill: none;
  stroke: var(--surface-3);
  stroke-width: 5;
}
.viz .ring-fill {
  fill: none;
  stroke: var(--tone);
  stroke-width: 5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px var(--tone-glow));
}
.viz .ring-text {
  fill: var(--text);
  font: 700 12px var(--sans);
  text-anchor: middle;
  dominant-baseline: central;
}

/* ── device ───────────────────────────────────────────────────────────── */
.viz .phone .shell {
  fill: var(--surface-2);
  stroke: var(--line-strong);
  stroke-width: 1.5;
}
.viz .phone .screen {
  fill: var(--surface);
}
.viz .phone .notch {
  fill: var(--surface-3);
}
.viz .phone .ui-bar {
  fill: var(--surface-2);
}
.viz .phone .ui-text {
  fill: var(--text);
  font: 700 11px var(--sans);
}
.viz .phone .ui-sub {
  fill: var(--text-muted);
  font: 500 9px var(--sans);
}
.viz .phone .ui-block {
  fill: var(--surface-2);
  transition: fill 0.4s, stroke 0.4s;
  stroke: transparent;
  stroke-width: 1;
}
.viz .phone .ui-block[data-hot] {
  fill: var(--tone-soft);
  stroke: var(--tone);
}
.viz .phone .screen-group {
  transition: opacity 0.5s;
}
.viz .phone .screen-group[data-state='hidden'] {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .viz * {
    animation: none !important;
    transition: none !important;
  }
}

/* ── transport controls (HTML bar under each scene) ───────────────────── */
.viz-controls {
  --sans: ui-sans-serif, -apple-system, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --accent: #8b5cf6;
  --accent-2: #3b9cf6;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font: 500 12px/1 var(--sans);
  color: var(--text-muted);
  user-select: none;
}
@media (max-width: 760px) {
  .viz-controls {
    grid-template-columns: auto 1fr;
  }
  .viz-controls .viz-speed {
    grid-column: 1 / -1;
  }
}
.viz-transport {
  display: flex;
  gap: 6px;
}
.viz-btn {
  width: 34px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background 0.2s, border-color 0.2s, transform 0.25s cubic-bezier(0.2, 1.25, 0.35, 1);
}
.viz-btn:hover {
  border-color: var(--line-strong);
}
.viz-btn:active {
  transform: scale(0.94);
}
.viz-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.viz-play {
  width: 40px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  border-color: transparent;
}
.viz-controls[data-playing='false'] .viz-play {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.viz-scrub {
  position: relative;
  display: grid;
  gap: 6px;
}
.viz-seek,
.viz-speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  outline: none;
  cursor: pointer;
  margin: 0;
}
.viz-seek::-webkit-slider-thumb,
.viz-speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  cursor: grab;
}
.viz-seek::-moz-range-thumb,
.viz-speed-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: grab;
}
.viz-seek:focus-visible,
.viz-speed-slider:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
.viz-ticks {
  position: absolute;
  left: 8px;
  right: 8px;
  top: -4px;
  height: 14px;
  pointer-events: none;
}
.viz-ticks i {
  position: absolute;
  top: 0;
  width: 2px;
  height: 14px;
  margin-left: -1px;
  border-radius: 1px;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}
.viz-readout {
  display: flex;
  justify-content: space-between;
  font: 500 11px var(--mono);
  color: var(--text-faint);
}
.viz-readout .viz-step {
  color: var(--text-muted);
}

.viz-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 330px;
}
.viz-speed-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
}
.viz-presets {
  display: flex;
  gap: 4px;
}
.viz-chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 8px;
  font: 600 10.5px var(--mono);
  cursor: pointer;
  transition: all 0.2s;
}
.viz-chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}
.viz-chip.is-active {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  border-color: var(--accent);
  color: var(--text);
}
.viz-speed-slider {
  width: 110px;
}
.viz-speed-value {
  font: 700 12px var(--mono);
  color: var(--text);
  min-width: 40px;
  text-align: right;
}

/* page-level "all scenes" control */
.viz-global {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font: 600 11px ui-sans-serif, -apple-system, 'Inter', sans-serif;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.viz-global input {
  width: 140px;
}
.viz-global output {
  font: 700 12px ui-monospace, Menlo, monospace;
  color: var(--text);
  min-width: 40px;
  text-align: right;
  text-transform: none;
}
