:root {
  --bg-0: #eaeef3;
  --bg-1: #e2e7ee;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --sheet: #ffffff;

  --ink: #121a24;
  --ink-2: #38424f;
  --muted: #667082;
  --faint: #7b8594;   /* 4.0:1 on white — was 2.8:1, illegible for low vision */

  --line: #e2e7ee;
  --line-2: #eef1f6;

  --accent: #0f857a;
  --accent-600: #0c6f65;
  --accent-700: #0a5a52;
  --accent-050: #e7f4f2;
  --accent-100: #cfeae5;

  --danger: #c23a26;
  --danger-050: #fbeae6;
  --danger-line: #efc9bf;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  /* the figure itself is set in Arial — what journals ask for, and what
     the exported file will use, so the preview is what you submit */
  --font-fig: Arial, Helvetica, sans-serif;

  --r1: 8px;
  --r2: 12px;
  --r3: 16px;

  --shadow-1: 0 1px 2px rgba(18, 26, 36, .06);
  --shadow-2: 0 6px 18px -8px rgba(18, 26, 36, .18);
  --shadow-3: 0 26px 56px -28px rgba(18, 26, 36, .40);
  --ring: 0 0 0 3px var(--accent-050);
}

* { box-sizing: border-box; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
button { font: inherit; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-0);
}

/* ============ Top bar ============ */
.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px;
  padding: 5px 10px; min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand__badge {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  background: var(--accent);
  display: grid; place-items: center;
}
.brand__badge svg { width: 20px; height: 20px; }
.brand__badge rect { fill: #fff; }
.brand__badge path { fill: none; stroke: #fff; stroke-width: 1.7; opacity: .95; }

.plan {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
  transition: border-color .15s;
}
.plan:hover { border-color: var(--faint); }
.plan__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.plan[data-pro="true"] { color: var(--accent-700); border-color: var(--accent-100); background: var(--accent-050); }
.plan[data-pro="true"] .plan__dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-100); }

#savedNote[data-state="bad"] { color: var(--danger); }

/* ---- dropdown menus ---- */
.menu { position: relative; }
.pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r3); box-shadow: var(--shadow-3);
  padding: 16px; width: 340px;
  animation: pop-in .14s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; } }
