/* ═══════════════════════════════════════════════════════════════
   XSEVERITY — shared visualizer engine
   Design tokens inherited from the site (--cur, --bg, --mono, --sans).
   Severity scale mirrors the XSEVERITY logo lockup: Low / Medium / High / Critical.
   ═══════════════════════════════════════════════════════════════ */

.viz [hidden],
.viz[hidden] { display: none !important; }

.viz {
  --sev-low:      #00e5a0;
  --sev-medium:   #ffd166;
  --sev-high:     #ff9f43;
  --sev-critical: #ff4d5e;
  --viz-node-bg:  #0c0c0e;
  --viz-line:     rgba(255,255,255,0.10);
  --viz-gap:      10px;

  display: flex;
  flex-direction: column;
  gap: 14px;
  container-type: inline-size;
}

/* ── toolbar ───────────────────────────────────────────────── */
.viz-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.viz-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.viz-seg button {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .2s, background .2s;
}

.viz-seg button:hover { color: var(--mid); }

.viz-seg button[aria-pressed="true"] {
  color: var(--cur);
  background: var(--cur-dim);
}

.viz-threat-btn {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 7px 11px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .2s, border-color .2s, background .2s;
}

.viz-threat-btn:hover { color: var(--mid); border-color: rgba(255,255,255,0.16); }

.viz-threat-btn[aria-pressed="true"] {
  color: var(--sev-critical);
  border-color: rgba(255,77,94,0.42);
  background: rgba(255,77,94,0.08);
}

.viz-threat-btn::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .55;
}

.viz-threat-btn[aria-pressed="true"]::before {
  opacity: 1;
  box-shadow: 0 0 8px var(--sev-critical);
}

/* ── scene ─────────────────────────────────────────────────── */
.viz-scene {
  position: relative;
  border: 1px solid var(--border);
  background:
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px),
    radial-gradient(circle at 50% 40%, var(--cur-glow), transparent 60%),
    #0a0a0c;
  background-size: 28px 28px, 28px 28px, auto, auto;
  padding: 14px;
  display: grid;
  gap: var(--viz-gap);
  grid-template-columns: 1fr;
  transition: background .3s;
}

.viz-wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.viz-wire {
  fill: none;
  stroke: var(--viz-line);
  stroke-width: 1.25;
  stroke-linecap: square;
  stroke-linejoin: miter;
  transition: stroke .3s, stroke-width .3s;
}

.viz-wire.is-complete { stroke: rgba(0,229,160,0.20); }

.viz-wire.is-active {
  stroke: var(--cur);
  stroke-width: 1.75;
  stroke-dasharray: 3 5;
  animation: vizDash .8s linear infinite;
  filter: drop-shadow(0 0 4px rgba(0,229,160,0.45));
}

@keyframes vizDash { to { stroke-dashoffset: -22; } }

/* ── nodes: the component IS the visual — no container box ─── */
.viz-node {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 2px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: rgba(236,236,236,0.34);
  transition: color .3s, filter .3s;
  -webkit-tap-highlight-color: transparent;
}

/* Mobile: fix the art height so components keep their true aspect —
   a tall DIMM must not be squashed by a short, wide cell. */
.viz-node-art {
  position: relative;
  width: 100%;
  height: 132px;
  display: block;
}

.viz-node-art svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* artwork detail classes (see viz_art.py) */
.viz-node svg .d    { opacity: .40; }
.viz-node svg .w    { opacity: .48; }
.viz-node svg .a    { fill: currentColor; stroke: none; opacity: .52; }
.viz-node svg .lga  { fill: currentColor; stroke: none; opacity: .20; }
.viz-node svg .screen { opacity: .34; }
.viz-node svg .silk {
  fill: currentColor;
  stroke: none;
  opacity: .48;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.05em;
}
.viz-node svg .silk.sm { font-size: 6.5px; opacity: .34; }

.viz-node-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.viz-node-label {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.3;
  transition: color .25s;
}

.viz-node-state {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.04em;
  color: rgba(236,236,236,0.26);
  line-height: 1.3;
  transition: color .25s;
}

.viz-node:hover { color: rgba(236,236,236,0.58); }

/* the component that starts the run — pulses until it has been pressed */
.viz-node.is-trigger.is-armed {
  color: var(--cur);
  animation: vizArm 1.9s ease-in-out infinite;
}
.viz-node.is-trigger.is-armed .viz-node-label { color: var(--cur); }
.viz-node.is-trigger.is-armed .viz-node-state { color: rgba(0,229,160,0.72); }

@keyframes vizArm {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(0,229,160,0.22)); }
  50%      { filter: drop-shadow(0 0 12px rgba(0,229,160,0.55)); }
}
.viz-node:hover .viz-node-label { color: var(--mid); }

.viz-node:focus-visible {
  outline: 1px solid var(--cur);
  outline-offset: 3px;
}

