/* ──────────────────────────────────────
   WHISPERAE FILL — colour arrives over the whisper image
   Two stacked images; the colour one is revealed by an animated mask.

   <div class="fill" data-mode="rise">
     <img class="fill-whisper" src="images/x_whisper.webp" alt="...">
     <img class="fill-colour"  src="images/x_colour.webp"  alt="" aria-hidden="true">
   </div>

   Modes: rise · sweep · bloom · flowers · fade
   Set --fill (0%–100%) yourself and add .is-held to stop the loop (used by the slider).
────────────────────────────────────── */
@property --fill {
  syntax: '<percentage>';
  inherits: true;
  initial-value: 0%;
}

.fill {
  --fill: 0%;
  --cycle: 10s;
  position: relative;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  overflow: hidden;
  animation: fillCycle var(--cycle) ease-in-out infinite;
  animation-delay: var(--delay, 0s);   /* a negative --delay starts part-way through */
}

.fill img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.fill :is(.fill-colour, .fill-mono) {
  --p: var(--fill);
  -webkit-mask-image: var(--mask);
          mask-image: var(--mask);
  animation: fillRest var(--cycle) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

/* Colour soaks up from the stems */
.fill[data-mode="rise"] :is(.fill-colour, .fill-mono) {
  --mask: linear-gradient(to top, #000 calc(var(--p) * 1.2 - 20%), transparent calc(var(--p) * 1.2));
}

/* A soft diagonal pass, like a brush across the page */
.fill[data-mode="sweep"] :is(.fill-colour, .fill-mono) {
  --mask: linear-gradient(115deg, #000 calc(var(--p) * 1.2 - 20%), transparent calc(var(--p) * 1.2));
}

/* Opens from the heart of the bouquet */
.fill[data-mode="bloom"] :is(.fill-colour, .fill-mono) {
  --mask: radial-gradient(circle at 50% 52%, #000 calc(var(--p) * 1.2 - 20%), transparent calc(var(--p) * 1.2));
}

/* One flower at a time, the way a hand colours it */
.fill[data-mode="flowers"] :is(.fill-colour, .fill-mono) {
  --mask:
    radial-gradient(circle at 36% 20%, #000 calc(var(--p) * 1.5 - 4%),  transparent calc(var(--p) * 1.5 + 6%)),
    radial-gradient(circle at 72% 33%, #000 calc(var(--p) * 1.5 - 14%), transparent calc(var(--p) * 1.5 - 4%)),
    radial-gradient(circle at 30% 62%, #000 calc(var(--p) * 1.5 - 24%), transparent calc(var(--p) * 1.5 - 14%)),
    radial-gradient(circle at 58% 76%, #000 calc(var(--p) * 1.5 - 34%), transparent calc(var(--p) * 1.5 - 24%)),
    radial-gradient(circle at 52% 46%, #000 calc(var(--p) * 1.5 - 44%), transparent calc(var(--p) * 1.5 - 34%));
}

/* Plain crossfade, as on the current front page */
.fill[data-mode="fade"] :is(.fill-colour, .fill-mono) {
  --mask: linear-gradient(rgb(0 0 0 / var(--p)), rgb(0 0 0 / var(--p)));
}

/* Three stages: whisper -> bold mono (first half) -> full colour (second half).
   <div class="fill fill--three" data-mode="..."> whisper img, .fill-mono img, .fill-colour img */
.fill--three .fill-mono   { --p: clamp(0%, var(--fill) * 2, 100%); }
.fill--three .fill-colour { --p: clamp(0%, var(--fill) * 2 - 100%, 100%); }

/* Whisper holds, colour arrives, colour holds, then quietly lets go */
@keyframes fillCycle {
  0%, 14%   { --fill: 0%; }
  58%, 100% { --fill: 100%; }
}
@keyframes fillRest {
  0%, 86% { opacity: 1; }
  98%     { opacity: 0; }
  100%    { opacity: 0; }
}

.fill.is-held,
.fill.is-held :is(.fill-colour, .fill-mono) {
  animation: none;
  opacity: 1;
}

/* Reduced motion (phone setting, or Windows "animation effects" off): no moving edges,
   but the colour still arrives, as a slow gentle crossfade.
   Add class "motion-ok" to <html> to show the moving versions anyway (the visitor's choice). */
@media (prefers-reduced-motion: reduce) {
  :root:not(.motion-ok) .fill { --cycle: 16s; }
  :root:not(.motion-ok) .fill[data-mode] :is(.fill-colour, .fill-mono) {
    --mask: linear-gradient(rgb(0 0 0 / var(--p)), rgb(0 0 0 / var(--p)));
  }
}

/* ──────────────────────────────────────
   WHISPERAE BRUSH — the visitor brings the colour back by hand (brush.js)
────────────────────────────────────── */
.brush {
  position: relative;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  overflow: hidden;
}
.brush .brush-whisper,
.brush .brush-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.brush .brush-canvas {
  touch-action: none;          /* dragging on the picture paints instead of scrolling the page */
  cursor: crosshair;
}
.brush .brush-hint {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.8);
  color: #4a4845;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.brush.is-touched .brush-hint { opacity: 0; }
.brush.is-letting .brush-canvas { cursor: cell; }

/* Brush size ring: follows the pointer (a finger only while it is down) and shows the brush size */
.brush .brush-ring {
  position: absolute;
  left: 0; top: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgb(255 255 255 / 0.9);
  box-shadow: 0 0 0 1px rgb(58 55 51 / 0.45), inset 0 0 0 1px rgb(58 55 51 / 0.25);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.brush .brush-ring.is-shown { opacity: 1; }
@media (hover: hover) { .brush .brush-canvas { cursor: none; } }   /* the ring replaces the crosshair on a mouse */
.brush.pen-on .brush-ring { display: none; }                        /* creator's Sharpie pointer instead */

/* Tease <-> Wipe slider and Reveal all (brush.js fills <div class="brush-controls" data-for="ID">) */
.brush-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.2rem; }
.brush-level { display: inline-flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: #6b6762; }
.brush-level-end { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.3rem; }
.brush-icon { flex: none; color: #6f8e6e; }
.brush-level input[type="range"] {
  width: clamp(8rem, 30vw, 13rem);
  height: 2.2rem;                  /* a big target for fingers */
  accent-color: #6f8e6e;
  cursor: pointer;
}
.brush-reveal-all {
  font: inherit; font-size: 0.85rem; padding: 0.4rem 0; cursor: pointer;
  border: none; border-bottom: 1px solid #c9c4bc; background: none; color: #6b6762;
}
.brush-reveal-all:focus-visible, .brush-level input:focus-visible { outline: 2px solid #6f8e6e; outline-offset: 3px; }
.brush, .brush * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* Creator-only recording panel (brush.js, page opened with #record) */
.brush-record {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.9rem;
  margin-top: 0.8rem; padding: 0.7rem 1rem; border: 1px dashed #b5b0a8; border-radius: 4px;
  font-size: 0.85rem; color: #4a4845; background: #fdfcf9;
}
.brush-record-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: #c62828; }
.brush-record button {
  font: inherit; font-size: 0.82rem; padding: 0.35rem 0.8rem; cursor: pointer;
  border: 1px solid #b5b0a8; border-radius: 999px; background: #fff; color: #1e1c1a;
}
.brush-record-text { flex: 1 1 100%; font-family: ui-monospace, Consolas, monospace; font-size: 0.75rem; }

/* Optional Sharpie pointer: switched on and sized in the #record panel (brush.js sets it);
   the default is a fine crosshair */
.brush-record-size { display: inline-flex; align-items: center; gap: 0.5rem; }
.brush-record-size input { width: 8rem; accent-color: #6f8e6e; }
.brush-record-size-px { font-variant-numeric: tabular-nums; min-width: 3.5em; }
.brush-record-pick { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; font-size: 0.82rem; }
.brush-record-pick label { display: inline-flex; flex-direction: column; gap: 0.25rem; }
