/* ============================================================================
   components/sysmap.css - Act IV. The centerpiece.

   Recovered from the pre-2.0 site, where this was the single most
   differentiated thing on the page and the only element that let a visitor
   INTERROGATE the operating system rather than read a claim about it.

   Translated, not pasted. The legacy rules referenced a palette that no longer
   exists (--panel, --panel2, --ink2, --ink3, --card, --flag-line, --serif,
   --mono). One translation is semantic rather than mechanical and is worth
   naming: legacy --gold-ink meant "gold-colored text", whereas 2.1's
   --gold-ink means "text placed ON a gold fill". Those are opposites, so every
   legacy fill:var(--gold-ink) becomes fill:var(--gold) here.

   Motion: the ambient packet loop runs 3.4s, well past 2.1's 250ms transition
   ceiling. That ceiling governs UI response, not an ambient diagram - a packet
   that crossed its edge in 250ms would read as a glitch. Every loop is gated
   behind prefers-reduced-motion, and the packets are removed entirely rather
   than merely stilled.
   ============================================================================ */

.sysmap {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: var(--space-xl);
  align-items: center;
}

.sysmap-map {
  position: relative;
  border-radius: var(--radius-l);
}

/* The ambient gold field the diagram floats in. Legacy value (420x320 at 12%)
   re-expressed in percentages so it tracks the container instead of assuming a
   fixed stage size. */
.sysmap-map::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(58% 48% at 50% 46%,
    color-mix(in oklab, var(--gold) 12%, transparent), transparent 70%);
}

.sysmap-stage { width: 100%; display: block; }
.sysmap-stage svg { width: 100%; height: auto; display: block; touch-action: manipulation; }

.sm-hint {
  position: absolute;
  left: 14px;
  bottom: 8px;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.04em;
  color: var(--ink-3);
  pointer-events: none;
}

/* ---- EDGES + PACKETS ----------------------------------------------------- */

.sm-line {
  stroke: var(--line-2);
  stroke-width: 1.4;
  opacity: 0.55;
  transition: stroke var(--dur-slow) var(--ease-out),
              opacity var(--dur-slow) var(--ease-out),
              stroke-width var(--dur-slow) var(--ease-out);
}
.sm-line.active { stroke: var(--gold); opacity: 0.9; stroke-width: 2; }

.sm-packet { pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .sm-packet { display: none; } }

/* ---- NODES --------------------------------------------------------------- */

.sm-node { cursor: pointer; outline: none; }

.sm-node .dot {
  fill: var(--surface-2);
  stroke: color-mix(in oklab, var(--gold) 25%, var(--line));
  stroke-width: 1.6;
  transition: stroke var(--dur-base) var(--ease-out),
              stroke-width var(--dur-base) var(--ease-out),
              fill var(--dur-base) var(--ease-out);
}
/* SVG text scales with the stage: viewBox is 680 wide and the stage renders at
   ~574px on a 1440 screen and ~499px at 1080, so a 13px/11.5px pair landed at
   11/9.7px and 9.5/8.4px - under the 11.5px floor the rest of the system
   holds. Raised so the rendered size clears the floor at 1080 and above. */
.sm-node .num {
  fill: var(--ink-2);
  /* Rendered size, not document size - see syncTypeScale() in sysmap.js.
     --sm-k is the inverse viewBox scale, so this resolves to 13px on screen at
     every viewport instead of shrinking with the stage. */
  font-size: calc(13px * var(--sm-k, 1));
  font-weight: 600;
  font-family: var(--font-mono);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  transition: fill var(--dur-base) var(--ease-out);
}
.sm-node .lbl {
  fill: var(--ink-2);
  /* Rendered size, not document size - see syncTypeScale() in sysmap.js.
     --sm-k is the inverse viewBox scale, so this resolves to 11.5px on screen at
     every viewport instead of shrinking with the stage. */
  font-size: calc(11.5px * var(--sm-k, 1));
  font-weight: 600;
  font-family: var(--font-mono);
  text-anchor: middle;
  pointer-events: none;
  transition: fill var(--dur-base) var(--ease-out);
}

