/* The How It Works diagram family (plan 2026-11-15-1401 build seven V0; R12, KTD11). Drawn from
   lib/site/parts/hiw-diagrams.ts; linked by `withDiagramSheet` just before the topic sheet.

   One vocabulary with the Guards gate rail (hiw-topic.css `ht-diagram`, `ht-gate`): a white card, its head (name left,
   tag right), a hollow ring where something arrives, navy discs for what acts on it, amber for what Jinn flags, a green
   tick where it is approved or ends. The family's own part is the connector: an arrow 3px thick with a 24px head and a
   12px amber dot centered on its line, about twice the main page's connectors (36x14, 1.5px; stage three ruling),
   pointing from cause to effect in reading order.

   Self-contained: its own frame and its own container, so a page without hiw-topic.css can use it.
   Down the card by default: that is the 390 layout. A card wide enough lays a flow across, and lanes side by side.
   Nothing here moves or hides: every diagram is complete at rest.
   No SVG: app/globals.css reverts SVG presentation attributes under the site root, so marks are CSS shapes and the
   arrowheads are CSS masks over currentColor (the depth.css pattern). Colors are the site tokens; no brown. */

.hd {
  --hd-arrow-long: 64px;   /* the gap an across arrow spans */
  --hd-arrow-down: 48px;   /* the gap a down arrow spans */
  --hd-arrow-thick: 24px;  /* the head's width across the line */
  --hd-stroke: 3px;
  --hd-dot: 12px;
  --hd-node: 40px;
  --hd-hair: rgba(21, 23, 28, .09);
  --hd-head-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 14'%3E%3Cpath d='M2 2l10 10 10-10' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --hd-head-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 24'%3E%3Cpath d='M2 2l10 10-10 10' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  container-type: inline-size;
  margin: clamp(20px, 2.4vw, 28px) 0 0;
  padding: 16px clamp(16px, 2.2vw, 28px) clamp(18px, 2.4vw, 28px);
  max-width: 980px;
  background: var(--card, var(--paper));
  border: 1px solid var(--hd-hair);
  border-radius: 14px;
  box-shadow: 0 1px 0 rgba(21, 23, 28, .04), 0 22px 44px -26px rgba(17, 22, 39, .4);
  color: var(--ink);
}
/* A long flow stays down the card at the widths this site has (it goes across only past 940px of card): the card keeps
   to the width its words and its chip column need, not the whole chapter. */
.hd:has(> .hd-flow--long) { max-width: 780px; }
.hd__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 12px; margin-bottom: clamp(18px, 2.2vw, 26px); border-bottom: 1px solid var(--hd-hair); font-family: var(--ui); }
.hd__title { font-size: .95rem; font-weight: 800; color: var(--ink); }
.hd__tag { font-size: .8rem; font-weight: 700; color: var(--ink-3); text-align: right; }
.hd__aside,
.hd__note,
.hd__source { margin: 18px 0 0; padding-top: 12px; border-top: 1px solid var(--hd-hair); font-size: .88rem; line-height: 1.5; color: var(--ink-2); max-width: none; }
.hd__aside + .hd__note,
.hd__aside + .hd__source,
.hd__note + .hd__source { margin-top: 8px; padding-top: 0; border-top: 0; }
.hd__source a { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; text-decoration-color: var(--amber); }
.hd__source a:hover { text-decoration-thickness: 2.5px; }
.hd__source a:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 3px; }

/* ---- steps (a flow's and a lane's) ---------------------------------------------------------- */
.hd-flow,
.hd-lane__states { margin: 0; padding: 0; list-style: none; display: grid; row-gap: var(--hd-arrow-down); counter-reset: hd; }
.hd-step { position: relative; display: grid; grid-template-columns: var(--hd-node) minmax(0, 1fr); column-gap: 16px; align-items: start; }

/* the connector down to the next step: shaft from under this node to the next node, head at the bottom */
.hd-step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: calc(var(--hd-node) / 2 - var(--hd-arrow-thick) / 2);
  width: var(--hd-arrow-thick);
  top: calc(var(--hd-node) + 6px);
  bottom: calc(-1 * var(--hd-arrow-down) + 6px);
  background-color: var(--ink-3);
  -webkit-mask: var(--hd-head-down) center bottom / var(--hd-arrow-thick) 14px no-repeat, linear-gradient(black, black) center top / var(--hd-stroke) calc(100% - 3px) no-repeat;
  mask: var(--hd-head-down) center bottom / var(--hd-arrow-thick) 14px no-repeat, linear-gradient(black, black) center top / var(--hd-stroke) calc(100% - 3px) no-repeat;
}
/* its dot: amber, centered on the line, halfway between the two nodes */
.hd-step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: calc(var(--hd-node) / 2);
  top: calc(50% + (var(--hd-node) + var(--hd-arrow-down)) / 2);
  width: var(--hd-dot);
  height: var(--hd-dot);
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--card, var(--paper));
  transform: translate(-50%, -50%);
}

