/*!
 * diffusion-avatar.css v4.0.0
 * Only what the component needs. The page sizes and shapes `.dz-avatar`
 * (width/height or aspect-ratio, plus border-radius + overflow:hidden or a clip-path)
 * and lays out `.dz-figure` (make it as wide as the avatar so the controls match it).
 * Rules wrapped in :where() have zero specificity, so page CSS always wins.
 * The controls use the inherited font and the page's colour variables when present:
 * --ink, --soft, --dim, --line, --acc, --panel, --bg (each has a neutral fallback).
 * In particle mode (the default) the canvas is transparent between the points, so the avatar's own
 * background (e.g. background: var(--panel)) shows through there while the points travel.
 * v4: the optional landscape row (.dz-landscape, first in .dz-controls) is 104 px tall by default.
 */

/* ------------------------------------------------------------- avatar -- */
:where(.dz-avatar) {
  position: relative;                 /* containing block for the canvas */
}

:where(.dz-avatar) > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;                  /* the canvas reproduces cover + object-position */
}

.dz-avatar > .dz-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease-out;  /* the canvas fades out over the crisp photo at t = 0 (pixels: noise also fades in on "sample") */
}

.dz-avatar.dz-on > .dz-canvas,
.dz-avatar.dz-pending > .dz-canvas {
  opacity: 1;
}

.dz-avatar.dz-pending > .dz-canvas,
.dz-avatar.dz-frozen > .dz-canvas {
  transition: none;
}

/* Particles: the photo under the transparent canvas is hidden while the canvas shows. The canvas appears
   at once, because its first frame is exactly what was on screen (the run then cross-fades from it), and
   at t = 0 its last frame is the crisp photo, which fades out over the <img> as above. */
.dz-avatar.dz-particles.dz-on > img,
.dz-avatar.dz-particles.dz-pending > img {
  opacity: 0;
}

.dz-avatar.dz-particles.dz-on > .dz-canvas {
  transition-duration: 0s;
}

/* click / tap on the photo samples (keyboard: the sample button) */
.dz-avatar.dz-interactive {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.dz-avatar.dz-interactive > img {
  -webkit-user-drag: none;
}

/* only when there is no .dz-play: the avatar itself is then a focusable button */
.dz-avatar.dz-interactive:focus {
  outline: none;
}

.dz-avatar.dz-interactive:focus-visible {
  outline: 2px solid var(--dz-focus, var(--acc, currentColor));
  outline-offset: 4px;
}

/* ----------------------------------------------------------- controls -- */
/* Two compact rows under the avatar:  [> sample]  t = 600
                                        ----------o--------------
   The slider runs left to right: left end = pure noise (t = 1000), right end = the photo (t = 0).
   Its value is the progress 1000 - t; --dz-p (0..1, written by the component) is that progress. */
.dz-controls[hidden] {
  display: none;                      /* author display rules would otherwise beat [hidden] */
}

/* until the effect is known to work, keep the (invisible, inert) space so nothing shifts */
.dz-controls.dz-reserve[hidden] {
  display: grid;
  visibility: hidden;
}

:where(.dz-controls) {
  --dz-track: var(--line, rgba(128, 128, 128, 0.35));   /* the part of the track still to go (right of the thumb) */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 4px 10px;
  box-sizing: border-box;
  width: 100%;
  margin-top: 12px;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.4;
  color: var(--soft, inherit);
}

/* a touch of --dim keeps the track visible on dark palettes, where --line is very faint */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :where(.dz-controls) {
    --dz-track: color-mix(in srgb, var(--dim, #888) 35%, var(--line, transparent));
  }
}

.dz-controls > .dz-play { grid-column: 1; grid-row: 1; justify-self: start; }
.dz-controls > .dz-t { grid-column: 2; grid-row: 1; justify-self: start; }
.dz-controls > .dz-slider { grid-column: 1 / -1; grid-row: 2; }

/* v4: with a landscape, it is the first row (full width); the button + readout and the slider move down.
   The component adds .dz-has-land (and removes it again if the landscape cannot draw). */
.dz-controls > .dz-landscape { grid-column: 1 / -1; grid-row: 1; }
.dz-controls.dz-has-land > .dz-play,
.dz-controls.dz-has-land > .dz-t { grid-row: 2; }
.dz-controls.dz-has-land > .dz-slider { grid-row: 3; }

:where(.dz-controls) .dz-play {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 1px 9px 1px 8px;
  border: 1px solid var(--line, rgba(128, 128, 128, 0.4));
  border-radius: 6px;
  background: var(--panel, transparent);
  color: var(--ink, inherit);
  font: inherit;
  line-height: 1.6;
  cursor: pointer;
  touch-action: manipulation;
}

/* small play triangle (decorative; the word "sample" is the label) */
:where(.dz-controls) .dz-play::before {
  content: "";
  flex: none;
  width: 6px;
  height: 7px;
  background: var(--acc, currentColor);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

:where(.dz-controls) .dz-play:hover {
  border-color: var(--dim, currentColor);
}

:where(.dz-controls) .dz-play:active {
  transform: translateY(1px);
}

/* the live t: fixed width ("t = 1000"), left-aligned, tabular digits: the label never moves */
:where(.dz-controls) .dz-t {
  min-width: 8ch;
  text-align: left;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--soft, inherit);
}

:where(.dz-controls) .dz-slider {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  touch-action: pan-y;                /* horizontal drags scrub, vertical ones still scroll */
}

/* track: the accent fills it from the left (noise) up to the thumb's centre: the progress made so far */
:where(.dz-controls) .dz-slider::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(to right,
    var(--acc, currentColor) 0 calc(6px + var(--dz-p, 1) * (100% - 12px)),
    var(--dz-track) 0);
}

:where(.dz-controls) .dz-slider::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: var(--dz-track);
}

