/*
  Tiles — the app's stylesheet (ADR §11).

  THE CONTRACT IN ONE LINE: every pixel of CHROME is decided HERE, and the Rust panels carry only
  the class and id hooks this file reads. Three `style` attributes survive in the whole app and all
  three carry DOCUMENT data rather than chrome:

  - `<svg id="canvas" style="--s0:…;--bg:…;--grid:…">`, one attribute write owned by
    `renderer::paint_vars` (E03.1): the values change per scheme and a recolor has to be ONE write
    with zero mutations under `#art` (E03), which no static stylesheet can be.
  - `<rect id="bg" style="fill:…">` and `#seams`/`#grid`'s `stroke:var(--grid)`, written by
    `render::screen_skeleton`, because a presentation attribute cannot hold a `var()` (E03.4).
  - `<button class="swatch" style="--sw:<slot hex>">`: the slot's COLOR, which is the document's color,
    not the theme's. Everything else about a swatch — size, radius, rings, chip — is here.

  The artwork never follows the theme (ADR §11: "the canvas background is a document property"), so
  no rule in this file targets anything inside `#scene`, and the only `#canvas` rule is an edge on
  the box. `e2e/smoke.spec.js` asserts both halves: no inline style outside the svg and the swatch
  color variable, and the artwork's colors unchanged across a `prefers-color-scheme` flip.

  LAYOUT (E27.1, M15U.01). THREE rows, three columns: the tool rail, the viewport, and the right
  COLUMN. The top bar and the status bar span all three, and the artwork's fit input is still
  `#viewport`'s box - both side columns take WIDTH off it, which is the harmless direction (E07: a
  fifth ROW would change the fitted cell size; a column only changes when the stage starts to scroll).

      +-----------------------------------------------------------+
      | #topbar                                 var(--topbar-h)    |
      | #tools  | #viewport  overflow:auto,       minmax(0,1fr)    |
      | column  |  native scroll  | #right-panel --right-w         |
      | #status                                 var(--status-h)    |
      +-----------------------------------------------------------+

  THE RIGHT CELL IS ONE COLUMN SINCE E27.1. `#right-panel` owns the `panel` area and holds, top to
  bottom, the scheme row, the palette GRID, the tool options, the layers and the collapsible editors
  (Color closed by default, then Harmony, Knobs, Library, Generators). Its width is `--panel-w`,
  which is `UiSettings.right_width` spelled by the splitter, and below 1100 px it becomes a 200 px
  column whose palette stays a 32 px grid while the other sections fly out of their icon tabs (the
  media query at the end of this file).

  THE LEFT COLUMN IS A RAIL SINCE M8.20. `#tools` owns the `rail` area and E27.2's seven tool
  chips; the row it sits in is the STAGE row, so the column and the canvas share one leftover height
  and the chrome still costs exactly three rows.

  THE BOTTOM DOCK IS GONE SINCE E27.1: "the bottom palette strip and the kind/shape chip bars are
  REMOVED; the status line stays". The strip did not die, it MOVED - the id is still `#palette`, now
  a grid in the column - and the kind and shape chips are the command palette's rows now, so the
  `#kinds`/`#shapes` CSS left with the bar that needed it.

  The rows are GRID AREAS rather than DOM order: `App` renders the viewport FIRST (tab order) and the
  bar still lands at the top edge. And because the bars are ROWS rather than floats over the canvas,
  `#viewport`'s measured box — E07's fit input, read by `app::send_viewport` — is the FREE space, so
  the artwork can no longer hide under a bar.
*/

/* ---------------------------------------------------------------- tokens

  Every chrome VALUE lives in `theme.css` (E33.1), which trunk links BEFORE this file: colors, font
  families and sizes, control heights, radii, spacing steps, shadows, motion durations and the focus
  ring are custom properties on `:root` there, and this file reads those names. The split is enforced
  by the gate's lint `chrome_tokens_only` (`cargo xtask chrome-tokens-only`), and `e2e/theme.spec.js`
  pins that reading them cost no pixel. One rule of layout belongs to a value nobody typed here:
  `--panel-w` is `--panel-tab-w` below 1100 px, and that one line sits with the tokens.
*/

/* ---------------------------------------------------------------- the frame */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  /* `dvh` so a mobile browser's collapsing URL bar does not push the status row off screen; `vh`
     above is the fallback for a browser without it. */
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: grid;
  /* THREE COLUMNS SINCE M9.07: rail, stage, right panel. The top bar, the dock and the status row
     span all three, so ADR §11's four ROWS are still four rows and the artwork's fit input is
     still `#viewport`'s box — the side columns take WIDTH off it (E07). */
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--panel-w);
  /* THREE ROWS since M15U.01: E27.1 took the bottom dock away ("the bottom palette strip and the
     kind/shape chip bars are REMOVED; the status line stays"), so the frame is top bar, stage, status
     and the artwork's fit input is still `#viewport`'s box. */
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--status-h);
  grid-template-areas:
    "top top top"
    "rail stage panel"
    "status status status";
  overflow: hidden;
  background: var(--stage);
  color: var(--ink);
  font: var(--ui-font);
}

/* The stage: ADR §11's center viewport, and the scroll container E07's fit measures. `overflow:auto`
   IS the pan (M8's `ScrollBy` nudges `scrollLeft`/`scrollTop`), `touch-action:none` stops the browser
   panning over a stroke, `overscroll-behavior:none` stops a swipe chaining into the page, and
   `user-select:none` is E09's text-selection half. `min-*:0` is what lets the grid row shrink below
   its content so the svg OVERFLOWS and scrolls instead of pushing the bars apart.

   E33.2 adds the dot grid behind everything: `--dot` dots every `--dot-gap`, painted on the CANVAS
   AREA (this box) and not on the artwork, and off when `UiSettings.canvas_dots` says off — which the
   app spells as `:root[data-dots="off"]`. `background-attachment` is left at its default, so the dots
   hold still while the artwork pans over them: they are the ground, not a texture on the paper. */
.viewport {
  grid-area: stage;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  background-image: radial-gradient(var(--dot) var(--dot-r), transparent var(--dot-r));
  background-size: var(--dot-gap) var(--dot-gap);
}

/* The switch. `canvas_dots` is core's bool (E33.2, `UiSettings.canvas_dots`); the app writes the
   attribute on `:root` every time it moves, and this is the only rule that reads it. */
:root[data-dots="off"] .viewport {
  background-image: none;
}

/* E33.2's other half of "fitted and centered": the artwork is ONE flex item (`#stage`) inside the
   scroll container, and `margin:auto` centres it in the free space on both axes. Auto margins are the
   SAFE centring: they absorb positive free space only, so an artwork bigger than the stage keeps its
   top-left at the container's origin, every pixel stays reachable by scrolling, and nothing jumps as
   the zoom crosses "exactly fits". Core's `Effect::ScrollTo` handles the other direction (a stage
   smaller than the art at the smallest rung); between them the art is centred at every size. */
.viewport {
  display: flex;
}

.stage {
  position: relative;
  flex: 0 0 auto;
  margin: auto;
}

/* An svg is an INLINE element, so its baseline would add a few px under the artwork and buy a
   permanent vertical scrollbar in a container that is exactly the artwork's height.
   `position: relative` since M15.02 for the stacking it describes, not for the artwork: `#paint` is
   absolutely positioned at this box, both elements are positioned, and positioned elements paint in
   DOM order — so the `<svg>` (later) is ABOVE the bitmap. That is the whole layering of the Canvas2D
   path: the bitmap paints the cells, the `<svg>` keeps the pointer (E03.3), the overlay, the grid
   hairlines and the room's marks, and none of them have to be redrawn anywhere else. */
.viewport {
  position: relative;
}

.stage > svg {
  display: block;
  position: relative;
  box-shadow: var(--art-edge);
}

/* M15.02's Canvas2D surfaces: the artwork above 4 096 cells (ADR §5.8 step (6)) and, under it since
   M15.04, its GROUND — the paper or E03.4's checkerboard the artwork is painted over.
   `pointer-events: none` is the item's "same hit testing" — every pointer still lands on the `<svg>`,
   so `offset_x`/`offset_y` are svg-local CSS px and `View::to_cell` still names the cell. `left/top:
   0` is the artwork's own origin because both are sized to exactly the `<svg>`'s box, box-shadow
   excepted. The chrome's geometry stays out of this rule on purpose: there is nothing here but the
   stacking — `#ground` first in the DOM, then `#paint`, then the `<svg>` — and the numbers come from
   `renderer::box_px`. */
#ground,
#paint {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- controls */

/* Every button in the chrome, from the SAME rule, so "≥ 24 px" is one line rather than a hope
   (WCAG 2.5.8). `font: inherit` because a button inherits no font by default. */
#topbar button,
/* M10.11: the `Open` label is a control of the bar like every other one (ADR §10.7's file picker), so
   it takes the SAME rule — the 24 px floor (WCAG 2.5.8) is still one line, and a label that styled
   itself would be the first control in the app small enough to miss it. E34.4's `.new-doc` sits LEFT of
   it and needs no rule of its own for the same reason: the bar's row order is core's (`TOP_BAR_SLOTS`),
   and every control the bar gains is already over the floor. */
#topbar .open-file,
#status button,
#tools button,
/* M8.23: the cheat sheet's `×` is a control of the chrome like the rest, so it takes this rule too —
   the 24 px floor (WCAG 2.5.8) is one line, and a float that grew its own button style would be the
   first control in the app small enough to miss it. */
.sheet-box button,
/* M9.07: the right panel's section headers are chrome controls too — the 24 px floor is one line.
   SINCE M15U.01 the palette grid lives in this panel, and the THREE controls the grid owns are NOT
   chrome buttons: a `.swatch` is a plate of the DOCUMENT's color (its `background` is `var(--sw)`, an
   inline value the palette writes) and `.add-slot` / `.make-ramp` are dashed and outlined squares. This
   rule's `background: var(--face)` would paint every plate the same grey, so they are excepted — the
   plates set their own size (48 px, `--grid-swatch`), which is over the 24 px floor by themselves. */
#right-panel button:not(.swatch):not(.add-slot):not(.make-ramp) {
  flex: 0 0 auto;
  height: var(--ctl-h);
  min-width: var(--ctl-h);
  padding: 0 8px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-5);
  background: var(--face);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

/* E10.13's "disabled per `can_undo`/`can_redo`", made visible. The `disabled` ATTRIBUTE is what
   stops the click (`panels::topbar`); this is the half that says WHY to the eye. A custom
   background above would beat the browser's own greying, so the bar dims it itself. */
#topbar button:disabled,
#status button:disabled,
#tools button:disabled,
/* M9.08: "Select all N pieces" with N = 0 and "Delete slot…" on a one-slot palette are DISABLED by
   core (`can_select`/`can_delete`), and a dead button that looks alive is the worse half of that. */
#right-panel button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Keyboard focus, which the pointer-only rules above say nothing about (WCAG 2.4.7). A focus ring on
   a control clicked by mouse is noise, so it is `:focus-visible` only — and no control in this app
   takes focus on mousedown anyway (`on:mousedown` prevents it). */
#topbar button:focus-visible,
/* M10.11: the picker's `<input>` is invisible, so the ring belongs on its LABEL — `focus-within` is
   the only way a caret that sits on the hidden field shows up where the eye is (WCAG 2.4.7). */
#topbar .open-file:focus-within,
#status button:focus-visible,
.swatch:focus-visible,
.tool:focus-visible,
#right-panel .panel-tab:focus-visible,
/* M9.08: the editor's two fields and three buttons — every one of them Tab-reachable, so every one of
   them shows where the caret is (WCAG 2.4.7). */
#right-panel button:focus-visible,
#right-panel input:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off);
}

/* M10.01: the same ring INSIDE a modal, where the rules above do not reach — a `<dialog>` is neither the
   top bar nor the right panel, and a focus trap whose caret is invisible is a trap you cannot see
   (WCAG 2.4.7, R3 AC-02's "focus trap in dialogs" edge). Written on the ELEMENT so every box the page has
   and every one M10 adds gets it without a new class: this is the stylesheet's half of the infrastructure.
   The box itself is in the list because `showModal` parks the caret on the `<dialog>` until the panel's
   own first control exists (M10.01's `focus_first` retry). */
dialog:focus-visible,
dialog :focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off);
}

/* ---------------------------------------------------------------- top bar */

#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: var(--bar-pad-y) var(--bar-pad-x);
  background: var(--chrome);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  user-select: none;
  touch-action: none;
}

/* The title ellipsises rather than wrapping: the name of the artwork is the one thing in this row
   the user wrote, and a bar that grows by a line moves the canvas mid-stroke. */
#topbar .title {
  min-width: 0;
  font-weight: 600;
  max-width: 22em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* M10.17: ADR §11's `Untitled*`. The star HUGS the name it qualifies — the bar's own `gap` would put
   a whole control's width between the name and a mark about that name — and it costs no space at all
   when the document is saved, because the element is empty then (an empty inline box has no box). The
   color is the file's one alarm red (`--bad`, M9.08): the mark means "not yet where it belongs", which
   is the same sentence the hex field says about a typo, and it is gone half a second later. */
#topbar .unsaved {
  color: var(--bad);
  font-weight: 700;
  margin-left: calc(0px - var(--gap) / 2);
  cursor: help;
}

/* The scheme group reads as ONE control with its name between the steppers, and the name keeps a
   minimum width so `‹ ›` do not slide sideways when Mocha becomes Latte — that would move the user's
   next click out from under the pointer. */
#schemes .scheme-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 2px;
}

#schemes .scheme {
  min-width: 5em;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The gap that pushes the action buttons to the right edge, where ADR §11's `[Export] [Share]` row
   lives. */
/* M10.11's file picker: the label is the button, the field is the sr-only half of it. `opacity:0` and
   1 px rather than `display:none`, because a `display:none` field is outside the tab order in some
   engines — and a control you cannot reach with the keyboard is a WCAG 2.1.1 failure, not a shortcut. */
#topbar .open-file {
  display: inline-flex;
  align-items: center;
  position: relative;
}

#topbar .open-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#topbar .spacer {
  flex: 1 1 auto;
}

/* ------------------------------------------------ scheme tabs (M9.13, ADR §11 `[Mocha][Latte][+]`) */

/* The tabs are a strip INSIDE the top bar's flex row, and they scroll sideways rather than wrapping:
   the title's rule applied to a longer list — a bar that grew by a line would move the canvas
   mid-stroke. `min-width:0` is what lets a flex child scroll instead of pushing the row wider, and
   the `max-width` leaves the action buttons their right edge. */
#schemes .scheme-strip {
  position: relative;
  display: flex;
  min-width: 0;
  max-width: 40vw;
}

