/* "How it works" architecture diagram. Layout via container queries on the diagram's own width:
   a vertical spine when narrow, one left-to-right row from 800px. Connectors are drawn by
   js/architecture.js from live element positions. */

.architecture {
  container: arch / inline-size;
  position: relative;
  isolation: isolate;
  max-width: 1120px;
  margin-inline: auto;
  color: var(--mist);
  line-height: 1.35;
}
.architecture p { margin: 0; }

/* ---------- Connector layer ---------- */
.architecture .arch-links {
  position: absolute; inset: 0; width: 100%; height: 100%;
  overflow: visible; pointer-events: none; z-index: 0;
}
.architecture .arch-base {
  fill: none; stroke-width: 1.25; stroke-linecap: round;
  stroke: color-mix(in srgb, var(--mist-2) 34%, transparent);
  transition: opacity 0.3s var(--ease), stroke-width 0.3s var(--ease);
}
.architecture .arch-base.k-ai { opacity: 0.5; }
.architecture .arch-base.k-go { stroke: color-mix(in srgb, var(--go) 42%, transparent); }
.architecture .arch-base.k-cue,
.architecture .arch-base.k-rail { stroke: color-mix(in srgb, var(--cue) 55%, var(--mist-2)); opacity: 0.55; }
.architecture .arch-base.k-rail { stroke-dasharray: 2 6; }
.architecture.has-hot .arch-base { opacity: 0.25; }
.architecture.has-hot .arch-base.is-hot { opacity: 1; stroke-width: 2; }

.architecture .arch-pulse {
  fill: none; stroke-linecap: round;
  stroke-dashoffset: var(--from);
  animation-name: arch-flow; animation-timing-function: linear; animation-iteration-count: infinite;
}
.architecture .arch-pulse.is-core { stroke-width: 2.25; }
.architecture .arch-pulse.is-halo { stroke-width: 8; opacity: 0.25; }
.architecture .arch-pulse.k-data { stroke: #fff; }
.architecture .arch-pulse.k-go { stroke: var(--go); }
.architecture .arch-pulse.k-cue,
.architecture .arch-pulse.k-rail { stroke: color-mix(in srgb, var(--cue) 60%, #fff); }
.architecture .arch-pulse.is-halo.k-cue,
.architecture .arch-pulse.is-halo.k-rail { stroke: var(--cue); opacity: 0.6; }
@keyframes arch-flow { from { stroke-dashoffset: var(--from); } to { stroke-dashoffset: var(--to); } }

/* Arrival flash on a card, timed by JS to the packet wave */
.architecture .arch-flash {
  --fc: var(--mist);
  position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; opacity: 0;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--fc) 80%, transparent), 0 0 26px -6px var(--fc);
  animation: arch-flash 1s linear infinite;
}
.architecture .arch-agent .arch-flash { --fc: var(--c); }
.architecture .arch-gate .arch-flash,
.architecture .arch-screen .arch-flash { --fc: var(--go); }
.architecture .arch-return .arch-flash { --fc: var(--cue); }
.architecture .arch-orb .arch-flash {
  inset: -16%; border-radius: 50%; box-shadow: none;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.5), color-mix(in srgb, var(--ai-3) 35%, transparent) 55%, transparent);
}
@keyframes arch-flash { 0% { opacity: 1; } 14%, 100% { opacity: 0; } }

/* Pause everything while off-screen */
.architecture:not(.is-playing) *,
.architecture:not(.is-playing) *::before,
.architecture:not(.is-playing) *::after { animation-play-state: paused !important; }

/* ---------- Layout: narrow first (one vertical spine), flow left to right from 800px ---------- */
.architecture .arch-body {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 22px 4px;
}
.architecture .arch-sources { width: 100%; }
.architecture .arch-eyebrow { text-align: center; font-size: 0.8125rem; color: var(--mist-2); margin-bottom: 12px; }

.architecture .arch-icon { display: block; width: 20px; height: 20px; flex: none; }
.architecture .arch-icon path { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* Sources */
.architecture .arch-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.architecture .arch-chip {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md); background: var(--night-2); border: 1px solid var(--night-line);
  color: #fff; font-size: 0.8125rem; font-weight: 500; line-height: 1.25;
  hyphens: auto; overflow-wrap: break-word;
  transition: border-color 0.25s var(--ease);
}
.architecture .arch-chip:last-child { grid-column: 1 / -1; justify-self: center; min-width: 50%; }
.architecture .arch-chip-icon {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 10px; color: var(--mist); background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px var(--night-line);
}
.architecture .arch-chip:hover { border-color: var(--mist-2); }

