/* Manual workspace: a Desmos-style editor (expression list left, one large graph right).
   Owned by workspace.rs, ws_list.rs, ws_canvas.rs and tablegrid.rs. Tokens come from style.css
   ("paper and ink"): the list is the paper, the graph plate stays white in both themes. */

/* Panes kept mounted and toggled with the hidden attribute. */
.side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-pane[hidden], .right[hidden] { display: none !important; }
.side-pane > .panel { flex: 1; min-height: 0; }

/* ---------- Expression list ---------- */

.ws-list {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  background: var(--surface);
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.ws-list-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s-1);
  padding: var(--s-2); background: var(--panel); border-bottom: 1px solid var(--border);
}
.ws-name {
  flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; color: var(--text);
  text-overflow: ellipsis;
}
.ws-name:hover { background: var(--sunken); }
.ws-name:focus-visible { background: var(--surface); border-color: var(--border-strong); outline-offset: 1px; }

.ws-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 4px 10px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.ws-btn:hover:not(:disabled) { background: var(--sunken); color: var(--text); }
.ws-btn.icon { width: 32px; padding: 0; }
.ws-btn.active, .ws-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.ws-btn.primary { background: var(--accent); color: var(--accent-ink); }
.ws-btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); color: var(--accent-ink); }
.ws-add-btn { background: var(--accent); color: var(--accent-ink); padding: 4px 12px 4px 8px; }
.ws-add-btn:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); filter: brightness(1.08); }
.ws-add, .ws-menu-wrap, .ws-pop-wrap { position: relative; }

.ws-scrim { position: fixed; inset: 0; z-index: 35; background: transparent; }
.ws-menu {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 210px;
  display: flex; flex-direction: column; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2);
}
.ws-menu.right { left: auto; right: 0; }
.ws-row-menu { left: auto; right: 0; }
.ws-menu-item {
  text-align: left; padding: 8px 12px; border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--text); font-size: var(--fs-sm); white-space: nowrap;
}
.ws-menu-item:hover, .ws-menu-item:focus-visible { background: var(--accent-soft); color: var(--accent-text); outline-offset: -2px; }
.ws-menu-item.danger { color: var(--danger); }
.ws-menu-item.danger:hover { background: var(--danger-soft); }

.ws-rows { display: flex; flex-direction: column; }

.ws-row { position: relative; border-bottom: 1px solid var(--border); background: var(--surface); }
.ws-row.dragging { z-index: 10; box-shadow: var(--shadow-2); opacity: 0.95; }
.ws-row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.ws-row-main { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; align-items: stretch; min-height: 52px; }

