/* ==========================================================================
   how-it-works.css — the private "how the system works" explainer page only.
   Uses the shared design tokens from styles.css; defines nothing site-wide.

   THE DIAGRAM COORDINATE SPACE is 1040 x 910 units (HIW_W / HIW_H in
   how-it-works.php). Boxes, bands and labels carry --x/--y(/--w/--h) in those
   units and are placed as percentages here; the SVG arrows use the same
   viewBox. If you change the space, change the two numbers in BOTH files.

   Text inside the diagram is sized in cqw (1% of the diagram's width) with a
   px floor, so it shrinks with the drawing but never below readable.
   ========================================================================== */

.hiw-hero { padding-bottom: 28px; }
.hiw-hero .lead { max-width: 720px; }
.hiw-private { font-family: var(--font-ui); font-size: 13px; letter-spacing: .04em; color: var(--muted-2); margin: 14px 0 0; }

.hiw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
  padding-bottom: 64px;
}
.hiw-stage { min-width: 0; }
.hiw-instructions { font-family: var(--font-ui); font-weight: 600; font-size: 15px; color: var(--muted); margin: 0 0 12px; }

/* ---------- The diagram ---------- */
.hiw-diagram {
  position: relative;
  aspect-ratio: 1040 / 910;
  container-type: inline-size;
}
.hiw-band, .hiw-node, .hiw-label { position: absolute; }
.hiw-band, .hiw-node {
  left:   calc(var(--x) / 1040 * 100%);
  top:    calc(var(--y) / 910 * 100%);
  width:  calc(var(--w) / 1040 * 100%);
  height: calc(var(--h) / 910 * 100%);
}
.hiw-label {
  left: calc(var(--x) / 1040 * 100%);
  top:  calc(var(--y) / 910 * 100%);
  transform: translate(-50%, -50%);
}
.hiw-edges { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.hiw-band { border-radius: clamp(8px, 1.6cqw, 16px); }
.hiw-band--call  { background: var(--alt-bg); border: 1px solid var(--line); }
.hiw-band--after { background: var(--input-bg); border: 1.5px dashed var(--line); }
.hiw-band-label {
  position: absolute; left: 1.9cqw; top: 1.2cqw;
  font-family: var(--font-ui); font-weight: 700; text-transform: uppercase;
  font-size: clamp(9.5px, 1.75cqw, 13px); letter-spacing: .14em; color: var(--accent);
}

/* Arrows */
.hiw-edge { transition: opacity .2s ease; }
.hiw-edge path { fill: none; stroke: var(--muted-2); stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; transition: stroke .2s ease, stroke-width .2s ease; }
.hiw-edge polygon { fill: var(--muted-2); transition: fill .2s ease; }
.hiw-edge.is-lit path { stroke: var(--accent); stroke-width: 7; }
.hiw-edge.is-lit polygon { fill: var(--accent); }

.hiw-label {
  font-family: var(--font-ui); font-weight: 600; line-height: 1.12;
  font-size: clamp(9.5px, 1.9cqw, 14px);
  color: var(--muted); text-align: center; white-space: nowrap;
  pointer-events: none; transition: color .2s ease, opacity .2s ease;
}
.hiw-label span { font-weight: 500; color: var(--muted-2); }
.hiw-label--right { transform: translate(-100%, -50%); text-align: right; }
.hiw-label.is-lit { color: var(--accent-hover); font-weight: 700; }
.hiw-label.is-lit span { color: var(--accent-hover); }

/* Boxes */
.hiw-node {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .25cqw;
  padding: .6cqw .8cqw; margin: 0;
  background: #fff; color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: clamp(6px, 1.2cqw, 11px);
  text-align: center; cursor: pointer;
  transition: background .18s ease, color .18s ease, border-color .18s ease, box-shadow .18s ease, opacity .2s ease, transform .18s ease;
}
.hiw-node-title { font-family: var(--font-headline); font-weight: 700; font-size: clamp(12.5px, 3.1cqw, 23px); line-height: 1.02; letter-spacing: 0; }
.hiw-node-sub,
.hiw-node-extra { font-family: var(--font-ui); font-weight: 500; font-size: clamp(9.5px, 1.95cqw, 14px); line-height: 1.1; color: var(--muted); }
.hiw-node-tag {
  font-family: var(--font-ui); font-weight: 700; text-transform: uppercase;
  font-size: clamp(8.5px, 1.45cqw, 11px); letter-spacing: .08em; color: var(--accent);
}
.hiw-node:hover { box-shadow: 0 4px 14px rgba(26, 25, 22, .14); transform: translateY(-1px); }
@container (max-width: 520px) {
  .hiw-node-extra { display: none; }
}

/* Focus states (boxes, chips, tour buttons) */
.hiw-node:focus-visible,
.hiw-chip:focus-visible,
.hiw-tour button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Something is selected / previewed / being toured: dim the rest */
.hiw-diagram.is-focused .hiw-edge:not(.is-lit) { opacity: .25; }
.hiw-diagram.is-focused .hiw-label:not(.is-lit) { opacity: .4; }
.hiw-diagram.is-focused .hiw-node:not(.is-selected):not(.is-related) { opacity: .5; }
.hiw-node.is-related { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.hiw-node.is-selected { background: var(--ink); color: var(--paper); border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent); }
.hiw-node.is-selected .hiw-node-sub,
.hiw-node.is-selected .hiw-node-extra { color: var(--dark-text); }
.hiw-node.is-selected .hiw-node-tag { color: var(--accent-warm); }

/* ---------- Supporting pieces (outside the call flow) ---------- */
.hiw-extras { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.hiw-extras-label { font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted-2); flex-basis: 100%; }
.hiw-chip {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px;
  font-family: var(--font-ui); font-size: 15px; text-align: left; color: var(--ink);
  background: transparent; border: 1.5px dashed var(--ink-2); border-radius: 9px;
  padding: 9px 14px; cursor: pointer;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.hiw-chip strong { font-weight: 700; }
.hiw-chip span { color: var(--muted); font-size: 14px; }
.hiw-chip:hover { background: #fff; border-color: var(--ink); }
.hiw-chip.is-selected { background: var(--ink); color: var(--paper); border-style: solid; border-color: var(--ink); }
.hiw-chip.is-selected span { color: var(--dark-text); }

/* ---------- Follow one call ---------- */
.hiw-tour {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  margin-top: 18px; padding: 14px 16px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
}
.hiw-tour[hidden], .hiw-tour [hidden] { display: none; }
.hiw-tour .btn { font-size: 16px; padding: 10px 18px; }
.hiw-tour .btn--outline { padding: 9px 16px; }
.hiw-tour-stop {
  font-family: var(--font-ui); font-weight: 700; font-size: 15px; color: var(--muted);
  background: none; border: none; padding: 8px 6px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.hiw-tour-stop:hover { color: var(--ink); }
.hiw-tour-status { flex: 1 1 220px; margin: 0; font-size: 16px; line-height: 1.4; color: var(--body-text); }
.hiw-tour-status b { font-family: var(--font-ui); color: var(--accent); margin-right: 4px; }

/* ---------- Explanation panel ---------- */
.hiw-panel {
  position: sticky; top: 100px;
  max-height: calc(100vh - 120px); overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 26px 22px;
}
.hiw-panel:focus { outline: none; }
.hiw-panel [data-panel][hidden] { display: none; }
.hiw-kicker { font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.hiw-panel-title { font-size: clamp(26px, 2.6vw, 32px); line-height: 1.02; margin: 0 0 16px; text-wrap: balance; }
.hiw-panel p, .hiw-panel li, .hiw-panel dd { font-size: 16.5px; line-height: 1.6; color: var(--body-text); }
.hiw-panel p { margin: 0 0 .9rem; }
.hiw-panel strong { color: var(--ink); }
.hiw-panel code { font-size: .88em; background: var(--alt-bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: var(--ink-2); white-space: nowrap; }
.hiw-hint { font-family: var(--font-ui); font-size: 15px !important; color: var(--muted-2) !important; }
.hiw-note { background: var(--badge-bg); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 15.5px !important; }

.hiw-role-card { margin: 0 0 18px; padding: 12px 14px; background: var(--alt-bg); border-radius: 10px; }
.hiw-role-card div { display: grid; grid-template-columns: 96px 1fr; gap: 10px; }
.hiw-role-card div + div { margin-top: 6px; }
.hiw-role-card dt { font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); padding-top: 4px; }
.hiw-role-card dd { margin: 0; font-size: 15.5px !important; line-height: 1.45 !important; color: var(--ink) !important; }

.hiw-roles { margin: 0 0 16px; }
.hiw-roles div { padding: 10px 0; border-top: 1px solid var(--line); }
.hiw-roles div:last-child { border-bottom: 1px solid var(--line); }
.hiw-roles dt { font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); }
.hiw-roles dd { margin: 2px 0 0; font-size: 15.5px !important; line-height: 1.45 !important; }

.hiw-steps { margin: 0; padding-left: 1.4rem; }
.hiw-steps li { padding: 5px 0 5px 4px; color: var(--muted-2); transition: color .2s ease; }
.hiw-steps li::marker { font-family: var(--font-ui); font-weight: 700; }
.hiw-steps li.is-done { color: var(--body-text); }
.hiw-steps li.is-current { color: var(--ink); font-weight: 600; }
.hiw-steps li.is-current::marker { color: var(--accent); }

/* ---------- Summary ---------- */
.hiw-summary-wrap { padding-bottom: 88px; }
.hiw-summary { background: var(--dark); color: var(--dark-text); border-radius: 16px; padding: clamp(28px, 4vw, 48px); }
.hiw-summary-list { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 10px; }
.hiw-summary-list li { font-size: clamp(18px, 2vw, 22px); line-height: 1.35; padding-left: 22px; position: relative; }
.hiw-summary-list li::before { content: ""; position: absolute; left: 0; top: .55em; width: 9px; height: 9px; border-radius: 2px; background: var(--accent-warm); }
.hiw-summary-list strong { color: var(--paper); font-weight: 600; }
.hiw-summary-line { font-family: var(--font-headline); font-weight: 700; font-size: clamp(26px, 3.4vw, 40px); line-height: 1.05; color: var(--paper); margin: 0 0 18px; text-wrap: balance; }
.hiw-summary-line em { font-style: normal; color: var(--accent-warm); }
.hiw-status { margin: 0; font-size: 15px; line-height: 1.55; color: var(--dark-muted); }

/* ---------- Narrow screens: panel drops below the diagram ---------- */
@media (max-width: 960px) {
  .hiw-layout { grid-template-columns: 1fr; gap: 24px; }
  .hiw-stage { width: 100%; max-width: 760px; }
  .hiw-panel { position: static; max-height: none; overflow: visible; max-width: 760px; }
}
@media (max-width: 480px) {
  .hiw-stage { margin-left: -8px; margin-right: -8px; width: auto; }
  .hiw-panel { padding: 20px 18px 16px; }
  .hiw-role-card div { grid-template-columns: 1fr; gap: 0; }
  .hiw-tour .btn { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .hiw-node, .hiw-chip, .hiw-edge, .hiw-edge path, .hiw-edge polygon, .hiw-label, .hiw-steps li { transition: none; }
  .hiw-node:hover { transform: none; }
}
