:root,
:root[data-theme="dark"] {
  --bg: #0b0d11;
  --panel: #12151c;
  --panel-2: #171b24;
  --line: #242a36;
  --text: #e6e9f0;
  --dim: #8b93a7;
  --accent: #f5b942;
  --accent-2: #6fa8ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  /* the square shell icons: a light fill inside a darker outline, flipped
     for this theme so the pair keeps the same contrast against the panel */
  --ic-line: #9aa3b5;
  --ic-fill: #4d5566;
}

:root[data-theme="light"] {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-2: #f0f2f6;
  --line: #d9dee7;
  --text: #14181f;
  --dim: #5d6678;
  --accent: #c8860a;
  --accent-2: #2563c9;
  --shadow: 0 18px 50px rgba(20, 30, 60, 0.18);
  --ic-line: #596172;
  --ic-fill: #c6ccd8;
}

:root {
  --radius: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

kbd {
  font: 11px var(--mono);
  padding: 0.5px 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
}

/* ------------------------------------------------------------------ header */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
header h1::before { content: "✦"; color: var(--accent); margin-right: 6px; }
/* the title doubles as the way back to the landing page */
header h1 a { color: inherit; text-decoration: none; }
header h1 a:hover { color: var(--accent); }
header a.ghost { text-decoration: none; display: inline-block; }
.spacer { flex: 1; }
.dim { color: var(--dim); }

/*
 * The document, in the corner where the title used to be: its name over what
 * it is made of. Two short lines rather than one long one, so a document with
 * a real name — "13. e₁f₁g₁" — is not pushed off the end by its own solid and
 * groups; both truncate rather than widen, because everything to their right
 * is a control and must keep its place.
 */
#docBar {
  display: flex; flex-direction: column; justify-content: center;
  min-width: 0; max-width: 30ch; line-height: 1.25;
}
#docName {
  font-size: 13px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#docMeta {
  font-size: 10.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.picker {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 9px 3px 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.picker img { width: 24px; height: 24px; border-radius: 50%; background: #fff; object-fit: contain; }
.picker b { color: var(--dim); font-weight: 400; }
.picker:hover { border-color: var(--accent); }

/* ------------------------------------------------------------------ layout */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  /* the column template lives with the splitter rules below, in var form, so
     there is one source of truth the responsive @media block can override */
  gap: 1px;
  background: var(--line);
  /* the positioning context for floating internal windows (workspace.js) */
  position: relative;
}

.stage {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.views {
  flex: 1;
  min-height: 0;
  display: grid;
  /* column template with the splitter rules below (var form), single source */
  gap: 1px;
  background: var(--line);
}

.view { position: relative; min-width: 0; min-height: 0; background: var(--bg); }
.view canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}
/*
 * The strip along the bottom of a view. It used to carry the gesture list and
 * needed a gradient to stay legible over the model; now that the gestures live
 * behind the ? button, all that is left is the hover readout, which is empty
 * most of the time. So the strip itself is transparent and the backdrop moved
 * onto the readout, which wears it only when it has something to say.
 */
.view-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--dim);
  pointer-events: none;
}
/*
 * The readout in the corner of a view: what the pointer is over, and what it
 * belongs to. Bottom LEFT — it used to be pushed right by a margin, which put
 * it where a wide diagram is busiest.
 *
 * Styled as the label that follows the pointer in the solid, because it says
 * the same kind of thing and there is no reason for one figure to answer in
 * two voices. It was accent-colored, which on the light theme is #c8860a: a
 * brown that reads as a warning rather than as an answer, and which collided
 * with the coset swatches sitting beside it.
 */
.hover { color: var(--text); font: 11px/1.5 var(--mono, monospace); }
.hover:not(:empty) {
  padding: 4px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.nogl { display: grid; place-items: center; height: 100%; padding: 20px; color: var(--dim); text-align: center; }

.statusbar {
  flex: none;
  /* the progress bar is absolutely positioned against this */
  position: relative;
  /* a row, so the stop button can sit at the far end while the message grows */
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  font: 11.5px var(--mono);
  color: var(--dim);
}
.statusbar #status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status.busy { color: var(--accent); }
#progress {
  position: absolute; top: -1px; left: 0;
  height: 2px;
  width: calc(var(--frac, 0) * 100%);
  background: var(--accent);
  transition: width 0.12s linear;
}

/* ------------------------------------------------------------------ right panel */