:where(.dz-controls) .dz-slider::-moz-range-progress {
  height: 2px;
  border-radius: 1px;
  background: var(--acc, currentColor);
}

:where(.dz-controls) .dz-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  margin-top: -5px;                   /* centre on the 2px track */
  border: 2px solid var(--bg, Canvas);
  border-radius: 50%;
  background: var(--ink, currentColor);
  box-shadow: 0 0 0 1px var(--ink, currentColor);
}

:where(.dz-controls) .dz-slider::-moz-range-thumb {
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  border: 2px solid var(--bg, Canvas);
  border-radius: 50%;
  background: var(--ink, currentColor);
  box-shadow: 0 0 0 1px var(--ink, currentColor);
}

/* visible keyboard focus */
:where(.dz-controls) .dz-play:focus-visible,
:where(.dz-controls) .dz-slider:focus-visible {
  outline: 2px solid var(--dz-focus, var(--acc, currentColor));
  outline-offset: 2px;
}

:where(.dz-controls) .dz-slider:focus-visible {
  border-radius: 3px;
}

:where(.dz-controls) .dz-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--ink, currentColor), 0 0 0 4px var(--line, rgba(128, 128, 128, 0.35));
}

:where(.dz-controls) .dz-slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--ink, currentColor), 0 0 0 4px var(--line, rgba(128, 128, 128, 0.35));
}

/* ---------------------------------------------------------- landscape -- */
/* <div class="dz-landscape" aria-hidden="true"></div>: the toy model's energy landscape. The component draws
   it into a canvas inside (decorative: the sample button is the accessible control; a click samples too).
   The page may set its height. Its colours are read from this element's computed style, so they follow the
   page's variables and theme:  lines = color (--ink), ball / trail / lit ring = border-top-color (--acc),
   plain rings = border-right-color (--line), stems = border-bottom-color (--dim). No border is drawn. */
:where(.dz-landscape) {
  position: relative;
  height: 104px;
  margin: 0 0 4px;
  -webkit-tap-highlight-color: transparent;
}

.dz-landscape {
  border-style: none;
  color: var(--ink, #3d3d3d);
  border-top-color: var(--acc, #3a62a8);
  border-right-color: var(--line, rgba(128, 128, 128, 0.45));
  border-bottom-color: var(--dim, #8a8a8a);
}

.dz-landscape[hidden] {
  display: none;
}

.dz-landscape > .dz-land {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 0.4s ease-out;   /* it appears once, after the first reveal has started */
}

.dz-landscape.dz-land-on > .dz-land {
  opacity: 1;
  cursor: pointer;
}

/* coarse pointers: a taller hit area for the thumb */
@media (pointer: coarse) {
  :where(.dz-controls) .dz-slider { height: 28px; }
  :where(.dz-controls) .dz-play { padding-top: 4px; padding-bottom: 4px; }
}

/* Windows High Contrast / forced colours: hand the slider back to the system */
@media (forced-colors: active) {
  .dz-controls > .dz-slider { -webkit-appearance: auto; appearance: auto; }
  .dz-controls > .dz-play::before { background: ButtonText; }
}

@media print {
  .dz-avatar > .dz-canvas,
  .dz-controls {
    display: none !important;          /* always print the clean photo */
  }
  .dz-avatar > img {
    opacity: 1 !important;             /* particles hide it while the canvas shows */
  }
}

@media (prefers-reduced-motion: reduce) {
  .dz-avatar > .dz-canvas {
    transition-duration: 0.5s;        /* a slow cross-fade, no motion */
  }
  .dz-landscape > .dz-land {
    transition-duration: 0.2s;
  }
  :where(.dz-controls) .dz-play:active {
    transform: none;
  }
}
