/* Tule's palette ("Reed"): the only place colors are defined. The pages
   (control/src/pages.ts) and the viewer (style.css, overlay colors) use these
   variables, never hex values of their own. From the logo: navy ink, reed gold
   for actions and highlights, stem green for running. Dark mode flips the
   same names; the viewer opts out with <html class="light-only"> for now. */
:root {
  /* brand (the logo uses navy, reed-light and stem-light) */
  --navy: #23344a;
  --reed: #c98a3a;
  --reed-light: #e0a45a;
  --stem: #4f8a3c;
  --stem-light: #8fc46a;

  /* text: four sizes, by role (DESIGN.md "Text"). Weights: 400, 500 for emphasis, 600 for titles only. */
  --fs-title: 16px; /* a project's name, a page's heading */
  --fs-body: 13px; /* rows, buttons, menus, inputs */
  --fs-small: 12px; /* secondary: counts, dates, notes, status (usually muted) */
  --fs-label: 11px; /* section labels (uppercase), axis ticks */

  /* surfaces and lines */
  --bg: #fffefb;
  --panel: #faf8f3;
  --hover: #f3efe6;
  --line: #ebe6da;
  --line-strong: #d6cfbf;

  /* text */
  --text: #23344a;
  --muted: #7a7568;
  --faint: #a39d90;

  /* actions: reed buttons with dark text, darker reed for links */
  --accent: #c98a3a;
  --accent-hover: #b67a2e;
  --on-accent: #1b1408;
  --link: #94601f;
  --selected: #f6ecda;
  --focus: rgba(201, 138, 58, 0.35);

  /* status: text color, fill (dots, bars), background (chips, banners) */
  --ok: #3f7a2f;
  --ok-fill: #4f8a3c;
  --ok-bg: #eaf2e3;
  --warn: #8a5300;
  --warn-fill: #d9a23a;
  --warn-bg: #fbf0de;
  --danger: #b03a28;
  --danger-fill: #d4574a;
  --danger-bg: #fbecea;
  --danger-line: #f0c2ba;
  --info: #35659a;
  --info-fill: #4a7fb8;
  --info-bg: #e8eff7;
  --idle: #cfc9bb;

  /* elevation */
  --shadow: rgba(35, 52, 74, 0.16);

  /* the 3D view: a soft backdrop, dark edges, the floor grid */
  --view-center: #fdfcf9;
  --view-mid: #f1eee7;
  --view-edge: #e5e0d5;
  --part: #8a96a3; /* a part without a color of its own */
  --edge: #23344a; /* the CAD edges: the navy (the 3D view stays light) */

  /* data colors: fixed, chosen to tell lines and faces apart, not roles */
  /* the sequence plot's lines, in order by key */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #8e5bd6;
  --series-8: #a8642a;
  --series-9: #17a2b8;
  --series-10: #6b7280;
  /* overlay roles beyond fixed and load, in order of appearance */
  --role-1: #4f8a3c;
  --role-2: #8a6bb8;
  --role-3: #2f9a95;
  --role-4: #c8689a;
  /* the value scale: a diverging blue-yellow-red ramp, low to high (hex only: it is interpolated) */
  --ramp-1: #3b4cc0;
  --ramp-2: #6f92f3;
  --ramp-3: #aac7fd;
  --ramp-4: #f2e5a0;
  --ramp-5: #f7a889;
  --ramp-6: #e26952;
  --ramp-7: #b40426;
  /* annotation pens (named red, blue, green, black in annotation.json), picked faces, labeled picks */
  --pen-red: #e5484d;
  --pen-blue: #2a78d6;
  --pen-green: #1baf7a;
  --pen-black: #23344a;
  --pick-selected: #9b5de5;
  --pick-1: #2a78d6;
  --pick-2: #eb6834;
  --pick-3: #1baf7a;
  --pick-4: #e87ba4;
  --pick-5: #008300;
  --pick-6: #eda100;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light-only) {
    --bg: #14171c;
    --panel: #1b1f25;
    --hover: #232831;
    --line: #2a2e35;
    --line-strong: #3a3f47;
    --text: #ece7dc;
    --muted: #a39d90;
    --faint: #6f6a60;
    --accent: #e0a45a;
    --accent-hover: #e8b673;
    --on-accent: #1b1408;
    --link: #e8b673;
    --selected: #3a2f1f;
    --focus: rgba(224, 164, 90, 0.4);
    --ok: #8fc46a;
    --ok-fill: #8fc46a;
    --ok-bg: #1f2a1a;
    --warn: #e0a526;
    --warn-fill: #e0a526;
    --warn-bg: #33280f;
    --danger: #ec6a5c;
    --danger-fill: #e5484d;
    --danger-bg: #3a1d1a;
    --danger-line: #5a2a24;
    --info: #7aa7d9;
    --info-fill: #7aa7d9;
    --info-bg: #1a2433;
    --idle: #4d4a44;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

/* colors: palette.css, which the build puts in front of this file */
:root {
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  font: var(--fs-body)/1.4 var(--sans);
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

button {
  font: inherit;
  font-size: var(--fs-body);
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--panel);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.line svg,
.menu svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* the download button and its menu */
.dl {
  position: relative;
}

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 10;
  min-width: 170px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 8px 28px var(--shadow);
  display: flex;
  flex-direction: column;
}

.menu button {
  border: none;
  height: 30px;
  padding: 0 8px;
  border-radius: 5px;
  justify-content: space-between;
  gap: 16px;
  font-weight: 400;
}

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

.menu small {
  font-size: var(--fs-small);
  font-weight: 400;
  color: var(--muted);
}

/* the section control: the axis, where the plane cuts (a slider over the parts' extent), flip, off */
.section-panel { width: 230px; gap: 6px; padding: 8px; }
.section-axes { display: flex; gap: 4px; }
.dl .section-axes button { flex: 1; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); height: 28px; padding: 0 6px; }
.dl .section-axes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.section-panel input[type="range"] { width: 100%; accent-color: var(--accent); }
.section-foot { display: flex; align-items: center; justify-content: space-between; font-size: var(--fs-small); color: var(--muted); }
.section-foot button { height: 26px; }