/* The gutter: row number, drag grip and the colour dot. It turns accent when the row is active. */
.ws-gutter {
  position: relative; display: flex; align-items: center; justify-content: center;
  background: var(--panel); border-right: 1px solid var(--border); color: var(--text-3);
  transition: background var(--dur-1) var(--ease);
}
.ws-row:hover > .ws-row-main > .ws-gutter { background: var(--sunken); }
.ws-row:focus-within > .ws-row-main > .ws-gutter, .ws-row.open > .ws-row-main > .ws-gutter { background: var(--accent); color: var(--accent-ink); }
/* Desmos' selected-row outline: a hairline of accent round the whole row. */
.ws-row:focus-within::after, .ws-row.open::after {
  content: ""; position: absolute; inset: -1px 0 0; pointer-events: none; z-index: 2;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.ws-num { position: absolute; left: 5px; top: 4px; font-size: 10.5px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.ws-grip {
  position: absolute; left: 0; bottom: 0; width: 18px; height: 22px; padding: 0; border: 0; border-radius: 0 var(--r-sm) 0 0;
  background: transparent; color: inherit; cursor: grab; touch-action: none; opacity: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.ws-grip svg { fill: currentColor; stroke: none; }
.ws-row:hover .ws-grip, .ws-row:focus-within .ws-grip, .ws-grip:focus-visible { opacity: 0.8; }
.ws-row.dragging .ws-grip { cursor: grabbing; }
/* The colour badge: a filled disc with Desmos' white curve glyph; hidden rows show a hollow ring
   with the glyph in the row colour. */
.ws-dot {
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 1px rgb(0 0 0 / 0.12);
  display: inline-flex; align-items: center; justify-content: center; color: var(--accent-ink);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.ws-dot span {
  display: block; width: 18px; height: 18px; background: #fff;
  -webkit-mask: var(--glyph-curve) center / contain no-repeat; mask: var(--glyph-curve) center / contain no-repeat;
}
.ws-dot:hover { transform: scale(1.08); }
.ws-dot:active { transform: var(--press); }
.ws-dot[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.ws-dot.off { background: var(--surface); box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 2px var(--c); }
.ws-dot.off span { background: var(--c); opacity: 0.75; }
.ws-dot:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 50%; }
:root { --glyph-curve: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 15.5c2.6 0 3.2-8.5 6-8.5s3.4 10 6 10 3.4-8.5 6-8.5' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E"); }
.ws-dot.action { --c: var(--text-2); border-width: 2px; background: var(--surface); color: var(--text-2); }
.ws-row:focus-within .ws-dot.action { color: var(--text-2); }
.ws-glyph { display: inline-flex; color: inherit; opacity: 0.8; }

.ws-body { min-width: 0; display: flex; align-items: center; padding: 4px 0 4px 2px; }
.ws-row.in-folder .ws-body { padding-left: 18px; box-shadow: inset 14px 0 0 -12px var(--border-strong); }
.ws-body .mathfield-host { flex: 1; min-width: 0; min-height: 40px; }
.ws-body math-field, .ws-body .mathfield-fallback {
  min-height: 40px; border: 0; border-radius: 0; background: transparent; padding: 6px 8px;
  font-size: 1.15rem;
}
.ws-body math-field:focus-within, .ws-body .mathfield-fallback:focus { outline: 0; }
/* MathLive's own menu is off for rows; the keyboard toggle shows on the active row (always on touch). */
.ws-body math-field::part(menu-toggle) { display: none; }
.ws-body math-field::part(virtual-keyboard-toggle) { visibility: hidden; }
.ws-body math-field:focus-within::part(virtual-keyboard-toggle) { visibility: visible; }
.ws-note, .ws-folder-title {
  flex: 1; min-width: 0; resize: none; border: 0; background: transparent; padding: 10px 8px;
  font: inherit; font-size: var(--fs-md); color: var(--text-2); line-height: 1.35; field-sizing: content; min-height: 40px;
}
.ws-note:focus, .ws-folder-title:focus { outline: 0; }
.ws-folder-head { display: flex; align-items: center; flex: 1; min-width: 0; }
.ws-folder-title { font-weight: 600; color: var(--text); }
.ws-caret svg { transition: transform var(--dur-1) var(--ease); }
.ws-caret.open svg { transform: rotate(90deg); }
.ws-table-title { padding: 0 8px; font-weight: 600; color: var(--text-2); font-size: var(--fs-sm); }

.ws-tools { display: flex; align-items: center; gap: 0; padding: 0 4px; opacity: 0; transition: opacity var(--dur-1) var(--ease); }
.ws-row:hover .ws-tools, .ws-row:focus-within .ws-tools, .ws-row.open .ws-tools { opacity: 1; }
.ws-tools .ws-btn.icon { width: 30px; min-height: 30px; color: var(--text-3); }
.ws-tools .ws-btn.icon:hover { color: var(--text); }
.ws-tools .ws-btn.active { color: var(--accent-text); opacity: 1; }
.ws-tools .ws-eye[aria-pressed] { background: transparent; color: var(--text-3); }
.ws-tools .ws-eye[aria-pressed="false"] { color: var(--danger); }
.ws-tools .ws-eye:hover { background: var(--sunken); color: var(--text); }
.ws-del:hover { color: var(--danger) !important; background: var(--danger-soft) !important; }
.ws-row.hidden-row .ws-body { opacity: 0.6; }

.ws-diag {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 0 8px 8px 58px; padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--warn-soft); color: var(--warn-text); font-size: var(--fs-sm); line-height: 1.35;
}
.ws-slider .ws-diag { margin-left: 0; }
.ws-diag svg { flex-shrink: 0; }
.ws-chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--accent-text);
  border-radius: var(--r-pill); padding: 2px 10px; font-size: var(--fs-xs); font-weight: 700;
}
.ws-chip:hover { background: var(--accent-soft); }
.ws-info { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; padding: 0 12px 8px 58px; color: var(--text-2); font-size: var(--fs-sm); }
.ws-info-val { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: var(--r-sm); background: var(--sunken); }
.static-math-host { display: inline-block; }
.static-math-host math-field.static-math { border: 0; background: transparent; padding: 0; min-height: 0; font-size: var(--fs-md); display: inline-block; width: auto; }
.ws-info[data-kind="regression"] { justify-content: flex-start; }
.ws-reg { display: flex; flex-wrap: wrap; gap: 4px 14px; font-family: var(--mono); font-size: var(--fs-xs); color: var(--text); }
.ws-check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); min-height: 28px; }
.ws-check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Style panel under a row */
.ws-style {
  margin: 0 8px 10px 58px; padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-3);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.ws-style-sec { display: flex; flex-direction: column; gap: var(--s-2); }
