/* gallery.css: the gallery's own chrome, and nothing an application
   receives. The section rhythm, the routes, the previous and next
   pair, the token and icon grids, the rail and its filter, the pinned
   bar, the phone index and the display settings menu. Every value is a
   token, so the page's own furniture changes theme with everything
   else. The preview widget, the code block and the highlight colours
   are view.css's; the two are served joined as one gallery.css.

   It is Rastrillo's gallery.css for the same chrome, with the scheme
   toggle's rules gone (Fiesta's scheme control is the system's own
   dropdown, lifted from the scheme-menu example) and data-gallery-js
   where Rastrillo's reads data-rst-js: the marker gallery.js sets on
   <html>, which is the whole of the scriptless story for the filter
   below. */

.ds-head { border-top: 1px solid var(--rst-line); margin: var(--rst-sp-6) 0 var(--rst-sp-3); padding-top: var(--rst-sp-5); }
.ds-head h2 { font-size: 1.35rem; letter-spacing: -0.01em; margin: 0; }
.ds-lead { color: var(--rst-text-muted); margin: 0 0 var(--rst-sp-4); max-width: 62ch; }
.ds-sub { font-size: var(--rst-fs-base); margin: var(--rst-sp-5) 0 var(--rst-sp-2); }
/* A heading is one word on the index, the tokens and the icons pages,
   and a word has to be able to break at 320px: the page may not scroll
   sideways for anything. */
[rst-page] h1, [rst-page] h2 { overflow-wrap: anywhere; }
/* An example page's family, under its heading: the family's name and
   its sentence, as a kicker back to the page that files it. Then the
   example's own sentence and the two every example page says. All
   three read as Rastrillo's page head reads its leads: one size, one
   colour, one step between them, so the head is a column of sentences
   rather than three type sizes stacked. */
.ds-kicker, [rst-page] > [rst-page-header-sub] { color: var(--rst-text-muted); font-size: inherit; margin: 0 0 var(--rst-sp-4); max-width: 62ch; }
.ds-kicker b { color: var(--rst-text); font-weight: 600; }
/* One state: a card, its label, the note on it, the widget view.css
   draws, and the routes it stands for. The label is styled by class,
   not by level: the outline moved once when the pages got real titles,
   and a rule keyed to h2 would silently unstyle the label the next
   time it moves. */
.ds-sample { background: var(--rst-surface-2); border: 1px solid var(--rst-line); border-radius: var(--rst-radius); margin: var(--rst-sp-3) 0; padding: var(--rst-sp-4); }
.ds-state { color: var(--rst-text-faint); font-size: var(--rst-fs-xs); font-weight: 650; letter-spacing: 0.06em; margin: 0 0 var(--rst-sp-3); text-transform: uppercase; }
.ds-note { border-inline-start: 2px solid var(--rst-line-strong); color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: var(--rst-sp-3) 0 0; max-width: 62ch; padding-inline-start: var(--rst-sp-3); }
/* A grouped widget's note names its state on a line of its own, so no
   joining punctuation has to be written, and translated, between the
   two. */
.ds-note__state { display: block; font-weight: 600; }
.ds-routes-note { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: var(--rst-sp-3) 0 0; max-width: 62ch; }
/* The Overview's link to the demo is the whole sentence, not a link in
   running text, so it takes the floor. inline-block, because an inline
   box's padding is added to its font's content area, not its line, so
   the same padding came out 28px. */
.ds-demo > .ds-note > a { display: inline-block; padding-block: max(0px, (var(--rst-target) - 1lh) / 2); }
/* The token grid, and the icon grid that reuses it: one chip per
   token, its name and value beside it. The icon sits inside its chip
   at the 1em tokens.css gives it, which is the size a component draws
   it at rather than a poster of it. The call under an icon's name is
   long enough to overrun a 13rem column on a 320px screen, so that is
   the one place in the grid that breaks inside a word. */
.ds-toks { display: grid; gap: var(--rst-sp-3); grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); list-style: none; margin: 0 0 var(--rst-sp-5); padding: 0; }
.ds-tok { align-items: center; display: flex; gap: var(--rst-sp-3); min-inline-size: 0; }
.ds-tok__text { min-inline-size: 0; }
.ds-tok__name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-tok__value { color: var(--rst-text-muted); display: block; overflow-wrap: anywhere; }
.ds-chip { background: var(--rst-surface); border: 1px solid var(--rst-line-strong); border-radius: var(--rst-radius-sm); block-size: 2.25rem; flex: none; inline-size: 2.25rem; }
.ds-chip--fill { background: var(--rst-accent); border-color: var(--rst-accent); }
.ds-chip--icon { align-items: center; color: var(--rst-text); display: flex; justify-content: center; }
.ds-bar { background: var(--rst-accent); block-size: 1.25rem; border-radius: 2px; flex: none; }
.ds-type { display: block; flex: none; inline-size: 3.25rem; line-height: 1.15; text-align: center; }
.ds-swatch-note { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: 0 0 var(--rst-sp-4); max-width: 62ch; }
/* The Overview's opening paragraph and the routes under it, which a
   family page reuses for its examples. .ds-files is the same row, a
   name, a sentence and a number, on the Getting started page. The
   paragraph is the one piece of copy on this site somebody wrote by
   hand rather than derived from the code, so it is set a step larger
   than body text and given the same 62ch measure everything else here
   reads at. A route's link takes the target floor like any control. */
