/* =====================================================================
   ch-simulation.css: chapter 2, 3D simulation (chapters/20-simulation.html), one page.
   Linked after css/book.css by tools/assemble.py. Layout and drawing
   sizes only: tokens, components and motion all come from book.css.

   It also holds the CONDENSED CHAPTER HEAD (.chead) and the sub-block heading
   (.cb-h) that the one-page chapters share (#simulation, #joint, #rc-plane):
   assemble.py links every css/ch-*.css on every build, so they are written once,
   here. They belong in book.css section 10 when the book is finished.
   ===================================================================== */

/* ------------------------------------------------------------------ CHAPTER HEAD (shared) */
/* A chapter is one page now: its head is the opener's furniture in a band at the top (the hatched
   numeral, the title, the sub, a compact title block), and an optional figure beside it (.has-media).
   The page keeps class="opener" for its deeper paper, its zone frame and the running heads' chapter
   names; the head replaces .opener-body, so the page is not held to one window. */
.chead { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: var(--s5) clamp(16px, 2.5vw, 40px); margin: 0 0 var(--s7); }
.chead.has-media { grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.1fr); }
.chead > :not(.ghost) { position: relative; z-index: 2; min-width: 0; }
.chead .numeral { height: min(36svh, 300px); }
.chead .ch-title { font-size: clamp(56px, 6.4vw, 112px); }
.chead .ch-sub { margin: 0 0 var(--s4); }
.chead-note { max-width: 30em; margin: 0 0 var(--s4); }
.chead-text { padding-bottom: 2px; }
.chead-tb { width: min(100%, 300px); }
.chead-media .fig { margin: 0; }
/* the ghost: behind the head only, faint (book.css .ghost rules), running off the page's right edge */
.chead-ghost { top: calc(-1 * var(--pad-top)); bottom: calc(-1 * var(--s6)); right: calc(-1 * var(--pad-x)); left: 30%; }

/* the sub-blocks' headings: small display caps on a rule (no sheet numbers: the sheets are gone) */
.cb-h { display: flex; align-items: center; gap: 14px; margin: 0 0 var(--s4); font: 700 clamp(24px, 2.2vw, 32px)/1 var(--f-disp); text-transform: uppercase; letter-spacing: .03em; }
.cb-h::after { content: ""; flex: 1; min-width: 24px; height: 1px; background: var(--line-2); }
.cblock { position: relative; z-index: 2; }
.cblock + .cblock { margin-top: var(--s7); }

/* below 1180 px the media beside the head gets too narrow: it goes under the numeral and text */
@media (min-width: 761px) and (max-width: 1180px) {
  .chead.has-media { grid-template-columns: auto minmax(0, 1fr); }
  .chead.has-media > .chead-media { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .chead, .chead.has-media { grid-template-columns: minmax(0, 1fr); margin-bottom: var(--s7); }
  .chead .numeral { height: 18svh; }
  .chead .ch-title { font-size: clamp(48px, 15vw, 72px); }
  .chead-ghost { left: 0; }
  .cblock + .cblock { margin-top: var(--s7); }
  .cb-h { font-size: 24px; }
}

/* ------------------------------------------------------------------ THIS CHAPTER */
/* ghost: the one thing it adds is the lidar fan that turns with the scroll; at book.css's 5% fill it
   all but vanishes, so it gets a little more of the ghost tone (about 10%) */
#simulation .ghost .plot .pl.fan-p { fill: color-mix(in srgb, var(--ghost) 60%, transparent); }

/* display lettering inside drawings: step names, policy names */
.plot text.sim-t-h { font: 700 21px/1 var(--f-disp); letter-spacing: .04em; fill: var(--ink); }

/* ------------------------------------------------------------------ TRAINING YOUR ROBOT */
.sim-app-text { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s3) clamp(24px, 4.5vw, 72px); align-items: baseline; }
.sim-app-text > p { margin: 0; }
.sim-app-text .small { max-width: 30em; }
.sim-flow { margin: var(--s5) 0 0; }
.sim-flow-draw { position: relative; }
.sim-flow-draw svg { width: 100%; height: auto; overflow: visible; }
.sim-flow-tall { display: none; }
.sim-flow-tall .t-xs { font-size: 13px; }   /* YOUR CAD / TRAINED POLICY: the tall drawing is shown at about 1:1 */
/* the Test step's placeholder sits on the drawing, under step 04 (HTML so book.js clouds it) */
.sim-flow-draw .sim-test-tbd { position: absolute; left: 83.1%; top: 45.4%; margin: 0; transform: translateY(-50%); font-size: 12.5px; white-space: nowrap; }
/* where the wide drawing is narrow, the placeholder wraps inside the space right of step 04 */
@media (min-width: 1001px) and (max-width: 1320px) {
  .sim-flow-draw .sim-test-tbd { max-width: 16.5%; white-space: normal; }
}

