/* Grids page: the art centered, cards either side, the control island at the bottom center.
   Shared tokens, the 0x44 look and the course header live in course.css. */
:root {
  --card: #F4F3EF; --hover: #E1DFDA; --selected: #DCDAD5; --text-body: #2E2D2B; --primary-hover: #3A3936;
  --track: #D3D1CC; --meter-bg: #E0DED9; --mark-border: #B9B7B1; --ring-soft: #D8D6D1; --code-bg: #EAE9E5;
  --float: 0 1px 2px rgb(var(--sh) / .07), 0 4px 10px rgb(var(--sh) / .06), 0 12px 28px rgb(var(--sh) / .06);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --spring: cubic-bezier(.22, 1, .36, 1);
  --card-w: 288px;
}
@supports (transition-timing-function: linear(0, 1)) {
  :root { --spring: linear(0, 0.046, 0.161, 0.311, 0.47, 0.619, 0.747, 0.85, 0.926, 0.978, 1.01, 1.026, 1.031, 1.028, 1.021, 1.013, 1.005, 0.999, 0.995, 0.993, 0.993, 0.994, 0.995, 0.997, 0.998, 0.999, 1, 1); }
}

* { box-sizing: border-box; }
p, h1, h2, h3, figure, ol, fieldset { margin: 0; }
fieldset { padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button, a, input, select, label, textarea { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
a { color: var(--ink); text-underline-offset: 3px; }
.mono { font-family: var(--mono); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, pre:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 3px;
}
.copy-fallback { position: fixed; left: -9999px; font-size: 16px; }
.noscript { padding: 24px; }

/* Buttons. */
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 0 14px; border-radius: 8px; font-size: 13px; white-space: nowrap; text-decoration: none;
  transition: background-color .2s var(--ease), transform .2s var(--ease); }
.button:active { transform: scale(.97); }
.button.primary { background: var(--ink); color: var(--btn-ink); }
.button.primary:hover { background: var(--primary-hover); }
.button.quiet { border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.button.quiet:hover { background: var(--hover); }
.button:disabled { opacity: .5; }
.text-button { display: inline-flex; align-items: center; min-height: 32px; padding: 0 4px; font-size: 13px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--mark-border); }
.text-button:hover { text-decoration-color: currentColor; }
.text-button:disabled { color: var(--muted); }

/* The frame. */
.lab { position: relative; min-height: calc(100svh - var(--lab-top, 57px)); padding: 8px 24px calc(var(--island-reserve, 120px) + 28px); }
.lab-top { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; min-height: 44px; }
.lab-lesson { grid-column: 1; justify-self: start; }
.lab-progress { grid-column: 2; display: grid; justify-items: center; }
.lab-progress > * { grid-area: 1 / 1; }
.switch { grid-column: 3; justify-self: end; display: inline-flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 4px; font-size: 13px; color: var(--ink); }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--track); transition: background-color .3s var(--spring); }
.switch-knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(18 24 32 / .2), 0 2px 6px rgb(18 24 32 / .1); transition: transform .45s var(--spring); }
.switch[aria-checked=true] .switch-track { background: var(--ink); }
.switch[aria-checked=true] .switch-knob { transform: translateX(16px); }

/* Progress, while the lesson runs. */
.rail { display: flex; gap: 26px; }
.rail-chapter { display: flex; align-items: center; gap: 8px; }
.rail-name { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.rail-name .tick { width: 12px; height: 12px; color: var(--ink); }
.rail-steps { display: flex; gap: 2px; }
.step { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0; color: var(--muted); font-size: 13px; }
.step-mark { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--mark-border); font-size: 11px; background: var(--card);
  transition: background-color .2s var(--ease), border-color .2s var(--ease); }
.step[data-state=done] .step-mark { background: var(--ink); border-color: var(--ink); color: var(--btn-ink); }
.step[data-state=current] .step-mark { border: 2px solid var(--ink); color: var(--ink); }
.step[data-state=locked] { opacity: .5; cursor: default; }
.step[aria-current=step] .step-mark { box-shadow: 0 0 0 3px var(--ring-soft); }
.count { display: inline-flex; align-items: center; min-height: 28px; font-size: 12px; }
.count-bar { display: inline-flex; gap: 12px; }
.count-chapter { display: grid; gap: 3px; }
.count-name { display: inline-flex; align-items: center; gap: 2px; line-height: 14px; color: var(--muted); }
.count-chapter[data-current] .count-name { color: var(--ink); font-weight: 600; }
.count-name .tick { width: 11px; height: 11px; color: var(--ink); }
.count-dots { display: flex; gap: 2px; }
.count-dots span { width: 7px; height: 4px; border-radius: 2px; background: var(--track); }
.count-dots span.on { background: var(--ink); }
.tick { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 20; }

/* The stage: cards either side of the art. The art never moves when cards come and go. */
.stage { --stage-h: calc(100svh - var(--lab-top, 57px) - var(--top-h, 44px) - var(--island-reserve, 120px) - 56px);
  --art: min(calc(var(--stage-h) - 22px), calc(100vw - 2 * var(--card-w) - 48px - 80px), 760px);
  /* The piece's own width: the room across, or its height's worth of room times its shape. --ratio is width over height. */
  --art-w: min(calc(100vw - 2 * var(--card-w) - 48px - 80px), calc(min(var(--stage-h) - 22px, 760px) * var(--ratio, 1)));
  display: grid; grid-template-columns: minmax(0, 1fr) var(--art-w) minmax(0, 1fr); column-gap: 40px; align-items: center; height: var(--stage-h); margin-top: 6px; }