/* the marks: CSS shapes, never SVG */
.hd-step__node { position: relative; z-index: 1; width: var(--hd-node); height: var(--hd-node); border-radius: 50%; display: grid; place-items: center; background: var(--navy); color: var(--paper); font-family: var(--ui); font-size: .95rem; font-weight: 800; line-height: 1; }
.hd-step--step,
.hd-step--gate { counter-increment: hd; }
.hd-step--step .hd-step__node::after,
.hd-step--gate .hd-step__node::after { content: counter(hd); }
.hd-step--start .hd-step__node { background: var(--card, var(--paper)); box-shadow: inset 0 0 0 2.5px var(--ink-3); }
.hd-step--start .hd-step__node::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--ink-3); }
.hd-step--gate .hd-step__node { box-shadow: 0 0 0 4px var(--card, var(--paper)), 0 0 0 6px var(--amber); }
.hd-step--flag .hd-step__node { background: var(--amber); }
.hd-step--flag .hd-step__node::after { content: ""; width: 16px; height: 3px; border-radius: 2px; background: var(--ink); }
.hd-step--end .hd-step__node { background: var(--viridian); color: var(--paper); }
.hd-step--end .hd-step__node::after { content: ""; width: 8px; height: 15px; margin-top: -3px; box-sizing: border-box; border-right: 3px solid currentColor; border-bottom: 3px solid currentColor; transform: rotate(45deg); }
.hd-step--past .hd-step__node { background: var(--card, var(--paper)); box-shadow: none; border: 2.5px dashed var(--ink-3); box-sizing: border-box; }
.hd-step--past .hd-step__label { color: var(--ink-2); }

.hd-step__copy { min-width: 0; padding-top: 8px; }
.hd-step__label { margin: 0; font-family: var(--ui); font-size: 1.02rem; font-weight: 800; line-height: 1.3; color: var(--ink); }
.hd-step__line { margin: 4px 0 0; max-width: 54ch; font-size: .95rem; line-height: 1.5; color: var(--ink-2); }
.hd-step__line .dp-fact { color: inherit; }

/* a gate's exit: what happens when it says no, in amber (the gate rail's stop, its mark included) */
.hd-stop { display: flex; align-items: flex-start; gap: 8px; margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius-sm, 10px); background: color-mix(in srgb, var(--amber) 14%, var(--card, var(--paper))); color: var(--ink); font-size: .9rem; line-height: 1.45; width: fit-content; max-width: 100%; }
.hd-stop b { font-family: var(--ui); font-weight: 800; }
.hd-stop__mark { flex: none; position: relative; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; background: var(--amber); }
.hd-stop__mark::after { content: ""; position: absolute; left: 4px; right: 4px; top: 7px; height: 2px; border-radius: 1px; background: var(--ink); }

/* a verdict: the page's own word, as a pill */
.hd-verdict { display: inline-block; margin: 8px 0 0; padding: 3px 12px; border-radius: 999px; font-family: var(--ui); font-size: .85rem; font-weight: 800; line-height: 1.4; }
.hd-verdict--flag { background: var(--amber); color: var(--ink); }
.hd-verdict--ok { background: color-mix(in srgb, var(--viridian) 16%, var(--card, var(--paper))); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--viridian); }
.hd-verdict + .hd-step__line { margin-top: 8px; }

/* illustration chips (hidden from the twin; the frame's note says they illustrate) */
.hd-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hd-chip { padding: 3px 10px; border-radius: 999px; font-family: var(--ui); font-size: .76rem; font-weight: 800; line-height: 1.4; color: var(--ink-2); box-shadow: inset 0 0 0 1.5px rgba(21, 23, 28, .24); }
.hd-chip--flag { background: var(--amber); color: var(--ink); box-shadow: none; }

