/* Discovery, made visual (/implementation#process, October 15; scripts/discovery_visual.py).
   Three pieces replace a wall of text: the messy-problem sorter (Rob's deck slide as a diagram), "Where to look first"
   as four checkpoints with two small scenes, and the question bank as icon cards.

   Motion contract (assets/onboarding-scenes.js drives every [data-ob-scene] here):
   - No script: nothing animates; every element shows its finished state.
   - [data-ob-run]: animations attach, paused until [data-ob-live] (40% visible, tab shown, page not left).
   - Keyframes animate FROM a start value TO the element's resting style, so the resting style is the end state.
   - Only transform (translate/scale) and opacity move. Reading copy never fades: in the sorter only the ticks, the
     route, and the zone highlight move; the two card scenes are aria-hidden illustrations ([data-illustration-loop]).
   - Story times (--t) are literal offsets on each scene's own clock; durations and curves are theme tokens. */

/* ---------- 1. The messy-problem sorter ---------- */
.msy {
  --msy-story: 3.4s;
  position: relative;
  scroll-margin-top: calc(var(--header-h, 72px) + 24px);
  margin-top: 40px;
  padding: clamp(24px, 3vw, 36px) clamp(22px, 3vw, 36px) clamp(24px, 3vw, 32px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
}
.msy::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: linear-gradient(180deg, var(--horizon-1), var(--horizon-2), var(--horizon-3)); }
.msy-head { max-width: 660px; }
.msy-head h3 { margin: 0 0 8px; font-size: clamp(21px, 0.8vw + 15px, 26px); line-height: 1.2; letter-spacing: -0.025em; }
.msy-head p { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--fg-2); }
.msy-flow { display: grid; grid-template-columns: minmax(0, 1fr) clamp(56px, 7vw, 96px) minmax(0, 1fr); align-items: center; gap: 0 14px; margin-top: 28px; }
.msy-col { min-width: 0; align-self: stretch; display: flex; flex-direction: column; }
.msy-k { margin: 0 0 12px; font-size: 15px; font-weight: 600; line-height: 1.35; letter-spacing: -0.01em; color: var(--fg); }
.msy-tests, .msy-zones { display: grid; gap: 8px; flex: 1; align-content: center; margin: 0; padding: 0; list-style: none; }

.msy-test { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.msy-test-text { font-size: 15px; font-weight: 500; line-height: 1.35; color: var(--fg); }
.msy-tick { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--horizon-line); border-radius: 50%; background: var(--horizon-soft); color: var(--horizon-ink); }
.msy-tick .icon { width: 12px; height: 12px; stroke-width: 2.4; }

.msy-route { position: relative; align-self: center; height: 40px; }
.msy-route-line, .msy-route-spark { position: absolute; top: 50%; }
.msy-route-line { left: 2px; right: 12px; height: 2px; margin-top: -1px; border-radius: 2px; background: linear-gradient(90deg, var(--line-3), var(--fg-3)); transform-origin: 0 50%; }
.msy-route-spark { left: 2px; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--horizon-2); box-shadow: 0 0 0 4px var(--horizon-soft); opacity: 0; }
.msy-route-head { position: absolute; right: -2px; top: 50%; translate: 0 -50%; display: grid; color: var(--fg-2); }

.msy-zones li { min-width: 0; }
.msy-zone { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 44px; padding: 7px 12px 7px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--fg); font-size: 15px; font-weight: 500; text-decoration: none; transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-2) var(--ease-out), scale var(--dur-1) var(--ease); }
.msy-zone-icon { position: relative; display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-subtle); color: var(--fg-2); }
/* The highlight that walks the zones tints the icon tile (its own layer, so only opacity moves). It is not a focus or
   selection ring, and it steps aside while the reader is pointing at or tabbing through the links. */
.msy-zone-icon::after { content: ""; position: absolute; inset: -1px; border-radius: inherit; border: 1px solid var(--horizon-line); background: var(--horizon-soft); opacity: 0; pointer-events: none; }
.msy-zone-icon .icon { position: relative; z-index: 1; }
.msy-zone-icon .icon { width: 15px; height: 15px; }
.msy-zone:is(:hover, :focus-visible) .msy-zone-icon { color: var(--fg); }
.msy-zone-arrow { color: var(--fg-3); transition: transform var(--dur-2) var(--ease-out), color var(--dur-1) var(--ease); }
.msy-zone:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
@media (hover: hover) {
  .msy-zone:hover { border-color: var(--line-3); box-shadow: var(--shadow-2); }
  .msy-zone:hover .msy-zone-arrow { transform: translateX(3px); color: var(--fg); }
}
.msy-zone:active { scale: var(--press-lg); }