.ws-show { font-weight: 600; color: var(--text); }
.ws-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.ws-swatch {
  width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--surface);
  background: var(--c); box-shadow: 0 0 0 1px var(--border-strong); color: var(--text-2); font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
}
.ws-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.ws-swatch.auto { background: conic-gradient(#c74440, #fa7e19, #388c46, #2d70b3, #6042a6, #c74440); color: #fff; text-shadow: 0 0 2px #000; }
.ws-swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); cursor: pointer; }
.ws-swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.ws-swatch.custom:focus-within { box-shadow: 0 0 0 2px var(--focus); }
.ws-seg { display: inline-flex; align-self: flex-start; padding: 3px; gap: 2px; background: var(--sunken); border-radius: var(--r-md); }
.ws-seg-btn {
  min-width: 36px; min-height: 30px; padding: 3px 10px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
}
.ws-seg-btn:hover { color: var(--text); background: var(--border); }
.ws-seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-1); }
.ws-range { display: grid; grid-template-columns: 80px minmax(0, 1fr) 44px; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); }
.ws-range input { width: 100%; accent-color: var(--accent); }
.ws-range output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.ws-input {
  width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm);
}
.ws-select { padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); font-size: var(--fs-sm); }
.ws-link { align-self: flex-start; border: 0; background: transparent; color: var(--accent-text); font-size: var(--fs-sm); font-weight: 600; padding: 2px 0; }
.ws-link:hover { text-decoration: underline; }

/* Sliders */
.ws-sliders, .ws-orphans { display: flex; flex-direction: column; }
.ws-orphans { border-bottom: 1px solid var(--border); }
.ws-slider { padding: 6px 12px 8px 58px; display: flex; flex-direction: column; gap: 4px; }
.ws-orphans .ws-slider { padding-left: 12px; }
.ws-slider-top { display: flex; align-items: center; gap: 6px; }
.ws-play { width: 28px !important; min-height: 28px !important; border-radius: 50% !important; border: 1.5px solid var(--border-strong) !important; color: var(--text-2); }
.ws-play:hover { border-color: var(--accent) !important; color: var(--accent-text); }
.ws-play.active { background: var(--accent) !important; border-color: var(--accent) !important; color: var(--accent-ink) !important; }
.ws-slider-name { font-family: var(--font-math); font-style: italic; font-size: 1.15rem; color: var(--text); padding-left: 2px; }
.ws-slider-val {
  width: 7.5em; padding: 3px 6px; border: 1px solid transparent; border-bottom-color: var(--border-strong); border-radius: 0;
  background: transparent; color: var(--text); font-size: var(--fs-md); font-variant-numeric: tabular-nums;
}
.ws-slider-val:focus { outline: 0; border-color: var(--focus); border-radius: var(--r-sm); }
.ws-slider-track { display: grid; grid-template-columns: 4.5em minmax(0, 1fr) 4.5em; align-items: center; gap: 6px; }
.ws-slider-track input[type="range"] { width: 100%; }

/* One range control for sliders, style panels and the slice: a hairline track and a Desmos-style
   knob (accent dot in a white ring, a soft halo while it is held). */