/* ---- a flow across the card, where it is wide enough ---------------------------------------- */
/* Each step's node sits above its words; the arrow runs right from this node to the next one, its dot halfway. */
@container (min-width: 700px) {
  .hd-flow:not(.hd-flow--down):not(.hd-flow--long) { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); column-gap: var(--hd-arrow-long); row-gap: 0; }
  .hd-flow:not(.hd-flow--down):not(.hd-flow--long) > .hd-step { grid-template-columns: minmax(0, 1fr); row-gap: 4px; }
  .hd-flow:not(.hd-flow--down):not(.hd-flow--long) > .hd-step:not(:last-child)::before {
    left: calc(var(--hd-node) + 6px);
    right: auto;
    width: calc(100% - var(--hd-node) - 12px + var(--hd-arrow-long));
    top: calc(var(--hd-node) / 2 - var(--hd-arrow-thick) / 2);
    bottom: auto;
    height: var(--hd-arrow-thick);
    -webkit-mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
    mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
  }
  .hd-flow:not(.hd-flow--down):not(.hd-flow--long) > .hd-step:not(:last-child)::after { left: calc(50% + (var(--hd-node) + var(--hd-arrow-long)) / 2); top: calc(var(--hd-node) / 2); }
  .hd-flow:not(.hd-flow--down):not(.hd-flow--long) .hd-step__copy { padding-top: 6px; }
}
@container (min-width: 940px) {
  .hd-flow--long { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); column-gap: var(--hd-arrow-long); row-gap: 0; }
  .hd-flow--long > .hd-step { grid-template-columns: minmax(0, 1fr); row-gap: 4px; }
  .hd-flow--long > .hd-step:not(:last-child)::before {
    left: calc(var(--hd-node) + 6px);
    right: auto;
    width: calc(100% - var(--hd-node) - 12px + var(--hd-arrow-long));
    top: calc(var(--hd-node) / 2 - var(--hd-arrow-thick) / 2);
    bottom: auto;
    height: var(--hd-arrow-thick);
    -webkit-mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
    mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
  }
  .hd-flow--long > .hd-step:not(:last-child)::after { left: calc(50% + (var(--hd-node) + var(--hd-arrow-long)) / 2); top: calc(var(--hd-node) / 2); }
  .hd-flow--long .hd-step__copy { padding-top: 6px; }
}

/* A flow kept down a wide card (a long one before it fits across): a step's chips move right of its words, so they read
   as one column that only grows from step to step; a gate's stop stays under its line. */
@container (min-width: 700px) {
  .hd-flow--down .hd-step__copy:has(> .hd-chips) { display: grid; grid-template-columns: minmax(0, 34ch) minmax(0, 1fr); column-gap: 28px; align-items: start; }
  .hd-flow--down .hd-step__copy:has(> .hd-chips) > * { grid-column: 1; }
  .hd-flow--down .hd-step__copy:has(> .hd-chips) > .hd-chips { grid-column: 2; grid-row: 1 / span 2; align-self: stretch; align-content: flex-start; margin-top: 0; padding: 2px 0 2px 16px; border-left: 2px dashed rgba(21, 23, 28, .18); }
}
@container (min-width: 700px) and (max-width: 939px) {
  .hd-flow--long .hd-step__copy:has(> .hd-chips) { display: grid; grid-template-columns: minmax(0, 34ch) minmax(0, 1fr); column-gap: 28px; align-items: start; }
  .hd-flow--long .hd-step__copy:has(> .hd-chips) > * { grid-column: 1; }
  .hd-flow--long .hd-step__copy:has(> .hd-chips) > .hd-chips { grid-column: 2; grid-row: 1 / span 2; align-self: stretch; align-content: flex-start; margin-top: 0; padding: 2px 0 2px 16px; border-left: 2px dashed rgba(21, 23, 28, .18); }
}

/* ---- lanes: how something ages, and what takes over ---------------------------------------- */
/* Down the card: the first lane, the handoff (its own down arrow), the second lane. */
.hd-lanes { display: grid; }
.hd-lane__name { margin: 0 0 14px; font-family: var(--ui); font-size: .82rem; font-weight: 800; letter-spacing: .01em; color: var(--ink-3); }
.hd-lane .hd-step--step .hd-step__node::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--paper); }
.hd-handoff { position: relative; margin: 0; padding: 18px 0 22px calc(var(--hd-node) + 16px); min-height: calc(var(--hd-arrow-down) + 24px); font-size: .92rem; line-height: 1.45; color: var(--ink-2); max-width: 46ch; }
.hd-handoff::before {
  content: "";
  position: absolute;
  left: calc(var(--hd-node) / 2 - var(--hd-arrow-thick) / 2);
  width: var(--hd-arrow-thick);
  top: 6px;
  bottom: 6px;
  background-color: var(--ink-3);
  -webkit-mask: var(--hd-head-down) center bottom / var(--hd-arrow-thick) 14px no-repeat, linear-gradient(black, black) center top / var(--hd-stroke) calc(100% - 3px) no-repeat;
  mask: var(--hd-head-down) center bottom / var(--hd-arrow-thick) 14px no-repeat, linear-gradient(black, black) center top / var(--hd-stroke) calc(100% - 3px) no-repeat;
}
.hd-handoff::after { content: ""; position: absolute; left: calc(var(--hd-node) / 2); top: 50%; width: var(--hd-dot); height: var(--hd-dot); border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px var(--card, var(--paper)); transform: translate(-50%, -50%); }

