/* =========================================================
   UI-Element-Device-Status-Screen — card-media composition.
   WordPress variant of assets/Startpage Card Screens/
   UI-Element-Device-Status-Screen.html (published by
   startpage-card-scenes/register.php as snippet 158, linked by the
   shortcode snippet 157).

   Replaces the `device-uptime-screen.webm` video in the start-page
   "01 Vereinen / Gerätemanagement" card. The video was an 880×504
   render that the card scaled to ~1/3 (labels ≈ 9px) — too small to
   read. This scene is designed for the slot itself: fluid width ×
   165px (the card's `--card-media-h`), 13px labels, no transform
   scaling. Rows stretch with the card, so desktop (~305px) and mobile
   (~396px) both get the full panel at identical type size.

   Story (mirrors the video): a Device Status panel from the Unwired
   Edge Cloud console; the Firmware Version field fills with a green
   progress bar, then resolves to the new version with a green check.
   Everything else is a calm, static backdrop.

   Differences from the standalone export (docs/ui-mockup-core.md):
   - no palette block: UI-Mockup-Core (117) owns the `--c-ui-color-*`
     aliases on :root; only the two permitted off-white tints are local;
   - the Core scene contract `[class*="c-ui-scene--"]` (450px square,
     centred, 16px) also matches this variant class, so the root
     re-declares width/height/aspect-ratio/margin/font-size here;
   - sequenced mode (`.is-uw-seq`, set by snippet 163) — see below.
   ========================================================= */

/* -------------------------
   Scene root — fluid width × 165px.
   No scale wrapper on purpose: `scale(calc(100cqw / 320px))` needs
   length÷length maths (Chromium ≥140 only) and a width-only wrapper
   would crop the bottom rows on mobile the way the video did. The
   272px min-width is the narrowest media content box the start-page
   grid produces (measured 2026-10-19: 299px desktop card − 24px pad =
   275; 320px phone: 288px card − 16px pad = 272) — below that the rows
   would squash, so the scene holds its width and the card clips.
------------------------- */
.c-ui-scene--device-status-screen {
  /* Permitted derived neutral tints (docs/ui-mockup-core.md). */
  --c-ui-tint-surface:       #f6f6f6;
  --c-ui-tint-border:        #ececec;
  --c-ui-tint-border-strong: #d6d6d6;

  /* `--c-ui-scene-loop` is the ONE value the card sequencer (snippet
     163) reads to know when this scene has told its story once; every
     keyframe below is a percentage of it. The entry offset shifts the
     loop so the first frame a viewer sees (and the static state before
     any animation / with reduced motion) is the resolved version, not
     an empty field. */
  --c-ui-scene-loop: 6s;
  --c-ui-dss-loop: var(--c-ui-scene-loop);
  --c-ui-dss-entry: calc(var(--c-ui-dss-loop) * -0.4);

  /* Overrides of the Core scene contract (same specificity, this file
     loads later; the card-context rule below repeats the sizing at a
     higher specificity so link order can never matter). */
  width: 100%;
  min-width: 272px;
  height: 165px;
  aspect-ratio: auto;
  margin: 0;
  /* Generous top gap so the legend doesn't crowd the card's media
     edge; the bottom gap stays minimal because the fixed 165px height
     has to hold 6 rows. */
  padding: 16px 8px 4px;
  background: var(--c-ui-color-g50);
  font-size: 13px;
  overflow: hidden;
}

.c-ui-scene--device-status-screen,
.c-ui-scene--device-status-screen *,
.c-ui-scene--device-status-screen *::before,
.c-ui-scene--device-status-screen *::after { box-sizing: border-box; }

/* Card slot: the same corner treatment System CSS (98) gives images
   and videos in `.c-card__media`, and the sizing once more at (0,2,0)
   so WP Rocket's used-CSS reordering cannot let the Core rule win. */
.c-card__media .c-ui-scene--device-status-screen {
  width: 100%;
  height: 165px;
  aspect-ratio: auto;
  margin: 0;
  border-radius: var(--c-ui-radius-12) 0 var(--c-ui-radius-12) 0;
}