#schemes .scheme-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  padding: 1px 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* A tab is a chip carrying the scheme's whole WORD, not a color square: what is being compared is a
   palette with a name attached, and the name is what `,` and `.`'s tooltip already says. `flex:0 0
   auto` keeps a long name from being squeezed into an unreadable stub. */
#schemes .scheme-tab {
  flex: 0 0 auto;
  height: var(--ctl-h);
  padding: 0 8px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-5);
  background: transparent;
  color: var(--ink);
  font: inherit;
  white-space: nowrap;
}

/* The lit tab is the scheme the artwork is WEARING — the ring language of a loaded kind chip and the
   tool that is up (an outline OUTSIDE the box, so it never covers the label), plus a lifted face.
   `aria-pressed` in the markup says it again.

   INK, not the accent (E33.2): the accent belongs to the current tool, the PRIMARY swatch ring, the
   selection outline and the keyboard ring, and "everything else is ink and paper, so the art is the
   only loud color on screen". A lit scheme tab is a label about the document, so it is ink and a
   lifted face — `--mark-ring-ink`. */
#schemes .scheme-tab.active {
  outline: var(--mark-ring-ink);
  outline-offset: var(--ring-off-tight);
  background: var(--chrome-2);
}

/* The A/B flash: the scheme ON SCREEN because `Backquote` is held. A dashed ring, and the lit tab
   STAYS lit: the document did not change, and the one preview in this app that must never look like an
   edit is the one that costs no undo step. */
#schemes .scheme-tab.flashing,
#schemes .scheme-row.flashing {
  outline: var(--focus-ring-dashed);
  outline-offset: var(--ring-off-tight);
}

/* The inline rename field, in the tab's own seat: the same height and the same rounding as the chip it
   replaced, so opening a rename does not slide the `×` or the `+` out from under a second click. */
#schemes .scheme-rename {
  flex: 0 0 auto;
  height: var(--ctl-h);
  padding: 0 6px;
  border: 1px solid var(--ring);
  border-radius: var(--radius-5);
  background: var(--face);
  color: var(--ink);
  font: inherit;
}

/* The three verbs of the strip: `×` deletes (asks first), `+` duplicates, `⋯` lists what the seats do
   not hold. All three keep the `--ctl-h` floor every control in the app keeps (WCAG 2.5.8). */
#schemes .scheme-del,
#schemes .scheme-add,
#schemes .scheme-more {
  flex: 0 0 auto;
  height: var(--ctl-h);
  min-width: var(--ctl-h);
  padding: 0 6px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-5);
  background: transparent;
  color: var(--ink);
  font: inherit;
}

/* A scheme can always be duplicated; it can be deleted only when another one exists to fall back to.
   `disabled` is core's `can_delete` attribute, so the grey IS the `LastScheme` rule, not a hint about
   it — and a real disabled button fires no click, which is how the e2e proves the gate. */
#schemes .scheme-del:disabled {
  opacity: 0.4;
}

/* The overflow rows: the tabs the seats do not hold, hanging below the bar. Absolutely positioned so a
   menu cannot resize the bar, and a bar that cannot resize cannot move the canvas under a list. */
#schemes .scheme-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
}

#schemes .scheme-row {
  height: var(--ctl-h);
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  text-align: left;
  white-space: nowrap;
}

/* ------------------------------------------------- scheme lerp (M9.14, ADR §7.7's lerp slider) */

/* The `mix` button and, while it is up, the row: a label, a thumb, the other end's label, a readout
   and the `+`. The row is a SIBLING of `.scheme-strip`, not a child: the tabs scroll sideways and a
   scroll container clips anything inside it, so a thumb in there could be dragged into invisibility.
   `flex:0 0 auto` on the wrapper and the slider keeps the bar's own height — a control that grew the
   top bar would shrink the box E07's fit measures, which is the one layout change a mix must never make. */
#schemes .scheme-lerp {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

/* The armed `mix` wears the same ring as a lit tab: it is the surface that is up, and the artwork is
   wearing a mix rather than a scheme. */
#schemes .scheme-lerp-toggle[aria-pressed="true"] {
  /* The INK twin: E33.2's accent belongs to the four, and an armed toggle is not one of them. */
  outline: var(--focus-ring-ink);
  outline-offset: var(--ring-off-tight);
  background: var(--chrome-2);
}

#schemes .scheme-lerp-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 4px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
}

/* The A end is a WORD about the scheme already on screen, so it is ink, not a control: clicking it
   would have to do nothing, and a button that does nothing is a question with no answer. */
#schemes .scheme-lerp-end {
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  opacity: 0.8;
}

/* A hundred ticks of mix on a track about as wide as a thumb's reach: 96 px is the compromise, and it
   is the reason the readout carries the number the track cannot show. `accent-color` paints the filled
   half with the same ring color every lit control uses. */
#schemes .scheme-lerp-slider {
  width: 96px;
  height: var(--ctl-h);
  accent-color: var(--ring);
  margin: 0;
}

/* The B end IS a control: clicking it walks the other end through the tabs (M9.14), so it is a chip in
   the tab's own shape rather than a label pretending to be one. */
#schemes .scheme-lerp-b {
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The percentage the thumb stands at, and the name the `+` would give. Tabular figures, so the number
   does not slide sideways as the thumb crosses a ten. */
#schemes .scheme-lerp-out {
  min-width: 3.5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* M10.03's export split button (E13.1: "click = re-export with the saved settings, caret = dialog").
   Two buttons that read as ONE control: the wrapper takes the gap out, the caret drops its left border
   so the join is one line rather than two, and the rounding stays on the outside corners only. Both
   halves are still plain `#topbar button`s, so the 24 px floor (WCAG 2.5.8), the `:focus-visible` ring
   and the `(pointer: coarse)` growth come from the rules above untouched — this adds a shape, not a
   second control model. */
#topbar .export-split {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

#topbar .export-split .download {
  border-radius: 5px 0 0 5px;
}

#topbar .export-split .export-caret {
  border-left: 0;
  border-radius: 0 5px 5px 0;
  padding: 0 6px;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1;
}

/* The pair is one control, so it lights as one: hovering either half rims the whole thing. */
#topbar .export-split:hover .download,
#topbar .export-split:hover .export-caret {
  border-color: var(--ring);
}

/* The e2e's `undo={n} redo={m}` read-out: `hidden` keeps it out of the layout, and this keeps
   `<pre>`'s UA margin from being a thing a later layout bug blames. */
#topbar .dbg {
  margin: 0;
}

/* ---------------------------------------------------------------- palette grid (E27.1, M15U.01)

  The strip became the GRID: E27.1 moved it out of the bottom dock and into the right column, "a swatch
  grid, as many 48 px swatches per row as fit", and the dock it used to share that row with the kind bar
  is GONE with the kind and shape chips. The id is still `#palette` — the control moved, it was not
  replaced — which is why every palette test in `e2e/` still addresses `#palette .swatch`.

  THE ONE GEOMETRY THAT MATTERS is the pitch. `grid-template-columns: repeat(auto-fill, var(--swatch))`
  with `gap: var(--sw-gap)` lays out exactly `grid_cols(content, swatch, gap)` columns (core's
  arithmetic and the browser's, agreeing), so:

    * a plate at position `p` sits at column `p % cols`, row `p / cols`, pitch `swatch + sw-gap`;
    * `--caret-col` / `--caret-row` and `--swap-col` / `--swap-row` put the two drag marks on that
      seam (the app does the divide and modulo, the stylesheet does the pixels);
    * a `.strip-pad` is a WHOLE number of hidden rows, which is why core's
      [`palette_grid_window`](tiles_core::controller::palette_grid_window) aligns its window to rows and
      the spacer can say `grid-column: 1 / -1`.

  The scroll axis is VERTICAL now (`max-height` + `overflow-y`), and `dom::grid_metrics` reads the
  height, the content width and the pitch off this element, so changing the numbers below moves the
  window with them — nothing here is spelled twice. */
#palette {
  /* The plate is `--grid-swatch` (48 px, 32 px in the narrow column, E27.1) — a token E27.1 declares
     in `theme.css`, where every chrome VALUE lives, and which that file writes over `--swatch` for this
     element so the swatch, the pads and the drag marks all read ONE number. */
  /* The containing block for `.caret` and `.swap-mark`, and the scroll port for the row of rows. */
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--swatch));
  gap: var(--sw-gap);
  align-content: start;
  justify-content: start;
  min-width: 0;
  max-height: 42vh;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: var(--pad-y) var(--pad-x);
  background: var(--face);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-8);
  user-select: none;
  touch-action: none;
}

/* The hidden rows, as ONE grid item that spans the column. `--hide` is core's COUNT of hidden swatches
   and `--cols` the count the app measured, so the height is `hide / cols` rows of pitch — minus one
   `gap`, because the grid adds the gap between the spacer and the first kept row itself. Exact to the
   pixel, which is the same promise the strip made about a kept swatch's x: a plate at position `p` is
   at `p % cols`, `p / cols` whether or not the grid is windowed. Built ONLY when something is hidden. */
.strip-pad {
  grid-column: 1 / -1;
  height: calc(var(--hide, 0) / var(--cols, 1) * (var(--swatch) + var(--sw-gap)) - var(--sw-gap));
  min-height: 0;
  pointer-events: none;
}

/* One swatch. The COLOR is `--sw` — inline, because it is the document's color and the theme has no
   claim on it — with a fallback so a swatch that never got one is a grey plate, not a hole. */
.swatch {
  position: relative;
  flex: 0 0 auto;
  width: var(--swatch);
  height: var(--swatch);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  appearance: none;
  background: var(--sw, gray);
  cursor: pointer;
}

/* PRIMARY is an `outline` (OUTSIDE the box, so it never covers the color); SECONDARY is an inset
   `box-shadow` — one element has one outline, so an inner ring is the only way both show at once.
   The chrome-colored line under the ring is what keeps the secondary legible on a light color too. */
.swatch.primary {
  outline: var(--mark-ring);
  outline-offset: var(--ring-off);
}

.swatch.secondary {
  box-shadow:
    inset 0 0 0 3px var(--chrome),
    inset 0 0 0 5px var(--ring);
}

.swatch .badge {
  position: absolute;
  left: 3px;
  top: 3px;
  min-width: 11px;
  padding: 1px 3px;
  border-radius: var(--radius-3);
  background: var(--chip);
  color: var(--chip-ink);
  font: var(--chip-font);
  text-align: center;
  /* The chip is decoration with a label on the button for the a11y tree, so it never eats a click
     aimed at its swatch. */
  pointer-events: none;
}

/* The usage chip (M9.01, ADR §7.7's "usage `n (p%)`", §11's "usage percentages"): the SHARE of the
   artwork this role paints, along the bottom edge, on the same unthemed plate as the digit — it sits
   on the document's color, so a themed chip would be unreadable on half the palette. `tabular-nums`
   so a swatch whose count changed does not jiggle its neighbours. `0%` is printed, not hidden: "this
   color is used NOWHERE" is the answer the badge exists to give (R3 COL-14). The exact count is in
   the swatch's name, which is also what a screen reader announces (R3 AC-03). */
.swatch .usage {
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 2px;
  border-radius: var(--radius-3);
  background: var(--chip);
  color: var(--chip-ink);
  font: var(--chip-font);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  /* A chip with no room to breathe would sit over the swatch's own rounded corner; `overflow` is the
     belt to `right: 2px`'s braces. */
  overflow: hidden;
  pointer-events: none;
}

/* The lock glyph (M9.01, E10.12's `Ctrl+click` row): a padlock on the same plate, in the corner the
   digit is not in. FILLED rather than the rail's 1.6 px stroke, because this one is drawn at 11 px
   and a stroke that thin turns to anti-aliased mush — which is also why core's `LOCK_GLYPH` is two
   closed subpaths instead of an outlined one. `currentColor` so the plate and the ink are the two
   numbers above it, and never a color the document owns (ADR §11). */
.swatch .lock {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-3);
  background: var(--chip);
  color: var(--chip-ink);
  pointer-events: none;
}

.swatch .lock svg {
  display: block;
  width: 11px;
  height: 11px;
  fill: currentColor;
}

/* The ramp underline (M9.18, E12.6's "Ramp members show an underline in the strip"): the role is one of
   the rungs of a `Palette::ramps` row, which is the ladder the Shade tool walks (`KeyU`, `shade_step`'s
   "the first ramp containing the slot"). A LINE rather than a glyph because a ramp is an ORDER, and a
   line is the one mark that reads "part of a sequence" on a swatch already carrying a digit, a share, a
   lock and up to two rings.

   A pseudo-element, so an underlined swatch is still the same three child nodes under a memo rebuild.
   `--ink`, not a document color (ADR §11: the chrome marks the chrome, and the line has to read on a
   mauve swatch and a black one alike). The usage chip LIFTS rather than fights for the bottom edge: one
   number moving six px is cheaper than two marks colliding, and the chip is the thing the eye checks
   second. */
.swatch.ramp::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 2px;
  height: 3px;
  border-radius: var(--radius-2);
  background: var(--ink);
  pointer-events: none;
}

.swatch.ramp .usage {
  bottom: 8px;
}

/* The `+` button (M9.06, ADR §7.7's "`+` adds via `suggest_distinct`"): a square at the end of
   the strip that is a CHROME control, not a swatch — no `--sw`, because it paints no document
   color until the click lands. A dashed edge says "a swatch goes here" without claiming the
   solid, color-filled identity of a real one. Same 44 px as a swatch so the strip height is
   unchanged. */
.add-slot {
  flex: 0 0 auto;
  width: var(--swatch);
  height: var(--swatch);
  padding: 0;
  border: 2px dashed var(--ctl-line);
  border-radius: var(--radius);
  appearance: none;
  background: transparent;
  color: var(--ink-dim);
  font: 20px/1 var(--ui-font);
  cursor: pointer;
}

.add-slot:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.add-slot:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off);
}

/* The ramp builder (M9.18, E12.6): the square after `+` that turns the two RINGED swatches into a
   ladder. `add-slot`'s measure with a SOLID edge instead of a dashed one — `+` proposes "a swatch goes
   here" and this promises "these two colors get rungs", and one dashed edge already says guess. No
   `--sw` either: it paints no document color, and `▁` is the same glyph the command palette prints for
   the same command, so the strip and `Ctrl+K` point at one thing. */
.make-ramp {
  flex: 0 0 auto;
  width: var(--swatch);
  height: var(--swatch);
  padding: 0;
  border: 2px solid var(--ctl-line);
  border-radius: var(--radius);
  appearance: none;
  background: transparent;
  color: var(--ink-dim);
  font: 20px/1 var(--ui-font);
  cursor: pointer;
}

.make-ramp:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.make-ramp:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off);
}

/* The insertion caret (E10.12 row 5, M9.04): the seam a `Shift+drag` would drop the swatch into.
   It EXISTS ONLY while such a drag is open — the panel renders no node when there is nothing to
   point at — so the strip is one element taller for the length of a gesture and never otherwise.

   `--caret` is a strip EDGE, `0..=n` (`0` before the first swatch, `n` past the last), and it is
   decided entirely in core (`caret_line`, checked against `MoveInOrder`). What is decided HERE is the
   pixel: the edge sits in the middle of the gap before swatch `k`, which is `k * (swatch + gap)`
   minus half a gap, measured from the padding box, and `translateX(-50%)` centres the 3 px bar on it
   without a second number to keep in step.

   `--ink`, not the document's color: the caret is chrome pointing at the chrome, and it has to stay
   visible over a mauve swatch and a black one alike. `pointer-events: none` so a caret drawn under
   the finger never becomes the thing the next `elementFromPoint` reports. */
.caret {
  position: absolute;
  /* The seam BEFORE plate `--caret`. The app divides the edge by the measured column count and writes
     `--caret-col` / `--caret-row`; this file only multiplies them by the pitch, so the mark lands on
     the same seam the full grid gives that edge, windowed or not. It is a plate tall (not a row of the
     whole strip tall, which is what the bottom row drew) because the grid is two-dimensional. */
  top: calc(var(--pad-y) + var(--caret-row, 0) * (var(--swatch) + var(--sw-gap)) - var(--sw-gap) / 2);
  left: calc(var(--pad-x) + var(--caret-col, 0) * (var(--swatch) + var(--sw-gap)) - var(--sw-gap) / 2);
  transform: translateX(-50%);
  height: var(--swatch);
  width: 3px;
  border-radius: var(--radius-2);
  background: var(--ink);
  pointer-events: none;
}

/* ---------------------------------------------------------------- tool rail (M8.20) */

/* ADR §11's left column, cut to E27.2's SEVEN chips: top to bottom in `Tool::RAIL` order — Select,
   Brush, Eraser, Fill, Transform, Stamp, Hand. The ICONS are `<path>` data out of core
   (`vm::tool_rail`) and they wear `currentColor`, so unlike a kind chip's glyph there is no document
   color anywhere on this rail: the column follows the chrome, and the only themed-vs-data split on
   screen stays inside `#canvas`. Each chip lives in a `.slot` with its flyout as a sibling, because a
   `<button>` may not hold a `<button>`. */