/* Knowledge hub */
.architecture .arch-hub {
  position: relative;
  width: 100%; margin-top: 28px;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 60%), var(--night-2);
  border: 1px solid var(--night-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 24px 60px -30px rgba(0, 0, 0, 0.7);
}
.architecture .arch-hub-head { display: flex; align-items: center; gap: 14px; }
.architecture .arch-hub-icon {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: var(--r-md); color: #fff;
  background: rgba(255, 255, 255, 0.05); box-shadow: inset 0 0 0 1px var(--night-line);
}
.architecture .arch-hub-icon .arch-icon { width: 22px; height: 22px; }
.architecture .arch-hub-title { color: #fff; font-weight: 650; font-size: 1.0625rem; font-variation-settings: "wdth" 92; }
.architecture .arch-hub-sub { color: var(--mist-2); font-size: 0.8125rem; margin-top: 2px; }
.architecture .arch-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.architecture .arch-tag {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 9px; border-radius: var(--r-pill);
  font-size: 0.75rem; color: var(--mist);
  background: rgba(255, 255, 255, 0.025); border: 1px solid var(--night-line);
}
.architecture .arch-tag.is-incident::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--signal); }

/* AI orchestrator orb */
.architecture .arch-orb-wrap { position: relative; margin-top: 36px; display: flex; align-items: center; gap: 22px; }
.architecture .arch-orb {
  --orb: 64px;
  position: relative; width: var(--orb); height: var(--orb); flex: none; border-radius: 50%;
  transform-style: preserve-3d;
}
.architecture .arch-orb-glow {
  position: absolute; inset: -48%; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--ai-1) 50%, transparent),
    color-mix(in srgb, var(--ai-2) 18%, transparent) 55%, transparent);
  filter: blur(14px);
  animation: arch-breathe 7s ease-in-out infinite;
}
.architecture .arch-orb-core {
  position: absolute; inset: 0; border-radius: 50%; overflow: hidden;
  background: var(--ai-1);
  box-shadow: 0 0 40px -6px color-mix(in srgb, var(--ai-1) 70%, transparent);
}
.architecture .arch-swirl {
  position: absolute; inset: -30%;
  background: conic-gradient(from 0deg, var(--ai-1), var(--ai-2), var(--ai-3), var(--ai-1));
  filter: blur(12px);
  animation: arch-spin 16s linear infinite;
}
.architecture .arch-swirl.is-2 {
  inset: -12%; opacity: 0.85; mix-blend-mode: screen; filter: blur(9px);
  background: conic-gradient(from 90deg, transparent 0 12%, color-mix(in srgb, var(--ai-3) 75%, #fff) 28%,
    transparent 44% 62%, var(--ai-2) 78%, transparent 94%);
  animation-duration: 10s; animation-direction: reverse;
}
/* Glass shading: specular highlight, shadowed underside, darker rim */
.architecture .arch-orb-core::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle at 34% 27%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.16) 12%, transparent 30%),
    radial-gradient(circle at 66% 84%, rgba(12, 18, 56, 0.55), transparent 55%),
    radial-gradient(circle, transparent 56%, rgba(12, 18, 56, 0.5));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
/* Tilted orbit with three agent "moons" that stay facing the viewer */
.architecture .arch-orbit {
  position: absolute; inset: -24%; border-radius: 50%;
  border: 1px solid rgba(201, 205, 234, 0.2);
  transform: rotateX(74deg); transform-style: preserve-3d;
}
.architecture .arch-orbit-spin { position: absolute; inset: 0; transform-style: preserve-3d; animation: arch-spin 22s linear infinite; }
.architecture .arch-moon {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  transform-style: preserve-3d;
  transform: rotate(var(--a)) translateX(calc(var(--orb) * 0.74)) rotate(calc(var(--a) * -1));
}
.architecture .arch-moon i {
  position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(closest-side, #fff, var(--c) 30%, color-mix(in srgb, var(--c) 35%, transparent) 50%, transparent);
  transform: rotateX(-74deg);
  animation: arch-counter 22s linear infinite;
}
.architecture .arch-orb-label { max-width: 220px; }
.architecture .arch-orb-title { font-weight: 700; font-size: 1.0625rem; font-variation-settings: "wdth" 92; }
.architecture .arch-orb-sub { color: var(--mist-2); font-size: 0.8125rem; margin-top: 3px; }

@keyframes arch-spin { to { transform: rotate(360deg); } }
@keyframes arch-counter { from { transform: rotate(0deg) rotateX(-74deg); } to { transform: rotate(-360deg) rotateX(-74deg); } }
@keyframes arch-breathe { 50% { opacity: 0.7; transform: scale(0.94); } }

/* Agents */
.architecture .arch-agents { width: 100%; margin-top: 26px; display: grid; gap: 10px; }
.architecture .arch-agent {
  position: relative; border-radius: var(--r-lg);
  padding: 10px 14px 11px;
  background: radial-gradient(120% 120% at 50% -30%, color-mix(in srgb, var(--c) 20%, transparent), transparent 60%), var(--night-2);
}
.architecture .arch-agent.ai-border::before { opacity: 0.55; transition: opacity 0.25s var(--ease); }
.architecture .arch-agent:hover::before { opacity: 1; }
.architecture .arch-agent-name { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 600; font-size: 0.9375rem; line-height: 1.25; }
.architecture .arch-agent-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c); box-shadow: 0 0 10px var(--c); }
.architecture .arch-agent-desc { color: var(--mist-2); font-size: 0.8125rem; margin-top: 4px; padding-left: 17px; }

