:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #faf9f7;
  --line: #e8e4dd;
  --line-strong: #d9d3c9;
  --text: #1f1c19;
  --muted: #77716a;
  --faint: #a59f96;
  --accent: #c4553a;
  --accent-hover: #ad4730;
  --accent-soft: #f8e9e3;
  --select: #2f6fed;
  --danger: #c8372d;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(31, 28, 25, 0.06);
  --shadow: 0 4px 16px rgba(31, 28, 25, 0.08), 0 1px 3px rgba(31, 28, 25, 0.06);
  --shadow-lg: 0 24px 64px rgba(31, 28, 25, 0.18), 0 4px 12px rgba(31, 28, 25, 0.08);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { flex: none; }
button svg, .btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--panel); cursor: pointer; white-space: nowrap;
  font-weight: 500; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--panel-2); border-color: #cbc4b8; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: #fdf0ef; border-color: #f0c7c3; }
.btn.dashed { border-style: dashed; box-shadow: none; background: transparent; color: var(--muted); }
.btn.dashed:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.btn.block { width: 100%; }
.btn.sm { height: 30px; padding: 0 9px; font-size: 13px; gap: 5px; }
.btn.sm svg { width: 14px; height: 14px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer; color: #4a4540;
  transition: background .12s, color .12s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: #efece7; color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.xs { width: 26px; height: 26px; }
.icon-btn.xs svg { width: 14px; height: 14px; }
.icon-btn.toggle.on { background: var(--accent-soft); color: var(--accent); }

.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: 13px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

.chip {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.divider { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.spacer { flex: 1; }
.row { display: flex; align-items: flex-end; }
.row.gap { gap: 8px; }
.row > * { flex: 1; min-width: 0; }

:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; }

/* ---------------------------------------------------------------- segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: #ece9e3; border-radius: 9px; }
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 500; transition: background .12s, color .12s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented.wide, .segmented.tabs { display: flex; }
.segmented.wide button, .segmented.tabs button { flex: 1; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 12px 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.logo svg { width: 30px; height: 30px; display: block; }
.logo rect { fill: var(--accent); }
.logo path { fill: #fbf3e6; }
.title-input {
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; padding: 5px 8px; width: min(320px, 100%); min-width: 0;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--select); outline: none; background: var(--panel); }
.toolbar { display: flex; align-items: center; gap: 2px; }
.toolbar .btn { margin-left: 6px; }

/* ---------------------------------------------------------------- layout */
.layout { flex: 1; display: grid; grid-template-columns: 264px 1fr 288px; min-height: 0; }
.panel { background: var(--panel); overflow-y: auto; min-height: 0; }
.left-panel { border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.right-panel { border-left: 1px solid var(--line); }
.side-pane { display: flex; flex-direction: column; gap: 10px; border-radius: var(--radius); }
.side-pane.drop-target { outline: 2px dashed var(--accent); outline-offset: 4px; background: var(--accent-soft); }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; line-height: 1.45; }

/* shape library */
.shape-library { display: flex; flex-direction: column; gap: 4px; }
.shape-item {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: var(--radius); cursor: pointer; border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.shape-item:hover, .shape-item:focus-visible { background: var(--panel-2); border-color: var(--line); }
.shape-item:active { cursor: grabbing; }
.shape-item .thumb { background: #f5f2ec; border-radius: 8px; padding: 6px; width: 52px; height: 52px; }
.thumb path { fill: #e9c5b8; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.shape-item .meta { display: flex; flex-direction: column; min-width: 0; }
.shape-item strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shape-item span { color: var(--muted); font-size: 12px; }
.item-actions { position: absolute; right: 6px; display: none; gap: 2px; background: var(--panel-2); border-radius: 6px; }
.shape-item:hover .item-actions { display: flex; }

/* fabric library */
.fabric-library { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; }
.fabric-item { position: relative; display: flex; flex-direction: column; gap: 4px; cursor: pointer; min-width: 0; }
.fabric-item .swatch {
  aspect-ratio: 1; border-radius: var(--radius); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
  background-repeat: repeat; transition: transform .12s, box-shadow .12s;
}
.fabric-item:hover .swatch { transform: translateY(-1px); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), var(--shadow); }
.fabric-item.active .swatch { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--select); }
.fabric-item > span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.fabric-item .edit { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,.92); display: none; box-shadow: var(--shadow-sm); }
.fabric-item:hover .edit { display: grid; }

/* ---------------------------------------------------------------- stage */
.stage-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.stage {
  position: absolute; inset: 0; overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(#dcd7ce 1px, transparent 1px);
  background-size: 22px 22px;
}
.stage.can-pan { cursor: grab; }
.stage.panning { cursor: grabbing; }
.quilt-canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; outline: none; }
.quilt-bg { filter: drop-shadow(0 6px 18px rgba(31, 28, 25, .14)) drop-shadow(0 1px 2px rgba(31, 28, 25, .1)); }
.quilt-edge { stroke: rgba(31, 28, 25, .18); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.quilt-label { fill: var(--muted); font-family: var(--font); font-weight: 500; pointer-events: none; }
.grid { pointer-events: none; }
.grid-minor { stroke: rgba(31, 28, 25, .07); stroke-width: 1; fill: none; }
.grid-major { stroke: rgba(31, 28, 25, .15); stroke-width: 1; fill: none; }
.piece { cursor: move; }
.piece:hover path { filter: brightness(1.05); }
.sel-halo { fill: none; stroke: #fff; stroke-width: 4; stroke-linejoin: round; pointer-events: none; opacity: .9; }
.sel-outline { fill: none; stroke: var(--select); stroke-width: 2; stroke-linejoin: round; pointer-events: none; }
.sel-box { fill: none; stroke: var(--select); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; opacity: .7; }
.rot-stem { stroke: var(--select); stroke-width: 1; pointer-events: none; }
.rot-handle { cursor: grab; }
.rot-handle circle { fill: #fff; stroke: var(--select); stroke-width: 1.5; filter: drop-shadow(0 1px 2px rgba(0,0,0,.2)); }
.rot-handle .rot-icon { fill: none; stroke: var(--select); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.snap-dot { fill: var(--accent); stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.marquee { fill: rgba(47, 111, 237, .08); stroke: var(--select); stroke-width: 1; pointer-events: none; }
.angle-label { fill: #fff; paint-order: stroke; stroke: var(--select); stroke-linejoin: round; font-family: var(--font); font-weight: 600; text-anchor: middle; pointer-events: none; }

.empty-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 22px 28px; border-radius: 14px; background: rgba(255,255,255,.85); backdrop-filter: blur(6px);
  box-shadow: var(--shadow); pointer-events: none; transition: opacity .2s;
}
.empty-hint svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.6; margin-bottom: 4px; }
.empty-hint strong { font-size: 15px; }
.empty-hint span { color: var(--muted); }
.empty-hint.hidden { opacity: 0; }

.float-bar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.zoom-readout {
  min-width: 56px; height: 34px; border: 0; background: none; border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums; font-weight: 500; cursor: pointer; color: #4a4540;
}
.zoom-readout:hover { background: #efece7; }

/* ---------------------------------------------------------------- inspector */
.insp-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.insp-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.insp-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.insp-section { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.insp-section:last-child { border-bottom: 0; }
.insp-section h4 { margin: 0; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.insp-section h4 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.btn-row.two { grid-template-columns: 1fr 1fr; }
.btn-row .btn { padding: 0 4px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline > span { white-space: nowrap; }
.field.grow { flex: 1; }
.field input:not([type=checkbox]):not([type=color]), .field select, .input-unit {
  height: 32px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--panel); padding: 0 8px; min-width: 0; width: 100%;
}
.field input:focus, .field select:focus, .input-unit:focus-within { border-color: var(--select); outline: none; box-shadow: 0 0 0 3px rgba(47,111,237,.15); }
.input-unit { display: flex; align-items: center; padding: 0 8px 0 0 !important; }
.input-unit input { border: 0 !important; height: 30px !important; box-shadow: none !important; background: transparent !important; flex: 1; }
.input-unit em { font-style: normal; color: var(--faint); font-size: 12px; }
input[type=color] {
  width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--panel); cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 5px; }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 5px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; row-gap: 2px; }
.slider span { font-size: 12px; color: var(--muted); font-weight: 500; }
.slider output { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text); }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 0; }

.current-fabric { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); }
.current-fabric .swatch { width: 40px; height: 40px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); flex: none; }
.current-fabric div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.current-fabric strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.current-fabric span { font-size: 12px; color: var(--muted); }

.usage { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.usage li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.usage li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage li b { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.mini-swatch { width: 18px; height: 18px; border-radius: 5px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.mini-swatch.empty { background: #e4ded3; }

/* ---------------------------------------------------------------- dialogs */
.modal {
  border: 0; padding: 0; border-radius: 16px; box-shadow: var(--shadow-lg); color: var(--text);
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--panel);
}
.modal[open] { display: flex; flex-direction: column; animation: pop .16s ease-out; }
.modal::backdrop { background: rgba(31, 28, 25, .35); backdrop-filter: blur(2px); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.modal-sm { width: min(380px, calc(100vw - 32px)); }
.modal-lg { width: min(920px, calc(100vw - 32px)); height: min(660px, calc(100vh - 32px)); }
.modal-head { display: flex; align-items: center; gap: 16px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px 20px; overflow: auto; flex: 1; min-height: 0; }
.modal-body.stack { display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 16px 16px; }
.confirm-text { margin: 4px 0; line-height: 1.5; }

/* shape builder */
.pane-basic { display: grid; grid-template-columns: 1fr 300px; gap: 20px; height: 100%; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; align-content: start; overflow: auto; padding: 2px; }
.type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); cursor: pointer;
  font-size: 12px; color: var(--muted); text-align: center; line-height: 1.2;
}
.type-btn:hover { border-color: var(--line-strong); background: var(--panel-2); color: var(--text); }
.type-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.type-btn .thumb { width: 34px; height: 34px; }
.basic-side { display: flex; flex-direction: column; gap: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.basic-preview { display: grid; place-items: center; height: 220px; }
.basic-preview .preview { width: 100%; height: 100%; }
.preview path { fill: #e9c5b8; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.basic-dims { text-align: center; color: var(--muted); font-size: 13px; }
.param-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.pane-draw { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.draw-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.draw-tools .field select { width: auto; }
.draw-board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
#draw-svg { width: 100%; height: 100%; max-height: 100%; cursor: crosshair; outline: none; touch-action: none; }
#draw-svg .board { fill: #fff; stroke: var(--line-strong); stroke-width: .02; }
#draw-svg .board-minor { stroke: rgba(31,28,25,.07); stroke-width: 1; fill: none; }
#draw-svg .board-major { stroke: rgba(31,28,25,.18); stroke-width: 1; fill: none; }
#draw-svg .board-label { fill: var(--faint); font-family: var(--font); text-anchor: middle; }
#draw-svg .draw-shape { fill: rgba(196, 85, 58, .2); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
#draw-svg .draw-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
#draw-svg .draw-preview { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
#draw-svg .draw-len { fill: var(--text); font-family: var(--font); font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: .08; }
#draw-svg .vertex { fill: #fff; stroke: var(--accent); stroke-width: .04; cursor: pointer; }
#draw-svg .vertex.first { fill: var(--accent); }
#draw-svg .vertex:hover { fill: var(--accent-soft); stroke-width: .06; }
#draw-svg .midpoint { fill: var(--accent); opacity: .35; cursor: copy; }
#draw-svg .midpoint:hover { opacity: .9; }
#draw-svg .draw-cursor { fill: var(--select); pointer-events: none; }
.draw-status { font-size: 12.5px; color: var(--muted); height: 2.9em; overflow: hidden; } /* fixed so the board never resizes mid-stroke */

.fabric-preview { height: 140px; border-radius: 12px; background-repeat: repeat; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }

.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; margin: 0 0 16px; font-size: 13.5px; }
.shortcuts dt { color: var(--muted); }
.shortcuts dd { margin: 0; }
kbd {
  display: inline-block; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 5px; font: 12px/1.4 var(--font); background: var(--panel-2); color: var(--text);
}

/* ---------------------------------------------------------------- toast & tooltip */
.toast {
  position: fixed; left: 50%; bottom: 76px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: #26221e; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow); transition: opacity .18s, transform .18s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: #26221e; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap;
}
.tooltip.show { opacity: 1; }


/* ---------------------------------------------------------------- print */
#print-area { display: none; }
@media print {
  body { background: #fff; display: block; overflow: visible; height: auto; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; text-align: center; }
  #print-area h1 { font: 600 18pt var(--font); margin: 0 0 2pt; }
  #print-area p { font: 10pt var(--font); color: #555; margin: 0 0 10pt; }
  #print-area img { max-width: 100%; max-height: 92vh; object-fit: contain; }
}
#help-dialog { width: min(580px, calc(100vw - 32px)); }

/* ---------------------------------------------------------------- pattern import */
.modal-xl { width: min(1180px, calc(100vw - 32px)); height: min(720px, calc(100vh - 32px)); }
.import-body { display: grid; grid-template-columns: 1fr 290px; gap: 20px; }
.import-main { min-width: 0; min-height: 0; display: flex; }
.import-drop {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--line-strong); border-radius: 14px; padding: 32px; text-align: center; background: var(--panel-2);
}
.import-drop > svg { width: 40px; height: 40px; fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.import-drop strong { font-size: 16px; }
.import-drop > span { color: var(--muted); }
.import-drop .hint { max-width: 440px; margin-top: 8px; }
.import-drop.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.import-work { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; min-height: 0; }
.import-work figure { margin: 0; display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.import-work figcaption { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.import-canvas { flex: 1; min-height: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; }
.import-canvas svg { width: 100%; height: 100%; touch-action: none; }
.import-dim { fill: rgba(31, 28, 25, .45); pointer-events: none; }
.import-grid { stroke: #fff; stroke-width: 1; fill: none; opacity: .9; pointer-events: none; mix-blend-mode: difference; }
.import-frame { fill: transparent; stroke: var(--select); stroke-width: 2; cursor: move; }
.import-handle { fill: #fff; stroke: var(--select); cursor: nwse-resize; }
.import-handle[data-h=tr], .import-handle[data-h=bl] { cursor: nesw-resize; }
#import-preview path { stroke: rgba(31, 28, 25, .35); stroke-width: .012; stroke-linejoin: round; }
.import-palette { display: flex; flex-wrap: wrap; gap: 5px; min-height: 20px; }
.import-palette i { width: 20px; height: 20px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.import-controls { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; padding-right: 2px; }
.import-controls section { display: flex; flex-direction: column; gap: 8px; }
.import-controls h4 { margin: 0; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.import-controls .check input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

/* ---------------------------------------------------------------- touch & small screens */
/* Elements that only exist for the phone layout */
#btn-more, .mobile-nav, .sel-bar, .menu, .sheet-handle, .narrow-only, .pointer-coarse { display: none; }

button, .shape-item, .fabric-item { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.stage { -webkit-touch-callout: none; }
.rot-handle .rot-hit { fill: transparent; stroke: none; filter: none; }

@media (pointer: coarse) {
  .pointer-fine { display: none; }
  .pointer-coarse { display: inline; }
}

/* No hover on touch screens: keep hover-only controls visible. */
@media (hover: none) {
  .shape-item .item-actions { display: flex; position: static; margin-left: auto; background: none; }
  .fabric-item .edit { display: grid; }
  .piece:hover path { filter: none; }
}

@media (max-width: 760px) {
  :root { --nav-h: 58px; --top-h: 52px; }
  body { height: 100dvh; }
  input, select { font-size: 16px !important; } /* stops iOS zooming into fields */

  /* top bar */
  .topbar { height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0 10px; gap: 4px; }
  .brand { gap: 6px; }
  .logo svg { width: 26px; height: 26px; }
  .title-input { width: 100%; font-size: 16px; padding: 5px 6px; }
  .toolbar .divider, #btn-new, #btn-open, #btn-save, #btn-help, #btn-import, #btn-print { display: none; }
  .toolbar .btn .label { display: none; }
  #btn-export { width: 40px; height: 36px; padding: 0; margin-left: 4px; }
  #btn-more { display: inline-grid; }
  .icon-btn { width: 40px; height: 40px; }
  .menu:not([hidden]) {
    display: flex; flex-direction: column; position: fixed; z-index: 40;
    top: calc(var(--top-h) + env(safe-area-inset-top) - 4px); right: 8px; min-width: 220px; padding: 6px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
    animation: pop .14s ease-out;
  }
  .menu button {
    display: flex; align-items: center; gap: 12px; padding: 12px; border: 0; background: none;
    border-radius: 9px; font-size: 15px; text-align: left; cursor: pointer;
  }
  .menu button:active { background: #efece7; }
  .menu svg { width: 18px; height: 18px; color: var(--muted); }

  /* canvas fills the space between the bars */
  .layout { display: block; position: relative; }
  .stage-wrap { position: absolute; inset: 0; }
  .float-bar { left: auto; right: 10px; top: 10px; bottom: auto; transform: none; flex-direction: column; padding: 3px; }
  #btn-zoom-in, #btn-zoom-out, .zoom-readout, .float-bar .divider { display: none; }
  .empty-hint { width: calc(100% - 48px); padding: 18px 20px; }
  .wide-only { display: none; }
  .narrow-only { display: inline; }

  /* selection toolbar */
  .sel-bar {
    display: flex; align-items: center; position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
    padding: 4px; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
    max-width: calc(100% - 16px); overflow-x: auto;
  }
  .sel-bar .divider { margin: 0 2px; }
  .sel-bar .icon-btn { width: 40px; height: 40px; flex: none; }
  .sel-bar [data-sel=del] { color: var(--danger); }

  /* bottom tab bar */
  .mobile-nav {
    display: flex; flex: none; z-index: 6; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line);
  }
  .mobile-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 500; cursor: pointer;
  }
  .mobile-nav button svg { width: 22px; height: 22px; }
  .mobile-nav button.active { color: var(--accent); }

  /* side panels become bottom sheets */
  .panel {
    position: fixed; left: 0; right: 0; z-index: 5;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    height: min(55dvh, 480px); border: 0 !important; border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgba(31, 28, 25, .14);
    transform: translateY(105%); visibility: hidden;
    transition: transform .24s cubic-bezier(.2, .8, .2, 1), visibility 0s .24s;
    overscroll-behavior: contain;
  }
  .panel::before {
    content: ''; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong);
    margin: 8px auto 0; flex: none;
  }
  body[data-sheet=shapes] .left-panel,
  body[data-sheet=fabrics] .left-panel,
  body[data-sheet=inspector] .right-panel {
    transform: none; visibility: visible; transition: transform .24s cubic-bezier(.2, .8, .2, 1);
  }
  .left-panel { padding: 0 14px 14px; gap: 10px; }
  .left-panel::before { margin-bottom: 4px; }
  .left-panel .segmented.tabs { display: none; }
  .right-panel .insp-head { padding-top: 8px; }
  .shape-item { padding: 8px; }
  .fabric-library { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
  .btn { height: 40px; }
  .btn.sm { height: 38px; }
  .toast { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 72px); }

  /* dialogs go full screen (except small confirmations) */
  .modal:not(.modal-sm) { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .modal:not(.modal-sm) .modal-foot { border-radius: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal:not(.modal-sm) .modal-head { padding-top: calc(12px + env(safe-area-inset-top)); flex-wrap: wrap; row-gap: 10px; }
  .modal-head .segmented { order: 3; width: 100%; }
  .modal-head .segmented button { flex: 1; padding: 8px 6px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .field.grow { flex-basis: 100%; }
  .modal:not(.modal-sm) .modal-foot .btn { flex: 1; }
  .modal-foot .spacer { display: none; }

  /* shape builder */
  .pane-basic { grid-template-columns: 1fr; grid-template-rows: auto 1fr; gap: 12px; }
  .type-grid { grid-auto-flow: column; grid-auto-columns: 88px; grid-template-columns: none; overflow-x: auto; overflow-y: hidden; padding-bottom: 6px; }
  .basic-side { padding: 12px; }
  .basic-preview { height: 150px; }
  .draw-tools { gap: 8px; }
  .draw-tools .spacer { display: none; }
  .draw-board-wrap { padding: 4px; }
  .draw-status { height: 4.4em; }

  /* pattern import */
  .import-body { display: flex; flex-direction: column; overflow-y: auto; }
  .import-main { flex: none; }
  .import-drop { padding: 24px 16px; }
  .import-work { display: flex; flex-direction: column; }
  .import-canvas { height: 46vh; flex: none; }
  .import-controls { overflow: visible; }
}

/* Tablets and phones in landscape: keep the side panels but slimmer. */
@media (min-width: 761px) and (max-width: 1100px) {
  .layout { grid-template-columns: 244px 1fr 260px; }
  .fabric-library { grid-template-columns: repeat(2, 1fr); }
}

@media (pointer: coarse) { .touch-tips { display: block; margin-bottom: 16px; font-size: 14px; } }

/* ---------------------------------------------------------------- layout lock */
.icon-btn.toggle#btn-lock.on { background: var(--accent); color: #fff; }
.locked-pill {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px;
  border: 0; border-radius: 999px; background: #26221e; color: #fff;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap;
}
.locked-pill svg { width: 14px; height: 14px; }
.locked-pill:hover { background: #3a342e; }
body.locked .sel-bar .layout-action { display: none; }
body.locked .shape-library { opacity: .5; }
body.locked .piece { cursor: pointer; }
.locked-note p { display: flex; gap: 8px; margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.locked-note p svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--accent); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- colour picker */
.colour-picker { display: flex; flex-direction: column; gap: 10px; }
.cp-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.cp-swatch {
  aspect-ratio: 1; min-width: 0; border: 0; border-radius: 7px; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); transition: transform .1s;
}
.cp-swatch:hover { transform: scale(1.06); }
.cp-swatch.active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--select); }
.cp-slider { display: flex; flex-direction: column; gap: 4px; }
.cp-slider span { font-size: 12px; color: var(--muted); font-weight: 500; }
.cp-slider input {
  -webkit-appearance: none; appearance: none; width: 100%; height: 14px; margin: 0;
  border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); cursor: pointer;
}
.cp-slider input::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 4px rgba(0, 0, 0, .3);
}
.cp-slider input::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 4px rgba(0, 0, 0, .3);
}
.cp-hex input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: lowercase; }
.cp-hex input.invalid { border-color: var(--danger) !important; }
.cp-preview { height: 56px; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.colour-btn {
  display: flex; align-items: center; gap: 8px; height: 32px; width: 100%; padding: 0 8px 0 4px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel); cursor: pointer;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted);
}
.colour-btn i { width: 24px; height: 24px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); flex: none; }
.colour-btn:hover { border-color: #cbc4b8; }
.fabric-preview { height: 110px; }

/* Let dialog bodies take their natural height: a 0 flex-basis can collapse to nothing in some
 * mobile browsers when the dialog has no fixed height. */
.modal-body { flex: 1 1 auto; }
@media (max-width: 760px) { .colour-btn { height: 40px; } }
.colour-picker .cp-slider input { height: 14px !important; padding: 0 !important; border: 0 !important; }