.pop__head { margin-bottom: 13px; }
.pop__head strong { display: block; font-family: var(--font-display); font-size: 14.5px; letter-spacing: -.01em; }
.pop__head span { display: block; font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.pop__label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.pop__note { margin: 7px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.pop__note:empty { display: none; }
.pop__grid { margin-top: 11px; }
.pop__row { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.pop__update {
  margin-top: 8px; width: 100%; padding: 8px; cursor: pointer;
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 550; color: var(--accent-700);
  background: var(--accent-050); border: 1px solid var(--accent-100); border-radius: 9px;
}
.pop__list { margin-top: 12px; max-height: 210px; overflow-y: auto; }
.pop__list:empty::after {
  content: "No saved projects yet."; display: block;
  font-size: 12px; color: var(--faint); padding: 10px 2px;
}
.proj {
  /* the name takes the room that is left; the row actions never wrap */
  display: flex; align-items: center; gap: 4px;
  padding: 8px 9px; border-radius: 9px; border: 1px solid transparent;
}
.proj > .proj__open { flex: 1; }
.proj:hover { background: var(--surface-2); border-color: var(--line-2); }
.proj__open { text-align: left; background: none; border: 0; cursor: pointer; padding: 0; min-width: 0; }
.proj__name { display: block; font-size: 12.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj__meta { display: block; font-family: var(--font-mono); font-size: 10px; color: var(--faint); margin-top: 2px; }
.proj--on .proj__name { color: var(--accent-700); font-weight: 600; }
.proj__del { flex: none; border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px; border-radius: 5px; }
.proj__del:hover { color: var(--danger); background: var(--danger-050); }
.pop__foot { display: flex; gap: 14px; margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line-2); }
.pop__link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: var(--font-ui); font-size: 12px; font-weight: 550; color: var(--accent-700);
}
.pop__link:hover { text-decoration: underline; }

/* ---- pre-flight ---- */
.preflight { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line-2); }
.pf__stats { display: flex; flex-wrap: wrap; gap: 6px; }
.pf__stat {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line-2);
  padding: 3px 7px; border-radius: 6px;
}
.pf__stat b { color: var(--ink); font-weight: 600; }
.pf__msg {
  display: flex; gap: 7px; margin-top: 8px; padding: 8px 10px;
  border-radius: 8px; font-size: 11.5px; line-height: 1.45;
}
.pf__msg::before { content: "!"; font-weight: 700; flex: none; }
.pf__msg--bad { background: var(--danger-050); border: 1px solid var(--danger-line); color: #8a3322; }
.pf__msg--warn { background: #fdf6e7; border: 1px solid #edd9ae; color: #7d5a14; }
.pf__msg--ok { background: var(--accent-050); border: 1px solid var(--accent-100); color: var(--accent-700); }
.pf__msg--ok::before { content: "✓"; }

/* ---- format picker ---- */
.formats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 13px; }
.fmt {
  position: relative;
  text-align: left; cursor: pointer; padding: 9px 11px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .14s, background .14s;
}
/* the arrow says it plainly: one click saves the file */
.fmt .ic { position: absolute; top: 9px; right: 9px; color: var(--faint); }
.fmt:hover .ic { color: var(--accent-700); }
.fmt:hover { border-color: var(--accent); background: var(--accent-050); }
.fmt strong { display: block; font-family: var(--font-display); font-size: 13px; }
.fmt span { display: block; font-size: 10.5px; color: var(--faint); margin-top: 1px; }
.fmt--no { opacity: .55; }
.fmt--no strong::after { content: " · not accepted"; font-family: var(--font-ui); font-weight: 400; font-size: 9.5px; color: var(--danger); }

.export { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-ui); font-weight: 550; font-size: 13px;
  height: 40px; padding: 0 14px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  transition: transform .08s, background .16s, border-color .16s, box-shadow .16s;
}
.btn:active { transform: translateY(1px); }
.btn__i { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.btn--primary {
  background: var(--accent); color: #fff;
}
.btn--primary:hover { background: var(--accent-600); }
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--icon { width: 40px; height: 40px; padding: 0; justify-content: center; }
.btn--ghost:hover { border-color: var(--accent-100); color: var(--accent-700); }

/* ============ Workspace ============ */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 336px 1fr;   /* every panel pixel is stage width */
  min-height: 0;
}

/* ============ Form panel ============ */
.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; overflow-y: auto;
}
.panel__head { padding: 16px 22px 8px; }
.tplpick__label {
  display: block; font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em; color: var(--accent-700);
  margin-bottom: 6px;
}
.tplpick {
  width: 100%; margin-bottom: 14px;
  font-family: var(--font-ui); font-weight: 550; font-size: 14px;
}
.panel__title { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: -.02em; margin: 0 0 7px; }
.panel__sub { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.panel__note {
  margin: auto 24px 0; padding: 15px 0 22px;
  color: var(--faint); font-size: 11.5px; line-height: 1.55;
  border-top: 1px solid var(--line-2);
}

.form { padding: 8px 24px; }
.fset { border: 0; margin: 0; padding: 16px 0; border-top: 1px solid var(--line-2); }
.fset:first-child { border-top: 0; }
.fset__legend {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .11em;
  color: var(--accent-700); margin-bottom: 13px;
}
.fset__legend::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }

.field { margin-bottom: 11px; }
.field__label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13.5px; color: var(--ink-2); margin-bottom: 6px; gap: 8px;
}
.field__label span { color: var(--faint); font-family: var(--font-mono); font-size: 10.5px; }

.input {
  width: 100%; font-family: var(--font-mono); font-size: 14px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 12px; transition: border-color .14s, box-shadow .14s, background .14s;
}
.input:hover { border-color: #d3d9e2; }
.input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: var(--ring); }
.input--text { font-family: var(--font-ui); }
input[type="number"].input { -moz-appearance: textfield; }
input[type="number"].input::-webkit-outer-spin-button,
input[type="number"].input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.computed {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border-radius: 9px; margin-bottom: 11px;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-left: 2.5px solid var(--accent);
}
.computed__label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.computed__val { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--ink); }
.computed--bad { background: var(--danger-050); border-color: var(--danger-line); border-left-color: var(--danger); }
.computed--bad .computed__val, .computed--bad .computed__label { color: var(--danger); }