/* Side by side, where the card is wide: one grid, a row per state, so time runs down both lanes and the second starts
   level with the state that hands over. The handoff sits between them, its arrow running right. */
@container (min-width: 640px) {
  .hd-lanes { grid-template-columns: minmax(0, 1fr) minmax(0, 170px) minmax(0, 1fr); row-gap: var(--hd-arrow-down); align-items: start; }
  .hd-lane,
  .hd-lane__states { display: contents; }
  .hd-lane > .hd-lane__name,
  .hd-lane__states > .hd-step { grid-row: var(--hd-row); }
  .hd-lane--1 > .hd-lane__name,
  .hd-lane--1 .hd-step { grid-column: 1; }
  .hd-lane--2 > .hd-lane__name,
  .hd-lane--2 .hd-step { grid-column: 3; }
  /* a lane's name sits just above its first state, in the gap, not a full gap away from it */
  .hd-lanes { margin-top: calc(14px - var(--hd-arrow-down)); }
  .hd-lane__name { margin: 0; align-self: end; transform: translateY(calc(var(--hd-arrow-down) - 12px)); }
  .hd-lane__states > .hd-step { align-self: stretch; }
  /* the dot sits halfway down the gap below the node, whatever the row's height */
  .hd-lane__states > .hd-step:not(:last-child)::after { top: auto; bottom: calc(-1 * var(--hd-arrow-down) / 2); transform: translate(-50%, 50%); }
  .hd-handoff { grid-column: 2; grid-row: var(--hd-row); min-height: 0; padding: calc(var(--hd-node) + 4px) 14px 0 10px; font-size: .86rem; }
  .hd-handoff::before {
    left: -8px;
    right: 6px;
    width: auto;
    top: calc(var(--hd-node) / 2 - var(--hd-arrow-thick) / 2);
    bottom: auto;
    height: var(--hd-arrow-thick);
    -webkit-mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
    mask: var(--hd-head-right) right center / 14px var(--hd-arrow-thick) no-repeat, linear-gradient(black, black) left center / calc(100% - 3px) var(--hd-stroke) no-repeat;
  }
  .hd-handoff::after { left: 50%; top: calc(var(--hd-node) / 2); }
}

/* ---- parts: the labeled parts of one thing ------------------------------------------------- */
.hd-parts { margin-top: 12px; padding: 14px 16px; border-radius: var(--radius-sm, 10px); background: color-mix(in srgb, var(--paper) 55%, var(--card, var(--paper))); box-shadow: inset 0 0 0 1px rgba(21, 23, 28, .12); }
.hd-parts dl { margin: 0; display: grid; gap: 12px; }
.hd-parts dt { font-family: var(--ui); font-size: .78rem; font-weight: 800; color: var(--ink-3); }
.hd-parts dd { margin: 2px 0 0; font-size: .98rem; line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.hd-parts__rest { margin-top: 14px; padding-top: 12px; border-top: 1px dashed rgba(21, 23, 28, .2); }
.hd-parts__restname { margin: 0; font-family: var(--ui); font-size: .78rem; font-weight: 800; color: var(--ink-3); }
.hd-parts__rest ul { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.hd-parts__rest li { padding: 3px 11px; border-radius: 999px; font-family: var(--ui); font-size: .8rem; font-weight: 700; line-height: 1.4; color: var(--ink-2); border: 1.5px dashed rgba(21, 23, 28, .3); }
@container (min-width: 560px) {
  .hd-parts dl { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); column-gap: 20px; }
}

/* ---- bars: a few bars from numbers the page prints ----------------------------------------- */
.hd-bars { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; }
.hd-bars__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 6px; align-items: center; }
.hd-bars__label { grid-column: 1 / -1; font-family: var(--ui); font-size: .92rem; font-weight: 800; color: var(--ink); }
.hd-bars__track { height: 12px; border-radius: 6px; background: rgba(21, 23, 28, .08); overflow: hidden; }
.hd-bars__fill { display: block; height: 100%; width: calc(var(--hd-share, 0) * 100%); border-radius: 6px; background: var(--harbor); }
.hd-bars__value { font-family: var(--ui); font-size: .9rem; font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; }
@container (min-width: 520px) {
  .hd-bars__row { grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) minmax(0, 7rem); }
  .hd-bars__label { grid-column: auto; }
}

/* ---- a phone's card ------------------------------------------------------------------------ */
/* The name and its tag would touch on one line: the tag goes under the name, left-aligned (the gate rail's FIX-3). */
@container (max-width: 420px) {
  .hd__head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .hd__tag { text-align: left; }
}