/* one line per file however many there are: long names end in … (the full name on hover) */
#download-menu {
  width: max-content;
  max-width: min(380px, calc(100vw - 32px));
  max-height: 60vh;
  overflow-y: auto;
}
#download-menu button { flex: none; min-width: 0; }
#download-menu button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#download-menu button small { flex: none; }

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#stage {
  flex: 1;
  position: relative;
  min-height: 0;
}

#viewer {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, var(--view-center) 0%, var(--view-mid) 60%, var(--view-edge) 100%);
  overflow: hidden;
  touch-action: none;
}

#viewer canvas {
  display: block;
}

.nogl {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.hud {
  position: absolute;
  display: flex;
  gap: 6px;
  align-items: center;
}

#hud {
  top: 10px;
  right: 10px;
}

.hud button {
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(4px);
  height: 28px;
  font-size: var(--fs-body);
}

.hud button.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.hud button.icon { width: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

.hud button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* the parts panel (parts.js), under the viewer's buttons */
/* the parts tree, under the selected output in the sidebar (parts.js) */
#parts {
  margin: 2px 0 8px 15px;
  padding-left: 6px;
  border-left: 2px solid var(--line);
  max-height: 45vh; /* a long list scrolls by itself: the output's files stay in view below it */
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: var(--fs-body);
  user-select: none;
  -webkit-user-select: none;
}

.parts-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 4px 4px 0 10px;
}

/* nothing hidden: nothing to show again */
#parts:not(.has-hidden) .parts-all {
  display: none;
}

#parts button {
  height: 22px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: var(--fs-small);
}

#parts .parts-all {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 4px;
  color: var(--link);
}

#parts .parts-all:hover {
  background: var(--hover);
}

.parts-list {
  min-height: 0;
  overflow-y: auto;
  padding: 4px;
}

.part {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 2px 0 calc(6px + var(--depth) * 17px);
  border-radius: 5px;
  cursor: default;
}

.part.lit {
  background: var(--hover);
}

.part.selected {
  background: var(--selected);
}

.part .lead { flex: none; width: 10px; }


.part .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part.off .name {
  color: var(--faint);
}

#parts .caret {
  flex: none;
  width: 10px;
  justify-content: center;
}

.caret svg,
.eye svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.caret svg {
  width: 10px;
  height: 10px;
  transition: transform 0.12s;
}

.part.open .caret svg {
  transform: rotate(90deg);
}

#parts .eye {
  flex: none;
  width: 24px;
  justify-content: center;
  border-radius: 4px;
}

.eye svg {
  width: 15px;
  height: 15px;
}

