/* scad-workbench 1.2.0
 * Everything is scoped to .swb. Colours, fonts and radii are CSS variables on
 * .swb, set to the Distorted Logic defaults: override any of them on .swb (or
 * an ancestor rule with higher specificity) to restyle. Dark theme follows
 * prefers-color-scheme, and data-theme="light|dark" on <html> wins over it.
 * Fonts: load Plus Jakarta Sans, Source Sans 3 and JetBrains Mono from Google
 * Fonts in the page, or set --swb-font-* to your own stacks.
 */
.swb {
  --bg: #ffffff; --panel: #ffffff; --band: #f3f6fb; --line: #e1e7f0; --fg: #111a2b; --muted: #5a6880;
  --accent: #1f5fe0; --accent-ink: #ffffff; --accent-soft: #e8effd;
  --warn: #b45309; --warn-soft: #fdf1e3; --bad: #b45309; --bad-soft: #fdf1e3;
  --stage: #f3f6fb; --ghost: #93a1b8;
  --swb-font-head: "Plus Jakarta Sans", system-ui, sans-serif;
  --swb-font-body: "Source Sans 3", system-ui, -apple-system, sans-serif;
  --swb-font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --swb-radius: 12px; --swb-radius-btn: 8px;
  --swb-rail: minmax(280px, 350px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .swb {
    --bg: #0c1220; --panel: #131d31; --band: #111a2c; --line: #22304a; --fg: #e6ecf5; --muted: #93a1b8;
    --accent: #6c9dff; --accent-ink: #0c1220; --accent-soft: #1a2a4a;
    --warn: #f0b46a; --warn-soft: #2a2113; --bad: #f0b46a; --bad-soft: #2a2113;
    --stage: #111a2c; --ghost: #5a6880;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] .swb {
  --bg: #0c1220; --panel: #131d31; --band: #111a2c; --line: #22304a; --fg: #e6ecf5; --muted: #93a1b8;
  --accent: #6c9dff; --accent-ink: #0c1220; --accent-soft: #1a2a4a;
  --warn: #f0b46a; --warn-soft: #2a2113; --bad: #f0b46a; --bad-soft: #2a2113;
  --stage: #111a2c; --ghost: #5a6880;
  color-scheme: dark;
}

.swb { display: grid; grid-template-columns: var(--swb-rail) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 16px; height: 100%; min-height: 0;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg); color: var(--fg); font: 17px/1.5 var(--swb-font-body); box-sizing: border-box; }
.swb *, .swb *::before, .swb *::after { box-sizing: border-box; }
.swb [hidden] { display: none !important; }
.swb button, .swb input, .swb select { font: inherit; color: inherit; }
.swb :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* rail */
.swb .rail { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--swb-radius); overflow: hidden; }
.swb .rail-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.swb h1 { font: 700 1.3rem/1.15 var(--swb-font-head); letter-spacing: -0.02em; margin: 0; text-wrap: balance; }
.swb .sub { color: var(--muted); font-size: 0.92rem; margin: 0; }
.swb .rail-scroll { overflow-y: auto; min-height: 0; flex: 1; }
.swb .rail-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* quick setup */
.swb .quick { padding: 14px 16px 16px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.swb .quick h2 { font: 500 0.72rem/1 var(--swb-font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.swb .q-block { display: grid; gap: 6px; }
.swb .q-label { font-weight: 600; font-size: 0.95rem; }
.swb .q-hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
.swb .q-err { color: var(--bad); font-size: 0.85rem; margin: 4px 0 0; }
.swb .q-result { background: var(--accent-soft); border-radius: var(--swb-radius-btn); padding: 9px 11px; font-size: 0.92rem; display: grid; gap: 3px; }
.swb .q-result b { font-family: var(--swb-font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.swb .q-note { color: var(--muted); font-size: 0.85rem; }
.swb .q-html svg { width: 100%; height: auto; display: block; }
.swb .presets { display: grid; gap: 6px; }
.swb .presets button { border: 1px solid var(--line); background: var(--panel); border-radius: var(--swb-radius-btn); padding: 8px 11px; cursor: pointer; display: grid; gap: 2px; text-align: left; }
.swb .presets button:hover { border-color: var(--accent); }
.swb .presets button b { font: 600 0.92rem var(--swb-font-body); }
.swb .presets button span { font: 0.74rem var(--swb-font-mono); color: var(--muted); }
.swb .presets button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.swb .presets button[aria-pressed="true"] b, .swb .presets button[aria-pressed="true"] span { color: var(--accent-ink); }
.swb .measure { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swb .measure.one { grid-template-columns: 1fr; }
.swb .measure label { display: grid; gap: 4px; font: 500 0.78rem var(--swb-font-mono); color: var(--muted); }
.swb .measure input { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--swb-radius-btn); background: var(--panel); font: 500 0.95rem var(--swb-font-mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--fg); }
.swb .measure input:hover { border-color: var(--accent); }
.swb .measure label.changed { color: var(--accent); }
.swb .measure label.changed input { border-color: var(--accent); }
.swb .measure input.bad { border-color: var(--bad); color: var(--bad); }
.swb .quick .seg { display: flex; }
.swb .quick .seg button { flex: 1; }

/* advanced */
.swb .adv > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 0.95rem; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.swb .adv > summary::-webkit-details-marker { display: none; }
.swb .adv > summary::after { content: "+"; font: 500 1.1rem var(--swb-font-mono); color: var(--muted); }
.swb .adv[open] > summary::after { content: "–"; }
.swb .adv .count { font: 0.78rem var(--swb-font-mono); color: var(--accent); margin-left: auto; margin-right: 10px; }
.swb .params { padding: 0 16px 16px; }
.swb .group { border: 0; margin: 0; padding: 12px 0 4px; border-bottom: 1px solid var(--line); }
.swb .group:last-child { border-bottom: 0; }
.swb .group legend { font: 500 0.72rem/1 var(--swb-font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0; margin-bottom: 8px; }
.swb .field { display: grid; grid-template-columns: minmax(0, 1fr) 92px 22px; align-items: center; gap: 6px 8px; padding: 5px 0; }
.swb .field label { font: 500 0.82rem/1.2 var(--swb-font-mono); overflow-wrap: anywhere; }
.swb .field .hint { grid-column: 1 / -1; color: var(--muted); font-size: 0.82rem; line-height: 1.3; margin-top: -2px; }
.swb .field input, .swb .field select { width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--swb-radius-btn); background: var(--panel); font-family: var(--swb-font-mono); font-size: 0.85rem; font-variant-numeric: tabular-nums; text-align: right; }
.swb .field select { text-align: left; }
.swb .field input:hover, .swb .field select:hover { border-color: var(--accent); }
.swb .field.changed label { color: var(--accent); }
.swb .field.changed input, .swb .field.changed select { border-color: var(--accent); }
.swb .reset { width: 22px; height: 22px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px; visibility: hidden; font-size: 0.95rem; line-height: 1; }
.swb .field.changed .reset { visibility: visible; }
.swb .reset:hover { color: var(--accent); background: var(--accent-soft); }

/* buttons */
.swb .btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: var(--swb-radius-btn); cursor: pointer; font-weight: 600; font-size: 0.88rem; }
.swb .btn:hover { border-color: var(--accent); color: var(--accent); }
.swb .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.swb .btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.swb .btn:disabled { opacity: 0.5; cursor: progress; }
.swb .toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--muted); cursor: pointer; }
.swb .toggle input { accent-color: var(--accent); }
.swb .seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--swb-radius-btn); overflow: hidden; background: var(--panel); }
.swb .seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 0.88rem; font-weight: 500; border-right: 1px solid var(--line); }
.swb .seg button:last-child { border-right: 0; }
.swb .seg button:hover { color: var(--accent); }
.swb .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* bench */
.swb .bench { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.swb .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.swb .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.swb .stage { position: relative; flex: 1; min-height: 320px; border-radius: var(--swb-radius); overflow: hidden; background: var(--stage); border: 1px solid var(--line); }
.swb .stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.swb .overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.swb .busy { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 0.9rem; display: inline-flex; gap: 8px; align-items: center; }
.swb .spin { width: 12px; height: 12px; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: swb-spin 0.8s linear infinite; }
@keyframes swb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .swb .spin { animation-duration: 2.4s; } }
.swb .cams { position: absolute; left: 10px; bottom: 10px; }
.swb .legend { position: absolute; right: 10px; top: 10px; display: flex; gap: 10px; font: 500 0.78rem var(--swb-font-mono); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; }
.swb .legend:empty { display: none; }
.swb .legend span { display: inline-flex; align-items: center; gap: 5px; }
.swb .legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swb .status { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; font-size: 0.9rem; color: var(--muted); min-height: 1.4em; }
.swb .status b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.swb .msg { border-radius: var(--swb-radius-btn); border: 1px solid var(--line); padding: 8px 12px; font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.swb .msg.warn, .swb .msg.bad { background: var(--warn-soft); color: var(--warn); }
.swb .msgs { display: grid; gap: 6px; }

@media (max-width: 760px) {
  /* narrow: one column, the page scrolls instead of the rail (!important beats a page that sets a height on the container) */
  .swb { grid-template-columns: 1fr; grid-template-rows: auto; height: auto !important; min-height: 100%; }
  .swb .bench { order: -1; }
  .swb .stage { min-height: 0; height: 62vh; flex: none; }
  .swb .rail-scroll { overflow: visible; }
}
@media (prefers-reduced-motion: no-preference) {
  .swb .btn, .swb .seg button, .swb .presets button { transition: border-color .15s, color .15s, background .15s; }
}