.chip {
  font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 6px; border-radius: 5px; vertical-align: middle;
}
.chip--auto { background: var(--accent-050); color: var(--accent-700); }

.input--select { cursor: pointer; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23667082' stroke-width='1.4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.rep-head { display: grid; gap: 6px; margin-bottom: 6px; padding: 0 2px; }
.rep-head span { font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); }

.reasons { display: flex; flex-direction: column; gap: 7px; }
.reason { display: grid; grid-template-columns: 1fr 64px 30px; gap: 6px; align-items: center; }
.reason .input { margin: 0; }
.reason__del {
  border: 1px solid var(--line); background: var(--surface); color: var(--faint);
  border-radius: 8px; height: 36px; cursor: pointer; font-size: 16px; line-height: 1;
  transition: color .14s, border-color .14s;
}
.reason__del:hover { color: var(--danger); border-color: var(--danger-line); }
.reason__add {
  margin-top: 9px; font-family: var(--font-ui); font-size: 12.5px; font-weight: 550;
  color: var(--accent-700); background: transparent; border: 1px dashed var(--line);
  border-radius: 9px; padding: 9px; width: 100%; cursor: pointer; transition: border-color .14s, background .14s;
}
.reason__add:hover { border-color: var(--accent); background: var(--accent-050); }

/* ============ Stage ============ */
.stage {
  position: relative;   /* anchors the floating canvas toolbar */
  /* a 2×2 grid: the rulers occupy the first row and column and collapse to
     nothing outside the free canvas, so every other template is unchanged */
  display: grid; grid-template-columns: 0 1fr; grid-template-rows: 0 1fr;
  min-height: 0;
  /* a grid item's implicit min-width:auto would let a zoomed sheet widen the
     whole page instead of scrolling inside the stage */
  min-width: 0;
  background:
    linear-gradient(rgba(148, 163, 184, .09) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(90deg, rgba(148, 163, 184, .09) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 100%);
}
/* on the canvas the format bar replaces the label and hint */
body[data-canvas="1"] .stage__label,
body[data-canvas="1"] .stage__hint { display: none; }
.stage__label { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); }
.stage__hint {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px;
}
.stage__hint svg { width: 12px; height: 12px; fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linejoin: round; }
.stage__right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.wm {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-ui); font-size: 11.5px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; transition: color .15s, border-color .15s;
}
.wm:hover { color: var(--accent-700); border-color: var(--accent-100); }
.wm--off { color: var(--accent-700); border-style: solid; border-color: var(--accent-100); background: var(--accent-050); }
body[data-canvas="1"] .wm span { display: none; }
body[data-canvas="1"] .wm { padding: 8px; }

.zoom { position: relative; display: flex; align-items: center; gap: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.zbtn { display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 38px; border: 0; background: transparent; color: var(--ink-2);
  border-radius: 8px; cursor: pointer; transition: background .15s, color .15s; }
.zbtn--on { background: var(--accent-050); color: var(--accent-700); }
.zbtn:hover { background: var(--surface-2); }

.zval {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2);
  min-width: 54px; height: 38px; padding: 0 3px 0 5px;
  background: transparent; border: 1px solid transparent; border-radius: 7px; cursor: pointer;
  transition: background .15s, color .15s;
}
.zval .ic { opacity: .7; }
.zval:hover { background: var(--surface-2); color: var(--ink); }
.zval--fit { background: var(--accent-050); color: var(--accent-700); border-color: var(--accent-100); }
.zmenu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; min-width: 158px; padding: 5px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-3);
}
.zitem {
  display: block; width: 100%; padding: 7px 10px; cursor: pointer; text-align: left;
  background: transparent; border: 0; border-radius: 7px;
  font-family: var(--font-ui); font-size: 12.5px; color: var(--ink);
}
.zitem:hover { background: var(--accent-050); color: var(--accent-700); }
.zitem--on { color: var(--accent-700); font-weight: 600; }
.zitem--on::after { content: " ✓"; }

