/* Diagrams for the proxy-partner pages, /proxy-partners/ and /partners/. The markup (inline SVG and
   plain HTML) is upstream's; this file draws it on the theme: flat, on black, coloured only through
   the tokens below. Orange is us, blue is the provider, red is whatever got stopped.

   MOTION. Nothing moves until diagrams.js marks a figure `data-run` (it does that while the figure
   is on screen). Every picture is drawn in its end state: with no script, the reader sees what
   happens, not a blank stage.
   Packets (.pk) exist only while moving, so they are hidden in that still picture; marks (.mk:
   a cross, a cut, a label) are visible in it and the animation only delays them. */

:root {
  --pd-ink: var(--text);
  --pd-muted: var(--text-dim);
  --pd-line: var(--outline-strong);
  --pd-wire: var(--text-faint);
  --pd-tile: var(--surface-2);
  --pd-net: var(--surface-1);
  --pd-us: var(--accent);
  --pd-us-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --pd-you: var(--wolf);
  --pd-you-soft: color-mix(in srgb, var(--wolf) 14%, transparent);
  --pd-ok: var(--success);
  --pd-ok-soft: color-mix(in srgb, var(--success) 12%, transparent);
  --pd-bad: var(--danger);
  --pd-bad-soft: color-mix(in srgb, var(--danger) 12%, transparent);
  --pd-pkt: var(--text);
}

.pd, .pd-grid, ol.pd-steps { position: relative; margin: var(--s-5) 0; color: var(--pd-ink); }
/* In the docs, a figure keeps the 24px a block component gets (theme/docs.css, Rhythm). */
.flow > * + :is(.pd, .pd-grid, .pd-steps), .flow > :is(.pd, .pd-grid, .pd-steps) + * { margin-top: var(--s-5); }
.pd svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.pd svg.pd-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.pd figcaption { margin-top: var(--s-3); color: var(--pd-muted); font-size: 0.875rem; line-height: 1.5; }

/* The drawing vocabulary */
.pd .node { fill: var(--pd-tile); stroke: var(--pd-line); stroke-width: 1; }
.pd .node.us { fill: var(--pd-us-soft); stroke: var(--pd-us); }
.pd .node.you { fill: var(--pd-you-soft); stroke: var(--pd-you); }
.pd .node.bad { fill: var(--pd-bad-soft); stroke: var(--pd-bad); }
.pd .zone { fill: var(--pd-net); stroke: none; }
.pd .zone.us { fill: var(--pd-us-soft); opacity: 0.5; }
.pd .zone.you { fill: var(--pd-you-soft); opacity: 0.5; }
.pd svg text { text-anchor: middle; }
.pd svg text.l { text-anchor: start; }
.pd svg text.r { text-anchor: end; }
.pd .t { fill: var(--pd-ink); font-size: 13px; font-weight: 600; }
.pd .s { fill: var(--pd-muted); font-size: 11.5px; font-weight: 400; }
.pd .z { fill: var(--pd-muted); font-size: 11.5px; font-weight: 500; }
.pd .xs { fill: var(--pd-muted); font-size: 10px; font-weight: 500; }
.pd .us-t { fill: var(--pd-us); }
.pd .you-t { fill: var(--pd-you); }
.pd .bad-t { fill: var(--pd-bad); }
.pd .ok-t { fill: var(--pd-ok); }
.pd .wire { fill: none; stroke: var(--pd-wire); stroke-width: 1.5; }
.pd .wire.ctl { stroke: var(--pd-us); stroke-dasharray: 5 5; }
.pd .wire.you { stroke: var(--pd-you); }
.pd .wire.cut { stroke: var(--pd-bad); stroke-width: 2; stroke-dasharray: 3 5; }
.pd .pk { fill: var(--pd-pkt); opacity: 0; }
.pd .pk.ok { fill: var(--pd-ok); }
.pd .pk.bad { fill: var(--pd-bad); }
.pd .pk.you { fill: var(--pd-you); }
.pd .pk text, .pd text.pkl { fill: var(--bg); font-size: 9px; font-weight: 600; }
.pd .x { fill: none; stroke: var(--pd-bad); stroke-width: 2.5; stroke-linecap: round; }
.pd .tick { fill: none; stroke: var(--pd-ok); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.pd .key { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pd .ah-ink { fill: var(--pd-wire); }
.pd .ah-us { fill: var(--pd-us); }
.pd .ah-you { fill: var(--pd-you); }
.pd .ah-bad { fill: var(--pd-bad); }

/* The architecture: one drawing for wide screens, one for narrow */
.pd-arch { container-type: inline-size; }
.pd-arch .tall { display: none; max-width: 440px; margin: 0 auto; }
@container (max-width: 700px) {
  .pd-arch .wide { display: none; }
  .pd-arch .tall { display: block; }
}

/* The attack cards */
.pd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--s-3); }
.pd-grid figure.pd {
  margin: 0;
  padding: var(--s-4);
  border: 1px solid var(--outline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}
.pd-grid p.pd-h { margin: 0 0 var(--s-2); padding-right: var(--s-6); color: var(--pd-ink); font-size: 0.9375rem; font-weight: 600; line-height: 1.3; }
.pd-grid figcaption { margin-top: var(--s-2); font-size: 0.8125rem; }
.pd-grid .t { font-size: 12px; }
.pd-grid .s { font-size: 10px; }

/* The consent gate and the bans: HTML flows, so they reflow on a phone */
.pd ol.pd-flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: var(--s-2) 0; margin: 0; padding: 0; list-style: none; }
.pd ol.pd-flow > li {
  position: relative;
  flex: 1 1 130px;
  min-width: 0;
  margin: 0 var(--s-5) 0 0;
  padding: var(--s-3);
  border: 1px solid var(--pd-line);
  border-radius: var(--r-md);
  background: var(--surface-1);
}
.pd ol.pd-flow > li:last-child { margin-right: 0; }
.pd-flow > li::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -18px;
  width: 10px;
  height: 12px;
  margin-top: -6px;
  background: var(--pd-wire);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.pd-flow > li:last-child::after { display: none; }