.part.partly .eye {
  opacity: 0.55;
}

#parts .only {
  padding: 0 6px;
  border-radius: 4px;
  font-size: var(--fs-small);
}

#parts .only:hover,
#parts .eye:hover {
  color: var(--link);
  background: var(--bg);
}

/* a mouse: the eye and "only" show on the row under it (and the eye of a
   hidden part stays); touch: eyes always, "only" on the tapped row */
@media (hover: hover) {
  .part:not(:hover):not(:has(:focus-visible)):not(.off):not(.partly) .eye {
    visibility: hidden;
  }
  .part:not(:hover):not(:has(:focus-visible)) .only {
    display: none;
  }
}

@media (hover: none) {
  .part {
    height: 32px;
  }
  .part:not(.selected) .only {
    display: none;
  }
  #parts .eye {
    width: 32px;
    height: 30px;
  }
}

/* the polygon count and genau time: quiet text in the viewer's corner */
#counts {
  position: absolute;
  right: 12px;
  bottom: 9px;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-shadow: 0 0 4px var(--bg), 0 0 2px var(--bg);
  white-space: nowrap;
  pointer-events: none;
}

#play {
  width: 24px;
  height: 22px;
  padding: 0;
  justify-content: center;
  flex: none;
}

#scrub {
  flex: 1 1 60px;
  width: 60px;
  min-width: 50px;
  max-width: 170px;
  margin: 0;
  accent-color: var(--accent);
}

#frame {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-body);
  pointer-events: none;
}

.status:empty {
  display: none;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}
.unsaved-dot { display: none; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--warn-fill); }
#project-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick { flex: none; width: 100%; height: 32px; padding: 0 10px; border: none; border-radius: 6px; gap: 8px; justify-content: space-between; text-align: left; }
.pick:hover, .pick:focus-visible { background: var(--hover); outline: none; }
.pick[aria-selected="true"] { background: var(--selected); color: var(--link); font-weight: 500; }
.pick .unsaved-dot { display: inline-block; }

/* narrow screens: viewer on top, editor below */
@media (max-width: 820px) {
  #download .label {
    display: none;
  }
  #download {
    width: 32px;
    padding: 0;
    justify-content: center;
  }
  .menu button {
    height: 38px;
  }
  .pick {
    height: 40px;
  }
  #scrub {
    min-width: 30px;
  }
}

/* phones: Run, Code (its icon), Save and the picker share one row; the
   replay, when there is one, gets the row above it */
@media (max-width: 520px) {
  #scrub {
    max-width: none;
  }
}

/* ---------------------------------------------------------------- tule */

/* the sidebar's top: back to your projects, and this project's name */
.project-head { flex: none; padding: 12px 12px 6px; }
.side-foot { flex: none; padding: 8px 12px; border-top: 1px solid var(--line); }
.project-head .back {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: -2px;
  padding: 2px 4px 2px 0;
  border-radius: 5px;
  color: var(--muted);
  font-size: var(--fs-small);
  text-decoration: none;
}
.project-head .back:hover { color: var(--text); }
.project-head .back svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.project-head .head-row { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.project-head .head-row .dl { margin-left: auto; }
.project-head .share { height: 24px; padding: 0 9px; font-size: var(--fs-body); white-space: nowrap; flex: none; }
.project-head .share.linked { display: inline-flex; align-items: center; gap: 5px; }
.project-head .share.linked svg { width: 13px; height: 13px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.share-menu { position: fixed; top: auto; right: auto; z-index: 30; min-width: 200px; } /* placed under the button (the sidebar clips) */
.share-menu p { margin: 0; padding: 6px 8px 4px; font-size: var(--fs-small); color: var(--muted); }
.share-menu .menu-error { color: var(--danger); max-width: 260px; line-height: 1.4; }
.view-only { display: none; font-size: var(--fs-small); color: var(--muted); }
/* opened from a view-only link: nothing that changes the project or needs an account */
.shared-view .project-head .back, .shared-view #annotate-toggle, .shared-view #save-now,
.shared-view #machine-more, .shared-view #machine-pick, .shared-view #outputs-empty { display: none !important; }
.shared-view .view-only { display: inline; }
/* a view-only link's visitor: what made this, and where to try it */
.made-with { display: none; flex: none; margin: 0 8px 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.shared-view .made-with { display: block; }
.made-with p { margin: 0 0 9px; font-size: var(--fs-small); line-height: 1.45; color: var(--muted); }
.made-with b { color: var(--text); font-weight: 600; }
.made-with .cta { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 12px; border-radius: 6px; background: var(--accent); color: var(--on-accent); font-weight: 500; font-size: var(--fs-body); text-decoration: none; }
.made-with .cta:hover { background: var(--accent-hover); }
.made-with .cta svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 640px) { /* phones: one row, so the outputs list keeps its room */
  .shared-view .made-with { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 10px; }
  .made-with p { flex: 1; margin: 0; }
  .made-with .long { display: none; }
  .made-with .cta { flex: none; height: 26px; padding: 0 10px; }
}
.project-name { margin-top: 8px; font-size: var(--fs-title); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.machine {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-small);
  color: var(--muted);
}

.machine .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--idle);
}