/* ------------------------------------------------------------------ LEARNING FROM CAMERAS */
.sim-arms { align-items: start; }
.sim-arms .lede { margin-top: 0; font-size: var(--t-body); }
.sim-ts svg { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto; overflow: visible; }
.sim-ts figcaption { max-width: 420px; margin-left: auto; margin-right: auto; }
/* on a phone the schematic shows at about 0.7:1, so its smallest labels are set larger (they still fit) */
@media (max-width: 600px) { .sim-ts .plot .t-xs { font-size: 12px; } }
.sim-how { max-width: 420px; margin: var(--s4) auto 0; font-size: var(--t-body); }
.sim-results { margin: var(--s4) 0 var(--s4); }
.sim-results .datasheet td.num, .sim-results .datasheet .res { white-space: nowrap; }
.sim-results del { text-decoration: none; color: var(--ink-2); background: linear-gradient(var(--redline), var(--redline)) 0 55% / 100% 2px no-repeat; }
/* what it trains on: two labelled rows of chips; the tasks with a result in the table are solid */
.sim-train { margin: 0; display: grid; gap: var(--s3); }
.sim-train > div { display: grid; gap: 8px; }
.sim-train dt { font: 500 11px/1.3 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.sim-train dd { margin: 0; }
.sim-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.sim-chips li { margin: 0; padding: 6px 9px 5px; border: 1px dashed var(--line-2); font: 500 12px/1.2 var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.sim-chips li.has-res { border: 1.5px solid var(--accent); color: var(--accent); font-weight: 600; }
.sim-chips.is-plain li { border-style: solid; border-color: var(--line-2); }
.sim-key { margin: var(--s3) 0 0; display: flex; align-items: flex-start; gap: 8px; }
.sim-key-sw { flex: none; width: 14px; height: 10px; margin-top: .4em; border: 1.5px solid var(--accent); }
/* below this the 5:7 pair leaves the results table too little width: one column, the schematic under the words */
@media (max-width: 1100px) {
  .cols.sim-arms { grid-template-columns: minmax(0, 1fr); }
}
/* the narrowest phones: the results may wrap (the struck 0% over the 95.8%) and the cells sit closer */
@media (max-width: 380px) {
  .sim-results .datasheet { font-size: 14px; }
  .sim-results .datasheet th, .sim-results .datasheet td { padding-right: 8px; }
  .sim-results .datasheet td.num, .sim-results .datasheet .res { white-space: normal; font-size: 13.5px; }
  .sim-results .datasheet thead th { letter-spacing: .08em; }
}
@media (max-width: 340px) {
  .sim-results .datasheet th, .sim-results .datasheet td { padding-right: 5px; }
  .sim-results .datasheet .tbd { font-size: 11px; }
}

/* ------------------------------------------------------------------ NARROW WINDOWS */
/* the wide workflow drawing gets too small to read below this, so the tall one takes over */
@media (max-width: 1000px) {
  .sim-flow-wide { display: none; }
  .sim-flow-tall { display: block; }
  .sim-flow-draw { max-width: 440px; }
  .sim-flow-draw .sim-test-tbd { left: 15.6%; top: 89.7%; }
}
@media (max-width: 760px) {
  .sim-app-text { grid-template-columns: minmax(0, 1fr); }
  .sim-flow { margin-top: var(--s4); }
}

/* ------------------------------------------------------------------ training a two-armed robot (js/anim/multicam.js)
   A control room: the big view on the left, the other three stacked beside it like monitors, one
   transport bar under all four. Each view has a corner-bracket frame and a CAM label; a REC dot
   blinks while the run plays. Pressing a small view swaps it into the big slot.
   With JS there is one video (all four cameras in one frame): .mc-stage holds it over the big tile's
   grid area, cropped to the chosen view, and the small tiles are canvases painted from it. */
.mcam { margin: 0; }
.mc-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); grid-template-rows: repeat(3, auto); grid-auto-flow: row dense; gap: 12px; }
.mc-tile { position: relative; grid-column: 2; aspect-ratio: 16 / 9; background: #06101f; outline: 1px solid var(--line-2); outline-offset: 3px; transition: outline-color .2s; }
.mc-tile.is-main { grid-column: 1; grid-row: 1 / span 3; aspect-ratio: auto; min-height: 100%; outline: 1.5px solid var(--line); }
.mc-screen { position: absolute; inset: 0; overflow: hidden; }
.mc-screen video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mc-tile.is-main .mc-screen video { object-fit: contain; background: #06101f; }
.mc-screen canvas { display: block; width: 100%; height: 100%; }
.mc-tile.is-main .mc-screen canvas { display: none; }
.mc-stage { grid-column: 1; grid-row: 1 / span 3; position: relative; z-index: 1; overflow: hidden; background: #06101f; pointer-events: none; }
.mc-stage video { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; object-fit: fill; display: block; }
/* corner brackets */
.mc-tile::before, .mc-tile::after { content: ""; position: absolute; z-index: 2; width: 18px; height: 18px; pointer-events: none; border: 0 solid var(--ink); }
.mc-tile::before { left: 6px; top: 6px; border-left-width: 2px; border-top-width: 2px; }
.mc-tile::after { right: 6px; bottom: 6px; border-right-width: 2px; border-bottom-width: 2px; }
.mc-lbl { position: absolute; z-index: 3; left: 12px; bottom: 9px; margin: 0; display: flex; align-items: center; gap: 7px; padding: 4px 7px; background: rgba(6,16,31,.72); font: 600 10.5px/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }
.mc-tile.is-main .mc-lbl { font-size: 12px; left: 16px; bottom: 14px; }
.mc-rec { width: 7px; height: 7px; border-radius: 50%; background: #ff5a4f; opacity: .35; }
.mo .mcam.is-playing .mc-rec { animation: mc-rec 1.2s steps(2, jump-none) infinite; }   /* all four views play (js/anim/multicam.js) */
@keyframes mc-rec { 0% { opacity: 1; } 100% { opacity: .25; } }
.mc-pick { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; }
.mc-tile.is-main .mc-pick { cursor: default; }
.mc-tile:not(.is-main):hover { outline-color: var(--ink); }
.mc-pick:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
html:not(.js) .mc-pick, .mcam:not(.is-live) .mc-pick, .mcam:not(.is-live) .mc-bar { display: none; }
html:not(.js) .mc-screen, .mcam:not(.is-live) .mc-screen { position: static; }
/* the transport bar: one button, one scrubber, one timecode for all four */
.mc-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px; margin-top: 16px; }
.mc-play { appearance: none; display: inline-flex; align-items: center; gap: 8px; min-width: var(--tap); min-height: var(--tap); padding: 0 14px; border: 1.5px solid var(--line); background: transparent; color: var(--ink); font: 600 11.5px/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; cursor: pointer; }
.mc-play:hover { background: rgba(216,232,255,.08); }
.mc-play svg { width: 15px; height: 15px; }
.mc-play svg path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.mc-play .i-pause, .mc-play.on .i-play { display: none; }
.mc-play.on .i-pause { display: block; }
.mc-scrub { -webkit-appearance: none; appearance: none; width: 100%; height: var(--tap); margin: 0; background: transparent; cursor: pointer; --p: 0; }
.mc-scrub::-webkit-slider-runnable-track { height: 14px; background: repeating-linear-gradient(90deg, var(--line-2) 0 1px, transparent 1px 2.5%) 0 100% / 100% 7px no-repeat, linear-gradient(var(--line-2), var(--line-2)) 0 100% / 100% 1px no-repeat; }
.mc-scrub::-moz-range-track { height: 14px; background: repeating-linear-gradient(90deg, var(--line-2) 0 1px, transparent 1px 2.5%) 0 100% / 100% 7px no-repeat, linear-gradient(var(--line-2), var(--line-2)) 0 100% / 100% 1px no-repeat; }
.mc-scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 3px; height: 26px; margin-top: -6px; background: var(--ink); border: 0; }
.mc-scrub::-moz-range-thumb { width: 3px; height: 26px; background: var(--ink); border: 0; border-radius: 0; }
.mc-scrub:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.mc-tc { font: 500 12.5px/1 var(--f-mono); color: var(--ink-2); white-space: nowrap; }
.mcam figcaption { margin-top: var(--s3); }
@media (max-width: 760px) {
  .mc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .mc-tile { grid-column: auto; }
  .mc-tile.is-main { grid-column: 1 / -1; grid-row: 1; aspect-ratio: 16 / 9; min-height: 0; }
  .mc-stage { grid-column: 1 / -1; grid-row: 1; }
  .mc-lbl { left: 6px; bottom: 5px; padding: 3px 5px; font-size: 9px; letter-spacing: .06em; }
  .mc-tile:not(.is-main)::before, .mc-tile:not(.is-main)::after { width: 10px; height: 10px; }
  .mc-tile:not(.is-main) .mc-lbl { display: none; }
}
