/*
   The anatomy study on a work page: a finished piece taken apart into colour plates,
   line work and palette (template-parts/study.php, assets/js/study.js).
   Lilac, because a model helped make it. Loaded only on pages that have a study.

   --ar  the study's width over its height, from its JSON, so the space is held before anything loads
*/
.study { margin-top: var(--section); padding: clamp(1.5rem, 4vw, 4.5rem) clamp(1.25rem, 4vw, 4.5rem); border-radius: var(--r-panel); background: var(--lilac); overflow: clip; }
.study .label { color: var(--ink); }

.study__head { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: 1.5rem clamp(2rem, 5vw, 5rem); align-items: end; padding-bottom: clamp(1.5rem, 3vw, 2.5rem); border-bottom: 1px solid var(--ink); }
.study__intro { display: grid; gap: 1rem; }
.study__intro .label { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.study__intro .lede { font-size: clamp(1.15rem, 1.5vw, 1.35rem); }

.study__body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: clamp(2rem, 5vw, 5rem); align-items: start; padding-block: clamp(2rem, 4vw, 3.5rem); }
.study__figure { display: grid; gap: 1rem; justify-items: center; }
.study__figure figcaption { justify-self: start; }
/* Beside a long palette the picture stays in view. */
@media (min-width: 901px) { .study__figure { position: sticky; top: 1.5rem; } }

/* The stage holds the artwork's shape. Tall pieces are kept to the height of the window so the whole stack can be seen at once. */
.study__stage { position: relative; width: 100%; scroll-margin-top: 1rem; max-width: calc(min(76vh, 820px) * var(--ar)); aspect-ratio: var(--ar); perspective: 1900px; }
/* study.js turns the stack and spreads its sheets in depth. `will-change` keeps each sheet's picture as drawn, so moving it costs no redrawing. */
.study__stack { position: absolute; inset: 0; transform-style: preserve-3d; }
.study__sheet { position: absolute; inset: 0; will-change: transform; transition: opacity 0.35s; }
.study__sheet svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.study__ground { background: var(--ground, var(--paper)); transition: opacity 0.35s, background-color 0.35s; }
/* The finished artwork lies on top of the closed stack and gives way as it opens. */
.study__art { position: absolute; inset: 0; overflow: hidden; transition: opacity 0.35s; }
.study__art img { position: absolute; max-width: none; height: auto; }
.study.is-ready.is-open .study__art, .study.is-ready.is-solo .study__art, .study.is-ready[data-mode="lines"] .study__art { opacity: 0; }

/* Each sheet gets an edge once the stack is open. The line work carries an index tab, and so does a plate shown on its own. */
.study__ground::after, .study__plate::after, .study__lines::after { content: ""; position: absolute; inset: 0; border: 1px solid rgb(33 28 26 / 0.3); opacity: 0; transition: opacity 0.35s; }
.study__tag { position: absolute; left: 0; bottom: 100%; margin-bottom: 0.5rem; writing-mode: vertical-rl; rotate: 180deg; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; line-height: 1; text-transform: uppercase; white-space: nowrap; color: var(--ink); opacity: 0; transition: opacity 0.35s; }
.study.is-open .study__sheet::after, .study.is-open .study__lines .study__tag, .study.is-open .study__plate.is-on .study__tag { opacity: 1; }

.study__lines { opacity: 0; }
.study.is-open .study__lines, .study[data-mode="lines"] .study__lines { opacity: 1; }
.study__lines path { stroke-width: 1.6; }
/* Every anchor point of a logo, as a small square. */
.study__lines .nodes { vector-effect: non-scaling-stroke; stroke: var(--tomato); stroke-width: 3.5px; }
.study[data-mode="plates"] .study__lines .nodes { opacity: 0; }

.study[data-mode="lines"] .study__plate { opacity: 0; }
.study.is-solo .study__plate:not(.is-on) { opacity: 0; }
.study.is-solo .study__lines { opacity: 0.3; }
/* A pale plate on its own is shown on ink, where it can be seen. */
.study.is-pale .study__ground { background: var(--ink); }
.study.is-pale .study__lines path:not(.nodes) { stroke: var(--paper); }

/* The line work draws itself. Shapes are selected by tag and class, never by [pathLength]: see the note on `.draw` in style.css. */
@media (prefers-reduced-motion: no-preference) {
	.js .study__lines path:not(.nodes) { stroke-dasharray: 1 1.5; stroke-dashoffset: 1.2; transition: stroke-dashoffset 1.5s var(--ease); }
	.js .study.is-drawn .study__lines path:not(.nodes) { stroke-dashoffset: 0; }
	.js .study__lines .nodes { opacity: 0; transition: opacity 0.6s; }
	.js .study.is-drawn[data-mode="lines"] .study__lines .nodes { opacity: 1; transition-delay: 1.4s; }
}