@keyframes msy-spark {
  0% { opacity: 0; translate: 0 0; }
  12% { opacity: 1; }
  78% { opacity: 1; }
  100% { opacity: 0; translate: var(--msy-run, 60px) 0; }
}
@keyframes msy-lit {
  0%, 26%, 100% { opacity: 0; }
  5%, 17% { opacity: 1; }
}
.msy[data-ob-run] .ob-clock { animation: ob-clock var(--msy-story) linear both; }
.msy[data-ob-run] .msy-tick { animation: ob-pop var(--dur-3) var(--ease-spring) calc(0.25s + var(--i) * 0.42s) both; }
.msy[data-ob-run] .msy-route-line { animation: ob-grow-x var(--dur-4) var(--ease-out) 1.95s both; }
.msy[data-ob-run] .msy-route-head { animation: ob-pop var(--dur-3) var(--ease-spring) 2.4s both; }
/* After the story: a spark keeps carrying work across, and the highlight walks the five zones (8s round). */
.msy[data-ob-run] .msy-route { container-type: inline-size; }
.msy[data-ob-run] .msy-route-spark { --msy-run: calc(100cqw - 22px); animation: msy-spark 1.6s var(--ease-in-out) 2.6s infinite both; }
.msy[data-ob-run] .msy-zone-icon::after { animation: msy-lit 8s linear calc(2.9s + var(--i) * 1.6s) infinite both; }
.msy .msy-zones:is(:hover, :focus-within) .msy-zone-icon::after { animation-play-state: paused; visibility: hidden; }
.msy[data-ob-run]:not([data-ob-live]) *,
.msy[data-ob-run]:not([data-ob-live]) *::after { animation-play-state: paused !important; }

/* ---------- 2. Where to look first ---------- */
.wlf .ob-more-head { margin-bottom: 16px; }
.msy + .wlf { margin-top: 56px; }
.wlf-checks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 20px; margin: 0 0 28px; padding: 0; list-style: none; }
.wlf-checks li { display: flex; align-items: center; gap: 12px; min-width: 0; font-size: 15px; font-weight: 500; line-height: 1.35; color: var(--fg); }
.wlf-card { display: flex; flex-direction: column; }
.implementation-opportunities .wlf-card h4 { margin-top: 20px; }

.wlf-art { --wlf-story: 2.6s; position: relative; display: grid; gap: 8px; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); font-size: 13px; line-height: 1.3; color: var(--fg); -webkit-user-select: none; user-select: none; }
.wlf-art .icon { width: 14px; height: 14px; flex: none; }
.wlf-bar { display: flex; align-items: center; gap: 8px; padding: 2px 2px 8px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--fg-3); }
.wlf-time { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.wlf-row { display: flex; align-items: center; gap: 10px; height: 40px; padding: 6px 8px 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-elev); }
.wlf-msg { display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wlf-msg .icon { color: var(--fg-3); }
.wlf-msg-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wlf-state { display: inline-flex; align-items: center; gap: 6px; flex: none; margin-left: auto; padding: 3px 9px 3px 7px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--fg-2); }
.wlf-state.is-done .icon { width: 12px; height: 12px; color: var(--horizon-ink); stroke-width: 2.4; }
/* Signal orange means one thing: a person is needed (docs/design-system.md). */
.wlf-state.is-person { border-color: var(--accent-line); color: var(--fg); }
.wlf-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.wlf-progress { flex: 1; min-width: 40px; max-width: 140px; height: 4px; margin-left: auto; overflow: hidden; border-radius: 4px; background: var(--line); }
.wlf-progress i { display: block; height: 100%; border-radius: inherit; background: var(--fg-2); transform-origin: 0 50%; }
.wlf-check { display: grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--fg); color: var(--bg-elev); }
.wlf-check .icon { width: 11px; height: 11px; stroke-width: 2.6; }

.wlf-art[data-ob-run] .ob-clock { animation: ob-clock var(--wlf-story) linear both; }
.wlf-art[data-ob-run] .wlf-row { animation: ob-in var(--dur-3) var(--ease-out) calc(0.2s + var(--i) * 0.5s) both; }
.wlf-art[data-ob-run] .wlf-state { animation: ob-pop var(--dur-3) var(--ease-spring) calc(0.6s + var(--i) * 0.5s) both; }
.wlf-art[data-ob-run] .wlf-progress i { animation: ob-grow-x 0.7s var(--ease-in-out) calc(0.35s + var(--i) * 0.5s) both; }
.wlf-art[data-ob-run] .wlf-check { animation: ob-pop var(--dur-3) var(--ease-spring) calc(1.05s + var(--i) * 0.5s) both; }
.wlf-art[data-ob-run]:not([data-ob-live]) * { animation-play-state: paused !important; }

