/*
 * The camera, taken apart (photography/camera): a Leica M-style rangefinder drawn with the
 * teardown skill (_teardown/rangefinder). The camera taken apart, with every part picked out on
 * its own; how it works, step by step (the lens, with the spot one point makes on the film; the
 * rangefinder at work; the shutter); every part listed with what it does. Light ink on the
 * photography pages' dark ground, its lines the same width on screen at any size: what moves
 * when the lens is focused in amber, the light in the LED red, the glass in pale blue, the
 * see-through shells dimmed. Phone first.
 */
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/schibsted-grotesk-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/schibsted-grotesk-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/geist-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0c0c0c;
  --panel: #111110;
  --ink: #edebe6;
  --muted: #9a978f;
  --rule: rgba(255, 255, 255, .1);
  --led: #ff4a2e;
  --ui: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --gut: clamp(1rem, 4vw, 2.4rem);
  --td-ink: #d9d5cc;
  --td-move: #f2a65a;
  --td-light: #ff4a2e;
  --td-glass: #8fc1dc;
  --td-pick: #ffd27a;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.55 var(--ui); }
a { color: inherit; text-underline-offset: .22em; text-decoration-thickness: 1px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
button { font: inherit; color: inherit; }
.cm-skip { position: absolute; left: var(--gut); top: -3rem; padding: .4rem .7rem; background: var(--ink); color: var(--bg); z-index: 5; }
.cm-skip:focus { top: .6rem; }
.cm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.cm-top { padding: var(--gut) var(--gut) 0; }
.cm-crumb { display: flex; gap: .55rem; margin: 0; font: 400 .78rem/1.3 var(--mono); color: var(--muted); }
.cm-crumb a { color: var(--ink); text-decoration: none; }
.cm-crumb a:hover { text-decoration: underline; }

.cm-main { width: min(100%, 78rem); margin: 0 auto; padding: 0 var(--gut); }
.cm-intro { padding: clamp(1.6rem, 6vw, 3.2rem) 0 1rem; max-width: 44rem; }
.cm-h1 { margin: 0 0 .6rem; font: 500 clamp(1.7rem, 6.4vw, 2.8rem)/1.08 var(--ui); letter-spacing: -.01em; text-wrap: balance; }
.cm-lede { margin: 0 0 .7rem; font-size: clamp(1.02rem, 3.6vw, 1.2rem); line-height: 1.45; text-wrap: pretty; }
.cm-note { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.cm-h2 { margin: 0 0 .9rem; font: 500 clamp(1.3rem, 4.6vw, 1.75rem)/1.15 var(--ui); }
.cm-h3 { margin: 0 0 .5rem; color: var(--muted); font: 400 .72rem/1.2 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.cm-body { margin: 0 0 1rem; max-width: 44rem; text-wrap: pretty; }

/* ---------- controls ---------- */
.cm-ctl { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .5rem .9rem; padding: .3rem 0 .6rem; }
.cm-ctl label { color: var(--muted); font: 400 .66rem/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; white-space: nowrap; }
.cm-ctl input { width: 100%; margin: 0; accent-color: var(--td-move); }
.cm-ctl output { min-width: 6.5ch; color: var(--td-move); font: 400 .95rem/1 var(--mono); text-align: right; white-space: nowrap; }
.cm-ctl--stack { grid-template-columns: minmax(0, 1fr); align-content: center; gap: .55rem; padding: 0; }
.cm-ctl__row { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; }
.cm-btn { min-height: 2.5rem; padding: 0 .95rem; border: 1px solid var(--rule); border-radius: .35rem; background: rgba(255, 255, 255, .03); font: 400 .74rem/1 var(--mono); letter-spacing: .06em; cursor: pointer; }
.cm-btn:hover { border-color: rgba(255, 255, 255, .3); }
.cm-btn--quiet { border-color: transparent; background: none; color: var(--muted); }
.cm-hint { margin: .4rem 0 0; color: var(--muted); font: 400 .7rem/1.4 var(--mono); }

/* ---------- the drawings ---------- */
.cm-fig { position: relative; margin: 0; border-radius: .6rem; background: var(--panel); aspect-ratio: 1 / 1.05; cursor: ew-resize; touch-action: pan-y; user-select: none; -webkit-user-select: none; overflow: hidden; }
.cm-fig.is-dragging { cursor: grabbing; }
.cm-layer { position: absolute; inset: 0; opacity: 0; transition: opacity .22s ease-out; }
.cm-layer.is-on { opacity: 1; }
.cm-fig.is-instant .cm-layer { transition: none; }
.cm-wait { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 1rem; color: var(--muted); font: 400 .7rem/1.4 var(--mono); letter-spacing: .1em; text-align: center; text-transform: uppercase; }
.cm-wait[hidden] { display: none; }
.cm-fig svg, .cm-pick__fig svg { display: block; width: 100%; height: 100%; }
.td-rangefinder path { fill: none; stroke: var(--td-ink); stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; transition: opacity .2s, stroke .2s; }
.td-rangefinder [data-line-role="outline"] { stroke-width: 1.25px; }
.td-rangefinder [data-line-role="edge"] { stroke-width: .85px; }
.td-rangefinder [data-line-role="detail"] { stroke-width: .65px; }
.td-rangefinder [data-line-role="texture"] { stroke-width: .4px; }
.td-rangefinder [data-line-role="axis"] { stroke-width: 1px; stroke-dasharray: 4 3; stroke-linecap: butt; }
.td-rangefinder text, .td-rangefinder circle { fill: var(--td-ink); transition: opacity .2s, fill .2s; }
.td-rangefinder text { font-family: var(--mono); letter-spacing: .25px; }
.td-rangefinder [data-leaders] path, .td-rangefinder [data-annotations] path { stroke-width: .6px; opacity: .7; }
.td-rangefinder [data-item="body"] path, .td-rangefinder [data-item="cover"] path { opacity: .45; }
.td-rangefinder [data-item="mirror"] path, .td-rangefinder [data-item="lever"] path,
.td-rangefinder [data-item="rocker"] path, .td-rangefinder [data-item="roller"] path,
.td-rangefinder [data-item="cam"] path, .td-rangefinder [data-item="focus-ring"] path,
.td-rangefinder [data-item="sight"] path { stroke: var(--td-move); }
.td-rangefinder [data-item="splitter"] path, .td-rangefinder [data-item="eyepiece"] path, .td-rangefinder [data-item="frame-window"] path,
.td-rangefinder [data-item="vf-window"] path, .td-rangefinder [data-item="rf-window"] path { stroke: var(--td-glass); }
.td-rangefinder [data-item="light"] path { stroke: var(--td-light); stroke-width: 1.1px; }
.td-rangefinder [data-item="subject"] path { stroke: var(--td-light); }
/* one part picked out: the rest dim, it and its name light up */
.td-rangefinder.has-pick [data-item]:not(.is-pick) path { opacity: .16; }
.td-rangefinder.has-pick [data-annotations] [data-for]:not(.is-pick) { opacity: .2; }
.td-rangefinder.has-pick [data-item].is-pick path { stroke: var(--td-pick); opacity: 1; }
.td-rangefinder.has-pick [data-item].is-pick [data-line-role="outline"] { stroke-width: 1.8px; }
.td-rangefinder.has-pick [data-annotations] text.is-pick, .td-rangefinder.has-pick [data-annotations] circle.is-pick { fill: var(--td-pick); }
.td-rangefinder.has-pick [data-annotations] path.is-pick { stroke: var(--td-pick); opacity: 1; }
/* no room for the names on a phone: the drawing alone, the list names the parts */
.cm-fig .td-rangefinder [data-annotations], .cm-fig .td-rangefinder [data-leaders] { display: none; }

/* solid parts: each filled a shade darker than its ink, so the drawing reads as objects; the
   see-through shell and the glass stay open */
.td-rangefinder [data-fills] path { stroke: none; fill: #1e1d1a; vector-effect: none; transition: opacity .2s; }
.td-rangefinder [data-fills] [data-fill="body"], .td-rangefinder [data-fills] [data-fill="base"] { fill: #171614; }
.td-rangefinder [data-fills] [data-fill="mirror"], .td-rangefinder [data-fills] [data-fill="lever"], .td-rangefinder [data-fills] [data-fill="rocker"],
.td-rangefinder [data-fills] [data-fill="roller"], .td-rangefinder [data-fills] [data-fill="cam"], .td-rangefinder [data-fills] [data-fill="focus-ring"],
.td-rangefinder [data-fills] [data-fill="iris"], .td-rangefinder [data-fills] [data-fill="first"], .td-rangefinder [data-fills] [data-fill="second"] { fill: #2a1f13; }
.td-rangefinder [data-fills] [data-fill="film"] { fill: #3a2d1c; }
.td-rangefinder [data-fills] [data-fill="exposure"] { fill: #ffd27a; }
.td-rangefinder [data-fills] [data-fill="subject"] { fill: #3a1510; }
.td-rangefinder [data-item="iris"] path, .td-rangefinder [data-item="first"] path, .td-rangefinder [data-item="second"] path { stroke: var(--td-move); }
.td-rangefinder [data-item^="glass"] path { stroke: var(--td-glass); }
.td-rangefinder [data-item="exposure"] path { stroke: #ffd27a; }
.td-rangefinder.has-pick [data-fills] path:not(.is-pick) { opacity: .25; }
.td-rangefinder.has-pick [data-fills] path.is-pick { fill: #3b2f16; }
/* the light's path through the camera taken apart: the lens's axis, dashed in the light's red */
.td-rangefinder [data-light] path { stroke: var(--td-light); stroke-width: 1.4px; stroke-dasharray: 7 4; stroke-linecap: butt; opacity: .95; }
.td-rangefinder.has-pick [data-light] path { opacity: .35; }
.cm-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin: .5rem 0 .3rem; color: var(--muted); font: 400 .7rem/1.4 var(--mono); }
.cm-legend i { display: inline-block; width: .8rem; height: .2rem; margin-right: .35rem; vertical-align: middle; border-radius: 1px; }
.cm-legend .is-move { background: var(--td-move); }
.cm-legend .is-slit { background: #ffd27a; }
.cm-legend .is-light { background: var(--td-light); }
.cm-legend .is-path { background: repeating-linear-gradient(90deg, var(--td-light) 0 5px, transparent 5px 8px); }
.cm-legend .is-glass { background: var(--td-glass); }
.cm-fig.cm-fig--shutter { aspect-ratio: auto; min-height: 9rem; cursor: default; touch-action: auto; }
.cm-fig--shutter svg { height: auto; }

/* ---------- how it works ---------- */
.cm-how { padding: clamp(2.2rem, 8vw, 4rem) 0 0; }
.cm-step { position: relative; margin: 0 0 clamp(2rem, 7vw, 3.4rem); padding-top: .2rem; }
.cm-step__n { display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; margin: 0 0 .55rem; border: 1px solid var(--td-move); border-radius: 50%; color: var(--td-move); font: 400 .8rem/1 var(--mono); }
.cm-step__h { margin: 0 0 .5rem; font: 500 clamp(1.12rem, 4.2vw, 1.4rem)/1.2 var(--ui); text-wrap: balance; }
.cm-toc { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; margin: 1rem 0 0; padding: 0; list-style: none; font: 400 .74rem/1.4 var(--mono); }
.cm-toc a { color: var(--ink); }

/* the section through the lens, drawn by camera-lens.js: cut metal hatched, the moving optical
   unit one way and the fixed barrel the other, the glass tinted, the light in the LED red */
.cm-lens { display: grid; gap: .55rem; margin: .7rem 0 .5rem; }
.cm-lens__draw { position: relative; min-height: 8rem; padding: .35rem .2rem; border-radius: .6rem; background: var(--panel); cursor: ew-resize; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.ls { display: block; width: 100%; height: auto; overflow: visible; }
.ls path { fill: none; vector-effect: non-scaling-stroke; }
.ls-cut { fill: #1d1c1a !important; stroke: var(--td-ink); stroke-width: 1px; }
.ls-unit .ls-cut { fill: #22201c !important; }
.ls-body .ls-cut { fill: #161514 !important; }
.ls-hatch { stroke: rgba(217, 213, 204, .36); stroke-width: .5px; }
.ls-focus .ls-cut { stroke: var(--td-move); }
.ls-focus .ls-hatch { stroke: rgba(242, 166, 90, .45); }
.ls-glass { fill: rgba(143, 193, 220, .16) !important; stroke: var(--td-glass); stroke-width: .9px; }
.ls-detail, .ls-thread { stroke: rgba(217, 213, 204, .55); stroke-width: .5px; }
.ls-film { stroke: #c9a46a; stroke-width: 3px; }
.ls-axis { stroke: rgba(217, 213, 204, .3); stroke-width: .6px; stroke-dasharray: 6 2 1 2; }
.ls-ray { stroke: var(--td-light); stroke-width: 1px; }
.ls-ray.is-blocked { opacity: .26; }
.ls-ray.is-beyond { opacity: .38; stroke-dasharray: 2 2; }
.ls-blade { fill: #2c2a26 !important; stroke: var(--td-move); stroke-width: 1px; }
.ls-spot { stroke: #ffd27a; stroke-width: 4px; stroke-linecap: round; }
.ls-label path { stroke: rgba(217, 213, 204, .55); stroke-width: .6px; }
.ls-label text { fill: var(--td-ink); font: 400 2.5px var(--mono); letter-spacing: .08px; }
/* the lens's step: the section, the spot on the film, and the two rings to set them */
.cm-lab { display: grid; gap: .75rem; margin: .7rem 0 1rem; }
.cm-lab .cm-lens { margin: 0; }
.cm-lab__ctl .cm-ctl { grid-template-columns: 5.6rem minmax(0, 1fr) auto; padding: .15rem 0; }
/* the spot one point makes on the film: two square views, and what they measure */
.ls-psf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .6rem; }
.ls-psf__view { margin: 0; }
.ls-psf canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: .4rem; background: #0f0d0b; box-shadow: 0 0 0 1px rgba(255, 255, 255, .14); }
.ls-psf figcaption { margin-top: .35rem; color: var(--muted); font: 400 .64rem/1.4 var(--mono); }
.ls-psf figcaption b { display: block; color: var(--ink); font: 500 .76rem/1.3 var(--ui); }
.ls-psf__read { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .15rem 1.1rem; margin: 0; color: var(--muted); font: 400 .7rem/1.45 var(--mono); }
.ls-psf__read b { color: var(--td-move); font-weight: 400; }

/* ---------- the part picked out ---------- */
.cm-pick { display: grid; grid-template-columns: minmax(0, 7.5rem) minmax(0, 1fr); gap: .9rem; margin-top: .8rem; padding: .9rem; border: 1px solid var(--rule); border-radius: .6rem; background: var(--panel); }
.cm-pick[hidden] { display: none; }
.cm-pick__fig { margin: 0; aspect-ratio: 1; border-radius: .4rem; background: #0a0a09; }
.cm-pick__fig .td-rangefinder path { stroke: var(--td-pick); }
.cm-pick__group { margin: 0 0 .2rem; color: var(--muted); font: 400 .66rem/1.2 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.cm-pick__h { margin: 0 0 .35rem; font: 500 1.1rem/1.25 var(--ui); }
.cm-pick__p { margin: 0 0 .7rem; font-size: .92rem; line-height: 1.5; text-wrap: pretty; }
.cm-pick__keys { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- every part ---------- */
.cm-parts { padding: clamp(2.2rem, 8vw, 4rem) 0 0; }
.cm-group { margin: 0 0 1.4rem; }
/* the catalogue: every part drawn small, its name under it; the card with what it does comes to
   stand under the tapped tile's row */
.cm-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-flow: dense; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.cm-tile { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: .35rem; width: 100%; min-height: 100%; padding: .4rem .4rem .55rem; border: 1px solid var(--rule); border-radius: .5rem; background: var(--panel); text-align: center; cursor: pointer; }
.cm-tile__fig { display: block; aspect-ratio: 1; border-radius: .3rem; background: #0a0a09; }
.cm-tile__fig svg { display: block; width: 100%; height: 100%; padding: 6%; box-sizing: border-box; }
.cm-tile b { display: block; align-self: start; font: 500 .72rem/1.25 var(--ui); text-wrap: balance; }
.js .cm-tile__text { display: none; }
.no-js .cm-grid { grid-template-columns: minmax(0, 1fr); }
.no-js .cm-tile { text-align: left; }
.no-js .cm-tile__fig { display: none; }
.no-js .cm-tile__text { color: var(--muted); font-size: .88rem; line-height: 1.45; }
.cm-tile:hover { border-color: rgba(255, 255, 255, .28); }
.cm-tile[aria-pressed="true"] { border-color: var(--td-pick); background: rgba(255, 210, 122, .06); }
.cm-tile[aria-pressed="true"] b { color: var(--td-pick); }
.cm-tile[aria-pressed="true"] .td-rangefinder path { stroke: var(--td-pick); }
.cm-grid__card { grid-column: 1 / -1; }
.cm-grid__card .cm-pick { margin-top: .1rem; }
.cm-pick [data-up] { display: none; }
.cm-grid__card .cm-pick [data-up] { display: inline-block; }

/* ---------- how it focuses ---------- */
.cm-focus { padding: clamp(2.2rem, 8vw, 4rem) 0 0; }
.cm-focus__deck { display: grid; grid-template-columns: minmax(0, 9.5rem) minmax(0, 1fr); gap: 1rem; align-items: center; margin: 0 0 .9rem; }
.cm-eye { margin: 0; }
.cm-eye svg { display: block; width: 100%; height: auto; border-radius: .4rem; box-shadow: 0 0 0 1px rgba(255, 255, 255, .14); }
.cm-eye figcaption { margin-top: .35rem; color: var(--muted); font: 400 .6rem/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.cm-eye__ghost { transition: transform .3s ease-out; }
.cm-fig--focus { aspect-ratio: 1 / 1.2; }

.cm-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.6rem; margin-top: clamp(2.5rem, 9vw, 4.5rem); padding: 1.4rem var(--gut); border-top: 1px solid var(--rule); color: var(--muted); font: 400 .74rem/1.45 var(--mono); }
.cm-foot p { margin: 0; }
.cm-foot__links { display: flex; gap: 1.2rem; }
.cm-foot a { color: var(--ink); }

/* ---------- wider screens: names on the drawings; the picked part beside the drawing ---------- */
@media (min-width: 600px) {
  .cm-fig { aspect-ratio: 16 / 10.5; }
  .cm-fig--focus { aspect-ratio: 16 / 8.5; }
  .cm-fig .td-rangefinder [data-annotations], .cm-fig .td-rangefinder [data-leaders] { display: inline; }
  .cm-pick { grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); }
  .cm-grid { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: .6rem; }
  .cm-tile b { font-size: .76rem; }
  .cm-focus__deck { grid-template-columns: minmax(0, 14rem) minmax(0, 26rem); }
  .td-rangefinder [data-line-role="outline"] { stroke-width: 1.5px; }
  .td-rangefinder [data-line-role="edge"] { stroke-width: 1px; }
  .td-rangefinder [data-line-role="detail"] { stroke-width: .75px; }
  .td-rangefinder [data-line-role="texture"] { stroke-width: .5px; }
}
@media (min-width: 1000px) {
  .cm-stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 19rem); grid-template-areas: "h h" "ctl ctl" "fig pick" "key pick" "hint pick"; column-gap: 1.2rem; align-items: start; }
  .cm-stage > .cm-h2 { grid-area: h; }
  .cm-stage > .cm-legend { grid-area: key; }
  .cm-stage > .cm-ctl { grid-area: ctl; max-width: 40rem; }
  .cm-stage > .cm-fig { grid-area: fig; }
  .cm-stage > .cm-hint { grid-area: hint; }
  .cm-stage > .cm-pick { grid-area: pick; grid-template-columns: minmax(0, 1fr); margin-top: 0; position: sticky; top: 1rem; }
  .cm-stage > .cm-pick .cm-pick__fig { aspect-ratio: 4 / 3; }
}
/* wider screens: one readable column per step, the drawings capped so their lettering stays small */
@media (min-width: 600px) {
  .cm-step { max-width: 54rem; }
  .cm-lens, .cm-lab__ctl { max-width: 40rem; }
  .ls-psf { max-width: 30rem; }
  .ls-label text { font-size: 2.1px; }
  .cm-step > .cm-fig, .cm-step > .cm-focus__deck { max-width: 54rem; }
}
/* wide screens: the spot on the film beside the section, the rings under the section */
@media (min-width: 1000px) {
  .cm-step--lens { max-width: 58rem; }
  .cm-lab { grid-template-columns: minmax(0, 40rem) minmax(0, 14rem); grid-template-areas: "draw psf" "ctl psf"; column-gap: 1.3rem; align-items: start; }
  .cm-lab .cm-lens { grid-area: draw; }
  .cm-lab .cm-lens__psf { grid-area: psf; }
  .cm-lab__ctl { grid-area: ctl; }
  .ls-psf { grid-template-columns: minmax(0, 1fr); }
  .ls-psf__read { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .cm-layer, .cm-eye__ghost, .td-rangefinder path, .td-rangefinder text { transition: none; }
}