.slot { display: flex; align-items: center; max-height: var(--stage-h); min-width: 0; transition: opacity .3s var(--spring); }
.slot-left { justify-self: end; width: var(--card-w); }
.slot-right { justify-self: start; width: var(--card-w); }
.lab[data-lesson=off][data-center=compare] .slot { opacity: 0; pointer-events: none; }
.stage-center { display: grid; justify-items: center; }
.stage-center > * { grid-area: 1 / 1; }
.art-figure { position: relative; width: var(--art-w); }
/* The art floats: the 0x44 lifted shadow and corner radius. */
.artwork { width: 100%; aspect-ratio: 1; background: var(--paper); border-radius: clamp(3px, calc(var(--art) * .0075), 7px); box-shadow: var(--lifted); overflow: hidden; transform: translateZ(0); }
.art-figure .artwork { aspect-ratio: var(--ratio, 1); }
.artwork svg { display: block; width: 100%; height: 100%; }
/* A piece's pixel finishes land on top of its SVG when they are ready. */
.artwork, .art, .saved-thumbnail { position: relative; }
.art-raster { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.art-caption { position: absolute; top: calc(100% + 10px); left: 0; right: 0; font: 12px/1.3 var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Review 12, in the lesson: twelve equal tiles in the art column. */
.review-sheet { width: var(--art); }
.review-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.review-tile { position: relative; min-width: 0; }
.review-open { display: block; width: 100%; padding: 0; text-align: left; }
.review-art { display: block; width: 100%; aspect-ratio: 1; background: var(--paper); border-radius: 3px; overflow: hidden; box-shadow: 0 1px 2px rgb(var(--sh) / .1), 0 4px 12px rgb(var(--sh) / .08); }
.review-art svg { display: block; width: 100%; height: 100%; }
.review-tile.current .review-art { outline: 1.5px solid var(--ink); outline-offset: 3px; }
.review-foot { display: contents; }
.review-big { display: none; }
.review-hash { display: none; font: 12px/1 var(--mono); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-line { display: flex; flex-wrap: wrap; gap: 0 8px; margin-bottom: 6px; font-size: 12px; line-height: 16px; color: var(--muted); }
.review-line b { font-size: 13px; line-height: 16px; font-weight: 600; color: var(--ink); }
.review-line .review-hash { display: block; font-size: 12px; line-height: 16px; color: var(--muted); }
.review-star { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border-radius: 50%; background: var(--card); color: var(--muted); box-shadow: 0 1px 3px rgb(var(--sh) / .18); opacity: 0; transition: opacity .2s var(--ease); }
.review-tile:hover .review-star, .review-star:focus-visible, .review-star[aria-pressed=true] { opacity: 1; }
@media (hover: none) { .review-star { opacity: 1; } }
.review-star svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.review-star[aria-pressed=true] { color: var(--ink); }
.review-star[aria-pressed=true] svg { fill: #f2b705; stroke: var(--ink); }
.compare-view { display: grid; gap: 10px; width: min(calc(var(--art) * 1.7 + 12px), calc(100vw - 48px)); }
.lab[data-lesson=on] .compare-view { width: var(--art); }
.compare-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-item { display: grid; gap: 6px; }
.compare-item .art-caption { position: static; }
.compare-item .artwork { border-radius: 5px; }
.compare-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.compare-message { flex: 1 1 200px; font-size: 12px; color: var(--muted); }
.badge { padding: 4px 10px; border-radius: 99px; background: var(--hover); font-size: 12px; color: var(--muted); }
.badge.same { background: var(--ink); color: var(--btn-ink); }

/* Cards. */
.card { overflow: hidden; width: 100%; max-height: var(--stage-h); display: flex; flex-direction: column; padding: 18px; border-radius: 14px; background: var(--card); box-shadow: var(--float); will-change: transform, opacity; }
.card-in { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.slot-left .card { transform-origin: right center; }
.slot-right .card { transform-origin: left center; }
.card h2 { margin-top: 4px; font-size: 18px; line-height: 1.25; font-weight: 600; color: var(--ink); }
.card-eyebrow, .idea-eyebrow, .card-label { font-size: 12px; color: var(--muted); }
.card-label { display: block; margin-top: 12px; font-size: 11px; letter-spacing: .03em; }
.card-body { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--text-body); }
.card-task { font-weight: 600; color: var(--ink); }
.card-small { margin-top: 8px; font-size: 12px; line-height: 1.5; color: var(--text-body); }
.card-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.step-nav { min-height: 36px; }
.lab[data-lesson=on] .slot-left .step-card { min-height: 236px; }
.lab[data-lesson=on] .step-card .card-in { flex: 1; display: flex; flex-direction: column; }
.lab[data-lesson=on] .step-nav { margin-top: auto; padding-top: 8px; min-height: 44px; }
.slot-left .bit-cell { line-height: 13px; }
.step-nav .button { margin-left: auto; }
.card-done { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; font-weight: 600; color: var(--ink); }
.card-done .tick { width: 20px; height: 20px; padding: 3px; border-radius: 50%; background: var(--ink); stroke: var(--btn-ink); }
.card-more { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.card-more summary { cursor: pointer; color: var(--ink); }
.step-progress { margin-top: 10px; font-size: 12px; color: var(--muted); }
.idea-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.idea-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 0; cursor: default; }
.idea-chevron { display: none; }
.tip-button, .tip-actions { display: none; }
.card-close { min-height: 28px; padding: 0 8px; border-radius: 6px; font-size: 12px; color: var(--muted); }
.card-close:hover { background: var(--hover); color: var(--ink); }
.full-seed { display: block; margin-top: 4px; font: 11px/1.5 var(--mono); color: var(--ink); overflow-wrap: anywhere; }
.code-line { margin-top: 12px; }
.code-line pre { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--code-bg); font: 11.5px/1.5 var(--mono); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.code-line .text-button { margin-top: 4px; font-size: 12px; }
.ask { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.ask .card-label { margin-top: 0; }
.ask-text { margin-top: 4px; font-size: 13px; line-height: 1.45; color: var(--text-body); }
.ask .button { margin-top: 10px; }
.variations { display: flex; gap: 10px; margin-top: 6px; }
.variation-example { min-width: 0; flex: 1; }
.mini-art { width: 100%; aspect-ratio: 1; border-radius: 3px; overflow: hidden; box-shadow: 0 1px 3px rgb(var(--sh) / .12); }
.mini-art svg { display: block; width: 100%; height: 100%; }
.variation-example figcaption { margin-top: 5px; font-size: 11px; line-height: 1.3; color: var(--muted); }
.bit-grid { display: grid; gap: 2px; margin-top: 12px; font-family: var(--mono); }
.bit-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.bit-cell { font-size: 11px; line-height: 18px; text-align: center; border-radius: 2px; background: var(--meter-bg); color: var(--muted); }
.bit-cell.on { background: var(--ink); color: var(--btn-ink); }

/* The island: tabs on top, the tab's controls below. */
.island { position: fixed; z-index: 10; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
  isolation: isolate; padding: 5px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--lifted); overflow: hidden; }
.island-row { display: flex; justify-content: center; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.tabs { position: relative; isolation: isolate; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-pill { position: absolute; z-index: -1; top: 0; bottom: 0; left: 0; border-radius: 8px; background: var(--selected); transition: transform .48s var(--spring), width .48s var(--spring); }
.tab { flex: none; min-height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; color: var(--muted); transition: color .2s var(--ease); }
.tab:hover { color: var(--ink); }
.tab[aria-selected=true] { color: var(--ink); font-weight: 600; }
.panels { padding-top: 5px; }
.panel { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 52px; }
.panel-ghost { position: absolute; z-index: 1; margin: 0; pointer-events: none; }

/* Controls. */
.ctl { display: grid; gap: 4px; align-content: start; min-width: 0; width: 196px; padding: 5px 8px; border-radius: 10px; transition: background-color .2s var(--ease), box-shadow .2s var(--ease); }
.ctl label, .ctl-label, .ctl legend { font-size: 12px; line-height: 1.2; color: var(--muted); }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ctl output { font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; }
.menu-button { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 14px; color: var(--ink); white-space: nowrap; }
.menu-button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.menu-button::after { content: ''; flex: none; width: 7px; height: 7px; margin: -3px 2px 0 0; border-right: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); transform: rotate(45deg); transition: transform .3s var(--spring); }
.menu-button[aria-expanded=true]::after { margin-top: 3px; transform: rotate(-135deg); }
.menu-button:hover:not(:disabled) { background: var(--hover); }
.menu-list { position: fixed; z-index: 30; max-height: calc(100svh - 24px); margin: 0; padding: 4px; overflow-y: auto; overscroll-behavior: contain; border-radius: 12px; background: var(--card); box-shadow: var(--lifted); list-style: none; outline: none; }
.menu-option { display: flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 8px; font-size: 14px; color: var(--ink); cursor: pointer; transition: background-color .2s var(--ease); -webkit-tap-highlight-color: transparent; }
.menu-option:hover, .menu-option.active { background: var(--hover); }
.menu-option[aria-selected=true] { font-weight: 600; }
.menu-button:disabled, .ctl input:disabled { opacity: .45; pointer-events: none; }
.ctl input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 24px; margin: 0; background: transparent; cursor: pointer; touch-action: none; }
.ctl input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: linear-gradient(to right, var(--ink) var(--fill, 50%), var(--track) var(--fill, 50%)); }
.ctl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); box-shadow: 0 1px 3px rgb(18 24 32 / .25); }
.ctl input[type=range]::-moz-range-track { height: 4px; border-radius: 99px; background: var(--track); }
.ctl input[type=range]::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--ink); }
.ctl input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); }
.ctl.is-step { background: var(--card); box-shadow: var(--float); }
.ctl.is-step label, .ctl.is-step legend, .ctl.is-step .ctl-label { color: var(--ink); font-weight: 600; }
.lab.demoing .ctl.is-step input[type=range]::-webkit-slider-thumb { background: var(--ink); }
/* One row: the info button, then the field. The help line only appears when it has news. */
.ctl-input { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; width: 340px; }
.ctl-input .ctl-head { flex: none; gap: 0; }
.ctl-input .seed-info { margin-left: 0; }
.ctl-input .input-with-action { flex: 1 1 0; min-width: 0; }
.ctl-input .seed-help { flex: 1 1 100%; }
.seed-help[data-state=hash] { display: none; }
.input-with-action { display: flex; align-items: center; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); overflow: hidden; }
.input-with-action:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.input-with-action input { flex: 1; min-width: 0; height: 100%; padding: 0 10px; border: 0; background: transparent; font: 12px var(--mono); outline: none; }
.draw-button { flex: none; height: 100%; padding: 0 12px; border-left: 1px solid var(--line); font-size: 12px; color: var(--ink); }
.draw-button:hover { background: var(--hover); }
.microcopy { font-size: 12px; line-height: 1.35; color: var(--muted); }
.seed-help { min-height: 16px; overflow-wrap: anywhere; }
.seed-help .seed-value { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.ctl-actions, .ctl-view { width: auto; align-self: center; }
/* The field, button and toggle share one top line and one height, even when the help line opens under the field. */
.panel-seed { align-items: flex-start; padding-top: 3px; }
.panel-seed .ctl-actions, .panel-seed .ctl-view { align-self: flex-start; }
.ctl-view .segmented { height: 36px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--hover); }
.segmented button, .segmented label { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 6px; font-size: 12px; color: var(--muted); cursor: pointer; transition: background-color .25s var(--ease), color .2s var(--ease); white-space: nowrap; }
.segmented button[aria-pressed=true], .segmented label:has(input:checked) { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(18 24 32 / .12); }
.radio-segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.radio-segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.ctl-read { width: auto; }
.rule-help { max-width: 160px; }
.ctl-palette { display: flex; align-items: center; gap: 10px; width: auto; }
.ctl-palette select { width: 180px; }
.ctl-pool { width: auto; }
.pool-picks { display: grid; grid-template-columns: repeat(4, max-content); gap: 0 14px; }
.pool-picks .pick { grid-template-columns: 22px minmax(0, 1fr); width: auto; }
.palette-swatches { display: flex; flex: none; gap: 3px; width: 120px; height: 8px; }
.palette-swatch { flex: 1; height: 8px; border-radius: 2px; background: var(--swatch-color); }

