:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #2b2620;
  --muted: #7a7065;
  --line: #e2dbd0;
  --accent: #b5652b;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}

h1, h2 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: -0.25rem 0 0.75rem; }
.empty { color: var(--muted); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--ink);
  color: #f6f3ee;
}
.topbar__brand { color: inherit; font-weight: 700; letter-spacing: 0.02em; text-decoration: none; }

.flash {
  margin: 1rem auto 0;
  max-width: 960px;
  padding: 0.6rem 1rem;
  background: #eef5e9;
  border: 1px solid #cfe2c2;
  border-radius: var(--radius);
}

/* Page */
.page { max-width: 960px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page__header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.section { margin-top: 2rem; }
.notes { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.25rem 1rem; }

/* Buttons */
.button {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { border-color: var(--muted); }
.button--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button--primary:hover { filter: brightness(0.95); border-color: var(--accent); }
.button--danger { color: var(--danger); margin-top: 2rem; }
.button--small { padding: 0.15rem 0.5rem; font-size: 0.85rem; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); }
.table th, .table td { padding: 0.45rem 0.75rem; border-bottom: 1px solid var(--line); text-align: left; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; width: 1%; white-space: nowrap; }

/* Forms */
.form { max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.75rem; flex: 1; min-width: 0; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field input, .field textarea, .field select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  color: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: flex; gap: 0.75rem; }
.form__actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.form__intro { color: var(--muted); margin: -0.25rem 0 1.25rem; }
.form__group { border: 1px solid var(--line); border-radius: 6px; padding: 0.75rem 1rem 0.25rem; margin: 0 0 1rem; }
.form__group legend { font-weight: 600; padding: 0 0.35rem; }
.field__hint { margin: 0; font-size: 0.8rem; color: var(--muted); }

.errors {
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  border: 1px solid #efc6c2;
  background: #fbeceb;
  border-radius: var(--radius);
  color: var(--danger);
}
.errors ul { margin: 0; padding-left: 1rem; }

@media (max-width: 600px) {
  .field-row { flex-direction: column; gap: 0; }
}

/* Rails wraps invalid fields in a div; keep it out of the layout. */
.field_with_errors { display: contents; }
.field_with_errors input { border-color: var(--danger); }

/* ───────────── Editor ───────────── */

.topbar__project { font-weight: 600; opacity: 0.85; }
.topbar__links { margin-left: auto; display: flex; gap: 1rem; font-size: 0.9rem; }
.topbar__links a { color: #e9e2d6; text-decoration: none; }
.topbar__links a:hover { color: #fff; }
.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; opacity: 0.85; }
.topbar__links ~ .topbar__user { margin-left: 0.5rem; padding-left: 1rem; border-left: 1px solid rgba(255, 255, 255, 0.2); }
.topbar__user form { display: contents; }
.topbar__account-link { color: #e9e2d6; text-decoration: none; }
.topbar__account-link:hover { color: #fff; text-decoration: underline; }
.topbar__sign-out { border: 0; background: none; color: #e9e2d6; font: inherit; padding: 0; cursor: pointer; }
.topbar__sign-out:hover { color: #fff; text-decoration: underline; }

/* Sign-in and People */
.sign-in { max-width: 28rem; margin: 3rem auto; }
.sign-in p { color: var(--muted); }
.invite-link { max-width: 560px; display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1.25rem; font-size: 0.9rem; }
.invite-link input { font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; }
/* Passkeys */
.access-token__command { font: 0.85rem ui-monospace, SFMono-Regular, Menlo, monospace; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; resize: none; }
.passkeys { max-width: 560px; }
.passkeys__intro { color: var(--muted); }
.passkeys__list { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.passkeys__item { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.passkeys__meta { display: block; color: var(--muted); font-size: 0.85rem; }
.passkeys__add { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.passkeys__error { flex-basis: 100%; margin: 0; }
.sign-in .passkeys__error { margin-top: 1rem; }
.people { list-style: none; padding: 0; margin: 0 0 1.5rem; max-width: 560px; }
.people__person { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }

body:has(.editor-main) { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.editor-main { flex: 1; min-height: 0; }

.editor {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "toolbar toolbar"
    "viewport panel"
    "statusbar statusbar";
}

.editor__toolbar {
  grid-area: toolbar;
  display: flex;
  gap: 0.75rem;
  padding: 0.35rem 0.6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.toolbar__group { display: flex; gap: 2px; padding-right: 0.75rem; border-right: 1px solid var(--line); }
.toolbar__group:last-child { border-right: 0; }

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 52px;
  padding: 0.3rem 0.4rem 0.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.7rem;
  cursor: pointer;
}
.tool svg { width: 20px; height: 20px; fill: currentColor; }
.tool:hover:not(:disabled) { background: var(--bg); }
.tool[aria-pressed="true"] { background: #f5e6d8; border-color: #e3c4a6; color: var(--accent); }
.tool:disabled { opacity: 0.35; cursor: default; }

.editor__viewport { grid-area: viewport; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.editor__viewport canvas { display: block; outline: none; touch-action: none; }

.editor__panel {
  grid-area: panel;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.entity-info__title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.75rem; }
.entity-info__summary { font-size: 1.05rem; margin-bottom: 0.5rem; }
.entity-info__hint { color: var(--muted); font-size: 0.85rem; }
.entity-info__subtitle { font-size: 0.75rem; font-weight: 600; margin: 0.75rem 0 0.35rem; }
.entity-info__edges { list-style: none; margin: 0 0 0.5rem; padding: 0; display: grid; gap: 0.2rem; font-size: 0.85rem; }
.entity-info__joints { list-style: none; margin: 0 0 0.75rem; padding: 0; display: grid; gap: 0.3rem; }
.entity-info__joint { display: grid; gap: 0.25rem; font-size: 0.85rem; padding: 0.35rem 0.45rem; border: 1px solid var(--line); border-radius: var(--radius); }
.entity-info__joint:hover { border-color: #d9731a; }
.entity-info__joint-actions { display: flex; gap: 0.3rem; }

/* Warnings: a message to click (shows the boards), and Join… where it fixes it. */
.panel__body.warnings { max-height: 14rem; padding: 0 0.75rem 0.75rem; } /* a long list mustn't push the Outliner away */
.warnings__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.warning { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; align-items: start; padding: 0.35rem 0.5rem; border-left: 3px solid #d9731a; background: #fbf4ec; border-radius: var(--radius); }
.warning__message { font: inherit; font-size: 0.85rem; text-align: left; color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer; }
.warning__message:hover { text-decoration: underline; }
.warnings__none { color: var(--muted); font-size: 0.85rem; }
.entity-info__group { border: 0; padding: 0; margin: 0.25rem 0 0.75rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.entity-info__group legend { font-size: 0.75rem; font-weight: 600; margin-bottom: 0.25rem; padding: 0; }
.entity-info__row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.entity-info__field { display: flex; flex-direction: column; gap: 0.15rem; margin-bottom: 0.6rem; min-width: 0; }
.entity-info__group .entity-info__field { margin-bottom: 0; }
.entity-info__field > span { font-size: 0.72rem; color: var(--muted); }
.entity-info__field input, .entity-info__field select {
  width: 100%;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
}
.entity-info__field input[inputmode="decimal"] { font-family: var(--mono); text-align: right; }
.entity-info__field input:focus, .entity-info__field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.entity-info__field--color input { width: 48px; height: 31px; padding: 2px; }
.entity-info__field--red > span { color: #c0302b; }
.entity-info__field--green > span { color: #2e8a40; }
.entity-info__field--blue > span { color: #2a5fc0; }

.editor__statusbar {
  grid-area: statusbar;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.3rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
}
.status { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="info"] { color: var(--ink); }
.save-status { color: var(--muted); }
.save-status[data-save-status="saving"] { color: var(--accent); }
.save-status[data-save-status="error"] { color: var(--danger); font-weight: 600; }

.vcb { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.vcb input {
  width: 150px;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--mono);
  text-align: right;
  background: var(--bg);
}
.vcb[data-active] input { background: #fff8e8; border-color: var(--accent); color: var(--ink); }

@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto auto; grid-template-areas: "toolbar" "viewport" "panel" "statusbar"; }
  .editor__panel { max-height: 40vh; border-left: 0; border-top: 1px solid var(--line); }
  .tool span { display: none; }
  .tool { min-width: 36px; }
}

.inference {
  position: absolute;
  top: 0;
  left: 0;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  pointer-events: none;
  white-space: nowrap;
}
.inference[data-kind="endpoint"] { color: #15a03a; }
.inference[data-kind="midpoint"] { color: #0b8aa6; }
.inference[data-kind="face"] { color: #2a62c9; }
.inference[data-kind="ground"] { color: var(--muted); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.device select {
  padding: 0.15rem 0.3rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  color: var(--muted);
}
.inference[data-kind="edge"] { color: #c2185b; }

.entity-info__actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; }
.entity-info__count { margin: 0 0 0.5rem; font-size: 0.9rem; }
.context-hint { font-size: 0.85rem; padding: 0.4rem 0.6rem; background: #eef3fb; border: 1px solid #cddcf3; border-radius: 4px; }

.context {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.35rem 0.25rem 0.65rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #cddcf3;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--ink);
}
.context__path { color: var(--muted); }
.context__path strong { color: var(--ink); }
.context button {
  border: 0;
  background: #eef3fb;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font: inherit;
  cursor: pointer;
}
.context[hidden] { display: none; }

/* Right panel: Entity Info, Materials and the Outliner, each folding away from
   its header (fold_controller.js); the Outliner fills what's left. */
/* The sidebar scrolls as a whole: panels keep their own height (long lists are
   capped and scroll inside), and the Outliner takes whatever room is left. */
.editor__panel { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
.panel { display: flex; flex-direction: column; flex: 0 0 auto; }
.panel + .panel { border-top: 1px solid var(--line); }
.panel__header { display: flex; align-items: center; gap: 0.25rem; padding: 0.55rem 0.75rem 0.4rem 1rem; }
.panel__title { flex: 1; margin: 0; font-size: inherit; }
.panel__toggle {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.panel__toggle:hover { color: var(--ink); }
.panel__toggle { gap: 0.55rem; }
/* A chevron from two borders of a small square: down when open, right when folded. */
.panel__toggle::before {
  content: ""; width: 0.45rem; height: 0.45rem; margin-left: 0.1rem;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-0.15rem) rotate(45deg); transition: transform 0.15s;
}
.panel.is-folded .panel__toggle::before { transform: rotate(-45deg); }
.panel.is-folded .panel__body, .panel.is-folded .panel__actions, .panel.is-folded .panel__resize { display: none; }
.panel__action { border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.72rem; cursor: pointer; padding: 0.1rem 0.3rem; border-radius: 3px; }
.panel__action:hover { background: var(--bg); color: var(--ink); }
.panel__body { min-height: 0; overflow-y: auto; padding-bottom: 0.75rem; }
/* Drag a panel's bottom edge to resize it (panel_size_controller.js). */
.panel__resize { flex: none; height: 7px; margin-top: -4px; cursor: row-resize; touch-action: none; position: relative; z-index: 1; }
.panel__resize:hover, .panel__resize:active { background: linear-gradient(transparent 2px, var(--line) 2px, var(--line) 5px, transparent 5px); }

.panel--entity-info { flex-shrink: 0; }
.panel__body.entity-info { padding: 0.1rem 1rem 0.9rem; }
.panel__body.materials { max-height: 18rem; }
.panel__body.hardware { max-height: 18rem; }

/* The hardware library: sizes by category, right-click one to edit or remove it. */
.panel__body.hardware { padding: 0 1rem 0.75rem; }
.hardware__category { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin: 0.6rem 0 0.25rem; }
.hardware__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.hardware__item { font-size: 0.8rem; font-variant-numeric: tabular-nums; padding: 0.15rem 0.45rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: context-menu; }
.hardware__empty { color: var(--muted); font-size: 0.85rem; }
.panel--outliner { flex: 1 0 auto; min-height: 14rem; }
.panel--outliner.is-folded { flex: 0 0 auto; min-height: 0; }
.panel__body.outliner { flex: 1; display: flex; flex-direction: column; }

.materials__list { list-style: none; margin: 0; padding: 0 0 0.5rem; overflow-y: auto; }
.materials__item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  border: 0; background: none; font: inherit; font-size: 0.85rem; color: var(--muted);
  padding: 0.22rem 0.75rem 0.22rem 1rem; text-align: left; cursor: pointer;
}
.materials__item.is-used { color: var(--ink); }
.materials__item:hover { background: var(--bg); }
.materials__item[aria-pressed=true] { box-shadow: inset 3px 0 0 var(--ink); background: var(--bg); color: var(--ink); }
.materials__swatch { flex: none; width: 14px; height: 14px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }
.materials__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.materials__thickness { flex: none; font-variant-numeric: tabular-nums; font-size: 0.78rem; color: var(--muted); }

/* Parameters: the selected parametric group's values (hidden otherwise).
   Components: the recipe library, placed with a click. */
.panel[hidden] { display: none; }
.panel__body.parameters { max-height: 26rem; }
.panel__body.parameters { padding: 0 1rem 0.9rem; }
.parameters__name { margin: 0 0 0.5rem; font-weight: 600; }
.parameters__form { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem; gap: 0.3rem 0.6rem; align-items: center; }
.parameters__field { display: contents; font-size: 0.85rem; }
.parameters__field label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parameters__field input, .parameters__field select {
  width: 100%; min-width: 0; font: inherit; font-size: 0.85rem; padding: 0.15rem 0.35rem;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink);
}
.parameters__field input[type=text], .parameters__field input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.parameters__field input:focus, .parameters__field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.parameters__field--check input { width: auto; justify-self: end; grid-column: 2; grid-row: auto; }
.parameters__field--check label { grid-column: 1; grid-row: auto; order: -1; }
.parameters__error { margin: 0.6rem 0 0; color: var(--danger); font-size: 0.82rem; }
.parameters__hint { margin: 0.6rem 0 0; color: var(--muted); font-size: 0.8rem; }

.panel__body.components { max-height: 22rem; }
.components__list { list-style: none; margin: 0; padding: 0; }
.components__item {
  display: block; width: 100%; border: 0; background: none; font: inherit; font-size: 0.85rem; color: var(--ink);
  padding: 0.22rem 0.75rem 0.22rem 1rem; text-align: left; cursor: pointer;
}
.components__item:hover { background: var(--bg); }
.components__hint { margin: 0.3rem 1rem 0.7rem; color: var(--muted); font-size: 0.8rem; }
.panel__action[aria-pressed=true] { background: var(--bg); color: var(--ink); }
.components__tiles { list-style: none; margin: 0; padding: 0.1rem 0.75rem 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.components__tile {
  display: flex; flex-direction: column; gap: 0.3rem; width: 100%; padding: 0.35rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  font: inherit; font-size: 0.8rem; color: var(--ink); text-align: center; cursor: pointer;
}
.components__tile:hover { border-color: var(--muted); }
.components__tile img, .components__no-picture { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 3px; background: #f3f1ed; }
.components__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.outliner__tree { flex: 1; overflow-y: auto; padding: 0 0 0.75rem; }
.outliner__empty { color: var(--muted); font-size: 0.85rem; padding: 0 1rem; }

.outliner__row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem 0.18rem calc(0.5rem + var(--level) * 14px);
  font-size: 0.85rem;
  cursor: default;
}
.outliner__row:hover { background: var(--bg); }
.outliner__row[aria-selected="true"] { background: #e3edfb; }
.outliner__row.is-open .outliner__name { font-weight: 600; }
.outliner__row.is-hidden .outliner__name, .outliner__row.is-hidden .outliner__icon { opacity: 0.4; }

.outliner__toggle, .outliner__toggle-spacer { width: 16px; flex: none; }
.outliner__toggle { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; font-size: 0.7rem; line-height: 1; }
.outliner__icon { display: flex; flex: none; color: var(--muted); }
.outliner__icon svg, .outliner__eye svg { width: 15px; height: 15px; }
.outliner__icon--group { color: var(--accent); }
.outliner__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.outliner__meta { flex: none; color: var(--muted); font-size: 0.72rem; font-family: var(--mono); }
.outliner__eye { display: flex; flex: none; border: 0; background: none; padding: 2px; color: var(--muted); cursor: pointer; border-radius: 3px; opacity: 0.55; }
.outliner__row:hover .outliner__eye, .outliner__row.is-hidden .outliner__eye { opacity: 1; }
.outliner__eye:hover { background: var(--line); color: var(--ink); }

/* Drag-select box: solid for a window (drag right), dashed for a crossing (drag left) */
.selection-box { position: absolute; pointer-events: none; border: 1px solid #1f6fe0; background: rgba(31, 111, 224, 0.08); }
.selection-box[data-mode="crossing"] { border-style: dashed; background: rgba(46, 155, 69, 0.08); border-color: #2e8a40; }
.selection-box[hidden] { display: none; }
.entity-info__actions--flip .button { flex: 1; }
.flip--red { color: #c0302b; }
.flip--green { color: #2e8a40; }
.flip--blue { color: #2a5fc0; }
.entity-info__actions { flex-wrap: wrap; }
.entity-info__actions .button { white-space: nowrap; padding-inline: 0.45rem; }

/* ───────────── Help ───────────── */
.page__actions { display: flex; gap: 0.5rem; }
.toolbar__group--end { margin-left: auto; padding-right: 0; border-right: 0; }

.help {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(43, 38, 32, 0.25);
  color: var(--ink);
  background: var(--surface);
}
.help[open] { display: flex; flex-direction: column; }
.help::backdrop { background: rgba(43, 38, 32, 0.35); }
.help__header { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--line); }
.help__header h2 { margin: 0; font-size: 1.1rem; }
.help__header form { margin: 0; }
.help__body { overflow-y: auto; padding: 0.5rem 1.25rem 1.5rem; }

.help-page { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 1.5rem 1.5rem; }
.help-reference { font-size: 0.92rem; }
.help-reference section { margin-top: 1.4rem; }
.help-reference h2 { font-size: 1rem; margin-bottom: 0.5rem; }
.help-reference ol, .help-reference ul { padding-left: 1.2rem; }
.help-reference li { margin-bottom: 0.35rem; }
.help-lead { color: var(--muted); margin-top: 1rem; }
.help-keys { width: 100%; border-collapse: collapse; }
.help-keys th, .help-keys td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.help-keys th[colspan] { padding-top: 0.9rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.help-keys thead th { font-size: 0.8rem; color: var(--muted); }
.help-keys td:first-child { white-space: nowrap; width: 1%; padding-right: 1.25rem; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  font: 0.8rem var(--mono);
  text-align: center;
}
code { font-family: var(--mono); font-size: 0.85em; background: var(--bg); padding: 0.05rem 0.3rem; border-radius: 3px; }
.axis { font-weight: 600; }
.axis--red { color: #c0302b; }
.axis--green { color: #2e8a40; }
.axis--blue { color: #2a5fc0; }

/* ───────────── Projects ───────────── */
.project-filters { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }
.project-filters__search {
  flex: 1;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
}
.project-filters__sort { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.9rem; }
.project-filters__sort select { padding: 0.35rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font: inherit; }

.project-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.project-card__link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  height: 100%;
  padding: 0 0 0.75rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}
.project-card__link:hover { border-color: var(--accent); }
.project-card__image, .project-card__placeholder { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #f3f1ed; margin-bottom: 0.5rem; }
.project-card__placeholder { background: repeating-linear-gradient(135deg, #f3f1ed 0 12px, #ece7df 12px 24px); }
.project-card__name { font-weight: 600; padding: 0 0.85rem; }
.project-card__meta { font-size: 0.82rem; padding: 0 0.85rem; }

.topbar__title { border: 0; background: none; color: inherit; font: inherit; font-weight: 600; padding: 0.1rem 0.35rem; border-radius: 4px; cursor: text; opacity: 0.9; }
.topbar__title:hover { background: rgba(255, 255, 255, 0.12); }
.topbar__title-input { font: inherit; font-weight: 600; padding: 0.1rem 0.35rem; border: 0; border-radius: 4px; min-width: 16rem; }
.settings-actions { display: flex; gap: 0.5rem; margin-top: 2rem; }
.settings-actions .button--danger { margin-top: 0; }

/* Sizes of the board under the Tape Measure, drawn on it (dimension_lines.js). */
.dimension {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(243, 241, 237, 0.75);
  color: #7a7168;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}
.dimension[hidden] { display: none; }
.inference[data-kind="intersection"] { color: #15a03a; }
.inference[data-kind="guide"] { color: #6b5f53; }

/* Views menu in the toolbar: a <details> dropdown (menu_controller.js). */
.views-menu { position: relative; }
.views-menu > summary { list-style: none; }
.views-menu > summary::-webkit-details-marker { display: none; }
.views-menu[open] > summary { background: var(--hover, rgba(0, 0, 0, 0.05)); }
.views-menu__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
.views-menu__list button {
  padding: 5px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.views-menu__list button:hover { background: rgba(0, 0, 0, 0.06); }
.views-menu__list hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

/* X, Y and Z on the axes (axis_labels.js): dim, in the axis colours. */
.axis-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.75;
  text-shadow: 0 0 3px var(--bg, #f3f1ed), 0 0 3px var(--bg, #f3f1ed);
  pointer-events: none;
  user-select: none;
}
.axis-label[hidden] { display: none; }

/* Presentation mode (studio.js): the model only, no labels over it. */
.presenting :is(.axis-label, .dimension, .inference, .context) { display: none; }
.axis-label[data-axis="x"] { color: #d0312d; }
.axis-label[data-axis="y"] { color: #2a62c9; }
.axis-label[data-axis="z"] { color: #2e9b45; }
.entity-info__delete { color: var(--danger); }

/* Outliner right-click menu (context_menu.js). */
.context-menu {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.14);
}
.context-menu button {
  padding: 5px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.context-menu button:hover, .context-menu button:focus-visible { background: rgba(0, 0, 0, 0.06); outline: none; }
.context-menu button.is-danger { color: var(--danger); }
.context-menu hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

/* Small dialogs for changing values (edit_dialog.js). */
.edit-dialog {
  width: min(22rem, calc(100vw - 32px));
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.edit-dialog--wide { width: min(30rem, calc(100vw - 32px)); }
.edit-dialog__note { margin: -0.4rem 0 0.75rem; font-size: 0.8rem; color: var(--muted); }
.edit-dialog::backdrop { background: rgba(30, 25, 20, 0.15); }
.edit-dialog__title { margin: 0 0 0.75rem; font-size: 1rem; }
.edit-dialog__fields { display: grid; gap: 0.6rem; }
.edit-dialog__field { display: grid; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.edit-dialog__field input, .edit-dialog__field select { min-width: 0; width: 100%; box-sizing: border-box; font: inherit; font-size: 0.95rem; padding: 0.3rem 0.45rem; color: var(--text, inherit); }
.edit-dialog__field--checkbox { grid-template-columns: auto 1fr; align-items: center; color: var(--ink); }
.edit-dialog__field--checkbox span { order: 2; }
.edit-dialog__field--length input, .edit-dialog__field--angle input { text-align: right; font-variant-numeric: tabular-nums; }
.edit-dialog__error { margin: 0.6rem 0 0; color: var(--danger); font-size: 0.85rem; }
.edit-dialog__error[hidden] { display: none; }
.edit-dialog__actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* Entity Info's read-only facts. */
.entity-info__name { margin: 0.1rem 0 0.4rem; font-weight: 600; }
.entity-info__facts { display: grid; gap: 0.25rem; margin: 0.5rem 0; }
.entity-info__fact { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0.5rem; font-size: 0.85rem; }
.entity-info__fact dt { color: var(--muted); }
.entity-info__fact dd { margin: 0; font-variant-numeric: tabular-nums; }
.inference[data-kind="aligned"] { color: #c2185b; }

/* Cut list: a plain, printable table per material and thickness. */
.cut-list__project { color: var(--muted); margin: 0.25rem 0 0; }
.cut-list__note { color: var(--muted); font-size: 0.9rem; margin: 0 0 1.5rem; }
.cut-list__empty { padding: 2rem 0; color: var(--muted); }
.cut-list__group { margin-bottom: 2rem; break-inside: avoid; }
.cut-list__heading { display: flex; align-items: baseline; gap: 1rem; font-size: 1.1rem; margin: 0 0 0.5rem; }
.cut-list__totals { margin-left: auto; font-size: 0.85rem; font-weight: normal; color: var(--muted); }
.cut-list__table { width: 100%; border-collapse: collapse; font-size: 0.92rem; table-layout: fixed; } /* columns line up across tables */
.cut-list__table th:nth-child(1) { width: 3.5rem; }
.cut-list__table th:nth-child(2), .cut-list__table th:nth-child(3) { width: 6rem; }
.cut-list__table th:nth-child(4) { width: 11rem; }
.cut-list__table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--line); }
.cut-list__table td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.cut-list__qty, .cut-list__size { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cut-list__qty { font-weight: 600; }
.cut-list__names { color: var(--muted); }
.hardware-list .cut-list__table th:nth-child(2) { width: auto; } /* qty, then the item across the rest */
.cut-list__cuts div + div, .cut-list__edges div + div { margin-top: 0.2rem; }

@media print {
  .topbar, .cut-list__actions { display: none; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .cut-list__table th, .cut-list__table td { border-color: #999; }
}

/* Sheet layouts on the cut list: each sheet drawn to scale, parts in it. */
.sheet-layout { margin-top: 0.9rem; }
.sheet-layout__summary { margin: 0 0 0.5rem; font-size: 0.9rem; }
.sheet-layout__warning { margin: 0 0 0.5rem; font-size: 0.9rem; color: #a3341f; }
.sheet-layout__hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }
.sheet-layout__sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1.25rem; }
.sheet-layout__sheet { margin: 0; break-inside: avoid; }
.sheet-layout__sheet svg { display: block; width: 100%; height: auto; }
.sheet-layout__sheet figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }
.sheet-layout__stock { fill: #ece6dc; stroke: #8a7f70; stroke-width: 3; vector-effect: non-scaling-stroke; }
.sheet-layout__part rect { fill: #e4d0a5; stroke: #2b2620; stroke-width: 1; vector-effect: non-scaling-stroke; }
.sheet-layout__part text { fill: #2b2620; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }

/* Solid wood on the cut list: glue-ups, and the boards on hand. */
.cut-list__section { font-size: 1.35rem; margin: 2.5rem 0 0.5rem; padding-top: 1.5rem; border-top: 2px solid var(--line); }
.glue-ups__material { margin-bottom: 2rem; }
.glue-ups__rough { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.stock-boards__remove { text-align: right; }
.stock-boards__remove form { display: inline; }
.stock-boards__form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem; margin-top: 0.9rem; }
.stock-boards__form .field { flex: 0 1 7rem; margin: 0; }
.stock-boards__form .field:first-child { flex: 1 1 10rem; }
.stock-boards__form .stock-boards__quantity { flex-basis: 4.5rem; }
.flash--alert { background: #f8e1dc; color: #7a2615; }
@media print { .stock-boards__form, .stock-boards__remove { display: none; } }

/* Workshop settings: the tools on hand, as checkboxes. */
.field--checkboxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.35rem 1rem; }
.field__checkbox { display: flex; align-items: center; gap: 0.45rem; font-weight: normal; }
