:root {
  color-scheme: light dark;
  --bg: #eef0f2;
  --panel: #ffffff;
  --panel-2: #f6f7f8;
  --line: #dde0e4;
  --field-line: #7d8590;
  --text: #1a1d21;
  --muted: #5f6975;
  --accent: #0f766e;
  --accent-soft: #d8f1ed;
  --on-accent: #ffffff;
  --danger: #b42318;
  --edge: #7a5a30;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121416;
    --panel: #1b1e21;
    --panel-2: #22262a;
    --line: #31363c;
    --field-line: #727a84;
    --text: #e7e9ec;
    --muted: #9aa4af;
    --accent: #2dd4bf;
    --accent-soft: #123c38;
    --on-accent: #06221f;
    --danger: #ff8a7a;
    --edge: #4d3817;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--sans);
}
h2 { margin: 0; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled, [aria-disabled="true"]) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button[aria-disabled="true"], button.danger[aria-disabled="true"] { color: var(--muted); border-style: dashed; background: transparent; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.empty { color: var(--muted); margin: 0; padding: 14px 16px; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 48px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  position: relative;
  z-index: 5;
}
.brand { font-weight: 700; white-space: nowrap; }
.proj { flex: 0 1 260px; min-width: 0; }
.proj input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--panel-2);
  font-weight: 600;
}
.saved { color: var(--muted); font-size: 12px; margin-right: auto; white-space: nowrap; }
.saved::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); }
.saved.failed::before { background: var(--danger); }
.bar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.more { display: none; }
.file-error { flex-basis: 100%; margin: 0; color: var(--danger); }

