/* Pattern Maker — flat, workshop-neutral UI. */

@font-face { font-family: "DM Sans"; src: url(vendor/fonts/dm-sans-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url(vendor/fonts/dm-sans-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url(vendor/fonts/dm-sans-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url(vendor/fonts/dm-sans-700.woff2) format("woff2"); font-weight: 700 800; font-display: swap; }
@font-face { font-family: "DM Mono"; src: url(vendor/fonts/dm-mono-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "DM Mono"; src: url(vendor/fonts/dm-mono-500.woff2) format("woff2"); font-weight: 500 800; font-display: swap; }

/* Palette: #cad2c5 sage · #84a98c moss · #52796f teal · #354f52 slate · #2f3e46 ink
   plus paper/white for surfaces and an error red. Contrast notes in mockups/round-2.html. */
:root {
  --sage: #cad2c5;
  --moss: #84a98c;
  --teal: #52796f;
  --slate: #354f52;
  --bg: #cad2c5;          /* app background */
  --panel: #f3f5f1;       /* panels, dialogs, menus (paper) */
  --ink: #2f3e46;         /* main text, header, outlines */
  --ink-2: #354f52;       /* secondary text (8:1) */
  --ink-3: #4d6b63;       /* hints (5.3:1) */
  --line: #dde3d9;        /* decorative dividers */
  --line-2: #52796f;      /* control borders (4.4:1, ≥3:1 for UI parts) */
  --accent: #52796f;      /* toggled-on, focus, selection */
  --accent-soft: #e4ece6;
  --primary: #354f52;
  --primary-hover: #2f3e46;
  --ok: #52796f;
  --ok-soft: #dfe9e0;
  --err: #b3261e;
  --err-soft: #fbe9e6;
  --radius: 8px;
  --gap: 12px;
  --tap: 40px;            /* minimum touch target */
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.4 var(--font);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
svg { display: block; }

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--ink);
  color: var(--sage);
}
.app-title { font-size: 16px; margin: 0; letter-spacing: 0.02em; font-weight: 650; }
.header-actions { display: flex; gap: 6px; }
.app-header .btn { background: transparent; border-color: var(--slate); color: #fff; }
.app-header .btn:not(:disabled):hover { background: var(--slate); }
.app-header .btn:not(:disabled):active { background: var(--teal); }

/* ---------- buttons & inputs ---------- */
.btn {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:not(:disabled):active { background: var(--line); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:not(:disabled):hover { background: var(--primary-hover); }
.btn:not(:disabled):hover { border-color: var(--ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:focus-visible, .chip-btn:focus-visible, .tpl-tile:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn.danger { color: var(--err); }
.btn.is-on { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.small { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (pointer: coarse) {
  .btn { min-height: var(--tap); }
  .icon-btn { width: var(--tap); height: var(--tap); }
}

input[type="number"], input[type="text"], input[type="search"], select {
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: #fff;
  min-width: 0;
}
input[type="number"] { width: 5.5em; }
label.field { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.muted { color: var(--ink-2); }
.hint { color: var(--ink-3); font-size: 12px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); margin: 0 0 4px; font-weight: 600; }

/* ---------- tabs & panels ---------- */
.tabs { display: none; }
.panels {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(350px, 1.1fr) minmax(432px, 1fr) minmax(330px, 1fr);
  gap: var(--gap);
  padding: var(--gap);
}
.panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 14px; margin: 0; font-weight: 650; }
.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; }

@media (max-width: 1099px) {
  .tabs {
    display: flex;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .tabs button {
    flex: 1;
    min-height: 44px;
    border: 0;
    background: none;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    color: var(--ink-2);
    cursor: pointer;
  }
  .tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
  .panels { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .panel { border: 0; border-radius: 0; display: none; }
  .panel.is-active { display: flex; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: min(92vw, 520px);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--err); }

/* ---------- dialogs ---------- */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(47, 62, 70, 0.5);
  display: grid; place-items: center;
  z-index: 40;
  padding: 16px;
}
.dialog {
  background: var(--panel);
  border-radius: 10px;
  padding: 18px;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.dialog h3 { margin: 0 0 8px; font-size: 16px; }
.dialog p { margin: 0 0 12px; color: var(--ink-2); }
.dialog .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- popover menu ---------- */
.menu {
  position: fixed;
  z-index: 45;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 4px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
}
.menu button {
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 5px;
  min-height: 36px;
  cursor: pointer;
}
.menu button:active, .menu button:focus-visible { background: var(--line); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-backdrop { position: fixed; inset: 0; z-index: 44; }

/* ---------- segmented buttons, toolbars ---------- */
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; margin-left: -1px; }
.seg .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg .btn:last-child { border-radius: 0 6px 6px 0; }
.toolbar, .blockbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.blockbar .name-input { flex: 1 1 80px; min-width: 80px; max-width: 220px; }
.blockbar .size-input { width: 4.8em; }
.blockbar.is-imperial .size-input { width: 6.4em; }
.letter-badge {
  min-width: 34px; height: 34px; padding: 0 6px;
  display: inline-grid; place-items: center;
  background: var(--ink); color: #fff; border-radius: 6px; font-weight: 700;
}

/* ---------- editor ---------- */
.editor-body { display: flex; flex-direction: column; gap: 10px; }
.editor-canvas {
  position: relative;
  flex: 1 0 320px;
  min-height: 320px;
  background:
    linear-gradient(45deg, #e7ece4 25%, transparent 25%, transparent 75%, #e7ece4 75%) 0 0 / 16px 16px,
    linear-gradient(45deg, #e7ece4 25%, transparent 25%, transparent 75%, #e7ece4 75%) 8px 8px / 16px 16px,
    #f3f5f1;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.editor-svg { width: 100%; height: 100%; position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.editor-svg .region { stroke: none; cursor: pointer; }
.editor-svg .region.is-selected { stroke: var(--accent); stroke-width: 3px; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; }
.editor-svg .block-outline { fill: none; stroke: var(--ink); stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; }
.editor-svg .seg { stroke: var(--ink); stroke-width: 2px; vector-effect: non-scaling-stroke; stroke-linecap: round; pointer-events: none; }
.editor-svg .seg.is-selected { stroke: var(--accent); stroke-width: 4px; }
.editor-svg .seg-hit { stroke: transparent; cursor: move; stroke-linecap: round; }
.editor-svg .node { fill: #fff; stroke: var(--ink); stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; }
.editor-svg .node-edge { fill: var(--ink); }
.editor-svg .node-segment, .editor-svg .node-intersection { fill: #52796f; stroke: #fff; }
.editor-svg .node.is-selected { fill: var(--accent); stroke: #fff; }
.editor-svg .node.is-error { fill: var(--err); }
.editor-svg .node-hit { fill: transparent; cursor: grab; }
.editor-svg .handle { fill: #fff; stroke: var(--ink); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.editor-svg .h-ew { cursor: ew-resize; } .editor-svg .h-ns { cursor: ns-resize; } .editor-svg .h-nwse { cursor: nwse-resize; }
.editor-svg .frac-grid line { stroke: rgba(47, 62, 70, 0.28); stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-dasharray: 3 3; pointer-events: none; }
.editor-svg.tool-draw { cursor: crosshair; }
.editor-svg .draw-start { fill: var(--accent); }
.editor-svg .draw-preview { stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; pointer-events: none; }
.editor-svg .snap-dot { fill: none; stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; }
.editor-svg .snap-free { fill: var(--accent); stroke: none; }
.editor-svg .snap-node, .editor-svg .snap-intersection { stroke: #52796f; }
.editor-hint { min-height: 1.4em; }

.inspector { display: flex; flex-direction: column; gap: 12px; }
.insp-section { display: flex; flex-direction: column; gap: 6px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 4px; }
.swatch {
  display: flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  cursor: pointer; text-align: left; font-size: 12.5px;
}
.swatch.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.swatch .chip { width: 18px; height: 18px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.swatch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- block library ---------- */
.library { display: flex; gap: 6px; overflow-x: auto; padding: 3px 3px 6px; margin: -3px -3px 0; scrollbar-width: thin; }
.lib-card { position: relative; flex: none; display: flex; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.lib-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.lib-select {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px 4px 8px; border: 0; background: none; cursor: pointer; min-width: 64px;
}
.lib-letter { font-weight: 700; font-size: 13px; }
.lib-name { font-size: 11px; color: var(--ink-2); max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-more { border: 0; background: none; cursor: pointer; padding: 0 8px; font-size: 18px; color: var(--ink-2); border-left: 1px solid var(--line); min-width: 32px; }
.lib-new {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 64px; border: 1px dashed var(--line-2); border-radius: 8px; background: none; cursor: pointer; color: var(--ink-2);
}
.lib-new span:first-child { font-size: 22px; line-height: 1; }
.block-thumb .thumb-line { stroke: rgba(47, 62, 70, 0.55); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.block-thumb .thumb-outline { fill: none; stroke: var(--ink); stroke-width: 1px; vector-effect: non-scaling-stroke; }

/* ---------- grid ---------- */
.grid-body { display: flex; flex-direction: column; gap: 8px; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 36px; padding: 3px 9px 3px 4px;
  border: 1px solid var(--line-2); border-radius: 18px; background: #fff;
  cursor: pointer; font-weight: 650;
}
.chip-btn.erase { padding-left: 10px; font-weight: 500; color: var(--ink-2); }
.chip-btn.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip-btn .block-thumb { border-radius: 3px; }
.grid-message { display: none; padding: 8px 10px; border-radius: 6px; background: var(--err-soft); color: var(--err); font-size: 13px; }
.grid-message.show { display: block; }
.grid-wrap { overflow: auto; flex: 1; min-height: 120px; }
.grid-table { display: grid; width: max-content; margin: 0 auto; gap: 2px; grid-auto-rows: minmax(40px, 48px); align-items: stretch; }
.gh {
  display: grid; place-items: center;
  border: 0; border-radius: 4px; background: var(--bg);
  color: var(--ink-2); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0;
}
.gh.corner { background: none; cursor: default; }
.gh:active { background: var(--line); }
.cell {
  position: relative; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
  cursor: pointer; outline: none; overflow: hidden;
}
.cell .block-thumb { position: absolute; inset: 3px; width: calc(100% - 6px); height: calc(100% - 6px); opacity: 0.85; }
.cell-letter {
  position: relative; font-weight: 700; font-size: 13px;
  background: rgba(255, 255, 255, 0.85); border-radius: 3px; padding: 0 3px; line-height: 1.3;
}
.cell-letter:empty { display: none; }
.cell.is-cursor { box-shadow: 0 0 0 2px var(--accent); z-index: 1; }
.cell:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.cell.has-error { border-color: var(--err); background: var(--err-soft); }
.cell.has-error .block-thumb { opacity: 0.35; }
.cell-err {
  position: absolute; top: 1px; right: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--err); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.cell.fits { background: var(--ok-soft); border-color: var(--moss); }
.cell.no-fit { background: #eef1ec; opacity: 0.6; }
.cell.conflict { box-shadow: 0 0 0 2px var(--err); animation: pulse 1s ease-in-out 3; }
.cell.flash { animation: shake 0.3s; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(179, 38, 30, 0.35); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------- preview ---------- */
.preview-tools { padding: 8px 12px 0; }
.preview-stage { position: relative; flex: 1; min-height: 300px; margin: 8px 12px 12px; border: 1px solid var(--line); border-radius: 6px; background: #e9eee6; overflow: hidden; }
.p2d, .p3d { position: absolute; inset: 0; }
.p2d[hidden], .p3d[hidden] { display: none; }
.preview-svg { width: 100%; height: 100%; touch-action: none; cursor: grab; }
.preview-svg:active { cursor: grabbing; }
.preview-svg path.glue { stroke: none; }
.preview-svg.show-glue path.glue { stroke: rgba(47, 62, 70, 0.45); stroke-width: 0.75px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.preview-svg .cell-outline { fill: none; stroke: none; }
.preview-svg.show-blocks .cell-outline { stroke: rgba(47, 62, 70, 0.9); stroke-width: 1.25px; vector-effect: non-scaling-stroke; }
.preview-svg .cell-error { fill: var(--err-soft); stroke: var(--err); stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }
.preview-svg .board-outline { fill: none; stroke: var(--ink); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.p3d-canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.p3d-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); }
.preview-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; pointer-events: none; }
.preview-empty[hidden] { display: none; }
#panel-preview .panel-head .seg .btn { min-width: 44px; }

@media (max-width: 1099px) {
  .editor-canvas { flex-basis: 55vh; }
  .preview-stage { min-height: 60vh; }
}

.editor-body > * { flex: none; }
.editor-body > .editor-canvas { flex: 1 0 300px; }
.grid-body > * { flex: none; }
.grid-body > .grid-wrap { flex: 1 1 auto; }
[hidden] { display: none !important; }

/* ===================== Round 2 ===================== */

/* data font: block letters, grid numbers, sizes */
.letter-badge, .lib-letter, .cell-letter, .gh, .data, input[type="number"], .chip-btn .data { font-family: var(--mono); font-weight: 500; }
.app-title { font-weight: 700; letter-spacing: 0.01em; }
.panel-head h2 { font-weight: 700; }
.letter-badge { background: var(--ink); }
.lib-card.is-active { border-color: var(--slate); box-shadow: 0 0 0 2px var(--slate); }
.cell.is-cursor { box-shadow: 0 0 0 2px var(--teal); }
.swatch.is-on { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }

/* + / − steppers */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; background: #fff; }
.stepper button { width: 32px; border: 0; background: #fff; color: var(--ink); font-size: 17px; cursor: pointer; touch-action: manipulation; }
.stepper button:hover { background: var(--accent-soft); }
.stepper button:active { background: var(--sage); }
.stepper input[type="number"] { border: 0; border-left: 1px solid var(--line-2); border-right: 1px solid var(--line-2); border-radius: 0; width: 3.4em; text-align: center; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
@media (pointer: coarse) { .stepper button { width: 40px; } }

/* palette chips: less rounded, room around the miniature */
.chip-btn {
  border-radius: 6px; padding: 6px 10px 6px 6px; min-height: 40px; gap: 7px;
  border: 1px solid var(--line-2); color: var(--ink);
}
.chip-btn.erase, .chip-btn.text { padding-left: 10px; font-weight: 500; color: var(--ink-2); }
.chip-btn.is-on { background: #fff; color: var(--ink); border-color: var(--slate); box-shadow: 0 0 0 2px var(--slate); }
.chip-btn.erase.is-on { background: var(--slate); color: #fff; }
.chip-btn .block-thumb { border-radius: 2px; }

/* modal dialogs (openModal) */
.dialog { padding: 0; overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 32px); background: var(--panel); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 16px; }
.dialog-x { border: 0; background: none; font-size: 16px; color: var(--ink-2); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; }
.dialog-x:hover { background: var(--accent-soft); }
.dialog-body { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.dialog .actions { margin: 0; padding: 12px 16px; border-top: 1px solid var(--line); }
.dialog:not(:has(.dialog-head)) { padding: 18px; }
.dialog-copy, .dialog-replace { width: min(480px, 100%); }
.dialog-templates { width: min(760px, 100%); }
.dialog-error { background: var(--err-soft); color: var(--err); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.dialog-error:empty, .dialog-error[hidden] { display: none; }
.field-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lbl { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.tight { margin: 0; }
label.field.checkbox { color: var(--ink); }
@media (max-width: 560px) {
  .dialog-backdrop { padding: 0; place-items: stretch; }
  .dialog { width: 100%; max-height: 100vh; border-radius: 0; }
  .dialog-copy .dialog-body, .dialog-replace .dialog-body, .dialog-templates .dialog-body { flex: 1; }
}

/* equal-width segmented buttons */
.eqseg { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; flex: 1; min-width: 0; }
.eqseg button { border: 0; border-left: 1px solid var(--line-2); background: #fff; padding: 7px 6px; text-align: center; cursor: pointer; font-size: 13px; color: var(--ink); white-space: nowrap; }
.eqseg button:first-child { border-left: 0; }
.eqseg button.on { background: var(--teal); color: #fff; }
.eqseg button:not(.on):hover { background: var(--accent-soft); }

/* quick-select chips + checkbox list */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip.sq { border: 1px solid var(--line-2); border-radius: 5px; background: #fff; padding: 3px 9px; font-size: 12.5px; cursor: pointer; color: var(--ink); min-height: 28px; }
.chip.sq:hover { background: var(--accent-soft); }
.every-n-wrap { display: inline-flex; gap: 3px; align-items: center; }
.every-n-wrap input.every-n { width: 3.6em; min-height: 28px; padding: 2px 4px; }
.cblist { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 8px; margin-top: 6px; }
.cblist .cb { display: flex; align-items: center; gap: 6px; font-size: 13px; min-height: 28px; cursor: pointer; white-space: nowrap; }
.cblist .cb input { width: 17px; height: 17px; accent-color: var(--teal); margin: 0; }
.cblist .cb.src { color: var(--ink-2); cursor: default; }
.cblist .cb.src .box { width: 17px; height: 17px; border: 1.5px dashed var(--ink-2); border-radius: 4px; display: inline-grid; place-items: center; font-size: 9px; background: var(--accent-soft); }
.target-picker { display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 420px) { .cblist { grid-template-columns: repeat(3, 1fr); } }

/* toast with an action */
.toast { display: flex; align-items: center; gap: 14px; }
.toast.has-action { pointer-events: auto; }
.toast-action { border: 0; background: none; color: var(--sage); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 4px 2px; }

/* template picker */
.tpl-groups { display: flex; flex-direction: column; gap: 12px; }
.tpl-group h4 { margin: 0 0 6px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.tpl-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 4px 6px;
  cursor: pointer; font-size: 11.5px; line-height: 1.2; color: var(--ink); text-align: center;
}
.tpl-tile:hover { border-color: var(--teal); background: var(--accent-soft); }
.tpl-mini .tpl-box { fill: #fff; stroke: var(--ink); stroke-width: 1.8px; vector-effect: non-scaling-stroke; }
.tpl-mini .tpl-line { stroke: var(--ink); stroke-width: 1.8px; vector-effect: non-scaling-stroke; stroke-linecap: square; }

/* editor selection: white halo + ink line, readable on any wood */
.editor-svg .region.is-selected { stroke: none; }
.editor-svg .sel-halo { fill: none; stroke: #fff; stroke-width: 6px; vector-effect: non-scaling-stroke; pointer-events: none; stroke-linejoin: round; }
.editor-svg .sel-line { fill: none; stroke: var(--ink); stroke-width: 2.5px; vector-effect: non-scaling-stroke; stroke-dasharray: 7 4; pointer-events: none; stroke-linejoin: round; }
.editor-svg .seg-halo { stroke: #fff; stroke-width: 8px; vector-effect: non-scaling-stroke; stroke-linecap: round; pointer-events: none; }
.editor-svg .seg.is-selected { stroke: var(--ink); stroke-width: 3.5px; }
.editor-svg .node.is-selected { fill: var(--ink); stroke: #fff; stroke-width: 2.5px; }
.editor-svg .draw-start { fill: var(--ink); }
.editor-svg .draw-preview, .editor-svg .snap-dot { stroke: var(--ink); }
.editor-svg .snap-free { fill: var(--ink); }

/* preview placeholders */
.preview-svg .cell-empty { fill: rgba(255, 255, 255, 0.55); stroke: rgba(82, 121, 111, 0.55); stroke-width: 0.8px; vector-effect: non-scaling-stroke; }
.preview-svg .cell-empty.guessed { stroke-dasharray: 4 3; }
.preview-empty { place-items: end center; padding-bottom: 14px; }

/* conflict highlight (grid) */
.cell.conflict { box-shadow: 0 0 0 2px var(--err); }
.grid-message { background: var(--err-soft); color: var(--err); }

/* TEMPORARY board capture tool */
.temp-btn { border-style: dashed; }
.dialog-capture { width: min(560px, 100%); }
.capture { display: flex; flex-direction: column; gap: 8px; }
.capture-name { flex: 1; min-width: 160px; }
.capture-list { margin: 0; padding-left: 22px; max-height: 180px; overflow: auto; }
.capture-list li { display: flex; align-items: center; gap: 6px; min-height: 32px; }
.capture-list li::marker { color: var(--ink-2); }
.capture-list .capture-title { font-weight: 600; }
.capture-list .btn { margin-left: auto; }
.capture-out { width: 100%; font-family: var(--mono); font-size: 11.5px; border: 1px solid var(--line-2); border-radius: 6px; padding: 6px; background: #fff; resize: vertical; }

/* board gallery */
.dialog-gallery { width: min(900px, 100%); }
.gallery { display: flex; flex-direction: column; gap: 14px; }
.gallery-group h4 { margin: 0 0 8px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.gallery-tile {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; text-align: left;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 10px; cursor: pointer; color: var(--ink);
}
.gallery-tile:hover { border-color: var(--teal); background: var(--accent-soft); }
.gallery-tile:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.gallery-art { height: 172px; display: grid; place-items: center; background: #e9eee6; border-radius: 5px; margin-bottom: 4px; }
.board-thumb path.glue { stroke: rgba(47, 62, 70, 0.35); stroke-width: 0.5px; vector-effect: non-scaling-stroke; }
.board-thumb-outline { fill: none; stroke: var(--ink); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.gallery-name { font-weight: 600; }
.gallery-meta { font-size: 12px; color: var(--ink-2); }
@media (max-width: 560px) { .gallery-grid { grid-template-columns: repeat(2, 1fr); } .gallery-art { height: 130px; } .gallery-art svg { max-width: 100%; height: auto; } }

/* grid panel header: sizes + reset on one line, gallery / capture below */
.grid-head { flex-direction: column; align-items: stretch; gap: 8px; }
.gh-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-head .stepper button { width: 28px; }
.grid-head .stepper input[type="number"] { width: 2.8em; }
@media (pointer: coarse) { .grid-head .stepper button { width: 36px; } }
.grid-head .gh-row { gap: 6px; }
.grid-head .gh-row > label.field { gap: 4px; }
.grid-head .stepper input[type="number"] { width: 2.5em; padding-left: 2px; padding-right: 2px; }

/* ===================== One control height =====================
   Every button, dropdown, number box and stepper in panels and dialogs is 32 px
   (40 px on touch screens). Exceptions on purpose: the top-bar undo/redo (36 px),
   block chips and library cards (they hold miniatures), small chips in dialogs. */
:root { --ctl: 32px; --ctl-fs: 13.5px; }
@media (pointer: coarse) { :root { --ctl: 40px; } }

.panel-head h2 { font-size: 20px; line-height: 1.2; }
.dialog-head h3 { font-size: 17px; }

.btn, .btn.small {
  min-height: var(--ctl); height: var(--ctl); padding: 0 12px; font-size: var(--ctl-fs);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.icon-btn, .panel .icon-btn { width: var(--ctl); height: var(--ctl); min-height: var(--ctl); padding: 0; }
.panel .icon-btn svg { width: 18px; height: 18px; }
.app-header .icon-btn { width: 36px; height: 36px; }
select, input[type="number"], input[type="text"], input[type="search"] {
  min-height: var(--ctl); height: var(--ctl); padding-top: 0; padding-bottom: 0; font-size: var(--ctl-fs);
}
.letter-badge { height: var(--ctl); min-width: var(--ctl); }
.stepper { height: var(--ctl); }
.stepper button { height: auto; }
.stepper input[type="number"] { height: auto; min-height: 0; }
.eqseg button { min-height: var(--ctl); padding-top: 0; padding-bottom: 0; }
.tabs button { min-height: 44px; }

/* Grid header: labels shrink to R / C when the panel is narrow */
#panel-grid .panel-head { container-type: inline-size; container-name: gridhead; }
.size-field { gap: 4px; }
.size-field .lbl-short { display: none; font-family: var(--mono); font-weight: 500; }
@container gridhead (max-width: 431px) {
  .size-field .lbl-long { display: none; }
  .size-field .lbl-short { display: inline; }
}

/* edge dropdown: fixed width so the short label sits neatly; the open list can be wider */
.edge-select { width: 11.3em; } /* fits the longest short label, "Roundover 10 mm" */
.preview-tools { gap: 6px; justify-content: flex-start; }
.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-group.right { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- canvas corner tools (rotate/mirror left, snapping right) ---------- */
.editor-canvas .editor-svg { top: calc(var(--ctl) + 12px); height: calc(100% - var(--ctl) - 12px); }
.canvas-tools { position: absolute; top: 6px; display: flex; align-items: center; gap: 6px; z-index: 2; }
.canvas-tools.left { left: 6px; }
.canvas-tools.right { right: 6px; }
.canvas-tools > .btn, .canvas-tools .seg .btn:not(.is-on) { background: #fff; }
.grid-btn { gap: 6px; padding: 0 10px; }
.grid-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.grid-btn .grid-btn-label { min-width: 1.6em; text-align: left; }
.grid-btn .caret { font-size: 10px; opacity: 0.8; }
.grid-btn.is-set { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.menu .check-item { position: relative; padding-left: 30px; }
.menu .check-item.is-checked { font-weight: 600; }
.menu .check-item.is-checked::before { content: '✓'; position: absolute; left: 10px; color: var(--teal); }

/* ---------- units ---------- */
.units-toggle .btn { padding: 0 9px; min-width: 0; }
.thickness-field { gap: 6px; }
.thickness-input { width: 4.8em; }
.is-imperial .thickness-input { width: 6.4em; }
.coord-input { width: 6.2em; }

/* ---------- wood estimate: shares the Preview column ---------- */
@media (min-width: 1100px) {
  .panels {
    grid-template-rows: minmax(0, 1fr) var(--wood-h, 50%);
    grid-template-areas: "editor grid preview" "editor grid wood";
  }
  #panel-editor { grid-area: editor; }
  #panel-grid { grid-area: grid; }
  #panel-preview { grid-area: preview; min-height: 0; }
  #panel-preview .preview-stage { min-height: 120px; }
  #panel-wood { grid-area: wood; min-height: 0; }
  #panel-wood.is-collapsed .wood-body { display: none; }
  #panel-wood.is-collapsed .wood-head { border-bottom: 0; }
}
@media (max-width: 1099px) {
  .wood-divider, .wood-fold { display: none !important; }
}
.wood-divider { flex: none; height: 10px; display: flex; align-items: center; justify-content: center; cursor: row-resize; touch-action: none; margin-bottom: -4px; }
.wood-divider span { width: 40px; height: 4px; border-radius: 2px; background: var(--moss); }
.wood-divider:hover span, .wood-divider:focus-visible span, .is-resizing .wood-divider span { background: var(--teal); width: 64px; }
.wood-divider:focus-visible { outline: none; }
.wood-head { padding-top: 4px; row-gap: 2px; }
.wood-summary { font-size: 13px; }
.wood-body { padding: 10px 12px 12px; }
.stack-bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; margin: 0 0 10px; }
.stack-bar span { display: block; min-width: 3px; }
.wood-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.wood-settings { display: flex; flex-wrap: wrap; gap: 8px 14px; background: var(--accent-soft); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.wood-settings .field, .plank-edit .field { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.wood-settings input, .plank-edit input { width: 4.2em; }
.wood-settings.is-imperial input, .plank-edit.is-imperial input { width: 5.6em; }
.wood-settings-foot { flex-basis: 100%; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.wood-list { display: flex; flex-direction: column; gap: 6px; }
.wood-empty { margin: 8px 2px; }
.sp-row { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.sp-row.open { border-color: var(--line-2); }
.sp-head { display: grid; grid-template-columns: 12px 16px minmax(0, 1fr) auto auto 48px; align-items: center; gap: 8px; width: 100%; min-height: var(--ctl); background: none; border: 0; padding: 6px 10px; font: inherit; font-size: 13.5px; color: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
div.sp-head { grid-template-columns: 16px minmax(0, 1fr) auto auto 64px; cursor: default; }
.sp-head .caret { font-size: 11px; color: var(--ink-3); }
.sp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.25); flex: none; }
.sp-bar { height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; display: block; }
.sp-bar span { display: block; height: 100%; }
.shape { padding: 6px 10px 8px; border-top: 1px dashed var(--line); }
.shape-head { display: flex; gap: 8px; align-items: center; margin: 2px 0 6px; font-size: 13.5px; }
.shape-head .block-thumb { flex: none; }
.endview { display: block; width: 100%; height: auto; max-height: 180px; }
.endview.large { max-height: 170px; max-width: 480px; }
.endview .plank-end { opacity: 0.25; stroke: var(--moss); stroke-width: 0.6; stroke-dasharray: 3 2; }
.endview .stick { stroke: var(--ink); stroke-width: 0.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.endview .plank-end { vector-effect: non-scaling-stroke; stroke-width: 1; }
.shape-note { margin: 4px 0 0; }
.sp-buy { margin: 0; padding: 6px 10px 2px; border-top: 1px dashed var(--line); }
.plank-edit { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px 10px; }
.bl-row { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 10px; font-size: 13.5px; }
.bl-row .block-thumb { flex: none; margin-top: 2px; }
.pieces { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12.5px; }
.chip-s { display: inline-flex; align-items: center; gap: 5px; }
.wood-foot { font-size: 12px; margin-top: 10px; line-height: 1.45; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--teal); text-decoration: underline; cursor: pointer; }
.wood-dialog { width: min(1100px, calc(100vw - 32px)); }
.wood-dialog .dialog-body { overflow: auto; }
.wood-large-sum { margin: 0 0 8px; }
.wood-large-cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.wood-large-cols > div { display: flex; flex-direction: column; gap: 8px; }
.wood-large-cols h4 { margin: 4px 0 0; font-size: 15px; }
@media (max-width: 800px) { .wood-large-cols { grid-template-columns: 1fr; } }
.wood-how { width: min(640px, calc(100vw - 32px)); }
.wood-how ol { padding-left: 20px; margin: 0 0 12px; }
.wood-how li { margin: 0 0 8px; }

.btn-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.wood-big { gap: 6px; }

/* ---------- custom woods ---------- */
.swatch.is-custom .chip { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15), 0 0 0 2px #fff, 0 0 0 3px var(--moss); }
.swatch-add { border-style: dashed; border-color: var(--teal); color: var(--teal); }
.swatch .chip.add { background: none; box-shadow: none; display: grid; place-items: center; font-weight: 600; font-size: 16px; line-height: 1; }
.cw-dialog { width: min(520px, calc(100vw - 32px)); }
.cw-body { display: flex; flex-direction: column; gap: 14px; }
.cw-list { display: flex; flex-direction: column; gap: 6px; }
.cw-list:empty { display: none; }
.cw-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.cw-row.is-editing { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cw-row-name { font-weight: 500; }
.cw-chip { width: 22px; height: 22px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); flex: none; display: inline-block; }
.cw-form { display: flex; flex-direction: column; gap: 8px; }
.cw-form-head { min-height: var(--ctl); }
.cw-form-head .group-label { margin: 0; }
.cw-name-field { display: flex; align-items: center; gap: 8px; }
.cw-name { flex: 1; }
.cw-err { margin: 0; color: var(--err); font-size: 13px; }
.cw-palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.cw-swatch { aspect-ratio: 1; min-height: 32px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.2); cursor: pointer; padding: 0; }
.cw-swatch.is-on { outline: 3px solid var(--accent); outline-offset: 2px; }
.cw-other-field { display: flex; align-items: center; gap: 8px; }
.cw-other { width: 48px; height: var(--ctl); padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff; }
.cw-preview { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; font-weight: 600; }
.cw-preview .cw-chip { width: 36px; height: 36px; }
.cw-preview .hint { font-weight: 400; margin-left: auto; }

.wood-head { container-type: inline-size; container-name: woodhead; }
.wood-head-btns { display: flex; gap: 6px; margin-left: auto; flex: none; }
.wood-head .wood-summary { flex: 1 1 auto; min-width: 0; }
@container woodhead (max-width: 560px) {
  .wood-head .wood-summary { order: 3; flex-basis: 100%; margin-top: -2px; }
}

/* ---------- wood guide ---------- */
.swatch-guide { border-color: var(--teal); color: var(--teal); }
.swatch-guide .chip.add { font-family: Georgia, serif; font-style: italic; font-size: 15px; border: 1.5px solid currentColor; border-radius: 50%; width: 18px; height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wg-dialog { width: min(940px, calc(100vw - 32px)); }
.wg-dialog .dialog-body { padding: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.wg { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.wg-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px 8px; }
.wg-search { width: 200px; }
.wg-chk { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.wg-scroll { overflow: auto; padding: 0 16px; min-height: 0; flex: 1; max-height: calc(100vh - 260px); }
.wg-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.wg-table th { position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left; padding: 0; border-bottom: 1px solid var(--moss); white-space: nowrap; }
.wg-sort { background: none; border: 0; font: inherit; font-weight: 600; color: var(--ink); padding: 8px 6px; cursor: pointer; }
.wg-table th.sorted .wg-sort { color: var(--teal); }
.wg-note { font-weight: 400; color: var(--ink-3); }
.wg-table td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.wg-row { cursor: pointer; }
.wg-row:hover td, .wg-row:focus-visible td { background: #fff; }
.wg-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.wg-row.open td { background: #fff; border-bottom: 0; }
.wg-row.current .wg-name { font-weight: 650; }
.wg-detail-row td { background: #fff; border-bottom: 1px solid var(--moss); }
.c-caret { width: 16px; font-size: 11px; color: var(--ink-3); }
.c-warn { width: 28px; text-align: center; }
.wg-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.wg-sw { width: 18px; height: 18px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); flex: none; }
.wg-hard { display: inline-flex; align-items: center; gap: 6px; }
.wg-hard-bar { width: 80px; height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; display: inline-block; }
.wg-hard-bar span { display: block; height: 100%; background: var(--teal); }
.wg-dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.wg-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: block; }
.wg-dots i.on { background: var(--teal); }
.wg-pores { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--ok-soft); color: var(--slate); white-space: nowrap; }
.wg-pores.open { background: #f6ead6; color: #6b4e1e; }
.wg-great { font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 4px; white-space: nowrap; }
.wg-great.main { background: var(--ok-soft); color: var(--ink); }
.wg-great.accent { background: #e9e4f2; color: #4a3a66; }
.wg-great.avoid { background: var(--err-soft); color: var(--err); }
.wg-warn { color: var(--err); }
.wg-detail { padding: 2px 0 10px; }
.wg-line { margin: 2px 0 8px; font-weight: 500; }
.wg-sci { font-weight: 400; font-style: italic; color: var(--ink-3); font-size: 12.5px; }
.wg-pc { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13px; }
.wg-pc ul { margin: 2px 0 0; padding-left: 18px; }
.wg-pc li { margin: 1px 0; }
.wg-food { font-size: 13px; margin: 8px 0 4px; }
.wg-food.warn { color: #8c2a1f; }
.wg-src { margin: 4px 0; }
.wg-src a { color: var(--teal); }
.wg-actions { margin-top: 8px; }
.wg-mobile-stats { display: none; gap: 16px; margin: 0 0 8px; font-size: 13px; align-items: center; }
.wg-mobile-stats > span { display: inline-flex; align-items: center; gap: 6px; }
.wg-sub td { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; padding-top: 14px; }
.wg-none { padding: 16px 6px; }
.wg-foot { padding: 8px 16px 0; margin: 0; }
@media (max-width: 700px) {
  .wg-table .c-work, .wg-table .c-pores { display: none; }
  .wg-mobile-stats { display: flex; }
  .wg-pc { grid-template-columns: 1fr; gap: 6px; }
  .wg-hard-bar { width: 44px; }
  .wg-search { width: 100%; }
  .wg-note { display: none; }
}
@media (max-width: 560px) {
  .wg-dialog, .cw-dialog, .wood-dialog, .wood-how { width: 100%; }
  .wg-dialog .dialog-body { flex: 1; }
  .wg-scroll { max-height: none; }
  .wg-scroll { padding: 0 8px; }
}

/* ---------- block editor rows (regroup on narrow screens) ---------- */
.edit-rows { display: flex; flex-direction: column; gap: 10px; }
.row-break { display: none; }
@media (max-width: 1099px) {
  .edit-rows { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 6px; }
  .edit-rows .blockbar, .edit-rows .toolbar { display: contents; }
  .edit-rows .row-break { display: block; flex-basis: 100%; height: 0; }
  .edit-rows .letter-badge, .edit-rows .name-input, .edit-rows .tb-del { order: 1; }
  .edit-rows .name-input { flex: 1 1 80px; max-width: none; }
  .edit-rows .b1 { order: 2; }
  .edit-rows .f-w, .edit-rows .f-h, .edit-rows .units-toggle { order: 3; }
  .edit-rows .units-toggle { margin-left: auto; }
  .edit-rows .b2 { order: 4; }
  .edit-rows .tb-tools, .edit-rows .tb-clear { order: 5; }
  .edit-rows .tb-tpl { order: 6; }

  /* preview tools: view + lines / edge + thickness + units */
  .preview-tools.row { flex-wrap: wrap; row-gap: 8px; }
  .preview-tools .tool-group { display: contents; }
  .preview-tools .row-break { display: block; flex-basis: 100%; height: 0; order: 3; }
  .preview-tools .pv-zoom, .preview-tools .pv-fit { order: 1; }
  .preview-tools .pv-blocks { order: 2; margin-left: auto; }
  .preview-tools .pv-glue { order: 2; }
  .preview-tools .edge-select, .preview-tools .thickness-field, .preview-tools .units-toggle { order: 4; }
  .preview-tools .thickness-field { margin-left: auto; }
}

/* narrow block canvas: snapping tools drop to a second row under rotate/mirror */
.editor-canvas { container-type: inline-size; container-name: blockcanvas; }
/* narrow block canvas: rotate/mirror stack down the left side, snapping stays top right */
@container blockcanvas (max-width: 420px) {
  .canvas-tools.left { flex-direction: column; }
  .editor-svg {
    top: calc(var(--ctl) + 12px) !important; height: calc(100% - var(--ctl) - 12px) !important;
    left: calc(var(--ctl) + 12px) !important; width: calc(100% - var(--ctl) - 12px) !important;
  }
}

.thickness-field .lbl-short { display: none; }
@media (max-width: 480px) {
  .thickness-field .lbl-long { display: none; }
  .thickness-field .lbl-short { display: inline; }
}

/* ---------- board name, status and file actions in the top bar ---------- */
.app-title { flex: none; }
.board-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; margin-left: 14px; }
.board-name-wrap { display: inline-grid; min-width: 0; max-width: min(420px, 100%); }
.board-name-wrap > * { grid-area: 1 / 1; font: 600 15px/1.2 var(--sans, 'DM Sans', sans-serif); padding: 5px 8px; white-space: pre; }
.board-name-sizer { visibility: hidden; overflow: hidden; }
.app-header input.board-name {
  width: 100%; min-width: 4em; height: auto; min-height: 0; background: transparent; color: #fff; border: 1px solid transparent; border-radius: 6px;
  text-overflow: ellipsis;
}
.app-header input.board-name:hover { border-color: var(--slate); }
.app-header input.board-name:focus { border-color: var(--moss); background: rgba(255, 255, 255, 0.06); outline: none; }
.board-status { font-size: 12.5px; color: var(--moss); white-space: nowrap; }
.board-status[data-state="dirty"], .board-status[data-state="unsaved"] { color: #e9c46a; }
.board-status[data-state="dirty"]::before, .board-status[data-state="unsaved"]::before { content: '● '; }
.board-status[data-state="saved"]::before { content: '✓ '; }
.header-actions { align-items: center; }
.app-header .btn.save-btn { background: var(--teal); border-color: var(--teal); height: 36px; min-height: 36px; padding: 0 14px; }
.app-header .btn.save-btn:not(:disabled):hover { background: var(--slate); }
.app-header .btn.boards-btn { height: 36px; min-height: 36px; padding: 0 12px; }
.app-header .more-btn { font-size: 18px; }
@media (max-width: 700px) {
  .app-title, .boards-btn { display: none; }
  .board-title { margin-left: 0; gap: 6px; }
  .board-status { font-size: 0; }
  .board-status::before { font-size: 13px; }
  .board-name-wrap > * { font-size: 14px; padding: 5px 6px; }
}

/* ---------- boards gallery: tabs, My boards ---------- */
.gallery-body { position: relative; display: flex; flex-direction: column; gap: 12px; }
.gallery-tabs { display: flex; align-items: center; gap: 10px; }
.gallery-tile.my-tile { position: relative; }
.gallery-tile.my-tile.is-open { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.tile-name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.open-badge { font-size: 11px; font-weight: 600; background: var(--teal); color: #fff; border-radius: 4px; padding: 1px 6px; }
.my-date { font-size: 12px; color: var(--ink-2); }
.tile-more { position: absolute; top: 14px; right: 14px; background: #fff; }
.tile-rename { width: 100%; font-weight: 600; }
.gallery-art.broken { color: var(--ink-3); font-size: 13px; }
.tile-upload { align-items: center; justify-content: center; text-align: center; border: 2px dashed var(--teal); background: #f7f9f6; color: var(--teal); min-height: 236px; gap: 6px; }
.tile-upload:hover { background: var(--accent-soft); }
.tile-upload-plus { font-size: 30px; line-height: 1; }
.tile-upload b { font-size: 15px; }
.drop-note { display: none; position: absolute; inset: 0; border: 3px dashed var(--teal); border-radius: 10px; background: rgba(243, 245, 241, 0.92); color: var(--teal); font-weight: 600; font-size: 17px; place-items: center; z-index: 5; pointer-events: none; }
.gallery-body.is-dropping .drop-note { display: grid; }
.save-dialog { width: min(460px, 100%); }
.save-body { display: flex; flex-direction: column; gap: 10px; }
.save-name { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.save-body .hint { margin: 0; }
.import-errors { margin: 0 0 10px; padding-left: 18px; }
.import-errors li { margin: 4px 0; }
@media (max-width: 560px) { .tile-upload { min-height: 180px; } .tile-more { top: 10px; right: 10px; } }

/* ---------- help, about, support ---------- */
.hdr-sep { width: 1px; height: 24px; background: var(--teal); margin: 0 4px; flex: none; }
.app-header .round-btn { width: 36px; height: 36px; min-height: 36px; border-radius: 50%; font: 600 15px/1 var(--sans, 'DM Sans', sans-serif); }
.app-header .about-btn { font-family: Georgia, 'Times New Roman', serif; font-style: italic; }
.coffee-link { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 8px; font-size: 13.5px; font-weight: 500; text-decoration: none; white-space: nowrap; flex: none; }
.coffee-link.header { color: var(--sage); border: 1px solid var(--teal); }
.coffee-link.header:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.coffee-link.brand { background: #ffdd00; color: #000; border: 1px solid #ffdd00; }
.coffee-link.brand:hover { background: #ffe94d; }
@media (max-width: 1099px) { .app-header .coffee-text { display: none; } .coffee-link.header { padding: 0; width: 36px; justify-content: center; } }
@media (max-width: 700px) { .hdr-sep, .app-header .help-btn, .app-header .about-btn, .app-header .coffee-link { display: none; } }
.about-dialog, .help-dialog { width: min(560px, calc(100vw - 32px)); }
.about { display: flex; flex-direction: column; gap: 14px; font-size: 14px; line-height: 1.5; }
.about p { margin: 0; }
.about h4, .help h4 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.about-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.about-pills span { font-size: 12.5px; background: var(--ok-soft); color: var(--ink); border-radius: 12px; padding: 2px 10px; }
.about-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.about-gh { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 600; text-decoration: none; border: 1px solid var(--moss); border-radius: 8px; padding: 6px 10px; background: #fff; }
.about-gh:hover { border-color: var(--teal); }
.about ul { margin: 0; padding-left: 18px; }
.about li { margin: 2px 0; }
.about a:not(.about-gh):not(.coffee-link), .help a { color: var(--teal); }
.help { display: flex; flex-direction: column; gap: 14px; font-size: 14px; line-height: 1.5; }
.help p { margin: 0 0 6px; }
.help-step { display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.help-step h4 { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--ink); }
.help-n { width: 26px; height: 26px; border-radius: 50%; background: var(--teal); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.help-keys dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
.help-keys dd { margin: 0; }
.help-keys kbd { font: 500 12px var(--mono, 'DM Mono', monospace); background: #fff; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.help-dialog .dialog-body, .about-dialog .dialog-body { overflow: auto; }