/* Studies and Export. */
.panel-studies { align-items: stretch; gap: 8px; max-width: min(900px, calc(100vw - 80px)); }
.save-row { display: flex; align-items: flex-start; gap: 6px; width: auto; flex: none; }
.save-row textarea { width: 200px; height: 36px; min-height: 36px; max-height: 96px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 13px; line-height: 1.4; resize: none; }
.saved-side { display: grid; gap: 4px; min-width: 0; align-content: start; }
.saved-count { font-size: 12px; color: var(--muted); }
.saved-list { display: flex; gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: thin; padding: 2px; }
.saved-empty { font-size: 13px; color: var(--muted); }
.saved-study { display: flex; gap: 8px; flex: none; width: 236px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.saved-thumbnail { flex: none; width: 52px; height: 52px; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 3px rgb(18 24 32 / .14); }
.saved-thumbnail svg { display: block; width: 100%; height: 100%; }
.saved-info { display: grid; gap: 1px; min-width: 0; }
.saved-info h3 { font-size: 12px; font-weight: 600; }
.saved-input, .saved-note, .saved-info time { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-input { font-family: var(--mono); }
.saved-note { color: var(--ink); }
.saved-study-actions { display: flex; gap: 2px; }
.saved-study-actions .text-button { min-height: 24px; padding: 0 3px; font-size: 11px; }
#save-help { font-size: 11px; }
/* Desktop: the count sits under the note field and the saved cards run beside them, so
   this tab is no taller than the others. */
@media (min-width: 768px) {
  .panel-studies { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 8px; }
  .saved-side { display: contents; }
  .saved-count { grid-column: 1; padding: 0 8px; }
  .saved-list { grid-column: 2; grid-row: 1 / span 2; align-items: center; }
  #save-help { grid-column: 1 / -1; padding: 0 8px; }
  .saved-study { gap: 6px; padding: 4px; }
  .saved-thumbnail { width: 44px; height: 44px; }
  .saved-info { grid-template-columns: auto minmax(0, 1fr); column-gap: 6px; align-content: center; gap: 0 6px; }
  .saved-note, .saved-info time, .saved-study-actions { grid-column: 1 / -1; }
  .saved-note + time { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .saved-study-actions .text-button { min-height: 18px; }
}
.panel-export { gap: 6px; }
.version { margin-left: 6px; font-size: 11px; color: var(--muted); }

/* Status: at the top, so it never covers the art, a comparison or the island. */
.toast { position: fixed; z-index: 30; left: 50%; top: calc(10px + env(safe-area-inset-top)); translate: -50% 0; max-width: min(560px, calc(100vw - 32px)); padding: 9px 16px; border-radius: 99px; background: var(--ink); color: var(--btn-ink); font-size: 13px; line-height: 1.35; box-shadow: var(--float); text-align: center; overflow-wrap: anywhere; }
.toast.error { background: #8a2d1f; }
.sheet { display: none; }
.why-button { display: none; }
.bits-slot[hidden] { display: none; }

/* Narrow desktop: the rail drops chapter names before it crowds the switches. */
@media (max-width: 1180px) and (min-width: 768px) {
  .rail-name { display: none; }
  .rail { gap: 12px; }
  :root { --card-w: 250px; }
}

/* Phone: cards stack in one sheet above the island and may overlay the bottom of the art,
   so the art stays at least about 260px wide. No row scrolls sideways. */
@media (max-width: 767px) {
  .lab { padding: 4px 16px calc(var(--island-reserve, 160px) + 24px); }
  /* A phone lesson fills the screen and does not scroll: the top row, the art, one card of
     fixed height, and an island of fixed height. Nothing moves when a card or tab changes. */
  html[data-lesson=on], html[data-lesson=on] body { height: 100svh; overflow: hidden; overscroll-behavior: none; }
  html[data-lesson=on] .site-header { display: none; }
  .lab[data-lesson=on] { min-height: 0; height: 100svh; padding-bottom: 0; }
  .lab[data-lesson=on] .switch, .lab[data-lesson=on] .rule-help, .lab[data-lesson=on] .saved-count { display: none; }
  .lab[data-lesson=on] .island { min-height: var(--island-reserve); }
  .lab[data-lesson=on] .sheet .step-card { min-height: var(--card-slot); }
  .lab[data-lesson=on] .card-done { margin-top: 6px; }
  .lab[data-lesson=on] .step-nav .button { padding: 0 8px; }
  .lab[data-lesson=on] .sheet .idea-card { order: -1; border-top: 0; border-bottom: 1px solid var(--line); }
  .lab[data-lesson=on] .idea-head { display: none; }
  .lab[data-lesson=on] .why-button { display: inline-flex; }
  .lab[data-lesson=on] .card-actions { flex-wrap: nowrap; }
  .lab[data-lesson=on] .card-actions .text-button { white-space: nowrap; }
  /* The 64 choices sit beside the single piece. Review 12 and a comparison need the whole width. */
  .lab[data-step=rule][data-center=art] .stage-center { grid-template-columns: auto auto; justify-content: center; gap: 12px; }
  .lab[data-step=rule][data-center=art] .stage-center > * { grid-area: auto; }
  .lab[data-step=rule]:not([data-center=art]) .bits-slot { display: none; }
  .bits-slot { width: calc(100vw - 44px - var(--art-fit)); }
  .bits-slot .bit-grid { margin-top: 0; height: var(--art-fit); grid-template-rows: repeat(8, 1fr); }
  .bits-slot .bit-cell { display: grid; place-items: center; font-size: 12px; line-height: 1; }
  .lab-top { grid-template-columns: auto 1fr minmax(0, auto); gap: 8px; min-height: 40px; }
  .lab-progress { justify-items: start; }
  .stage { display: block; height: auto; margin-top: 8px; }
  .slot { display: none; }
  .art-figure { --art: var(--art-fit, 300px); width: var(--art-fit, 300px); transition: width .45s var(--spring); }
  .review-sheet, .compare-view, .lab[data-lesson=on] .compare-view { width: 100%; margin-left: 0; }
  /* Review 12: the current seed big, twelve small tiles beside it, as tall as each other. */
  .review-sheet:not([hidden]) { --big: min(var(--art-fit, 300px), calc((100vw - 44px) * .58)); --tile: min(calc((100vw - 52px - var(--big)) / 3), calc((var(--big) - 15px) / 4)); display: flex; justify-content: center; align-items: flex-start; gap: 10px; }
  .review-big { position: relative; display: block; flex: none; width: var(--big); }
  .review-big .review-art { border-radius: 5px; box-shadow: var(--lifted); }
  .review-big .review-star { top: 6px; right: 6px; width: 32px; height: 32px; opacity: 1; }
  #review-line { display: none; }
  .review-big .review-line { margin: 6px 0 0; }
  /* The pool step is about the twelve, and a saved study can make the island tall, so its line gives way to them. */
  .lab[data-step=pool] .review-big .review-line { display: none; }
  .lab[data-lesson] .review-grid { grid-template-columns: repeat(3, var(--tile)); gap: 5px 5px; align-items: start; }
  .lab[data-lesson] .review-tile.current { grid-column: auto; grid-row: auto; width: auto; }
  .lab[data-lesson] .review-tile.current .review-art { border-radius: 3px; box-shadow: none; outline: 1.5px solid var(--ink); outline-offset: 1px; }
  .lab[data-lesson] .review-grid .review-foot { display: contents; }
  .lab[data-lesson] .review-grid .review-hash { display: none; }
  .lab[data-lesson] .review-grid .review-star { display: none; }
  .lab[data-lesson] .review-grid .review-star[aria-pressed=true] { position: absolute; top: 2px; right: 2px; display: grid; width: 16px; height: 16px; margin: 0; background: var(--card); box-shadow: none; opacity: 1; pointer-events: none; }
  .review-grid .review-star svg { width: 10px; height: 10px; }
  .sheet { position: fixed; z-index: 9; left: 12px; right: 12px; bottom: calc(var(--island-h) + 12px + 8px + env(safe-area-inset-bottom)); display: grid; overflow: hidden;
    border-radius: 18px; background: var(--card); box-shadow: var(--lifted); transition: opacity .3s var(--spring); }
  .sheet[data-empty=true] { box-shadow: none; }
  .lab[data-lesson=off][data-center=compare] .sheet { opacity: 0; pointer-events: none; }
  .sheet .card { max-height: none; border-radius: 0; box-shadow: none; padding: 12px 16px; }
  .sheet .card + .card:not([hidden]) { border-top: 1px solid var(--line); }
  .sheet .step-card:not([hidden]) ~ .idea-card { padding-top: 8px; padding-bottom: 10px; }
  .sheet .card h2 { font-size: 16px; }
  .sheet .card-body { font-size: 13px; }
  .lab[data-lesson=off] .switch { display: none; }
  .lab[data-lesson=off] .tip-button { grid-column: 3; display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; min-height: 36px; padding: 0 12px; border-radius: 99px; background: var(--card); box-shadow: 0 1px 2px rgb(18 24 32 / .12); font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; }
  /* A long tip name shortens here. It never pushes the page wider than the phone. */
  #tip-button-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* With Review beside Sheet and Single there is no room for the word at phone widths. */
  .tip-word { display: none; }
  @media (max-width: 385px) { #tip-button-label { display: none; } }
  .tip-button-i { flex: none; display: grid; place-items: center; width: 16px; height: 16px; border: 1.5px solid var(--ink); border-radius: 50%; font-size: 10px; font-weight: 700; line-height: 1; }
  .idea-card.short .idea-head, .idea-card.short .why-rest, .idea-card.short .variations { display: none; }
  .idea-card.short .tip-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
  .idea-toggle { cursor: pointer; min-height: 28px; }
  .idea-chevron { display: block; width: 8px; height: 8px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .4s var(--spring); }
  .idea-card.open .idea-chevron { transform: rotate(-135deg) translateY(-2px); }
  .idea-card:not(.open) .code-line, .idea-card:not(.open) .ask, .idea-card:not(.open) .card-more, .idea-card:not(.open) .full-seed, .idea-card:not(.open) .card-label { display: none; }
  .sheet .step-card:not([hidden]) ~ .idea-card:not(.open) .idea-body { display: none; }
  .idea-body { max-height: 34svh; overflow-y: auto; }
  .island { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); transform: none; width: auto; max-width: none; }
  .island-row { justify-content: flex-start; }
  .tabs { width: 100%; justify-content: space-between; }
  .tab { padding: 0 8px; }
  .panel { flex-wrap: wrap; justify-content: stretch; min-height: 0; }
  .panel-seed { padding-top: 0; }
  .ctl { flex: 1 1 96px; width: auto; padding: 5px 6px; }
  .menu-button { padding: 0 8px; font-size: 13px; }
  .menu-option { min-height: 44px; }
  .ctl-input { flex: 1 1 100%; }
  .ctl-actions, .ctl-view { flex: 1 1 auto; }
  .ctl-actions .button { width: 100%; }
  .ctl-read { flex: 1 1 100%; }
  .ctl-read .segmented, .ctl-view .segmented { display: grid; grid-template-columns: 1fr 1fr; }
  .ctl-read .segmented label, .ctl-view .segmented button { justify-content: center; }
  .ctl-palette { display: grid; gap: 4px; flex: 1 1 100%; }
  .ctl-pool { flex: 1 1 100%; }
  .pool-picks { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 8px; }
  .palette-swatches { width: auto; margin-top: 4px; }
  .rule-help { max-width: none; flex: 1 1 100%; padding: 0 6px; }
  .panel-studies { display: grid; max-width: none; flex: 1 1 100%; }
  .save-row { display: grid; grid-template-columns: 1fr auto; }
  .save-row textarea { width: 100%; }
  /* One row you swipe: the next study shows at the edge, so the list reads as more than one. */
  .saved-list { gap: 8px; scroll-snap-type: x proximity; scroll-padding-left: 2px; scrollbar-width: none; }
  .saved-list::-webkit-scrollbar { display: none; }
  .saved-study { width: calc(100% - 48px); scroll-snap-align: start; }
  .saved-study:only-child { width: 100%; }
  .panel-export { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; flex: 1 1 100%; }
  .panel-export .button { min-width: 0; padding: 0 6px; font-size: 12px; white-space: normal; text-align: center; line-height: 1.2; }
  .panel-export .text-button { justify-content: center; }
  .version { margin: 0; align-self: center; text-align: center; }
  .toast { border-radius: 14px; }
}

/* The lab outside the lesson: 24 pieces on a sheet and an island that edits the recipe.
   Approved on Cap's iPhone (2026-11-06). Each island shows only for its own mode. */
.lab[data-lesson=off] #island, .lab[data-lesson=on] #lab-island, .lab[data-lesson=on] .lab-view { display: none; }
.lab[data-center=sheet] .stage { display: none; }
.lab[data-lesson=off] .lab-top .text-button, .lab[data-lesson=off] .tip-button { min-height: 40px; }
.piece-view { margin-top: 6px; }
.art { display: block; width: 100%; aspect-ratio: 1; background: var(--paper); overflow: hidden; }
.art svg { display: block; width: 100%; height: 100%; }
.tile { position: relative; display: block; min-width: 0; width: 100%; padding: 0; }
.tile .art { border-radius: 3px; box-shadow: 0 1px 2px rgb(var(--sh) / .1), 0 4px 12px rgb(var(--sh) / .08); }
.tile[aria-pressed=true] .art { outline: 1.5px solid var(--ink); outline-offset: 2px; }
.tile .art-old, .tile[aria-pressed=true] .art-old { position: absolute; inset: 0; outline: none; box-shadow: none; pointer-events: none; }
.piece-sheet { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
/* A sheet of one frame takes that frame, with fewer pieces across as they get wider. */
.piece-sheet[data-frame=portrait] .art { aspect-ratio: 2 / 3; }
.piece-sheet[data-frame=landscape] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.piece-sheet[data-frame=landscape] .art { aspect-ratio: 3 / 2; }
.piece-sheet[data-frame=banner] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.piece-sheet[data-frame=banner] .art { aspect-ratio: 3; }
/* A sheet of mixed frames keeps square places, and each piece sits whole in the middle of its own. */
.piece-sheet[data-frame=mixed] .art { display: grid; place-items: center; background: none; box-shadow: none; overflow: visible; }
.piece-sheet[data-frame=mixed] .art svg { width: 100%; height: auto; border-radius: 3px; box-shadow: 0 1px 2px rgb(var(--sh) / .1), 0 4px 12px rgb(var(--sh) / .08); }
.piece-sheet[data-frame=mixed] .art[data-frame=portrait] svg { width: auto; height: 100%; }
.hashline { display: flex; gap: 8px; font-size: 12px; line-height: 16px; color: var(--muted); white-space: nowrap; }
.hashline .mono { min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

/* The curve here never overshoots, so the island's height only ever moves one way. */
.lab-island { --lab-spring: cubic-bezier(.22, 1, .36, 1); --knob: #F4F3EF;
  position: fixed; z-index: 10; left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding: 5px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--lifted); }
/* Eight tabs fit a 375 phone at their own widths. On a narrower one the row scrolls, and never squeezes a word. */
.lab-tabs { display: flex; gap: 1px; padding-bottom: 5px; border-bottom: 1px solid var(--line); overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.lab-tabs::-webkit-scrollbar { display: none; }
.lab-tab { flex: 1 0 auto; min-height: 40px; padding: 0 2px; border-radius: 8px; font-size: 13px; color: var(--muted); transition: background-color .25s var(--ease), color .2s var(--ease); }
.lab-tab[aria-selected=true] { background: var(--selected); color: var(--ink); font-weight: 600; }
@media (max-width: 380px) { .lab-tabs { gap: 0; } }
.panel-wrap { position: relative; }
.lab-panel { display: flex; flex-wrap: wrap; gap: 4px; max-height: calc(62svh - 84px); padding-top: 5px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.lab-panel::-webkit-scrollbar { display: none; }
.panel-wrap.enter { animation: lab-fade-in .26s ease both; }
@keyframes lab-fade-in { from { opacity: 0; } }
.panel-wrap[data-more=true] .lab-panel { -webkit-mask-image: linear-gradient(#000 calc(100% - 48px), transparent); mask-image: linear-gradient(#000 calc(100% - 48px), transparent); }
.more { position: absolute; left: 50%; bottom: 2px; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 99px; background: var(--card); box-shadow: var(--float); font-size: 12px; color: var(--ink); }
.more::after { content: ''; position: absolute; inset: -4px 0; }
.more i { width: 7px; height: 7px; margin-top: -3px; border-right: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); transform: rotate(45deg); }
.panel-wrap[data-more=false] .more { display: none; }
.grab { position: relative; display: grid; place-items: center; width: 100%; height: 22px; margin-top: -3px; padding: 0; touch-action: none; cursor: grab; }
.grab::after { content: ''; position: absolute; left: 0; right: 0; top: -18px; bottom: 0; }
.grab i { width: 40px; height: 4px; border-radius: 99px; background: var(--muted); opacity: .55; }
.compact { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0; font-size: 13px; line-height: 18px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact b { font-weight: 400; color: var(--muted); }
.lab-island .dice { margin: 0; color: var(--ink); }
.recipe { display: grid; flex: 1 1 100%; min-width: 0; }
.rrow { display: flex; justify-content: space-between; gap: 12px; min-height: 40px; align-items: center; padding: 0 6px; font-size: 13px; }
.rrow span:first-child { color: var(--muted); }

.lab-ctl { display: grid; gap: 2px; align-content: start; flex: 1 1 100%; min-width: 0; padding: 3px 6px; }
.ctl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; }
.ctl-name { display: grid; min-width: 0; font-size: 12px; line-height: 16px; color: var(--muted); }
.ctl-name span { white-space: nowrap; }
.ctl-name output { font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode { flex: none; display: inline-grid; grid-auto-flow: column; padding: 2px; border-radius: 9px; background: var(--hover); }
.mode button { min-height: 40px; padding: 0 9px; border-radius: 7px; font-size: 12px; color: var(--muted); transition: background-color .25s var(--ease); }
.mode button[aria-pressed=true] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(var(--sh) / .12); }
.lab-island .menu-button { height: 40px; font-size: 13px; }
.lab-island .button { min-height: 40px; }
.seed-row { display: flex; align-items: center; gap: 10px; flex: 1 1 100%; min-width: 0; padding: 3px 6px; }
.seed-text { flex: 1 1 0; min-width: 0; }
.seed-text .draws { display: flex; gap: 8px; font-size: 13px; line-height: 18px; white-space: nowrap; }
.seed-text .draws b { flex: none; font-weight: 600; }
.seed-text .draws span { min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 767px) {
  .seed-row { gap: 6px; }
  .seed-row .button { padding: 0 12px; }
  .hashline, .seed-text .draws { gap: 6px; }
}
.seed-col { display: grid; flex: 1 1 100%; min-width: 0; gap: 2px; }
.lab-island .ctl-input { width: auto; padding: 3px 6px; }
.lab-island .input-with-action { height: 42px; }

.sl { position: relative; height: 40px; touch-action: pan-y; cursor: pointer; user-select: none; -webkit-user-select: none; }
.sl-track, .sl-fill { position: absolute; top: 18px; height: 4px; border-radius: 99px; }
.sl-track { left: 10px; right: 10px; background: var(--track); }
.sl-fill { background: var(--ink); }
.sl-h { position: absolute; top: 10px; width: 20px; height: 20px; margin-left: -10px; border: 2px solid var(--ink); border-radius: 50%; background: var(--knob); box-shadow: 0 1px 3px rgb(var(--sh) / .25); }

.seen { font-size: 12px; line-height: 16px; color: var(--muted); text-align: right; }
.rows { display: grid; }
.wrow { display: grid; grid-template-columns: 96px minmax(0, 1fr) 34px; align-items: center; gap: 6px; min-height: 40px; }
.wname { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.wname span:last-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wpct { font: 12px/1 var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.pick { display: grid; grid-template-columns: 22px minmax(0, 1fr) 34px; align-items: center; gap: 6px; min-height: 40px; width: 100%; padding: 0; text-align: left; }
.pick-box { width: 18px; height: 18px; border: 1.5px solid var(--muted); border-radius: 5px; }
.pick[aria-pressed=true] .pick-box { border-color: var(--ink); background: var(--ink); box-shadow: inset 0 0 0 3px var(--card); }
.sw { flex: none; display: flex; align-items: center; gap: 1px; width: 26px; height: 18px; padding: 3px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgb(var(--sh) / .18); }
.sw i { flex: 1; height: 100%; }
.readout { font-size: 12px; line-height: 16px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: pre-wrap; }

.form { display: grid; gap: 8px; margin-top: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.field input[type=text] { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font-size: 16px; }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.lab-island input[type=color] { flex: none; width: 44px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; }
.form-row { display: flex; flex-wrap: wrap; gap: 6px; }
.form-row .primary { margin-left: auto; }
.add-palette { margin-top: 6px; width: 100%; }
/* The shape pool. Marks are grouped by family; Range ticks them, Weighted gives each one a slider. */
.lab-ctl[hidden], .rrow[hidden], .readout[hidden] { display: none; }
.pool-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.family { display: grid; }
.pool { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 12px; }
.pool .wrow { grid-template-columns: 24px minmax(0, 1fr) 34px; }
.pool.ticks { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 4px; }
.mark-icon { display: block; width: 22px; height: 22px; color: var(--ink); }
.mark-icon svg { display: block; width: 100%; height: 100%; }
.pool-pick { display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 52px; padding: 4px 0; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--line); transition: background-color .25s var(--ease); }
.pool-pick .mark-icon { color: var(--muted); }
.pool-pick[aria-pressed=true] { background: var(--selected); box-shadow: none; }
.pool-pick[aria-pressed=true] .mark-icon { color: var(--ink); }
.dice { flex: none; display: grid; place-items: center; width: 40px; height: 40px; margin: -4px -6px -4px 0; padding: 0; border-radius: 8px; color: var(--muted); }
.dice svg { width: 22px; height: 22px; }

/* The rule stack, first in the Rules tab. A row is a sentence; one row opens at a time.
   Add rule stays in reach while the stack scrolls under it. */
.rules { display: grid; flex: 1 1 100%; min-width: 0; padding: 0 6px 6px; }
.rules-head { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 12px; color: var(--muted); }
/* Sticky measures from inside the panel's 5px top padding, so the head reaches up to cover it. */
.rules-top { position: sticky; top: -5px; z-index: 1; margin-top: -5px; padding-top: 5px; background: var(--surface); }
.rules-head b { flex: none; font-size: 13px; font-weight: 600; color: var(--ink); }
.rules-head span { flex: 1 1 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rules-head .button { flex: none; margin-left: auto; }
.rules-head span + .button { margin-left: 0; }
.rules-head .dice:disabled { opacity: .45; }
.rule-group { display: grid; }
.rule-stage { font-size: 12px; line-height: 20px; color: var(--muted); }
.tab-heading { flex: 1 1 100%; padding: 6px 6px 0; }
.tab-heading:first-child { padding-top: 0; }
.rule { display: grid; grid-template-columns: 46px minmax(0, 1fr); align-items: start; border-top: 1px solid var(--line); scroll-margin: 72px 0 24px; }
.rule[data-open=true] { grid-template-columns: 46px minmax(0, 1fr) 40px; }
.rule-switch { display: grid; place-items: center start; width: 46px; min-height: 44px; padding: 0; }
.rule-switch .switch-track { display: block; }
.rule-switch[aria-checked=true] .switch-track { background: var(--ink); }
.rule-switch[aria-checked=true] .switch-knob { transform: translateX(16px); }
.rule[data-on=false] .rule-read, .rule[data-on=false] .rule-edit { opacity: .55; }
.rule-read { display: grid; gap: 1px; width: 100%; min-height: 44px; padding: 5px 0 6px; text-align: left; }
.rule-text { font-size: 13px; line-height: 18px; color: var(--ink); }
.rule-seen { font-size: 12px; line-height: 16px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule-edit { display: grid; gap: 2px; min-width: 0; padding: 2px 0 6px; }
.rule-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 13px; color: var(--ink); }
.rule-menu { display: block; flex: 0 1 auto; min-width: 0; }
.rule-mark { margin-left: -4px; }
.rule-line { min-height: 44px; padding: 2px 0; border-top: 1px solid var(--line); }
.rule-line .button { margin-left: auto; }
.rule-odds { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.rule-odds output { font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule-foot { display: flex; align-items: center; gap: 4px; }
.rule-foot .rule-seen { flex: 1 1 0; min-width: 0; }
.rule-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 8px; color: var(--ink); }
.rule-icon:hover:not(:disabled) { background: var(--hover); }
.rule-icon:disabled { opacity: .3; }
.rule-icon svg { width: 16px; height: 16px; }

/* What never varies: a tick for each Fixed trait, two across. */
.sig-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
.sig-tag { font-size: 12px; color: var(--muted); }

/* Studies and Export, borrowed from the lesson's island, read and touch at the lab's sizes. */
.lab-island .panel-studies, .lab-island .panel-export { flex: 1 1 100%; min-height: 0; padding: 3px 6px; }
.lab-island .saved-input, .lab-island .saved-note, .lab-island .saved-info time, .lab-island #save-help, .lab-island .version { font-size: 12px; }
.lab-island .saved-study-actions .text-button { font-size: 12px; }
@media (pointer: coarse), (max-width: 767px) {
  .lab-island .saved-study-actions .text-button, .lab-island .panel-export .text-button { min-height: 40px; }
  .lab-island .save-row textarea { min-height: 40px; }
}
@media (max-width: 767px) {
  .lab[data-lesson=off] .lab-progress { justify-items: center; }
  .lab-island .panel-export .button { min-width: 0; }
}
@media (min-width: 768px) {
  .piece-sheet { --t: clamp(52px, min(calc((100vw - 48px - 56px) / 8), calc((100svh - var(--lab-top, 57px) - var(--top-h, 44px) - var(--island-reserve, 120px) - 66px) / 3)), 240px); grid-template-columns: repeat(8, var(--t)); justify-content: center; gap: 8px; padding-top: 4px; }
  /* The same width as eight square pieces, in fewer, wider ones. */
  .piece-sheet[data-frame=landscape] { grid-template-columns: repeat(6, calc((var(--t) * 8 + 16px) / 6)); }
  .piece-sheet[data-frame=banner] { grid-template-columns: repeat(4, calc(var(--t) * 2 + 8px)); }
  .lab-island { left: 50%; right: auto; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); bottom: 14px; }
  .lab-tabs { justify-content: center; }
  .lab-tab { flex: none; padding: 0 14px; }
  .lab-panel { justify-content: center; align-items: flex-start; max-height: 38svh; }
  .lab-ctl { flex: none; width: 300px; }
  .lab-ctl[data-wide=true] { width: 360px; }
  .tab-heading { text-align: center; }
  .seed-row { flex: none; width: 440px; }
  .seed-col { flex: none; width: 440px; }
  .seed-col .seed-row { width: auto; }
  .recipe { flex: none; width: 360px; }
  .rules { grid-template-columns: minmax(0, 640px); justify-content: center; }
  .lab-island .panel-studies, .lab-island .panel-export { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-tab, .mode button { transition: none; }
  .panel-wrap.enter { animation: none; }
}

/* The AI prompt and starter code popup: the Discover code window, with text that wraps
   so it reads on a phone, and its actions always in reach under the scrolling text. */
.export-dialog .code-window pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.popup-note { margin-bottom: 12px; font-size: 13px; line-height: 20px; color: var(--ink); }
.export-dialog[data-kind=file] { width: min(420px, calc(100vw - 32px)); }
.export-dialog[data-kind=file] .code-scroll { padding-bottom: 0; }
.export-dialog[data-kind=file] .popup-note { margin-bottom: 0; }
.export-dialog[data-kind=file] .code-actions { padding-top: 16px; border-top: 0; }
.code-actions { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.code-actions .button { min-height: 44px; min-width: 96px; }

/* A popup with no index keeps its title in line with its words. */
.export-dialog .sketch-index:empty { display: none; }
/* A file popup can list what is inside. */
.popup-list { display: grid; gap: 8px; margin: 0; padding-top: 12px; }
.popup-list dt { font: 12px/16px var(--mono); color: var(--ink); }
.popup-list dd { margin: 0; font-size: 13px; line-height: 20px; color: var(--muted); }

/* The end of the road: a full page in the course's quiet list style, opened over the lab or the finish page. */
.end-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; background: var(--ground); color: var(--ink); box-shadow: none; }
.end-dialog .code-head { flex: none; padding: calc(8px + env(safe-area-inset-top)) 8px 0 16px; }
.end-dialog .code-close { width: 40px; height: 40px; }
.end-dialog .code-scroll { flex: 1; display: flex; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
.end-page { display: grid; gap: 12px; align-content: start; width: min(100%, 440px); margin: 0 auto; }
.end-page h2 { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -.02em; }
.end-dialog h2:focus-visible { outline: none; }
.end-head { display: flex; align-items: flex-start; gap: 12px; }
.end-mark { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin-top: 2px; border-radius: 50%; background: var(--ink); }
.end-mark .tick { width: 18px; height: 18px; stroke: var(--btn-ink); }
.end-line { font-size: 13px; line-height: 20px; color: var(--ink); }
/* The padding only reaches past the line, so the link is a 40px target and the text stays put. */
.end-line a { padding: 12px 0; color: var(--ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--mark-border); }
.end-list { display: grid; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.end-list li { border-bottom: 1px solid var(--line); }
.end-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 6px 0; text-align: left; }
.end-row:hover b { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--mark-border); }
.end-row span { display: grid; min-width: 0; }
.end-row b { font-size: 13px; line-height: 20px; font-weight: 500; }
.end-row small { font-size: 13px; line-height: 20px; color: var(--muted); }
.end-row svg { flex: none; width: 16px; height: 16px; color: var(--muted); }
.end-label { margin-top: 4px; font-size: 12px; line-height: 16px; font-weight: 400; color: var(--muted); }
.end-ways { display: grid; gap: 8px; margin-top: 4px; }
.end-ways .button { min-height: 44px; }
.end-page .text-button { justify-self: center; min-height: 40px; }
@media (min-width: 768px) {
  /* Auto margins and not align-self, so a page taller than the window scrolls from its top. */
  .end-page { gap: 10px; margin-block: auto; }
  .end-row { min-height: 40px; }
  .end-page h2 { font-size: 28px; line-height: 34px; }
  .end-ways { grid-auto-flow: column; grid-auto-columns: 1fr; }
  .end-ways .button { min-height: 40px; }
}

/* The finish page. It covers the whole screen and never scrolls on a phone: the art takes
   what the words and buttons leave. */
html[data-finish=on], html[data-finish=on] body { height: 100svh; overflow: hidden; overscroll-behavior: none; }
.finish { position: fixed; z-index: 20; inset: 0; background: var(--ground); overflow: hidden; }
.finish-flood { position: absolute; inset: 0; overflow: hidden; }
.finish-flood:empty { display: none; }
.finish-tile { position: absolute; display: block; max-width: none; object-fit: contain; will-change: transform, opacity; }
.finish-full { position: absolute; will-change: transform; }
.finish-full img { display: block; width: 100%; height: 100%; object-fit: contain; }
.finish-page { --art: min(calc(100vw - 32px), calc(100svh - 296px)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; height: 100svh; padding: calc(12px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom)); }
.finish-title { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); outline: none; }
.finish-piece { display: grid; gap: 6px; width: var(--art); }
.finish-hash { font-size: 12px; line-height: 16px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.finish-side { display: grid; gap: 10px; width: min(100%, 420px); }
.finish-chapters { display: flex; justify-content: center; gap: 14px; padding: 0; list-style: none; }
.finish-chapters li { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; line-height: 20px; color: var(--ink); }
.finish-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.finish-stats div { display: flex; flex-direction: column; align-items: center; }
.finish-stats dt { font-size: 12px; line-height: 16px; color: var(--muted); }
.finish-stats dd { margin: 0; font-size: 20px; line-height: 26px; color: var(--ink); font-variant-numeric: tabular-nums; }
.finish-ways { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.finish-ways .button { min-height: 44px; font-size: 14px; }
.finish-ways .primary { grid-column: 1 / -1; }
/* With a claim config the badge and one more button take a little from the art. */
.finish-page[data-claim] #finish-lab { grid-column: 1 / -1; }
.card-badge { margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--muted); }
@media (max-width: 767px) {
  .finish-page[data-claim] { --art: min(calc(100vw - 32px), calc(100svh - 408px)); }
}
@media (min-width: 768px) {
  .finish-page { --art: min(calc(100svh - 96px), 52vw, 720px); display: grid; grid-template-columns: var(--art) 320px; grid-template-rows: auto auto; column-gap: 48px; row-gap: 18px; align-content: center; justify-content: center; align-items: start; }
  .finish-piece { grid-column: 1; grid-row: 1 / -1; }
  .finish-title { grid-column: 2; font-size: 28px; line-height: 34px; align-self: end; }
  .finish-side { grid-column: 2; grid-row: 2; align-self: start; width: auto; gap: 18px; }
  .finish-chapters { justify-content: flex-start; }
  .finish-stats div { align-items: flex-start; }
  .finish-ways .button { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .tab-pill, .idea-chevron, .switch-knob, .switch-track, .art-figure, .review-art, .slot, .sheet { transition: none; }
}

/* The About seeds tip opens upward inside the island, and phone sliders keep a 44px touch target. */
.island .seed-info-bubble { top: auto; bottom: calc(100% + 8px); }
@media (max-width: 767px) {
  .ctl input[type=range] { height: 44px; margin: -10px 0; }
}
/* iOS zooms into any text field under 16px and leaves the page zoomed. */
@media (hover: none), (max-width: 767px) {
  #seed-input, #study-note { font-size: 16px; }
  #study-note { padding: 7px 10px; line-height: 20px; }
}