/* ---------- 3. The question bank: icon cards behind one disclosure ---------- */
.qb > summary .qb-summary-text { min-width: 0; }
.qb-count { flex: none; margin-left: auto; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; font-weight: 500; color: var(--fg-3); }
.qb > p { max-width: 70ch; margin: 0; color: var(--fg-2); line-height: 1.65; }
.qb-groups { display: grid; gap: 28px; margin: 22px 0 4px; }
.qb-group h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 17px; line-height: 1.3; }
.qb-group-icon { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-subtle); color: var(--fg-2); }
.qb-group-icon .icon { width: 16px; height: 16px; }
.qb-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin: 0; padding: 0; list-style: none; }
.qb-grid > li { grid-column: span 2; }
/* Five questions sit three over two (a six-column grid), so no card is left beside an empty slot. */
.qb-grid:has(> :nth-child(5):last-child) > li:nth-child(n+4) { grid-column: span 3; }
.qb-grid li { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 12px; min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.qb-text { display: grid; gap: 4px; min-width: 0; }
.qb-text strong { font-size: 14.5px; font-weight: 600; line-height: 1.35; color: var(--fg); }
.qb-text span { font-size: 14px; line-height: 1.5; color: var(--fg-2); }
/* Opening the bank: the cards settle into place one after another at full contrast (position only, never fade). */
@keyframes qb-settle { from { translate: 0 6px; } }
html.js .qb[open] .qb-grid li { animation: qb-settle var(--dur-3) var(--ease-out) calc(var(--i) * 40ms) both; }

/* ---------- Tablet and phone ---------- */
@media (max-width: 1100px) {
  .wlf-checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qb-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qb-grid > li, .qb-grid:has(> :nth-child(5):last-child) > li:nth-child(n+4) { grid-column: auto; }
  .qb-grid > li:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .msy-flow { grid-template-columns: minmax(0, 1fr); gap: 0; margin-top: 22px; }
  /* Stacked: the route turns downward between the signs and the places to start. */
  .msy-route { width: 40px; height: 44px; justify-self: center; rotate: 90deg; }
  .msy-tests { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msy-test { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "icon tick" "text text"; align-items: start; gap: 8px 10px; padding: 10px; }
  .msy-test-icon { grid-area: icon; }
  .msy-tick { grid-area: tick; justify-self: end; }
  .msy-test-text { grid-area: text; font-size: 14px; }
  .msy-zones { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msy-zones li:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .msy + .wlf { margin-top: 40px; }
}
@media (max-width: 720px) {
  .msy { margin-top: 32px; padding: 22px 18px 20px; }
  .msy-head p { font-size: 15px; }
  .msy-test .icon-tile { width: 32px; height: 32px; }
  .wlf-checks { gap: 14px 16px; margin-bottom: 24px; }
  .wlf-checks li { gap: 10px; font-size: 14px; }
  .wlf-checks .icon-tile { width: 32px; height: 32px; }
  .wlf-msg .icon { display: none; }
  .wlf-row { gap: 8px; padding-left: 10px; }
  .qb-grid { grid-template-columns: minmax(0, 1fr); }
  .qb-grid > li:last-child:nth-child(odd) { grid-column: auto; }
  .qb-grid li { padding: 12px; }
}
/* Phones: compact zone links (no arrow glyph); one per row below 375px, so "Cancellations" never clips. */
@media (max-width: 480px) {
  .msy-zone { gap: 8px; padding: 7px 10px 7px 8px; font-size: 14px; }
  .msy-zone-icon { width: 24px; height: 24px; border-radius: 7px; }
  .msy-zone-icon .icon { width: 14px; height: 14px; }
  .msy-zone-arrow { display: none; }
}
@media (max-width: 374px) {
  .msy-zones { grid-template-columns: minmax(0, 1fr); }
  .msy-zones li:last-child:nth-child(odd) { grid-column: auto; }
}
@media (max-width: 359px) {
  .wlf-checks { grid-template-columns: minmax(0, 1fr); }
}
@media (forced-colors: active) {
  .msy-tick, .wlf-check { background: CanvasText; color: Canvas; }
  .msy-route-line, .wlf-progress i { background: CanvasText; }
}