.panel.right {
  background: var(--panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.group { padding: 9px 11px; border-bottom: 1px solid var(--line); }

h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--dim);
}

details.group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.group > summary::-webkit-details-marker { display: none; }
/* the disclosure arrow: small enough to be furniture, big enough to aim at */
details.group > summary::before {
  content: "▸";
  font-size: 15px;
  line-height: 1;
  width: 11px;
  color: var(--dim);
}
details.group[open] > summary::before { content: "▾"; }
details.group > summary:hover h2 { color: var(--text); }
details.group[open] > summary { margin-bottom: 7px; }

/* ---- cells table ---- */

.cells-group { display: flex; flex-direction: column; }
.group-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 7px; }

.cells-wrap {
  flex: none;
  height: 200px;
  min-height: 90px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}
#cells { display: block; width: 100%; height: 100%; }

.info {
  min-height: 16px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.row { display: flex; gap: 5px; flex-wrap: wrap; }
.row + .row { margin-top: 5px; }
.buttons button, .filebtn, .ghost {
  flex: 1 1 auto;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.buttons.tight button { padding: 3px 6px; font-size: 11.5px; }
.buttons button:hover, .filebtn:hover, .ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost { flex: none; }
.ghost.icon { width: 30px; text-align: center; padding: 4px 0; }

.filebtn { display: block; margin-top: 5px; text-align: center; }
.filebtn.inline { margin-top: 0; }
.filebtn input { display: none; }
.buttons button.primary {
  background: color-mix(in srgb, var(--accent) 18%, var(--panel-2));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  font-weight: 600;
}
.note code {
  font: 11px var(--mono);
  padding: 0 3px;
  border-radius: 3px;
  background: var(--panel-2);
}

.field {
  display: flex; align-items: center; gap: 8px;
  margin: 5px 0;
  font-size: 12px;
  color: var(--dim);
}
.field > span { flex: none; min-width: 84px; }
.field > span b { color: var(--accent); font-family: var(--mono); }
.field select, .field input[type="number"] {
  flex: 1; min-width: 0;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-size: 12px;
}
.field input[type="range"] { flex: 1; accent-color: var(--accent); }

/*
 * The symmetry section sizes its controls to their own contents.
 *
 * Everywhere else a field stretches, which is right for a slider or a long
 * list of colorings. Here the contents are short — a group symbol and its
 * order, a shell count of one or two digits — and a menu pulled across the
 * whole panel to hold "I (60)" reads as a text box waiting to be typed in,
 * not as a choice among a few. They may still shrink if the panel is narrow.
 */
#symGroup .field select { flex: 0 1 auto; }
#symGroup .field input[type="number"] { flex: none; width: 4.5em; }

.check {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 0;
  font-size: 12.5px;
  cursor: pointer;
}
.check input { accent-color: var(--accent); }

.note { margin: 6px 0 2px; font-size: 11px; line-height: 1.5; color: var(--dim); }

#cellsString {
  width: 100%;
  margin-top: 6px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
}

/* ------------------------------------------------------------------ dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }

/* The New picker fills its window: a column of source bar, search, chips, the
   scrolling grid, and the footer. The window itself carries the size. */
.cat-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* the New dialog's source bar: the catalog is this dialog's own content,
   the other three hand off to where they already live */
.cat-sources {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 12px 14px 0;
  flex: none;
  font-size: 13px;
}
.cat-sources button.on { color: var(--accent); border-color: var(--accent); opacity: 1; }
.cat-head {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px;
  flex: none;
}
#search {
  flex: 1;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-size: 13px;
}
#search::placeholder { color: var(--dim); }
#search:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }

.cat-chips {
  display: flex; gap: 5px;
  padding: 0 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--dim);
  font: inherit; font-size: 11.5px;
  white-space: nowrap;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

#catalog { flex: 1; overflow-y: auto; padding: 0 14px 14px; }
.scroll { overscroll-behavior: contain; }

.cat h3 {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  margin: 0;
  padding: 12px 2px 6px;
  font-size: 10.5px; font-weight: 650;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--dim);
  background: linear-gradient(var(--panel) 72%, transparent);
}
.cat h3 em { font-style: normal; opacity: 0.6; font-size: 10px; }
.cat h3::after {
  content: ""; flex: 1; height: 1px;
  background: var(--line);
}