.sm-node:hover .dot,
.sm-node:focus-visible .dot { stroke: var(--gold); stroke-width: 2.4; }
.sm-node:hover .lbl,
.sm-node:focus-visible .lbl { fill: var(--ink); }

/* Focus is drawn on the node itself rather than as a browser outline, because
   an outline on an SVG <g> boxes the label and the dot together and reads as a
   rectangle floating in the diagram. */
.sm-node:focus-visible .dot { stroke: var(--gold); stroke-width: 3; }

.sm-node.active .dot { fill: var(--gold); stroke: var(--gold); stroke-width: 2.4; }
.sm-node.active .num { fill: var(--gold-ink); }
.sm-node.active .lbl { fill: var(--ink); }

/* ---- CORE ---------------------------------------------------------------- */

.sm-core { cursor: pointer; outline: none; }
.sm-core .disc { fill: color-mix(in oklab, var(--gold) 12%, var(--bg)); }
.sm-core .ring { fill: none; stroke: var(--gold); stroke-width: 1.6; opacity: 0.9; }
.sm-core .halo { fill: none; stroke: var(--gold); stroke-width: 1.2; opacity: 0.35; }
.sm-core .ttl {
  fill: var(--gold);
  /* Rendered size, not document size - see syncTypeScale() in sysmap.js.
     --sm-k is the inverse viewBox scale, so this resolves to 13.5px on screen at
     every viewport instead of shrinking with the stage. */
  font-size: calc(13.5px * var(--sm-k, 1));
  font-weight: 600;
  font-family: var(--font-display);
  font-variation-settings: var(--fraunces-data);
  text-anchor: middle;
}
.sm-core:focus-visible .ring { stroke-width: 3; }

/* The map lives inside .band--sunk, which is darker than the page ground in
   the light theme. --gold measures 4.16:1 there; --gold-deep measures 6.13:1.
   See the matching note in home-v2.css. */
@media (prefers-color-scheme: light) {
  .sm-core .ttl { fill: var(--gold-deep); }
}
:root[data-theme="light"] .sm-core .ttl { fill: var(--gold-deep); }

/* ---- DETAIL PANEL -------------------------------------------------------- */

.sysmap-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: var(--space-m);
  box-shadow: inset 0 1px 0 color-mix(in oklab, #fff 6%, transparent);
}
:root[data-theme="light"] .sysmap-detail { box-shadow: inset 0 1px 0 #fff; }

.dt-tag {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
  margin-bottom: var(--space-2xs);
}
.dt-name {
  font-family: var(--font-display);
  font-variation-settings: var(--fraunces-data);
  font-size: var(--step-2);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.12;
  margin: 0 0 var(--space-2xs);
}
.dt-desc {
  color: var(--ink-2);
  font-size: var(--step--1);
  line-height: 1.55;
  margin: 0 0 var(--space-s);
  text-wrap: pretty;
}
.dt-roles-h {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
  margin-bottom: var(--space-2xs);
}
.dt-roles {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3xs) var(--space-2xs);
  margin: 0;
  padding: 0;
}
.dt-roles li {
  font-size: var(--step--1);
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}
.dt-roles li.note {
  background: transparent;
  border: none;
  padding: var(--space-2xs) 0 0;
  color: var(--gold);
  font-style: italic;
}

/* ---- MOBILE FALLBACK -----------------------------------------------------
   Below 860px the radial diagram is unreadable at any size a phone can give
   it, so it is replaced - not merely shrunk - by a tappable list that drives
   the same detail panel. This is recovered behavior, and it is the reason the
   component was accessible on a phone in the first place.                  */