/* layout notes float over the drawing: opening them moves nothing */
.ribbon { position: absolute; top: 10px; left: 14px; z-index: 18; margin: 0; }
.ribbon summary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; cursor: pointer; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; color: var(--muted);
  transition: border-color .15s, color .15s;
}
.ribbon summary::-webkit-details-marker { display: none; }
.ribbon summary:hover { color: var(--ink); border-color: #dcc9a8; }
.ribbon__icon { width: 16px; height: 16px; color: #b45a1e; flex: none; }
.ribbon__chev { width: 14px; height: 14px; color: var(--faint); transition: transform .18s; }
.ribbon[open] .ribbon__chev { transform: rotate(180deg); }
.ribbon:not([open]) .ribbon__msgs { display: none; }
.ribbon__msgs {
  position: absolute; top: calc(100% + 6px); left: 0;
  margin: 0; padding: 10px 14px; width: max-content; max-width: 560px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow-2);
}
.ribbon__msgs span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.stage__scroll { grid-area: 2 / 2; overflow: auto; display: flex; padding: 18px; }

/* ============ Rulers & guides ============ */
.rul { display: none; }
body[data-canvas="1"] .stage { grid-template-columns: 17px 1fr; grid-template-rows: 17px 1fr; }
body[data-canvas="1"] .rul { display: block; }
body[data-canvas="1"] .ribbon { top: 26px; left: 30px; }
.rul--corner { grid-area: 1 / 1; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
.rul--h {
  grid-area: 1 / 2; width: 100%; height: 17px;
  border-bottom: 1px solid var(--line-2); cursor: ns-resize;
}
.rul--v {
  grid-area: 2 / 1; width: 17px; height: 100%;
  border-right: 1px solid var(--line-2); cursor: ew-resize;
}
body.c-guide-h #sheetInner, body.c-guide-h .rul { cursor: ns-resize !important; }
body.c-guide-v #sheetInner, body.c-guide-v .rul { cursor: ew-resize !important; }
.sheet {
  position: relative; background: var(--sheet);
  border: 1px solid var(--line); border-radius: 3px;
  box-shadow: var(--shadow-3);
  /* auto margins centre a small sheet but collapse to zero when it outgrows
     the viewport, so every scaled pixel stays inside the scroll range */
  /* visible: hover dots and the "+" now hang past the slim page margin,
     and must still render (they draw over the grey stage) */
  margin: auto; flex: none; overflow: visible;
  animation: sheet-in .3s ease-out;
}
/* opacity only: a transform here would fight the explicit sheet size and
   freezes at its first frame in throttled background tabs */
@keyframes sheet-in { from { opacity: 0; } to { opacity: 1; } }
.sheet__inner { display: block; transform-origin: 0 0; }
.sheet__inner svg { display: block; overflow: visible; }

.reg { position: absolute; width: 12px; height: 12px; pointer-events: none; }
.reg::before, .reg::after { content: ""; position: absolute; background: var(--faint); opacity: .7; }
.reg::before { width: 100%; height: 1px; top: 50%; }
.reg::after { height: 100%; width: 1px; left: 50%; }
.reg--tl { top: -20px; left: -20px; }
.reg--tr { top: -20px; right: -20px; }
.reg--bl { bottom: -20px; left: -20px; }
.reg--br { bottom: -20px; right: -20px; }

/* ============ SVG diagram ============ */
.d-box { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.4; }
.d-box--soft { fill: #fbfcfd; }
.d-box--bad { stroke: #cf7a5f; fill: #fdf8f6; }
.d-band { fill: var(--ink); }
.d-band-text { fill: #fff; font-family: var(--font-fig); font-weight: 500; font-size: 12px; letter-spacing: .06em; }
.d-txt { fill: var(--ink); font-family: var(--font-fig); font-size: 12.5px; }
.d-txt--lead { font-weight: 600; }
.d-num { font-family: var(--font-fig); font-weight: 600; fill: var(--ink); }
.d-edge { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.d-wm { fill: var(--faint); font-family: var(--font-fig); font-size: 11px; }
.d-decision { fill: #eef5f3; }
.d-terminal { fill: var(--ink); }
.d-txt--inv { fill: #fff; }
/* branch labels (Yes/No) read at a glance: larger and heavier than body text */
.d-edgelabel { fill: var(--muted); font-family: var(--font-fig); font-size: 13px; font-weight: 600; }

/* inline colour-swatch row (edge label colour in the panel) */
.swrow { display: flex; gap: 6px; flex-wrap: wrap; }

/* while a connection is selected, button captions give way so the whole
   strip — tools, line controls and the app's right side — stays one row */
.cbar--edge .bbtn__lbl { display: none; }

/* THE BAR NEVER WRAPS. Wrapping produced a second row (the user saw
   "three bars" inside the artifact viewer). Instead the strip stays one
   row at every width: captions collapse first, then secondary chrome
   hides, and as a last resort the tool strip scrolls sideways. */
.topbar { flex-wrap: nowrap; }
.stage__right { flex: none; }   /* app chrome never squashes */
.stage__label, .stage__hint { min-width: 0; }
.stage__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1560px) {
  .cbar .bbtn__lbl { display: none; }
  .stage__hint { display: none; }
}
@media (max-width: 1280px) {
  #wmHint, #planBadge { display: none; }
  #btnExport .btn__t { display: none; }
  .zbtn { display: none; }         /* the presets menu still covers zoom */
  #cBar .baux { display: none; }   /* label size stays in the panel */
}
@media (max-width: 1160px) {
  #cBar .baux2 { display: none; }  /* medium line weight yields; thin/thick stay */
  /* everything hidden here stays reachable in the right-click menu */
  .bsizewrap .bbtn { display: none; }
  #cBar .bgroup--right .bbtn:not(.bbtn--danger):not(.bbtn--lock) { display: none; }
  .bsep { margin: 0 2px; }
}
@media (max-width: 1040px) {
  /* cramped (artifact viewer on a laptop): undo/redo buttons yield —
     Ctrl+Z / Ctrl+Y and the right-click menu keep both reachable —
     and the remaining targets slim down a notch */
  #cBar .bbtn--aux { display: none; }
  #cBar .bbtn { min-width: 34px; width: 34px; height: 34px; }
  #cBar .bsel { min-width: 62px; }
  .cbar { gap: 2px; }
  .bsep { display: none; }
}
.sheet__inner .d-edit { cursor: text; }
.sheet__inner .d-edit:hover { fill: var(--accent); text-decoration: underline; text-decoration-thickness: 1.5px; }
.sheet__inner .d-box--bad .d-num { fill: var(--danger); }
.sheet__inner [data-comp] { cursor: help; }
.sheet__inner .d-cell { cursor: pointer; }
.sheet__inner .d-cell:hover { fill: rgba(15, 133, 122, .10); }
/* the canvas is dragged directly, so suppress text selection while editing it */
body[data-canvas="1"] .sheet__inner { cursor: default; user-select: none; }
body[data-canvas="1"] .sheet__inner text { user-select: none; }

/* ---- free canvas: palette, properties, shortcut list ---- */
.tab--free { position: relative; }
.tab--free::before {
  content: ""; position: absolute; left: 3px; top: 50%; transform: translateY(-50%);
  width: 1px; height: 14px; background: var(--line);
}
.palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pal {
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: grab;
  padding: 11px 6px 8px; border-radius: 10px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-ui); font-size: 12.5px; color: var(--muted);
  transition: border-color .15s, background .15s, color .15s;
}
.pal:hover { border-color: var(--accent); background: var(--accent-050); color: var(--accent-700); }
.pal:active { cursor: grabbing; }
.pal--dragging { opacity: .45; }
.pal__ico { width: 52px; height: 34px; flex: none; color: var(--ink-2); display: block; }
.pal__ico svg { width: 100%; height: 100%; display: block; }
.pal:hover .pal__ico { color: var(--accent-700); }
.pal__lbl { line-height: 1.2; }

/* ---- shared icon sizing (one family, one stroke) ---- */
.ic { flex: none; display: block; }
.btn .ic { margin-right: -1px; }

/* ---- shape search ---- */
.shapesearch {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 22px 10px; padding: 0 11px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  color: var(--faint);
}
.shapesearch:focus-within { border-color: var(--accent); box-shadow: var(--ring); background: var(--surface); }
.shapesearch__in {
  flex: 1; min-width: 0; height: 38px; border: 0; background: transparent;
  font-family: var(--font-ui); font-size: 13px; color: var(--ink); outline: none;
}
.shapesearch__in::-webkit-search-cancel-button { cursor: pointer; }

/* ---- keyboard sheet (folded away by default) ---- */
.keysheet { margin: 6px 22px 20px; border-top: 1px solid var(--line-2); padding-top: 12px; }
.keysheet summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  font-size: 12.5px; font-weight: 550; color: var(--muted); padding: 4px 0;
}
.keysheet summary::-webkit-details-marker { display: none; }
.keysheet summary:hover { color: var(--accent-700); }
.keysheet summary span { flex: 1; }
.keysheet summary .ic:last-child { transition: transform .18s; }
.keysheet[open] summary .ic:last-child { transform: rotate(180deg); }
.keysheet .keys { margin-top: 10px; }

.lockednote {
  display: flex; align-items: flex-start; gap: 7px; margin: 10px 0 0;
  padding: 8px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line-2);
  font-size: 11.5px; color: var(--muted); line-height: 1.45;
}
.lockednote .ic { margin-top: 1px; color: var(--faint); }

/* ---- fixed format bar (sits in the stage chrome, covers nothing) ---- */
.cbar {
  /* NOWRAP is the whole point: a wrapped strip reads as a second bar.
     At narrow widths the media queries below shed captions and secondary
     buttons instead. No overflow rule here — the colour palettes hang
     out of this box and would be clipped by any overflow value. */
  display: flex; align-items: center; flex-wrap: nowrap; gap: 3px 3px;
  flex: 1 1 auto; min-width: 0; padding: 0;
  background: transparent;
  /* never scroll or clip: the colour palettes hang out of this box, and
     overflow-x:auto silently forces overflow-y:auto, which cut them off */
}
.bgroup { display: flex; align-items: center; gap: 3px; }
.bgroup--right { margin-left: auto; padding-left: 6px; }
.bsep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; flex: none; }
.bbtn {
  position: relative;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 40px; height: 40px; flex: none; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  color: var(--ink-2); transition: background .15s, color .15s;
}
/* the five actions everyone needs carry their name, not just a glyph */
.bbtn--labeled { flex-direction: row; gap: 5px; padding: 0 9px; width: auto; }
.bbtn__lbl { font-family: var(--font-ui); font-size: 13px; font-weight: 550; }
.bbtn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.bbtn--on { background: var(--accent-050); color: var(--accent-700); border-color: var(--accent-100); }
.bbtn--danger:hover:not(:disabled) { background: var(--danger-050); color: var(--danger); }
.bbtn:disabled { color: #cfd6e0; cursor: default; }
.bswatch { position: relative; display: flex; flex: none; }
.swbar {
  width: 18px; height: 4px; border-radius: 2px; display: block;
  border: 1px solid rgba(18, 26, 36, .14);
}
.bsel {
  height: 40px; flex: none; cursor: pointer; padding: 0 28px 0 11px;
  font-family: var(--font-ui); font-size: 13.5px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23667082' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.bsel:hover { border-color: var(--faint); }
.bhint { font-size: 13.5px; color: var(--muted); white-space: nowrap; padding-left: 4px; }
.bsizewrap { display: flex; align-items: center; gap: 2px; flex: none; }
.bsizewrap .bsel { min-width: 74px; }

.tpop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60;
  display: grid; grid-template-columns: repeat(5, 30px); gap: 8px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-3);
}
.tpop--right { left: auto; right: 0; }
.swopt { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.swopt:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.swopt--on { outline: 2px solid var(--accent-700); outline-offset: 1px; }

/* ---- right-click menu ---- */
.cmenu {
  position: fixed; z-index: 60; min-width: 232px; padding: 5px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; box-shadow: var(--shadow-3);
  max-height: 82vh; overflow-y: auto;
}
.mitem {
  display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 10px;
  width: 100%; padding: 10px 10px; cursor: pointer; text-align: left;
  background: transparent; border: 0; border-radius: 7px;
  font-family: var(--font-ui); font-size: 13.5px; color: var(--ink);
}
.mitem__i { display: flex; color: var(--faint); }
.mitem:hover:not(:disabled) .mitem__i { color: var(--accent-700); }
.mitem:disabled .mitem__i { color: var(--line); }
.mitem:hover:not(:disabled) { background: var(--accent-050); color: var(--accent-700); }
.mitem:disabled { color: var(--faint); cursor: default; }
.mitem kbd {
  font-family: var(--font-mono); font-size: 10px; color: var(--faint);
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: 4px; padding: 1px 5px;
}
.mdiv { height: 1px; background: var(--line-2); margin: 4px 6px; }

/* Per-position cursors are set inline by the canvas (resize arrows, crosshair,
   move). These whole-canvas modes are the exception, so the script clears the
   inline value while one is active and lets these rules through. */
body.c-pan .sheet__inner { cursor: grab; }
body.c-panning .sheet__inner { cursor: grabbing; }
body.c-linetool .sheet__inner { cursor: crosshair; }

.cbtn {
  width: 100%; margin-top: 8px; padding: 9px; cursor: pointer;
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 550;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px;
  transition: border-color .14s, color .14s, background .14s;
}
.cbtn:hover { border-color: var(--accent); color: var(--accent-700); background: var(--accent-050); }
.cbtn--danger:hover { border-color: var(--danger-line); color: var(--danger); background: var(--danger-050); }
.cgrid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btnrow { display: flex; gap: 4px; }
.btnrow .bbtn { background: var(--surface-2); border-color: var(--line); }
.btnrow .bbtn.bbtn--on { background: var(--accent-050); border-color: var(--accent-100); }

.keys { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; align-items: baseline; }
.keys dt {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--accent-700);
  background: var(--accent-050); border-radius: 5px; padding: 2px 6px; white-space: nowrap;
}
.keys dd { margin: 0; font-size: 12.5px; color: var(--muted); }

.canvas-editor {
  position: fixed; display: none; z-index: 40; resize: none;
  font-family: var(--font-fig); text-align: center; line-height: 1.36;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--accent); border-radius: 6px;
  padding: 6px; box-shadow: 0 4px 16px -4px rgba(12, 111, 101, .5), var(--ring);
  outline: none; overflow: hidden;
}

/* floating inline editor */
.fig-editor {
  position: fixed; display: none; z-index: 40;
  font-family: var(--font-mono); font-weight: 500; text-align: center;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--accent); border-radius: 6px;
  padding: 0 4px; box-shadow: 0 4px 14px -4px rgba(12, 111, 101, .5), var(--ring);
  outline: none; line-height: 1;
}

/* ============ Modal ============ */
.modal { position: fixed; inset: 0; background: rgba(18, 26, 36, .44); display: grid; place-items: center; z-index: 50; padding: 20px; backdrop-filter: blur(2px); }
.modal__box { position: relative; background: var(--surface); border-radius: var(--r3); padding: 30px 28px 26px; max-width: 404px; box-shadow: var(--shadow-3); }
.modal__x { position: absolute; top: 14px; right: 16px; border: 0; background: transparent; cursor: pointer; font-size: 22px; line-height: 1; color: var(--faint); }
.modal__eyebrow { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent-700); margin: 0 0 6px; }
.modal__title { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 0 0 10px; letter-spacing: -.02em; }
.modal__body { margin: 0 0 16px; color: var(--muted); line-height: 1.55; font-size: 13.5px; }
.modal__list { margin: 0 0 20px; padding-left: 0; list-style: none; }
.modal__list li { padding: 7px 0 7px 25px; position: relative; font-size: 13px; border-top: 1px solid var(--line-2); }
.modal__list li::before { content: "✓"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.modal__cta { display: flex; gap: 10px; }
.modal__cta .btn { flex: 1; justify-content: center; }

/* ============ Account & cloud projects ============ */
.btn--on { color: var(--accent-700); border-color: var(--accent-100); background: var(--accent-050); }
#cloudNote { font-size: 11.5px; }
#cloudNote:empty { display: none; }
#cloudNote[data-state="saving"] { color: var(--muted); }
#cloudNote[data-state="saved"] { color: var(--accent-700); }
#cloudNote[data-state="error"] { color: var(--danger); }
.cloudbox { border-bottom: 1px solid var(--line-2); padding-bottom: 11px; margin-bottom: 11px; }
.cloudbox__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 11.5px; color: var(--muted); margin-bottom: 8px;
}
.cloudbox__head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloudcta {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 12px; margin-bottom: 11px; border-radius: 10px;
  background: var(--accent-050); border: 1px solid var(--accent-100);
  font-family: var(--font-ui);
}
.cloudcta strong { display: block; font-size: 12.5px; color: var(--accent-700); }
.cloudcta span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.cloudcta:hover { background: #e6f3f0; }
.proj__ico {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--faint);
}
.proj__ico:hover { background: var(--bg-1); color: var(--accent-700); }
.pop__empty { font-size: 12px; color: var(--faint); padding: 8px 2px; }
.authnote { margin: 4px 0 0; font-size: 12px; color: var(--muted); min-height: 16px; }
.authnote[data-bad="1"] { color: var(--danger); }
.authlinks { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.verlist { display: flex; flex-direction: column; gap: 2px; max-height: 40vh; overflow: auto; }
.ver {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 2px; border-top: 1px solid var(--line-2); font-size: 12.5px; color: var(--muted);
}

/* ============ AI spelling check ============ */
.aibody { max-height: 46vh; overflow: auto; }
.aibody p { margin: 0 0 10px; }
.aiform { display: grid; gap: 4px; margin-top: 6px; }
.aiform .input { margin-bottom: 8px; }
.aifix {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 9px 2px; border-top: 1px solid var(--line-2);
}
.aifix input { margin-top: 3px; accent-color: var(--accent); }
.aifix__txt { flex: 1; min-width: 0; font-size: 13px; line-height: 1.45; }
.aifix del { display: block; color: var(--danger); text-decoration-line: line-through; }
.aifix ins { display: block; color: var(--accent-700); text-decoration: none; font-weight: 600; }
.aita {
  width: 100%; min-height: 72px; margin-bottom: 8px; padding: 8px;
  font: 12px/1.5 var(--font-mono); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; resize: vertical;
  background: var(--surface);
}

/* the custom-theme dialog */
.themeform {
  display: grid; grid-template-columns: 1fr auto; gap: 9px 14px; align-items: center;
}
.themeform__lbl { font-size: 13px; color: var(--ink); }
.themeform__col {
  width: 52px; height: 32px; padding: 2px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}

/* ============ Colour popover: recents, rainbow picker, hex ============ */
.tpop__custom {
  display: flex; gap: 7px; align-items: center;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-2);
  grid-column: 1 / -1;
}
.tpop__custom--panel { border-top: 0; padding-top: 2px; margin-top: 7px; }
/* the rainbow circle everyone recognises as "all the colours" — clicking it
   opens the system's full colour-picker dialog */