#tools {
  grid-area: rail;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--pad-y) 0;
  background: var(--chrome);
  border-right: 1px solid var(--line);
  user-select: none;
  touch-action: none;
  /* A short window scrolls the rail on its own axis rather than pushing the rows apart — the rows are
     E07's fit input and must not move — and `scrollbar-width:thin` keeps that scrollbar inside
     `--rail-w` instead of eating the chips. Seven chips fit any window the app is used in, but the rule
     costs nothing and a rail that grew again would keep the stage's box intact. */
  overflow-y: auto;
  scrollbar-width: thin;
}

/* One chip and its flyout. The slot is the positioning parent for the corner glyph and the box that
   long-press opens, and it is what `pointerleave` fires on — the flyout is a DESCENDANT, so moving
   from the chip into the box is not a leave and does not close it. */
#tools .slot {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
}

/* The sub-mode corner mark (E27.2): the letter of the sub-mode that is up, on the TOP-right so it
   cannot be mistaken for the chip's own key badge in the bottom-right. Empty on the six chips that are
   one tool, so the mark doubles as the affordance: a chip with a corner has a flyout. */
#tools .subglyph {
  position: absolute;
  right: 1px;
  top: 0;
  min-width: 9px;
  padding: 0 2px;
  border-radius: var(--radius-3);
  color: var(--ink-dim);
  font: var(--chip-font);
  text-align: center;
  pointer-events: none;
}

/* The flyout: E27.2's long-press menu. `position:fixed` because `#tools` clips on its own scroll axis
   and a menu that opens INSIDE the 38 px column is not a menu; `--fx`/`--fy` are the pointer's window
   px, handed over inline by `toolbar.rs` as data about one gesture. `--menu-shadow` is the same depth
   the swatch menu floats at, so two menus that mean the same thing look the same. */
#tools .tool-flyout {
  position: fixed;
  left: var(--fx, 0px);
  top: var(--fy, 0px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 132px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome-2);
  box-shadow: var(--menu-shadow);
}

/* One chip: a square, the icon inside it, and the key in its corner. `#tools button` rather than
   `.tool` because the shared control rule above is an ID selector too, and this is the rule that
   OVERRIDES its `--ctl-h` height: a tool chip is square, and a 24 x 24 icon with a badge crammed into
   a 24-tall box is a badge on top of an icon. `flex:0 0 auto` (shared) is what stops a flex column
   from stretching a chip to fill the rail. */
#tools button {
  position: relative;
  width: var(--tool);
  height: var(--tool);
  padding: 2px;
}

/* The icon. Strokes take the chip's ink and a `.solid` path is FILLED with it — one rule for every
   icon, so no icon can invent its own weight or its own color, and the disabled chip dims the whole
   thing with the shared `opacity` rule. `stroke-linejoin:round`, because half of these shapes are
   arrowheads and a mitered tip at 30 px is a spike. */
#tools .icon {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#tools .icon .solid {
  fill: currentColor;
  stroke: none;
}

/* A flyout row: the sub-mode's icon, its word, and the key that means it — one row per tool, the same
   thirty-pixel control height as everything else, and NOT the square the chips are (`#tools button`
   above sizes every button in the column to `--tool`, and a 30 x 30 row cannot hold a word). */
#tools .tool-flyout button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: auto;
  height: var(--ctl-h);
  padding: 0 6px;
  border-radius: var(--radius-4);
}

#tools .tool-flyout .icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

#tools .tool-flyout .sub-name {
  flex: 1 1 auto;
  text-align: left;
  color: var(--ink);
  white-space: nowrap;
}

#tools .tool-flyout .sub-key {
  flex: 0 0 auto;
  min-width: 12px;
  color: var(--ink-dim);
  font: var(--chip-font);
  text-align: right;
}

/* The tool that is up: the same ring language as a loaded kind chip and a primary swatch — an outline
   OUTSIDE the box, so it never covers the icon — with a slightly lifted face so the chip reads as
   "this one" even where the ring lands on the rail's own edge. `aria-pressed` says it again. */
#tools button.active {
  outline: var(--mark-ring);
  outline-offset: var(--ring-off);
  background: var(--chrome-2);
}

/* The key badge: ADR §11's wireframe prints one letter per chip, and a tool you cannot name is a tool
   you will not try. The letter alone would lie about `Shift+KeyB`, so the badge carries the Shift too
   (core decides which string, `rail_badge_names_a_real_chord` refuses a badge whose chord moved). The
   tooltip has the whole chord. ADR §11's coarse-pointer half hides the labels: a touch user has no
   key to read. */
#tools .badge {
  position: absolute;
  right: 1px;
  bottom: 0;
  min-width: 9px;
  padding: 0 2px;
  border-radius: var(--radius-3);
  background: var(--chip);
  color: var(--chip-ink);
  font: var(--chip-font);
  text-align: center;
  pointer-events: none;
}

@media (pointer: coarse) {
  #tools .badge {
    display: none;
  }
}

/* ------------------------------------------------------------- right panel (M9.07) */

/* ADR §11's right column: the five collapsible sections. The column owns the `panel` grid area,
   which spans the STAGE row only — the palette dock stays full-width below it, so the strip never
   loses a swatch to the panel. `overflow-y:auto` lets a long stack of open sections scroll on its
   own axis instead of pushing the rows apart (E07's fit input is `#viewport`, not this). */
/* E27.1's ONE column: the scheme row, the palette grid, the tool options, the layers and the editors,
   with the drag splitter on its LEFT edge. Its width is `--panel-w` in the body grid, which is
   `calc(var(--right-w) * 1px)` — the number is `UiSettings.right_width` (260..=560, core's clamp), the
   unit is CSS's, and the app writes the number on `:root`. Below 1100 px `theme.css` overrides
   `--panel-w` with `--panel-narrow-w`, and the splitter goes away with it.
   `position:relative` is the anchor the splitter hangs off (and the narrow flyout's, since M9.07). */
.right-panel {
  grid-area: panel;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* E33.2: "open, not boxed". The column is the SAME paper as the workspace behind it, and what
     divides its sections is a 1 px `--rule` line and whitespace (`--pad-y`/`--pad-x`), not a bordered
     panel — the one `--surface` slab in this column is a control. Its left edge is still a rule,
     because the stage and the column do need a line between them. */
  background: var(--paper);
  border-left: 1px solid var(--rule);
  /* The column itself does NOT scroll: `.panel-scroll` below does. A handle that lives inside the
     scroller scrolls away with the content — `bottom:0` is the CONTENT box, so after any wheel in the
     column the splitter sat at `top:-364px` and the drag hit the artwork instead. */
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

/* The scrolling half of the column: everything but the handle. `min-height:0` is the flexbox line that
   lets it scroll at all (a flex item's default `min-height:auto` is its content, which grows instead of
   scrolling), and `scrollbar-width:thin` is the same measure the strip had. */
.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* The splitter (E27.1): a 6 px handle on the column's left edge, `cursor:col-resize`, and a wide
   invisible hit area (`::before`) so the 6 px is not the target. It is IN the column rather than a
   fourth grid column because the column's width is the state and the handle is a decoration on it; a
   grid column of its own would be chrome the fit input has to reason about.
   `touch-action:none` so dragging it on a touch screen does not scroll the column instead. */
.splitter {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--splitter-w);
  cursor: col-resize;
  background: transparent;
  touch-action: none;
  /* ABOVE the sections it belongs to. Every `.panel-section` is `position:relative` (the narrow-mode
     flyout hangs off it), and two positioned elements with `z-index:auto` stack in DOM ORDER — so the
     column's own children painted OVER the first child and the handle swallowed no pointer at all.
     One number, and it is above the headers but below the floats (`.swatch-menu` 35, dialogs higher). */
  z-index: 2;
  /* The 24 px WCAG floor is met by the hit area, not the visible line. */
}

.splitter::before {
  content: "";
  position: absolute;
  left: -9px;
  top: 0;
  bottom: 0;
  width: 24px;
}

.splitter:hover,
.splitter:active {
  background: var(--ring);
}

/* The scheme row (E27.1): the top bar's scheme controls, moved here unchanged. They stack — the
   `‹ name ›` row, the tabs under it, the `mix` slider under those — because the column is 340 px and
   the tabs already scroll sideways when a scheme collection outgrows it. */
#schemes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--pad-y) var(--pad-x);
  border-bottom: 1px solid var(--line);
  background: var(--chrome-2);
  min-width: 0;
}

/* The palette section's body is the grid, and the grid brings its own padding: a section body around
   it would be a frame around a frame. */
#right-panel .panel-section[data-section="palette"] .panel-body {
  padding: var(--pad-y) 6px;
}

/* The palette's header is a heading, not a button (E27.1 (a): the palette never closes), so it takes
   the cursor and the hover of a static label. */
#right-panel .panel-tab.pinned {
  cursor: default;
}

#right-panel .panel-tab.pinned:hover {
  background: var(--chrome);
}

/* One section: a header button, and (while open) its body below. `position:relative` is the
   anchor the narrow-mode flyout below hangs off. */
.panel-section {
  position: relative;
  flex: 0 0 auto;
}

/* The header: a full-width tab across the column. It reuses the shared `#right-panel button`
   baseline (24 px floor, font, cursor) and overrides just the edges: no side borders (the panel's
   own `border-left` is the panel's edge) and square corners so adjacent headers read as one stack.
   `width:100%` beats the shared rule's `flex:0 0 auto` because this file puts the panel rules
   AFTER the shared block. */
#right-panel .panel-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  /* E33.2: the header is paper with a rule under it, not a raised slab — the column is one sheet, and
     the only boxes in it are controls. A hover brings `--surface` up under the label, which is the one
     place a section says "this is clickable" now that the box is gone. */
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
}

#right-panel .panel-tab:hover {
  background: var(--face);
}

/* The letter. In wide mode it is a quiet mnemonic beside the name (the wireframe's letters live in
   the LEFT rail, but one letter per section is the ADR's own shorthand for the sections); below
   1100 px it is ALL that shows, so it grows a touch. */
#right-panel .panel-tab .glyph {
  flex: 0 0 auto;
  width: 1.2em;
  text-align: center;
  font: var(--mono-font);
  color: var(--ink-dim);
}

#right-panel .panel-tab .name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The collapse arrow: state is on `aria-expanded` (the a11y half); the glyph is the visible half.
   Both come from the SAME `vm.open`, so they cannot disagree. */
#right-panel .panel-tab .chev {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--ink-dim);
}

/* The body exists in the DOM only while the section is open (Leptos renders it conditionally), so
   there is no hidden state to keep in step with `aria-expanded`. */
#right-panel .panel-body {
  padding: var(--pad-y) var(--pad-x);
  border-bottom: 1px solid var(--line);
}

/* The shell's placeholder line, until M9.15/M9.16/M9.19/M11 fill their body (Color's is the editor
   below). */
#right-panel .panel-note {
  margin: 0;
  color: var(--ink-dim);
  font-size: 12px;
}

/* ------------------------------------------------- harmony tray (M9.15, E12.4)
   The Harmony body: one row per color rule, from the primary. THE RUST DECIDES EVERYTHING A ROW SAYS —
   the rule list, its swatches, how many slots it moves, whether it is clickable and why not
   (`controller::harmony_tray`) — and this block only places a label, a strip of plates and a count. A
   swatch's color arrives as `--c` written by Rust, the palette strip's `--sw` convention: a document
   color is not a stylesheet's to know, and `gray` is the fallback if a plate is ever built without it. */
#right-panel .harmony-tray {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#right-panel .harmony-base {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 2px;
  color: var(--ink-dim);
  font-size: 12px;
}

#right-panel .harmony-dot,
#right-panel .harmony-sw {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
  background: var(--c, gray);
}

#right-panel .harmony-slot {
  color: var(--ink);
  font-weight: 600;
}

/* A row is a button: label left, plates, count right. The border is transparent at rest so the lit row
   below grows no box — a tray that resized under the pointer would move the row the pointer is on. */
#right-panel .harmony-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
}

#right-panel .harmony-row:hover:not(:disabled) {
  background: var(--face);
}

/* THE LIT ROW IS THE PALETTE ON SCREEN. `aria-pressed` is core's `hovered` flag, so the row that glows
   and the scheme the artwork is wearing are one fact written by one field (M9.14's convention). */
#right-panel .harmony-row.hovered,
#right-panel .harmony-row:focus-visible {
  border-color: var(--ring);
  background: var(--face);
}

/* A greyed row IS its reason: `disabled` from core's `usable`, the words in its `title` from `note`. */
#right-panel .harmony-row:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#right-panel .harmony-rule {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#right-panel .harmony-swatches {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

#right-panel .harmony-count {
  flex: 0 0 auto;
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
}

#right-panel .harmony-note {
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 12px;
}

/* ------------------------------------------------- library shelf (M9.19, E12.5)
   The Library body: one row per bundled palette, each showing the fit THIS artwork would wear. As in the
   tray, THE RUST DECIDES EVERYTHING A ROW SAYS — the palette list, its swatches (already re-ordered into
   the strip's order by `controller::library`), how many slots the fit moves, whether the row is clickable
   and why not — and this block only places a name, a strip of plates and a count. A plate's color arrives
   as `--c` written by Rust, the palette strip's `--sw` convention: a document color is not a stylesheet's
   to know. Ten rows of 16 px plates is the tallest body in the panel, and `.right-panel` already scrolls
   its own axis, so the shelf needs no height rule of its own. */
#right-panel .library {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#right-panel .library-head {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 0 0 2px;
  color: var(--ink-dim);
  font-size: 12px;
}

#right-panel .library-count {
  color: var(--ink);
  font-weight: 600;
  font: var(--mono-font);
}

/* A row is a button: name left, plates, count right. The border is transparent at rest so the lit row
   below grows no box — a shelf that resized under the pointer would move the row the pointer is on. */
#right-panel .library-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
}

#right-panel .library-row:hover:not(:disabled) {
  background: var(--face);
}

/* THE LIT ROW IS THE PALETTE ON SCREEN. `aria-pressed` is core's `hovered` flag — and core's `lit` refuses
   a row whose scheme anchor is gone, so the row that glows and the fit the artwork is wearing are one
   fact written by one field (M9.14's convention, M9.19's anchor). */
#right-panel .library-row.hovered,
#right-panel .library-row:focus-visible {
  border-color: var(--ring);
  background: var(--face);
}

/* A greyed row IS its reason: `disabled` from core's `usable` (a fit that moves nothing), the words in its
   `title` from `note`. The starter's own palette greys on the starter. */
#right-panel .library-row:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#right-panel .library-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

#right-panel .library-swatches {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

#right-panel .library-sw {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
  background: var(--c, gray);
}

#right-panel .library-changes {
  flex: 0 0 auto;
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
}

/* ------------------------------------------------- My palettes (M10C.04, E35.4)
   The owner's OWN rows, stacked ABOVE the bundled shelf in the same section. Same visual grammar as the
   shelf (name, plates, a mono tail) so "yours" and "ours" read as one list of palettes rather than two
   widgets — with two differences that carry the whole item. The plates are the ENTRY's colors in the
   ENTRY's order (core sends them; nothing here fits), and the tail says how many colors and how long ago
   ("25 slots · edited 3 min ago"), because a saved palette that cannot say when it was saved is a file
   browser. The `⋮` opens the row's seven buttons inline; a modal for Apply would be a dialog you dismiss
   in order to do the thing you were already looking at. */
#right-panel .saved {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

#right-panel .saved-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

#right-panel .saved-title {
  font-size: 12px;
  font-weight: 600;
}

#right-panel .saved-count {
  flex: 0 0 auto;
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
}

#right-panel .saved-search {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 24px;
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  background: var(--bg);
  color: var(--ink);
  font-size: 11px;
}

#right-panel .saved-trash {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--ink-dim);
}

/* WCAG 2.5.8, and the smoke test's ruler: the box IS 24 px on both edges, so the toggle is a target
   and not a dot. `accent-color` keeps it the theme's ring rather than the browser's blue. */
