/* How it works: the four steps as cards on the app's factory canvas
   (group zones on a dot grid, ports, curved wires). 03-how.js draws the wires
   and runs the packet; without it every card shows its finished state. */

.how { padding: clamp(96px, 12vw, 160px) 0 0; }

.how-head { display: grid; gap: 16px; margin-bottom: clamp(40px, 5vw, 64px); }
.how-title { font-size: clamp(32px, 4.2vw, 52px); max-width: 15ch; }
.how-lede { max-width: 44ch; font-size: 17px; line-height: 1.55; color: var(--body); }
@media (min-width: 900px) {
  .how-head { grid-template-columns: 1.3fr 1fr; align-items: end; gap: 48px; }
  .how-lede { justify-self: end; }
}

/* The frame: an app window with a header bar over the canvas pane. */
.how-frame {
  width: min(1360px, calc(100% - 2 * var(--gutter))); margin-inline: auto;
  border: 1px solid transparent; border-radius: var(--radius-lg); overflow: hidden;
  background: linear-gradient(var(--sunk), var(--sunk)) padding-box,
    linear-gradient(to bottom, rgb(255 255 255 / 0.12), rgb(255 255 255 / 0.03) 40%, var(--line)) border-box;
  box-shadow: var(--shadow-card);
}
.how-bar {
  display: flex; align-items: center; gap: 12px 16px; min-height: 56px; padding: 6px 8px 6px 18px;
  border-bottom: 1px solid var(--line); background: var(--card);
  background-image: linear-gradient(to bottom, rgb(255 255 255 / 0.018), transparent);
}
.how-bar-task { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; font-size: 14px; }
.how-bar-ref { font-size: 12.5px; color: var(--muted); }
.how-bar-name { color: var(--title); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.how-bar-status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--body); white-space: nowrap; font-variant-numeric: tabular-nums; }
.how-bar-step { margin-left: -3px; }
.how-bar-step::before { content: "· "; }
.how-bar-step:empty { display: none; }
.how-replay {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--ink); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.how-replay svg { transition: transform var(--dur-base) var(--ease); }
.how-replay:hover { border-color: var(--line-strong); background-color: rgb(255 255 255 / 0.035); color: var(--link); }
.how-replay:hover svg { transform: rotate(-35deg); }
.how-replay[hidden] { display: none; }
.how-bar-ref { white-space: nowrap; }
@media (max-width: 560px) {
  .how-bar-name, .how-bar-step { display: none; }
}

/* The pane: the app's 18px dot grid, moved a little by scroll. */
.how-pane { position: relative; overflow: hidden; padding: 44px 28px 32px; }
.how-grid {
  position: absolute; inset: -60px 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--line-strong) 1px, transparent 1.3px);
  background-size: 18px 18px; background-position: 9px 9px; opacity: 0.7; will-change: transform;
}
.how-stage { position: relative; transform-origin: 50% 0; }
.how-wires { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }

/* Wires: quiet curves with an arrowhead; the lit copy carries the packet. */
.how-edge { fill: none; stroke: var(--line-strong); stroke-width: 1.5; stroke-linecap: round; }
.how-edge { transition: stroke var(--dur-base) var(--ease); }
.how-edge.wire-on { stroke: var(--lime); stroke-width: 2; }
.how:not([data-inview]) .wire-on { animation-play-state: paused; }
.how-arrow { fill: var(--line-strong); }
.how-arrow-on { fill: var(--lime); }
.how-edge-lit { fill: none; stroke: var(--lime); stroke-width: 2; stroke-linecap: round; opacity: 0; }
.how-packet { opacity: 0; transition: opacity 240ms var(--ease); }
.how-packet.is-on { opacity: 1; }
.how-packet-halo { fill: var(--lime-soft); stroke: var(--lime-line); stroke-width: 1; }
.how-packet-core { fill: var(--lime); }

/* Flow: three zones in a row (desktop), stacked (below 1140px). */
.how-flow { position: relative; display: grid; gap: 52px; max-width: 520px; margin-inline: auto; }
.how-zone {
  --wash: var(--muted); --zl: var(--line-strong); --zw: rgb(255 255 255 / 0.035);
  position: relative; display: grid; gap: 40px; padding: 26px 12px 12px;
  border: 1px solid var(--zl); border-radius: 16px;
  background: linear-gradient(to right, var(--zw), rgb(21 24 29 / 0.5) 85%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.03);
}
.how-zone-once { --wash: var(--info); --zl: rgb(59 125 216 / 0.3); --zw: rgb(59 125 216 / 0.11); }
.how-zone-any { --wash: var(--success); --zl: rgb(31 157 111 / 0.3); --zw: rgb(31 157 111 / 0.11); }
.how-badge { --wash: inherit; position: absolute; top: -12px; left: 14px; }