.ds-intro { font-size: 1.05rem; margin: 0 0 var(--rst-sp-5); max-width: 62ch; }
.ds-routes, .ds-files { display: grid; gap: var(--rst-sp-4); list-style: none; margin: 0 0 var(--rst-sp-5); padding: 0; }
.ds-routes > li, .ds-files > li { border-inline-start: 2px solid var(--rst-line-strong); padding-inline-start: var(--rst-sp-3); }
.ds-routes a, .ds-files a { align-items: center; display: inline-flex; font-weight: 600; min-block-size: var(--rst-target); }
.ds-routes span, .ds-files span { color: var(--rst-text-muted); display: block; font-size: var(--rst-fs-sm); max-width: 62ch; }
/* Prev/next at the foot. Two grid columns rather than a flex row with
   space-between, because the ends of the sequence are missing a link
   and not missing a column: the Overview's Next has to stay on the
   inline end rather than sliding across to where Previous would have
   been. */
.ds-updown { border-block-start: 1px solid var(--rst-line); display: grid; gap: var(--rst-sp-3); grid-template-columns: 1fr 1fr; margin-block-start: var(--rst-sp-6); padding-block-start: var(--rst-sp-4); }
/* A grid of one so the floor's height centres the text; the links
   were their 21px line, 24px on a phone. */
.ds-updown__prev, .ds-updown__next { align-content: center; display: grid; min-block-size: var(--rst-target); }
.ds-updown__prev { grid-column: 1; justify-self: start; }
.ds-updown__next { grid-column: 2; justify-self: end; text-align: end; }
.ds-shell { margin: var(--rst-sp-5) 0; }
.ds-shell__name { font-size: 1.05rem; margin: 0 0 var(--rst-sp-1); }

/* The rail is the shipped sidebar layout's, below 800px the phone
   index on the Overview and hidden on every other page, all by
   tokens.css's own rules. What is left here is what a rail of links
   has no attribute for: a collapsible section per group, and the
   filter over them. */
.ds-rail { gap: var(--rst-sp-2); }
/* border-box: on the content box the floor came on top of the padding,
   and the headings grew from 28 to 43px. */
.ds-nav > details > summary { align-items: center; box-sizing: border-box; color: var(--rst-text-faint); cursor: pointer; display: flex; font-size: var(--rst-fs-xs); font-weight: 650; gap: 0.35rem; letter-spacing: 0.06em; list-style: none; min-block-size: var(--rst-target); padding-block: 0.35rem; text-transform: uppercase; }
.ds-nav > details > summary::-webkit-details-marker { display: none; }
/* The disclosure glyph is the icon set's own chevron inside an
   [rst-caret], which tokens.css already flips 180 degrees on [open]
   and already stills under prefers-reduced-motion. It is aria-hidden
   because it sits beside the section's own name. */
.ds-nav > details > summary > [rst-caret] { flex: none; }
.ds-nav > details[aria-current] > summary { color: var(--rst-accent); }
/* A section with nothing to list is a link to its page rather than a
   disclosure over an empty box. It wears the summary's typography so
   the rail still reads as one list. */
.ds-nav__page { color: var(--rst-text-faint); font-size: var(--rst-fs-xs); font-weight: 650; letter-spacing: 0.06em; padding-block: 0.35rem; text-transform: uppercase; }
.ds-nav__page[aria-current] { color: var(--rst-accent); }
.ds-nav__page:hover { color: var(--rst-text); }
.ds-nav > details > summary:hover { color: var(--rst-text); }
.ds-nav > details > summary:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: 2px; }
/* The filter hides a link by setting [hidden] on it, and the shell
   paints every rail link display: block, which the browser's own
   [hidden] rule loses to. This selector outranks it rather than
   shouting !important at it. */
[rst-shell-sidebar] .ds-nav a[hidden], .ds-nav details[hidden] { display: none; }
/* No script, no filter, and no box sitting there looking like one. The
   nav under it is a complete list of every page either way. */
.ds-search { display: none; }
:root[data-gallery-js] .ds-search { display: block; }
/* The magnifier sits inside the field at its inline start, over the
   field's padding, and lets a tap through to the field under it. It is
   the icon set's own search glyph, aria-hidden, because the field's
   label already names it. */