main {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 312px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "parts view inspector" "parts cut inspector";
  min-height: 0;
}
.parts { grid-area: parts; }
.view { grid-area: view; }
.cut { grid-area: cut; }
.inspector { grid-area: inspector; }
.parts, .inspector { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.parts { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); overflow: auto; }
.pane-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.parts-h { display: block; padding: 0 12px 10px 16px; }
.parts-h h2 { min-height: 44px; display: flex; align-items: center; }
.add-shapes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; }
.add-label { grid-column: 1 / -1; font-size: 12px; line-height: 16px; color: var(--muted); }
.add-shapes button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 0;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  background: var(--panel);
  border: 1px solid var(--field-line);
  border-radius: 6px;
}
.add-shapes .choice-icon { color: var(--accent); }
.add-shapes button:hover { background: var(--accent-soft); border-color: var(--accent); }
.add-shapes button:active { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-icon { display: inline-block; min-width: 1.2em; font-size: 18px; line-height: 1; text-align: center; }
.choice-icon.pentagon { width: 18px; min-width: 0; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.count { margin-left: 6px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); color: var(--text); letter-spacing: 0; }

.list { list-style: none; margin: 0; padding: 6px; overflow: auto; }
.row { border: 1px solid transparent; border-radius: 6px; }
.row.sel { background: var(--accent-soft); border-color: var(--accent); }
.row-main {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  grid-template-areas: "sw nm" "sw dim" ". tag" ". warn";
  column-gap: 10px;
  align-items: center;
  width: 100%;
  height: auto;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  text-align: left;
}
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--edge); }
.sil { grid-area: sw; width: 16px; height: 16px; overflow: visible; }
.sil path { stroke: var(--edge); stroke-width: 1; fill-rule: evenodd; vector-effect: non-scaling-stroke; }
.nm { grid-area: nm; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dim { grid-area: dim; font: 12px var(--mono); color: var(--muted); white-space: normal; overflow-wrap: anywhere; }
.tag { grid-area: tag; font-size: 12px; color: var(--muted); }
.lock { width: 100%; }
.lock[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.fields input:disabled, .fields select:disabled { opacity: 0.6; cursor: not-allowed; }
.warn { grid-area: warn; font-size: 12px; color: var(--danger); }
.row-acts { display: flex; gap: 6px; padding: 0 10px 8px 34px; }
.row-acts button { height: 26px; padding: 0 8px; font-size: 12px; }

.view { position: relative; overflow: hidden; min-width: 0; min-height: 260px; }
.viewport { position: absolute; inset: 0; }
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewport canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.view-tools {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
}
.move-tools { position: absolute; top: 50px; left: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
.tool-group { display: flex; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); overflow: hidden; pointer-events: auto; }
.tool-group button { height: 28px; padding: 0 10px; font-size: 12px; border: 0; border-right: 1px solid var(--line); border-radius: 0; }
.tool-group button:last-child { border-right: 0; }
.tool-group [aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.view-tools button { height: 28px; padding: 0 10px; font-size: 12px; border: 0; border-right: 1px solid var(--line); border-radius: 0; }
.view-tools button:last-child { border-right: 0; }
.view-tools [aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.view-tools button:focus-visible, .tool-group button:focus-visible { outline-offset: -2px; }
.view-sel {
  position: absolute;
  top: 12px;
  right: 12px;
  max-width: calc(100% - 280px);
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--accent);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.view-sel b { font-weight: 600; }
.debug {
  position: absolute;
  right: 12px;
  bottom: 34px;
  max-width: min(340px, calc(100% - 24px));
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  font: 11px/1.5 var(--mono);
  white-space: pre-wrap;
  pointer-events: none;
}
.debug .bad { color: var(--danger); }
.debug .summary { display: none; }
#potato-toggle[aria-pressed="true"],
#debug-toggle[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.view-hint { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--muted); pointer-events: none; }

.cut { background: var(--panel); border-top: 1px solid var(--line); max-height: 42vh; overflow: auto; }
.overall { font-size: 12px; color: var(--muted); text-align: right; }
.table-wrap { overflow-x: auto; padding: 4px 16px 0; }
.cut-list { width: 100%; border-collapse: collapse; font-size: 13px; }
.cut-list th, .cut-list td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: baseline; }
.cut-list th { font-size: 12px; color: var(--muted); font-weight: 600; }
.cut-list td:nth-child(1) { font: 600 13px var(--mono); white-space: nowrap; }
.cut-list td:nth-child(2), .cut-list td:nth-child(5), .cut-list td:nth-child(6) { font: 13px var(--mono); white-space: nowrap; }
.cut-list td:nth-child(3), .cut-list td:nth-child(4) { color: var(--muted); }
.cut-list .num { text-align: right; }
.hardware-list td:nth-child(2) { font: 13px var(--sans); white-space: normal; }
.hardware-list td:nth-child(3) { font: 13px var(--mono); color: var(--text); white-space: nowrap; }
.shape-note { display: block; font: 12px var(--sans); color: var(--muted); white-space: normal; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 0; padding: 10px 16px 14px; font-size: 13px; }
.totals b { font: 600 14px var(--mono); }

.fields { padding: 14px 16px 16px; display: grid; gap: 14px; }
.fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.fields fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.fields legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.fields input, .fields select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}
.fields input.num { font-family: var(--mono); }
.fields input[aria-invalid="true"] { border-color: var(--danger); outline-color: var(--danger); }
.field-error { margin: 4px 0 0; font-size: 12px; color: var(--danger); }
/* Stays rendered while empty, so its aria-live region is in place before a message arrives. */
.field-error:empty { margin: 0; }
.help { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.cut-from { margin: 8px 0 0; font: 12px var(--mono); color: var(--muted); }
.choices { display: grid; grid-auto-columns: minmax(min-content, 1fr); grid-auto-flow: column; border: 1px solid var(--field-line); border-radius: 6px; background: var(--panel); }
.fields label.choice {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-height: 34px;
  padding: 6px 2px;
  border-right: 1px solid var(--line);
  color: var(--text);
  text-align: center;
  cursor: pointer;
}
.choice:first-child { border-radius: 5px 0 0 5px; }
.choice:last-child { border-right: 0; border-radius: 0 5px 5px 0; }
.fields .choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.choice:has(input:checked) { background: var(--accent-soft); font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.choice:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.fields .choice input:disabled { cursor: not-allowed; }
.corners-box { display: grid; gap: 10px; }
.corner-pick { position: relative; height: 112px; max-width: 344px; }
.corner-shape { position: absolute; top: 12px; left: 12px; width: calc(100% - 24px); height: calc(100% - 24px); overflow: visible; }
.corner-shape path { fill: var(--panel-2); stroke: var(--field-line); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.fields label.corner { position: absolute; display: flex; align-items: center; gap: 4px; padding: 3px; color: var(--text); cursor: pointer; }
.corner span { padding: 0 4px; border-radius: 4px; background: var(--panel-2); }
.corner.tl { top: 25px; left: 25px; }
.corner.tr { top: 25px; right: 25px; flex-direction: row-reverse; }
.corner.bl { bottom: 25px; left: 25px; }
.corner.br { bottom: 25px; right: 25px; flex-direction: row-reverse; }
.fields .corner input { flex: none; width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wood { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; }
.wood .sw { width: auto; height: 34px; border-radius: 6px; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.joints { display: grid; gap: 6px; margin-bottom: 8px; }
.joint { border: 1px solid var(--line); border-radius: 6px; }
.joint[open] { border-color: var(--field-line); }
.joint summary { display: grid; gap: 1px; padding: 7px 10px; cursor: pointer; }
.joint .jn { font-weight: 600; color: var(--text); }
.joint summary > * { grid-area: auto; }
.joint .dim { font: 12px var(--mono); color: var(--muted); }
.swing .duo { grid-column: 1 / -1; }
.joint-body { display: grid; gap: 10px; padding: 4px 10px 10px; }
.joint .warn, .joint .help, .joints-box .warn { margin: 0; }
.joint-body fieldset legend { margin-bottom: 4px; }
.fields label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.fields label.check input { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }
.swing { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 6px 8px; align-items: center; }
.swing > label { grid-column: 1 / -1; }
.fields input[type="range"] { height: auto; padding: 0; border: 0; background: none; accent-color: var(--accent); }
.joint-add { display: grid; gap: 8px; margin-top: 8px; }
#hardware-empty { padding: 0 16px 14px; }
.free-box { display: grid; gap: 8px; margin-bottom: 10px; }
.free-pick { height: 112px; max-width: 344px; padding: 12px; }
.free-preview { display: block; width: 100%; height: 100%; overflow: visible; }
.free-preview path { stroke: var(--field-line); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.edit-outline { width: 100%; }

.outline-dialog {
  width: min(960px, 100vw - 48px);
  height: min(720px, 100vh - 48px);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  overflow: hidden;
}
.outline-dialog[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 296px;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "head head" "draw side" "tools side" "foot foot";
}
.outline-dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.outline-head { grid-area: head; }
.outline-draw { grid-area: draw; position: relative; min-height: 0; background: var(--panel-2); }
.outline-svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }
.outline-svg:focus { outline: none; }
.outline-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.outline-svg .grid-major, .outline-svg .grid-minor { fill: none; stroke: var(--line); stroke-width: 1; }
.outline-svg .grid-minor { opacity: 0.5; }
.outline-svg .blank { fill: none; stroke: var(--field-line); stroke-width: 1; stroke-dasharray: 4 3; }
.outline-svg text { font: 11px var(--mono); fill: var(--muted); }
.outline-svg .shape { stroke: var(--edge); stroke-width: 1.5; stroke-linejoin: round; }
.outline-svg .shape.bad { stroke: var(--danger); fill-opacity: 0.4; }
.outline-svg .edge-bad { fill: none; stroke: var(--danger); stroke-width: 3; }
.outline-svg .pt { fill: var(--panel); stroke: var(--accent); stroke-width: 2; }
.outline-svg .pt.sel { fill: var(--accent); }
.outline-svg .bend-handle { fill: var(--panel); stroke: var(--field-line); stroke-width: 1.5; }
.outline-svg .bend-handle.on { stroke: var(--accent); }
.outline-svg .stroke { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.outline-chip { position: absolute; top: 10px; left: 10px; padding: 5px 10px; border-radius: 6px; background: var(--panel); border: 1px solid var(--accent); font: 12px var(--mono); pointer-events: none; }
.outline-draw-help { position: absolute; left: 12px; right: 12px; bottom: 8px; margin: 0; pointer-events: none; }
.outline-tools { grid-area: tools; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.outline-tools .field-error { flex-basis: 100%; margin: 0; }
.outline-tools .field-error.status { color: var(--muted); }
.outline-side { grid-area: side; min-height: 0; overflow: auto; align-content: start; gap: 6px; border-left: 1px solid var(--line); }
.points-head, .points li { display: grid; grid-template-columns: 24px repeat(3, minmax(0, 1fr)); gap: 6px; align-items: center; }
.points-head { position: sticky; top: -14px; z-index: 1; margin-top: -14px; padding: 14px 5px 4px; background: var(--panel); font-size: 11px; line-height: 1.2; color: var(--muted); align-items: end; }
.points { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.points li { padding: 3px 4px; border: 1px solid transparent; border-radius: 6px; }
.points li.sel { background: var(--accent-soft); border-color: var(--accent); }
.points input { padding: 0 6px; appearance: textfield; }
.points input::-webkit-inner-spin-button, .points input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.points .pt-n { font: 12px var(--mono); color: var(--muted); text-align: center; }
.points .field-error { grid-column: 2 / -1; margin: 0; }
.outline-foot { grid-area: foot; padding: 10px 16px; border-top: 1px solid var(--line); }
.outline-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.outline-discard p { margin: 0 auto 0 0; }

.tabs, .add-bar { display: none; }

@media (max-width: 720px) {
  :root { --view-h: min(300px, 40vh); --tabs-h: 46px; --add-bar-h: 88px; --status-h: 0px; --bottom-clear: calc(var(--add-bar-h) + var(--status-h) + 16px); }
  :root:has(#save-state.failed) { --status-h: 34px; }
  html { scroll-padding-top: calc(var(--view-h) + var(--tabs-h)); scroll-padding-bottom: var(--bottom-clear); }
  body { display: block; height: auto; padding-bottom: var(--bottom-clear); }
  .bar { min-height: 52px; }
  .brand { display: none; }
  .saved { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .saved.failed {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--add-bar-h);
    display: flex;
    align-items: center;
    width: auto;
    height: auto;
    min-height: var(--status-h);
    margin: 0;
    padding: 6px 16px;
    overflow: visible;
    clip-path: none;
    border-top: 1px solid var(--line);
    background: var(--panel);
    color: var(--danger);
    font-size: 13px;
    white-space: normal;
  }
  .saved.failed::before { flex: none; }
  .proj { flex: 1; }
  .proj input { height: 40px; font-size: 16px; }
  .more { display: block; width: 44px; height: 40px; padding: 0; font-size: 20px; flex: none; }
  .bar-actions {
    display: none;
    position: absolute;
    top: 100%;
    right: 16px;
    left: 16px;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  }
  .bar.menu-open .bar-actions { display: grid; }
  .bar-actions button { height: 44px; }
  .file-error { position: absolute; top: 100%; left: 16px; right: 16px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--danger); border-radius: 8px; }

  main { display: flex; flex-direction: column; }
  .view { order: 1; height: var(--view-h); min-height: 0; position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); }
  .view-tools { top: 10px; left: 10px; }
  .move-tools { top: 46px; left: 10px; right: 10px; gap: 6px; }
  .view-hint { display: none; }
  .debug { top: auto; bottom: 10px; right: 10px; max-width: calc(100% - 170px); padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .debug .summary { display: block; }
  .debug .detail { display: none; }
  .view-sel { top: auto; bottom: 10px; left: 10px; right: auto; max-width: calc(100% - 20px); }
  .tabs { order: 2; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: var(--view-h); z-index: 2; }
  .tabs button { height: var(--tabs-h); border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; font-weight: 600; color: var(--muted); }
  .tabs [aria-pressed="true"] { color: var(--text); border-bottom-color: var(--accent); }
  .parts, .inspector, .cut { order: 3; border: 0; display: none; max-height: none; overflow: visible; }
  main[data-tab="parts"] .parts, main[data-tab="edit"] .inspector { display: flex; flex-direction: column; }
  main[data-tab="cut"] .cut { display: block; }
  .parts .pane-h { display: none; }
  .list { padding: 8px 16px; overflow: visible; }
  .row-main { min-height: 52px; padding: 9px 10px; }
  .row-acts button { height: 36px; padding: 0 12px; font-size: 14px; }
  .fields input, .fields select { height: 40px; font-size: 16px; }
  .add-bar { display: block; position: fixed; left: 0; right: 0; bottom: 0; height: var(--add-bar-h); padding: 6px 16px 10px; background: var(--panel); border-top: 1px solid var(--line); z-index: 3; }
  .add-bar .add-shapes { gap: 6px; }
  .add-bar .add-shapes button { min-height: 48px; font-size: 12px; }
  .fields label.choice { min-height: 44px; }
  .edit-outline { height: 44px; }
  .outline-dialog { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; overflow: auto; overscroll-behavior: contain; scroll-padding-bottom: 6rem; }
  .outline-dialog[open] { display: flex; flex-direction: column; }
  .outline-draw { flex: none; height: min(100vw, 45dvh); }
  .outline-tools { padding: 8px 16px; }
  .outline-tools .tool-group button { height: 36px; padding: 0 8px; }
  .outline-side { flex: 1 1 auto; min-height: 10rem; border-left: 0; border-top: 1px solid var(--line); }
  .outline-foot { flex: none; position: sticky; bottom: 0; z-index: 2; background: var(--panel); }
  .outline-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .outline-actions button { height: 44px; }
  .outline-discard p { grid-column: 1 / -1; margin: 0; }
}

@media (max-width: 360px) {
  .add-bar .add-shapes { gap: 4px; }
  .add-bar .add-shapes button { font-size: 11px; }
}

@media (max-width: 520px) {
  .cut-list, .cut-list tbody { display: block; }
  .cut-list thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .cut-list tr { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .cut-list td { display: block; padding: 0; border: 0; text-align: left; }
  .cut-list .num { text-align: left; }
  .cut-list td:nth-child(1) { grid-row: 1 / span 4; }
  .cut-list td:nth-child(2) { grid-column: 2 / -1; white-space: normal; }
  .cut-list td:nth-child(3), .cut-list td:nth-child(4) { grid-column: 2 / -1; color: var(--text); }
  .cut-list td:nth-child(n+3)::before { content: attr(data-label) ": "; content: attr(data-label) ": " / ""; font: 12px var(--sans); color: var(--muted); }
  .cut-list td:nth-child(n+5)::before { content: attr(data-label); content: attr(data-label) / ""; display: block; }
  .cut-list td:nth-child(5) { grid-column: 2; }
  .cut-list td:nth-child(6) { grid-column: 3; }
  .hardware-list tr { grid-template-columns: auto minmax(0, 1fr) auto; }
  .hardware-list td:nth-child(1) { grid-row: 1 / span 2; }
  .hardware-list td:nth-child(2) { grid-column: 2; }
  .hardware-list td:nth-child(3) { grid-column: 3; }
  .hardware-list td:nth-child(3)::before { content: none; }
  .hardware-list td:nth-child(4) { grid-column: 2 / -1; color: var(--muted); }
}

@media (max-width: 720px) and (max-height: 500px) {
  html { scroll-padding-top: 0; }
  .view { position: relative; height: min(300px, 70vh); }
  .tabs { position: static; }
}
.fields > .field-error { margin-top: -10px; }
.fields > .field-error:empty { margin-top: -14px; }
.parts-note:not(:empty) { padding: 4px 16px 10px; }
