/* Drapeform: design tokens
 *
 * Look: a warm dressmaker's workshop. Paper and kraft card for the panels, chalk and
 * thread for marks, a green self-healing cutting mat behind the cutting layout,
 * pin heads for selection and a tape-measure strip as the signature accent.
 * Light mode is a daylight workroom; dark mode is the same room at night under a lamp
 * (warm umber, never pure black).
 *
 * Core (used everywhere):
 *   --bg, --surface, --surface-2, --surface-3   page, paper panels, recessed paper, deeper recess
 *   --line, --line-strong                        hairlines / input borders
 *   --ink, --ink-2, --ink-3                      text: body, secondary, tertiary (all >= 4.5:1 on --surface)
 *   --accent, --accent-ink, --accent-soft        terracotta thread: primary action, its text, tinted fill
 *   --accent-strong                              darker accent for pressed edges / borders
 *   --focus                                      keyboard focus ring
 *   --warn-bg, --warn-ink                        sticky-note warnings
 *   --stage                                      3D studio backdrop (behind the transparent WebGL canvas)
 *   --radius, --radius-sm, --shadow-sm, --shadow
 *
 * Workshop tokens (pattern editor #draft-view, cutting view .layout-view, accents):
 *   --mat              cutting-mat green (background behind the fabric / pattern work)
 *   --mat-line         mat grid lines, every 1 cm
 *   --mat-line-strong  mat grid lines, every 10 cm
 *   --chalk            tailor's-chalk marks and text drawn ON the mat (>= 4.5:1 on --mat)
 *   --paper            pattern paper (the sheet pieces are drafted on)
 *   --paper-line       grid / dot lines printed on the pattern paper
 *   --pin              pin-head colour: selection, drag handles, "this one" markers
 *   --thread           seam / stitch colour for meaningful stitching (seams, sewn edges, progress)
 *   --thread-2         quiet stitch for decoration (stitched card borders, unselected seams)
 *   --cloth            the fabric laid on the mat in the cutting view (stays light in both modes)
 *   --kraft, --kraft-ink   kraft card stock for tags and labels, and its text
 *   --tape, --tape-ink     tape-measure yellow and its tick marks
 *   --grain            tiny paper-fibre noise texture (background-image layer)
 */
