/* ── Generic diagram styling (per-diagram CSS is scoped inside each module) ─────────── */
.dg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; touch-action: none; overflow: hidden; }
.dg .lbl {
  fill: var(--ink); font-family: var(--font); font-weight: 550;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none; transition: opacity .3s var(--ease);
}
.dg .lbl-line { stroke: var(--ink-dim); stroke-width: 1; fill: none; pointer-events: none; transition: opacity .3s var(--ease); }
.dg.hide-labels .lbl, .dg.hide-labels .lbl-line { opacity: 0; }
.dg [data-id] { cursor: pointer; transition: opacity .35s var(--ease), filter .25s var(--ease); }
.dg [data-id].is-hover { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--accent) 70%, transparent)) brightness(1.18); }
.dg.has-focus [data-id]:not(.is-active) { opacity: .22; }
.dg [data-id].is-active { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 80%, transparent)) brightness(1.15); }
.dg.has-focus .lbl { opacity: .35; }
.dg.paused, .dg.paused * { animation-play-state: paused !important; }
.dg.thumb { pointer-events: none; }
.dg.thumb .lbl, .dg.thumb .lbl-line { display: none; }
:root[data-theme="light"] .dg .lbl { stroke: var(--surface); }

/* ── Viewer layout ─────────────────────────────────────────── */
.dgv { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; height: 100%; min-height: 0; }
.dgv.loading { display: grid; place-items: center; grid-template-columns: 1fr; min-height: 300px; }
.dgv-stage {
  position: relative; min-height: 0; border-radius: 18px; overflow: hidden; border: 1px solid var(--line-soft);
  background:
    radial-gradient(70% 70% at 50% 45%, color-mix(in srgb, var(--sys, var(--accent)) 7%, transparent), transparent 70%),
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--bg-2);
  background-blend-mode: normal;
}
.dgv-stage .dg { cursor: grab; }
.dgv-stage .dg.dragging { cursor: grabbing; }
.dgv-tools {
  position: absolute; top: 12px; right: 12px; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--line-soft); backdrop-filter: blur(10px);
}
.dgv-tools .sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.dgv-tip, .tip {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none; padding: 7px 11px; border-radius: 10px;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; opacity: 0; transition: opacity .15s; max-width: 260px;
}
.dgv-tip.show, .tip.show { opacity: 1; }
.dgv-tip b, .tip b { font-size: 14px; }
.dgv-tip span, .tip span { font-size: 12px; color: color-mix(in srgb, var(--c, var(--ink-dim)) 70%, var(--ink-dim)); }
.dgv-side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }
.dgv-desc { font-size: 14.5px; color: var(--ink-dim); }
.dgv-steps { border-color: color-mix(in srgb, var(--sys, var(--accent)) 35%, transparent); }
.steps-head { display: flex; justify-content: space-between; align-items: center; }
.steps-head h4 { margin: 0; }
.step-count { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.step-body { margin: 10px 0; min-height: 40px; }
.step-body h5 { font-size: 16px; margin-bottom: 6px; color: var(--ink); }
.step-body:not(:has(h5:not(:empty)))::before { content: 'Press play for a guided tour, or pick a step.'; color: var(--ink-dim); font-size: 14px; }
.step-body.swap { animation: rise .4s var(--ease) both; }
.step-text { font-size: 14px; color: var(--ink-dim); }
.step-dots { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 12px; }
.step-dots button { width: 22px; height: 6px; border-radius: 4px; background: var(--line); transition: background .3s, width .3s var(--ease); }
.step-dots button.on { background: var(--sys, var(--accent)); width: 34px; }
.step-ctrls { display: flex; align-items: center; gap: 6px; }
.dgv.autoplay .step-dots button.on { animation: pulse-dot 5.2s linear; }
@keyframes pulse-dot { from { box-shadow: inset 0 0 0 0 var(--accent); } }
.dgv-info.pop { animation: rise .35s var(--ease) both; }
.dgv-info h4 { font-size: 18px; margin: 6px 0 8px; }
.info-head { display: flex; justify-content: space-between; align-items: center; }
.dgv-info .btn { margin-top: 10px; }
.dgv-parts h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); margin: 4px 0 8px; display: flex; gap: 8px; align-items: center; }
.dgv-parts h4 b { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.dgv-parts ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.dgv-parts li {
  position: relative; padding: 6px 8px 6px 18px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--ink-dim);
  transition: background .15s, color .15s;
}
.dgv-parts li::before { content: ''; position: absolute; left: 7px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--c); opacity: .7; }
.dgv-parts li:hover, .dgv-parts li.hover { background: var(--surface-2); color: var(--ink); }
.dgv-parts li.active { background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: var(--ink); }

@media (max-width: 1000px) {
  .dgv { grid-template-columns: 1fr; grid-template-rows: minmax(320px, 60vh) auto; height: auto; }
  .dgv-side { overflow: visible; }
}

/* Gallery thumbnails stay still until hovered (saves CPU with many diagrams on screen). */
.dg.thumb * { animation-play-state: paused !important; }
.dg-card:hover .dg.thumb *, .dg-card:focus-visible .dg.thumb * { animation-play-state: running !important; }