.sysmap-list { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3xs); }
.sysmap-list button {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: var(--space-2xs) var(--space-xs);
  min-height: 44px;
  color: var(--ink-2);
  font-size: var(--step--1);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.sysmap-list button .n {
  flex: 0 0 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--step--2);
  font-family: var(--font-mono);
  color: var(--ink-2);
}
.sysmap-list button.active { border-color: var(--gold); color: var(--ink); }
.sysmap-list button.active .n { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.sysmap-list .core-chip { grid-column: 1 / -1; justify-content: center; border-color: var(--gold-line); color: var(--gold); }

@media (max-width: 860px) {
  .sysmap { grid-template-columns: 1fr; gap: var(--space-m); }
  /* 2026-11-08: the diagram stays on phones (Kyle asked for it back and it is the
     part he liked); the tappable list stays beneath it as the large-target path.
     Labels hold a constant rendered size through the --sm-k scale, so the ring
     reads at phone widths; the stage is capped so it does not push the detail
     panel a screen away. */
  .sysmap-map { display: block; max-width: 30rem; margin-inline: auto; width: 100%; }
  .sysmap-list { display: grid; }
  .sm-hint { position: static; display: block; text-align: center; padding-top: var(--space-2xs); }
}
/* Under 600px the 14 labels cannot sit beside their nodes without touching, so the
   ring is drawn with its numbered nodes only and the numbered chips beneath are the
   legend (the node numbers and the chip numbers are the same numbers). */
@media (max-width: 600px) {
  .sm-node .lbl { display: none; }
  .sm-hint { display: none; }
}

/* ---- ENTRANCE ------------------------------------------------------------
   Edges draw, nodes pop, core halo begins its slow pulse. Applied only when
   .anim is present, which the script withholds under reduced motion - so the
   diagram is fully drawn on first paint for those users rather than animating
   to a visible state.                                                      */

.sysmap.anim .sm-line { stroke-dasharray: 180; stroke-dashoffset: 180; }
.sysmap.anim .sm-node,
.sysmap.anim .sm-core { opacity: 0; transform-box: fill-box; transform-origin: center; }
.sysmap.anim .sm-node { transform: scale(0.55); }
.sysmap.anim .sm-core { transform: scale(0.7); }

.sysmap.anim.lit .sm-line { animation: smDraw 0.65s ease forwards; }
.sysmap.anim.lit .sm-node { animation: smPop 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
.sysmap.anim.lit .sm-core { animation: smPop 0.55s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
.sysmap.anim.lit .sm-core .halo { animation: smPulse 3.4s ease-in-out 1.1s infinite; }

@keyframes smDraw  { to { stroke-dashoffset: 0; } }
@keyframes smPop   { 0% { opacity: 0; } 60% { opacity: 1; } 100% { opacity: 1; transform: scale(1); } }
@keyframes smPulse { 0%, 100% { transform: scale(1); opacity: 0.32; } 50% { transform: scale(1.16); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .sysmap.anim .sm-line,
  .sysmap.anim .sm-node,
  .sysmap.anim .sm-core {
    opacity: 1;
    transform: none;
    stroke-dashoffset: 0;
    animation: none;
  }
}


/* ---- Restored 2026-11-08: no-JS list -------------------------- */
.sm-static { list-style: none; margin: var(--space-m) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2xs); justify-content: center; }
.sm-static li { font-size: var(--step--1); color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; }

/* ---- Phone length (Round 2, 2026-11-08) ---------------------------------------
   A smaller ring and a tighter detail panel on phones. The numbered ring, the
   tappable list and the detail panel all stay; only their size and padding
   change. */
@media (max-width: 600px) {
  .sysmap { gap: var(--space-s); }
  .sysmap-map { max-width: 21rem; }
  /* The drawing carries about 60px of empty ground above and below the ring at this
     size; crop it (nothing is drawn there) so it does not read as a gap. */
  .sysmap-stage { overflow: hidden; }
  .sysmap-stage svg { margin-block: -2.9rem; }
  .sysmap-detail { padding: var(--space-s); }
  .dt-name { font-size: var(--step-1); }
  .dt-desc { margin-bottom: var(--space-xs); }
  .sysmap-list button { min-height: 40px; padding-block: 0.25rem; }
}