:root {
  --bg: #efe5d3;
  --surface: #fcf8f0;
  --surface-2: #f5eee2;
  --surface-3: #ebe1cf;
  --line: #e2d6c2;
  --line-strong: #cbbba0;
  --ink: #2b221b;
  --ink-2: #5c4f43;
  --ink-3: #6c5f53;
  --accent: #a64427;          /* terracotta thread */
  --accent-strong: #82341d;
  --accent-ink: #fffaf3;
  --accent-soft: #f5e0d2;
  --focus: #2f5bd3;
  --warn-bg: #fbe7a6;
  --warn-ink: #5b4206;
  --mat: #3d6a50;
  --mat-line: rgba(236, 246, 236, .13);
  --mat-line-strong: rgba(236, 246, 236, .34);
  --chalk: #f3efe1;
  --paper: #fffbf2;
  --paper-line: #eadfca;
  --pin: #c8344f;
  --thread: #2f6a8c;
  --thread-2: #cdb999;
  --cloth: #f1e8d6;
  --kraft: #dcc29a;
  --kraft-ink: #3b2a16;
  --tape: #ecd07e;
  --tape-ink: rgba(70, 50, 10, .55);
  --stage:
    radial-gradient(120% 75% at 50% 28%, #fdf8ef 0%, #f3eadb 52%, #e5d6bf 100%);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .26 0 0 0 0 .14 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --shadow-sm: 0 1px 2px rgba(60, 40, 15, .08), 0 1px 1px rgba(60, 40, 15, .05);
  --shadow: 0 10px 30px rgba(60, 40, 15, .14), 0 2px 6px rgba(60, 40, 15, .08);
  --radius: 14px;
  --radius-sm: 9px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: Fraunces, Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18130f; --surface: #221b16; --surface-2: #2a221b; --surface-3: #342a21; --line: #3a2f25; --line-strong: #54463a;
    --ink: #f2e8d9; --ink-2: #cdbda7; --ink-3: #a5937e; --accent: #e58b61; --accent-strong: #b8643e; --accent-ink: #26140a; --accent-soft: #42291c;
    --focus: #8fb0ff; --warn-bg: #4a3a12; --warn-ink: #f7de95;
    --mat: #23402f; --mat-line: rgba(214, 236, 214, .09); --mat-line-strong: rgba(214, 236, 214, .24); --chalk: #e8e2d0;
    --paper: #2b241d; --paper-line: #3d3329; --pin: #f0718a; --thread: #7fb6d6; --thread-2: #5a4b3c;
    --cloth: #e4d9c4; --kraft: #6d5337; --kraft-ink: #fbeedb; --tape: #a98a3c; --tape-ink: rgba(30, 20, 5, .6);
    --stage: radial-gradient(95% 70% at 50% 22%, #3d3024 0%, #271f18 55%, #17120e 100%);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.45); --shadow: 0 12px 34px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18130f; --surface: #221b16; --surface-2: #2a221b; --surface-3: #342a21; --line: #3a2f25; --line-strong: #54463a;
  --ink: #f2e8d9; --ink-2: #cdbda7; --ink-3: #a5937e; --accent: #e58b61; --accent-strong: #b8643e; --accent-ink: #26140a; --accent-soft: #42291c;
  --focus: #8fb0ff; --warn-bg: #4a3a12; --warn-ink: #f7de95;
  --mat: #23402f; --mat-line: rgba(214, 236, 214, .09); --mat-line-strong: rgba(214, 236, 214, .24); --chalk: #e8e2d0;
  --paper: #2b241d; --paper-line: #3d3329; --pin: #f0718a; --thread: #7fb6d6; --thread-2: #5a4b3c;
  --cloth: #e4d9c4; --kraft: #6d5337; --kraft-ink: #fbeedb; --tape: #a98a3c; --tape-ink: rgba(30, 20, 5, .6);
  --stage: radial-gradient(95% 70% at 50% 22%, #3d3024 0%, #271f18 55%, #17120e 100%);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.45); --shadow: 0 12px 34px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }

/* ---------- layout ---------- */
.app {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: 380px minmax(0, 1fr); grid-template-rows: 60px 1fr;
  grid-template-areas: "top top" "panel stage";
}
.topbar {
  grid-area: top; position: relative; display: flex; align-items: center; gap: 12px; padding: 0 10px 5px 16px;
  background: var(--grain), var(--surface); z-index: 5;
}
/* tape-measure strip along the bottom of the top bar */
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; pointer-events: none;
  background:
    repeating-linear-gradient(90deg, var(--tape-ink) 0 1px, transparent 1px 50px) 0 0 / 100% 6px no-repeat,
    repeating-linear-gradient(90deg, var(--tape-ink) 0 1px, transparent 1px 5px) 0 0 / 100% 3px no-repeat,
    var(--tape);
  box-shadow: 0 1px 0 rgba(60, 40, 10, .18);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; white-space: nowrap; }
/* a four-hole sewing button */
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background:
    radial-gradient(circle at 39% 39%, var(--surface) 0 1.9px, transparent 2.4px),
    radial-gradient(circle at 61% 39%, var(--surface) 0 1.9px, transparent 2.4px),
    radial-gradient(circle at 39% 61%, var(--surface) 0 1.9px, transparent 2.4px),
    radial-gradient(circle at 61% 61%, var(--surface) 0 1.9px, transparent 2.4px),
    radial-gradient(circle, transparent 0 9px, rgba(0,0,0,.14) 9.5px 10.2px, transparent 10.7px),
    radial-gradient(circle at 35% 30%, #d77b55, var(--accent) 70%);
  box-shadow: inset 0 -1.5px 0 rgba(0,0,0,.18), var(--shadow-sm);
}
.brand-text { font-family: var(--font-display); font-size: 19px; letter-spacing: -.01em; }
.brand-text b { font-weight: 600; }
.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 2px 7px; border-radius: 4px;
  background: var(--kraft); color: var(--kraft-ink); font-weight: 600;
}

/* workspace stepper: numbered steps joined by a stitched thread */
.modes { display: flex; align-items: center; margin: 0 auto; counter-reset: step; }
.mode {
  counter-increment: step; position: relative; flex: none;
  display: flex; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer;
  padding: 4px 10px 4px 4px; border-radius: 999px; color: var(--ink-2); font-weight: 500;
  transition: background .15s, color .15s;
}
.mode + .mode { margin-left: 14px; }
.mode + .mode::before {
  content: ''; position: absolute; left: -14px; width: 14px; top: 50%; margin-top: -1px;
  border-top: 2px dashed var(--line-strong);
}
.mode .mi {
  position: relative; display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--line-strong); color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.mode .mi svg { width: 15px; height: 15px; }
.mode .mi::after {
  content: counter(step); position: absolute; right: -6px; bottom: -5px; width: 17px; height: 17px;
  border-radius: 50%; background: var(--surface-3); color: var(--ink); border: 1.5px solid var(--surface);
  font: 700 10px/14px var(--font); text-align: center; box-sizing: border-box;
}
.mode:hover { color: var(--ink); background: var(--surface-2); }
.mode:hover .mi { border-color: var(--ink-3); }
/* steps before the current one: thread-coloured, stitched line solid in thread */
.mode:has(~ .mode.active) .mi { border-color: var(--thread); color: var(--thread); }
.mode:has(~ .mode.active)::before, .mode.active::before { border-top-color: var(--thread); }
.mode.active { color: var(--ink); font-weight: 600; background: var(--accent-soft); }
.mode.active .mi { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 0 var(--accent-strong); }
.mode.active .mi::after { background: var(--ink); color: var(--surface); }
.actions { display: flex; align-items: center; gap: 2px; }

.panel {
  grid-area: panel; display: flex; flex-direction: column; min-height: 0;
  background: var(--grain), var(--surface); border-right: 1px solid var(--line); z-index: 4;
}
.sheet-handle { display: none; }
.page { display: none; padding: 18px 18px 24px; overflow-y: auto; flex: 1; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.page.active { display: block; }
/* page titles: a kraft luggage tag */
.page-head h2 {
  position: relative; display: inline-block; margin: 0 0 6px -4px; padding: 3px 16px 4px 24px;
  font-family: var(--font-display); font-weight: 600; font-size: 21px; letter-spacing: -.005em; line-height: 1.25;
  background: var(--grain), var(--kraft); color: var(--kraft-ink);
  clip-path: polygon(11px 0, 100% 0, 100% 100%, 11px 100%, 0 50%);
  border-radius: 0 4px 4px 0; transform: rotate(-1deg);
}
.page-head h2::before {   /* the tag's eyelet */
  content: ''; position: absolute; left: 9px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%;
  background: var(--surface); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--kraft-ink) 35%, transparent);
}
.page-head p { margin: 2px 0 14px; }
.panel-foot { padding: 10px 18px 12px; border-top: 1px dashed var(--line-strong); font-size: 11px; color: var(--ink-3); }
.panel-foot a { color: var(--ink-2); }
.stage { grid-area: stage; position: relative; background: var(--stage); min-width: 0; min-height: 0; overflow: hidden; }
.stage::before {   /* faint paper-sweep texture over the studio backdrop */
  content: ''; position: absolute; inset: 0; background: var(--grain); opacity: .6; pointer-events: none;
}
#three { position: relative; width: 100%; height: 100%; display: block; touch-action: none; }
.no-webgl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--ink-2); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 500; white-space: nowrap;
  box-shadow: 0 1.5px 0 var(--line-strong);
  transition: background .15s, border-color .15s, transform .05s, box-shadow .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); box-shadow: 0 .5px 0 var(--line-strong); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent-strong); box-shadow: 0 2px 0 var(--accent-strong); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.primary:active { box-shadow: 0 1px 0 var(--accent-strong); }
