/* Scoped Rotation, in full: one registered, inherited angle, animated on the swatches, on the root or on the
   painting (a radio group, mirrored into data-scope). Wherever it is declared, every element below re-resolves each
   frame; only the swatches and, in the last case, the painting's dots use it, and a frame draws that scope.
   showcase.js samples the painting into the dots, keeps every turn on one clock and times the frames; when the stage
   is out of view the turn pauses, so the page stops paying. */

/* a number of degrees, not an angle: in relative colour, the h it is added to resolves to a number */
@property --turn{syntax:'<number>';inherits:true;initial-value:0}
@keyframes turn{to{--turn:360}}

.scope{--paper:#EFE9DC;--ink:#1F1A14;--mid:#5A5145;--dim:#877D6F;--line:rgb(31 26 20 / .14);--scoped:#B4502A;color-scheme:light;
  width:100vw;margin-inline:calc(50% - 50vw);border:0;border-radius:0;background:var(--paper);color:var(--ink);
  display:grid;grid-template-columns:minmax(0,1.8fr) minmax(290px,1fr);gap:clamp(24px,3.6vw,60px);align-items:start;
  padding:clamp(28px,5vw,72px) clamp(16px,4vw,64px)}

/* the painting, in dots; the image itself stands in until they are drawn */
.mosaic{display:grid;grid-template-columns:repeat(var(--cols),1fr);aspect-ratio:var(--cols) / var(--rows)}
.mosaic:not(:has(i)){background:var(--src) 0 0 / 100% 100%}
.mosaic i{aspect-ratio:1;margin:11%;border-radius:50%}

/* where the angle lives: data-scope, mirrored from the radios by showcase.js onto the stage and, for the root, onto
   <html>. Attribute selectors, not :has(): every dot re-matches its selectors each frame, and a :has() in them
   multiplied the painting's cost six times over. Each dot carries its colour as OKLCH, converted once. */
.swatches li{background:oklch(from var(--c) l c calc(h + var(--turn)))}
.scope[data-scope=swatches] .swatches{animation:turn 8s linear infinite}
:root[data-scope=root]{animation:turn 8s linear infinite}
.scope[data-scope=painting] .mosaic{animation:turn 8s linear infinite}
.mosaic i{background:oklch(var(--l) var(--k) var(--h))}
.scope[data-scope=painting] .mosaic i{background:oklch(var(--l) var(--k) calc(var(--h) + var(--turn) * 1deg))}

/* the scope, drawn: a frame around the element the angle is declared on, and around the whole page for the root.
   Every turn keeps one clock (showcase.js), so from the swatches to the root the colours carry on unbroken and only
   the frame and the counter move */
.swatches,.mosaic{outline:1.5px solid transparent;outline-offset:9px;transition:outline-color .45s var(--settle)}
.scope[data-scope=swatches] .swatches,.scope[data-scope=painting] .mosaic{outline-color:var(--scoped)}
.scope::after{content:'';position:fixed;inset:0;z-index:100;pointer-events:none;box-shadow:inset 0 0 0 1.5px var(--scoped);
  opacity:0;transition:opacity .45s var(--settle)}
.scope[data-scope=root]::after{opacity:1}

.panel{position:sticky;top:calc(var(--bar) + 24px);display:grid;gap:clamp(18px,2.6svh,28px)}
.where{display:grid;gap:6px;margin:0;padding:0;border:0}
.where legend{margin-bottom:10px;padding:0;font:10px/1 var(--mono);letter-spacing:.16em;text-transform:uppercase;color:var(--dim)}
.where input{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.where label{display:flex;justify-content:space-between;align-items:baseline;gap:12px;padding:12px 16px;border-radius:12px;
  cursor:pointer;font:400 clamp(17px,1.4vw,20px)/1.15 var(--display);white-space:nowrap;box-shadow:inset 0 0 0 1px var(--line);
  transition:background-color .25s var(--settle),color .25s var(--settle)}
/* where the panel is narrow, the note wraps and the name does not */
.where label small{font:10px/1.4 var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--dim);white-space:normal;
  text-align:right}
.where label:hover{box-shadow:inset 0 0 0 1px var(--ink)}
.where input:checked + label{background:var(--ink);color:var(--paper)}
.where input:checked + label small{color:rgb(239 233 220 / .66)}
.where input:focus-visible + label{outline:2px solid var(--ink);outline-offset:2px}

.meter{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px 22px;align-items:start}
.meter p{margin:0;display:grid;gap:6px}
.meter output{font:400 clamp(40px,4.4vw,64px)/.9 var(--sans);letter-spacing:-.03em;font-variant-numeric:tabular-nums}   /* Melodrama's zero is slashed */
.meter p span{font:10px/1.3 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--dim)}
.meter canvas{grid-column:1 / -1;width:100%;height:48px;display:block;margin-top:8px}
.meter .scale{grid-column:1 / -1;font:10px/1.3 var(--mono);letter-spacing:.06em;color:var(--dim)}

.swatches{display:grid;grid-template-columns:repeat(12,1fr);gap:6px;margin:0;padding:0;list-style:none}
.swatches li{aspect-ratio:1;border-radius:50%}
.original{display:grid;grid-template-columns:88px 1fr;gap:14px;align-items:center;margin:0}
.original img{display:block;width:88px;height:calc(88px / var(--ar))}
.original figcaption{font:10px/1.5 var(--mono);letter-spacing:.06em;color:var(--dim)}

@media (max-width:900px){
  .scope{grid-template-columns:minmax(0,1fr)}
  .panel{position:static}
}