/* Tablet: a staircase. Step 1 top left, steps 2-3 across, step 4 bottom right. */
@media (min-width: 720px) and (max-width: 1139px) {
  .how-flow { grid-template-columns: 1fr 1fr; gap: 56px 36px; max-width: 900px; }
  .how-zone-session { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: 36px; }
  .how-zone-any { grid-column: 2; }
}
@media (min-width: 1140px) {
  .how-flow { grid-template-columns: 1fr 2.06fr 1fr; gap: 44px; max-width: none; align-items: stretch; }
  .how-zone-session { grid-template-columns: 1fr 1fr; gap: 36px; }
}

/* Cards: the app's canvas card. */
.how-card {
  position: relative; display: flex; flex-direction: column; min-width: 0; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.045), var(--shadow-card);
  transition: border-color var(--dur-slow) var(--ease), box-shadow var(--dur-slow) var(--ease);
}
.how-card:hover { border-color: var(--line-strong); }
.how-card.is-picked {
  border-color: var(--lime);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.045), 0 0 0 0.5px var(--lime), 0 0 0 4.5px rgb(111 181 65 / 0.22), var(--shadow-card);
}
.how-card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 0%), rgb(255 255 255 / 0.05), transparent 70%);
  opacity: 0; transition: opacity var(--dur-base) var(--ease);
}
@media (hover: hover) { .how-card:hover::after { opacity: 1; } }

.how-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.how-chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px;
  background: var(--raised); color: var(--body-strong); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05);
  transition: background-color var(--dur-base) var(--ease), color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