/* Approval gate */
.architecture .arch-gate {
  position: relative; margin-top: 26px;
  display: inline-flex; align-items: center; gap: 12px;
  padding: 7px 18px 7px 7px; border-radius: var(--r-pill);
  background: var(--night-2);
  border: 1px solid color-mix(in srgb, var(--go) 50%, transparent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--go) 7%, transparent), 0 10px 34px -12px color-mix(in srgb, var(--go) 60%, transparent);
}
.architecture .arch-gate-badges { display: flex; flex: none; }
.architecture .arch-gate-badges > span {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #fff;
  box-shadow: 0 0 0 2px var(--night-2);
}
.architecture .arch-gate-person { background: var(--cue); }
.architecture .arch-gate-check { background: var(--go); margin-left: -8px; }
.architecture .arch-gate-badges .arch-icon { width: 18px; height: 18px; }
.architecture .arch-gate-check .arch-icon path { stroke-width: 2.2; }
.architecture .arch-gate-title { display: block; color: #fff; font-weight: 600; font-size: 0.9375rem; }
.architecture .arch-gate-sub { display: block; color: var(--mist-2); font-size: 0.75rem; }

/* Screens */
.architecture .arch-screens { width: 100%; margin-top: 26px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.architecture .arch-screen {
  position: relative; border-radius: var(--r-lg); padding: 8px 10px 8px 8px;
  display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; column-gap: 8px;
  background: var(--night-2); border: 1px solid var(--night-line);
  hyphens: auto; overflow-wrap: break-word;
  transition: border-color 0.25s var(--ease);
}
.architecture .arch-screen:hover { border-color: color-mix(in srgb, var(--cue) 70%, var(--mist)); }
.architecture .arch-glyph {
  grid-row: span 2; display: block; width: 100%; height: 34px; padding: 3px 0;
  border-radius: 10px; background: var(--night); box-shadow: inset 0 0 0 1px var(--night-line);
}
.architecture .arch-glyph .g-frame { fill: none; stroke: color-mix(in srgb, var(--mist-2) 50%, transparent); stroke-width: 1.2; }
.architecture .arch-glyph .g-fill { fill: color-mix(in srgb, var(--mist-2) 26%, transparent); }
.architecture .arch-glyph .g-qr { fill: none; stroke: var(--mist); stroke-width: 1.6; }
.architecture .arch-glyph .g-cue { fill: var(--cue); }
.architecture .arch-glyph .g-cue-soft { fill: color-mix(in srgb, var(--cue) 32%, transparent); }
.architecture .arch-glyph .g-go { fill: var(--go); }
.architecture .arch-screen-name { align-self: end; color: #fff; font-weight: 600; font-size: 0.875rem; line-height: 1.25; }
.architecture .arch-screen-who { align-self: start; color: var(--mist-2); font-size: 0.75rem; line-height: 1.3; margin-top: 1px; }

/* Feedback loop label */
.architecture .arch-return {
  position: relative; margin-top: 26px; max-width: calc(100% - 8px);
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 12px 8px 10px; border-radius: var(--r-md);
  font-size: 0.75rem; line-height: 1.35; color: var(--mist);
  background: var(--night);
  border: 1px solid color-mix(in srgb, var(--cue) 55%, var(--night-line));
}
.architecture .arch-return .arch-icon { width: 16px; height: 16px; color: color-mix(in srgb, var(--cue) 55%, #fff); }

/* ---------- Phones: trim secondary detail so the chain fits one screen ---------- */
@container arch (max-width: 799px) {
  .architecture .arch-body { padding-inline: 12px; }
  .architecture .arch-eyebrow { margin-bottom: 8px; }
  .architecture .arch-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .architecture .arch-chip { padding: 5px 9px; border-radius: var(--r-pill); font-size: 0.75rem; }
  .architecture .arch-chip:last-child { min-width: 0; }
  .architecture .arch-chip-icon { display: none; }
  .architecture .arch-hub { margin-top: 20px; padding: 12px 14px; }
  .architecture .arch-hub-icon { width: 38px; height: 38px; }
  .architecture .arch-tags,
  .architecture .arch-agent-desc { display: none; }
  .architecture .arch-orb-wrap { margin-top: 26px; flex-direction: column; gap: 8px; }
  .architecture .arch-orb { --orb: 52px; }
  .architecture .arch-orb-label { text-align: center; }
  .architecture .arch-orb-sub { display: none; }
  .architecture .arch-agents { margin-top: 22px; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .architecture .arch-agent { display: grid; align-items: center; padding: 9px 8px; }
  .architecture .arch-agent-name { gap: 6px; font-size: 0.75rem; hyphens: auto; overflow-wrap: break-word; }
  .architecture .arch-gate { margin-top: 20px; padding-block: 5px; }
  .architecture .arch-screens { margin-top: 20px; gap: 8px; }
  .architecture .arch-screen { grid-template-columns: minmax(0, 1fr); padding: 6px 10px; }
  .architecture .arch-glyph { display: none; }
  .architecture .arch-return { margin-top: 20px; padding-block: 6px; }
}

/* ---------- Wide: one row, left to right, so the whole diagram fits a laptop screen ---------- */
@container arch (min-width: 800px) {
  .architecture .arch-body {
    display: grid; align-items: center;
    grid-template-columns: minmax(110px, 0.85fr) minmax(120px, 0.95fr) minmax(190px, 1.6fr) minmax(100px, 0.6fr) minmax(140px, 1.1fr);
    grid-template-areas: "src hub orb gate scr" "src hub agents gate scr" ". . ret ret .";
    column-gap: clamp(26px, 3.6cqi, 48px);
    padding: 4px 8px 8px;
  }
  .architecture .arch-sources { grid-area: src; }
  .architecture .arch-eyebrow { text-align: left; }
  .architecture .arch-chips { grid-template-columns: 1fr; }
  .architecture .arch-chip:last-child { grid-column: auto; justify-self: stretch; min-width: 0; }

  .architecture .arch-hub { grid-area: hub; margin: 0; gap: 12px; }
  .architecture .arch-hub-head { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* Orb top-left of its column; agents hang off it like a tree (connector runs down from the orb's centre) */
  .architecture .arch-orb-wrap { grid-area: orb; align-self: end; margin: 0; }
  .architecture .arch-orb { --orb: 72px; }
  .architecture .arch-agents { grid-area: agents; align-self: start; margin: 22px 0 0; padding-left: 52px; gap: 10px; }

  .architecture .arch-gate {
    grid-area: gate; margin: 0;
    flex-direction: column; text-align: center; gap: 8px;
    padding: 14px 12px 13px; border-radius: var(--r-lg);
  }

  .architecture .arch-screens { grid-area: scr; margin: 0; grid-template-columns: 1fr; gap: 10px; }
  .architecture .arch-screen { grid-template-columns: 50px minmax(0, 1fr); column-gap: 10px; }
  .architecture .arch-glyph { height: 40px; padding: 4px 0; }
  .architecture .arch-screen-who { font-size: 0.8125rem; }

  .architecture .arch-return { grid-area: ret; justify-self: center; margin-top: 26px; max-width: 100%; }
}

/* Small laptops / tablets in landscape: drop the screen glyphs to give the AI column room */
@container arch (min-width: 800px) and (max-width: 959px) {
  .architecture .arch-body { grid-template-columns: minmax(0, 0.85fr) minmax(0, 0.95fr) minmax(0, 1.8fr) minmax(96px, 0.6fr) minmax(0, 0.9fr); }
  .architecture .arch-hub-title { font-size: 0.9375rem; }
  .architecture .arch-screen { grid-template-columns: minmax(0, 1fr); padding: 8px 10px; }
  .architecture .arch-glyph { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .architecture .arch-orb-glow,
  .architecture .arch-swirl,
  .architecture .arch-orbit-spin,
  .architecture .arch-moon i { animation: none; }
  .architecture .arch-moon i { transform: rotateX(-74deg); }
}