/* -------------------------
   Panel — fieldset look: 1px hairline frame with the legend sitting
   ON the top border (white backing cuts the line), like the console's
   grouped status block.
------------------------- */
.c-ui-dss__panel {
  position: relative;
  height: 100%;
  border: 1px solid var(--c-ui-tint-border-strong);
  border-radius: 8px;
  /* 12px top clears the legend (overhangs the border by 6px) with 8px
     to spare before the first row. */
  padding: 12px 10px 6px;
}

.c-ui-dss__legend {
  position: absolute;
  top: -6px;
  left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 5px;
  background: var(--c-ui-color-g50);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ui-color-g500);
}
.c-ui-dss__legend svg {
  width: 10px;
  height: 10px;
  fill: currentColor;
}

/* Rows: fixed label column so values align; 21px row height × 6 rows
   = 126px + panel padding 18px = 144px inside the 145px panel
   (165 − 16 − 4). Horizontal budget at the 272px minimum: 272 − 16
   (scene pad) − 2 (border) − 20 (panel pad) = 234px → 112px labels
   ("Firmware Version:" needs ~110) + 6px gap leaves 116px for the
   value column, which must hold the 112px firmware field. */
.c-ui-dss__rows {
  display: grid;
  grid-template-columns: 112px 1fr;
  grid-auto-rows: 21px;
  align-items: center;
  column-gap: 6px;
  margin: 0;
}

.c-ui-dss__key {
  color: var(--c-ui-color-g500);
  white-space: nowrap;
}

.c-ui-dss__val {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 100%;
  margin: 0;
  color: var(--c-ui-color-g800);
  white-space: nowrap;
}

.c-ui-dss__val--ok { color: var(--c-ui-color-p800); }

.c-ui-dss__check {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  fill: var(--c-ui-color-p700);
}

/* Skeleton pill — the console's "not loaded yet" placeholder. Kept for
   the rows that don't carry the story so the panel reads as a live
   screen without competing text. */
.c-ui-dss__skeleton {
  display: block;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--c-ui-tint-border);
}
.c-ui-dss__skeleton--load { width: 100%; }
.c-ui-dss__load { flex: 0 0 auto; min-width: 30px; }

/* -------------------------
   Firmware beat
   Two stacked states in the same grid cell:
     .c-ui-dss__field   — bordered input with a caret and a green fill
                          that grows 0→100%
     .c-ui-dss__version — "21.02-207 ✓" in green
   The field owns the first ~1/3 of the loop, the version the rest.
   Both animate opacity so the handoff is a short crossfade instead of
   a hard cut. Base styles = the resolved state (field hidden, version
   shown), which is also the keyframe the negative entry delay starts
   on, so there is no jump when the loop kicks in.
------------------------- */
.c-ui-dss__field {
  position: relative;
  width: 112px;
  height: 16px;
  border: 1px solid var(--c-ui-color-g600);
  border-radius: 4px;
  background: var(--c-ui-color-g50);
  overflow: hidden;
  opacity: 0;
  animation: c-ui-dss-field var(--c-ui-dss-loop) linear var(--c-ui-dss-entry) infinite;
}

.c-ui-dss__caret {
  position: absolute;
  top: 3px;
  left: 4px;
  width: 1px;
  height: 8px;
  background: var(--c-ui-color-g800);
  /* Caret blinks on its own fast loop; the growing fill simply covers
     it once the progress starts. */
  animation: c-ui-dss-caret 1s steps(2, jump-none) infinite;
}

.c-ui-dss__fill {
  position: absolute;
  inset: 1px;
  border-radius: 2px;
  background: var(--c-ui-color-p700);
  transform-origin: left center;
  transform: scaleX(1);
  animation: c-ui-dss-fill var(--c-ui-dss-loop) linear var(--c-ui-dss-entry) infinite;
}

