/* DN-MOPD project page, p5c_datamotion: data-driven animated results.
   Loaded after style.css; everything here is prefixed dm-. Uses the base tokens (--teal, --gold, --blue, --purple, ink/text,
   surfaces) and adds a few chart tokens below. Without JS (html lacks .dm-js) or without the data (figure lacks .dm-ready),
   the static fallbacks stay visible and the chart UI stays hidden.
   Merge (p5_all): the gradient-share chart and the multiplier notes are dropped (their facts are on the page already: the
   bento meter and the "What the rule does in practice" cards); CSS motion is transform / opacity only (the toggle thumb
   no longer transitions width, and the DN-MOPD row highlight fades a layer instead of moving a background). */

:root {
  --dm-dn: var(--teal);
  --dm-label: #AEB9C5;          /* Label: neutral slate, lighter than teal so the pair separates by lightness (CVD-safe) */
  --dm-band: rgba(20, 143, 134, .065);
  --dm-band-line: rgba(20, 143, 134, .42);
  --dm-cont: rgba(17, 43, 69, .028);
  --dm-seed: #112B45;
  --dm-sweep: rgba(20, 143, 134, .20);
  --dm-playhead: rgba(17, 43, 69, .55);
  --dm-pill-bg: #112B45;
  --dm-pill-fg: #FFFFFF;
  --dm-hit: rgba(17, 43, 69, .035);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --dm-label: #51657A;
    --dm-band: rgba(47, 181, 167, .075);
    --dm-band-line: rgba(47, 181, 167, .45);
    --dm-cont: rgba(255, 255, 255, .025);
    --dm-seed: #EFF4F9;
    --dm-sweep: rgba(47, 181, 167, .22);
    --dm-playhead: rgba(239, 244, 249, .55);
    --dm-pill-bg: #EFF4F9;
    --dm-pill-fg: #0B1620;
    --dm-hit: rgba(255, 255, 255, .035);
  }
}
:root[data-theme="dark"] {
  --dm-label: #51657A;
  --dm-band: rgba(47, 181, 167, .075);
  --dm-band-line: rgba(47, 181, 167, .45);
  --dm-cont: rgba(255, 255, 255, .025);
  --dm-seed: #EFF4F9;
  --dm-sweep: rgba(47, 181, 167, .22);
  --dm-playhead: rgba(239, 244, 249, .55);
  --dm-pill-bg: #EFF4F9;
  --dm-pill-fg: #0B1620;
  --dm-hit: rgba(255, 255, 255, .035);
}

/* ---------------------------------------------------------------- progressive enhancement switches */
.dm-when-ready { display: none; }
.dm-fig.dm-ready .dm-when-ready { display: block; }
.dm-fig.dm-ready .dm-ctrls.dm-when-ready,
.dm-fig.dm-ready .dm-legend.dm-when-ready,
.dm-fig.dm-ready .dm-mult-top.dm-when-ready { display: flex; }
.dm-fig.dm-ready .dm-len-grid.dm-when-ready { display: grid; }
.dm-fig.dm-ready .dm-fallback { display: none; }
.dm-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------------------------------------------------------------- controls */
.dm-ctrls { flex-wrap: wrap; gap: 10px 12px; margin-top: 18px; }
.dm-seg {
  position: relative; display: inline-flex; align-items: stretch; padding: 3px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); isolation: isolate; max-width: 100%;
}
.dm-seg button {
  position: relative; z-index: 1; appearance: none; -webkit-appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-body); font-size: 13.5px; font-weight: 600; line-height: 1; color: var(--muted);
  padding: 0 13px; min-height: 34px; border-radius: 9px; white-space: nowrap; transition: color .25s ease;
  -webkit-tap-highlight-color: transparent;
}
.dm-seg button:hover { color: var(--heading); }
.dm-seg button[aria-pressed="true"] { color: var(--heading); }
.dm-seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.dm-seg-thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 9px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(16, 38, 61, .10), 0 0 0 1px var(--border-strong);
  transform: translateX(0); transform-origin: 0 50%; opacity: 0;
}
/* the width snaps and datamotion.js FLIPs the thumb from its old box with translateX + scaleX: transform only */
.dm-seg.dm-seg-on .dm-seg-thumb { opacity: 1; transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
:root[data-theme="dark"] .dm-seg-thumb { background: var(--surface-3); box-shadow: 0 0 0 1px var(--border-strong); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .dm-seg-thumb { background: var(--surface-3); box-shadow: 0 0 0 1px var(--border-strong); } }

/* ---------------------------------------------------------------- legends and keys */
.dm-legend { flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 16px; font-size: 13px; color: var(--text-2); }
.dm-legend > span { display: inline-flex; align-items: center; gap: 8px; }
.dm-sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }
.sw-dn { background: var(--dm-dn); }
.sw-label { background: var(--dm-label); }
.sw-ghost { background: transparent; border: 1.5px dashed var(--muted); }
.sw-band { background: var(--dm-band); border: 1px solid var(--dm-band-line); border-left: 0; border-right: 0; border-radius: 0; height: 12px; }
.sw-floor { background: var(--purple); opacity: .55; height: 8px; border-radius: 2px; }
.dm-wh { width: 18px; height: 12px; display: inline-block; flex: none; border-left: 2px solid var(--whisker); border-right: 2px solid var(--whisker);
  background: linear-gradient(var(--whisker), var(--whisker)) center / 100% 2px no-repeat; }