.how-zone-once .how-chip { background: var(--info-soft); color: var(--info-ink); }
.how-zone-any .how-chip { background: var(--success-soft); color: var(--success-ink); }
.how-card.is-picked .how-chip { background: var(--card); color: var(--lime-ink); box-shadow: inset 0 0 0 1px var(--lime-line); }
.how-key { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.how-card-copy { margin: 12px 0 16px; }
.how-card-title { font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.how-card-text { margin-top: 6px; font-size: 13.5px; line-height: 1.5; color: var(--body); }

/* Ports: top/bottom near the right edge on phones (clear of the zone badges),
   per wire on the tablet staircase, left/right on desktop. 03-how.js reads
   which edge each port sits on to bend its wire. */
.how-port {
  position: absolute; z-index: 1; width: 9px; height: 9px; border-radius: 50%;
  background: var(--card); border: 1.5px solid var(--line-strong); box-shadow: 0 0 0 2px var(--sunk);
  transition: background-color var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
.how-port-in { top: -5px; right: 36px; }
.how-port-out { bottom: -5px; right: 36px; }
@media (min-width: 720px) and (max-width: 1139px) {
  .how-port-in, .how-port-out { right: auto; left: 50%; margin-left: -4.5px; }
  .how-card[data-step="2"] .how-port-out { left: auto; right: -5px; bottom: auto; top: 50%; margin: -4.5px 0 0; }
  .how-card[data-step="3"] .how-port-in { left: -5px; top: 50%; margin: -4.5px 0 0; }
}
@media (min-width: 1140px) {
  .how-port { top: 50%; margin-top: -4.5px; }
  .how-port-in { left: -5px; right: auto; }
  .how-port-out { right: -5px; bottom: auto; }
}
.how-card[data-state="done"] .how-port { background: var(--line-strong); }
.how-card.is-picked .how-port { background: var(--lime); border-color: var(--lime); box-shadow: 0 0 0 2px var(--sunk), 0 0 0 3.5px var(--lime-line); }

/* Payload: a tiny real-looking result inset at the foot of the card. */
.how-payload {
  margin: auto 0 0; padding: 10px; list-style: none;
  border: 1px solid var(--line-soft); border-radius: 9px; background: rgb(11 13 16 / 0.55);
  box-shadow: inset 0 1px 0 rgb(0 0 0 / 0.25);
  font-size: 12.5px; line-height: 1.45; color: var(--body);
}
.how-payload b { color: var(--title); font-weight: 600; }
/* Not reached yet: an empty dashed slot, like a canvas card waiting for its step. */
.how[data-armed] .how-card:not([data-state]) .how-payload { border-style: dashed; border-color: var(--line-strong); background: transparent; box-shadow: none; }
.how-payload .mono { font-size: 11.5px; font-weight: 500; }
.how-payload .ref { font-size: 11.5px; padding-inline: 1px; }

/* Revealed in sequence once the card has been reached (only while JS runs the flow). */
.how[data-armed] .how-seq { opacity: 0; transform: translateY(6px); transition: opacity 420ms var(--ease), transform 420ms var(--ease); }
.how[data-armed] .how-card[data-state] .how-seq { opacity: 1; transform: none; transition-delay: calc(var(--i, 0) * 260ms + 180ms); }

/* Step 1: the connector entry. */
.how-conn { display: flex; align-items: center; gap: 10px; }
.how-conn-mark { width: 30px; height: 30px; border-radius: 8px; background-color: var(--raised); }
.how-conn-name { display: grid; min-width: 0; line-height: 1.3; }
.how-conn-name span { font-size: 12px; color: var(--muted); }
.how-conn-state { position: relative; display: grid; justify-items: end; margin-left: auto; }
.how-conn-state > span { grid-area: 1 / 1; padding-left: 8px; }
.how-conn-state i { width: 6px; height: 6px; border-radius: 50%; }
.how-conn-wait { opacity: 0; }
.how-conn-wait i { background: var(--muted); }
.how-conn-ok i { background: var(--success); }
.how[data-armed] .how-conn-wait { opacity: 1; transition: opacity 240ms var(--ease) 0ms; }
.how[data-armed] .how-conn-ok { opacity: 0; transition: opacity 240ms var(--ease) 0ms; }
.how[data-armed] .how-card[data-state] .how-conn-wait { opacity: 0; transition-delay: 1000ms; }
.how[data-armed] .how-card[data-state] .how-conn-ok { opacity: 1; transition-delay: 1060ms; }
.how-conn-foot { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); }

/* Step 2: the bootstrap result. */
.how-boot { display: grid; gap: 4px; }
.how-boot li { display: flex; align-items: center; gap: 9px; min-height: 22px; }
.how-boot li .ref + span { margin-left: -3px; }
.how-boot i { width: 6px; height: 6px; flex: none; border-radius: 50%; }
.how-tone-neutral { background: var(--muted); }
.how-tone-info { background: var(--info); }
.how-tone-warning { background: var(--warning); }

/* Step 3: the claim, its heartbeat and what it reported. */
.how-claim { display: flex; align-items: center; gap: 9px; }
.how-av { background-color: var(--av, var(--id-blue)); color: var(--title); }
.how-claim-who, .how-pick-who { display: grid; min-width: 0; line-height: 1.25; }
.how-claim-who span, .how-pick-who span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.how-live { margin-left: auto; padding-left: 8px; }
/* Live dots only pulse while the section is on screen and their card has been reached. */
.how:not([data-inview]) .live-dot,
.how[data-armed] .how-card:not([data-state]) .live-dot { animation-play-state: paused; }

.how-beat { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 11.5px; color: var(--muted); }
.how-beat-track { position: relative; flex: 1; height: 16px; overflow: hidden; }
.how-beat-run { position: absolute; left: 0; top: 0; width: 480px; height: 16px; max-width: none; }
.how-beat-run path { fill: none; stroke: var(--lime); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.how[data-inview] .how-beat-run { animation: how-beat 1.5s linear infinite; }
@keyframes how-beat { to { transform: translateX(-60px); } }

.how-events { margin: 8px 0 0; padding: 8px 0 0; list-style: none; border-top: 1px solid var(--line-soft); display: grid; gap: 3px; }
.how-events li { display: flex; align-items: baseline; gap: 6px; }
.how-events li .ref + span { margin-left: 1px; }

/* Step 4: the same record, opened from whichever tool. */
.how-tools { display: flex; gap: 6px; }
.how-tool {
  position: relative; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--raised); border: 1px solid var(--line); color: var(--muted);
  background-image: linear-gradient(to bottom, rgb(255 255 255 / 0.04), transparent 60%);
  transition: color var(--dur-slow) var(--ease);
}
.how-tool svg { width: 16px; height: 16px; }
.how-tool::after {
  content: ""; position: absolute; inset: -1px; border-radius: 9px; border: 1.5px solid var(--lime);
  box-shadow: 0 0 0 3px var(--lime-line); opacity: 0; transition: opacity var(--dur-slow) var(--ease);
}
.how-tool[data-on] { color: var(--title); }
.how-tool[data-on]::after { opacity: 1; }
.how-pick { display: flex; align-items: center; gap: 9px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.how-status { --wash: var(--info); margin-left: auto; }

@media (max-width: 1139px) {
  .how-pane { padding: 40px 16px 24px; }
}
@media (max-width: 420px) {
  .how-frame { border-radius: var(--radius); }
  .how-pane { padding: 36px 12px 20px; }
  .how-zone { padding: 26px 10px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .how-beat-run, .how-live .live-dot, .how-bar-dot, .how-edge.wire-on { animation: none !important; }
  .how-stage, .how-grid { transform: none !important; }
}