.btn.ghost { border-color: transparent; background: none; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 999px; cursor: pointer;
  border: 0; background: none; color: var(--ink-2); font-size: 17px;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.toolrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.search {
  flex: 1; min-width: 140px; padding: 7px 12px 7px 34px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface-2) no-repeat 12px 50% / 15px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23927e68' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m15.5 15.5 5 5'/%3E%3C/svg%3E");
  box-shadow: inset 0 1px 2px rgba(60, 40, 15, .07);
}
.seg { display: inline-flex; background: var(--surface-3); border-radius: 999px; padding: 3px; box-shadow: inset 0 1px 2px rgba(60, 40, 15, .08); }
.seg-btn { border: 0; background: none; padding: 4px 11px; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-weight: 500; font-size: 13px; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line-strong), var(--shadow-sm); font-weight: 600; }
.field { display: block; margin: 10px 0; }
.field > span { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field > span b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.field.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { margin: 0; white-space: nowrap; }
select, input[type=number], input[type=text], .dialog input {
  width: 100%; padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background-color: var(--surface-2); box-shadow: inset 0 1px 2px rgba(60, 40, 15, .07);
}
.dialog input.search { padding-left: 34px; border-radius: 999px; background-color: var(--surface-2); }
select:hover, input[type=number]:hover, input[type=text]:hover { border-color: var(--ink-3); }
.check { display: flex; align-items: flex-start; gap: 9px; margin: 10px 0; font-size: 13px; color: var(--ink-2); }
.check input { margin-top: 2px; accent-color: var(--accent); }
.note { font-size: 12px; color: var(--ink-3); margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* sliders: a tape-measure track with a pin-head thumb */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track {
  height: 7px; border-radius: 2px; border: 1px solid color-mix(in srgb, var(--tape-ink) 60%, transparent);
  background: repeating-linear-gradient(90deg, var(--tape-ink) 0 1px, transparent 1px 6px) 0 0 / 100% 3px no-repeat, var(--tape);
}
input[type=range]::-moz-range-track {
  height: 7px; border-radius: 2px; border: 1px solid color-mix(in srgb, var(--tape-ink) 60%, transparent);
  background: repeating-linear-gradient(90deg, var(--tape-ink) 0 1px, transparent 1px 6px) 0 0 / 100% 3px no-repeat, var(--tape);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin-top: -6.5px; border-radius: 50%;
  border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(40, 20, 10, .35);
  background: radial-gradient(circle at 35% 32%, rgba(255,255,255,.7) 0 2px, transparent 3px), var(--pin);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(40, 20, 10, .35);
  background: radial-gradient(circle at 35% 32%, rgba(255,255,255,.7) 0 2px, transparent 3px), var(--pin);
}
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.1); }
input[type=range]:focus-visible { outline-offset: 0; border-radius: 4px; }