.pd-flow b { display: block; font-size: 0.9375rem; line-height: 1.3; }
.pd-flow span { display: block; margin-top: var(--s-1); color: var(--pd-muted); font-size: 0.8125rem; line-height: 1.45; }
.pd-flow .us { border-color: var(--pd-us); background: var(--pd-us-soft); }
.pd-flow .you { border-color: var(--pd-you); background: var(--pd-you-soft); }
.pd-flow .ok { border-color: var(--pd-ok); background: var(--pd-ok-soft); }
.pd-flow .bad { border-color: var(--pd-bad); background: var(--pd-bad-soft); }
.pd-branch { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-3); margin-top: var(--s-3); }
.pd-branch > div { padding: var(--s-3); border: 1px dashed var(--pd-line); border-radius: var(--r-md); color: var(--pd-muted); font-size: 0.875rem; line-height: 1.5; }
.pd-branch .bad { border-color: var(--pd-bad); }
.pd ul.pd-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.pd ul.pd-out > li {
  margin: 0;
  padding: var(--s-3);
  border: 1px solid color-mix(in srgb, var(--pd-bad) 45%, transparent);
  border-radius: var(--r-md);
  background: var(--pd-bad-soft);
  color: var(--pd-muted);
  font-size: 0.8125rem;
  line-height: 1.45;
}
.pd-out b { display: block; font-size: 0.875rem; }
@media (max-width: 620px) {
  .pd ol.pd-flow { flex-direction: column; gap: var(--s-5); }
  .pd ol.pd-flow > li { flex-basis: auto; margin-right: 0; }
  .pd-flow > li::after { top: auto; right: auto; bottom: -18px; left: 50%; width: 12px; height: 10px; margin: 0 0 0 -6px; clip-path: polygon(0 0, 100% 0, 50% 100%); }
}

/* Bans: what starts one, the ban, what it does */
.pd-ban { display: grid; grid-template-columns: minmax(0, 1fr) 104px minmax(0, 1.3fr); align-items: center; gap: var(--s-3) var(--s-6); }
.pd-ban .src { display: grid; gap: var(--s-2); }
.pd-ban .src > div { padding: var(--s-3); border: 1px solid var(--pd-line); border-radius: var(--r-md); background: var(--surface-1); color: var(--pd-muted); font-size: 0.8125rem; line-height: 1.45; }
.pd-ban .src b { display: block; font-size: 0.9375rem; }
.pd-ban .src .you { border-color: var(--pd-you); background: var(--pd-you-soft); }
.pd-ban .src .us { border-color: var(--pd-us); background: var(--pd-us-soft); }
.pd-ban .hub {
  position: relative;
  display: grid;
  place-content: center;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pd-bad);
  color: var(--bg);
  line-height: 1.2;
  text-align: center;
}
.pd-ban .hub b { display: block; color: inherit; font-size: 1.25rem; }
.pd-ban .hub span { font-size: 0.8125rem; font-weight: 500; }
.pd-ban .hub::before, .pd-ban .hub::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 10px;
  height: 12px;
  margin-top: -6px;
  background: var(--pd-wire);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.pd-ban .hub::before { left: -22px; }
.pd-ban .hub::after { right: -22px; }
@media (max-width: 620px) {
  .pd-ban { grid-template-columns: minmax(0, 1fr); gap: var(--s-6); }
  .pd-ban .hub { width: 104px; justify-self: center; }
  .pd-ban .hub::before, .pd-ban .hub::after { right: auto; left: 50%; width: 12px; height: 10px; margin: 0 0 0 -6px; clip-path: polygon(0 0, 100% 0, 50% 100%); }
  .pd-ban .hub::before { top: -22px; }
  .pd-ban .hub::after { top: auto; bottom: -22px; }
}