/* Controls */
.study__side { display: grid; gap: clamp(2rem, 4vw, 3rem); }
.study__controls { display: grid; gap: 0.5rem; }
.study__pull { -webkit-appearance: none; appearance: none; width: 100%; height: var(--tap); margin: 0; background: none; cursor: grab; touch-action: pan-y; }
.study__pull::-webkit-slider-runnable-track { height: 2px; background: var(--ink); }
.study__pull::-moz-range-track { height: 2px; background: var(--ink); }
/* A square thumb, like an anchor point. */
.study__pull::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -13px; border: 0; border-radius: 0; background: var(--tomato); }
.study__pull::-moz-range-thumb { width: 28px; height: 28px; border: 0; border-radius: 0; background: var(--tomato); }
.study__pull:active { cursor: grabbing; }
.study__pull:disabled { opacity: 0.45; cursor: default; }
.study__modes { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Palette */
.study__palette { display: grid; gap: 1rem; justify-items: start; }
.study__bar { display: flex; width: 100%; height: clamp(2.75rem, 5vw, 4rem); border: 1px solid var(--ink); }
.study__bar span { flex: 0 0 auto; min-width: 3px; cursor: pointer; }
.study__swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.5rem; width: 100%; margin: 0; border-top: 1px solid var(--ink); }
.study__swatch { display: grid; grid-template-columns: 1.5rem 1.75rem minmax(0, 1fr) auto; gap: 0.6rem; align-items: center; width: 100%; min-height: 46px; padding: 0.25rem 0.5rem; border: 0; border-bottom: 1px solid rgb(33 28 26 / 0.22); border-radius: 0; background: none; text-align: left; font-variant-numeric: tabular-nums; cursor: pointer; transition: background-color 0.2s, color 0.2s; }
.study__swatch:hover { background: rgb(255 255 255 / 0.55); }
.study__swatch[aria-pressed="true"] { background: var(--ink); color: var(--lilac); }
.study__no { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; }
.study__chip { width: 1.75rem; height: 1.75rem; border: 1px solid rgb(33 28 26 / 0.4); }
.study__swatch[aria-pressed="true"] .study__chip { border-color: var(--lilac); }
.study__hex { font-weight: 700; font-stretch: 80%; letter-spacing: 0.04em; }
.study__share { font-family: var(--font-serif); }
.study__note { font-size: 0.95rem; max-width: 30em; }
.study__all:disabled { visibility: hidden; }

/* A logo at four sizes. */
.study__sizes { display: grid; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--ink); }
.study__sizes ul { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; margin: 0; padding: 0; list-style: none; }
.study__sizes li { display: grid; gap: 0.5rem; }
.study__sizes img { box-sizing: content-box; padding: 8px; background: var(--paper); }

/* The numbers */
.study__foot { display: grid; gap: clamp(1.25rem, 2.5vw, 2rem); padding-top: clamp(1.25rem, 2.5vw, 2rem); border-top: 1px solid var(--ink); }
.study__numbers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem clamp(1rem, 3vw, 3rem); margin: 0; }
.study__numbers div { display: grid; grid-template-rows: 1fr auto; gap: 0.5rem; }
.study__numbers dd { margin: 0; font-size: clamp(2.75rem, 10.5vw, 10rem); font-variant-numeric: tabular-nums; }
.study__small { font-size: 0.95rem; max-width: 44em; }

/* Without scripts the finished artwork, the palette and the numbers still read; the controls would do nothing. */
html:not(.js) .study__controls, html:not(.js) .study__hint, html:not(.js) .study__all { display: none; }
html:not(.js) .study__swatch, html:not(.js) .study__bar span { pointer-events: none; }

@media (max-width: 900px) {
	.study__head, .study__body { grid-template-columns: 1fr; }
	.study__lines path { stroke-width: 2; }
	.study__lines .nodes { stroke-width: 2.5px; }
	.study__tag { font-size: 0.56rem; letter-spacing: 0.1em; margin-bottom: 0.35rem; }
}
@media (max-width: 520px) {
	.study__swatches { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
	.study__sheet, .study__sheet::after, .study__art, .study__tag, .study__swatch { transition: none; }
}