.tpop__wheelbtn {
  position: relative; display: block; flex: none;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line);
  background: conic-gradient(#f00, #ff8000, #ff0, #0c0, #0cc, #06f, #90f, #f0c, #f00);
}
.tpop__wheelbtn .tpop__wheel {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.tpop__hex {
  width: 86px; padding: 5px 7px; font-size: 12.5px;
  font-family: var(--font-mono);
}
.input--bad { border-color: var(--danger) !important; }
.tpop__recent { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.tpop__recent:empty { display: none; }
.swopt--mini { width: 22px !important; height: 22px !important; }

/* ============ Design themes popover ============ */
.tpop--themes {
  display: block; width: 228px; padding: 7px;
}
.theme {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 8px; cursor: pointer; border: 0; border-radius: 8px;
  background: none; font-family: var(--font-ui); font-size: 12.5px;
  color: var(--ink); text-align: left;
}
.theme:hover { background: var(--bg-1); }
.theme__chips { display: flex; gap: 3px; flex: none; }
.theme__chips span {
  width: 15px; height: 15px; border-radius: 4px;
  border: 1.4px solid transparent; display: block;
}
.theme__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ "+" shape picker ============ */
.cpluspick {
  position: fixed; z-index: 70;
  display: grid; grid-template-columns: repeat(4, 46px); gap: 4px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow-3);
}
.cpluspick__opt {
  width: 46px; height: 38px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; color: var(--ink);
  display: grid; place-items: center;
}
.cpluspick__opt:hover, .cpluspick__opt:focus-visible { background: var(--bg-1); color: var(--accent-700); }
.cpluspick__opt svg { width: 34px; height: 25px; }

/* ============ Format painter ============ */
body.c-paint #sheetInner, body.c-paint #sheetInner * { cursor: copy !important; }

/* ============ Export width & dpi rows ============ */
.pop__dpirow { display: flex; gap: 7px; }
.pop__dpirow .input--select { flex: 1; min-width: 0; }
#dpiCustom, #widthMm { width: 86px; flex: none; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px; padding: 11px 18px; border-radius: 10px;
  z-index: 60; box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .55);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ Responsive ============ */
@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .topbar { grid-template-columns: auto 1fr; row-gap: 10px; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
  .topbar__actions { grid-row: 1; }
  .stage__hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