.viz-node.is-complete { color: rgba(0,229,160,0.46); }
.viz-node.is-complete .viz-node-label { color: rgba(0,229,160,0.58); }

.viz-node.is-active {
  color: var(--cur);
  filter: drop-shadow(0 0 7px rgba(0,229,160,0.30));
}
.viz-node.is-active .viz-node-label { color: var(--cur); }
.viz-node.is-active .viz-node-state { color: rgba(0,229,160,0.66); }

/* threat mode: the component under attack in this stage */
.viz.is-threat .viz-node.is-target {
  color: var(--sev);
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--sev) 34%, transparent));
}
.viz.is-threat .viz-node.is-target .viz-node-label { color: var(--sev); }
.viz.is-threat .viz-node.is-target .viz-node-state {
  color: color-mix(in srgb, var(--sev) 70%, transparent);
}
.viz.is-threat .viz-wire.is-active { stroke: var(--sev); }

/* ── the monitor's own screen, not a separate square ──────── */
.viz-node-screen {
  position: absolute;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 3px;
  background: #050506;
  transition: background .35s;
}

.viz-readout-text {
  font-family: var(--mono);
  font-size: 7.5px;
  line-height: 1.5;
  letter-spacing: 0.03em;
  color: rgba(236,236,236,0.26);
  text-align: center;
  white-space: pre-line;
  transition: color .35s;
}

.viz-node-screen[data-screen="powered"] { background: radial-gradient(circle at 50% 45%, #0a1a14, #050506 74%); }
.viz-node-screen[data-screen="powered"] .viz-readout-text { color: rgba(0,229,160,0.48); }
.viz-node-screen[data-screen="post"]    { background: #06080a; }
.viz-node-screen[data-screen="post"] .viz-readout-text { color: rgba(0,229,160,0.72); }
.viz-node-screen[data-screen="logo"]    { background: #070a09; }
.viz-node-screen[data-screen="logo"] .viz-readout-text { color: #ecffee; letter-spacing: 0.20em; }
.viz-node-screen[data-screen="os"]      { background: linear-gradient(150deg, #0a1a14, #060a12); }
.viz-node-screen[data-screen="os"] .viz-readout-text { color: #ecffee; }

/* ── controls ──────────────────────────────────────────────── */
.viz-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viz-btn-row { display: flex; gap: 7px; flex-wrap: wrap; }

.viz-btn {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 9px 13px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--muted);
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}

.viz-btn:hover:not(:disabled) { color: var(--cur); border-color: var(--cur-border-h); }
.viz-btn:disabled { opacity: .32; cursor: not-allowed; }

.viz-btn-primary {
  border-color: var(--cur-border-h);
  background: var(--cur-dim);
  color: var(--cur);
  min-width: 118px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.viz-btn-primary:hover:not(:disabled) { background: rgba(0,229,160,0.16); }

.viz-btn-stop {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 92px;
}
.viz-btn-stop:hover:not(:disabled) {
  color: var(--sev-critical);
  border-color: rgba(255,77,94,0.42);
}

.viz-track-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.viz-track-head b { color: var(--cur); font-weight: 400; }

.viz-range {
  width: 100%;
  accent-color: var(--cur);
  cursor: pointer;
  background: transparent;
}

.viz-range:focus-visible { outline: 2px solid var(--cur); outline-offset: 3px; }

.viz-speed {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.viz-speed .viz-range { max-width: 130px; }

/* ── stage panel ───────────────────────────────────────────── */
.viz-panel {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.012);
  padding: 16px;
}

.viz-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.viz-stage-badge {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--cur);
  border: 1px solid var(--cur-border-h);
  background: var(--cur-dim);
  padding: 4px 8px;
}

.viz-stage-time {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.viz-stage-title {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: #ecffee;
  margin: 0 0 8px;
}

.viz-stage-summary {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 300;
  line-height: 1.65;
  color: var(--mid);
  margin: 0 0 14px;
}

.viz-sub {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 7px;
}

.viz-detail {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 300;
  line-height: 1.65;
  color: var(--mid);
  margin: 0;
}

.viz-signals {
  margin: 0;
  padding: 11px;
  border: 1px solid var(--border);
  background: #08080a;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.6;
  color: rgba(0,229,160,0.62);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.viz-block { margin-top: 14px; }

/* ── threat card ───────────────────────────────────────────── */
.viz-threat {
  margin-top: 14px;
  border: 1px solid color-mix(in srgb, var(--sev) 32%, transparent);
  background: color-mix(in srgb, var(--sev) 6%, transparent);
  padding: 13px;
}


.viz-threat-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 9px;
  flex-wrap: wrap;
}

.viz-sev {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sev);
  border: 1px solid color-mix(in srgb, var(--sev) 42%, transparent);
  padding: 3px 7px;
}

.viz-threat-name {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
}

.viz-threat-row { margin-top: 9px; }

.viz-threat-row p {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--mid);
  margin: 0;
}

.viz-threat-row .viz-sub { color: color-mix(in srgb, var(--sev) 70%, transparent); }

/* ── event log ─────────────────────────────────────────────── */
.viz-log {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: #08080a;
}

.viz-log:empty::after {
  content: attr(data-empty);
  display: block;
  padding: 14px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: rgba(236,236,236,0.22);
}

.viz-log-row {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.5;
  color: var(--muted);
}

.viz-log-row:last-child { border-bottom: 0; }
.viz-log-row b { color: var(--cur); font-weight: 400; }
.viz-log-row.is-threat b { color: var(--sev-critical); }

/* ── legend ────────────────────────────────────────────────── */
.viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }

.viz-legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .5;
}

.viz-legend .lg-active   { color: var(--cur); }
.viz-legend .lg-active i { opacity: 1; box-shadow: 0 0 7px var(--cur); }
.viz-legend .lg-done     { color: rgba(0,229,160,0.55); }
.viz-legend .lg-threat   { color: var(--sev-critical); }
.viz-legend .lg-threat i { opacity: 1; box-shadow: 0 0 7px var(--sev-critical); }

/* ── node modal ────────────────────────────────────────────── */
.viz-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 16px;
}

.viz-modal.is-open { display: grid; }

.viz-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4,4,5,0.82);
  backdrop-filter: blur(6px);
}

.viz-modal-card {
  position: relative;
  z-index: 2;
  width: min(560px, 100%);
  max-height: 84dvh;
  overflow-y: auto;
  border: 1px solid var(--cur-border-h);
  background: #0a0a0c;
  padding: 22px;
}

.viz-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}

