/* Ordered Dithering, in full: the photograph, and over it a canvas where showcase.js dithers it against the 8×8
   Bayer matrix; beside it the tones (a readout, the ladder of the tones in use, the dial), the grain, the matrix
   itself and the three pictures. The pictures are sized from their own proportions inside the plate. */

.tones{--pad:clamp(16px,3.4vh,36px);position:relative;width:100vw;margin-inline:calc(50% - 50vw);border:0;border-radius:0;
  box-sizing:border-box;min-height:calc(100svh - var(--bar));padding:var(--pad) clamp(18px,4vw,64px);
  display:grid;grid-template-columns:minmax(0,1fr) minmax(280px,340px);gap:clamp(20px,4vw,64px);align-items:center;
  background:#121110;color:#ECE6DB}

/* the photograph, as large as the plate allows; the canvas lies exactly over it */
.plate{position:relative;margin:0;height:calc(100svh - var(--bar) - 2 * var(--pad));container-type:size;display:grid;place-items:center}
.plate img{--ih:min(100cqh,calc(100cqw / var(--ar)));grid-area:1/1;display:block;height:var(--ih);width:calc(var(--ih) * var(--ar));
  box-shadow:0 30px 80px -40px rgb(0 0 0 / .9)}
.plate img[hidden]{display:none}
.plate canvas{position:absolute;image-rendering:pixelated}
.plate canvas[hidden]{display:none}

.panel{display:grid;gap:clamp(14px,2.6vh,26px);align-content:center}
.count{margin:0;display:grid;gap:6px}
.count output{font-family:var(--sans);font-weight:400;font-size:clamp(44px,5vw,76px);line-height:.95;letter-spacing:-.03em}   /* Melodrama's zero is slashed */
.count .per{font:10px/1.4 var(--mono);letter-spacing:.14em;text-transform:uppercase;color:#9A9286}
.count .per:empty{display:none}
/* the tones in use, each as a band */
.ladder{height:16px;margin:0;border-radius:2px;background:var(--ladder,none),repeating-linear-gradient(90deg,#2A2724 0 6px,#1D1B19 6px 12px);
  box-shadow:0 0 0 1px rgb(255 255 255 / .12)}

.dial{display:grid;gap:8px}
.dial label,.panel legend{font:10px/1 var(--mono);letter-spacing:.16em;text-transform:uppercase;color:#9A9286;padding:0}
.dial input{width:100%;margin:4px 0 0;height:22px;background:none;appearance:none;cursor:ew-resize}
.dial input::-webkit-slider-runnable-track{height:2px;background:linear-gradient(90deg,#ECE6DB,#5A554E)}
.dial input::-webkit-slider-thumb{appearance:none;width:16px;height:16px;margin-top:-7px;border-radius:50%;background:#ECE6DB;
  box-shadow:0 0 0 4px rgb(236 230 219 / .16)}
.dial input:focus-visible{outline:none}
.dial input:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 6px rgb(236 230 219 / .35)}
.dial .ends{display:flex;justify-content:space-between;font:9.5px/1 var(--mono);letter-spacing:.1em;color:#7F786E}

.grain,.pictures{margin:0;padding:0;border:0;display:flex;flex-wrap:wrap;gap:6px}
.grain legend,.pictures legend{width:100%;margin-bottom:8px}
.grain input,.pictures input{position:absolute;opacity:0;pointer-events:none}
.grain label{padding:7px 12px;border-radius:999px;cursor:pointer;font:10px/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;
  color:#B5AEA3;box-shadow:inset 0 0 0 1px rgb(255 255 255 / .16)}
.grain input:checked + label{background:#ECE6DB;color:#141210;box-shadow:none}
.grain input:focus-visible + label,.pictures input:focus-visible + label{outline:2px solid #ECE6DB;outline-offset:2px}

/* the matrix: 64 thresholds, each cell as light as its threshold */
.matrix{margin:0;display:grid;grid-template-columns:auto 1fr;gap:14px;align-items:center}
.tile{display:grid;grid-template-columns:repeat(8,13px);grid-auto-rows:13px;justify-self:start;box-shadow:0 0 0 1px rgb(255 255 255 / .14)}
.tile i{display:grid;place-items:center;font:6.5px/1 var(--mono);font-style:normal;background:rgb(calc(var(--v) * 4) calc(var(--v) * 4) calc(var(--v) * 3.9));
  color:rgb(0 0 0 / .55)}
.tile i:nth-child(n){color:color-mix(in srgb,#000 calc(100% - var(--v) * 1.6%),#fff)}
.matrix figcaption{font-size:12.5px;line-height:1.45;color:#B5AEA3}

.pictures{flex-direction:column;flex-wrap:nowrap;gap:4px}
.pictures label{display:grid;grid-template-columns:44px 1fr;gap:12px;align-items:center;padding:6px;border-radius:4px;cursor:pointer;
  color:#B5AEA3;transition:background-color .25s var(--settle),color .25s var(--settle)}
.pictures label img{width:44px;height:44px;object-fit:cover;display:block;border-radius:2px;filter:grayscale(.2)}
.pictures label b{display:block;font-weight:400;font-size:14px;line-height:1.25;color:#ECE6DB}
.pictures label i{display:block;margin-top:2px;font:9.5px/1.3 var(--mono);font-style:normal;letter-spacing:.08em;text-transform:uppercase}
.pictures input:checked + label{background:rgb(236 230 219 / .1)}
.pictures label:hover{background:rgb(236 230 219 / .06)}

@media (max-width:860px){
  .tones{grid-template-columns:minmax(0,1fr);align-items:start}
  .plate{height:62svh}
  .panel{grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-items:start;gap:18px}
  .count,.ladder,.dial,.pictures{grid-column:1/-1}
  .matrix{grid-template-columns:auto;gap:8px}
  .matrix figcaption{font-size:11.5px}
}