.machine[data-state="running"] .dot { background: var(--ok-fill); }
/* several machines: the footer is a picker (an invisible select over it) */
.machine .chev { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-left: -3px; }
.machine select { position: absolute; inset: 0; opacity: 0; cursor: pointer; font: inherit; width: 100%; }
.machine:has(select:not([hidden])):hover { color: var(--text); }
.machine .unsaved { color: var(--warn); }
.side-foot .machine { flex: 0 1 auto; min-width: 0; max-width: 100%; white-space: nowrap; gap: 6px; font-size: var(--fs-small); }
.side-foot .machine .chev { width: 10px; height: 10px; margin-left: -2px; }
#machine-text { overflow: hidden; text-overflow: ellipsis; }
.machine[data-state="starting"] .dot { background: var(--warn-fill); }

#outputs {
  width: 240px;
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 8px;
}

.outputs-head {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 4px 6px 8px;
}

.output {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  text-align: left;
}
.output:hover { background: var(--hover); }
.output-icon { flex: none; width: 15px; height: 15px; fill: none; stroke: var(--muted); stroke-width: 1.3; stroke-linejoin: round; }
.output-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-body); }
.output small { flex: 0 1 auto; min-width: 0; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--fs-small); font-variant-numeric: tabular-nums; }
.output small[data-tone="error"] { color: var(--danger); }
.output small[data-tone="warning"] { color: var(--warn); }
.output small[data-tone="live"] { color: var(--ok); }
.output small[data-tone="ok"] { color: var(--ok); }
.output[aria-selected="true"] { background: var(--bg); border-color: var(--line); }
.output[aria-selected="true"] .output-icon { stroke: var(--accent); }

/* the selected output's title, above the view (overlays show theirs in the legend) */
.caption {
  position: absolute;
  top: 12px;
  left: 14px;
  max-width: calc(100% - 420px);
  font-size: var(--fs-body);
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
@media (max-width: 640px) { .caption { display: none; } }

.outputs-empty {
  color: var(--muted);
  font-size: var(--fs-small);
  padding: 0 6px;
}

.pick-label {
  position: absolute;
  pointer-events: none;
  font: 12px/1.3 var(--mono);
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

#sequence {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#sequence { flex-direction: column; align-items: stretch; gap: 6px; }
.seq-row { display: flex; align-items: center; gap: 10px; }
#scrub { flex: 1; max-width: none; }
#frame { font-size: var(--fs-small); color: var(--muted); white-space: nowrap; }
.live { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-small); color: var(--ok); }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok-fill); animation: blink 1.2s ease-in-out infinite; }
.plot { display: flex; flex-direction: column; gap: 3px; }
.plot-svg { display: block; width: 100%; height: 64px; cursor: pointer; touch-action: none; }
.plot-base { stroke: var(--line); stroke-width: 1; }
.plot-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot-dot { stroke: var(--panel); stroke-width: 2; }
.plot-cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 2; }
.plot-hover { stroke: var(--faint); stroke-width: 1; }
.plot-axis { font: var(--fs-label) var(--sans); fill: var(--muted); }
.plot-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: var(--fs-small); color: var(--muted); }
.plot-frame { color: var(--text); font-weight: 500; }
.plot-key { display: inline-flex; align-items: center; gap: 5px; }
.plot-key i { width: 10px; height: 3px; border-radius: 2px; }
.plot-key b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.plot-key small { font-size: var(--fs-small); }
.plot-key[title] { cursor: pointer; }
.plot-key.off { opacity: 0.45; }
.plot-key.solo .k { text-decoration: underline; text-underline-offset: 2px; }
#play.on { background: var(--accent); color: var(--on-accent); }