.dm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dm-seed); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border-strong); display: inline-block; flex: none; }
.dm-lg-seeds { transition: opacity .45s ease; }
.dm-gains:not(.dm-mean) .dm-lg-seeds { opacity: .0; visibility: hidden; transition: opacity .3s ease, visibility 0s linear .3s; }
.dm-key { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dm-key.k-math, .dm-lk.k-math { background: var(--gold); }
.dm-key.k-code, .dm-lk.k-code { background: var(--blue); }
.dm-key.k-if, .dm-lk.k-if { background: var(--purple); }
.dm-lk { width: 20px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.dm-lk.k-faint { background: var(--muted); opacity: .38; height: 1.5px; }
.dm-lk.k-solid { background: var(--muted); height: 2.5px; }
.dm-lk.k-dot { background: radial-gradient(circle, var(--purple) 45%, transparent 50%) 0 50% / 5px 3px repeat-x; height: 3px; }
.dm-lk.k-m80 { width: 3px; height: 14px; background: linear-gradient(var(--heading) 55%, transparent 55%) 0 0 / 2px 5px repeat-y; opacity: .7; border-radius: 0; }
.dm-lg-sep { position: relative; }
.dm-legend-mult { gap: 8px 16px; font-size: 12.5px; }

/* ---------------------------------------------------------------- chart mounts, svg text roles */
.dm-mount { position: relative; margin-top: 14px; }
.dm-svg { display: block; overflow: visible; max-width: 100%; }
.dm-svg text { font-family: var(--font-body); }
.dm-gl { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.dm-axis0 { stroke: var(--axis); stroke-width: 1.25; shape-rendering: crispEdges; }
.dm-tick { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.dm-axt { font-size: 12.5px; fill: var(--muted); }
.dm-note { font-size: 11.5px; fill: var(--muted); font-weight: 500; }
.dm-size { font-family: var(--font-display) !important; font-weight: 650; font-size: 17px; fill: var(--heading); }
.dm-val { font-family: var(--font-display) !important; font-weight: 650; font-size: 17px; fill: var(--heading); font-variant-numeric: tabular-nums; }
.dm-ci { font-size: 12.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.dm-bar { fill: var(--dm-dn); }
.dm-bar-label { fill: var(--dm-label); }
.dm-hit { fill: transparent; transition: fill .2s ease; }
.dm-row { outline: none; cursor: default; }
.dm-row:hover .dm-hit, .dm-row:focus-visible .dm-hit { fill: var(--dm-hit); }
.dm-row:focus-visible .dm-hit { stroke: var(--focus); stroke-width: 2; }
.dm-wk { stroke: var(--whisker); stroke-width: 2; stroke-linecap: butt; fill: none; }
.dm-wk-ring { stroke: var(--surface); stroke-width: 5.5; stroke-linecap: butt; fill: none; }
.dm-seed { fill: var(--dm-seed); stroke: var(--surface); stroke-width: 2; }

/* tooltip */
.dm-tip {
  position: absolute; left: 0; top: 0; z-index: 6; width: max-content; max-width: 250px; pointer-events: none;
  padding: 8px 11px; border-radius: 10px; background: var(--tip-bg); color: var(--tip-fg); font-size: 12.5px; line-height: 1.5;
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .16s ease; font-variant-numeric: tabular-nums;
}
.dm-tip.on { opacity: 1; }
.dm-tip b { display: block; font-weight: 650; margin-bottom: 2px; }
.dm-tip .dm-tk { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* ---------------------------------------------------------------- multipliers */
.dm-mult-top { flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-top: 20px; }
.dm-readout { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: 13.5px; color: var(--text-2); min-height: 34px; }
.dm-readout b { font-family: var(--font-display); font-weight: 650; font-size: 15.5px; color: var(--heading); font-variant-numeric: tabular-nums; }
.dm-ro-u, .dm-ro-d { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.dm-ro-d .dm-key { align-self: center; }
.dm-ro-u b { display: inline-block; min-width: 3ch; text-align: right; }
.dm-ro-d b { display: inline-block; min-width: 4ch; }
.dm-ro-k { color: var(--muted); }
.dm-ro-of { color: var(--muted); font-variant-numeric: tabular-nums; }
.dm-ro-phase {
  margin-left: 4px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); transition: background-color .3s ease, color .3s ease;
}
.dm-ro-phase.is-main { background: var(--teal-wash); color: var(--heading); }
.dm-ro-flag { font-size: 12px; color: var(--muted); }
.dm-ro-flag.is-floor { color: var(--heading); font-weight: 600; }
.dm-mult .dm-mount { margin-top: 10px; border-radius: 12px; }
.dm-mult .dm-mount:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.dm-mult .dm-svg { touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.dm-overlay { fill: transparent; cursor: ew-resize; }
.dm-band { fill: var(--dm-band); }
.dm-bandline { stroke: var(--dm-band-line); stroke-width: 1; shape-rendering: crispEdges; }
.dm-cont { fill: var(--dm-cont); }
.dm-one { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; opacity: .8; }
.dm-ln { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.dm-ln.raw { stroke-width: 1.1; opacity: .34; }
.dm-ln.sm { stroke-width: 2.2; }
.dm-ln.pre { stroke-width: 1.4; stroke-dasharray: 1.2 3.2; opacity: .8; }
.dm-ln.c-math { stroke: var(--gold); } .dm-ln.c-code { stroke: var(--blue); } .dm-ln.c-if { stroke: var(--purple); }
.dm-floor rect { fill: var(--purple); opacity: .55; }
.dm-floor { transition: opacity .55s ease; }
.dm-m80 { stroke: var(--heading); stroke-width: 1.25; stroke-dasharray: 4 4; opacity: .62; }
.dm-m80-t { font-size: 11.5px; fill: var(--text-2); font-weight: 600; }
.dm-xt { transition: opacity .2s ease; }
.dm-ph-line { stroke: var(--dm-playhead); stroke-width: 1.25; }
.dm-ph-dot { stroke: var(--surface); stroke-width: 2; }
.dm-ph-dot.c-math { fill: var(--gold); } .dm-ph-dot.c-code { fill: var(--blue); } .dm-ph-dot.c-if { fill: var(--purple); }
.dm-pill { fill: var(--dm-pill-bg); }
.dm-pill-t { font-size: 11.5px; font-weight: 650; fill: var(--dm-pill-fg); font-variant-numeric: tabular-nums; }
.dm-end { font-size: 12.5px; font-weight: 600; fill: var(--heading); }
.dm-end-key { stroke-width: 2.5; stroke-linecap: round; }
.dm-end-key.c-math { stroke: var(--gold); } .dm-end-key.c-code { stroke: var(--blue); } .dm-end-key.c-if { stroke: var(--purple); }
.dm-hint { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.dm-tv-note { margin-top: 10px; font-size: 13px; color: var(--muted); }
.dm-fig .data-view.dm-tv { margin-top: 16px; }

/* ---------------------------------------------------------------- lengths */
.dm-len-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px 36px; margin-top: 8px; }
.dm-panel { min-width: 0; }
.dm-panel-h { margin-top: 14px; font-size: .98rem; font-weight: 650; color: var(--heading); }
.dm-panel-h span { font-weight: 500; color: var(--muted); font-size: .88rem; margin-left: 6px; }
.dm-panel .dm-mount { margin-top: 8px; }
.dm-lv { font-family: var(--font-display) !important; font-weight: 650; font-size: 14.5px; fill: var(--heading); font-variant-numeric: tabular-nums; }
.dm-lv-sub { font-size: 12px; fill: var(--muted); font-weight: 500; }
.dm-lghost { fill: none; stroke: var(--muted); stroke-width: 1.25; stroke-dasharray: 4 3.5; } /* opacity is animated through the attribute */

/* ---------------------------------------------------------------- Tables 1-3: staggered rows + DN-MOPD highlight (JS adds .dm-stagger)
   Merge: these tables own their entry (they are not generic .rv reveals). The DN-MOPD row's one-off highlight is a
   teal layer per cell whose opacity pulses left to right; p5c moved a background-position, which is not transform/opacity.
   The first cell is already sticky (positioned); the others become relative so the layer fits the cell. */
@media (prefers-reduced-motion: no-preference) {
  .dm-stagger:not(.dm-rows-in) tbody tr { opacity: 0; }
  .dm-stagger.dm-rows-in tbody tr { animation: dm-row .6s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--dm-i, 0) * 38ms + 80ms); }
  .dm-stagger tr.dn-row > td { position: relative; }
  .dm-stagger.dm-rows-in tr.dn-row > th::after, .dm-stagger.dm-rows-in tr.dn-row > td::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; background: var(--dm-sweep); opacity: 0;
    animation: dm-flash .9s ease-out both; animation-delay: calc(var(--dm-i, 0) * 38ms + 420ms + var(--dm-c, 0) * 70ms);
  }
  /* merge: a table passed during a fast jump is shown at once by polish.js's reveal sweep (.dm-rows-now) */
  .dm-stagger.dm-rows-now tbody tr, .dm-stagger.dm-rows-now tr.dn-row > th::after, .dm-stagger.dm-rows-now tr.dn-row > td::after { animation: none; }
  /* p5d's phone card view of Table 3 makes the cells static: no layer there */
  @media (max-width: 680px) {
    #table3 .dt-cards tr.dn-row > th::after, #table3 .dt-cards tr.dn-row > td::after { content: none; }
  }
}
@keyframes dm-row { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dm-flash { 0% { opacity: 0; } 35% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .dm-len-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 680px) {
  .dm-ctrls { gap: 8px; }
  .dm-seg button { padding: 0 11px; font-size: 13px; }
  .dm-legend { gap: 6px 14px; font-size: 12.5px; }
  .dm-readout { gap: 4px 14px; font-size: 13px; }
  .dm-readout b { font-size: 14.5px; }
  .dm-ro-u { flex-basis: 100%; }
  .dm-size { font-size: 15px; }
  .dm-val { font-size: 15.5px; }
  .dm-ci { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .dm-seg.dm-seg-on .dm-seg-thumb, .dm-floor, .dm-tip, .dm-lg-seeds, .dm-xt, .dm-hit, .dm-ro-phase { transition: none !important; }
}
@media (forced-colors: active) {
  .dm-bar, .dm-bar-label, .dm-ln, .dm-floor rect, .dm-sw, .dm-key, .dm-lk { forced-color-adjust: none; }
}
@media print {
  .dm-stagger tbody tr { opacity: 1 !important; animation: none !important; }
  .dm-hint, .dm-ctrls { display: none !important; }
}