/* stitched card: a dashed seam just inside the edge */
.group, .current-design, .grain-box, .stat, .fs-note, .tpl, .fab, .gcard, .save {
  outline: 1.25px dashed var(--thread-2); outline-offset: -5px;
}
.group .group { outline: 0; }

/* parameter groups */
.params { display: flex; flex-direction: column; gap: 10px; }
.group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.group > summary {
  list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; border-radius: var(--radius);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: ''; margin-left: auto; width: 7px; height: 7px; border-right: 1.5px solid var(--ink-3); border-bottom: 1.5px solid var(--ink-3); transform: rotate(45deg); transition: transform .15s; }
.group[open] > summary::after { transform: rotate(-135deg); }
.group > summary:hover { color: var(--accent); }
.group > .gbody { padding: 0 16px 12px; }
.group .group { background: var(--surface-2); margin: 6px 0; box-shadow: none; }
.group.dim { opacity: .6; }
.group-sep, .recent-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 10px 2px 2px;
}
.group-sep::after, .recent-head::after { content: ''; flex: 1; border-top: 1.5px dashed var(--line-strong); }
.prow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 8px 0; border-top: 1px dashed var(--line); }
.gbody > .prow:first-child { border-top: 0; }
.prow .pname { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 4px; min-width: 0; }
.prow .pname small { color: var(--ink-3); font-size: 11px; }
.prow .pval { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.prow .pctl { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.prow .pctl > :first-child { flex: 1; min-width: 0; }
.help { display: block; font-size: 11.5px; color: var(--ink-3); grid-column: 1 / -1; margin-top: -2px; }
.lock { border: 0; background: none; cursor: pointer; color: var(--ink-3); font-size: 11px; padding: 2px 5px; border-radius: 6px; opacity: .55; }
.prow:hover .lock, .lock.on { opacity: 1; }
.lock.on { color: var(--accent); background: var(--accent-soft); }
.switch { position: relative; width: 36px; height: 20px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background .15s; pointer-events: none; box-shadow: inset 0 1px 2px rgba(0,0,0,.12); }
.switch i::after { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: #fffdf8; transition: transform .15s; box-shadow: var(--shadow-sm); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { width: 78px !important; flex: none !important; text-align: right; padding: 4px 8px !important; font-variant-numeric: tabular-nums; }

/* design picker: current design + recent row */
.current-design {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 10px 12px;
  padding: 12px 14px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.cd-thumb {
  width: 64px; height: 64px; border-radius: var(--radius-sm); display: grid; place-items: center; color: var(--ink-2);
  background: linear-gradient(var(--paper-line) 1px, transparent 1px) 0 0 / 8px 8px, linear-gradient(90deg, var(--paper-line) 1px, transparent 1px) 0 0 / 8px 8px, var(--paper);
  border: 1px solid var(--line);
}
.cd-thumb svg { width: 56px; height: 56px; }
.cd-kicker { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cd-name { font-family: var(--font-display); font-weight: 600; font-size: 19px; line-height: 1.2; margin: 1px 0 2px; overflow: hidden; text-overflow: ellipsis; }
.cd-browse { grid-column: 1 / -1; width: 100%; justify-content: center; }
.cd-desc { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.recent-head { margin: 4px 0 8px; }
.templates { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 10px; margin: 0 -2px 4px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.tpl {
  position: relative; flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 86px; padding: 9px 6px 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); cursor: pointer; font-size: 11.5px; text-align: center; line-height: 1.2;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tpl:hover { border-color: var(--line-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.tpl.active { border-color: var(--accent); background: var(--accent-soft); outline-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.tpl svg { width: 44px; height: 54px; color: var(--ink-2); }
.tpl.more { justify-content: center; color: var(--ink-2); font-weight: 500; }
.tpl.more b { font-size: 20px; font-weight: 400; line-height: 1; }
/* a pin stuck through the chosen card */
.tpl.active::after, .gcard.active::after, .fab.active::after {
  content: ''; position: absolute; top: -4px; left: 50%; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; z-index: 1;
  background: radial-gradient(circle at 35% 32%, rgba(255,255,255,.75) 0 1.5px, transparent 2.5px), var(--pin);
  box-shadow: 0 1.5px 2px rgba(40, 10, 10, .35);
}
.pill { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; text-transform: none; vertical-align: 1px; }
.pill.drape { background: var(--accent-soft); color: var(--accent); }
:root[data-theme="dark"] .pill.drape { color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.drape { color: var(--ink); } }
.pill.flat { background: var(--surface-3); color: var(--ink-2); }

/* design gallery */
.dialog.gallery { width: min(1040px, calc(100vw - 24px)); height: min(820px, calc(100dvh - 40px)); }
.dialog.gallery[open] { display: flex; flex-direction: column; }
.gal-tools { padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px dashed var(--line-strong); }
.gal-tools .search { width: 100%; }
.gal-kinds { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
.gal-kinds::-webkit-scrollbar { display: none; }
.gal-kinds .chip small { opacity: .7; margin-left: 4px; font-weight: 400; }
.gal-filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.gal-check { flex: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.gal-check input { accent-color: var(--accent); }
.gal-count { margin-left: auto; }
.gal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 16px 18px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.gal-sec { margin-top: 14px; }
.gal-sec h4 { margin: 0 0 10px; font-family: var(--font-display); font-weight: 600; font-size: 17px; display: flex; align-items: baseline; gap: 8px; }
.gal-sec h4::after { content: ''; flex: 1; align-self: center; border-top: 1.5px dashed var(--line-strong); }
.gal-sec h4 small { font-family: var(--font); font-size: 12px; color: var(--ink-3); font-weight: 400; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.gcard {
  position: relative; display: flex; flex-direction: column; text-align: left; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); color: inherit; transition: border-color .12s, transform .12s, box-shadow .12s;
}
.gcard:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.gcard.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); outline-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.gcard .gthumb {
  position: relative; aspect-ratio: 4 / 3; display: grid; place-items: center; color: var(--ink-2);
  border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px dashed var(--line);
  --pl: color-mix(in srgb, var(--paper-line) 70%, var(--paper));
  background: linear-gradient(var(--pl) 1px, transparent 1px) 0 0 / 12px 12px, linear-gradient(90deg, var(--pl) 1px, transparent 1px) 0 0 / 12px 12px, var(--paper);
}
.gcard .gthumb svg { width: 64%; height: 82%; }
.gcard .gthumb .pill { position: absolute; top: 9px; right: 9px; }
.gcard .gtext { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gcard .gname { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.gcard .gby { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gcard .gdesc { font-size: 12px; color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.diff { letter-spacing: 1px; color: var(--accent); font-size: 9px; }
.diff i { font-style: normal; color: var(--line-strong); }
.gal-empty { padding: 40px 10px; text-align: center; color: var(--ink-3); }
.gal-foot { padding: 8px 16px; border-top: 1px dashed var(--line-strong); }
.thumb-path { fill: currentColor; fill-opacity: .14; stroke: currentColor; stroke-width: 1.3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
@media (max-width: 820px) {
  .dialog.gallery { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; border: 0; }
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .gcard .gdesc { display: none; }
  .gal-foot { display: none; }
  .cd-thumb { width: 52px; height: 52px; }
  .cd-thumb svg { width: 46px; height: 46px; }
}
.fs-note { font-size: 12.5px; line-height: 1.45; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.fs-note a { color: inherit; }

/* fabric */
.fabric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-bottom: 8px; }
.fab {
  position: relative; text-align: left; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); cursor: pointer;
  background: repeating-linear-gradient(45deg, rgba(120, 90, 50, .035) 0 2px, transparent 2px 4px), var(--surface-2);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.fab:hover { border-color: var(--line-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.fab b { display: block; font-size: 13px; }
.fab span { font-size: 11px; color: var(--ink-3); }
.fab.active { border-color: var(--accent); background: var(--accent-soft); outline-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.fab.active span { color: var(--ink-2); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong), 0 1px 2px rgba(0,0,0,.15); cursor: pointer; padding: 0; transition: transform .1s; }
.sw:hover { transform: scale(1.08); }
.sw.active { box-shadow: 0 0 0 2px var(--accent), 0 1px 3px rgba(0,0,0,.2); }
.sw-custom { width: 30px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }
.adv { margin-top: 12px; border-top: 1px dashed var(--line-strong); padding-top: 8px; }
.adv > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.adv > summary:hover { color: var(--accent); }

/* cutting */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 4px; }
.stat { background: var(--grain), var(--kraft); color: var(--kraft-ink); border-radius: var(--radius-sm); padding: 10px 11px; outline-color: color-mix(in srgb, var(--kraft-ink) 30%, transparent); outline-offset: -4px; }
.stat b { display: block; font-size: 18px; font-family: var(--font-display); font-weight: 600; }
.stat span { font-size: 11px; color: var(--kraft-ink); opacity: .85; }
.steps { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--ink-2); }
.steps li { margin: 5px 0; }
.steps li::marker { color: var(--accent); font-weight: 600; }
/* the cutting layout lies on a green self-healing cutting mat */
.layout-view {
  position: absolute; inset: 0; overflow: auto; padding: 64px 24px 80px;
  background:
    linear-gradient(var(--mat-line-strong) 1px, transparent 1px) -1px -1px / 100px 100px,
    linear-gradient(90deg, var(--mat-line-strong) 1px, transparent 1px) -1px -1px / 100px 100px,
    linear-gradient(var(--mat-line) 1px, transparent 1px) -1px -1px / 10px 10px,
    linear-gradient(90deg, var(--mat-line) 1px, transparent 1px) -1px -1px / 10px 10px,
    radial-gradient(120% 90% at 50% 30%, transparent 40%, rgba(0, 0, 0, .18)),
    var(--mat);
  background-attachment: local;
  scrollbar-color: var(--mat-line-strong) transparent;
}
.layout-view > p { color: var(--chalk) !important; }
.layout-view svg { display: block; margin: 0 auto; background: none; touch-action: none; overflow: visible; }
.layout-view .fabric > path[d$="Z"] { fill: var(--cloth); filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .25)); }
.layout-view svg > text,
.layout-view .fabric > text[transform],
.layout-view .fabric > text[text-anchor="start"] { fill: var(--chalk); }
.layout-view .fabric > path[stroke="#9c8f7c"]:not([d$="Z"]) { stroke: var(--chalk); }
.draft-view { position: absolute; inset: 0; }
.layout-view .piece { cursor: grab; }
.layout-view .piece .cut { fill: rgba(255, 252, 244, .72); }
.layout-view .piece.overlap .cut { stroke: #d33; fill: rgba(220, 50, 50, .16); }
.layout-view .piece:hover .cut { fill: rgba(240, 214, 196, .85); }
.layout-view .piece.on-fold { cursor: ns-resize; }
.layout-view .fabric { pointer-events: none; }
.cutlist { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13px; }
.cutlist li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.cutlist li span { color: var(--ink-2); text-align: right; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
#fold-seg { margin-top: 2px; }

/* stage overlays */
.viewbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px;
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-sm), 0 2px 0 var(--line); z-index: 2; max-width: calc(100% - 24px); overflow-x: auto;
}
.chip { border: 0; background: none; padding: 6px 12px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip.on { background: var(--ink); color: var(--surface); }
.chip:disabled { opacity: .4; }
.status {
  position: absolute; left: 14px; bottom: 14px; display: flex; align-items: center; gap: 8px; z-index: 2;
  background: var(--grain), var(--surface); padding: 7px 14px 7px 12px; border-radius: 999px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--line); outline: 1.25px dashed var(--thread-2); outline-offset: -4px; font-size: 12.5px; color: var(--ink-2);
  max-width: calc(100% - 28px);
}
.status.idle .spinner { display: none; }
.status.idle::before {   /* a small spool of thread when idle */
  content: ''; width: 10px; height: 12px; flex: none; border-radius: 2px;
  background: linear-gradient(var(--ink-3) 0 2px, transparent 2px calc(100% - 2px), var(--ink-3) calc(100% - 2px)),
              repeating-linear-gradient(var(--accent) 0 1px, color-mix(in srgb, var(--accent) 70%, #fff) 1px 2px) 1.5px 2px / 7px 8px no-repeat;
}
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.sim-bar { position: absolute; left: 0; right: 0; top: 0; height: 3px; z-index: 3; }
.sim-bar > div {
  height: 100%; width: 0; transition: width .15s linear;
  background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 9px);
}
.legend {
  position: absolute; right: 14px; bottom: 14px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2);
  background: var(--surface); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); box-shadow: var(--shadow-sm); z-index: 2;
}
.legend .bar { width: 110px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #4c7bd9, #4fae7a 45%, #f0c34a 70%, #e0503c); }
.toast {
  position: absolute; left: 50%; transform: translateX(-50%); top: 64px; max-width: min(520px, calc(100% - 28px));
  background: var(--ink); color: var(--surface); padding: 9px 14px; border-radius: var(--radius); font-size: 13px; box-shadow: var(--shadow); z-index: 6;
}
/* warnings: a sticky note */
.warn-chip {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 60px; z-index: 6;
  display: flex; align-items: flex-start; max-width: min(520px, calc(100% - 28px));
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 4px 4px 10px 4px; box-shadow: var(--shadow); font-size: 12.5px;
}
.warn-chip::before {   /* a strip of tape holding the note */
  content: ''; position: absolute; top: -7px; left: 18px; width: 38px; height: 13px; transform: rotate(-4deg); pointer-events: none;
  background: color-mix(in srgb, var(--surface) 65%, transparent); box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.warn-chip[hidden] { display: none; }
.warn-chip.open { width: min(520px, calc(100% - 28px)); }
.warn-text {
  all: unset; cursor: pointer; padding: 8px 4px 8px 12px; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.warn-text::before { content: "⚠ "; }
.warn-chip.open .warn-text { white-space: normal; }
.warn-x { all: unset; cursor: pointer; padding: 8px 11px 8px 6px; opacity: .7; flex: none; }
.warn-x:hover, .warn-text:focus-visible, .warn-x:focus-visible { opacity: 1; outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 4px; }
/* 2D pattern: always light pattern paper, since GarmentCode draws it in dark ink */
.pattern-card {
  position: absolute; right: 14px; top: 64px; bottom: 60px; width: min(460px, calc(100% - 28px));
  background: linear-gradient(#ece2cf 1px, transparent 1px) 0 0 / 20px 20px, linear-gradient(90deg, #ece2cf 1px, transparent 1px) 0 0 / 20px 20px, #fffbf2;
  color: #2b221b; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; z-index: 3;
  border: 1px solid #e2d6c2;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px 10px 18px; border-bottom: 1px dashed var(--line-strong); }
.card-head h3 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 20px; }
.pattern-card .card-head { border-color: #cbbba0; background: #f5eee2; }
.pattern-card .card-head b { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.pattern-card .icon-btn { color: #5c4f43; }
.pattern-card .icon-btn:hover { background: #ebe1cf; color: #2b221b; }
.pattern-svg { overflow: auto; padding: 10px; flex: 1; }
.pattern-svg svg { width: 100%; height: auto; display: block; }

/* menus & dialogs */
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 270px; max-height: calc(100dvh - 80px); overflow-y: auto;
  background: var(--grain), var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 20;
}
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.menu-pop button:hover { background: var(--accent-soft); }
.menu-label { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 8px 10px 3px; }
.menu-label::after { content: ''; flex: 1; border-top: 1.5px dashed var(--line); }
.show-sm { display: none !important; }
.dialog {
  position: relative; border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--grain), var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); box-shadow: var(--shadow);
  outline: 1.25px dashed var(--thread-2); outline-offset: -6px;
}
.dialog:focus-visible { outline: 2px solid var(--focus); }
.dialog::backdrop { background: rgba(40, 25, 10, .38); backdrop-filter: blur(2px); }
.dialog .card-head { padding: 14px 14px 12px 20px; }
.dialog .toolrow { padding: 14px 16px 0; }
.about { padding: 6px 22px 18px; }
.about li { margin: 6px 0; }
.about li::marker { color: var(--accent); }
.saves { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 16px; }
.save { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); display: flex; flex-direction: column; }
.save img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: var(--stage); cursor: pointer; display: block; }
.save .meta { padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; }
.save .meta small { display: block; color: var(--ink-3); font-size: 11px; }
.empty { color: var(--ink-3); padding: 18px; text-align: center; grid-column: 1 / -1; }

/* ---------- medium widths: keep the top bar on one line ---------- */
@media (max-width: 1290px) and (min-width: 821px) {
  .brand-text { display: none; }
}
@media (max-width: 1120px) and (min-width: 821px) {
  .mode:not(.active) > span:last-child { display: none; }
  .mode:not(.active) { padding-right: 4px; }
}
@media (max-width: 960px) and (min-width: 821px) {
  .badge { display: none; }   /* the disclaimer stays in the panel footer and About */
}

/* ---------- small screens: bottom sheet ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "stage" "panel"; }
  .topbar, .panel, .stage { min-width: 0; }
  .topbar { flex-wrap: wrap; gap: 4px 4px; padding: 6px 6px 10px 12px; }
  .brand-text { font-size: 16px; }
  .brand-mark { width: 24px; height: 24px; }
  .badge { display: none; }
  .actions { margin-left: auto; }
  /* stepper: icon bubble over a short label, thread runs between the bubbles */
  .modes { order: 3; width: 100%; min-width: 0; margin: 0; }
  .mode { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 4px 2px 5px; border-radius: 12px; font-size: 11.5px; line-height: 1.2; }
  .mode > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mode + .mode { margin-left: 0; }
  .mode + .mode::before { left: calc(-50% + 19px); width: calc(100% - 38px); top: 18px; margin-top: 0; }
  .mode.active { background: var(--accent-soft); }
  .hide-sm { display: none !important; }
  .show-sm { display: block !important; }
  #btn-theme, #btn-redo { display: none; }
  .actions .btn.primary { padding: 6px 12px; }
  .panel {
    height: var(--sheet-h, 46dvh); border-right: 0; border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0; margin-top: -18px; box-shadow: 0 -8px 24px rgba(40, 25, 10, .14);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet-handle { display: flex; justify-content: center; padding: 8px 0 4px; cursor: ns-resize; touch-action: none; flex: none; }
  .sheet-handle span { width: 44px; height: 5px; border-radius: 3px; background: var(--line-strong); }
  .page { padding: 4px 16px 20px; }
  .page-head h2 { font-size: 18px; }
  .page-head p { display: none; }
  .panel-foot { display: none; }
  .viewbar { top: 8px; left: 8px; right: 8px; transform: none; max-width: none; justify-content: flex-start; }
  .chip { padding: 6px 10px; }
  .status { bottom: 26px; left: 10px; }
  .legend { bottom: 26px; right: 10px; }
  .warn-chip { bottom: auto; top: 54px; }
  .pattern-card { top: 56px; bottom: 26px; right: 8px; left: 8px; width: auto; }
  .menu-pop { position: fixed; left: 8px; right: 8px; top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); min-width: 0; max-height: 70dvh; }
  .menu-pop button { padding: 12px; }
  .layout-view { padding: 56px 10px 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* fabric grain */
.grain-box { margin: 12px 0; padding: 6px 14px 4px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.grain-box .field { margin: 6px 0; }
.grain-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; margin-top: 8px; }
.grain-ico { width: 22px; height: 22px; color: var(--ink-2); }
.grain-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 10px; flex-wrap: wrap; }
.grain-row > span { font-size: 13px; color: var(--ink-2); }
.cutlist select.grain-sel { font-size: 12px; padding: 1px 4px; margin-left: 6px; }