#right-panel .saved-trash-box {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  accent-color: var(--ring);
  cursor: pointer;
}

#right-panel .saved-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#right-panel .saved-line {
  display: flex;
  align-items: center;
  gap: 4px;
}

#right-panel .saved-apply {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
}

#right-panel .saved-apply:hover:not(:disabled) {
  background: var(--face);
}

#right-panel .saved-apply:focus-visible {
  border-color: var(--ring);
  background: var(--face);
}

#right-panel .saved-apply:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#right-panel .saved-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

#right-panel .saved-swatches {
  display: flex;
  gap: 2px;
  flex: 0 1 auto;
  overflow: hidden;
}

#right-panel .saved-sw {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
  background: var(--c, gray);
}

#right-panel .saved-meta {
  flex: 0 0 auto;
  font: var(--mono-font);
  font-size: 10px;
  color: var(--ink-dim);
}

#right-panel .saved-menu-btn {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-4);
  background: transparent;
  color: var(--ink-dim);
  line-height: 1;
}

#right-panel .saved-menu-btn:hover,
#right-panel .saved-menu-btn[aria-expanded="true"] {
  border-color: var(--line);
  background: var(--face);
  color: var(--ink);
}

#right-panel .saved-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  padding-left: 8px;
}

#right-panel .saved-menu button {
  min-height: 24px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  background: var(--bg);
  color: var(--ink);
  font-size: 11px;
}

#right-panel .saved-export {
  display: inline-flex;
  gap: 2px;
}

#right-panel .saved-rename {
  width: 100%;
  min-height: 24px;
  padding: 2px 4px;
  border: 1px solid var(--ring);
  border-radius: var(--radius-4);
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
}

#right-panel .saved-version {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 1px 4px 1px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-4);
  background: transparent;
  font-size: 11px;
  color: var(--ink-dim);
}

#right-panel .saved-version:hover {
  border-color: var(--line);
  background: var(--face);
}

#right-panel .saved-empty,
#right-panel .saved-no-versions {
  margin: 0;
  font-size: 11px;
  color: var(--ink-dim);
}

#right-panel .library-note {
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 12px;
}

/* ------------------------------------------------- import box, offer, export (M9.20, ADR §7.7, §10.7)
   The foot of the same section: a box to paste a palette into, a file picker, the whole panel as a drop
   zone, the leftover offer, and four export buttons. As in the shelf above, THE RUST DECIDES THE WORDS AND
   THE COLORS: the offer's sentence, its plates and whether "Add them as slots" is clickable come off
   `XferVm`, and the four file names come off `ExportItemVm` — so the menu can say WHAT it is about to save
   without the markup knowing anything about formats.

   The textarea is a text field on purpose (`dom::text_entry_focused` then holds the chords back, which is
   what makes typing `b` into a palette paste box safe), it is 3 rows because a `.gpl` is a dozen lines, and
   it keeps its text after an import — a refusal a person has to re-paste through is a refusal twice.
   The file input stays VISIBLE rather than hidden behind a styled button: it is the one control whose own
   rendering says "this is a file", and it is keyboard-native for free. */
#right-panel .import-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

#right-panel .import-lead {
  color: var(--ink-dim);
  font-size: 11px;
}

#right-panel .import-field {
  width: 100%;
  min-height: 48px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--face);
  color: var(--ink);
  font: var(--mono-font);
  font-size: 11px;
  resize: vertical;
}

#right-panel .import-field:focus-visible {
  border-color: var(--ring);
}

#right-panel .import-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#right-panel .import-pick {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-dim);
  font-size: 11px;
  min-width: 0;
}

#right-panel .import-file {
  max-width: 140px;
  color: var(--ink-dim);
  font-size: 11px;
}

/* THE OFFER IS A QUESTION, SO IT LOOKS LIKE ONE: the sentence, the plates that have nowhere to go, and
   two answers. No timer and no animation — an offer that moves while it is being read was never made. */
#right-panel .import-offer {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding: 4px 6px;
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  background: var(--face);
}

#right-panel .offer-line {
  margin: 0;
  flex: 1 1 100%;
  color: var(--ink);
  font-size: 12px;
}

#right-panel .offer-swatches {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

#right-panel .offer-sw {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
  background: var(--c, gray);
}

#right-panel .offer-yes:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* The menu: four suffixes, because the format IS the difference and a scheme name belongs in the `title`
   the button already carries. */
#right-panel .export-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

#right-panel .export-lead {
  margin-right: 2px;
  color: var(--ink-dim);
  font-size: 11px;
}

#right-panel .export-item {
  flex: 0 0 auto;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--face);
  color: var(--ink);
  font: var(--mono-font);
  font-size: 11px;
}

#right-panel .export-item:hover {
  border-color: var(--ring);
}

/* ------------------------------------------------- knobs drawer (M9.16, ADR §7.7)
   Four thumbs over the WHOLE scheme — hue, lightness, chroma, temperature — and the two buttons that end
   the argument. As everywhere in this panel EVERY NUMBER AND EVERY WORD IS CORE'S: the four ranges, the
   home tick, the signed readouts, what Apply would do and why it is greyed all come off `KnobsVm`; this
   block only places a row and lights a thumb that is holding a change. The native control and its 24 px
   target come from the editor's `input[type="range"]` rule above, which is why there is no `appearance`
   business here. */
#right-panel .knobs-drawer {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* The scheme the knobs act on (there is no picker: the drawer tunes the picture on screen) and how many
   slots the four thumbs would move right now. */
#right-panel .knobs-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin: 0 0 2px;
}

#right-panel .knobs-scheme {
  color: var(--ink);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#right-panel .knobs-count,
#right-panel .knob-out {
  color: var(--ink-dim);
  font: var(--mono-font);
  font-size: 11px;
}

#right-panel .knob-out {
  text-align: right;
}

/* name | track | number. The label column is 6.5 em because "Temperature" is the widest thing core names
   a knob and a label that wrapped would move the track under a dragging finger. `minmax(0, 1fr)` is the
   same shrink that keeps the 200 px flyout honest. */
#right-panel .knob-row {
  display: grid;
  grid-template-columns: 6.5em minmax(0, 1fr) 3.6em;
  align-items: center;
  gap: 6px;
}

#right-panel .knob-name {
  color: var(--ink-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A knob off home is holding a change the document does NOT have — the fact Revert exists to forget — so
   its two words brighten. Ink, not a new hue: `--good` and `--bad` are contrast VERDICTS (M9.12) and a
   pending edit is neither, and the row's own geometry never moves, so a lit knob cannot shift the track
   under the finger. */
#right-panel .knob-row.moved .knob-name,
#right-panel .knob-row.moved .knob-out {
  color: var(--ink);
}

#right-panel .knobs-actions {
  display: flex;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

#right-panel .knobs-actions button {
  flex: 1 1 auto;
  min-width: 0;
}

/* A greyed Apply IS its reason (`KnobsVm::note` in its `title`), the tray's and the mix row's convention. */
#right-panel .knobs-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#right-panel .knobs-note {
  margin: 0;
  color: var(--ink-dim);
  font-size: 12px;
}

/* ------------------------------------------------- color editor header (M9.08, E12.2)
   The Color body: the `primary` slot's name and hex, its lock, and the two commands that reach for
   the artwork ("Select all N pieces", "Delete slot…"). THE RUST DECIDES EVERY NUMBER HERE EXCEPT
   THESE PIXELS: the fields' text, which button is disabled and what the lock says all come from
   `color_editor_vm`, and this block only says what a row, a plate and a red border look like. */
#right-panel .color-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Name, chip, lock: one row, and the FIELD is what stretches. `min-width:0` is the half that keeps a
   long role name from pushing the padlock out of a 240 px column (and a 200 px flyout below 1100 px). */
#right-panel .editor-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* The chip is the slot's COLOR, so it is the one place in the panel that may not be themed: it reads
   `--sw`, which the panel writes from core's `chip` — the preview while one is up, the committed color
   otherwise. `--sw` is the same name the strip's swatch uses, for the same reason. */
#right-panel .editor-chip {
  flex: 0 0 auto;
  width: var(--ctl-h);
  height: var(--ctl-h);
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-5);
  background: var(--sw, var(--face));
}

/* The two fields. The strip's `user-select:none` is the panel's own, and an `<input>` that will not
   let you select its text is broken, so the fields take selection back. */
#right-panel input {
  height: var(--ctl-h);
  min-width: 0;
  padding: 0 6px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-5);
  background: var(--chrome-2);
  color: var(--ink);
  font: var(--mono-font);
  user-select: text;
}

#right-panel .editor-name {
  flex: 1 1 auto;
  font: var(--ui-font);
}

#right-panel .editor-hex {
  width: 100%;
  letter-spacing: 0.04em;
}

/* R3 COL-05's edge, drawn: invalid text keeps the old value AND says so. The border and the ink are
   the ONLY things an unparseable string is allowed to touch — the artwork above it still shows the
   color the document actually has. */
#right-panel .editor-hex.bad {
  border-color: var(--bad);
  color: var(--bad);
}

/* `n (p%)`, the strip's own string, plus the reason the box is red. */
#right-panel .editor-usage {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin: 0;
  color: var(--ink-dim);
  font: var(--mono-font);
}

#right-panel .editor-usage .hint {
  color: var(--bad);
}

#right-panel .editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* The two verbs are the only labels that reach the artwork, so they wrap rather than truncate; the
   shared `#right-panel button` baseline gives them the 24 px floor. */
#right-panel .editor-select,
#right-panel .editor-delete {
  flex: 1 1 auto;
  white-space: nowrap;
}

/* The padlock is the strip's glyph (core's `LOCK_GLYPH`), so the same shape means the same fact in
   both places, and neither one is an emoji someone's font may not have. */
#right-panel .editor-lock {
  display: grid;
  place-items: center;
  padding: 0;
}

#right-panel .editor-lock svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ------------------------------------------------- color editor sliders (M9.09, ADR §7.7)
   Six thumbs under the header: OKLCH with the in-gamut chroma maximum marked, then RGB. As in the
   header, EVERY NUMBER IS CORE'S — the scale, the thumb, the readout and the tick's position all come
   off `SliderVm`; this block decides only what a row is and where a mark sits. */
#right-panel .editor-sliders {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

/* The space the row set reads in (`OKLCH` / `RGB`) sits above its three rows rather than beside them:
   two columns of six would leave 1 em for the track in a 240 px panel. */
#right-panel .slider-group,
#right-panel .slider-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#right-panel .slider-space {
  color: var(--ink-dim);
  font: var(--mono-font);
  font-size: 10px;
  letter-spacing: 0.08em;
}

/* letter | track | number. The number column is 3.6 em so `0.787`, `305°` and `255` all sit without
   shifting the track when one of them changes width. */
#right-panel .slider-row {
  display: grid;
  grid-template-columns: 1em minmax(0, 1fr) 3.6em;
  align-items: center;
  gap: 6px;
}

#right-panel .slider-label,
#right-panel .slider-out {
  color: var(--ink-dim);
  font: var(--mono-font);
  font-size: 11px;
}

#right-panel .slider-out {
  text-align: right;
}

/* The track's box is the tick's containing block, and `min-width:0` is what lets a long row shrink in
   the 200 px flyout instead of pushing the readout out of it. */
#right-panel .slider-track {
  display: block;
  position: relative;
  min-width: 0;
}

/* The native control, which is the reason `<input type=range>` is the widget: drag, keyboard, touch
   and screen-reader semantics for free, and no gesture of ours to get wrong. The shared
   `#right-panel input` rule gave every field a 24 px plate with a border and a mono font; a range is a
   TRACK, not a box, so it takes all of that back. `accent-color` is the one decoration the native
   thumb accepts, and it is themed to the panel's own ink. */
#right-panel input[type="range"] {
  width: 100%;
  /* The target is the whole track, not the thumb: 24 px, the same floor WCAG 2.5.8 makes the app's
     buttons keep and the same `--ctl-h` the fields above use. */
  height: var(--ctl-h);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  accent-color: var(--ring);
  cursor: ew-resize;
  appearance: auto;
}

/* ADR §7.7's "the in-gamut chroma maximum marked": a hairline on the C track at `--tick`, the fraction
   core measured (`SliderVm::gamut` over that axis's steps).
   The `8px … 16px` is the native thumb's own gutter: a range draws its value 0 at the LEFT EDGE OF THE
   THUMB and its maximum at the right one, so the usable run is the box minus a thumb. Without the
   gutter the mark would sit up to a thumb's width off the color it names, which is the entire point of
   drawing it. `pointer-events:none` keeps the hairline from being a thing the finger can hit. */
#right-panel .gamut-tick {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: calc(8px + (100% - 16px) * var(--tick, 0));
  width: 2px;
  margin-left: -1px;
  background: var(--ink-dim);
  opacity: 0.8;
  pointer-events: none;
}

/* ------------------------------------------------- color editor Okhsl square (M9.11, ADR §7.7)
   A third reading of the same slot: `s` across — LEFT edge gray, RIGHT edge the sRGB gamut AT THAT
   LIGHTNESS, which is the whole reason Okhsl is the space a picker wants — and `l` up. As in the two
   blocks above, EVERY NUMBER IS CORE'S: the twelve band gradients, the crosshair's two fractions and
   the readout all come off `PickerVm`. This block decides what a band and a crosshair look like. */
#right-panel .editor-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* The box the pointer and the keyboard talk to. `touch-action:none` is not a nicety: without it the
   first drag sideways becomes a panel scroll and the gesture is lost mid-color, and `user-select` is
   the band of text a drag would otherwise pull behind it. */
#right-panel .picker-field {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 108px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

/* The one thing `PickerVm::active` changes: the square is being dragged, so its border says "grabbed".
   Not the crosshair and not the bands — a drag must not repaint what it is painting over. */
#right-panel .picker-field.active {
  border-color: var(--ring);
}

/* The square is Tab-reachable and it moves a color, so the focus ring is not decoration (WCAG 2.4.7).
   `:focus-visible` rather than `:focus`: a click that aims the crosshair should not also paint a ring
   over the color being aimed at. */
#right-panel .picker-field:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off-tight);
}

/* Twelve EVEN bands, `flex: 1 1 0` rather than a height each, so the square is the twelve rows core
   drew in the order core drew them (TOP first) whatever height the panel is today.
   Each band carries the three points core says are EXACT — `--a` the neutral point (`s = 0`), `--b` the
   kink of the `s` -> chroma mapping, `--c` the gamut edge (`s = 1`) — and THIS is where they become a
   gradient: a horizontal ramp with the middle stop pinned at `--mid`, the field's copy of `OKHSL_MID`
   (0.80 across, not the 0.50 a three-stop gradient would guess). Between the stops the ramp
   interpolates; that is the one approximation the square makes, twelve times over a 108 px box, at a
   hue the crosshair cannot change mid-drag. */
#right-panel .picker-band {
  flex: 1 1 0;
  min-height: 0;
  background-image: linear-gradient(90deg, var(--a) 0%, var(--b) calc(var(--mid) * 100%), var(--c) 100%);
}

/* The crosshair: `--x`/`--y` are core's two fractions, with the one inversion (`l` grows up, a CSS
   offset grows down) already made in `PickerVm::y`, so this is a position and not an arithmetic
   exercise. White on black is the only theme-proof outline over a field that contains every color in
   the document, and the crosshair draws NO color of the artwork — it is UI over it.
   `pointer-events:none` keeps it from being the thing the finger hits instead of the field. */
#right-panel .picker-cross {
  position: absolute;
  left: calc(var(--x, 0) * 100%);
  top: calc(var(--y, 0) * 100%);
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border: 2px solid var(--thumb-line);
  border-radius: var(--round);
  box-shadow: var(--thumb-shadow);
  pointer-events: none;
}

#right-panel .picker-out {
  color: var(--ink-dim);
  font: var(--mono-font);
  font-size: 11px;
  text-align: right;
}