:root[data-gallery-js] .ds-search { position: relative; }
/* 16px like the system's search box's icon: tokens.css sizes an icon
   that way only inside its own controls, and this box is the gallery's. */
.ds-search > .icon { block-size: 1rem; color: var(--rst-text-faint); inline-size: 1rem; inset-block-start: 50%; inset-inline-start: 0.55rem; pointer-events: none; position: absolute; transform: translateY(-50%); }
.ds-search input { background: var(--rst-bg); border: 1px solid var(--rst-line-strong); border-radius: var(--rst-radius-sm); box-sizing: border-box; color: var(--rst-text); font: inherit; font-size: var(--rst-fs-sm); inline-size: 100%; min-block-size: var(--rst-target); padding-block: 0.35rem; padding-inline: 1.9rem 0.5rem; }
.ds-search input:focus-visible { border-color: var(--rst-accent); outline: 2px solid var(--rst-accent); outline-offset: -1px; }
.ds-nav__empty { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: var(--rst-sp-3) 0 0; }
/* The rail's filter box is 12.5px like everything else in here, and a
   sub-16px field is exactly what makes mobile Safari zoom the whole
   page when it takes focus. tokens.css lifts the app's own controls on
   a coarse pointer; this one carries a ds- class of its own, so it
   outranks that rule and has to say the same thing again. */
@media (pointer: coarse) {
  .ds-search input { font-size: max(1rem, 1em); }
}

/* The frame. At 800px and up the bar is pinned over main. A grid
   item's containing block is its grid area and a sticky box cannot
   leave it, so a bar in a one-row area has no room to stick; it gets
   the rail's shape instead, an area spanning every row, with the first
   row reserving its height. Lines are numbered, not sided, so in
   Arabic the rail is on the right and the bar over main on the left
   with no rule here.

   --ds-bar-h is the bar's border-box height, the measured tallest over
   every theme and language. From 1024px the no-wrap rule below keeps
   the bar to one row everywhere, so the reservation is that one line's
   height. Below 1024px the controls could still wrap to a second line,
   but since the scheme control became three icons they fit on one in
   every language, so the one reservation serves both bands.
   TestThePinnedBarFitsItsReservation measures what is inside the bar
   against it, band by band. */
:root { --ds-bar-h: 3.25rem; }
.ds-top { align-items: center; border-block-end: 1px solid var(--rst-line); display: flex; flex-wrap: wrap; gap: var(--rst-sp-2) var(--rst-sp-3); justify-content: space-between; padding: var(--rst-sp-2) var(--rst-sp-4); }
/* Padding rather than a min-block-size, because from 1024px the brand
   elides its text, which a flex or grid box cannot do: the link grows
   to the floor round its one line, and the bar centres it. */
.ds-top__brand { color: var(--rst-text); font-weight: 650; padding-block: max(0px, (var(--rst-target) - 1lh) / 2); text-decoration: none; }
.ds-top__controls { align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-3); justify-content: flex-end; }
.ds-top__controls [rst-dropdown] { position: relative; }
/* The theme switcher is the system's seg-tabs, which leaves a block's
   gap under itself. Here it sits in a row and in a column that space
   their own items: in the bar's centred row the margin lifted the tabs
   above the menus beside them, and in the phone card it more than
   doubled the gap under them. */
.ds-top__controls [rst-seg-tabs], .ds-prefs [rst-seg-tabs] { margin: 0; }
.ds-top__controls [rst-dropdown] > summary { padding-block: 0.25rem; }
/* The bar's own box is fixed at --ds-bar-h and cannot grow to a second
   row without overflowing its grid area (above), so from 1024px it
   must not wrap at all. The brand is what yields: eliding its text
   leaves its accessible name untouched, while every control has to
   stay whole for its hit target and its label to both still work. */