.ws-slider-track input[type="range"], .ws-range input[type="range"], .ws-slice-range {
  -webkit-appearance: none; appearance: none; height: 22px; margin: 0; background: transparent; cursor: pointer;
  --knob: 16px;
}
.ws-slider-track input[type="range"]::-webkit-slider-runnable-track, .ws-range input[type="range"]::-webkit-slider-runnable-track, .ws-slice-range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--border);
}
.ws-slider-track input[type="range"]::-moz-range-track, .ws-range input[type="range"]::-moz-range-track, .ws-slice-range::-moz-range-track {
  height: 4px; border-radius: 2px; background: var(--border);
}
.ws-slider-track input[type="range"]::-moz-range-progress, .ws-range input[type="range"]::-moz-range-progress, .ws-slice-range::-moz-range-progress {
  height: 4px; border-radius: 2px; background: var(--accent);
}
.ws-slider-track input[type="range"]::-webkit-slider-thumb, .ws-range input[type="range"]::-webkit-slider-thumb, .ws-slice-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: var(--knob); height: var(--knob); margin-top: calc((4px - var(--knob)) / 2);
  border-radius: 50%; border: 3px solid var(--surface); background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgb(0 0 0 / 0.25);
  transition: box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.ws-slider-track input[type="range"]::-moz-range-thumb, .ws-range input[type="range"]::-moz-range-thumb, .ws-slice-range::-moz-range-thumb {
  width: calc(var(--knob) - 6px); height: calc(var(--knob) - 6px);
  border-radius: 50%; border: 3px solid var(--surface); background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgb(0 0 0 / 0.25);
}
.ws-slider-track input[type="range"]:hover::-webkit-slider-thumb, .ws-range input[type="range"]:hover::-webkit-slider-thumb, .ws-slice-range:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 6px var(--accent-soft);
}
.ws-slider-track input[type="range"]:active::-webkit-slider-thumb, .ws-range input[type="range"]:active::-webkit-slider-thumb, .ws-slice-range:active::-webkit-slider-thumb {
  transform: scale(1.12); box-shadow: 0 0 0 1px var(--accent), 0 0 0 8px var(--accent-soft);
}
.ws-slider-track input[type="range"]:focus-visible, .ws-range input[type="range"]:focus-visible, .ws-slice-range:focus-visible { outline: 0; }
.ws-slider-track input[type="range"]:focus-visible::-webkit-slider-thumb, .ws-range input[type="range"]:focus-visible::-webkit-slider-thumb, .ws-slice-range:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}
.ws-slider-track input[type="range"]:focus-visible::-moz-range-thumb, .ws-range input[type="range"]:focus-visible::-moz-range-thumb, .ws-slice-range:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}
.ws-bound {
  width: 100%; min-width: 0; padding: 2px 4px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text-3); font-size: var(--fs-xs); text-align: center; font-variant-numeric: tabular-nums;
}
.ws-bound:hover { border-color: var(--border); }
.ws-bound:focus { outline: 0; border-color: var(--focus); color: var(--text); background: var(--surface); }
.ws-slider-more summary { font-size: var(--fs-xs); color: var(--text-3); cursor: pointer; width: max-content; padding: 2px 0; }
.ws-slider-opts { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 4px; font-size: var(--fs-xs); color: var(--text-2); }
.ws-slider-opts .ws-bound { width: 5em; border-color: var(--border); }

/* Tables */
.tbl { padding: 0 12px 10px 58px; display: flex; flex-direction: column; gap: 6px; }
.tbl-scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.tbl-grid { border-collapse: collapse; font-size: var(--fs-sm); }
.tbl-grid th, .tbl-grid td { border: 1px solid var(--border); padding: 0; }
.tbl-grid thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.tbl-rn { width: 2.6em; color: var(--text-3); font-weight: 500; font-size: var(--fs-xs); background: var(--panel); position: relative; text-align: center; }
.tbl-rn .tbl-rm { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }
.tbl-rn:hover .tbl-rm, .tbl-rn .tbl-rm:focus-visible { opacity: 1; background: var(--danger-soft); color: var(--danger); }
.tbl-head-cell { display: flex; align-items: center; position: relative; }
/* Rendered name (x with a subscript) shown over the plain-text input until it is focused. */
.tbl-head:not(:focus) { color: transparent; }
.tbl-head-view { position: absolute; left: 0; top: 0; bottom: 0; width: 6.5em; display: flex; align-items: center; justify-content: center; pointer-events: none; font-family: var(--font-math); font-size: 1rem; color: var(--text); }
.tbl-head-view sub { font-size: 0.7em; font-style: normal; }
.tbl-head:focus + .tbl-head-view { display: none; }
.tbl-cell { width: 6.5em; padding: 6px 8px; border: 0; background: transparent; color: var(--text); font-family: var(--mono); font-size: var(--fs-sm); }
.tbl-head { font-weight: 500; font-family: var(--font-math); font-style: italic; font-size: 1rem; text-align: center; }
.tbl-cell:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: var(--surface); }
.tbl-rm { border: 0; background: transparent; color: var(--text-3); padding: 2px 4px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-sm); }
.tbl-rm:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.tbl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tbl-btn { border: 1px solid var(--border-strong); min-height: 28px; padding: 2px 8px; font-size: var(--fs-xs); }

/* Table glyph in the gutter (each y column has its own colour badge instead). */
.ws-table-glyph { color: var(--text-2); }
.ws-row:focus-within .ws-table-glyph, .ws-row.open .ws-table-glyph { color: var(--accent-ink); }