.c-ui-dss__version {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  animation: c-ui-dss-version var(--c-ui-dss-loop) linear var(--c-ui-dss-entry) infinite;
}

/* Timeline (6s loop):
     0–7%    (0–0.4s)  empty field, caret blinks
     7–33%   (0.4–2s)  fill grows (eased by keyframe spacing)
     33–40%  (2–2.4s)  field fades out, version fades/scales in
     40–100% (2.4–6s)  hold the result — the free-running loop STARTS
                        here (entry delay = -40%), so a viewer sees the
                        resolved version first, then the update beat
                        3.6s later. */
@keyframes c-ui-dss-field {
  0%, 33%  { opacity: 1; }
  40%, 100% { opacity: 0; }
}

@keyframes c-ui-dss-fill {
  0%, 7%   { transform: scaleX(0); }
  20%      { transform: scaleX(0.62); }
  33%, 100% { transform: scaleX(1); }
}

@keyframes c-ui-dss-version {
  0%, 34%  { opacity: 0; transform: translateY(2px); }
  40%, 100% { opacity: 1; transform: translateY(0); }
}

@keyframes c-ui-dss-caret {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* -------------------------
   Sequenced mode — the start-page card sequencer (snippet 163) marks
   every scene it controls with `is-uw-seq` and the one whose turn it
   is with `is-uw-playing`. Idle scenes are PAUSED, not reset
   (`animation-play-state`): they hold the frame they are on and resume
   from it — a card the pointer interrupted mid-story picks up where it
   stopped instead of starting over (Philipp, 2026-10-22). In the
   regular rotation the sequencer hands over only on loop boundaries,
   so an idle scene normally holds the base frame anyway; the playing
   scene runs to the end of its loop and lands on that same frame.
   `is-uw-reset` is the one place the keyframes DO rewind: the sequencer
   flashes it (add → reflow → remove) at boot — the scene has been
   free-running since this sheet arrived, the script comes later —, on
   tab return, where timer and CSS clock may have drifted, and whenever
   a scene is paused ON a boundary (same frame, re-anchors the clock;
   pause/resume latencies would otherwise add up as a random walk).
   `animation: none` is the only way to rewind a CSS animation. The
   reset rule sits after the pause gate as a reading convention; it
   does not depend on order — the shorthand zeroes `animation-name`,
   which the gate never sets (the gate only pauses).
   In this mode the beat must start right away instead of after the
   3.6s hold the free-running loop needs, so the entry offset moves to
   96%: the story opens with 240ms of the resolved version (= base
   frame), then the deliberate hard cut to the empty field — the same
   cut the free-running loop makes at 100%→0%, the "reset" a viewer
   expects before a new update beat — and ENDS on the resolved version
   at 96% (seamless freeze). Why 96% and not 0%: the sequencer treats a
   timer up to 150ms late as "on the boundary"; with the cut at 0% those
   late frames would flash the empty field, and a late timer beyond the
   40ms rewind window PARKS the scene on that frame (review, 2026-10-19;
   was 97% = 180ms). The CSS clock can also run up to a frame ahead of
   the sequencer per pause/resume pair, so 4% of 6s = 240ms keeps ≈90ms
   of headroom over 150ms + a few frames (review, 2026-10-22).
   (0,3,0) + universal: outranks every element rule above.
------------------------- */
.c-ui-scene--device-status-screen.is-uw-seq {
  --c-ui-dss-entry: calc(var(--c-ui-dss-loop) * -0.96);
}
.c-ui-scene--device-status-screen.is-uw-seq:not(.is-uw-playing) * {
  animation-play-state: paused;
}
.c-ui-scene--device-status-screen.is-uw-seq.is-uw-reset * {
  animation: none;
}

/* Reduced motion: base styles already ARE the resolved state, so just
   stop the loops. */
@media (prefers-reduced-motion: reduce) {
  .c-ui-dss__field,
  .c-ui-dss__fill,
  .c-ui-dss__caret,
  .c-ui-dss__version { animation: none; }
}
