/*
 * Same dark stage and same accent as /explainers/inside-the-machine/, so the
 * two pages read as one body of work.
 *
 * Hue carries meaning: a block's colour is its kind, and the key stays true at
 * every zoom level. Blue is memory whether it is an HBM stack on the package
 * or a register file inside a processing block; orange is arithmetic whether
 * it is a whole die or thirty-two lanes.
 */
:root {
  --void: #07090c;
  --panel: #0c0f14;
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.24);
  --ink: #e9e7e2;
  --muted: #8f958f;
  --dim: #676c6b;
  --accent: #ef4f2f;

  --compute: #ef4f2f;
  --memory: #4cc9f0;
  --cache: #35d39a;
  --fabric: #9aa2ff;
  --control: #c7b8a3;
  --io: #ff8a4c;
  --substrate: #6a7280;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.9);
  flex: 0 0 auto;
}

.home {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  text-decoration: none;
  flex: 0 0 auto;
}

.home:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.topbar-title {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.topbar-title strong {
  font-size: 14px;
  font-weight: 600;
}

.topbar-title span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11.5px;
}

.crumb {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font: inherit;
  padding: 3px 8px;
  cursor: pointer;
}

.crumb:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--line);
}

.crumb:disabled {
  color: var(--accent);
  cursor: default;
}

.crumb-sep {
  color: var(--dim);
}

.back {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 5px 10px;
  cursor: pointer;
}

.back:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.back:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ------------------------------------------------------------------- shell */

.shell {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 0;
}

.viewer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 18px 22px 14px;
}

.scene-head {
  flex: 0 0 auto;
  max-width: 780px;
}

.scene-head h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.scene-subtitle {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}

.scene-blurb {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* ------------------------------------------------------------------- stage */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 14px;
  /* The frame the zoom happens inside: a scene scaled to 3× must not paint
     over the panel on its way out. */
  overflow: hidden;
}

.layer {
  position: absolute;
  inset: 0;
}

/* The scene being zoomed through must not eat clicks meant for the new one. */
.layer.leaving {
  pointer-events: none;
}

.layer.stashed {
  visibility: hidden;
  pointer-events: none;
}

.layer svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.zoomer {
  transform-box: view-box;
  transform-origin: center;
  will-change: transform, opacity;
}

/* -------------------------------------------------------------- svg blocks */

.node {
  --hue: var(--control);
  cursor: pointer;
  outline: none;
}

.node.kind-compute {
  --hue: var(--compute);
}
.node.kind-memory {
  --hue: var(--memory);
}
.node.kind-cache {
  --hue: var(--cache);
}
.node.kind-fabric {
  --hue: var(--fabric);
}
.node.kind-control {
  --hue: var(--control);
}
.node.kind-io {
  --hue: var(--io);
}
.node.kind-substrate {
  --hue: var(--substrate);
}

.node-body {
  fill: color-mix(in srgb, var(--hue) 9%, transparent);
  stroke: color-mix(in srgb, var(--hue) 45%, transparent);
  stroke-width: 1.2;
  transition:
    fill 160ms ease,
    stroke 160ms ease;
}

.node.passive {
  cursor: default;
  pointer-events: none;
}

.node.passive .node-body {
  fill: rgba(255, 255, 255, 0.014);
  stroke: var(--line);
}

.node.container .node-body {
  fill: color-mix(in srgb, var(--hue) 5%, transparent);
  stroke-dasharray: 3 4;
}

.node.overlay .node-body {
  fill: color-mix(in srgb, var(--hue) 16%, transparent);
  stroke: color-mix(in srgb, var(--hue) 70%, transparent);
}

.node:hover .node-body,
.node:focus-visible .node-body {
  fill: color-mix(in srgb, var(--hue) 20%, transparent);
  stroke: var(--hue);
}

.node.selected .node-body {
  fill: color-mix(in srgb, var(--hue) 24%, transparent);
  stroke: var(--hue);
  stroke-width: 2;
}

.node:focus-visible .node-body {
  stroke-width: 2;
  stroke-dasharray: none;
}

.glyph-cell {
  fill: color-mix(in srgb, var(--hue) 26%, transparent);
}

.node:hover .glyph-cell,
.node.selected .glyph-cell {
  fill: color-mix(in srgb, var(--hue) 52%, transparent);
}

.glyph-outline {
  fill: none;
  stroke: color-mix(in srgb, var(--hue) 26%, transparent);
  stroke-width: 1;
}