/*
 * The specimen grid: thumbnails only, names live in the footer.
 *
 * 128px to the tile, and the 10px gap that goes with it, so a solid here is
 * the same size as a document in the Files window — the two shelves of
 * pictures are read the same way, and one of them showing stamps while the
 * other showed postcards was the only thing telling them apart.
 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 128px);
  gap: 10px;
  /* fixed tiles leave a remainder; split it evenly rather than banking
     it all against the right edge, where it reads as a missing column */
  justify-content: center;
}

.poly {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.09s ease, border-color 0.09s ease, box-shadow 0.09s ease;
}
.poly img {
  width: 100%; height: 100%;
  display: block;
  object-fit: contain;
}
:root[data-theme="dark"] .poly { filter: brightness(0.9); }
.poly:hover, .poly:focus-visible {
  border-color: var(--accent);
  transform: translateY(-1px) scale(1.06);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  outline: none;
  filter: none;
  z-index: 2;
  position: relative;
}
.poly.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  filter: none;
}

.cat-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  flex: none;
  min-height: 54px;
}
.cat-foot img {
  width: 34px; height: 34px;
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
  flex: none;
}
.cat-foot-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
#footName { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#footMeta { font-size: 11px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#footCount { margin-left: auto; font-size: 11px; white-space: nowrap; }

/*
 * Help.
 *
 * It was a <dialog>, which brought its own box and its own close button. As an
 * internal window the frame, the title bar and the close button belong to the
 * window, so what is left here is the prose: padding, measure and rhythm. The
 * interior scrolls because help is longer than any height worth opening at,
 * and the max-width keeps the line length readable when the window is dragged
 * wider than prose wants to be.
 */
.help-window .iw-interior {
  padding: 20px 24px 22px;
  line-height: 1.62;
  overflow-y: auto;
}
.help-window .iw-interior > * { max-width: 62ch; }
.help-window h2 { font-size: 18px; text-transform: none; letter-spacing: -0.01em; color: var(--text); margin-bottom: 10px; }
.help-window h3 { margin: 18px 0 6px; font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--dim); }
.help-window ul { padding-left: 18px; margin: 6px 0; }
.help-window li { margin: 6px 0; }
.help-window a { color: var(--accent-2); }

/*
 * The swatch that shows a group's color inside a readout.
 *
 * A blend answers "which cosets?" with a color, and a color is exactly what
 * you cannot read back — three colors mixed in Oklab is not three colors any
 * more. So the readouts name the members and put their colors beside the
 * numbers: the mix on the facet, and what went into it, side by side.
 */
.tipsw {
  display: inline-block; width: 9px; height: 9px; margin-right: 3px;
  border-radius: 2px; border: 1px solid rgba(128, 128, 128, 0.5);
  vertical-align: -1px;
}
.tipdim { color: var(--dim); }

/*
 * What a Colors row is doing, beside its name: a facet count, "in N mixed" for
 * a group that only ever appears inside a blend, or "unused here" for one the
 * figure never mentions. Quiet, because it is an annotation on the name rather
 * than part of it.
 */
.col-use {
  margin-left: 6px; font-style: normal; font-size: 10px;
  color: var(--dim); font-family: var(--mono, monospace);
}
.col-idle { opacity: 0.55; }

/*
 * The animation transport: play/pause, rewind, record, and the turn itself.
 *
 * The buttons are the app's small ghost icons; the slider takes whatever is
 * left, since it is the control being read at a glance while the rest are
 * pressed once. The record dot wears the one warning color in the app, which
 * is what a record button is for.
 */
.anim-transport { display: flex; align-items: center; gap: 6px; }
.anim-transport .icon { flex: none; font-size: 13px; line-height: 1; }
.anim-transport .icon.rec { color: #d1494a; }
.anim-transport .icon.rec:disabled { color: var(--dim); }
.anim-transport input[type="range"] { min-width: 60px; }
#animClock { flex: none; font-size: 11px; min-width: 3.4em; text-align: right; }

/* the key to the Cells bar colors */
.legend {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 7px;
  font-size: 10.5px;
  color: var(--dim);
}
.legend-label { letter-spacing: 0.04em; text-transform: uppercase; font-size: 9.5px; }
.legend-item { display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono); }
.legend-item i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }
.note a { color: var(--accent-2); text-decoration: none; }
.note a:hover { text-decoration: underline; }