/* M9.12's contrast badges (ADR §7.7's "WCAG badge vs the background slot and the other active slot,
   APCA behind the feature"). The NUMBER, the neighbour's name, the tone and the sentence are all
   core's (`ContrastVm`); this rule only says what a `fail` looks like. No inline style and no document
   color: a badge's colors are THEME colors, so `smoke.spec.js`'s inline-style allowlist is untouched. */
#right-panel .editor-contrast {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 6px;
}

#right-panel .contrast-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
}

#right-panel .contrast-badge .contrast-num {
  color: var(--ink);
  font-weight: 600;
}

/* The tone is core's `WcagGrade` (AA 3:1 / AAA 4.5:1 for a large area), never a stylesheet threshold. */
#right-panel .contrast-badge.fail {
  border-color: var(--bad);
}

#right-panel .contrast-badge.fail .contrast-num {
  color: var(--bad);
}

#right-panel .contrast-badge.aaa .contrast-num,
#right-panel .contrast-badge.aa .contrast-num {
  color: var(--good);
}

/* APCA is the OPTIONAL second badge (R2 §5.2): dimmer, and named beta on its face, so nobody reads it
   as WCAG. It only exists in a build compiled with `feature = "apca"`. */
#right-panel .contrast-badge.apca {
  border-style: dashed;
}

#right-panel .contrast-badge.apca .contrast-num {
  color: var(--ink-dim);
  font-weight: 400;
}

/* No second color to measure (a one-role palette, or a grid that wears exactly one): the dash is the
   honest answer, and the panel never invents a ratio. */
#right-panel .contrast-none {
  color: var(--ink-dim);
  font: var(--mono-font);
  font-size: 11px;
}

/* M9.07's collapse (ADR §11 + product-25: below 1100 px the right panel becomes an icon-tab
   column). The column narrows to `--panel-tab-w`, the name and chevron go away, and an OPEN
   section's body flies out as a card to the LEFT of its tab — the panel's content is still
   reachable, it just stops eating the stage. It is pure CSS over the same five open bits, so a
   `UiSettings` that says "Knobs open" means the same thing at every width. `overflow:visible` is
   what lets the card escape the (now 40 px) column without clipping. */
@media (max-width: 1099.98px) {
  /* E27.1's narrow layout: the column is `--panel-narrow-w` (200 px, `theme.css`), the palette stays a
     GRID in it at `--grid-narrow-swatch` (32 px), and every OTHER section's body goes back to being a
     flyout off its icon tab (the rules below, unchanged since M9.07). The splitter goes away: a column
     the user cannot size has no handle. */
  #right-panel {
    overflow: visible;
  }
  /* …and the scroller opens up with it: the icon-tab column shows its tabs and lets an open section's
     FLYOUT leave the column, which a `overflow-y:auto` ancestor would clip. */
  .panel-scroll {
    overflow: visible;
  }
  .splitter {
    display: none;
  }
  #palette {
    /* …and the narrow plate, which is `--grid-narrow-swatch` written over `--swatch` by `theme.css`. */
    max-height: 40vh;
  }
  /* …but the palette's body stays IN the column: E27.1 leaves the palette on screen at every width, so
     it is `position:static` and shown whatever the hover state is. */
  #right-panel .panel-section[data-section="palette"] .panel-body {
    display: block;
    position: static;
    width: auto;
    padding: 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  #schemes .scheme-tab,
  #schemes .scheme {
    font-size: 11px;
  }
  #right-panel .panel-tab {
    justify-content: center;
    padding: 0;
  }
  #right-panel .panel-tab .name,
  #right-panel .panel-tab .chev {
    display: none;
  }
  #right-panel .panel-tab .glyph {
    width: auto;
    font-size: 14px;
    color: var(--ink);
  }
  /* An open body is a POPOVER here, not a second column. M9.07 shipped the flyout always-shown, and a
     one-line placeholder got away with it; M9.08's color editor is ~150 px tall, five of those over
     the stage is a wall the pointer cannot get past (it swallows the wheel, the click and the stroke
     over a third of the artwork). So the card belongs to the tab it explains: it is there while that
     section is hovered, it stays while a field inside it has the focus (which is what lets you type in
     a flyout), and it is GONE otherwise, so the stage is the stage.
     `right:100%`, not `calc(100% + 8px)`: an 8 px air gap is 8 px of STAGE between the tab and its own
     card, and crossing it would drop the hover and slam the card shut on the way in. */
  #right-panel .panel-body {
    display: none;
    position: absolute;
    top: 0;
    right: 100%;
    width: 200px;
    padding: var(--pad-y) var(--pad-x);
    border: 1px solid var(--line);
    border-radius: var(--radius-8);
    background: var(--face);
    box-shadow: var(--shadow);
    z-index: 20;
  }
  #right-panel .panel-section:hover .panel-body,
  #right-panel .panel-section:focus-within .panel-body {
    display: block;
  }
}

/* ---------------------------------------------------------------- status bar */

#status {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 0 var(--pad-x);
  background: var(--chrome-2);
  color: var(--ink-dim);
  border-top: 1px solid var(--line);
  font: var(--mono-font);
  user-select: none;
  touch-action: none;
}

/* The ellipsis belongs on the TEXT, not the bar, so the `×` keeps its place at the right edge however
   long the seed or the hint is. `min-width:0` is what makes a flex item ellipsise at all. */
#status .status-line {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The hint's `×`: 24 px of target around a one-character glyph (WCAG 2.5.8 again), with the glyph
   itself big enough to see. */
#status .dismiss {
  font-size: 14px;
  line-height: 1;
}

/* ---------------------------------------------------------------- toast */

/* The one FLOATING surface left, and it must stay out of flow: a grid item there would resize the
   stage row when a message arrives, and that row is E07's fit input, so A TOAST WOULD RESIZE THE
   ARTWORK. It hangs below the top bar with `pointer-events:none` on the whole subtree — a message
   that eats a `pointerdown` blocks the drawing it is complaining about. */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + 8px);
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  justify-content: center;
  max-width: min(92vw, 44em);
  pointer-events: none;
  user-select: none;
}

.toast .toast-msg {
  display: block;
  padding: 8px 14px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-8);
  background: var(--face);
  color: var(--ink);
  box-shadow: var(--shadow);
  font: var(--toast-font);
  text-align: center;
}

/* ---------------------------------------------------------------- motion */

/* ADR §11: reduced motion pauses the marching ants. The animation itself is core's
   (`render::style::FIXED_RULES`, which the exporters share); this is the app's override, and the id
   is what wins it against the scene's own `.ants` rule. */
@media (prefers-reduced-motion: reduce) {
  #scene .ants {
    animation: none;
  }
}

/* ------------------------------------------------------- the command palette (M8.22) */

/* ADR §6.7's palette, and ADR §11's rule that the chrome's geometry lives HERE: a box floated over
   the artwork, not a fifth grid row. The rows are `body`'s business (four of them, E07's fit
   measures the stage), so the palette takes none: it is `position:fixed`, centred on the top third,
   and the artwork stays exactly where it was while you search.

   `.cmd-backdrop` is a sibling rather than a background on the box: a click on it closes the palette,
   and a click INSIDE the box must not, which is one rule per element instead of a target test. It
   dims the artwork without hiding it — the palette is not modal (`aria-modal="false"`, and
   `the_command_palette_is_focused_not_modal` has pinned that since M2.24). */
.cmd-palette {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.cmd-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim-35);
}

.cmd-box {
  position: relative;
  margin-top: 12vh;
  width: min(560px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-10);
  background: var(--face);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.cmd-input {
  height: var(--ctl-h);
  padding: 0 8px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome-2);
  color: var(--ink);
  font: var(--ui-font);
}

/* The list is the scroll box, and its height is a count of ROWS rather than a viewport fraction:
   six and a half rows is what makes the lit one read as "in the middle of a list", and a search with
   two answers does not open a hole in the chrome. `overscroll-behavior: contain` keeps a wheel over
   the list from
   scrolling the artwork behind it. */
.cmd-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: calc(6.5 * 34px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cmd-row {
  display: grid;
  grid-template-columns: 20px minmax(96px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  /* 34 px: over WCAG 2.5.8's 24 px floor with a pointer target the height of the whole row. */
  min-height: 34px;
  padding: 2px 8px;
  border-radius: var(--radius);
  cursor: pointer;
}

.cmd-row.lit,
.cmd-row:hover {
  background: var(--chrome-2);
  outline: 1px solid var(--ctl-line);
}

.cmd-icon {
  font: var(--ui-font);
  text-align: center;
}

.cmd-name {
  font: var(--ui-font);
  font-weight: 600;
  white-space: nowrap;
}

.cmd-help {
  font: var(--ui-font);
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The gutter: the chord that means the same thing as this row (core's `chord_label`), mono so the
   modifiers line up down the list. A palette-only command prints nothing here and the column
   collapses, which is the answer to "why is there no key on this row". */
.cmd-key {
  font: var(--mono-font);
  color: var(--ink-dim);
  white-space: nowrap;
}

.cmd-count {
  margin: 0;
  padding: 2px 8px 0;
  font: var(--mono-font);
  color: var(--ink-dim);
}

.cmd-count.hidden {
  visibility: hidden;
}

/* --------------------------------------------------------------------------
   M8.23: THE CHEAT SHEET — `Shift+/`, the second float over the artwork
   --------------------------------------------------------------------------
   The SAME three pieces as the palette: a fixed layer, a backdrop that leaves when clicked, and a
   box. `.cmd-box` is reused for the box's face (border, colour, radius, shadow) because ADR §11
   draws ONE kind of floating box; what `.sheet-box` changes is only the size, since 89 rows in one
   column is a scroll you read by hunting.

   Like the palette it is `position: fixed` and takes NO grid area, so `#viewport`'s measured box —
   E07's fit input — is exactly as big with the page open as with it closed: a reference card must not
   resize the artwork behind it.

   The z-index is the palette's, and that is the whole story of two floats: core keeps them from being
   open at once (`cheat_sheet` and `cmd_palette` close each other on the way in), so nothing here has
   to decide which of two overlays paints on top.
*/

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim-35);
}

/* Wider than the palette and shorter against the viewport: the page wants three columns and it wants
   the foot rule visible without scrolling to the end of the last one. */
.sheet-box {
  width: min(1080px, calc(100vw - 32px));
  margin-top: 6vh;
  max-height: 88vh;
  gap: 6px;
}

.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 2px 4px 0;
}

.sheet-title {
  margin: 0;
  font: var(--ui-font);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

/* The count line, so the page says how big it is and a filtered future version can say the same. */
.sheet-sub {
  flex: 1 1 auto;
  margin: 0;
  font: var(--mono-font);
  font-size: 12px;
  color: var(--ink-dim);
}

/* The `×` is a control like every other in the chrome, and takes the shared rule above (added to its
   selector list for exactly this); what is left here is where it sits. */
.sheet-close {
  flex: 0 0 auto;
  align-self: center;
  line-height: 1;
}

/* The scroll box. Columns are `auto-fill` rather than a count: the page is three columns on a laptop,
   two on a small window, and one on a phone, and the sections keep their reading order either way.
   `overscroll-behavior: contain` keeps a wheel over the page from moving the artwork behind it. */
.sheet-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-content: start;
  gap: 10px 24px;
  padding: 0 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-part-title {
  margin: 0 0 2px;
  font: var(--mono-font);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--ctl-line);
}

.sheet-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Two lines per command: keys and name, then the sentence. Nothing is truncated — the palette can
   afford an ellipsis because its help is a repeat of what the row already said in the field above it;
   here the sentence is the only place the command is explained. */
.sheet-row {
  display: grid;
  grid-template-columns: minmax(96px, auto) minmax(0, 1fr);
  column-gap: 8px;
  align-items: baseline;
  min-height: 20px;
  font: var(--ui-font);
  font-size: 13px;
}

.sheet-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: flex-end;
}

/* The chord chip: mono, so a column of them lines up, and boxed so `Shift+←` reads as one key
   combination rather than as a path. */
.sheet-key {
  padding: 0 4px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius-4);
  background: var(--chrome-2);
  font: var(--mono-font);
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
}

.sheet-name {
  font-weight: 600;
  color: var(--ink);
}

.sheet-help {
  grid-column: 1 / -1;
  color: var(--ink-dim);
  font-size: 12px;
  line-height: 1.25;
}

.sheet-foot {
  margin: 0;
  padding: 2px 8px 0;
  font: var(--mono-font);
  font-size: 12px;
  color: var(--ink-dim);
}

/* The box takes the focus when the keyboard opens it (so `Escape` has somewhere to land), and it says
   so with the chrome's OWN ring: 2 px of `--ring`, offset, and `:focus-visible` only, so a mouse click
   on the page is not decorated. Without this the user-agent default draws it instead, and the float is
   the one place in the app where "the keyboard is in here" needs no decoration to be true — it needs
   the decoration. */
#sheetbox:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--ring-off);
}

/* ---------------------------------------------------------------- swatch swap mark + swatch menu (M9.05) */

/* The swap target (E10.12 row 6): the ring round the plate a `Ctrl+drag` would trade places with.
   Same measure as `.caret` — core prints the strip POSITION as `--swap`, the arithmetic lives here —
   and the same two rules that make the caret safe: it is a positioned SIBLING of the row's swatches
   (never inserted among them, which would rebuild the swatch under the finger and drop the pointer
   capture) and `pointer-events: none`, so the mark can never become the thing the next `elementFromPoint`
   reports. `--ring`, not the document's color: this is chrome pointing at chrome, and it has to read
   over a black plate and a white one alike. */
.swap-mark {
  position: absolute;
  top: calc(var(--pad-y) + var(--swap-row, 0) * (var(--swatch) + var(--sw-gap)));
  left: calc(var(--pad-x) + var(--swap-col, 0) * (var(--swatch) + var(--sw-gap)));
  height: var(--swatch);
  width: var(--swatch);
  box-sizing: border-box;
  border: 3px solid var(--ring);
  border-radius: var(--radius-10);
  pointer-events: none;
}

/* The swatch menu (E10.12's last row): a float, not a `<dialog>` — the artwork stays visible and
   clickable under a menu about one of its colors. The z-index is the palette's and the sheet's, and
   core keeps two of them from being up at once; the Confirm that follows a destructive row IS modal,
   and it lands above this on its own merits. */
.swatch-menu {
  position: fixed;
  inset: 0;
  z-index: 35;
}

.menu-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim-25);
}

/* The box sits ABOVE the swatch it belongs to. SINCE M15U.01 the anchor is the PLATE's own page box
   (`--at-x`/`--at-y`, measured by `dom::plate_anchor`) rather than a seat along one row: the grid is
   two-dimensional, it scrolls inside a column the user sizes, and no arithmetic of this file can know
   where plate 17 is drawn. `clamp` keeps it on screen at both ends - a menu off the right edge, or one
   whose plate could not be measured, is a menu nobody can read. */
.menu-box {
  position: absolute;
  bottom: clamp(8px, calc(100vh - var(--at-y, 0) * 1px + 8px), calc(100vh - 8px));
  left: clamp(8px, calc(var(--at-x, 0) * 1px), calc(100vw - 280px));
  max-width: 264px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
  box-shadow: var(--menu-shadow);
}

.menu-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 2px 4px;
  font-size: 12px;
  color: var(--ink-dim);
}

.menu-chip {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-3);
  background: var(--sw, gray);
  outline: 1px solid var(--line);
}

.menu-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 2px;
}