/* The three steps that open both pages */
ol.pd-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); padding: 0; list-style: none; counter-reset: pds; }
ol.pd-steps > li {
  position: relative;
  margin: 0;
  padding: var(--s-4);
  border: 1px solid var(--outline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  color: var(--pd-muted);
  font-size: 0.875rem;
  line-height: 1.5;
  counter-increment: pds;
}
.pd-steps li::before {
  content: counter(pds);
  position: absolute;
  top: var(--s-4);
  left: var(--s-4);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-container);
  color: var(--on-accent-container);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 28px;
  text-align: center;
}
.pd-steps b { display: block; margin-bottom: var(--s-2); padding-left: 40px; color: var(--pd-ink); font-size: 1rem; font-weight: 600; line-height: 28px; }
@media (max-width: 760px) { ol.pd-steps { grid-template-columns: minmax(0, 1fr); } }

/* The pause button diagrams.js adds to a moving figure */
.pd-pause {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  z-index: 1;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-dim);
  font: 600 0.6875rem/1 var(--font);
  cursor: pointer;
}
.pd-pause:hover, .pd-pause:focus-visible { background: var(--surface-4); color: var(--text); }
/* Outside a card the button gets a row of its own, so it never sits on the drawing. */
.pd:not(.pd-grid > *):has(> .pd-pause) { padding-top: var(--s-6); }
.pd:not(.pd-grid > *) > .pd-pause { top: 0; right: 0; }
.pd[data-paused] * { animation-play-state: paused !important; }

/* ── Motion ─────────────────────────────────────────────────────────────────────────────────────
   One 8-second cycle for every card. A packet's own trip starts at --t and travels (--dx, --dy); a mark (.mk)
   appears .atN seconds in. */
.pd[data-run] .pk { animation: pd-pass 8s linear var(--t, 0s) infinite both; }
.pd[data-run] .pk.drop { animation-name: pd-drop; }
.pd[data-run] .pk.slow { animation-name: pd-pass-slow; }
.pd[data-run] .mk { animation: pd-in-1 8s linear infinite both; }
.pd[data-run] .mk.at2 { animation-name: pd-in-2; }
.pd[data-run] .mk.at3 { animation-name: pd-in-3; }
.pd[data-run] .mk.at4 { animation-name: pd-in-4; }
.pd[data-run] .mk.at5 { animation-name: pd-in-5; }
.pd[data-run] .mk.at6 { animation-name: pd-in-6; }
.pd[data-run] .flow { animation: pd-dash 1.2s linear infinite; }
.pd[data-run] .glow { animation: pd-glow 8s linear var(--t, 0s) infinite both; }
.pd[data-run] .step { animation: pd-step var(--cycle, 8s) linear var(--t, 0s) infinite both; }
.pd[data-run] .pd-ban .hub { animation: pd-pulse 8s ease-out var(--t, 0s) infinite both; }
.pd[data-run] .pd-out li { animation: pd-fan 8s ease-out var(--t, 0s) infinite both; }
@keyframes pd-pass {
  0% { opacity: 0; transform: translate(0, 0); }
  1.5% { opacity: 1; }
  11% { opacity: 1; transform: translate(var(--dx, 0), var(--dy, 0)); }
  13%, 100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, 0)); }
}
@keyframes pd-pass-slow {
  0% { opacity: 0; transform: translate(0, 0); }
  2% { opacity: 1; }
  22% { opacity: 1; transform: translate(var(--dx, 0), var(--dy, 0)); }
  25%, 100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, 0)); }
}
/* A dropped packet reaches the relay, turns red and goes no further. */
@keyframes pd-drop {
  0% { opacity: 0; transform: translate(0, 0); }
  1.5% { opacity: 1; }
  8% { opacity: 1; transform: translate(var(--dx, 0), var(--dy, 0)); fill: var(--pd-pkt); }
  9% { fill: var(--pd-bad); }
  16%, 100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, 0)); fill: var(--pd-bad); }
}
/* A mark appears N seconds into the cycle (.atN, 1 s by default) and stays to its end. */
@keyframes pd-in-1 { 0%, 12% { opacity: 0; } 15%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-in-2 { 0%, 25% { opacity: 0; } 28%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-in-3 { 0%, 37% { opacity: 0; } 40%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-in-4 { 0%, 50% { opacity: 0; } 53%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-in-5 { 0%, 62% { opacity: 0; } 65%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-in-6 { 0%, 75% { opacity: 0; } 78%, 97% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pd-dash { to { stroke-dashoffset: -20; } }
@keyframes pd-glow { 0%, 100% { opacity: 0.25; } 10%, 30% { opacity: 1; } }
/* The step being told gets a ring, not a shadow: the theme has none. */
@keyframes pd-step { 0% { box-shadow: 0 0 0 0 transparent; } 3%, 17% { box-shadow: 0 0 0 2px var(--pd-us); } 20%, 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes pd-pulse { 0% { box-shadow: 0 0 0 0 var(--pd-bad-soft); } 6% { box-shadow: 0 0 0 12px var(--pd-bad-soft); } 14%, 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes pd-fan { 0%, 8% { opacity: 0.25; transform: translateY(6px); } 14%, 92% { opacity: 1; transform: none; } 100% { opacity: 0.25; } }