#play svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

@media (max-width: 640px) {
  main { flex-direction: column; }
  #outputs { width: auto; max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------------------------------------------------------------- overlays */

.legend { font-size: var(--fs-small); }
.legend-row {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: start;
  column-gap: 7px;
  padding: 4px 6px;
  border-radius: 5px;
}
.legend-row:hover { background: var(--hover); }
.swatch {
  flex: none;
  margin-top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--c);
  box-shadow: inset 0 0 0 1px var(--shadow);
}
.swatch.hatch { background: repeating-linear-gradient(135deg, var(--c) 0 3px, color-mix(in srgb, var(--c) 35%, var(--bg)) 3px 6px); }
.swatch.arrow { background: none; box-shadow: none; position: relative; }
.swatch.arrow::before { content: ""; position: absolute; left: 5px; top: 0; width: 2px; height: 8px; background: var(--c); }
.swatch.arrow::after { content: ""; position: absolute; left: 2px; top: 7px; border: 4px solid transparent; border-top: 5px solid var(--c); border-bottom: 0; }
.legend-kind {
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.legend-kind.error { color: var(--danger); }
.legend-kind.warning { color: var(--warn); }
.legend-kind.info { color: var(--info); }
.legend-label { min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
.legend-faces { grid-column: 3; color: var(--muted); font: var(--fs-label)/1.3 var(--mono); }

#marks { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mark-chip {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--reed);
  color: var(--on-accent);
  font: 500 var(--fs-small)/1.3 var(--sans);
  white-space: nowrap;
  box-shadow: 0 1px 4px var(--shadow);
}

/* ---------------------------------------------------------------- annotations */

#ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
#ink.drawing { pointer-events: auto; cursor: crosshair; touch-action: none; }
#stage.annotating #parts { display: none; }

.annot {
  position: absolute;
  z-index: 3;
  top: 46px;
  right: 10px;
  width: 300px;
  max-height: calc(100% - 82px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 24px var(--shadow);
  font-size: var(--fs-body);
}
.annot-head { display: flex; align-items: center; justify-content: space-between; }
.annot-head b { font-weight: 500; }
.annot .close { border: none; background: none; font-size: 19px; width: 24px; height: 24px; padding: 0; justify-content: center; color: var(--muted); }
.annot-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.annot-tools button { height: 26px; font-size: var(--fs-small); padding: 0 8px; }
.annot-gap { flex: 1; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ink-colors { display: inline-flex; gap: 4px; }
.annot .ink-color { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 2px solid var(--bg); background: var(--c); box-shadow: 0 0 0 1px var(--line); }
.annot .ink-color[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--c); }
.annot-hint { margin: 0; color: var(--muted); font-size: var(--fs-small); }
.annot-label-row { display: flex; gap: 6px; }
.annot-label-row input, .annot textarea {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: var(--fs-body);
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}
.annot textarea { resize: vertical; min-height: 44px; }
.annot-label-row input:focus, .annot textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.annot-label-row button { flex: none; }
#annot-picks:empty { display: none; }
.annot-pick { display: grid; grid-template-columns: 12px auto 1fr auto; align-items: center; column-gap: 7px; padding: 2px 0; }
.annot-pick-label { font-weight: 500; }
.annot-pick small { color: var(--muted); font: var(--fs-label)/1.3 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.annot .annot-x { border: none; background: none; height: 20px; width: 20px; padding: 0; justify-content: center; color: var(--muted); font-size: 15px; }
.annot-save { display: flex; align-items: center; gap: 8px; }
#annot-why { color: var(--warn); font-size: var(--fs-small); }
.annot-done { padding: 8px; border-radius: 6px; background: var(--ok-bg); border: 1px solid color-mix(in srgb, var(--ok-fill) 30%, var(--ok-bg)); display: flex; flex-direction: column; gap: 4px; }
.annot-done code { font: 12px var(--mono); }
.annot-done.error { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.annot-done.error > :not(.annot-summary) { display: none; }
.annot-tell { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.annot-say { font-weight: 500; }
.annot-tell button { height: 22px; font-size: var(--fs-small); padding: 0 7px; }
.annot-summary { color: var(--muted); font-size: var(--fs-small); }
.annot-done.error .annot-summary { color: var(--danger); }
#annot-past summary { cursor: pointer; color: var(--muted); font-size: var(--fs-small); }
#annot-past-list { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; max-height: 180px; overflow-y: auto; }
.annot-past-item { display: flex; flex-direction: column; align-items: flex-start; height: auto; padding: 5px 7px; border-color: transparent; background: none; text-align: left; gap: 1px; }
.annot-past-item:hover { background: var(--hover); }
.annot-past-item b { font: 500 var(--fs-small) var(--mono); }
.annot-past-item small { color: var(--muted); font-size: var(--fs-small); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.annot-shown {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 20px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 90%, transparent);
  color: var(--bg);
  font-size: var(--fs-small);
}
.annot-shown span { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.annot-shown button { flex: none; height: 24px; font-size: var(--fs-small); background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, transparent); }

@media (max-width: 640px) {
  .annot { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; max-height: 55%; }
  #hud .label { display: none; }
  #stage.annotating .legend { display: none; }
}

/* ---------------------------------------------------------------- the outputs list */

#outputs { padding: 0; display: flex; flex-direction: column; }
#outputs .outputs-head { flex: none; padding: 10px 14px 4px; }
.side-pane { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 8px; }
.dl .menu button { justify-content: space-between; }

/* medium widths (tablets, a narrow window): the sidebar gets narrower; phones stack (640px below) */
@media (max-width: 900px) and (min-width: 641px) {
  #outputs { width: 200px; }
}

/* the strip under the view: the output's info, a value scale, findings and conditions (overlay.js) */
.strip { flex: none; max-height: 34%; overflow-y: auto; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.strip .legend-head { padding: 0 6px 8px; color: var(--text); font-size: var(--fs-body); font-weight: 500; }
.strip .legend-head:empty { display: none; }
.strip .legend-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0 14px; }
.legend-scale { display: flex; align-items: center; gap: 8px; margin: 0 6px 10px; font-size: var(--fs-small); }
.legend-scale-label { color: var(--text); margin-right: 4px; }
.legend-scale small { color: var(--muted); font-size: var(--fs-label); font-variant-numeric: tabular-nums; }
.legend-ramp { flex: 0 1 220px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--shadow); }

/* in the sidebar the output's row names the assembly: the tree's header only offers "Show all" */
#parts:not(.has-hidden) .parts-head { display: none; }
#parts .parts-head { padding: 2px 4px 0 6px; min-height: 24px; }

.output-fold { flex: none; width: 13px; height: 13px; margin-left: -2px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s; }
.output.open .output-fold { transform: rotate(90deg); }
.output.in-group { padding-left: 24px; }
.output.in-group + .under { margin-left: 31px; }

/* ---------------------------------------------------------------- under the selected entry: its views, an assembly's parts */

.under { margin: 2px 0 8px 15px; padding-left: 6px; border-left: 2px solid var(--line); }
.under #parts { margin: 0 0 2px 14px; padding: 0; border-left: 0; }
.view { display: flex; align-items: center; gap: 7px; width: 100%; height: 26px; padding: 0 6px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: var(--fs-body); text-align: left; }
.view span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view .output-icon { width: 13px; height: 13px; }
.view:hover { background: var(--hover); color: var(--text); }
.view[aria-current="true"] { color: var(--text); background: var(--hover); }
.view[aria-current="true"] .output-icon { stroke: var(--accent); }
.inputs-head { padding: 16px 6px 6px; }

/* ---------------------------------------------------------------- the page: a view that is not 3D (files.js) */

.page { position: absolute; inset: 0; display: none; overflow: auto; background: var(--bg); }
#stage.paged .page { display: block; }
#stage.paged #annotate-toggle, #stage.paged #fit, #stage.paged #view-link, #stage.paged #counts, #stage.paged #caption, #stage.paged #marks, #stage.paged #pick,
#stage.paged #ink, #stage.paged #annotate, #stage.paged #annot-shown { display: none; }
.page-body { max-width: 920px; margin: 0 auto; padding: 52px 28px 40px; }
.page-empty { color: var(--muted); font-size: var(--fs-body); text-align: center; margin-top: 18vh; }
.page-error { color: var(--danger); font-size: var(--fs-body); }
.page-note { color: var(--muted); font-size: var(--fs-small); margin: 8px 2px 0; }
.page-error { margin: 0 0 14px; color: var(--danger); font-size: var(--fs-body); line-height: 1.5; overflow-wrap: anywhere; }
.page-body details > summary { cursor: pointer; color: var(--muted); font-size: var(--fs-small); margin-bottom: 8px; }
.page-text { margin: 0; font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.page-image { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 4px; }
.page-dxf svg { display: block; width: 100%; max-height: calc(100vh - 160px); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.page-dxf path { fill: none; stroke: var(--text); stroke-width: 1.2; }
.page-dxf text { font-family: inherit; }
.dxf-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: var(--fs-small); color: var(--muted); }
.dxf-layer { display: inline-flex; align-items: center; gap: 6px; }
.dxf-layer svg { width: 28px; height: 6px; flex: none; }
.dxf-layer line { stroke-width: 2; }
.dxf-layer span { color: var(--text); }
.page-pdf { display: block; width: 100%; height: calc(100vh - 120px); border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.page-file { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; font-size: var(--fs-body); }
.page-file span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.page-file small { color: var(--muted); }
.page-missing { color: var(--muted); }

.table-wrap { overflow: auto; max-width: 100%; max-height: calc(100vh - 110px); border: 1px solid var(--line); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: var(--fs-body); font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data th { position: sticky; top: 0; background: var(--panel); font-weight: 500; }
table.data .num { text-align: right; }
table.data td.long { white-space: normal; min-width: 14em; max-width: 30em; }
table.data td.long .clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.page-body:has(> .table-wrap) { max-width: none; }
table.data th button { all: unset; cursor: pointer; color: var(--muted); font-size: var(--fs-small); }
table.data th button:hover { color: var(--text); }
table.data th[data-sort="up"] button::after { content: " ↑"; }
table.data th[data-sort="down"] button::after { content: " ↓"; }
table.data tbody tr:hover { background: var(--hover); }
button.link, a.link { all: unset; cursor: pointer; color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); text-underline-offset: 2px; }
button.link:hover, a.link:hover { text-decoration-color: var(--link); }

.chart { width: 100%; }
.chart svg { display: block; max-width: 100%; }

.page-doc { font-size: 15px; line-height: 1.6; color: var(--text); }
.page-doc > :not(table) { max-width: 720px; } /* text at a reading width; a wide table takes the page, and scrolls past it */
.page-doc > :first-child { margin-top: 0; }
.page-doc h1 { font-size: 22px; margin: 0 0 14px; }
.page-doc h2 { font-size: 17px; margin: 26px 0 10px; }
.page-doc h3 { font-size: 15px; margin: 20px 0 8px; }
.page-doc a { color: var(--link); }
.page-doc code { font: 13px var(--mono); background: var(--panel); padding: 1px 4px; border-radius: 4px; }
.page-doc pre { background: var(--panel); padding: 10px 12px; border-radius: 6px; overflow: auto; }
.page-doc pre code { background: none; padding: 0; }
.page-doc img { max-width: 100%; height: auto; border-radius: 4px; }
.page-doc table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; }
.page-doc th, .page-doc td { border-bottom: 1px solid var(--line); padding: 5px 10px; text-align: left; vertical-align: top; }
.page-doc td.prose { min-width: 16em; }
.page-doc blockquote { margin: 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.page-embed { margin: 14px 0; }

@media (max-width: 640px) {
  .page-body { padding: 48px 14px 28px; }
  .page-doc { font-size: 14px; }
}

/* the footer's Save: a link after the copy's state, while it has unsaved work */
.side-foot { display: flex; align-items: center; gap: 8px; }
.foot-save { all: unset; flex: none; display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-size: var(--fs-small); font-weight: 500; color: var(--link); cursor: pointer; }
.foot-save .unsaved-dot { display: inline-block; }
.foot-save:hover { text-decoration: underline; }
.foot-save:disabled { color: var(--faint); cursor: default; text-decoration: none; }

select.field-pick { height: 24px; max-width: 100%; font: inherit; font-size: var(--fs-small); padding: 0 6px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }

/* an empty project: what to ask the agent, and how to connect one */
.empty-hint { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); padding: 18px 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 6px 24px rgb(0 0 0 / 6%); z-index: 2; }
.empty-hint h2 { margin: 0 0 8px; font-size: var(--fs-title); font-weight: 600; }
.empty-hint p { margin: 0 0 8px; line-height: 1.5; }
.empty-hint p:last-child { margin-bottom: 0; }
.empty-hint q { color: var(--text); }
.empty-hint .muted { color: var(--muted); font-size: var(--fs-small); }
.empty-hint a { color: var(--link); }
