/* =====================================================================
   ch-joint.css: chapter 3, Robot joint (chapters/30-joint.html), one page.
   Layout for the page's own drawn things: the head ghost's 8:1 turn, the CAD print
   beside the head, the drive's stage key, the to-scale tolerance band, the dial
   clip's speed chain. The chapter head itself (.chead, .cb-h) is shared and lives
   in css/ch-simulation.css. Tokens only (css/book.css); every pending state is
   scoped to .mo, so no-JS and reduced motion show the finished page. The drive
   module gets its mounted size reserved, so mounting never changes the page's height.
   ===================================================================== */

/* ------------------------------------------------------------------ head ghost */
/* the sector and the drum turn about their own centres (data-scrub-rotate, written by book.js) */
#joint .jg-turn { transform-box: view-box; }
#joint .jg-sector { transform-origin: 330px 440px; }
#joint .jg-drum { transform-origin: 330px 155.75px; }
/* the capstan sits behind the title, between the numeral and the CAD print */
#joint .jt-ghost { left: 12%; right: 30%; top: calc(-1 * var(--pad-top)); bottom: 0; }
#joint .jt-ghost svg { overflow: hidden; }
/* the CAD print beside the head: square-ish, so it is held narrower than a video would be */
#joint .jl-cad { width: min(100%, 420px); margin-left: auto; }
@media (max-width: 1180px) { #joint .jl-cad { margin-left: 0; } }

/* ------------------------------------------------------------------ shared */
.jt-cols { align-items: start; }
.jt-cols > * { min-width: 0; }

/* ------------------------------------------------------------------ the drive */
/* the order and the why across the top, then the drawing on its own, the full width of the block
   (held to 1040 px so the one-row drawing never gets taller than the page) */
.jdr-lede { max-width: 44em; margin-bottom: var(--s6); }
.jdr-cols { display: block; max-width: 1040px; }
#joint-drive .anim { min-height: 200px; }
html:not(.js) #joint-drive .anim { aspect-ratio: auto; }   /* no JS: the key sets the height */
/* with JS, the box already has the size js/anim/drivetrain.js will give it, by the figure's width:
   one row from 553 px, below that the stages stacked top to bottom (no wider than 420 px inside the
   1.5 px border, so no taller than 730.33 px inside it) */
#joint-drive .jdr-fig { container-type: inline-size; }
.js #joint-drive .anim:not(.anim-drivetrain) { aspect-ratio: 720 / 310; }
@container (max-width: 552.98px) { .js #joint-drive .anim:not(.anim-drivetrain) { aspect-ratio: auto; height: 733.33px; } }
@container (max-width: 423px) { .js #joint-drive .anim:not(.anim-drivetrain) { aspect-ratio: 360 / 626; height: auto; } }
/* and the controls bar the module adds under the drawing (44 px buttons + 1.5 px rule), plus the
   caption's top margin, which would otherwise collapse into this one */
.js #joint-drive .jdr-fig:not(:has(.vp-tools)) .anim { margin-bottom: calc(45.5px + var(--s3)); }
/* four buttons: the three views (Whole drive, Show backlash, How the capstan works; one is always
   pressed) and Pause, set apart at the end. They fit one row from 553 px. Below that, while the
   drawing is stacked, they always make two rows (Whole drive and Show backlash, then How the capstan
   works and Pause), so the bar is a known 44 + 44 + 1.5 px (the second row's rule sits inside its
   buttons) and that height is reserved too */
#joint-drive .jdr-tools button { padding: 0 12px; }
#joint-drive .jdr-tools [data-act="capstan"] { border-right: 0; }
#joint-drive .jdr-tools [data-act="play"] { margin-left: auto; border-right: 0; border-left: 1px solid var(--line-2); }
@container (max-width: 552.98px) {
  #joint-drive .jdr-tools [data-act="whole"], #joint-drive .jdr-tools [data-act="backlash"] { flex: 1 1 40%; }
  #joint-drive .jdr-tools [data-act="backlash"] { border-right: 0; }
  #joint-drive .jdr-tools [data-act="capstan"] { flex: 1 1 auto; border-top: 1px solid var(--line-2); }
  #joint-drive .jdr-tools [data-act="play"] { flex: 0 0 auto; margin-left: 0; border-top: 1px solid var(--line-2); }
  .js #joint-drive .jdr-fig:not(:has(.vp-tools)) .anim { margin-bottom: calc(89.5px + var(--s3)); }
}
/* the way back from a close-up: in the drawing's top right corner, over the Schematic tag; when the
   drawing is stacked, in the bottom right corner instead, just above the toolbar */
#joint-drive .jdr-back {
  position: absolute; top: 0; right: 0; z-index: 4; min-height: var(--tap); min-width: var(--tap); padding: 0 12px;
  border: 0; border-left: 1.5px solid var(--line); border-bottom: 1.5px solid var(--line); background: var(--paper);
  color: var(--ink); font: 600 11.5px var(--f-mono); letter-spacing: .1em; text-transform: uppercase; cursor: pointer;
}
#joint-drive .jdr-back[hidden] { display: none; }
#joint-drive .jdr-back:hover { background: linear-gradient(rgba(216,232,255,.08), rgba(216,232,255,.08)), var(--paper); }
#joint-drive .jdr-back:focus-visible { outline-offset: -5px; }   /* the drawing clips anything outside it */
#joint-drive .jdr-compact .jdr-back { top: auto; bottom: 0; border-bottom: 0; border-top: 1.5px solid var(--line); }
#joint-drive .jdr-zoomed:not(.jdr-compact) .vp-tag { visibility: hidden; }
/* on the narrowest phones (a 320 px screen leaves the figure about 228 px) the type tightens a
   little so How the capstan works and Pause still share the second row (after the
   rules above, so it wins) */
@container (max-width: 289.98px) {
  #joint-drive .jdr-tools button, #joint-drive .jdr-back { padding: 0 8px; font-size: 11px; letter-spacing: .06em; }
}
/* the stage key, for no JS (the module replaces it with the drawing) */
.jdr-key { list-style: none; margin: 0; padding: 40px 20px 20px; display: grid; gap: 10px; font: 500 14px/1.45 var(--f-mono); }
.jdr-key b { display: inline-grid; place-items: center; width: 26px; height: 26px; margin-right: 10px; border: 1.5px solid var(--line); border-radius: 50%; font-weight: 600; }
.jdr-key li:last-child b { border-width: 3px; }
/* the drawing appears with its frame, then turns (the module plays only while it is on screen) */
.mo .jdr-fig:not(.in) .anim > svg { opacity: 0; }
.mo .jdr-fig.in .anim > svg { transition: opacity .6s ease .15s; }

/* ------------------------------------------------------------------ tests */
#joint-tests .jt-dial { width: min(100%, 250px); justify-self: start; }
#joint-tests .jt-results td.res, #joint-tests .jt-results td.num { white-space: normal; }
#joint-tests .jt-results td small { margin-top: 4px; font: italic 400 14px/1.35 var(--f-body); color: var(--ink-2); white-space: normal; }
#joint-tests .jt-results td small .tbd { font-style: normal; }
#joint-tests .table-wrap { margin-top: var(--s6); }
#joint-tests .jt-cols { grid-template-columns: 250px minmax(0, 1fr); gap: var(--s5) clamp(32px, 5vw, 80px); }

/* the tolerance band, to scale (no JS): the field is 1.0 mm wide, -0.5 to +0.5 mm;
   the measured ±0.22 mm is the amber band from 28% to 72%. It opens from 0 like calipers. */
.jt-scale { display: block; padding: 4px 0 0; }
.jt-sc-head { display: flex; justify-content: space-between; gap: 12px; font: 500 var(--t-label)/1.2 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.jt-sc-field { position: relative; display: block; height: 96px; margin: 8px 0 0; }
.jt-band-lbl { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); white-space: nowrap; font: 600 14px/1 var(--f-mono); letter-spacing: .06em; color: var(--accent); }
.jt-band { position: absolute; left: 28%; width: 44%; top: 38px; height: 12px; background: var(--accent); }
.jt-band::before, .jt-band::after { content: ""; position: absolute; top: -9px; bottom: -9px; width: 2px; background: var(--accent); }
.jt-band::before { left: 0; }
.jt-band::after { right: 0; }
.jt-axis { position: absolute; left: 0; right: 0; bottom: 14px; height: 1.5px; background: var(--line); }
.jt-axis::before { content: ""; position: absolute; left: 0; right: 0; top: -6px; height: 13px;
  background-image: linear-gradient(90deg, var(--line-2) 1px, transparent 1px), linear-gradient(90deg, var(--line) 2px, transparent 2px);
  background-size: calc(10% - .1px) 7px, calc(50% - 1px) 13px; background-position: 0 3px, 0 0; background-repeat: repeat-x; }
.jt-axis::after { content: ""; position: absolute; right: -1px; top: -6px; height: 13px; border-left: 2px solid var(--line); }
.jt-sc-ticks { position: relative; display: block; height: 20px; font: 500 12px/1 var(--f-mono); color: var(--ink-2); }
.jt-sc-ticks span { position: absolute; left: calc(var(--at) * 100%); transform: translateX(-50%); white-space: nowrap; }
.jt-sc-ticks span:first-child { transform: none; }
.jt-sc-ticks span:last-child { transform: translateX(-100%); }
.jt-band { transform-origin: 50% 50%; }
.mo .jt-readout:not(.in) .jt-band { transform: scaleX(0); }
.mo .jt-readout:not(.in) .jt-band-lbl { opacity: 0; }
.mo .jt-readout.in .jt-band { transition: transform .8s var(--ease) .25s; }
.mo .jt-readout.in .jt-band-lbl { transition: opacity .3s ease .8s; }

/* the dial clip's speed labels as a chain dimension over the frame: 2x, 5x, 10x in proportion to
   when each label is on screen (2x to about 7 s, 5x to about 13 s, 10x to the end, 34.2 s) */
.jt-chain { display: flex; margin: 0 0 10px; }
.jt-chain .dim { flex: 0 0 calc(var(--w) * 100%); margin: 0; gap: 6px; text-transform: none; letter-spacing: .04em; }

/* ------------------------------------------------------------------ phone */
@media (max-width: 760px) {
  #joint-tests .jt-dial { justify-self: center; width: min(100%, 300px); }
  #joint-tests .jt-cols { grid-template-columns: minmax(0, 1fr); }
  #joint .jt-ghost { left: 0; right: -20%; }
  .jt-band-lbl { font-size: 13px; }
  .jt-sc-head { font-size: 10.5px; letter-spacing: .1em; }
}

/* ------------------------------------------------------------------ tests: precision on the scale of things */
/* js/anim/precision.js replaces the static band (.jt-scale, kept for no JS) with a zoom from a basketball
   down to a hair. Height reserved before it mounts so mounting never changes the page's height:
   head 22 + 6, stage 440, zoom row 8 + 44, tools 10 + 46 = 576 px (phone: stage 340, tools in two rows: 520) */
.js #fig-joint-readout:not(.is-live) { min-height: 576px; }
.jt-readout.is-live .jt-scale { display: none; }
#joint-tests .jt-results .jt-lift2 { display: block; margin-top: 4px; }
.prec { container-type: inline-size; }
.prec-head { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 12px; height: 22px; margin: 0 0 6px; font: 500 var(--t-label)/1.2 var(--f-mono); color: var(--ink-2); white-space: nowrap; }
.prec-view { color: var(--ink); letter-spacing: .04em; font-variant-numeric: tabular-nums; }
/* the scale bar: a 100 px line scaled to the round length, its right tick and its text moved along */
.prec-bar { position: relative; flex: 1 1 auto; height: 22px; min-width: 150px; }
.prec-bar i { position: absolute; left: 0; display: block; background: var(--ink); }
.prec-bar-a, .prec-bar-b { top: 5px; width: 1.5px; height: 12px; }
.prec-bar-l { top: 10.25px; width: 100px; height: 1.5px; transform-origin: 0 50%; }
.prec-bar-t { position: absolute; left: 0; top: 3px; color: var(--ink); font-variant-numeric: tabular-nums; }
.prec-stage { position: relative; height: 440px; border: 1px solid var(--line-2); background: radial-gradient(110% 85% at 45% 35%, rgba(216,232,255,.07), transparent 70%); touch-action: pan-y; cursor: grab; -webkit-user-select: none; user-select: none; overflow: hidden; contain: layout paint; }
.prec-stage.is-dragging { cursor: grabbing; }
.prec-svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.prec-zoom { display: grid; grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap); align-items: center; gap: 10px; margin-top: 8px; }
.prec-step { appearance: none; width: var(--tap); height: var(--tap); padding: 0; border: 1.5px solid var(--line); background: transparent; color: var(--ink); font: 500 20px/1 var(--f-mono); cursor: pointer; }
.prec-step:hover { background: rgba(216,232,255,.08); }
.prec-step:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.prec-range { -webkit-appearance: none; appearance: none; width: 100%; height: var(--tap); margin: 0; background: transparent; cursor: pointer; }
.prec-range::-webkit-slider-runnable-track { height: 14px; background: repeating-linear-gradient(90deg, var(--line-2) 0 1px, transparent 1px 5%) 0 100% / 100% 7px no-repeat, linear-gradient(var(--line-2), var(--line-2)) 0 100% / 100% 1px no-repeat; }
.prec-range::-moz-range-track { height: 14px; background: repeating-linear-gradient(90deg, var(--line-2) 0 1px, transparent 1px 5%) 0 100% / 100% 7px no-repeat, linear-gradient(var(--line-2), var(--line-2)) 0 100% / 100% 1px no-repeat; }
.prec-range::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 28px; margin-top: -7px; background: var(--ink); border: 0; box-shadow: inset 0 0 0 5px var(--ink), inset 0 0 0 6px var(--paper); }
.prec-range::-moz-range-thumb { width: 14px; height: 28px; background: var(--ink); border: 0; border-radius: 0; }
.prec-range:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.prec-tools { margin-top: 10px; border-top: 1.5px solid var(--line); background: transparent; }
.prec-tools .prec-play { border-right: 1.5px solid var(--line); }
.prec-tools button:focus-visible { outline: 2px solid var(--ink); outline-offset: -4px; }
@container (max-width: 700px) { .prec-tools .vp-hint { display: none; } }
@media (max-width: 560px) {
  .prec-stage { height: 340px; }
  .js #fig-joint-readout:not(.is-live) { min-height: 520px; }
  /* the buttons in a 3 x 2 grid, every one a full 44 px target */
  .prec-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .prec-tools button { padding: 0 6px; letter-spacing: .06em; }
  .prec-tools button:nth-of-type(3n) { border-right: 0; }
  .prec-tools button:nth-of-type(n+4) { border-top: 1px solid var(--line-2); }
  .prec-tools .prec-play { border-right: 1px solid var(--line-2); }
  .prec-tools .vp-hint { display: none; }
}
@media (max-width: 760px) { .prec-head { font-size: 10.5px; } }