/* Column colour badge (Desmos: a filled disc with a scatter glyph left of the y header). */
.tbl-grid .tbl-rn { min-width: 2.6em; }
.tbl-head-cell.has-badge { padding-left: 6px; gap: 2px; }
.tbl-head-cell.has-badge .tbl-head-view { left: 32px; }
.tbl-badge {
  flex: none; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12); display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.tbl-badge span {
  display: block; width: 16px; height: 16px; background: #fff;
  -webkit-mask: var(--glyph-scatter) center / contain no-repeat; mask: var(--glyph-scatter) center / contain no-repeat;
}
.tbl-badge:hover { transform: scale(1.08); }
.tbl-badge[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.tbl-badge.off { background: var(--surface); box-shadow: inset 0 0 0 2px var(--c); }
.tbl-badge.off span { background: var(--c); opacity: 0.75; }
.tbl-badge:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:root { --glyph-scatter: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='6' cy='15' r='2.6'/%3E%3Ccircle cx='11' cy='8' r='2.6'/%3E%3Ccircle cx='13' cy='17' r='2.6'/%3E%3Ccircle cx='18.5' cy='10' r='2.6'/%3E%3C/svg%3E"); }

/* Column popover */
.tbl-colstyle { margin: 0; max-width: 340px; }
.tbl-colstyle-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.ws-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 28px; font-size: var(--fs-sm); font-weight: 600; color: var(--text); cursor: pointer; position: relative; }
.ws-switch input { position: absolute; opacity: 0; width: 34px; height: 20px; right: 0; margin: 0; cursor: pointer; }
.ws-switch-track { width: 34px; height: 20px; border-radius: 10px; background: var(--border-strong); position: relative; transition: background var(--dur-1) var(--ease); }
.ws-switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--dur-1) var(--ease); }
.ws-switch input:checked + .ws-switch-track { background: var(--accent); }
.ws-switch input:checked + .ws-switch-track::after { transform: translateX(14px); }
.ws-switch input:focus-visible + .ws-switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.tbl-add-reg { width: 100%; justify-content: center; min-height: 34px; border: 1px solid var(--border-strong); font-weight: 600; }

/* Regression panel under its table (Desmos). */
.ws-row:has(+ .ws-row.reg-attached) { border-bottom-color: transparent; }
.ws-row.reg-attached .ws-num { visibility: hidden; }
.ws-row.reg-attached .ws-row-main { min-height: 44px; }
.ws-tools.panel-tools { display: none; }
.ws-regp-head { display: flex; align-items: center; gap: 4px; width: 100%; padding-right: 8px; }
.ws-reg-type { flex: 1; min-width: 0; min-height: 34px; padding: 4px 8px; font-size: var(--fs-sm); }
.ws-regp { display: flex; flex-direction: column; gap: 8px; padding: 0 12px 10px 58px; font-size: var(--fs-sm); color: var(--text); }
.ws-regp-label { display: flex; align-items: center; gap: 4px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); font-weight: 600; }
.ws-regp-edit { width: 22px !important; min-height: 22px !important; color: var(--text-3); }
.ws-regp-edit[aria-pressed="true"] { color: var(--accent-text); }
.ws-regp-sec { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ws-regp-eq { font-family: var(--font-math); }
.ws-regp-params, .ws-regp-reslist { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-2); overflow-wrap: anywhere; }
.ws-regp-none { color: var(--text-3); font-size: var(--fs-xs); }
.ws-regp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 18px; }
.ws-regp-stats { margin: 0; display: flex; flex-direction: column; gap: 1px; }
.ws-regp-stats div { display: flex; gap: 6px; font-family: var(--font-math); }
.ws-regp-stats dt { font-style: italic; min-width: 2.6em; text-align: right; }
.ws-regp-stats dt::after { content: " ="; font-style: normal; }
.ws-regp-stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.ws-regp-res { display: flex; align-items: center; gap: 8px; font-family: var(--font-math); }
.ws-regp-plot {
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--sunken); color: var(--text);
  font-size: 11px; padding: 2px 9px; min-height: 22px; font-family: system-ui, sans-serif;
}
.ws-regp-plot[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ws-regp-plot:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.ws-new-row {
  display: grid; grid-template-columns: 50px 1fr; align-items: center; min-height: 52px; padding: 0; border: 0;
  border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text-3); text-align: left; font-size: var(--fs-sm);
}
.ws-new-row > span:last-child { padding-left: 12px; }
.ws-new-num { align-self: stretch; display: flex; align-items: flex-start; padding: 3px 5px; background: var(--panel); border-right: 1px solid var(--border); font-size: 10px; font-weight: 600; }
.ws-new-row:hover { color: var(--accent-text); background: var(--accent-soft); }
.ws-hint {
  margin: var(--s-4) var(--s-4) var(--s-5); padding: var(--s-3) var(--s-4);
  border-left: 2px solid var(--border-strong);
  color: var(--text-3); font-size: var(--fs-xs); line-height: 1.75; text-wrap: pretty;
}
.ws-hint code {
  font-family: var(--mono); font-size: 0.95em; white-space: nowrap;
  padding: 1px 6px; border-radius: 4px; color: var(--text-2);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--border);
}
/* With only the blank first row, the hint is the first-run state: give it more presence. */
.ws-list:has(.ws-rows > .ws-row:only-child) .ws-hint { color: var(--text-2); font-size: var(--fs-sm); border-left-color: var(--accent); }