.menu-row {
  min-height: var(--ctl-h);
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.menu-row:hover {
  background: var(--chrome);
}

.menu-row.disabled {
  color: var(--ink-dim);
  opacity: 0.5;
  cursor: default;
}

.menu-field {
  height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

/* The Confirm (E05, E10.8's first rung). A NATIVE `<dialog>`: `showModal` is the focus trap, the inert
   background and the `Escape`, which is why the app has no code for any of the three. The palette's
   tokens, because a question is chrome, and `::backdrop` is the browser's own dimming rather than a
   div. */
#confirm {
  margin: auto;
  padding: 0;
  max-width: 26rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#confirm::backdrop {
  background: var(--scrim-45);
}

.confirm-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.confirm-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.confirm-body {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-actions button {
  min-height: var(--ctl-h);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.confirm-ok {
  border-color: var(--ring) !important;
  font-weight: 600;
}

/* The recolor-by-mapping dialog (M9.21, ADR §7.5's last sentence). A second NATIVE `<dialog>`, so it
   borrows the Confirm's frame — `::backdrop`, the focus trap, the `Escape` — and adds the one thing the
   Confirm never needed: two rows of COLOR plates. They are the palette's own colors as inline
   `background`, never the chrome tokens: a swatch that wore `--chrome` would be a lie about the artwork.
   Two rows because the map has a direction (from → to) and one row of eight-plus-eight is the smallest
   honest picture of it. */
#remap {
  margin: auto;
  padding: 0;
  max-width: 30rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#remap::backdrop {
  background: var(--scrim-45);
}

.remap-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.remap-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.remap-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.remap-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* The two rows share their label column, so `from` and `to` line up and the plates read as a mapping
   rather than as two unrelated strips. */
.remap-row {
  display: grid;
  grid-template-columns: 3rem repeat(8, minmax(0, 1fr));
  align-items: center;
  gap: 4px;
}

.remap-row-label {
  font-size: 11px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.remap-cell {
  position: relative;
  display: block;
}

.remap-plate {
  display: block;
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-5);
  cursor: pointer;
  padding: 0;
}

/* The picked FROM plate wears the app's own ring (the strip's primary/secondary rings use it too), and
  the plate the picked row currently points at wears it in the TO row: two ends of one arrow. */
.remap-plate.picked,
.remap-plate.target {
  border-color: var(--ring);
  box-shadow: var(--inset-ring);
}

.remap-plate.moved {
  border-style: dashed;
}

.remap-clear {
  position: absolute;
  top: -6px;
  right: -4px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-8);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}

.remap-line {
  margin: 0;
  min-height: 16px;
  font-size: 12px;
  color: var(--ink-dim);
}

.remap-sel {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.remap-sel-line {
  margin: 0;
  font-size: 11px;
  color: var(--ink-dim);
}

.remap-sel-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 7rem;
  overflow: auto;
}

.remap-sel-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-11);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

/* The plate is the ARTWORK's color, so it is painted from the same `--sN` the canvas reads — one source
   of truth, and it follows a scheme switch, a scrub or an undo without this panel knowing about it. */
.remap-sel-plate {
  width: 12px;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-3);
}

.remap-sel-count {
  color: var(--ink-dim);
}

.remap-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.remap-actions button {
  min-height: var(--ctl-h);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.remap-actions button:disabled {
  color: var(--ink-dim);
  cursor: default;
  opacity: 0.6;
}

.remap-apply:not(:disabled) {
  border-color: var(--ring) !important;
  font-weight: 600;
}

/* ------------------------------------------------------ layers panel (M9L.07 → M15L.01, E18.10 + E30.1)
   THE BODY OF THE PANEL'S SIXTH SECTION. As everywhere else in the inspector, THE RUST DECIDES WHAT A ROW
   SAYS AND WHAT IT MEANS: `controller::vm::layers_vm` hands over the rows TOP FIRST (the reverse of
   `Document::layers`, which is bottom-first because that is what a painter means by a stack), each one's
   name, flags, blend, percent, thumbnail, selection mark and whether the footer's buttons can be pressed
   at all. This block places them; the row order is the one thing a stylesheet must never "fix" with
   `column-reverse`, because a reversed list and a reversed model are two ways to be wrong.
   E30.1 moved the two numbers ONTO THE ROW ("the blend mode as an inline dropdown, opacity as a scrub
   field") and the panel's verbs into its FOOTER, because the owner styles SEVERAL layers at once and a
   header that answers only the active one makes that a click, a change, a click back, a change. */
#right-panel .layers {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#right-panel .layers-foot {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* The three stack buttons: `+`, `⧉`, `×`. Square, `--ctl-h` tall (WCAG 2.5.8's floor, and 44 px in the
   coarse block below), and greyed by core's `can_add` / `can_delete` rather than hidden — a `×` that is
   there but disabled teaches that the last layer is a different kind of thing. */
#right-panel .layers-foot button,
#right-panel .layer-eye,
#right-panel .layer-lock,
#right-panel .layer-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

#right-panel .layers-foot button:hover:not(:disabled),
#right-panel .layer-eye:hover,
#right-panel .layer-lock:hover,
#right-panel .layer-more:hover {
  background: var(--face);
  border-color: var(--ring);
}

#right-panel .layers-foot button:disabled {
  color: var(--ink-dim);
  opacity: 0.45;
  cursor: not-allowed;
}

/* The blend `<select>`: the 16 CSS keywords in E18.3's order, spelled exactly as CSS spells them, so a
   word looked up in a reference is the word on screen. It takes the row's remaining width. */
#right-panel .layer-blend {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--ctl-h);
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}

/* THE SCRUB FIELD (E30.1): a percent you drag sideways and can click to type. It is a text field rather
   than a range input because E30.1 asks for both gestures on one control, and the pointer half lives in
   `panels/layers.rs` (`ScrubDrag`), not in the browser: the pointer is captured to `#layers` so the drag
   survives the row being re-rendered under it, every move sends one `LayerOpacitySample` (a preview) and
   the release sends ONE `LayerOpacityEnd` — so a drag and a typed number are each ONE undo step
   (`opacity_scrub_one_entry`). The percent beside it is the same number while the field has no caret. */
#right-panel .layer-scrub {
  flex: 0 0 3.2em;
  min-width: 3em;
  min-height: var(--ctl-h);
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  background: var(--chrome);
  color: var(--ink);
  font: var(--mono-font);
  font-size: 11px;
  text-align: right;
  cursor: ew-resize;
  touch-action: none;
}

#right-panel .layer-scrub:focus {
  cursor: text;
}

/* E33.2's four uses of the accent, and a scrub field that has the KEYBOARD is the keyboard ring —
   `:focus-visible`, spelled like every other focus ring in the app, so the lint that counts them
   (`accent-uses-only-four`) sees one carrier and not five. */
#right-panel .layer-scrub:focus-visible {
  border-color: var(--focus-ring);
  outline: none;
}

/* The list. Its OWN scroll box: 32 layers (E18.1's `MAX_LAYERS`) at 28 px is a thousand pixels, and the
   panel's axis would push the Color section off the top of the inspector. */
#right-panel .layer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 40vh;
  overflow-y: auto;
}

/* A ROW IS THE LAYER: eye, lock, name, `×`, and the whole row is the drag handle (`draggable="true"`,
   E18.10's "drag a row = `Move`"). The border is transparent at rest so the lit row grows no box — a list
   that resized under the pointer would move the row the pointer is on mid-drag. */
#right-panel .layer-row {
  display: flex;
  align-items: center;
  /* A ROW NOW CARRIES EVERYTHING E30.1 ASKS FOR (thumb, two flags, name, count, blend, opacity, menu),
     which is more than a 260 px column can lay on one line — so the controls WRAP rather than shrink
     into a 30 px select nobody can aim at. A two-line row is a taller row; the list scrolls. */
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}

#right-panel .layer-row:hover {
  background: var(--face);
}

/* THE LIT ROW IS THE LAYER THE TOOLS WRITE (E18.5's `active_layer`, marked by `data-active` from core and
   by nothing else). */
#right-panel .layer-row.active {
  border-color: var(--ring);
  background: var(--face);
}

/* The row under a drag is HALF A ROW: the pointer is carrying it somewhere, and the ghost of where it
   came from is the thing to leave on screen. `dragging` is core's `LayerSurface::drag`, so a drop, a
   `dragend` in the gutter and a document boundary all clear the same one field. */
#right-panel .layer-row.dragging {
  opacity: 0.5;
  border-color: var(--ring);
  border-style: dashed;
}

/* A hidden layer is DIM, not gone: its pieces still count in `usage_counts` (E18.1) and its eye is one
   click from bringing it back. A locked layer keeps the padlock as its whole signal — the glyph is the
   state, and `aria-pressed` says it to a screen reader too. */
#right-panel .layer-row.off {
  opacity: 0.5;
}

#right-panel .layer-row.locked {
  cursor: default;
}

#right-panel .layer-row.locked .layer-name {
  color: var(--ink-dim);
}

/* THE ROW'S THUMBNAIL (E30.1): the layer ALONE, painted by core (`vm::layer_thumb`) in the active
   scheme, in its own little `<svg>`. The `viewBox` is the whole layer, so `--layer-thumb` square is
   every layer's own aspect and one size fits a 16x20 sheet and a 4x4 one alike. It is `aria-hidden`
   because the name beside it says what the row is, and the picture adds what the eye cannot be asked
   to read out. */
#right-panel .layer-thumb {
  flex: 0 0 var(--layer-thumb);
  width: var(--layer-thumb);
  height: var(--layer-thumb);
  border: 1px solid var(--rule);
  border-radius: var(--radius-4);
  background: var(--paper);
}

/* TWO FACTS, TWO MARKS (E30.1): `.active` is the row the tools WRITE, `.sel` is a row in the
   multi-select set a merge would take. A selected row is not lit, it is HALOED — a dashed rule of the
   ink color, so the one solid ring in the list stays the paint target's. */
#right-panel .layer-row.sel {
  border-color: var(--line);
  border-style: dashed;
  background: var(--face);
}

#right-panel .layer-row.active.sel {
  border-style: solid;
}

/* E30.1's instance count, "when non-zero". Zero shows nothing at all, which is why the slot costs
   nothing until M15S puts instances on a layer. */
#right-panel .layer-count {
  flex: 0 0 auto;
  min-width: 1.6em;
  padding: 0 3px;
  border-radius: var(--radius-4);
  background: var(--face);
  color: var(--muted);
  font: var(--mono-font);
  font-size: 10px;
  text-align: center;
}

/* The row's `⋯` menu (E30.1). It is a CHILD of the row it belongs to, absolutely placed under it, so
   there is no portal to keep aimed at the right layer and the row's own `position: relative` is the
   anchor; the row menu's items are the SAME actions the footer and the chords send. */
#right-panel .layer-row {
  position: relative;
}

#right-panel .layer-menu {
  position: absolute;
  top: calc(100% - 2px);
  right: 4px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 132px;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--menu-shadow);
}

#right-panel .layer-menu button {
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius-4);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

#right-panel .layer-menu button:hover {
  background: var(--face);
}

/* A merge item the stack cannot honour (E30.2's `>= 2`): greyed, and it answers nothing. The op refuses
   again, so a caller that ignores the grey gets a toast rather than a surprise. */
#right-panel .layer-menu button:disabled {
  color: var(--ink-dim);
  background: transparent;
  cursor: default;
}

/* THE FOOTER (E30.1): the panel's verbs. They take the place E18.10 gave a HEADER, and they act on the
   ACTIVE layer — the merge rows M15L.03 adds will act on the SET, which is why they land here rather
   than up among the per-row numbers. */
#right-panel .layers-foot {
  display: flex;
  align-items: center;
  gap: 4px;
}

#right-panel .layers-foot-sep {
  flex: 0 0 auto;
  width: 1px;
  align-self: stretch;
  background: var(--rule);
}

#right-panel .layer-contents,
#right-panel .layer-clear {
  font-size: 11px;
  padding: 0 6px;
}

/* ------------------------------------------------ E30.1's TWO COLUMNS (≥ 1440 px)
   E27.1's column is ONE scrolling column; E30.1 adds a second half to it at a window width of 1440 px or
   more — Palette | LAYERS, each with its OWN scroll. THE DOM IS THE SAME AT EVERY WIDTH: `right_panel`
   renders the main half and the side half (core's `PanelSectionVm::side`, and only `Layers` has it), and
   `order` on every section carries E27.1's order across the flattening. Below 1440 px BOTH halves are
   `display: contents`, so each `.panel-section` is a flex item of `.panel-scroll` again and the column
   scrolls as one — one DOM, one order, one scroller, and no resize handler that can lag a frame. */
#right-panel .panel-main,
#right-panel .panel-side {
  display: contents;
}

#right-panel .panel-activity {
  order: 1000;
}

/* Flattened (below 1440 px), the side half's Layers section sits where E27.1 drew it — after the tool
   options, before the detail editors — and the detail editors step past it. THREE numbers in this file
   stand for E27.1's order, and they are not the authority: `right_column_sections_order` pins CORE's
   list, and the browser's own reading of the column (`right column: E27.1 order…` in `smoke.spec.js`,
   which sorts the headers by where they ARE) fails the page if these two rules ever drift from it. */
#right-panel .panel-side > .panel-section {
  order: 3;
}

#right-panel .panel-main > .panel-section[data-section="color"],
#right-panel .panel-main > .panel-section[data-section="harmony"],
#right-panel .panel-main > .panel-section[data-section="knobs"],
#right-panel .panel-main > .panel-section[data-section="library"],
#right-panel .panel-main > .panel-section[data-section="generators"] {
  order: 4;
}

#right-panel .panel-activity:empty {
  display: none;
}

@media (min-width: 1440px) {
  /* The column takes TWO of itself: the user's `--panel-w` for the palette half, another for the
     layers half, and the splitter once (`--panel-wide-w`, `theme.css`). The stage keeps what is left,
     and `#viewport`'s box is still the fit input, so the artwork refits exactly as it does when the
     splitter moves. */
  body {
    grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--panel-wide-w);
  }

  #right-panel .panel-scroll {
    flex-direction: row;
    overflow: hidden;
  }

  #right-panel .panel-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  #right-panel .panel-side {
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--panel-w);
    min-width: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    border-left: 1px solid var(--rule);
  }

  /* The side half's rows get the column to themselves: the list's own 40 vh box would fight a column
     that scrolls, so the layers list gives its scroll back to the half it lives in. */
  #right-panel .panel-side .layer-list {
    max-height: none;
    overflow-y: visible;
  }
}

#right-panel .layer-eye[aria-pressed="false"] {
  color: var(--ink-dim);
}

#right-panel .layer-lock[aria-pressed="true"] {
  border-color: var(--ring);
}

#right-panel .layer-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

/* The rename box is UNCONTROLLED (M8.22's caret rule, the editor's name field): it is born holding the
   name and core writes it never — `Enter` or the blur commits, `Escape` throws it away. */
#right-panel .layer-name-field {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--ctl-h);
  padding: 2px 4px;
  border: 1px solid var(--ring);
  border-radius: var(--radius-4);
  background: var(--face);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}

/* Coarse pointers get the 44 px floor everywhere else gets it; the list keeps its own scroll box so a
   touch panel with 32 layers is still a scroll rather than an infinitely tall column. */
@media (pointer: coarse) {
  #right-panel .layers-foot button,
  #right-panel .layer-eye,
  #right-panel .layer-lock,
  #right-panel .layer-more {
    min-width: 44px;
    min-height: 44px;
  }

  #right-panel .layer-row {
    min-height: 48px;
  }
}

/* The export dialog (M10.02, ADR §10.1, E13.1). A third NATIVE `<dialog>`, so it borrows what the
   Confirm and the remap box already proved: `::backdrop` for the dim, `dialog :focus-visible` for the
   ring, and `dialog.rs` for the trap and the `Escape`. What it adds over them is a FORM: a preset, two
   pickers, three length boxes and five checkboxes, which is a two-column grid rather than the stacked
   question the Confirm asks. The width is capped because the read-out line ("768 x 960 px — 1 file")
   is the reason the boxes exist and it must be legible without the dialog filling the screen.
   THE SELECTORS ARE STRUCTURAL ON PURPOSE: every `class` the box does not need is 12-20 bytes of the
   skeleton string, and the skeleton string ships in the wasm (the 1 MB cap, ADR §10's perf row). What
   the box keeps as hooks is only what the e2e and `panels/export.rs` aim at: the ids, `data-ex`,
   `data-px`, `data-act`, `.export-body`, `.export-actions`, `.ex-tile-row`, `.ex-checks`,
   `.ex-tile-preset`, `.ex-download`. */
