/* Ping My Lab · live network scenes (js/scenes/). Tokens only, so the scenes follow the dark and the light theme.
   Markup a page writes:
     <figure class="scene" data-scene="home-web | start-ping | pan-flow | fgt-flow">
       <p class="scene-source">Source: ...</p>
     </figure>
     <script type="module" src="js/scenes/boot.js?v=..."></script>
   The script adds the stage, the caption, the fields, the controls and the numbered list of steps. State for tests
   and styling: data-step (1-based) and data-state (playing | paused | waiting | still) on the figure. */

.scene {
  --scene-glow: color-mix(in srgb, var(--teal) 55%, transparent);
  --scene-amber-glow: color-mix(in srgb, var(--amber) 55%, transparent);
  container-type: inline-size;
  position: relative;
  margin: 0;
  min-width: 0;
  padding: clamp(14px, 2.2vw, 22px);
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r-l);
  box-shadow: 0 30px 60px -36px color-mix(in srgb, var(--bg) 85%, transparent), 0 0 70px -34px var(--scene-glow);
  color: var(--ink-2);
}
.scene:not(.is-ready) { min-height: 380px; }
.scene.is-failed { min-height: 0; }

/* Order: top row and stage, then the controls, then the caption and the fields (side by side when there is room). */
.scene-live { display: grid; gap: 12px 24px; grid-template-columns: minmax(0, 1fr); }
.scene-live-b { margin-top: 16px; align-items: start; }
@container (min-width: 760px) {
  .scene-live-b { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .scene-live-b .scene-caption { font-size: 1.0625rem; }
}

/* ---------- top row ---------- */
.scene-top { display: flex; align-items: center; gap: 10px; min-width: 0; font-family: var(--f-mono); font-size: .75rem; font-weight: 600; letter-spacing: .04em; line-height: 1.4; }
.scene-pip { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.scene[data-state="playing"] .scene-pip { background: var(--teal); box-shadow: 0 0 0 0 var(--scene-glow); animation: scene-pip 1.8s ease-out infinite; }
.scene[data-state="paused"] .scene-pip { background: var(--amber); }
@keyframes scene-pip { 0% { box-shadow: 0 0 0 0 var(--scene-glow); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
.scene-name { flex: 1 1 auto; min-width: 0; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-count { flex: none; color: var(--teal); }

/* ---------- stage ---------- */
.scene-stage {

  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background-color: var(--console);
  background-image: radial-gradient(color-mix(in srgb, var(--ink-3) 26%, transparent) 1px, transparent 1.4px);
  background-size: 18px 18px;
}
.scene-svg { display: block; width: 100%; height: auto; overflow: visible; }

.scene-band rect { fill: var(--teal-tint); stroke: color-mix(in srgb, var(--teal) 30%, transparent); stroke-width: 1; stroke-dasharray: 4 5; }
.scene-band.is-out rect { fill: var(--surface-flat); stroke: var(--line-2); }
.scene-band text { fill: var(--ink-3); font-family: var(--f-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }

.scene-cable { stroke: var(--line-2); stroke-width: 2.5; stroke-linecap: round; }
.scene-cable-lit { stroke: var(--teal); stroke-width: 2.5; stroke-linecap: round; opacity: 0; transition: opacity .4s ease; }
.scene-cable-lit.is-on { opacity: .85; filter: drop-shadow(0 0 3px var(--scene-glow)); }

.scene-box { fill: var(--card); stroke: var(--line-2); stroke-width: 1.5; transition: fill .35s ease, stroke .35s ease; }
.scene-icon { fill: none; stroke: var(--ink-2); stroke-linecap: round; stroke-linejoin: round; transition: stroke .35s ease; }
.scene-label { fill: var(--ink); font-family: var(--f-body); font-size: 12.5px; font-weight: 600; }
.scene-sub { fill: var(--ink-3); font-family: var(--f-mono); font-size: 10.5px; font-weight: 500; }
.scene-mark { fill: var(--ink-3); font-family: var(--f-mono); font-size: 10.5px; font-weight: 600; }
.scene-node.is-active .scene-box { stroke: var(--teal); fill: color-mix(in srgb, var(--teal) 12%, var(--card)); }
.scene-node.is-active .scene-icon { stroke: var(--teal); }
.scene-node.is-active.is-amber .scene-box { stroke: var(--amber); fill: color-mix(in srgb, var(--amber) 13%, var(--card)); }
.scene-node.is-active.is-amber .scene-icon { stroke: var(--amber); }
.scene-node.is-active { filter: drop-shadow(0 0 7px var(--scene-glow)); }
.scene-node.is-active.is-amber { filter: drop-shadow(0 0 7px var(--scene-amber-glow)); }
.scene-ring { fill: none; stroke: var(--teal); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.scene-node.is-amber .scene-ring { stroke: var(--amber); }
.scene-node.is-pulse .scene-ring { animation: scene-pulse .85s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes scene-pulse { from { opacity: .8; transform: scale(1); } to { opacity: 0; transform: scale(1.5); } }

.scene-pkt { pointer-events: none; }
.scene-dot { fill: var(--teal); }
.scene-halo { fill: var(--teal); opacity: .2; }
.scene-trail { fill: var(--teal); }
.scene-pkt .scene-dot { filter: drop-shadow(0 0 5px var(--scene-glow)); }
.scene-tag rect { fill: var(--teal); }
.scene-tag text { fill: var(--on-teal); font-family: var(--f-mono); font-size: 10.5px; font-weight: 700; letter-spacing: .02em; }

/* ---------- caption ---------- */
.scene-head { min-width: 0; }
.scene-caption { display: none; margin: 0; font-size: 1rem; line-height: 1.6; color: var(--ink); text-wrap: pretty; }
.scene-caption.is-now { display: block; animation: scene-in .45s ease both; }
@keyframes scene-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.scene-term { font-family: var(--f-mono); font-size: .875em; font-weight: 600; color: var(--teal); white-space: normal; }
.scene-caption.is-amber .scene-term { color: var(--amber); }

/* ---------- fields ---------- */
.scene-side { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--console); }
.scene-fields-title { margin: 0 0 8px; padding: 0 8px; font-family: var(--f-mono); font-size: .6875rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.scene-fields { display: grid; gap: 2px; margin: 0; }
.scene-field { display: grid; grid-template-columns: minmax(92px, 34%) minmax(0, 1fr); gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: .8125rem; line-height: 1.45; }
.scene-field dt { color: var(--ink-3); }
.scene-field dd { margin: 0; min-width: 0; color: var(--ink); font-family: var(--f-mono); font-size: .78rem; overflow-wrap: anywhere; }
.scene-field.is-changed { background: var(--teal-tint); box-shadow: inset 2px 0 0 var(--teal); animation: scene-flash 1.2s ease both; }
.scene-field.is-changed.is-amber { background: var(--amber-tint); box-shadow: inset 2px 0 0 var(--amber); animation-name: scene-flash-amber; }
.scene-field.is-changed .scene-val { font-weight: 700; }
@keyframes scene-flash { from { background: color-mix(in srgb, var(--teal) 26%, transparent); } }
@keyframes scene-flash-amber { from { background: color-mix(in srgb, var(--amber) 26%, transparent); } }
.scene-was { display: block; color: var(--ink-3); font-size: .7rem; }
.scene-was s { text-decoration-thickness: 1px; }

/* ---------- controls ---------- */
.scene-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-top: 14px; }
.scene-progress { display: flex; flex: 1 1 140px; gap: 4px; min-width: 120px; }
.scene-progress i { flex: 1; height: 4px; border-radius: 2px; background: var(--line-2); transition: background-color .3s ease; }
.scene-progress i.is-done { background: color-mix(in srgb, var(--teal) 45%, var(--line-2)); }
.scene-progress i.is-now { background: var(--teal); box-shadow: 0 0 8px var(--scene-glow); }
.scene-btns { display: flex; gap: 6px; }
.scene-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 42px; min-height: 42px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface-flat); color: var(--ink);
  font-family: var(--f-body); font-size: .875rem; font-weight: 600; line-height: 1; cursor: pointer;
  transition: border-color .2s ease, background-color .2s ease, transform .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.scene-btn svg { flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scene-btn:hover { border-color: var(--teal); background: var(--teal-tint); }
.scene-btn:active { transform: translateY(1px); }
.scene-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.scene-btn-toggle { min-width: 92px; }

/* ---------- the numbered list: for screen readers while it moves, on screen when motion is reduced ---------- */
.scene:not(.is-still) .scene-steps { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.scene-steps { display: grid; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; counter-reset: scene; }
.scene-step { counter-increment: scene; position: relative; padding: 12px 14px 12px 50px; border: 1px solid var(--line); border-radius: 12px; background: var(--console); }
.scene-step::before { content: counter(scene); position: absolute; left: 12px; top: 11px; display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid color-mix(in srgb, var(--teal) 40%, transparent); border-radius: 50%; background: var(--teal-tint); color: var(--teal); font-family: var(--f-mono); font-size: .75rem; font-weight: 700; }
.scene-step-cap { max-width: 68ch; margin: 0 0 6px; font-size: 1rem; line-height: 1.55; color: var(--ink); }
.scene-step-fields { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; font-size: .8125rem; line-height: 1.5; }
.scene-step-fields div { display: flex; gap: 6px; min-width: 0; }
.scene-step-fields dt { color: var(--ink-3); }
.scene-step-fields dt::after { content: ":"; }
.scene-step-fields dd { margin: 0; min-width: 0; color: var(--ink-2); font-family: var(--f-mono); font-size: .78rem; overflow-wrap: anywhere; }
.scene-step-fields .is-changed dd { color: var(--ink); font-weight: 700; }
.scene-step-fields .scene-was { display: inline; font-weight: 500; color: var(--ink-3); font-size: inherit; }

.scene.is-still .scene-top, .scene.is-still .scene-head, .scene.is-still .scene-side, .scene.is-still .scene-bar, .scene.is-still .scene-pkt { display: none; }
.scene.is-still .scene-live { display: block; }
.scene.is-still .scene-live-b { display: none; }

.scene-note { margin: 14px 0 0; font-size: .9375rem; line-height: 1.55; color: var(--ink-2); }
.scene-source { max-width: 68ch; margin: 12px 0 0; font-size: .8125rem; line-height: 1.55; color: var(--ink-3); }
.scene-source a { color: var(--teal); }

/* Home: the scene is the hero's visual; the "show batches" terminal sits in its own short section below. */
.hero-scene { align-self: center; }
.home-glance { padding: clamp(8px, 2vw, 24px) 0 clamp(40px, 5vw, 64px); }
.home-glance .term { max-width: 760px; margin: 0 auto; }
@media (min-width: 980px) {
  .home-glance .term { font-size: .9375rem; }
  .home-glance .term-body { padding: 22px 26px 24px; }
}

/* A section that holds a scene on a page */
.scene-section .section-head { margin-bottom: clamp(20px, 3vw, 32px); }

@media (prefers-reduced-motion: reduce) {
  .scene *, .scene *::before { animation: none !important; transition: none !important; }
}

/* The home hero with reduced motion: the still list of nine steps would make the hero very tall and push the
   headline far down. Keep the hero copy at the top and let the list scroll inside its own box (keyboard: it can take
   focus, see scene.js). */
@media (min-width: 980px) {
  .hero-grid:has(.scene.is-still) { align-items: start; }
  .hero-scene:has(.scene.is-still) { align-self: start; }
}
.hero-scene .scene.is-still .scene-steps { max-height: min(34rem, 70vh); overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; }
.hero-scene .scene.is-still .scene-steps:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

/* Reduced motion on a phone: the steps are a list; the first three show, a button opens the rest (js/scenes/scene.js). */
.scene-more { display: none; }
@media (max-width: 699px) {
  .scene.is-still .scene-steps.is-folded > .scene-step:nth-child(n+4) { display: none; }
  .scene.is-still .scene-more:not([hidden]) { display: inline-flex; width: 100%; margin: 12px 0 0; }
}
.scene-step:focus { outline: none; }
.scene-step:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