/* ---------- Graph side ---------- */

.right.ws-right { overflow: hidden; }
.ws-canvas-area { flex: 1; min-height: 0; display: flex; flex-direction: column; container-type: inline-size; }
.ws-toolbar {
  display: flex; align-items: center; gap: var(--s-2); flex-wrap: nowrap;
  padding: 6px var(--s-3); background: var(--surface); border-bottom: 1px solid var(--border); min-height: 48px;
}
.ws-grow { flex: 1; }
.ws-tb-btn { border-color: var(--border); }
.ws-tb-btn.primary { border-color: transparent; }
.ws-split { display: inline-flex; }
.ws-split > .ws-btn { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.ws-split .ws-pop-wrap > .ws-btn { border-radius: 0 var(--r-sm) var(--r-sm) 0; border-left: 1px solid rgb(255 255 255 / 0.35); padding: 4px 6px; }
@container (max-width: 640px) { .ws-tb-label { display: none; } .ws-tb-btn { padding: 4px 8px; } }

.ws-slice-panel {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3);
  padding: 6px var(--s-3); background: var(--panel); border-bottom: 1px solid var(--border); font-size: var(--fs-sm);
}
.ws-slice-val { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-math); font-style: italic; }
.ws-slice-val input { width: 6em; padding: 4px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); font-style: normal; font-family: var(--mono); }
.ws-slice-range { flex: 1; min-width: 120px; accent-color: var(--accent); }
.ws-slice-status { flex-basis: 100%; color: var(--text-2); font-size: var(--fs-xs); }
.ws-slice-status:empty { display: none; }
.ws-slice-status.err { color: var(--danger); }

.ws-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.ws-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity var(--dur-2) var(--ease); }
.ws-canvas.ready { opacity: 1; }
.ws-canvas:focus-visible { outline: 2px solid var(--plate-accent); outline-offset: -3px; }
.lbl-tick[data-axis="4"] { font-size: 12px; font-weight: 600; color: var(--plate-ink); }
.ws-pending { position: absolute; inset: 0; display: flex; flex-direction: column; gap: var(--s-3); align-items: center; justify-content: center; color: var(--plate-ink-2); margin: 0; font-size: var(--fs-sm); }
/* a drawn axis pair above the "Starting the graph" line while the engine boots */
.ws-pending::before {
  content: ""; width: 44px; height: 44px; border-left: 2px solid var(--plate-line); border-bottom: 2px solid var(--plate-line);
  background: linear-gradient(135deg, transparent 46%, var(--plate-ink-2) 47% 53%, transparent 54%) no-repeat 0 100% / 0% 100%;
  animation: ws-draw 1.6s var(--ease) infinite;
}
@keyframes ws-draw { 0% { background-size: 0% 100%; } 60%, 100% { background-size: 100% 100%; } }
.ws-fail { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: var(--s-5); text-align: center; color: var(--plate-ink); }
.ws-fail h2 { font-family: var(--font-display); font-size: var(--fs-xl); }
.ws-fail .mono { color: var(--plate-ink-2); max-width: 60ch; }