#export {
  margin: auto;
  padding: 14px 16px;
  max-width: 34rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

/* THE `[open]` IS LOAD-BEARING. `#confirm` and `#remap` put their grid on an inner wrapper and leave
   the `dialog` element alone, so the UA's `dialog:not([open]) { display: none }` keeps a closed box out
   of the page; this box has no wrapper (the skeleton string ships its bytes), which means the id rule
   below would otherwise HIDE NOTHING — a closed `#export` still covers the artwork and eats every click
   (found by `e2e/dialogs.spec.js`, whose first `page.click` was intercepted by `#export-title`).
   `[open]` only ever matches a box `dialog::open` showed, so the two files stay the only doors. */
#export[open] {
  display: grid;
  gap: 10px;
}

#export::backdrop {
  background: var(--scrim-45);
}

/* M10.06's tab row (ADR §10.2): two buttons that say which FILE the box writes. The active one is
   marked by the box's OWN `data-tab` — the sync effect writes that one attribute and the stylesheet
   does the rest — so a tab switch is one DOM write, not a show/hide per control. The same attribute
   hides the other tab's rows: `display:none` leaves the Tab ring too, so M10.01's trap walks only
   what the person can see. A row with no tab class belongs to every tab. */
.ex-tabs {
  grid-column: 1 / -1;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

#export .ex-tab {
  min-height: var(--ctl-h);
  padding: 2px 12px;
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  background: none;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

#export .ex-tab:hover {
  color: var(--ink);
}

#export[data-tab="svg"] .ex-tab[data-tab="svg"],
#export[data-tab="html"] .ex-tab[data-tab="html"],
#export[data-tab="png"] .ex-tab[data-tab="png"],
#export[data-tab="kit"] .ex-tab[data-tab="kit"] {
  background: var(--face);
  color: var(--ink);
  font-weight: 600;
}

/* A row belongs to the tabs its CLASSES name (M10.06 for two tabs, M10.07 for three, M10W.06 for
   four): `.ex-html` is the page's row, `.ex-png` is the preview, `.ex-kit` is the kit's file list, and
   `.ex-svg.ex-png` — the Background tick — is a row TWO tabs share, because paper is a question both
   files answer. A row with no tab class belongs to every tab, and there are now exactly two such rows
   left: the tab strip itself and the read-out. Everything the kit cannot honour — Units, the tile row
   and the whole tick block — carries `ex-svg ex-html ex-png` instead, which is how "no knobs on that
   tab" is spelled without a single `if` in the app.
   THE RULE SHOWS, IT DOES NOT HIDE-BY-MISMATCH. `#export:not([data-tab="png"]) .ex-png` reads nicer,
   but it cannot express "a row with two tab classes shows on EITHER of them": on the tab it is not
   named by, the mismatch rule would hide a row the other rule wants. So every tabbed row starts
   hidden and the tab that owns it puts it back — the pair `#export .ex-svg` (0,1,1) loses to
   `#export[data-tab="png"] .ex-png` (0,2,1), which is the whole mechanism. `display:none` leaves the
   Tab ring too, so M10.01's trap walks only what the person can see. */
#export .ex-svg,
#export .ex-html,
#export .ex-png,
#export .ex-kit {
  display: none;
}

#export[data-tab="svg"] .ex-svg,
#export[data-tab="html"] .ex-html,
#export[data-tab="png"] .ex-png,
#export[data-tab="kit"] .ex-kit {
  display: flex;
}

/* The kit's file list (M10W.06): the nine names a person is about to download, in the order they meet
   them, plus the one instruction that makes the folder work (E23.4: `file://` does not load a module
   script). Long, so it wraps and reads small; `text-wrap: pretty` keeps a single orphan off the last
   line where the browser honours it. */
#ex-kit-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-dim);
  text-wrap: pretty;
}

/* The PNG tab's way OUT of a clamp (M15.08): the sentence that says the browser stopped at 16 384 px
   and names the command that does not. Two rules make the row appear:
   - `.ex-png` (above) keeps it off the other three tabs, and
   - `#ex-cli:empty` keeps it off THIS one when nothing was clamped: core hands back `None`, the panel
     writes the empty string, and a `<p>` with no children is `:empty` — no line box, no gap.
   The ID plus the pseudo-class (1,1,0) outranks the tab's show rule (0,2,1), so this needs no
   `!important` and no class toggled from Rust. Monospace for the whole line, because the last two
   thirds of it are a command to type, and `user-select: all` lets one click take the whole thing. */
#ex-cli:empty {
  display: none;
}

#ex-cli {
  grid-column: 1 / -1;
  margin: 0;
  font: var(--mono-font);
  line-height: 1.45;
  color: var(--ink-dim);
  text-wrap: pretty;
  user-select: all;
}

#export-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* Two columns of labelled controls; one column when the box is squeezed, because the tile chips wrap
   into a row of their own before they become a scrolling column. */
.export-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 8px 14px;
  align-items: center;
}

/* Every row of the form is one flex line: a word, then the control(s). That is all five labelled fields,
   the chip row and the tick block, so the rule takes the rows by position and they carry no class. */
.export-body > * {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-dim);
}

/* The pickers and the boxes share one box model, so a length field and a `<select>` cannot look like
   two different kinds of control. */
#export select,
#export input[type="number"] {
  flex: 1 1 auto;
  min-width: 4rem;
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--face);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

/* E13.1's tile row: the presets as chips and the free field at the end. A chip is a SHORTCUT into the
   box beside it (it sends the same `Tile` edit a typed number does), which is why they are buttons and
   why the box, not the chip, is the one that shows the current size. */
.ex-tile-row {
  flex-wrap: wrap;
}

.ex-tile-preset {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-5);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ex-tile-preset:hover {
  border-color: var(--ring);
}

.ex-checks {
  /* The five checkboxes span BOTH columns: they read as one block of yes/no rows, not as two columns
     of unrelated ticks. */
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.ex-checks > label {
  gap: 6px;
  color: var(--ink);
  cursor: pointer;
}

#export input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ring);
  cursor: pointer;
}

/* The computed total (ADR §10.1's "768 x 960 px") and the file count — the two numbers the person is
   deciding between, printed where the boxes that produce them are. */
#ex-size {
  grid-column: 1 / -1;
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-dim);
}

/* The PNG tab's preview (M10.07, ADR §10.3, R4 §4.1 rule 5): the raster file at the preview tile,
   laid over a CHECKERBOARD so that "no background" is something a person can see rather than a word
   beside a checkbox. The board is the wrapper's own background, not a layer of the picture: when the
   document has paper the art covers the board completely, and when it has none the board is what the
   PNG will have in it — alpha. The two greys are the convention (a Figma or Photoshop canvas board)
   rather than the app's palette, because a transparency board has to read the same in every theme.
   The `<img>` is capped at the preview tile's own ceiling (`PREVIEW_MAX` = 320 px) so the box does not
   grow when the artwork is a 256x256 sheet. */
.ex-preview {
  grid-column: 1 / -1;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background-color: var(--checker-a);
  background-image:
    linear-gradient(
      45deg,
      var(--checker-b) 25%,
      transparent 25%,
      transparent 75%,
      var(--checker-b) 75%
    ),
    linear-gradient(
      45deg,
      var(--checker-b) 25%,
      transparent 25%,
      transparent 75%,
      var(--checker-b) 75%
    );
  background-size: 16px 16px;
  background-position:
    0 0,
    8px 8px;
}