/* the Cells shortcut key — one line per gesture, compact */
.note.keys { list-style: none; margin: 5px 0 3px; padding: 0; }
.note.keys li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 1.5px 0;
  white-space: nowrap;
}
.note.keys kbd { flex: none; }

/* ------------------------------------------------ draggable pane splitters */

main { grid-template-columns: minmax(0, 1fr) 6px var(--panel-w, 322px); }
.views { grid-template-columns: var(--views-a, 1fr) 6px var(--views-b, 1fr); }

.splitter {
  background: var(--line);
  cursor: col-resize;
  position: relative;
  transition: background 0.12s ease;
}
.splitter::after {                 /* a fatter invisible grab area */
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.splitter:hover, .splitter.dragging { background: var(--accent); }

/* ------------------------------------------------ always-visible view tools */

.view { position: relative; }
.view-tools {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 5px;
  z-index: 5;
}
/*
 * Icons rather than the words "fit" and "home".
 *
 * These sit on top of the picture, and two words of text over a solid is
 * clutter in the one place the eye is meant to be. The icons say the same thing
 * in less ink, and the title carries the full sentence for anyone who wants it —
 * which is why the titles now name the action too, the visible word being gone.
 */
.view-tools button,
.buttons.icons button {
  width: 26px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  flex: none;
}
/* the orientation menu wears the same skin as the buttons beside it */
.view-orient {
  height: 24px;
  padding: 0 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--dim);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  flex: none;
}
.view-orient:hover { color: var(--accent); border-color: var(--accent); }
/* the blank option means "not on a standard view" — keep the box from jumping */
.view-orient { min-width: 44px; }

/*
 * One rule for every icon in the app, wherever the button lives.
 *
 * `stroke: currentColor` is the whole trick: an icon then follows its button's
 * color through hover, disabled and both themes without a second rule
 * anywhere. Shapes that need to read as *filled* — a selected shell in the
 * cells icons — carry class="on" and swap the two.
 */