/* Floating canvas controls (Desmos' wrench / zoom stack): white keys on the white plate, warm ink. */
.ws-float { position: absolute; top: 10px; right: 10px; z-index: 6; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.ws-fgroup { display: flex; flex-direction: column; border: 1px solid var(--plate-line); border-radius: var(--r-md); background: #fff; box-shadow: 0 1px 2px rgb(60 48 20 / 0.12), 0 4px 12px rgb(60 48 20 / 0.08); overflow: hidden; }
.ws-fbtn {
  width: 36px; height: 36px; padding: 0; border: 1px solid var(--plate-line); border-radius: var(--r-md);
  background: #fff; color: var(--plate-ink); display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgb(60 48 20 / 0.12), 0 4px 12px rgb(60 48 20 / 0.08);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.ws-fgroup .ws-fbtn { border: 0; border-radius: 0; box-shadow: none; }
.ws-fgroup .ws-fbtn + .ws-fbtn { border-top: 1px solid var(--plate-line); }
.ws-fbtn:hover { background: var(--plate-hover); color: #000; }
.ws-fbtn:active { transform: var(--press); }
.ws-fbtn:focus-visible { outline: 2px solid var(--plate-accent); outline-offset: -3px; border-radius: inherit; }
.ws-fbtn[aria-expanded="true"] { background: var(--plate-accent); color: #fff; border-color: var(--plate-accent); }

.ws-settings {
  position: absolute; z-index: 40; top: 0; right: calc(100% + 8px); width: min(320px, calc(100vw - 80px));
  max-height: calc(100vh - 160px); overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2);
  text-align: left; user-select: text;
}
.ws-settings-head { display: flex; align-items: center; justify-content: space-between; }
.ws-settings-head h2 { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; }
.ws-settings-sec { display: flex; flex-direction: column; gap: 6px; }
.ws-settings-label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.ws-window { border: 0; padding: 0; margin: 0; }
.ws-window legend { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; padding: 0; margin-bottom: 6px; }
.ws-win-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; font-family: var(--font-math); font-style: italic; color: var(--text-2); }
.ws-win-row .ws-input { text-align: center; font-family: var(--mono); font-style: normal; }
.ws-axes { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.ws-axes legend { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; padding: 0; margin-bottom: 6px; }
.ws-axis-row { display: grid; grid-template-columns: 1.2em 1fr 5.5em; align-items: center; gap: 8px; font-family: var(--font-math); font-style: italic; color: var(--text-2); }
.ws-axis-row .ws-input { font-family: var(--mono); font-style: normal; min-width: 0; }
.ws-fbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.ws-settings-actions { flex-direction: row; flex-wrap: wrap; }
.ws-settings-actions .ws-btn { border-color: var(--border); }

.ws-slice-frame { position: absolute; z-index: 4; border: 2px solid var(--plate-accent); border-radius: 4px; pointer-events: auto; }
.ws-slice-title { position: absolute; left: 6px; top: 4px; font-size: 11px; font-weight: 700; color: var(--plate-accent); background: rgb(255 255 255 / 0.85); padding: 0 4px; border-radius: 3px; }
.ws-slice-close { position: absolute; right: 2px; top: 2px; width: 24px !important; min-height: 24px !important; background: rgb(255 255 255 / 0.9) !important; color: var(--plate-ink) !important; }

.ws-ticker {
  position: absolute; left: 12px; bottom: 12px; z-index: 6; display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2);
  font-size: var(--fs-sm); user-select: text;
}
.ws-ticker-rate input { width: 5em; padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); }
.ws-toast {
  position: absolute; left: 50%; bottom: 16px; z-index: 30; transform: translateX(-50%); max-width: min(90%, 560px);
  padding: 8px 14px; border-radius: var(--r-md); background: var(--text); color: var(--surface); font-size: var(--fs-sm);
  box-shadow: var(--shadow-2); overflow-wrap: anywhere; user-select: text;
}
.ws-print { display: none; }

/* ---------- AI in the workspace (ws_ai.rs): the Ask box and the variants tray ---------- */
.ws-ask { flex-shrink: 0; display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-2) var(--s-3) var(--s-3); background: var(--panel); border-top: 1px solid var(--border); }
.ws-ask-status { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); font-size: var(--fs-sm); }
.ws-ask-reply { max-height: 9rem; overflow-y: auto; padding: var(--s-2) var(--s-3); border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); font-size: var(--fs-sm); }
.ws-ask-reply.err { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.ws-ask-text { margin: 0; color: inherit; overflow-wrap: anywhere; }
.ws-ask-meta { margin: 2px 0 0; color: var(--text-3); font-size: var(--fs-xs); }
.ws-ask-notes { margin: 4px 0 0; padding-left: 1.1em; color: var(--text-2); font-size: var(--fs-xs); }
.ws-ask-reply .btn { margin-top: var(--s-2); }
.ws-ask-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.ws-ask-chips .chip-btn { padding: 3px 10px; font-size: var(--fs-xs); }
.ws-ask-form { display: flex; gap: var(--s-2); align-items: center; }
.ws-ask-input { flex: 1; min-width: 0; padding: 8px 12px; }
.ws-tray { flex-shrink: 0; max-height: 46%; overflow-y: auto; background: var(--panel); }
.ws-tray:empty { display: none; }
.ws-tray .vt { margin: var(--s-2) var(--s-3); padding: var(--s-3); }
.ws-tray .vt-closed { margin: var(--s-2) var(--s-3); }
.ws-tray .vt-grid { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(200px, 240px); overflow-x: auto; padding-bottom: var(--s-1); }

/* ---------- Form builder dialog (the old Manual form) ---------- */
.form-modal { width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel); color: var(--text); }
.form-modal[open] { display: flex; flex-direction: column; }
.form-head { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.form-modal .panel { min-height: 0; flex: 1; }

/* ---------- Small screens: the list is the bottom sheet, the graph fills the page ---------- */
@media (max-width: 767px) {
  .right.ws-right { padding-bottom: var(--peek-h); }
  .ws-toolbar { padding: 4px var(--s-2); gap: 4px; overflow-x: auto; }
  .ws-row-main { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .ws-diag, .ws-info, .ws-style, .ws-slider, .tbl { margin-left: 0; padding-left: 12px; }
  .ws-diag, .ws-style { margin-left: 8px; }
  .ws-settings { right: 0; top: calc(100% + 8px); position: absolute; }
  .ws-float .ws-pop-wrap { position: static; }
  .ws-float { position: absolute; }
}
@media (pointer: coarse) {
  .ws-tools { opacity: 1; }
  .ws-body math-field::part(virtual-keyboard-toggle) { visibility: visible; }
  .ws-grip { opacity: 0.7; width: 22px; height: 28px; }
  .ws-btn, .ws-seg-btn, .ws-menu-item { min-height: var(--touch); }
  .ws-btn.icon, .ws-tools .ws-btn.icon { width: var(--touch); min-height: var(--touch); }
  .ws-fbtn { width: var(--touch); height: var(--touch); }
  .ws-swatch { width: 36px; height: 36px; }
  .ws-dot { width: 32px; height: 32px; }
  .tbl-cell { min-height: var(--touch); }
}

/* ---------- Print: the workspace graph only ---------- */
@media print {
  body[data-print="ws"] .app-header, body[data-print="ws"] .left, body[data-print="ws"] .resizer,
  body[data-print="ws"] .skip-link, body[data-print="ws"] #graphs,
  body[data-print="ws"] .ws-toolbar, body[data-print="ws"] .ws-slice-panel, body[data-print="ws"] .ws-stage { display: none !important; }
  body[data-print="ws"] .ws-right { display: block !important; padding: 0; }
  body[data-print="ws"] .ws-print { display: block; width: 100%; height: auto; }
  /* Printing the gallery never shows the workspace. */
  body:not([data-print="ws"]) .ws-right { display: none !important; }
}
.ws-gridkind { display: flex; gap: 6px; padding-left: 24px; }
.ws-gk-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text-3); cursor: pointer; }
.ws-gk-btn:hover { color: var(--text); }
.ws-gk-btn[aria-pressed="true"] { color: var(--accent-text); border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.ws-more > summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); list-style-position: inside; }
.ws-more[open] > summary { margin-bottom: 4px; }
.ws-scale-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ws-scale-name { font-size: var(--fs-sm); color: var(--text-2); }
.ws-hint { margin: 0; font-size: var(--fs-xs); color: var(--text-3); }
.lbl-tick[data-axis="5"] { color: var(--text-3); font-size: 11px; }