.viz-modal-close:hover { color: var(--cur); }

.viz-modal-kicker {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cur);
}

.viz-modal-card h3 {
  font-family: var(--sans);
  font-size: 19px;
  font-weight: 500;
  color: #ecffee;
  margin: 9px 0 10px;
  letter-spacing: -0.01em;
}

.viz-modal-card > p {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 300;
  line-height: 1.7;
  color: var(--mid);
  margin: 0;
}

.viz-modal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 16px;
}

.viz-modal-item {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  padding: 11px;
}

.viz-modal-item strong {
  display: block;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--cur);
  font-weight: 400;
  margin-bottom: 5px;
}

.viz-modal-item span {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 300;
  line-height: 1.55;
  color: var(--mid);
}

/* ── responsive ────────────────────────────────────────────── */
/* Mobile default: nodes stack into a vertical chain and the wires,
   measured from live geometry, follow automatically. */
@container (min-width: 600px) {
  .viz-modal-grid { grid-template-columns: 1fr 1fr; }
}

/* Wide: the readout sits beside the board rather than under it, so the whole
   widget stays inside one screen. .viz is the query container itself, so this
   grid has to live on a descendant — a container cannot style itself. */
@container (min-width: 880px) {
  .viz-scene { grid-auto-rows: 116px; padding: 18px; }
}
@container (min-width: 1000px) {
  .viz-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 336px;
    column-gap: 16px;
    align-items: start;
  }
  .viz-stack { min-width: 0; }
  .viz-side  { min-width: 0; }
  .viz-side .viz-panel { margin-top: 0; }
  .viz-log { max-height: 150px; }
}

@container (min-width: 600px) {
  .viz { --viz-gap: 10px; }
  .viz-scene {
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 104px;
    padding: 16px;
  }
  /* data-driven placement kicks in only here; below this the nodes
     reflow into a readable vertical chain and the wires follow */
  .viz-node { grid-column: var(--gc); grid-row: var(--gr); min-height: 0; }
  .viz-node-art { flex: 1; height: auto; min-height: 0; }
  .viz-controls { flex-direction: row; align-items: center; gap: 18px; }
  .viz-track { flex: 1; min-width: 0; }
  .viz-stage-title { font-size: 19px; }
}

/* No container query support → fall back to viewport widths */
@supports not (container-type: inline-size) {
  @media (min-width: 640px) {
    .viz-scene { grid-template-columns: repeat(12, 1fr); grid-auto-rows: 104px; }
    .viz-node { grid-column: var(--gc); grid-row: var(--gr); min-height: 0; }
    .viz-node-art { flex: 1; height: auto; min-height: 0; }
    .viz-controls { flex-direction: row; align-items: center; gap: 18px; }
    .viz-track { flex: 1; min-width: 0; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .viz-wire.is-active { animation: none; }
  .viz-node.is-trigger.is-armed { animation: none; filter: drop-shadow(0 0 8px rgba(0,229,160,0.45)); }
  .viz-node, .viz-wire, .viz-readout { transition: none; }
}