svg.ic {
  width: 15px;
  height: 15px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg.ic .on { fill: currentColor; stroke: currentColor; }

/*
 * The four shell icons are the exception to currentColor: one square, with the
 * third of it that is selected filled. They are read against each other rather
 * than against the button, so the pair of grays is fixed — a light fill inside
 * a darker outline — and only flips with the theme.
 */
/* 1.6 is what every other icon strokes at, and the square sits beside them */
svg.sq .edge { fill: none; stroke: var(--ic-line); stroke-width: 1.6; }
svg.sq .fill { fill: var(--ic-fill); stroke: none; }
/* the ? is a character, not a path, so it needs the weight the icons do not */
.view-tools button.glyph,
.buttons.icons button.glyph { font-weight: 600; line-height: 1; }
.view-tools button:hover,
.buttons.icons button:hover { border-color: var(--accent); color: var(--accent); }
.view-tools button[aria-expanded="true"],
.buttons.icons button[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
/*
 * Disabled applied only to `.buttons` before, so undo and redo were dimmed in
 * the cells row and looked perfectly live in the two views, where they had just
 * been added.
 */
.view-tools button:disabled,
.buttons.icons button:disabled { opacity: 0.35; cursor: default; }
.view-tools button:disabled:hover,
.buttons.icons button:disabled:hover { border-color: var(--line); color: var(--dim); }

/*
 * The gesture list, shown on request rather than printed under every view.
 *
 * Anchored under the tool row it belongs to, capped in width so the lines break
 * where they read best, and dismissed by clicking anywhere on it — the whole
 * panel is the target, which is easier to hit than any close button and is what
 * you would try first.
 */
.view-help {
  position: absolute;
  top: 38px;
  left: 8px;
  z-index: 6;
  max-width: min(330px, calc(100% - 16px));
  padding: 9px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.13);
  font-size: 12px;
  line-height: 1.65;
  cursor: pointer;
}
.view-help[hidden] { display: none; }
.view-help > div { white-space: normal; }
.view-help .what { color: var(--dim); margin-bottom: 4px; }
.view-help .dismiss {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 11px;
}

/* -------------------------------------------------- add / remove, one palette

   Green adds, red carves, and the pair reads the same in the 3-D view, in the
   diagram and in the Cells table. Keeping the words in the captions the same
   color as the outline that appears under the pointer is what ties the three
   together — before, each view had its own idea of what a highlight looked like.
   Kept identical in light and dark: these are signal colors, not decoration. */
:root { --add: #2fa855; --rem: #d63c3c; }
:root[data-theme="dark"] { --add: #4acb70; --rem: #f05454; }
.add { color: var(--add); }
.rem { color: var(--rem); }

/*
 * A boxed group inside a panel section: a thin frame and a small legend, so
 * a handful of related controls read as one thing rather than as a run of
 * loose rows. `.subsection` is the general case; the two older names are
 * kept because the markup and its comments still speak of them.
 */
.subsection,
.edge-kinds,
.sym-elems {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px 6px;
  margin: 6px 0 4px;
}
.subsection legend,
.edge-kinds legend,
.sym-elems legend { font-size: 10.5px; color: var(--dim); padding: 0 4px; }
.subsection .check,
.edge-kinds .check,
.sym-elems .check { margin: 2px 0; }

/* the two kinds of edge: a checkbox, then its color and weight on one row */
.edge-style {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px 18px;      /* indented under the checkbox it belongs to */
}
.edge-style input[type="color"] {
  width: 26px; height: 18px; padding: 0;
  border: 1px solid var(--line); border-radius: 4px;
  background: none; cursor: pointer; flex: none;
}
.edge-style input[type="range"] { flex: 1; min-width: 0; }

/*
 * One control line: a switch and the two or three settings that belong to
 * it, side by side instead of stacked. A boxed subsection of five rows and
 * a legend was taller than the thing it was describing.
 */
.ctl-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.ctl-line.wrap { flex-wrap: wrap; row-gap: 2px; column-gap: 10px; }
.ctl-line .grow { flex: 1; min-width: 0; }
.ctl-line input[type="color"] {
  width: 26px; height: 18px; padding: 0; flex: none;
  border: 1px solid var(--line); border-radius: 4px;
  background: none; cursor: pointer;
}
/* a weight typed rather than dragged: narrow enough to share the line */
.ctl-line input[type="number"] {
  flex: none; width: 3.9em;
  padding: 2px 4px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 12px;
}
/*
 * A two-way choice on the same line: narrow, and allowed to shrink before
 * the label does, since "lines" and "cylinders" stay readable clipped and a
 * half-hidden "facet edges" does not.
 */
.ctl-line select {
  flex: 0 1 auto; min-width: 0; max-width: 8.2em;
  padding: 2px 4px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 11.5px;
}
/* the label gives way first, and says so with an ellipsis */
.ctl-line .check.grow { overflow: hidden; }
.ctl-line .check.grow > :last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edge-style b { font-variant-numeric: tabular-nums; color: var(--dim); font-weight: 500; min-width: 20px; }
.sw {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  vertical-align: baseline; margin-right: 1px;
}
.sw.ax { background: #40b8f2; }
.sw.mi { background: #6be0cc; }
.sw.im { background: #b873f2; }

/* undo / redo sit with the other cell buttons and gray out when there is
   nothing to undo — the disabled state is the only affordance saying whether a
   change has been made yet */
.buttons button.icon { width: 26px; padding: 4px 0; text-align: center; }
/*
 * The cells row is all icons now, and matches the tool buttons over the views:
 * same 26x24 square, same muted color, same translucent panel.
 *
 * It did neither before. `.buttons button` stretches to fill its row, so these
 * came out wider than square; and it paints `color: var(--text)`, the full
 * strength text color, so icons drawn in currentColor came out near black
 * beside the same icons in a view, which use `--dim`. Two rows of buttons doing
 * comparable jobs should not look like they come from different programs.
 */
.buttons.icons { gap: 5px; }
/* the cells help hangs under its own group, the way each view's hangs under its tools */
.cells-group { position: relative; }
.cells-group .view-help { top: 34px; left: 0; right: 0; max-width: none; }
.buttons button:disabled { opacity: 0.35; cursor: default; }
.buttons button:disabled:hover { border-color: var(--line); color: inherit; }

/* the diagram's two toggle colors — gold beneath the plane, blue above */
:root { --below: #b98d10; --above: #2f7cc9; }
:root[data-theme="dark"] { --below: #f5d24d; --above: #4da3f5; }
.below { color: var(--below); }
.above { color: var(--above); }

/* element checkboxes gray out when the group has none of that kind */
.sym-elems .check.off { opacity: 0.4; }
.elem-legend { margin-top: 4px; }
.elem-legend:empty { display: none; }

/* the same three colors the arrows are drawn in, so the label is the key */
.ax-x { color: #e64747; }
.ax-y { color: #5cc75c; }
.ax-z { color: #5c8cf2; }

/*
 * Saving diagrams: what, how it looks, where it goes.
 *
 * The body of an internal window rather than a <dialog>, so it wears the same
 * chrome as the app's other floating panels. The window scrolls its own
 * interior, which is why the padding lives here and not on a fixed height.
 */
.ex-body { padding: 11px 13px 13px; }

/* the Colors panel: one row per group of facets — swatch, name, opacity */
.col-list { padding: 0 13px; max-height: 46vh; overflow-y: auto; }
.col-row {
  display: grid; grid-template-columns: 28px 1fr 84px 30px;
  gap: 8px; align-items: center; padding: 3px 0;
}
.col-row input[type="color"] {
  width: 28px; height: 22px; padding: 0; border: 1px solid var(--line);
  border-radius: 4px; background: none; cursor: pointer;
}
.col-name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-alpha { width: 84px; }
.col-pct {
  font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums;
  color: var(--dim); font-weight: 500;
}
.pushright { margin-left: auto; }
.ex-body .note { margin: 0 0 4px; }
.ex-section {
  border-top: 1px solid var(--line);
  padding-top: 9px; margin-top: 11px;
}
.ex-section > b { display: block; margin-bottom: 6px; }
.ex-section label { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.ex-grid {
  display: grid; gap: 7px 14px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.ex-grid label { flex-direction: column; align-items: stretch; gap: 3px; }
.ex-grid select { width: 100%; }
.ex-section .row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }

/*
 * The four kinds of ink: a switch, a name, a weight, a readout, one per row —
 * so the eye runs down the switches to see what is on, and down the numbers to
 * compare weights, without either column being interrupted by the other.
 */
.ex-kinds { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 4px; }
.ex-kind {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: auto 8.5em 1fr 3.6em;
  margin: 0; font-size: 12.5px;
}
.ex-kind > span { color: var(--text); white-space: nowrap; }
.ex-kind input[type="range"] { width: 100%; min-width: 60px; }
.ex-kind > b { font-weight: 500; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ex-kind > b.dim { color: var(--dim); }
.ex-kind input:disabled { opacity: 0.4; }
.ex-kind-sel { grid-column: 3 / span 2; width: 100%; }

/*
 * One card per kind of face: the picture that would be written, and the tick
 * that says whether to write it. Each card is the file, so the art sits on the
 * background it will be saved on rather than on the panel's.
 */
.ex-picks-head { display: flex; align-items: baseline; gap: 8px; }
.ex-picks-head #exPicksCount { flex: 1; }
.ex-picks-head button { padding: 2px 7px; font-size: 11px; }
.ex-picks {
  display: grid; gap: 10px; margin: 8px 0 2px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
/* one diagram is not a grid — give it the room the old single preview had */
.ex-picks.one { grid-template-columns: minmax(0, 240px); justify-content: center; }
/* .ex-section label is a flex row; a card is a column, so it must say so louder */
.ex-picks .ex-pick { display: block; margin: 0; cursor: pointer; }
.ex-pick-art {
  display: block; background: #fff; aspect-ratio: 1;
  border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
.ex-pick-art svg { width: 100%; height: 100%; display: block; }
.ex-pick-cap {
  display: flex; align-items: center; gap: 5px; justify-content: center;
  margin-top: 4px; font-size: 11.5px;
}
.ex-pick-cap b { font-weight: 550; }
.ex-pick-sub {
  display: block; text-align: center; font-size: 10px; color: var(--dim);
  line-height: 1.35;
}
/* a face the figure never reaches: shown, but plainly not a file */
.ex-pick.blank .ex-pick-art { background: repeating-linear-gradient(
  45deg, transparent, transparent 6px, var(--line) 6px, var(--line) 7px); opacity: 0.5; }
.ex-pick.blank .ex-pick-cap { opacity: 0.55; }
#exWhere { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ex-body .note.warn { color: var(--accent); }
#exScale, #exWidth, #exHeight { width: 68px; }
#exName { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.ex-body select:disabled, .ex-body input:disabled { opacity: 0.45; }
/*
 * Export and Cancel stay put while the rest scrolls. The window can be resized
 * to anything and the list of choices is longer on a solid with several kinds
 * of face, so the buttons cannot be trusted to be on screen — sticky is what
 * makes the dialog work at any height instead of at one.
 */
.ex-body .row.buttons {
  position: sticky; bottom: 0;
  justify-content: flex-end; gap: 6px;
  margin-top: 12px; padding: 9px 0 2px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

/* the plane editor: rows on the left, the preview on the right */
.planes-body { padding: 12px 14px 14px; }
.planes-layout { display: grid; grid-template-columns: 1fr 280px; gap: 14px; }
.planes-right { min-width: 0; }
#planesPreview {
  width: 100%; height: 300px; display: block;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  touch-action: none;
}
/* chip · numbers · factor · group · orbit · delete */
.planes-head, .plane-row {
  display: grid;
  grid-template-columns: 12px 1fr 58px 92px 40px 24px;
  gap: 6px; align-items: center;
}
.planes-head {
  font-size: 10.5px; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 4px; padding: 0 2px;
}
#planesRows { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.plane-row .plane-chip { width: 10px; height: 10px; border-radius: 3px; }
.plane-row .plane-nums {
  width: 100%; box-sizing: border-box; min-width: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 7px; font-size: 11.5px;
}
.plane-row .plane-factor {
  width: 100%; box-sizing: border-box; min-width: 0; text-align: right;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 6px; font-size: 11.5px;
}
.plane-row.bad .plane-nums, .plane-row.bad .plane-factor { border-color: #c0504d; }
.plane-row .plane-group { width: 100%; font-size: 11.5px; }
.plane-row .plane-orbit { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); }
.plane-row .plane-del {
  border: none; background: none; color: var(--dim); cursor: pointer;
  font-size: 12px; padding: 2px;
}
.plane-row .plane-del:hover { color: #c0504d; }
.planes-tools { margin-top: 8px; align-items: center; }
.planes-tools select { max-width: 190px; }
@media (max-width: 720px) {
  .planes-layout { grid-template-columns: 1fr; }
  #planesPreview { height: 200px; }
}

/* Narrow screens: the header is a flex row and its children overrun a phone,
   pushing the theme toggle and the help button off-screen where they cannot be
   reached. Wrapping the row instead would make it taller and break the
   scroll-margin the section anchors depend on, so secondary links marked
   `optional` are hidden below 650px. Same rule already used on historical.html. */
@media (max-width: 650px) {
  .doc-head .optional, header .optional { display: none; }
}

/* ------------------------------------------------------------ windowed mode
 *
 * workspace.js moves the panel subtrees into floating internal windows and
 * adds `windowed` to <body>. The docked grid stays in the markup — these
 * rules only quiet it down: one column, the emptied side panel and both
 * splitters hidden, and the (now childless) views grid left as the desktop
 * the windows float over. The statusbar deliberately stays docked at the
 * bottom — status and progress belong to the app, not to any one window.
 */

body.windowed main { grid-template-columns: minmax(0, 1fr) !important; }
body.windowed .panel.right,
body.windowed .splitter { display: none; }
body.windowed .views { background: var(--bg); }

/* the sizing contract a .view expects from its host: a positioned box it can
   fill — the same contract the docked grid cell and the tutorial figures give */
.iw-interior > .view { position: absolute; inset: 0; }

/* the cells group must flex inside a resizable window; its docked 200px
   height stays untouched for the docked panel */
.iw-interior > .cells-group {
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  border-bottom: none;
}
.iw-interior > .cells-group .cells-wrap { height: auto; flex: 1; min-height: 90px; }

/* header buttons that hold an svg icon rather than a text glyph */
.win-btn svg.ic { display: block; margin: 0 auto; }
button[aria-pressed="true"].win-btn { color: var(--accent); border-color: var(--accent); }

/* The windows menu is live in both modes: docked it still lists the preset and
   file browsers, which float over the docked layout just the same. */
#winMenu { display: inline-block; }

/* ---------------------------------------------------------------- responsive
 *
 * One responsive section, at the very end so it wins.
 *
 * This used to be scattered up the file, and half of it was dead: the docked
 * grid was declared plain near the top AND again in var form lower down for the
 * splitters, and the later declaration -- being later, at equal specificity --
 * beat the media queries sitting above it. So the views never actually stacked
 * on a narrow screen. The grid now has one home (the splitter rules), and these
 * queries come after it, so they take effect.
 *
 * The panel splitters are grid children (column 2 of their track); to collapse
 * a track they must be display:none, not just visually hidden.
 */

@media (max-width: 1080px) {
  /* the two views stack instead of sitting side by side */
  .views { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #splitViews { display: none; }
}

@media (max-width: 900px) {
  /* the side panel drops below the stage */
  main { grid-template-columns: 1fr; }
  #splitPanel { display: none; }
}

@media (max-width: 780px) {
  /* a phone: the whole thing is one scrolling column, and windowed mode
     (and its toggle) are gone -- floating panels here are a worse scroll */
  body { overflow: auto; }
  main { grid-auto-rows: min-content; }
  .stage { min-height: 60dvh; }
  /*
   * Not 50dvh each: the canvases take every touch gesture for themselves
   * (orbit, pan — touch-action: none), so if they and the header tile the
   * whole screen there is no surface left that can scroll the page, and the
   * panel below might as well not exist (issue #15: "can't scroll down or
   * click anything"). At 40 the statusbar and the first ~90px of the panel
   * show inside the first screen — visibly more page, and room to scroll
   * from.
   */
  .views { grid-template-rows: 40dvh 40dvh; }
  .panel.right { max-height: none; }
  /*
   * The name stays; what it is made of is the first thing to go — the picker
   * beside it still names the solid. On a phone the header has no slack, and
   * left to itself flex takes the whole squeeze out of the document name,
   * which is the one thing here that cannot be read anywhere else. So the name
   * keeps a floor and the picker gives up the room, ellipsis first, thumbnail
   * last.
   */
  #docMeta, #modeBtn { display: none; }
  #docBar { min-width: 7ch; }
  .picker { min-width: 0; }
  #pickName { overflow: hidden; text-overflow: ellipsis; }
}

/*
 * The document buttons on one line. They are a close-packed row of related
 * verbs, so this row alone trims its padding and its column gap to keep them
 * together at the docked panel's usual width. Anywhere narrower they still
 * wrap, which is what should happen.
 *
 * The row gap is deliberately LARGER than the column gap. A wrapped line
 * separated by exactly the column gap reads as crowded — at some zoom levels
 * the borders of two lines land on the same device pixel and the second row
 * looks like it is sitting on the first. Giving the lines a little more air
 * than the buttons have between them removes the question.
 */
.row.buttons.files { column-gap: 4px; row-gap: 6px; }
.row.buttons.files button { padding: 3px 4px; }

/*
 * Buttons that keep their own width.
 *
 * `.buttons button` is `flex: 1 1 auto`, which fills the row — right for a
 * dialog's pair of actions, wrong for a row of independent verbs: when the
 * row wraps, the one or two buttons left on the last line stretch across the
 * whole panel and stop looking like the same kind of thing as the line above.
 * These keep the width their text asks for and may still shrink if a panel
 * gets narrower than the row.
 */
.row.buttons.nogrow button { flex: 0 1 auto; }

/*
 * The stop button in the status bar, shown only while an arrangement is being
 * intersected. It sits at the right-hand end so the growing progress bar and
 * the plane count never push it about.
 */
#stopBuild {
  margin-left: auto;
  flex: none;
  padding: 1px 9px 2px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-2);
  color: var(--dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
#stopBuild:hover { border-color: var(--bad, #c0392b); color: var(--bad, #c0392b); }

/* the turntable's axis field: monospace, and plainly wrong when it is wrong */
#animAxis { flex: 1; min-width: 0; font: 12px var(--mono); }
.field input.invalid { border-color: #c0392b; }

/* ---- coset painting ---------------------------------------------------- */
.paint-bar {
  position: absolute; top: 44px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  max-width: 92%; padding: 5px 7px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 4;
}
/* the explicit display above would otherwise beat the UA's [hidden] rule */
.paint-bar[hidden] { display: none; }
.paint-sw {
  width: 20px; height: 20px; padding: 0; border-radius: 5px;
  border: 1px solid var(--line); cursor: pointer;
}
.paint-word {
  font-size: 11px; padding: 2px 7px; border-radius: 5px;
  border: 1px solid var(--line); background: transparent;
  color: var(--text); cursor: pointer;
}
.paint-sw.sel, .paint-word.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.paint-bar .gap { width: 4px; }
#paintBtn[aria-pressed="true"] { color: var(--accent); }

/* the placement rig's toggle, lit like the paint brush while it is down */
#texPlace[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