/* Typeset expressions inside a chat sentence: a soft chip so each equation reads as one unit */
.msg-text .static-math-host { margin: 0 .1em; padding: .05em .4em; border-radius: 6px; background: color-mix(in srgb, currentColor 9%, transparent); }
.msg-text .static-math-host math-field.static-math { font-size: 1.05em; }
.msg-text .msg-swatch { display: inline-block; margin-left: .35em; width: .9em; height: .9em; border-radius: 50%; vertical-align: -.1em; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); }

/* Hover on a curve: a dot on the point and its coordinates beside it */
.ws-hover { position: absolute; width: 0; height: 0; pointer-events: none; z-index: 3; }
.ws-hover-dot { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.45); }
.ws-hover-tip { position: absolute; left: 10px; top: -30px; white-space: nowrap; padding: 2px 7px; border-radius: 6px; font-size: .8125rem; background: var(--surface, #fff); color: var(--text, #1a1a1a); border: 1px solid var(--border, rgba(0,0,0,.2)); box-shadow: 0 1px 4px rgba(0,0,0,.35); font-variant-numeric: tabular-nums; }

/* Special points of the selected curve: small grey dots */
.ws-special { position: absolute; width: 0; height: 0; pointer-events: none; z-index: 2; }
.ws-special::before { content: ""; position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: #8a8f98; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