.ex-preview img {
  display: block;
  max-width: min(320px, 100%);
  height: auto;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.export-actions button {
  min-height: var(--ctl-h);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ex-download {
  border-color: var(--ring) !important;
  font-weight: 600;
}

/* ------------------------------------------------------ Scale dialog (M10S.10, E20.4)
   THE THIRD SELF-PRINTING `<dialog>`, and the only one whose PREVIEW is NOT inside it: the artwork behind
   the box shows the scaled result because core holds it in `AppState::scale` and the renderer paints the
   ACTIVE layer from it. So this box stays narrow and lets the canvas be the picture — which is why the
   backdrop dims to 30 % instead of the Confirm's 45 %: a preview you cannot see is not a preview. */
#scale {
  margin: auto;
  padding: 0;
  max-width: 26rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#scale::backdrop {
  background: var(--scrim-30);
}

.scale-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.scale-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scale-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.scale-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* The field and its five presets share a row: the number is what you type and the five are what you
   mostly mean, and E20.4 asks for both in the same box. The field takes a fixed 6 rem so the presets never
   move when the number grows to four digits. */
.scale-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scale-label {
  font-size: 13px;
  color: var(--ink-dim);
}

.scale-percent {
  width: 6rem;
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.scale-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.scale-preset {
  min-height: var(--ctl-h);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.scale-preset.pressed,
.scale-preset:hover {
  border-color: var(--ring);
}

.scale-preset.pressed {
  background: var(--face);
  font-weight: 600;
}

/* The read-out is the sentence about THIS box ("6 × 4 cells → 12 × 8 cells, exact"); the exactness line is
   the standing promise E20.4 words for us, and it never changes, so it is the dimmer of the two. */
.scale-line {
  margin: 0;
  font-size: 13px;
}

.scale-exact {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.scale-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.scale-actions button {
  min-height: var(--ctl-h);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.scale-actions button:disabled {
  color: var(--ink-dim);
  cursor: default;
  opacity: 0.6;
}

.scale-apply:not(:disabled) {
  border-color: var(--ring);
  font-weight: 600;
}

/* ------------------------------------------------------ Merge dialog (M15L.03, E30.3)
   THE SEVENTH `<dialog>`, and the only one that carries its OWN preview: the artwork behind it stays the
   stack exactly as it is, because the box is about a layer that does not exist yet and the two doors
   ("add the colors" versus "snap") would be invisible on the canvas until after the fact. So the merged
   LAYER is drawn small, in the palette the merge WOULD leave, beside the three sentences the plan says. */
#merge {
  margin: auto;
  padding: 0;
  max-width: 30rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#merge::backdrop {
  background: var(--scrim-45);
}

.merge-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.merge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.merge-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.merge-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* The layers going in, TOP first — the same order the panel above the box lists them. */
.merge-names {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.merge-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* The merged layer, painted by core's own emitter. The `viewBox` is the whole layer, so one square box
   fits a 2x1 or a 16x20 document and the aspect is the ART's, not the box's. */
.merge-preview {
  flex: 0 0 auto;
  width: 7rem;
  height: 7rem;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
}

.merge-lines {
  display: grid;
  gap: 4px;
  align-content: start;
}

.merge-line {
  margin: 0;
  font-size: 13px;
}

/* The new slots' names are the provenance E30.3 words ("multiply of mauve + base"): useful, and a notch
   quieter than the count they explain. The caveat and the approximation are the "what you give up" pair. */
.merge-slot,
.merge-approx,
.merge-caveat {
  font-size: 12px;
  color: var(--ink-dim);
}

.merge-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.merge-actions button {
  min-height: var(--ctl-h);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.merge-actions button:disabled {
  color: var(--ink-dim);
  cursor: default;
  opacity: 0.6;
}

/* `Merge` is the door the sentence above it recommends (E30.3: the colors that keep the look under every
   scheme), and `Enter` presses it. */
.merge-add:not(:disabled) {
  border-color: var(--ring);
  font-weight: 600;
}

/* The active row's "Scale…" (E20.4). A word, not a glyph: the row's other four controls are all glyphs,
   and the one button that opens a DIALOG says so. `flex: 0 0 auto` keeps it its own width so the layer
   name still takes the row's remaining space. */
#right-panel .layer-scale {
  flex: 0 0 auto;
  min-height: var(--ctl-h);
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

#right-panel .layer-scale:hover {
  background: var(--face);
  border-color: var(--ring);
}

/* ------------------------------------------------------ Gallery dialog (M10.13, ADR §10.6)
   THE LIST BEHIND `Ctrl+KeyO`, and the fifth `<dialog>`. Two rules shape it:

   **THE LAYOUT IS UNDER `#gallery[open]`, NOT `#gallery`.** M10.01's pitfall: a `display` on the id
   beats the UA's `dialog:not([open]) { display: none }`, so a CLOSED gallery would cover the page and
   eat every click. The box's chrome (border, colour) may live on the id; its `display` may not.

   **THE ROWS SCROLL AND THE HEAD DOES NOT.** ADR §10.6 budgets ~500 documents; a list that grew the box
   instead of scrolling it would put row 400 below the bottom of the screen, which is the same as not
   having it. `grid-template-rows: auto auto 1fr` with `overflow:auto` on the middle child is the whole
   of that, and the banner is the row that only exists when the quota is nearly gone.

   The thumbnail is an `<img>` at its own aspect ratio (`object-fit: contain`), because core hands the
   row a `data:` URI of a 6 px-a-cell Union picture — 96 x 120 for the default document — and 500 of
   those as inlined `<path>`s is exactly the blank-panel-forever mistake the index exists to avoid. */
#gallery {
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#gallery[open] {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0;
  margin: auto;
  padding: 0;
  width: min(56rem, 92vw);
  max-height: 86vh;
}

#gallery::backdrop {
  background: var(--scrim-40);
}

.gallery-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.gallery-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* How full the browser is, ALWAYS said — the banner is the warning, this is the reading you can watch
   climb. `margin-left: auto` puts it beside the `×`, which is where a person looks when a write fails. */
.gallery-usage {
  margin-left: auto;
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.gallery-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* ADR §10.6's "above 4 MB the gallery warns 'storage nearly full'". The word is the sentence's, the
   colour is `--bad` rather than a new one, and the row is inside the box: a quota you have to close the
   gallery to read is a warning that arrives after the write that failed. */
.gallery-banner {
  margin: 0;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--bad);
  font-size: 13px;
}

.gallery-list {
  display: grid;
  grid-auto-rows: max-content;
  gap: 4px;
  align-content: start;
  overflow: auto;
  padding: 8px;
}

.gallery-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  cursor: pointer;
}

.gallery-row:hover {
  background: var(--chrome);
  border-color: var(--line);
}

/* The row this session has open — the one the next autosave tick refreshes. A ring rather than a filled
   row, so the thumbnail (the thing you are actually recognising) stays the loudest part of it. */
.gallery-row.active {
  border-color: var(--ring);
  background: var(--chrome);
}

.gallery-thumb {
  display: block;
  width: 44px;
  max-height: 60px;
  border: 1px solid var(--line);
  border-radius: var(--radius-4);
  object-fit: contain;
  background: var(--face);
}

.gallery-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.gallery-row-title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-row-sub {
  font: var(--mono-font);
  font-size: 11px;
  color: var(--ink-dim);
}

/* The badge on a row whose thumb passed the 10 KB band (a big canvas, not a mistake), and the mark on
   the row this window is editing. Both are subordinate to the title, so they are the dim colour. */
.gallery-over,
.gallery-here {
  color: var(--ink-dim);
}

.gallery-over {
  color: var(--bad);
}

.gallery-name {
  width: 100%;
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.gallery-row button {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.gallery-row button:hover {
  border-color: var(--ctl-line);
  color: var(--ink);
}

/* The verb spelled out, because "click anywhere on the row" is a rule the pointer has to be told once. */
.gallery-open {
  font-size: 12px;
  padding: 0 8px;
}

.gallery-empty {
  margin: 0;
  padding: 16px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 13px;
}

/* ============================================================ M10.14 · New document */

/* The sheet `Shift+KeyN` opens: two numbers, E16's six presets, the recipe and the color set, the seed
   and its dice, and Create. NO `display` on `#newdoc` itself — a `display` on a dialog's id beats the UA's
   `dialog:not([open]) { display: none }` and the CLOSED box eats every click on the page (M10.05's
   pitfall, and `e2e/dialogs` died on it). The layout lives on `.nd-box`, which only exists inside an open
   box because the panel prints an empty one. */
#newdoc {
  margin: auto;
  padding: 0;
  width: min(92vw, 32rem);
  max-width: 32rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#newdoc::backdrop {
  background: var(--scrim-32);
}

.nd-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.nd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nd-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.nd-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* The two numbers, then the six chips. A chip writes BOTH fields, so it reads as one gesture and shows up
   as one row of the Tab ring. */
.nd-dims {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nd-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nd-label {
  font-size: 13px;
  color: var(--ink-dim);
}

.nd-num {
  width: 4.5rem;
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

/* Out of the 1..=256 window: the field says so in its own border, and Create is already disabled. The
   number stays exactly as typed. */
.nd-num.invalid {
  border-color: var(--bad);
  color: var(--bad);
}

.nd-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nd-preset {
  min-height: var(--ctl-h);
  padding: 0 8px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.nd-preset:hover {
  border-color: var(--ring);
  color: var(--ink);
}

.nd-preset.pressed {
  border-color: var(--ring);
  background: var(--chrome-2);
  color: var(--ink);
  font-weight: 600;
}

/* Recipe, colors, seed, dice: one row on a wide box, a wrapping two on a narrow one. */
.nd-choices {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nd-recipe,
.nd-set {
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.nd-recipe:disabled {
  opacity: 0.5;
}

.nd-seed-label {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-dim);
}

.nd-seed {
  font-family: var(--mono-font);
  font-size: 13px;
  color: var(--ink);
}

.nd-dice {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.nd-dice:hover {
  border-color: var(--ring);
}

.nd-blank {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-dim);
}

.nd-blank-box {
  width: 15px;
  height: 15px;
  accent-color: var(--ring);
}

/* The read-out is the whole preview a new document has: the sentence naming what Create will make. It
   turns to `--bad` when a number is out of window, which is the same fact the field border and the
   disabled Create are saying. */
.nd-line {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font-size: 13px;
}

.nd-line.nd-warn {
  border-color: var(--bad);
  color: var(--bad);
}

.nd-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.nd-cancel,
.nd-create {
  min-height: var(--ctl-h);
  padding: 0 12px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.nd-create {
  border-color: var(--ring);
  background: var(--ring);
  color: var(--chrome);
  font-weight: 600;
}

.nd-cancel:hover,
.nd-create:hover {
  border-color: var(--ring);
}

.nd-create:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* M10.14's New, in the gallery head: the same command as `Shift+KeyN`, so it is a button of the head,
   not of a row. The `.gallery-usage` span keeps its `margin-left: auto`, which is what holds the New on
   the LEFT with the reading on the right. */
.gallery-new {
  min-height: var(--ctl-h);
  padding: 0 10px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.gallery-new:hover {
  border-color: var(--ring);
}

/* E34.4's `New…` tile: the FIRST tile of the list, ahead of every saved document, because the owner's
   report was that they could not find how to start over. It borrows a row's shape (a square where the
   thumbnail goes, words to its right) and keeps the ring on hover so it reads as a door, not as artwork.
   It is NOT a `.gallery-row`: it has no document to duplicate, rename or delete, and every reader that
   counts `.gallery-row` means SAVED documents. The order is core's (`GalleryVm::slots`). */
.gallery-new-tile {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px dashed var(--ctl-line);
  border-radius: var(--radius-8);
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.gallery-new-tile:hover {
  border-style: solid;
  border-color: var(--ring);
  background: var(--chrome);
}

/* The square the thumbnail would occupy, holding a `+` so the tile says "make one" at a glance. */
.gallery-new-glyph {
  display: grid;
  place-items: center;
  width: 44px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font-size: 18px;
  line-height: 1;
}

.gallery-new-word {
  font-size: 13px;
  font-weight: 600;
}

/* ============================================================ M10.15 · Resize canvas */

/* The box the palette's "Resize canvas…" row opens: two numbers beside a 3x3 anchor picker, and the two
   lines that say what the change costs. NO `display` on `#resize` itself — a `display` on a dialog's id
   beats the UA's `dialog:not([open]) { display: none }` and the CLOSED box eats every click on the page
   (M10.05's pitfall, the same one M10.14 wrote about). The layout lives on `.rz-box`, which only exists
   inside an open box because the panel prints an empty one. */
#resize {
  margin: auto;
  padding: 0;
  width: min(92vw, 30rem);
  max-width: 30rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-10);
  background: var(--chrome-2);
  color: var(--ink);
}

#resize::backdrop {
  background: var(--scrim-32);
}

.rz-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.rz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rz-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.rz-close {
  min-width: var(--ctl-h);
  min-height: var(--ctl-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* The numbers on the left, the nine seats on the right: the picker is a PICTURE of the canvas, and it
   reads beside the size it is about rather than under it. A narrow box stacks them. */
.rz-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.rz-dims {
  display: grid;
  gap: 8px;
}

.rz-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rz-label {
  width: 2.6rem;
  font-size: 13px;
  color: var(--ink-dim);
}

.rz-num {
  width: 5rem;
  min-height: var(--ctl-h);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

/* Out of the 1..=256 window: the field says so in its own border, and Resize is already disabled. The
   number stays exactly as typed. */
.rz-num.invalid {
  border-color: var(--bad);
  color: var(--bad);
}

/* The size the canvas is right now, so the two fields are read as "to", not as "is". */
.rz-now {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
}

/* Anchor9: three rows of three, the seat a person picks is the side that HOLDS. `44 px` is the touch
   target (R3's coarse-pointer row), and the glyph is 17 px so the arrows read at arm's length. */
.rz-pick {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
}

.rz-a {
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.rz-a:hover {
  border-color: var(--ring);
  color: var(--ink);
}

.rz-a.pressed {
  border-color: var(--ring);
  background: var(--chrome-2);
  color: var(--ink);
}

/* The read-out. Line 1 is the size and the anchor; line 2 is what the change costs, in cells and in
   edges — the preview a resize has, since its picture is another canvas's skeleton. */
.rz-line {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink-dim);
  font-size: 13px;
}

.rz-line.rz-warn {
  border-color: var(--bad);
  color: var(--bad);
}

.rz-detail {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ring);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font-size: 12px;
}

/* Cells fall off. Not `--bad`: the op is one `Ctrl+Z` wide and the line says so — a red box would argue
   for a Confirm the item does not ask for. */
.rz-detail.rz-crop {
  border-left-color: var(--bad);
}

.rz-hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.rz-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.rz-cancel,
.rz-apply {
  min-height: var(--ctl-h);
  padding: 0 12px;
  border: 1px solid var(--ctl-line);
  border-radius: var(--radius);
  background: var(--chrome);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.rz-apply {
  border-color: var(--ring);
  background: var(--ring);
  color: var(--chrome);
  font-weight: 600;
}

.rz-cancel:hover,
.rz-apply:hover {
  border-color: var(--ring);
}

.rz-apply:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------ the pair bar (M10P.10, E21.5) */

/* The room's segment of the TOP row, not a fifth row of its own: E07 fits the artwork to
   `#viewport`'s MEASURED box, so chrome that takes height changes the cell size, and ADR §11 draws
   exactly four rows. The dot, the id, the word, two buttons, one note — every one of them a fact core
   already decided (`controller::vm::pair::pair_bar_vm`).

   `[hidden]` is restated because `display:flex` below would otherwise WIN over the UA's
   `display:none` — the classic "hidden element that shows up anyway", and the reason the unpaired app
   must pay nothing for a bar it is not using. */
.pairbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--chrome-2);
  font: var(--ui-font);
  min-width: 0;
}

.pairbar[hidden] {
  display: none;
}

/* The status dot: four states, four colors, one element. The word beside it is the same state in text,
   so the pair is never colour-only (WCAG 1.4.1) and `e2e` can read `textContent` instead of a pixel. */
.pairbar .dot {
  width: 10px;
  height: 10px;
  border-radius: var(--round);
  background: var(--line);
  flex: none;
}

.pairbar .dot.live {
  background: var(--good);
}

.pairbar .dot.wait {
  background: var(--pair-wait);
}

.pairbar .dot.heal {
  background: var(--bad);
}

/* The room id in mono: it is an address to read out to an agent, not prose. */
.pairbar .room {
  font: var(--mono-font);
  color: var(--ink);
}

.pairbar .status {
  color: var(--ink-dim);
}

.pairbar .pair-note {
  color: var(--ink-dim);
  max-width: 22em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The bar's two buttons take the row's 24 px floor like everything else in the chrome (WCAG 2.5.8),
   which `#topbar button` already grants — they ARE `#topbar` descendants, so no size rule here, only
   the lit state for the one whose value is a bool. */
.pairbar button {
  font: var(--ui-font);
}

.pairbar .follow.lit {
  border-color: var(--ring);
  color: var(--ink);
}

/* --------------------------------------------------- the room's marks on the canvas */

/* E21.5: the agent's focus is "a dashed accent rectangle with the note beside it", and cells changed
   by a remote op "flash (outline, 600 ms fade; none under reduced motion)".

   `#pairfx` is a sibling of `#scene` (`canvas.rs`), so `#scene *{pointer-events:none}` (E03.3) does
   NOT reach it and it needs its own rule: a box over the art must never eat a stroke. The stroke is
   `--ring` (the accent the app already uses for "the keyboard is here"), and `vector-effect` keeps it
   one hairline wide at every zoom instead of a bar as thick as the cell. */
#pairfx {
  pointer-events: none;
}

#pairfx .agentbox {
  fill: none;
  stroke: var(--select-ring);
  stroke-width: 2;
  stroke-dasharray: 10 7;
}

/* The agent's note, drawn with a light "halo" (`paint-order: stroke`) so it stays readable over any
   artwork the agent is talking about. */
#pairfx .agentnote {
  font: 600 15px system-ui, sans-serif;
  fill: var(--ink);
  stroke: var(--chrome);
  stroke-width: 4px;
  paint-order: stroke;
}

#pairfx .pflash {
  fill: none;
  stroke: var(--good);
  stroke-width: 3;
  animation: pair-flash var(--flash) ease-out forwards;
}

@keyframes pair-flash {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

/* E21.5's other half, and the app's rather than core's because it is a painting rule: under reduced
   motion there is no fade at all. Core also skips the box entirely (see `AppState::reduced_motion`),
   so this rule is the belt to that braces — a stray `.pflash` from a frame that raced the media query
   still cannot animate. */
@media (prefers-reduced-motion: reduce) {
  #pairfx .pflash {
    display: none;
    animation: none;
  }
}

/* --------------------------------------------------- the activity list (M10P.10, E21.5) */

/* The right panel's room feed: the last twenty log entries, newest first, in the same section shell as
   the six sections above it (`.panel-section`) so it inherits the column's typography and the ≤1100 px
   collapse. Its header is a plain `<div>`, not a `.panel-tab` button: there is no open bit for it in
   `UiSettings::panel_open`, because pairing is not a setting the user configures. */
.activity {
  border-top: 1px solid var(--line);
  margin-top: var(--gap);
  padding-top: var(--gap);
}

.activity-head {
  font-weight: 600;
  color: var(--ink);
  padding: 0 2px 4px;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
  font: var(--ui-font);
  color: var(--ink-dim);
}

.activity-list li {
  padding: 2px 2px;
  border-bottom: 1px solid color-mix(in oklab, var(--line) 45%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The author, colored rather than only named: the agent's lines are the ones you scan for while it
   works, and `data-author` is what an e2e asserts on instead of a substring. */
.activity-list li.aagent {
  color: var(--ink);
}

/* ---------------------------------------------------------------------------------------------
   E27.3's color ring (M15U.03) — the swatches around the pointer while `C` is held.

   `pointer-events: none` on the WHOLE overlay: the ring is a picture of a choice, and the canvas
   underneath is what answers. Core reads the same pointer px to light a swatch (`note_move`) and to
   take it (`click`), so an overlay that swallowed an event would break the pick it is drawn for.
   `position: fixed` because `#viewport` and `#tools` both clip, and a ring cropped by a scroll
   container has swatches nobody can release over. Each plate is placed by `--x`/`--y` (client px,
   written by `crate::ring`) and pulled back by half its own box, so the pointer sits at its centre.
   --------------------------------------------------------------------------------------------- */
.color-ring {
  position: fixed;
  inset: 0;
  z-index: var(--ring-z);
  pointer-events: none;
}

.ring-sw {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--ring-sw);
  height: var(--ring-sw);
  transform: translate(var(--x), var(--y)) translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sw, gray);
  box-shadow: var(--menu-shadow);
  font: var(--ring-badge-font);
  color: var(--ink);
}

/* The lit seat: an OUTSIDE ring so it never covers the color being chosen (the palette's own
   primary ring draws the same way, E10.12). */
.ring-sw.lit {
  outline: var(--ring-edge) solid var(--ink);
  outline-offset: var(--ring-edge);
}

/* ---------------------------------------------------------------------------------------------
 * M15U.05 — the cell pool (E27.5) and the Simplify row (E27.6).
 *
 * FIVE GLYPHS, ONE WIDTH EACH. The row is `display:grid` with five equal columns rather than flex, so
 * the glyphs sit in a line a person can read as "the five kinds in the order the strip prints them",
 * and the dots underneath never push a neighbour sideways when a weight changes. Every control keeps
 * the `--ctl-h` floor the rest of the chrome keeps (WCAG 2.5.8).
 * ------------------------------------------------------------------------------------------ */
.pool {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap, 4px);
  align-items: stretch;
}

.pool-glyph {
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 2px;
  height: var(--ctl-h);
  min-width: var(--ctl-h);
  padding: 0 2px;
  line-height: 1;
}

/* The weight is the DOTS, and the dots are ink only on a kind that is IN the pool: an unused kind is a
   dim glyph with nothing under it, which is the difference between "never" and "sometimes" at a glance. */
.pool-glyph .mark {
  font-size: 13px;
}

.pool-glyph .dots {
  font-size: 8px;
  letter-spacing: 1px;
  opacity: 0.75;
}

.pool-glyph:not(.live) {
  opacity: 0.4;
}

/* The last kind standing (E27.5's floor) is MARKED rather than locked: the button still answers, and its
   tooltip says why the weight will not go. */
.pool-glyph.last {
  outline: 1px solid var(--ink);
  outline-offset: -1px;
}

.pool-readout {
  grid-column: 1 / -1;
  font: var(--mono, monospace);
  font-size: 10px;
  opacity: 0.6;
  text-align: center;
}

/* The top bar's split: `Surprise` and its `▾` are two buttons in one group, so the caret's hit area is
   its own and the label keeps being the verb. */
.surprise-group {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.surprise-menu {
  position: absolute;
  z-index: 30;
  top: 100%;
  right: 0;
  display: grid;
  gap: var(--gap, 4px);
  min-width: 168px;
  padding: var(--gap, 4px);
  background: var(--panel, canvas);
  color: var(--ink);
  box-shadow: var(--menu-shadow);
  border-radius: 6px;
}

.surprise-menu .texture {
  height: var(--ctl-h);
}

/* Tool options (E27.1's slot, E27.5's contents): the pool, then the two verbs that read or coarsen it. */
.tool-options {
  display: grid;
  gap: var(--gap, 6px);
}

.tool-options-verbs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap, 4px);
}

.tool-options-verbs button {
  height: var(--ctl-h);
}

/* E27.6's three coarsenings, in the Scale box under the percents. They are NOT presets — a percent
   resizes and can move the art, a Simplify keeps the box — and the row being SEPARATE, with its own
   label, is what says so. */
.scale-simplify {
  display: flex;
  align-items: center;
  gap: var(--gap, 4px);
}

.scale-simplify-label {
  font-size: 11px;
  opacity: 0.7;
}

.scale-simplify-btn {
  height: var(--ctl-h);
  min-width: var(--ctl-h);
}