.glyph-wire {
  stroke: color-mix(in srgb, var(--hue) 34%, transparent);
  stroke-width: 1;
  fill: none;
}

.glyph-node {
  fill: color-mix(in srgb, var(--hue) 62%, transparent);
}

.glyph-via {
  stroke: color-mix(in srgb, var(--hue) 75%, transparent);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
}

.node-label {
  fill: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.01em;
  pointer-events: none;
}

.node-label.compact {
  font-size: 11px;
  fill: var(--muted);
}

.node-label.vertical {
  font-size: 11px;
  fill: var(--muted);
}

.node:hover .node-label,
.node.selected .node-label {
  fill: #fff;
}

.node-sub {
  fill: var(--dim);
  font-family: var(--mono);
  font-size: 10.5px;
  pointer-events: none;
}

.node-affordance {
  fill: color-mix(in srgb, var(--hue) 60%, transparent);
  font-size: 13px;
  pointer-events: none;
}

.scene-note {
  fill: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
}

/* -------------------------------------------------------------- viewer foot */

.viewer-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
  flex-wrap: wrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.legend-item {
  --hue: var(--control);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-item::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--hue) 55%, transparent);
  border: 1px solid var(--hue);
}

.legend-item.kind-compute {
  --hue: var(--compute);
}
.legend-item.kind-memory {
  --hue: var(--memory);
}
.legend-item.kind-cache {
  --hue: var(--cache);
}
.legend-item.kind-fabric {
  --hue: var(--fabric);
}
.legend-item.kind-control {
  --hue: var(--control);
}
.legend-item.kind-io {
  --hue: var(--io);
}
.legend-item.kind-substrate {
  --hue: var(--substrate);
}

.hint {
  margin: 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--muted);
}

/* ------------------------------------------------------------------- panel */

.panel {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 20px 22px 28px;
  min-height: 0;
}

.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  --hue: var(--control);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--hue);
  border: 1px solid color-mix(in srgb, var(--hue) 40%, transparent);
  background: color-mix(in srgb, var(--hue) 10%, transparent);
}

.chip.kind-compute {
  --hue: var(--compute);
}
.chip.kind-memory {
  --hue: var(--memory);
}
.chip.kind-cache {
  --hue: var(--cache);
}
.chip.kind-fabric {
  --hue: var(--fabric);
}
.chip.kind-control {
  --hue: var(--control);
}
.chip.kind-io {
  --hue: var(--io);
}
.chip.kind-substrate {
  --hue: var(--substrate);
}

.chip.confidence {
  --hue: var(--dim);
  cursor: help;
}

.chip.confidence.schematic {
  --hue: #b48a5c;
}

.panel-detail h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.panel-detail .tagline {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--accent);
}

.panel-detail .blurb {
  margin: 12px 0 0;
  font-size: 13.5px;
  line-height: 1.62;
  color: #cfd0cb;
}

.facts {
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11.5px;
}

.facts dt {
  padding: 7px 12px 7px 0;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
}

.facts dd {
  margin: 0;
  padding: 7px 0;
  text-align: right;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.open-child {
  margin-top: 18px;
  width: 100%;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  padding: 9px;
  cursor: pointer;
}

.open-child:hover {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  border-color: var(--accent);
}

.panel-idle {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.stat {
  background: var(--panel);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
}

.stat strong {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
}

.stat span {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--dim);
}

.panel-idle h3 {
  margin: 24px 0 10px;
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
}

.ladder {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.ladder li {
  display: grid;
  grid-template-columns: 108px 1fr 58px;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
}

.ladder-label {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ladder-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.ladder-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--memory) 60%, transparent),
    var(--accent)
  );
}

.ladder-value {
  text-align: right;
  color: var(--ink);
}

.sources {
  margin: 26px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--dim);
}

.sources code {
  font-family: var(--mono);
  font-size: 10.5px;
}

/* --------------------------------------------------------------- fallbacks */

.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 40px;
  background: var(--void);
}

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

/* Narrow screens stack the panel under the diagram rather than beside it. */
@media (max-width: 940px) {
  body {
    overflow: auto;
  }

  /*
   * Stacked, the page scrolls rather than fitting the viewport, so the viewer
   * must size to its content — a flex column here would squeeze the stage
   * below the height it was given and spill the diagram over the panel.
   */
  .shell {
    grid-template-columns: minmax(0, 1fr);
    flex: 0 0 auto;
  }

  .viewer {
    display: block;
    padding: 14px 16px;
  }

  .stage {
    height: 62vh;
  }

  .panel {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .crumbs {
    display: none;
  }
}