@media (min-width: 1024px) {
  .ds-top { flex-wrap: nowrap; }
  .ds-top__controls { flex-shrink: 0; }
  .ds-top__brand { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (min-width: 800px) {
  body > [rst-shell-sidebar] { grid-template-rows: var(--ds-bar-h) 1fr; }
  body > [rst-shell-sidebar] > [rst-shell-rail] { grid-column: 1; grid-row: 1 / -1; }
  /* Opaque, and above page content (auto, the positioned preview boxes
     and transformed frames included) but below the skip link's 60. */
  .ds-top { align-self: start; background: var(--rst-bg); block-size: var(--ds-bar-h); box-sizing: border-box; grid-column: 2; grid-row: 1 / -1; inset-block-start: 0; position: sticky; z-index: 10; }
  body > [rst-shell-sidebar] > [rst-shell-main] { grid-column: 2; grid-row: 2; }
  /* The name the phone row shows; the pinned bar carries it here. */
  body > [rst-shell-sidebar] > .ds-rail > [rst-shell-brand] { display: none; }
  /* Fragments and focus stop below the pinned bar (WCAG technique C43).
     Only here: below 800px what is pinned is the shell's header row,
     and its clearance is tokens.css's to set; a rule on html at every
     width would override that. */
  html { scroll-padding-block-start: calc(var(--ds-bar-h) + var(--rst-sp-2)); }
}
/* Pieces only the phone index shows, written on the Overview alone. At
   800px and up the Overview is a page with the rail beside it, as the
   shell's index is, and these would be a second list under the tree
   and a second set of controls beside the bar's. */
.ds-index-lead, .ds-rail > .ds-index { display: none; }
@media (max-width: 799.98px) {
  /* On a phone a section page is the way back and the content, and the
     controls are in the display settings menu at the top of every page
     (below). The shell's layout puts the rail's pieces in its grid; on
     a content page the filter is the index's, so it goes with the nav. */
  .ds-top, body > [rst-shell-sidebar~="page"] > .ds-rail > .ds-search { display: none; }
  /* The index's pieces under its row, in the rail's order, the width of
     the screen less the shell's gutters, where the shell puts its one
     nav: the lead, the filter, then the rows (or the tree a query
     filters). Contained, as the shell's nav is, so a long line takes
     the row's width rather than lending the grid its own. */
  body > [rst-shell-sidebar~="index"]:has([rst-shell-up]) > .ds-rail > :is(.ds-index-lead, .ds-search, .ds-nav__empty, [rst-shell-nav]) { contain: inline-size; grid-column: 1 / -1; grid-row: auto; margin-inline: var(--rst-sp-4); min-inline-size: 0; }
  body > [rst-shell-sidebar~="index"]:has([rst-shell-up]) > .ds-rail > .ds-index-lead { margin-block-start: var(--rst-sp-4); }
  [rst-shell-sidebar~="index"] .ds-index-lead { color: var(--rst-text-muted); display: block; margin: 0 0 var(--rst-sp-4); padding-inline: 0.25rem; }
  [rst-shell-sidebar~="index"] > .ds-rail > .ds-index { display: flex; }
  /* The rail on the index has no gap of its own (the rows sit flush
     under the heading), so the field would touch the first row. */
  [rst-shell-sidebar~="index"] .ds-search { margin-block-end: var(--rst-sp-3); }
  /* A query swaps the rows for the tree it filters. Two rules, so an
     engine without :has() drops both and shows rows and tree one after
     the other: long, but with no route missing. */
  [rst-shell-sidebar~="index"]:not(:has(#ds-filter:not(:placeholder-shown))) > .ds-rail > .ds-nav { display: none; }
  [rst-shell-sidebar~="index"]:has(#ds-filter:not(:placeholder-shown)) > .ds-rail > .ds-index { display: none; }
}
@media (max-width: 799.98px) {
  /* On a phone the stage is the screen's width. The bleed is what sits
     between the widget and the screen's edge: the page's padding, and
     inside a sample card its padding and border as well. Written per
     context rather than measured, so a change to either shows up as a
     sideways scroll in the reflow and phone drives instead of a quietly
     narrower stage. The tabs and the code stay in the text column. */
  .ds-view { --ds-bleed: var(--rst-sp-4); margin-inline: calc(-1 * var(--ds-bleed)); }
  .ds-sample .ds-view { --ds-bleed: calc(2 * var(--rst-sp-4) + 1px); }
  .ds-view__tabs, .ds-view__code { margin-inline: var(--ds-bleed); }
  /* Content-box sizing under max-inline-size: 100%: a border here
     would make a full-width box 2px wider than the screen. */
  .ds-view__box, .ds-view__stage { border-inline-width: 0; border-radius: 0; }
}

/* Display settings, on a phone. Below 800px the pinned bar is gone,
   and the theme, scheme and language controls are one menu at the
   inline end of every page's header row, where an app's avatar sits.
   It is an rst-dropdown, so fiesta.js closes it on an outside click
   and on Escape, and its card is the system's anchored panel. At 800px
   and up the bar has the controls and the menu is not drawn. */
.ds-prefs { display: none; }
/* border-box, so the system's target floor is the whole button rather
   than 44px of icon inside its padding. */
.ds-prefs > summary { border-radius: var(--rst-radius-sm); box-sizing: border-box; color: var(--rst-text); justify-content: center; padding: 0.4rem; }
.ds-prefs > summary:hover, .ds-prefs[open] > summary { background: var(--rst-accent-soft); }
.ds-prefs > summary:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: -2px; }
/* Scripts off, a tap outside the card still closes it: the open
   summary grows a layer over the viewport, under the card, so the tap
   is a click on the summary. The system's menu cards do the same. */
.ds-prefs[open] > summary::before { content: ""; cursor: default; inset: 0; position: fixed; z-index: 1; }
/* Taller than a menu's usual 20rem cap: the screen is the room it has,
   not a row of a toolbar, and where popovers are missing the language
   list still opens in place, twelve 44px rows. */
.ds-prefs > [rst-dropdown-menu] { align-items: flex-start; box-sizing: border-box; display: flex; flex-direction: column; gap: var(--rst-sp-3); inline-size: max-content; max-block-size: calc(100dvh - 6rem); max-inline-size: calc(100vw - 1.5rem); padding: var(--rst-sp-3); }
/* Language is a row, as in an app's account card: the label, then the
   page's language, which opens the list as a sheet over the page
   (tokens.css). The row is the card's full width, its value at the
   inline end. */
.ds-prefs [rst-menu-row] { align-self: stretch; padding-inline: 0; }
@media (max-width: 799.98px) {
  /* At the row's inline end, as far in as the up link is, where the
     shell puts a rail foot's avatar; on a content page it sticks at the
     top with the row, as the avatar does, and is lifted while open. */
  body > [rst-shell-sidebar] > .ds-rail > .ds-prefs { align-self: center; display: block; grid-column: 3; grid-row: 1; justify-self: end; margin-inline-end: var(--rst-sp-1); }
  body > [rst-shell-sidebar~="page"] > .ds-rail > .ds-prefs { align-self: start; grid-row: 1 / -1; inset-block-start: calc((var(--rst-shell-strip) - 2.75rem) / 2); margin-block-start: calc((var(--rst-shell-strip) - 2.75rem) / 2); position: sticky; z-index: 9; }
  body > [rst-shell-sidebar~="page"] > .ds-rail > .ds-prefs[open] { z-index: 45; }
}

/* view.css: the preview widget's half of the gallery's stylesheet,
   served joined to gallery.css as one file. The widget ([Desktop]
   [Mobile] [HTML] over one frame), the code block under it with its
   wrapper line and Copy button, and the five highlight colours
   codeview.Highlight writes; TestHighlightColoursPassAgainstTheCodeBackground
   reads those off this file by their exact lines. It is Rastrillo's
   widget block and code-block rules, the Template tab's rules dropped,
   with Fiesta's marks where Rastrillo reads its own: data-gallery-js
   (set by view.js, which is what shows a frame) for data-rst-js, and
   data-gallery-painted, the mark part 3 established, for
   data-ds-painted. */

/* ── The code block ──────────────────────────────────────────────────
   A source block can still scroll sideways where a single token is
   wider than its column, and a box that scrolls must be reachable from
   the keyboard (axe's scrollable-region-focusable; WCAG 2.1.1), so
   every pre.ds-src carries tabindex="0". */
.ds-src { background: var(--rst-surface); border: 1px solid var(--rst-line); border-radius: var(--rst-radius); margin: var(--rst-sp-3) 0; overflow-x: auto; padding: var(--rst-sp-4); }
/* Source soft-wraps rather than scrolling sideways. An inline run (a
   meter's whole output, a choice card) is one line however long,
   because breaking inside it would change the space a reader sees; so
   the block wraps it on screen, and copying takes textContent, which
   has no soft breaks in it. */
.ds-src code { overflow-wrap: anywhere; white-space: pre-wrap; }
/* Code is left to right in every language. Inheriting an Arabic page's
   rtl, a block sits against the right edge and the bidi algorithm
   mirrors its brackets and moves trailing punctuation to the front, so
   what a reader sees is not what Copy puts on the clipboard. isolate
   keeps a name inside a sentence (the wrapper line's) from reordering
   the words around it. */
.ds-src, .ds-wrap code { direction: ltr; text-align: start; unicode-bidi: isolate; }
/* The five token colours, from theme tokens so they follow theme and
   scheme, each at 4.5:1 or better against --rst-surface, the block's
   background, in every theme and both schemes; the test reads these
   lines, one rule per element. */
ds-t { color: var(--rst-accent); }
ds-a { color: var(--rst-tone-negative-fg); }
ds-v { color: var(--rst-tone-positive-fg); }
ds-x { color: var(--rst-text-muted); }
ds-s { color: var(--rst-tone-warning-fg); }
.ds-wrap { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: 0 0 var(--rst-sp-2); }
/* Sits directly before the block it copies. inline-size: fit-content
   with margin-inline-start: auto pushes a block-level button to the far
   edge without a flex wrapper around it, on the inline axis, so it
   lands on the right in a left-to-right page and the left in Arabic
   with no direction check anywhere in view.js. It reads the target
   floor itself, because tokens.css floors a button only through
   rst-btn; border-box so the floor is the whole button, not its text. */
.ds-copy { align-items: center; background: none; border: 1px solid var(--rst-line); border-radius: var(--rst-radius-sm); box-sizing: border-box; color: var(--rst-text-muted); cursor: pointer; display: flex; font: inherit; font-size: var(--rst-fs-sm); inline-size: fit-content; justify-content: center; margin-inline-start: auto; min-block-size: var(--rst-target); min-inline-size: var(--rst-target); padding-block: 0.2rem; padding-inline: 0.6rem; }
.ds-copy:hover { background: var(--rst-accent-soft); color: var(--rst-text); }
.ds-copy:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: 2px; }

/* ── A grouped widget's states ───────────────────────────────────────
   Under a grouped widget every state has a block of its own: the
   state's name on a line of its own, and its note where the prose has
   one. The name and the note are two elements with nothing written
   between them, since a joiner would be copy no review saw. */
.ds-group-note { margin-block-start: var(--rst-sp-3); }
.ds-note__state { display: block; font-weight: 600; }
.ds-group-note > .ds-note { margin: var(--rst-sp-1) 0 0; }

/* ── The preview widget ──────────────────────────────────────────────
   [Desktop] [Mobile] [HTML] over one frame. HTML is there only when
   the example has code to show, so a widget has two or three tabs.

   No script anywhere in it. The tabs are radio inputs sharing a name,
   hidden but focusable inside their labels, and :has() reads which one
   is checked from the wrapper, so the panels switch on the browser's
   own form behaviour and a reader with JavaScript off has the same
   views as everyone else.

   None of them starts checked, and that is the whole of how the
   opening view follows the reader. CSS cannot tell "the reader chose
   Desktop" from "Desktop is what the markup shipped checked", so a
   widget that opens on a checked radio can never let the width pick
   the opening view and still take an explicit choice. With nothing
   checked the width picks Desktop or Mobile, and any tab, once
   clicked, overrides it at any size.

   Which width picks is the stage's, asked with a container query on
   .ds-view, and not the viewport's. The viewport is the wrong ruler
   because the gallery's rail arrives at 800px and takes its width out
   of the column: a reader who widens their window makes the preview
   narrower, so a viewport rule switches to the rendering that needs
   the most room at exactly the width where it has the least. A
   container query measures the box a reader actually gets.

   One number does the deciding, written twice because CSS cannot put a
   custom property in a query condition: --ds-kmin, the least the frame
   may be scaled to, and the stage width at which the desktop rendering
   reaches it, --ds-wd × --ds-kmin. Keep them in step; the drives
   assert the identity off each widget's own --ds-wd.

   Two width classes. --ds-wd is the width the desktop rendering is
   laid out at:

     .ds-view--page   1200px   a whole page: the layout documents, the
                               two shell idioms, the modal, the demo
                               application. A page frame wants a window
                               to be a page frame in.
     .ds-view         900px    everything else: a field, a pill, a row,
                               a menu. A component is something inside
                               a page, and never gets a window's width
                               in an app either.

   The default is the component one, because nearly every example is a
   component. view.go's pageFrame() decides which is which. Laid out at
   1200px, every component was drawn at four-fifths size in the stage
   the gallery's column allows; at 900px a field is a field. Not the
   full column, because tokens.css switches the shells to their narrow
   layout at 800px, and a "desktop" rendering under that width would be
   the mobile layout under a lit Desktop tab.

   Where 0.72 comes from: the type in these samples is 14px, 12.5px and
   11.5px, and 12.5px carries most pages, so it is the one to protect;
   9px is about where rendered text stops being read and starts being
   texture, and 12.5 × 0.72 = 9.0px exactly. That gives both the floor
   and the thresholds: 1200 × 0.72 = 864px = 54rem for a page frame,
   900 × 0.72 = 648px = 40.5rem for a component. The arithmetic is exact
   at a 16px root and only there; a reader who scales their root type
   up moves the rem values and not the ratio, and the gap falls the safe
   way.

   The pair is written as (min-width: Nrem) and its exact negation
   rather than a min/max pair: a max-width one pixel under leaves a gap
   a fractional width can land in, where neither rule applies and no
   tab is lit. The highlight is driven by the same two queries, so the
   tab a reader sees lit is always the rendering in front of them. An
   engine with :has() but no container queries gets a third rule that
   lights Desktop to match the rendering it will be showing.

   The scale: the frame is laid out at a virtual --ds-w (its class's
   --ds-wd, or 390px on Mobile) and scaled to fit the reader's column,
   so the desktop rendering is the desktop rendering on a phone too.
   CSS divides two lengths into a plain number with tan(atan2(a, b)),
   and 100cqw is the container's own width, so --ds-k is that fraction;
   the 1 stops it scaling anything up and --ds-kmin stops it scaling
   anything into illegibility. Where the trig functions are missing the
   @supports block never applies, --ds-k stays 1, and the frame is a
   virtual-width page clipped to the column: smaller, not broken.

   Below its class's threshold the desktop rendering stops shrinking and
   starts panning: --ds-k holds at 0.72, the box stays as wide as the
   column, and the scaled page inside it scrolls horizontally within
   the box. The scroller is on the box itself, not on the state that
   made it necessary: the Mobile rendering clamps at 0.72 too, and
   under 281px of stage the opening view cropped 42px at a 320px window
   with no way to reach it. A box that can clamp can overflow, and one
   that can overflow has to scroll.

   The container is .ds-view and not .ds-view__stage, because the tabs
   are the stage's siblings and a query on the stage cannot reach them.
   .ds-view carries no padding and no border, so the two are the same
   number of pixels wide; the drives measure both and require them
   equal.

   --ds-h is the frame's virtual height, written per example by
   previewStyle from the measured table in heights.go. It sizes the
   box; the frame takes its height back off the box, 100% / --ds-k,
   which is the same number until a reader drags the resize grip and
   then is whatever they dragged it to. The box is a window on a
   document, not a fit to it: a taller sample scrolls inside its frame,
   and the grip is there for the ones a reader wants more of.

   min-block-size is insurance: block-size names --ds-k, and a --ds-k an
   engine parses but cannot resolve drops that declaration to auto,
   which for a box whose only child is absolutely positioned is zero.
   Its value is the smallest height the healthy cascade can produce, so
   it never binds when things work. The @supports guard tests the same
   shape the declaration uses, 100cqw and all. */
.ds-view { --ds-wd: 900px; --ds-w: var(--ds-wd); --ds-wm: 390px; --ds-h: 220px; --ds-hm: 330px; --ds-kmin: 0.72; container-name: ds-view; container-type: inline-size; margin: var(--rst-sp-3) 0; }
.ds-view--page { --ds-wd: 1200px; }
/* A grouped row's frame sits flush with its tabs, not centred: its
   states start at the inline start like the labels above them. */
.ds-view--rows .ds-view__box { margin-inline-start: 0; }
/* Two pairs, the renderings and the source, that wrap as wholes: three
   tabs in one row can be wider than a sample's column on a 320px phone
   in a language with long words, and a label that may wrap breaks a
   tab into two lines of text. */
.ds-view__tabs { border: 0; display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); margin: 0 0 var(--rst-sp-2); padding: 0; }
.ds-view__pair { display: inline-flex; }
/* A tab is a target like any control: the floor in force, border-box so
   the border and padding are inside it. */
.ds-view__tab { align-items: center; border: 1px solid var(--rst-line); box-sizing: border-box; color: var(--rst-text-muted); cursor: pointer; display: inline-flex; font-size: var(--rst-fs-sm); min-block-size: var(--rst-target); padding: 0.2rem 0.7rem; white-space: nowrap; }
.ds-view__tab + .ds-view__tab { border-inline-start: 0; }
.ds-view__tab:first-of-type { border-end-start-radius: var(--rst-radius-sm); border-start-start-radius: var(--rst-radius-sm); }
.ds-view__tab:last-of-type { border-end-end-radius: var(--rst-radius-sm); border-start-end-radius: var(--rst-radius-sm); }
.ds-view__tab input { block-size: 1px; clip-path: inset(50%); inline-size: 1px; margin: 0; overflow: hidden; position: absolute; }
.ds-view__tab:hover { background: var(--rst-accent-soft); color: var(--rst-text); }
.ds-view__tab:has(input:checked) { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; }
/* One pair of queries per width class, and the two declarations each
   pair drives are written inside it: which rendering opens, and which
   tab is lit over it, are one decision, and two rules answering to two
   copies of the same condition is the shape a divergence hides in. */
@container ds-view (min-width: 40.5rem) { .ds-view:not(.ds-view--page):not(:has(input:checked)) .ds-view__tab--d { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; } }
@container ds-view not (min-width: 40.5rem) {
  .ds-view:not(.ds-view--page):not(:has(input:checked)) .ds-view__tab--m { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; }
  .ds-view:not(.ds-view--page):not(:has(.ds-view__tab--d input:checked)) .ds-view__box { --ds-h: var(--ds-hm); --ds-w: var(--ds-wm); }
}
@container ds-view (min-width: 54rem) { .ds-view--page:not(:has(input:checked)) .ds-view__tab--d { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; } }
@container ds-view not (min-width: 54rem) {
  .ds-view--page:not(:has(input:checked)) .ds-view__tab--m { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; }
  .ds-view--page:not(:has(.ds-view__tab--d input:checked)) .ds-view__box { --ds-h: var(--ds-hm); --ds-w: var(--ds-wm); }
}
@supports not (container-type: inline-size) { .ds-view:not(:has(input:checked)) .ds-view__tab--d { background: var(--rst-accent-soft); color: var(--rst-accent); font-weight: 600; } }
.ds-view__tab:has(input:focus-visible) { outline: 2px solid var(--rst-accent); outline-offset: 2px; }
.ds-view__box { --ds-k: 1; background: var(--rst-bg); block-size: calc(var(--ds-h) * var(--ds-k)); border: 1px solid var(--rst-line); border-radius: var(--rst-radius); inline-size: calc(var(--ds-w) * var(--ds-k)); margin-inline: auto; max-inline-size: 100%; min-block-size: calc(var(--ds-h) * var(--ds-kmin)); overflow: hidden; overflow-x: auto; overscroll-behavior-x: contain; position: relative; resize: vertical; scrollbar-width: thin; }
.ds-view__frame { block-size: calc(100% / var(--ds-k)); border: 0; inline-size: var(--ds-w); inset-block-start: 0; inset-inline-start: 0; min-block-size: 100%; position: absolute; transform: scale(var(--ds-k)); transform-origin: top left; }
/* transform-origin has no logical keywords, so the side is a selector.
   Anchored at the physical left, a right-to-left box could not scroll
   to the frame's start. */
[dir="rtl"] .ds-view__frame { transform-origin: top right; }
/* A frame shows nothing of its own until view.js marks it, once its
   document is parsed and styled and has the page's scheme written on
   it (load if that is missed), and again for each document a
   navigation inside the frame loads. Before that, in every scheme:
   - the frame holds the about:blank it was created with, which Safari
     painted white on a dark page (see the color-scheme rule below);
   - its document is parsing, or parsed without its stylesheets;
   - with Light or Dark chosen, it has painted in the OS's scheme while
     scrolling to a lazy frame, after a reload at a remembered scroll,
     or on a click inside one.
   Hidden, the box behind it shows this page's --rst-bg instead; a
   hidden frame still lazy-loads. data-gallery-js because view.js is
   what shows it: with scripts off nothing would, and the frames show
   as they come. */
:root[data-gallery-js] .ds-view__frame:not([data-gallery-painted]) { visibility: hidden; }
/* A browser compares a frame's color-scheme with its document's, and
   Safari draws a document whose scheme differs on an opaque canvas.
   about:blank declares none, so it is light, and with the frame
   inheriting a dark page's scheme every frame was white until its
   document came. Normal matches it. A preview declares its own scheme
   and paints its whole canvas, so this changes nothing once it paints.
   It is all a reader without scripts gets, since nothing hides their
   frames. */
.ds-view__frame { color-scheme: normal; }
@supports (block-size: calc(1px * clamp(0.5, tan(atan2(100cqw, 1200px)), 1))) {
  /* Mobile is the stage's width up to 390px: below 390px of stage,
     laying the page out at the stage's width is what that screen would
     show, and min() keeps a 760px window's Mobile the 390px phone
     rather than a 760px tablet. --ds-k is then at least 1, so Mobile is
     never scaled. The cqw resolves where --ds-w is used, inside
     .ds-view, its container. */
  .ds-view { --ds-wm: min(390px, 100cqw); }
  .ds-view__box { --ds-k: clamp(var(--ds-kmin), tan(atan2(100cqw, var(--ds-w))), 1); }
}
/* An explicit Mobile beats the width, at either class and any size. */
.ds-view:has(.ds-view__tab--m input:checked) .ds-view__box { --ds-h: var(--ds-hm); --ds-w: var(--ds-wm); }
/* A widget with a rest height (--ds-hr and --ds-hmr, written by
   previewStyle for a frame whose menus open far below its page) is
   marked data-ds-rest by view.js while no menu in its frame is open.
   The stage then hands the box the rest heights under the names its
   Desktop and Mobile rules read, so either rendering rests short.
   Unmarked, as with scripts off, the box keeps the open height and a
   menu opened in it is in view. */
.ds-view[data-ds-rest] > .ds-view__stage { --ds-h: var(--ds-hr); --ds-hm: var(--ds-hmr); }
/* HTML replaces the frame with its panel, and only then: the radios
   are one group, so one is checked at most. */
.ds-view__code { display: none; margin-block-start: 0; }
.ds-view:has(.ds-view__tab--h input:checked) .ds-view__stage { display: none; }
.ds-view:has(.ds-view__tab--h input:checked) .ds-view__code--h { display: block; }

/* On a phone the stage is the screen's width. The bleed is what sits
   between the widget and the screen's edge: the page column's inline
   padding. Written rather than measured, so a change to the column
   shows up as a sideways scroll in the reflow and phone drives instead
   of a quietly narrower stage. The tabs and the code stay in the text
   column. */
@media (max-width: 799.98px) {
  .ds-view { --ds-bleed: var(--rst-sp-4); margin-inline: calc(-1 * var(--ds-bleed)); }
  .ds-view__tabs, .ds-view__code { margin-inline: var(--ds-bleed); }
  /* Content-box sizing under max-inline-size: 100%: a border here
     would make a full-width box 2px wider than the screen. */
  .ds-view__box { border-inline-width: 0; border-radius: 0; }
}
