/* ===== Beadify · production stylesheet ===== */
*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}
/* the hidden attribute must always win: author display rules (.img-preview/.btn/
   .hover-tip use display:flex) override the UA [hidden] style, which made
   imgPreview/hoverTip/esRestore/galleryMore/saveResult ignore .hidden toggling */
[hidden]{display:none!important}
html,body{height:100%;overflow:hidden}
:root{
  /* dark color-scheme: native select popups / checkboxes / autofill follow
     the theme instead of flashing white; Firefox thin scrollbars below
     complement the -webkit-scrollbar trio further down */
  color-scheme:dark;
  scrollbar-width:thin;
  scrollbar-color:var(--border) var(--bg-deep);
  --bg:#1a1614; --bg-elev:#221d1a; --bg-card:#2a2420; --bg-deep:#131110;
  --surface:#332c27; --border:#3d342e; --border-strong:#524538;
  --text:#f0e9e0; --text-dim:#a99c8f; --text-mute:#9c897b;
  /* secondary text for SELECTED states only: --text-dim/-mute drop below AA 4.5:1
     on the accent-soft composite bg, these clear it (math pinned in test/contrast.test.js) */
  --text-dim-strong:#b5a89b; --text-mute-strong:#b4a396;
  --accent:#f5a623; --accent-deep:#d4881a; --accent-soft:rgba(245,166,35,.14);
  --danger:#e8554e; --ok:#5eb887;
  --radius:10px; --radius-sm:6px; --radius-lg:16px;
  --shadow:0 8px 30px rgba(0,0,0,.45);
  --font-display:'Fraunces',Georgia,serif;
  --font-body:'Spline Sans',system-ui,sans-serif;
  --mono:ui-monospace,'SF Mono',monospace;
  --ease:cubic-bezier(.4,0,.2,1);
}
body{font-family:var(--font-body);background:var(--bg);color:var(--text);font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;display:flex;flex-direction:column}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
input,select{font-family:inherit;color:inherit}
/* touch: kill the double-tap-zoom tap delay (mobile browsers otherwise wait
   ~300ms for a possible second tap before firing click) and the gray system
   tap flash — our own :active states below give the immediate feedback */
button,select,input,[role=button]{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
canvas{display:block}
::-webkit-scrollbar{width:10px;height:10px}
::-webkit-scrollbar-track{background:var(--bg-deep)}
::-webkit-scrollbar-thumb{background:var(--border);border-radius:5px}
::-webkit-scrollbar-thumb:hover{background:var(--border-strong)}
/* focus ring only — no border-radius side effect: a radius on the global
   :focus-visible reshaped EVERY focused element to 3px for the duration of
   focus (a 6px-rounded button visibly snapped corners while tabbing). The
   outline follows each element's own border-radius on its own. */
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
kbd{font-family:var(--mono);font-size:10px;padding:1px 5px;border-radius:4px;background:var(--bg-deep);border:1px solid var(--border);color:var(--text-dim)}
/* visually hidden but screen-reader available (clip pattern — keeps the text
   in the a11y tree and in tab/reading order without a layout box) */
.sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;
  clip:rect(0,0,0,0);white-space:nowrap;border:0}

/* No-JS banner (body noscript in index.html): must render with JS off, so
   pure CSS on a plain div — no dependency on any script-injected class */
.noscript-banner{padding:10px 16px;background:var(--accent-soft);border-bottom:1px solid rgba(245,166,35,.4);
  color:var(--accent);font-size:13px;font-weight:600;text-align:center;line-height:1.5}

/* ===== Shell ===== */
.shell{flex:1;display:flex;flex-direction:column;min-height:0;
  background:radial-gradient(ellipse 80% 60% at 20% 0%,rgba(245,166,35,.06),transparent 60%),
  radial-gradient(ellipse 70% 50% at 90% 100%,rgba(94,184,135,.04),transparent 60%),var(--bg)}
.topbar{display:flex;align-items:center;gap:16px;padding:0 20px;height:56px;flex-shrink:0;
  background:rgba(19,17,16,.7);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-bottom:1px solid var(--border);z-index:20}
.logo{display:flex;align-items:center;gap:10px}
.logo-mark{width:30px;height:30px;border-radius:7px;background:linear-gradient(135deg,var(--accent),var(--accent-deep));
  display:grid;place-items:center;box-shadow:0 4px 14px rgba(245,166,35,.3);position:relative}
.logo-mark::before{content:'';width:14px;height:14px;border-radius:50%;background:var(--bg-deep);box-shadow:inset 0 2px 4px rgba(0,0,0,.4)}
.logo-text{font-family:var(--font-display);font-weight:900;font-size:20px;letter-spacing:-.5px}
/* logo suffix accent (index.html: <span class="logo-accent">, NOT <em> — the
   coloring is branding, not emphasis; font-style:normal cancel dropped along
   with the <em>) */
.logo-text .logo-accent{color:var(--accent);font-weight:500}
.topbar-spacer{flex:1}
.topbar-meta{font-size:12px;color:var(--text-mute);display:flex;align-items:center;gap:8px}
.topbar-dot{width:6px;height:6px;border-radius:50%;background:var(--ok);box-shadow:0 0 8px var(--ok)}
/* beginner mode */
.beginner-mode .adv{display:none}
.beginner-toggle{display:flex;align-items:center;gap:8px;background:transparent;border:1px solid var(--border);
  border-radius:20px;padding:6px 12px;cursor:pointer;transition:border-color .15s;margin-right:12px}
.beginner-toggle:hover{border-color:var(--border-strong)}
.beginner-toggle-label{font-size:12px;color:var(--text-dim);font-weight:600}
.beginner-toggle.on .beginner-toggle-label{color:var(--accent)}
.beginner-toggle-track{width:30px;height:17px;border-radius:9px;background:var(--bg-deep);border:1px solid var(--border);position:relative;transition:background .15s;flex-shrink:0}
.beginner-toggle-knob{position:absolute;top:1.5px;left:2px;width:12px;height:12px;border-radius:50%;background:var(--text-mute);transition:left .15s,background-color .15s}
.beginner-toggle.on .beginner-toggle-track{background:var(--accent-soft);border-color:var(--accent)}
.beginner-toggle.on .beginner-toggle-knob{left:15px;background:var(--accent)}
.workspace{flex:1;display:flex;min-height:0}

/* ===== Sidebar ===== */
.sidebar{width:300px;flex-shrink:0;background:var(--bg-elev);border-right:1px solid var(--border);
  overflow-y:auto;padding:18px 16px 24px;display:flex;flex-direction:column;gap:18px}
.panel-group{display:flex;flex-direction:column;gap:10px}
.panel-label{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:1.4px;color:var(--text-mute);
  display:flex;align-items:center;justify-content:space-between}
.panel-label .val{font-family:var(--mono);font-weight:600;color:var(--accent);text-transform:none;letter-spacing:0;font-size:13px}

/* Dropzone */
.dropzone{border:2px dashed var(--border-strong);border-radius:var(--radius);padding:24px 16px;text-align:center;
  transition:border-color .25s var(--ease),background .25s var(--ease),transform .25s var(--ease);cursor:pointer;position:relative;overflow:hidden}
.dropzone:hover{border-color:var(--accent);background:var(--accent-soft)}
.dropzone.dragover{border-color:var(--accent);background:var(--accent-soft);transform:scale(1.01)}
.dropzone-icon{width:40px;height:40px;margin:0 auto 10px;border-radius:50%;background:var(--surface);
  display:grid;place-items:center;color:var(--accent)}
.dropzone-title{font-weight:600;font-size:13px;margin-bottom:3px}
.dropzone-sub{font-size:11px;color:var(--text-mute)}

/* Image preview */
.img-preview{display:flex;align-items:center;gap:10px;padding:8px;background:var(--bg-card);
  border:1px solid var(--border);border-radius:var(--radius-sm)}
.img-thumb-wrap{width:44px;height:44px;border-radius:6px;overflow:hidden;flex-shrink:0;
  background:var(--bg-deep);border:1px solid var(--border)}
.img-thumb-wrap img{width:100%;height:100%;object-fit:cover}
.img-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.img-name{font-size:12px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.img-dims{font-size:10.5px;color:var(--text-mute);font-family:var(--mono)}
.img-remove{width:26px;height:26px;flex-shrink:0;border-radius:6px;display:grid;place-items:center;
  color:var(--text-mute);transition:color .15s,background-color .15s}
.img-remove:hover{color:var(--danger);background:rgba(232,85,78,.12)}

/* Mode cards */
.mode-grid{display:flex;flex-direction:column;gap:7px}

/* MARD tier selector */
.tier-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:5px}
.tier-btn{padding:6px 0;border-radius:5px;background:var(--bg-card);border:1px solid var(--border);font-size:11px;font-weight:600;color:var(--text-dim);transition:border-color .15s,color .15s,background-color .15s;font-family:var(--mono)}
.tier-btn:hover{border-color:var(--border-strong);color:var(--text)}
.tier-btn.active{background:var(--accent-soft);border-color:var(--accent);color:var(--accent)}
.mode-card{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:var(--radius-sm);
  background:var(--bg-card);border:1px solid var(--border);cursor:pointer;transition:border-color .2s var(--ease),background-color .2s var(--ease),box-shadow .2s var(--ease);position:relative}
.mode-card:hover{border-color:var(--border-strong)}
.mode-card.active{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 1px var(--accent) inset}
.mode-icon{width:28px;height:28px;flex-shrink:0;border-radius:6px;display:grid;place-items:center;font-size:14px}
.mode-icon.perfect{background:linear-gradient(135deg,#f5a623,#d4470a)}
.mode-icon.medium{background:linear-gradient(135deg,#5eb887,#3a8a5e)}
.mode-icon.basic{background:linear-gradient(135deg,#6b9fd6,#3d6ea8)}
.mode-info{flex:1;min-width:0}
.mode-name{font-weight:600;font-size:13px;line-height:1.2}
.mode-desc{font-size:10.5px;color:var(--text-dim);margin-top:2px;line-height:1.3}
.mode-check{width:16px;height:16px;flex-shrink:0;border-radius:50%;border:2px solid var(--border-strong);transition:border-color .2s,background-color .2s,box-shadow .2s}
.mode-card.active .mode-check{border-color:var(--accent);background:var(--accent);box-shadow:inset 0 0 0 3px var(--bg-elev)}
.mode-card.active .mode-desc{color:var(--text-dim-strong)}

/* Sliders */
.slider-row{display:flex;flex-direction:column;gap:8px}
input[type=range]{-webkit-appearance:none;width:100%;height:4px;background:var(--border);border-radius:2px;outline:none}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:16px;height:16px;border-radius:50%;
  background:var(--accent);cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.4);border:2px solid var(--bg-elev);transition:transform .12s}
input[type=range]::-webkit-slider-thumb:hover{transform:scale(1.15)}
input[type=range]::-moz-range-thumb{width:14px;height:14px;border-radius:50%;background:var(--accent);cursor:pointer;border:2px solid var(--bg-elev)}
/* 2.4.7: the input[type=range] reset above sets outline:none at (0,1,1), which
   beats the global :focus-visible at (0,1,0) — restore the keyboard focus ring */
input[type=range]:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
/* same class of fix for the four text-like controls (`.text-input`,
   `.conv-select`, `.cmp-select`/`.cmp-filter`, `.stk-input`): each reset sets
   outline:none at (0,1,0) and later source order, silently beating the
   global :focus-visible — keyboard focus fell back to a 1px border-color
   change, below this project's own ring standard. No border-radius here
   either — each control keeps its own corners while focused. */
.text-input:focus-visible,.conv-select:focus-visible,.cmp-select:focus-visible,.cmp-filter:focus-visible,.stk-input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.slider-presets{display:flex;gap:5px}
.slider-presets button{flex:1;padding:4px 0;border-radius:5px;background:var(--bg-card);border:1px solid var(--border);
  font-size:11px;font-weight:600;color:var(--text-dim);transition:border-color .15s,color .15s,background-color .15s;font-family:var(--mono)}
.slider-presets button:hover{border-color:var(--border-strong);color:var(--text)}
.slider-presets button.active{background:var(--accent-soft);border-color:var(--accent);color:var(--accent)}
.size-hint{margin-top:8px;padding:7px 9px;border-radius:var(--radius-sm);background:var(--accent-soft);
  border:1px solid rgba(245,166,35,.4);font-size:11px;line-height:1.5;color:var(--accent)}

/* Toggle */
.toggle-row{display:flex;align-items:center;justify-content:space-between;padding:9px 12px;
  background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-sm);cursor:pointer;transition:border-color .15s}
.toggle-row:hover{border-color:var(--border-strong)}
.toggle-label{font-size:12.5px;font-weight:500}
.toggle-hint{font-size:10px;color:var(--text-mute);margin-top:1px}
.switch{position:relative;width:38px;height:22px;background:var(--surface);border-radius:11px;cursor:pointer;transition:background .25s;flex-shrink:0}
.switch::after{content:'';position:absolute;width:16px;height:16px;border-radius:50%;background:var(--text-dim);top:3px;left:3px;transition:left .25s var(--ease),background-color .25s var(--ease)}
.switch.on{background:var(--accent)}
.switch.on::after{left:19px;background:#fff}

/* Buttons */
.btn{display:flex;align-items:center;justify-content:center;gap:7px;padding:10px 14px;border-radius:var(--radius-sm);
  font-weight:600;font-size:13px;transition:transform .2s var(--ease),filter .2s var(--ease),opacity .2s var(--ease),
  box-shadow .2s var(--ease),border-color .2s var(--ease),color .2s var(--ease),background-color .2s var(--ease)}
.btn-primary{background:linear-gradient(135deg,var(--accent),var(--accent-deep));color:#1a1208;box-shadow:0 4px 14px rgba(245,166,35,.28)}
.btn-primary:hover:not(:disabled){filter:brightness(1.08);transform:translateY(-1px)}
.btn-primary:active:not(:disabled){transform:translateY(0)}
.btn-primary:disabled{opacity:.4;cursor:not-allowed;filter:grayscale(.5);box-shadow:none}
.btn-ghost{background:var(--bg-card);border:1px solid var(--border);color:var(--text-dim)}
.btn-ghost:hover:not(:disabled){border-color:var(--border-strong);color:var(--text)}
/* press feedback works on touch too, unlike :hover — instant "tapped" feel */
.btn:active:not(:disabled){transform:scale(.97)}
.btn-ghost:disabled{opacity:.4;cursor:not-allowed}
.btn-row{display:flex;gap:8px}
.btn-row .btn{flex:1}

/* KBD hints */
.kbd-hints{display:flex;flex-wrap:wrap;gap:6px 10px;padding-top:4px}
.kbd-hint{font-size:10.5px;color:var(--text-mute);display:flex;align-items:center;gap:4px}

/* ===== Canvas Area ===== */
.canvas-area{flex:1;min-width:0;display:flex;flex-direction:column;
  background:repeating-conic-gradient(var(--bg-deep) 0% 25%,#171311 0% 50%) 50%/22px 22px;position:relative;overflow:hidden}
.canvas-toolbar{display:flex;align-items:center;gap:12px;padding:10px 16px;flex-shrink:0;
  background:rgba(19,17,16,.5);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--border);z-index:5}
.tb-info{font-size:12px;color:var(--text-dim);display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.pill{padding:3px 9px;border-radius:20px;background:var(--bg-card);border:1px solid var(--border);font-size:11px;font-weight:600}
.tb-spacer{flex:1}
.zoom-ctrl{display:flex;align-items:center;gap:6px}
.zoom-btn{width:28px;height:28px;border-radius:6px;background:var(--bg-card);border:1px solid var(--border);
  display:grid;place-items:center;font-size:16px;transition:border-color .15s,color .15s,background-color .15s;position:relative}
.zoom-btn:hover{border-color:var(--border-strong);background:var(--surface)}
.zoom-display{font-family:var(--mono);font-size:12px;font-weight:600;min-width:48px;text-align:center;color:var(--text-dim)}

.canvas-scroll{flex:1;overflow:hidden;position:relative;display:flex}
.canvas-stage{flex:1;position:relative;min-height:0}
.canvas-wrap{position:absolute;inset:0;cursor:grab;touch-action:none;background:#0a0908}
.canvas-wrap.grabbing{cursor:grabbing}
.canvas-wrap:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
#beadCanvas{display:block;position:absolute;inset:0}

.empty-state{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:14px;color:var(--text-mute);pointer-events:none}
.empty-state .es-icon{width:64px;height:64px;border-radius:16px;background:var(--bg-card);border:1px solid var(--border);
  display:grid;place-items:center;color:var(--text-dim)}
.empty-state h2{font-family:var(--font-display);font-weight:500;font-size:22px;color:var(--text-dim)}
.empty-state p{font-size:13px;max-width:320px;text-align:center;line-height:1.6}
.es-btn{pointer-events:auto}

/* Hover tooltip */
.hover-tip{position:absolute;pointer-events:none;display:flex;align-items:center;gap:8px;
  padding:6px 10px;background:var(--surface);border:1px solid var(--border-strong);border-radius:8px;
  box-shadow:var(--shadow);font-size:12px;z-index:50;transform:translate(12px,-100%);transition:opacity .1s}
.ht-swatch{width:16px;height:16px;border-radius:50%;flex-shrink:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.3)}
.ht-name{font-weight:600}
.ht-code{font-family:var(--mono);font-size:11px;color:var(--text-dim)}

/* ===== Palette Panel ===== */
.palette-panel{width:260px;flex-shrink:0;background:var(--bg-elev);border-left:1px solid var(--border);overflow-y:auto;display:flex;flex-direction:column}
.palette-head{padding:14px 16px 10px;flex-shrink:0;border-bottom:1px solid var(--border);position:sticky;top:0;background:var(--bg-elev);z-index:2}
.palette-head h2{font-family:var(--font-display);font-weight:700;font-size:16px;margin-bottom:2px}
.palette-head .sub{font-size:11px;color:var(--text-mute)}
.palette-stats{display:flex;gap:8px;margin-top:10px}
.stat-chip{flex:1;text-align:center;padding:6px 4px;border-radius:var(--radius-sm);background:var(--bg-card);border:1px solid var(--border)}
.stat-chip .num{font-family:var(--mono);font-weight:700;font-size:16px;color:var(--accent)}
.stat-chip .lbl{font-size:10.5px;color:var(--text-mute);text-transform:uppercase;letter-spacing:.8px}
.palette-list{flex:1;overflow-y:auto;padding:8px 12px 16px;display:flex;flex-direction:column;gap:3px}
.palette-item{display:flex;align-items:center;gap:9px;padding:6px 8px;border-radius:var(--radius-sm);transition:background .15s;cursor:pointer;position:relative}
.palette-item:hover{background:var(--bg-card)}
.palette-item.pinned{background:var(--accent-soft);box-shadow:inset 0 0 0 1px var(--accent)}
.palette-item.pinned .pi-code{color:var(--text-mute-strong)}
.pi-swatch{width:22px;height:22px;border-radius:50%;flex-shrink:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.25),0 1px 3px rgba(0,0,0,.3)}
.pi-info{flex:1;min-width:0}
.pi-name{font-size:11.5px;font-weight:600;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pi-code{font-size:10px;color:var(--text-mute);font-family:var(--mono)}
.pi-bar{height:3px;border-radius:2px;background:var(--border);margin-top:4px;overflow:hidden}
.pi-bar span{display:block;height:100%;background:var(--accent);border-radius:2px;opacity:.7}
.pi-count{font-family:var(--mono);font-weight:700;font-size:13px;color:var(--accent);min-width:28px;text-align:right}
.pi-replace{flex-shrink:0;width:24px;height:24px;border-radius:5px;background:var(--bg-deep);border:1px solid var(--border);color:var(--text-mute);font-size:10px;font-weight:700;transition:color .15s,border-color .15s}
.pi-replace:hover{color:var(--accent);border-color:var(--accent)}
.palette-empty{padding:24px 16px;text-align:center;color:var(--text-mute);font-size:12px}

/* Loader */
/* visibility (not just opacity) keeps the hidden overlay/toast out of the
   a11y tree so screen readers don't announce "正在生成拼豆图纸…" at rest;
   visibility transitions discretely — visible for the whole fade-out, then
   hidden — so the fade still renders */
.loader-overlay{position:absolute;inset:0;background:rgba(10,9,8,.75);backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;z-index:30;
  opacity:0;visibility:hidden;pointer-events:none;transition:opacity .2s,visibility .2s}
.loader-overlay.show{opacity:1;visibility:visible;pointer-events:auto}
.spinner{width:36px;height:36px;border:3px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.loader-text{font-size:13px;color:var(--text-dim)}
.loader-bar-track{width:200px;height:4px;border-radius:2px;background:var(--border);overflow:hidden}
.loader-bar{height:100%;width:0%;background:var(--accent);border-radius:2px;transition:width .15s linear}

/* Toast */
.toast{position:fixed;bottom:44px;left:50%;transform:translateX(-50%) translateY(20px);
  background:var(--surface);border:1px solid var(--border-strong);padding:10px 18px;border-radius:var(--radius-sm);
  box-shadow:var(--shadow);font-size:13px;font-weight:500;opacity:0;visibility:hidden;pointer-events:none;transition:opacity .3s var(--ease),transform .3s var(--ease),visibility .3s;z-index:100;
  display:flex;align-items:center;gap:12px;max-width:92vw}
.toast.show{opacity:1;visibility:visible;transform:translateX(-50%) translateY(0);pointer-events:auto}
.toast-action{background:var(--accent);color:#1a1614;border:0;border-radius:6px;padding:6px 12px;
  font-size:12.5px;font-weight:700;cursor:pointer;white-space:nowrap;transition:filter .15s;flex-shrink:0}
.toast-action:hover{filter:brightness(1.12)}

/* ===== Site footer: identity + ICP filing strip =====
   In-flow sibling of .shell (NOT fixed): body is height:100% flex-column, so
   this strip pins itself to the viewport bottom while .shell (flex:1) yields
   the rows. Every bottom-anchored FIXED layer — toast (above), mobile-bar and
   the off-canvas drawers (780px media) — must offset above it accordingly. */
.site-footer{flex-shrink:0;display:flex;align-items:center;justify-content:space-between;gap:12px;
  height:28px;padding:0 16px;background:var(--bg-deep);border-top:1px solid var(--border);
  font-size:11px;color:var(--text-mute)}
.sf-brand{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
/* mono face matches the numeric accents elsewhere (panel-label .val, img-dims);
   hover warms to the accent like every other quiet link in the chrome */
.sf-icp{font-family:var(--mono);font-size:10.5px;letter-spacing:.3px;color:var(--text-mute);
  text-decoration:none;white-space:nowrap;transition:color .15s}
.sf-icp:hover{color:var(--accent)}
.sf-icp:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

/* Responsive */
@media(max-width:1024px){.sidebar{width:260px}.palette-panel{width:220px}}
/* reduced-motion: duration collapse alone still replayed infinite loops
   (the .8s spinner) every .01ms tick — iteration-count:1 runs each animation
   exactly once at ~0ms, the standard full-convergence recipe */
@media(prefers-reduced-motion:reduce){*{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}}

/* ===== Modals / overlays ===== */
.modal-overlay,.gallery-overlay{position:fixed;inset:0;z-index:90;display:flex;align-items:center;justify-content:center;padding:20px;background:rgba(8,7,6,.6);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px)}
.modal,.gallery{background:var(--bg-elev);border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow);width:100%;max-width:420px;max-height:85vh;display:flex;flex-direction:column;overflow:hidden}
.modal-head,.gallery-head{display:flex;align-items:center;justify-content:space-between;padding:14px 18px;border-bottom:1px solid var(--border)}
.modal-head h2,.gallery-head h2{font-family:var(--font-display);font-weight:700;font-size:17px}
.modal-close{width:28px;height:28px;border-radius:6px;display:grid;place-items:center;font-size:20px;color:var(--text-dim);transition:background-color .15s,color .15s}
.modal-close:hover{background:var(--bg-card);color:var(--text)}
.modal-body{padding:16px 18px;display:flex;flex-direction:column;gap:10px}
.field-label{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:1px;color:var(--text-mute)}
.text-input{width:100%;padding:9px 12px;border-radius:var(--radius-sm);background:var(--bg-card);border:1px solid var(--border);color:var(--text);font-size:13px;outline:none;transition:border-color .15s}
.text-input:focus{border-color:var(--accent)}
.save-preview{font-size:12px;color:var(--text-dim);background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-sm);padding:8px 10px}
.modal-foot{display:flex;gap:8px;padding:14px 18px;border-top:1px solid var(--border)}
.modal-foot .btn{flex:1}
.save-result{padding:14px 18px;border-top:1px solid var(--border);display:flex;flex-direction:column;gap:8px}
.save-result-title{font-size:12px;font-weight:600;color:var(--ok)}
.share-link-row{display:flex;gap:8px}
.share-link-row .text-input{flex:1;font-family:var(--mono);font-size:11px}
.share-link-row .btn{flex:0 0 auto;padding:0 14px}

/* Gallery */
.gallery{max-width:720px}
.gallery-grid{flex:1;overflow-y:auto;padding:14px;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:12px;align-content:start}
.gal-card{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;cursor:pointer;transition:border-color .2s var(--ease),transform .2s var(--ease),box-shadow .2s var(--ease);display:flex;flex-direction:column;position:relative}
.gal-card:hover{border-color:var(--accent);transform:translateY(-2px);box-shadow:var(--shadow)}
.gal-del{position:absolute;top:6px;right:6px;width:24px;height:24px;border-radius:50%;border:1px solid var(--border);background:rgba(10,9,8,.72);color:var(--text-mute);font-size:11px;line-height:1;cursor:pointer;opacity:0;transition:opacity .15s var(--ease),color .15s var(--ease),border-color .15s var(--ease),background-color .15s var(--ease);display:grid;place-items:center;padding:0}
.gal-card:hover .gal-del,.gal-del:focus-visible{opacity:1}
.gal-del:hover{color:#ff6b5e;border-color:#ff6b5e;background:rgba(10,9,8,.9)}
.gal-thumb{width:100%;aspect-ratio:1;background:#0a0908;display:grid;place-items:center;overflow:hidden}
.gal-thumb img{width:100%;height:100%;object-fit:contain}
.gal-thumb .gal-ph{font-size:22px;color:var(--text-mute)}
.gal-meta{padding:8px 10px}
.gal-name{font-size:12px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.gal-sub{font-size:10px;color:var(--text-mute);margin-top:2px;font-family:var(--mono)}
.gal-empty{padding:40px 20px;text-align:center;color:var(--text-mute);font-size:13px;grid-column:1/-1}
.gallery-more{margin:0 auto 14px;align-self:center}
/* SHARED tab-bar recipe (gallery source tabs + compare used/full tabs — same
   control, one recipe, two class aliases; used to be two hand-copied twins
   that had already drifted apart by a transform transition) */
.gal-tabs,.compare-tabs{display:flex;gap:4px;background:var(--bg-card);border:1px solid var(--border);border-radius:7px;padding:3px}
/* border/background/font-family inherit from the global button reset above;
   the transform transition is inert for .gal-tab (it never transforms) and
   serves the .ctab press feedback below */
.gal-tab,.ctab{padding:5px 12px;border-radius:5px;font-size:12px;font-weight:600;color:var(--text-dim);transition:color .15s,background-color .15s,transform .15s;cursor:pointer}
.gal-tab:hover,.ctab:hover{color:var(--text)}
.gal-tab.active,.ctab.active{background:var(--accent-soft);color:var(--accent)}

/* Color picker (replace) */
.replace-from{font-size:12px;color:var(--text-dim);background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-sm);padding:8px 10px;margin-bottom:4px}
.color-picker{display:grid;grid-template-columns:repeat(auto-fill,minmax(34px,1fr));gap:6px;max-height:280px;overflow-y:auto}
.cp-cell{width:34px;height:34px;border-radius:50%;cursor:pointer;border:2px solid transparent;transition:transform .12s,border-color .12s;padding:0;appearance:none;-webkit-appearance:none;font:inherit;line-height:1}
.cp-cell:hover{transform:scale(1.12)}
.cp-cell.selected{border-color:#fff;box-shadow:0 0 0 2px var(--accent)}

/* Crop editor */
.crop-stage{position:relative;background:#0a0908;border-radius:var(--radius-sm);overflow:hidden;display:grid;place-items:center;min-height:200px}
#cropCanvas{display:block;cursor:move;touch-action:none}
.crop-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:10px}
.crop-toolbar .btn{padding:6px 12px;font-size:12px}
.crop-aspect{display:flex;align-items:center;gap:5px;font-size:12px;color:var(--text-dim)}
.crop-info{margin-left:auto;font-size:11px;color:var(--text-mute);font-family:var(--mono)}

/* Undo button in palette head — sizing lives here (was an inline style:
   keeps the page free of style attributes for the server-side CSP) */
.undo-btn{margin-top:8px;font-size:11px;padding:6px 10px}

/* Modal size modifiers — .modal.modal--* double-class specificity keeps the
   cap winning over the ≤780px bottom-sheet `max-width:none` exactly like the
   inline styles they replace (P2-13) */
.modal.modal--sm{max-width:480px}
.modal.modal--md{max-width:560px}
.modal.modal--lg{max-width:620px}

/* ===== Brand selector (sidebar) ===== */
.brand-grid{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.brand-card{padding:8px 10px;border-radius:var(--radius-sm);background:var(--bg-card);border:1px solid var(--border);
  cursor:pointer;transition:border-color .15s var(--ease),background-color .15s var(--ease),box-shadow .15s var(--ease)}
.brand-card:hover{border-color:var(--border-strong)}
.brand-card.active{background:var(--accent-soft);border-color:var(--accent);box-shadow:0 0 0 1px var(--accent) inset}
.bc-name{font-size:12.5px;font-weight:700;line-height:1.2}
.brand-card.active .bc-name{color:var(--accent)}
.brand-card.active .bc-sub{color:var(--text-mute-strong)}
.bc-sub{font-size:10.5px;color:var(--text-mute);margin-top:2px;line-height:1.35}
.brand-hint{font-size:10px;color:var(--text-mute);line-height:1.5}
/* 混拼 mode: mix card + multi-select member cards */
.brand-card.mix-card{border-style:dashed}
.brand-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent) inset}
.brand-card.picked .bc-name::after{content:' ✓';color:var(--accent);font-size:10px}
.pi-brand-tag{display:inline-block;margin-right:4px;padding:0 4px;border-radius:3px;background:var(--bg-elev);
  color:var(--text-mute);font-size:10.5px;font-family:var(--mono)}
.stk-brand-chips{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:10px}
.stk-brand-chip{padding:3px 10px;border-radius:999px;background:var(--bg-card);border:1px solid var(--border);
  font-size:11px;cursor:pointer}
.stk-brand-chip.active{background:var(--accent-soft);border-color:var(--accent);color:var(--accent)}

/* ===== Palette panel: conversion controls & chips ===== */
.conv-row{display:flex;gap:6px;margin-top:10px}
.conv-select{flex:1;min-width:0;padding:7px 8px;border-radius:var(--radius-sm);background:var(--bg-card);
  border:1px solid var(--border);color:var(--text-dim);font-size:11.5px;outline:none;cursor:pointer;transition:border-color .15s;
  display:flex;align-items:center;gap:7px;appearance:none;-webkit-appearance:none;font-family:inherit;text-align:left}
.conv-select:hover,.conv-select:focus{border-color:var(--border-strong);color:var(--text)}
.conv-select[aria-expanded=true]{border-color:var(--accent)}
.conv-select .cv-cur{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-select .cv-caret{flex-shrink:0;color:var(--text-mute);transition:transform .15s}
.conv-select[aria-expanded=true] .cv-caret{transform:rotate(180deg);color:var(--accent)}
.conv-table-btn{flex:0 0 auto;padding:7px 10px;font-size:11.5px}
/* conversion-target picker sheet */
.conv-sheet{max-width:340px}
.conv-sheet-title{min-width:0}
.conv-sheet-sub{font-size:11px;color:var(--text-mute);margin-top:2px}
.conv-list{display:flex;flex-direction:column;gap:6px;padding:12px;overflow-y:auto}
.conv-opt{display:flex;align-items:center;gap:10px;width:100%;min-height:50px;padding:9px 12px;border-radius:var(--radius);
  background:var(--bg-card);border:1px solid var(--border);cursor:pointer;text-align:left;font:inherit;color:var(--text);
  transition:border-color .15s var(--ease),background-color .15s var(--ease),transform .15s var(--ease)}
.conv-opt:hover{border-color:var(--border-strong);background:var(--surface)}
.conv-opt:active{transform:scale(.98)}
.co-txt{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.co-name{font-size:13px;font-weight:600;line-height:1.25}
.co-sub{font-size:10.5px;color:var(--text-mute);line-height:1.35;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.co-check{flex-shrink:0;width:20px;height:20px;border-radius:50%;border:1.5px solid var(--border-strong);
  display:grid;place-items:center;font-size:11px;color:transparent;transition:background-color .15s,border-color .15s,color .15s}
.conv-opt.active{background:var(--accent-soft);border-color:var(--accent)}
.conv-opt.active .co-name{color:var(--accent)}
.conv-opt.active .co-sub{color:var(--text-mute-strong)}
.conv-opt.active .co-check{background:var(--accent);border-color:var(--accent);color:#1a1208;font-weight:700}
.pi-conv{display:flex;align-items:center;gap:6px;margin-top:5px;padding:3px 7px;border-radius:5px;
  background:var(--bg-deep);border:1px solid var(--border);width:fit-content;max-width:100%}
.pi-conv.exact{border-color:rgba(94,184,135,.55)}
.pic-swatch{width:12px;height:12px;border-radius:50%;flex-shrink:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.3)}
.pic-brand{font-size:10.5px;color:var(--text-mute)}
.pic-code{font-family:var(--mono);font-size:10.5px;font-weight:600;color:var(--text)}
.pic-de{font-size:10.5px;color:var(--text-mute);font-family:var(--mono)}
.pi-conv.exact .pic-de{color:var(--ok)}
.ht-conv{font-size:11px;color:var(--accent);font-family:var(--mono)}

/* ===== Cross-brand comparison overlay ===== */
.compare-gallery{max-width:1080px}
.compare-head{flex-wrap:wrap;gap:10px}
/* .compare-tabs/.ctab base+hover+active live in the SHARED tab-bar recipe up
   in the Gallery section (.gal-tabs,.compare-tabs / .gal-tab,.ctab) — only the
   compare-only press feedback stays here */
.ctab:active{transform:scale(.96)}
.compare-tools{display:flex;align-items:center;gap:6px;margin-left:auto;flex-wrap:wrap}
.cmp-select,.cmp-filter{padding:6px 9px;border-radius:var(--radius-sm);background:var(--bg-card);
  border:1px solid var(--border);color:var(--text);font-size:11.5px;outline:none;transition:border-color .15s}
.cmp-select{cursor:pointer}
.cmp-select:hover:not(:disabled),.cmp-filter:focus{border-color:var(--accent)}
.cmp-select:disabled{opacity:.5;cursor:not-allowed}
/* source-brand picker face (`.cmp-srcbtn` — NOT `.cmp-src`, that class is the
   compare table's source-column header in app-export.js): select text hidden,
   one “源” + custom chevron — the button reads a single word while the
   dropdown keeps the full brand info */
.cmp-srcbtn{position:relative;display:inline-flex;flex:0 0 auto}
.cmp-srcbtn::before{content:"源";position:absolute;left:9px;top:0;bottom:0;display:flex;align-items:center;
  pointer-events:none;color:var(--text)}
.cmp-srcbtn::after{content:"";position:absolute;right:9px;top:50%;transform:translateY(-50%);pointer-events:none;
  border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid var(--text-dim)}
.cmp-srcbtn .cmp-select{width:4.6em;padding-right:8px;color:transparent;appearance:none;-webkit-appearance:none}
.cmp-srcbtn .cmp-select option{color:initial}
.cmp-srcbtn:has(.cmp-select:disabled)::before,.cmp-srcbtn:has(.cmp-select:disabled)::after{opacity:.5}
.cmp-filter{width:110px}
.cmp-filter::placeholder{color:var(--text-mute)}
.cmp-export{padding:6px 10px;font-size:11.5px}
/* shopping panel head: same one-row toolbar recipe as compare-head/compare-tools,
   so brand select + both export buttons sit on ONE line instead of stacking */
.shopping-head{flex-wrap:wrap;gap:10px}
.shopping-tools{display:flex;align-items:center;gap:6px;margin-left:auto;flex-wrap:wrap}
.shopping-summary{padding:10px 18px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}
.compare-wrap{flex:1;overflow:auto;padding:0 14px 14px}
.cmp-table{width:100%;border-collapse:separate;border-spacing:0;font-size:11.5px;margin-top:12px}
.cmp-table thead th{position:sticky;top:0;z-index:2;background:var(--bg-card);border-bottom:1px solid var(--border-strong);
  padding:8px 8px;font-size:11px;color:var(--text-dim);white-space:nowrap;text-align:left}
.cmp-table thead th.cmp-src{color:var(--accent)}
.cmp-table tbody td{padding:5px 8px;border-bottom:1px solid var(--border);white-space:nowrap}
.cmp-table tbody tr:hover td{background:rgba(245,166,35,.05)}
.cmp-srccell{white-space:nowrap}
.cmp-sw,.shp-sw{display:inline-block;width:16px;height:16px;border-radius:50%;flex-shrink:0;margin-right:7px;vertical-align:middle;
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.3)}
.cmp-code{font-family:var(--mono);font-weight:600;font-size:11px;vertical-align:middle}
.cmp-code.exact{color:var(--ok)}
.cmp-srccell .cmp-code{margin-right:7px}
.cmp-hex{font-family:var(--mono);font-size:10.5px;color:var(--text-mute)}
.cmp-n{text-align:right;font-family:var(--mono);color:var(--accent)}
.cmp-de{font-size:10.5px;color:var(--text-mute);font-family:var(--mono);margin-left:5px}
.cmp-note{font-size:10.5px;color:var(--text-mute);padding:10px 2px 4px;line-height:1.6}

/* ===== Special-material toggle (tier panel) ===== */
.spec-toggle{margin-top:2px}
.spec-toggle.disabled{opacity:.5;cursor:default}
.spec-toggle.disabled:hover{border-color:var(--border)}

/* ===== Color-count limiting ===== */
.maxcolors-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:5px}

/* ===== Perceptual metric picker (in-page grid — native <select> popup
   clashes with the dark theme and is unstyled on mobile browsers) ===== */
.metric-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:5px}
.metric-btn{display:flex;flex-direction:column;align-items:flex-start;gap:2px;
  padding:8px 10px;border-radius:var(--radius-sm);background:var(--bg-card);border:1px solid var(--border);
  cursor:pointer;text-align:left;transition:border-color .15s,background-color .15s,box-shadow .15s}
.metric-btn:hover{border-color:var(--border-strong)}
.metric-btn.active{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 1px var(--accent) inset}
.metric-name{font-family:var(--mono);font-size:11.5px;font-weight:700;line-height:1.2;color:var(--text)}
.metric-btn.active .metric-name{color:var(--accent)}
.metric-desc{font-size:10.5px;line-height:1.3;color:var(--text-dim)}

/* ===== Bead stock entry ===== */
.stock-gallery{max-width:880px}
.stock-toolbar{display:flex;align-items:center;gap:7px;flex-wrap:wrap;padding:10px 14px;border-bottom:1px solid var(--border);background:var(--bg-card)}
.stock-toolbar .btn{padding:6px 10px;font-size:11.5px}
.stock-toolbar .cmp-filter{width:130px}
.stock-toolbar .cmp-select{max-width:120px}
.stk-opt{display:flex;align-items:center;gap:5px;font-size:11.5px;color:var(--text-dim);cursor:pointer;user-select:none;white-space:nowrap}
.stk-opt input{accent-color:var(--accent);cursor:pointer}
.stk-sep{width:1px;height:18px;background:var(--border);margin:0 2px;flex-shrink:0}
.stk-step-label{font-size:11px;color:var(--text-mute)}
.stk-step{display:flex;background:var(--bg-deep);border:1px solid var(--border);border-radius:6px;overflow:hidden}
.stk-step button{padding:5px 11px;font-size:11.5px;color:var(--text-dim);background:transparent;border:0;cursor:pointer;font-family:var(--mono);transition:background-color .12s,color .12s}
.stk-step button+button{border-left:1px solid var(--border)}
.stk-step button.active{background:var(--accent-soft);color:var(--accent)}
.stock-strict{border-style:dashed}
.stock-strict.on{border-color:var(--accent);border-style:solid;color:var(--accent);background:var(--accent-soft)}
.stock-grid{flex:1;overflow-y:auto;padding:10px 14px;display:flex;flex-direction:column;gap:2px}
.stk-group-head{display:flex;align-items:center;gap:8px;padding:8px 8px 5px;cursor:pointer;user-select:none;position:sticky;top:0;background:var(--bg-elev);z-index:1}
.stk-caret{width:0;height:0;border-top:5px solid var(--text-mute);border-left:4px solid transparent;border-right:4px solid transparent;transition:transform .15s;flex-shrink:0}
.stk-group-head.collapsed .stk-caret{transform:rotate(-90deg)}
.stk-gname{font-size:12px;font-weight:700;color:var(--text)}
.stk-group-head:hover .stk-gname{color:var(--accent)}
.stk-gmeta{margin-left:auto;display:flex;align-items:baseline;gap:9px}
.stk-gcount{font-size:10.5px;color:var(--text-mute);font-family:var(--mono)}
.stk-gsum{font-size:10.5px;color:var(--accent);font-family:var(--mono)}
.stk-group{display:grid;grid-template-columns:repeat(auto-fill,minmax(128px,1fr));gap:7px;padding:2px 0 8px}
.stock-cell{display:flex;align-items:center;gap:4px;padding:4px 6px;border-radius:var(--radius-sm);
  background:var(--bg-card);border:1px solid var(--border)}
.stk-sw{width:15px;height:15px;border-radius:50%;flex-shrink:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.3)}
.stk-code{font-family:var(--mono);font-size:10px;color:var(--text-dim);flex:1;min-width:0;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.stk-stepbtn{width:24px;height:24px;flex-shrink:0;border-radius:4px;border:1px solid var(--border);background:var(--bg-deep);
  color:var(--text-dim);font-size:12px;line-height:1;cursor:pointer;display:grid;place-items:center;padding:0;transition:border-color .12s,color .12s;position:relative}
/* 2.5.8: +/- steppers sit in tight 2-per-row stock cells on phones — the
   ::after halo grows the tappable region (24→34px, ≥32 on touch) without
   widening the row */
.stk-stepbtn::after{content:'';position:absolute;inset:-5px}
.stk-stepbtn:hover{border-color:var(--accent);color:var(--accent)}
.stk-input{width:44px;flex-shrink:0;padding:2px 4px;border-radius:4px;background:var(--bg-deep);
  border:1px solid var(--border);color:var(--text);font-size:11px;font-family:var(--mono);outline:none;text-align:center}
.stk-input:focus{border-color:var(--accent)}
.stk-input::-webkit-outer-spin-button,.stk-input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
.stk-empty{padding:34px;text-align:center;color:var(--text-mute);font-size:12.5px}
.stock-foot{display:flex;align-items:center;justify-content:space-between;gap:10px}
.stock-summary{font-size:11px;color:var(--text-dim);flex:1}
/* stock import modal */
.stk-import-text{resize:vertical;font-family:var(--mono);font-size:12px;line-height:1.7;min-height:130px}
.stk-import-hint{font-size:11px;color:var(--text-mute);line-height:1.6}
.stk-import-hint b{color:var(--text-dim)}
.stk-import-result{font-size:12px;padding:8px 10px;border-radius:var(--radius-sm);border:1px solid var(--border)}
.stk-import-result.ok{color:var(--ok);border-color:rgba(94,184,135,.4);background:rgba(94,184,135,.08)}
.stk-import-result.err{color:#ff8a7a;border-color:rgba(255,107,94,.4);background:rgba(255,107,94,.08)}

/* ===== Palette simplification suggestion ===== */
.simplify-box{flex-shrink:0;margin:0 12px 12px;padding:10px 12px;border-radius:var(--radius-sm);
  background:var(--accent-soft);border:1px solid rgba(245,166,35,.4);display:flex;flex-direction:column;gap:7px}
.simp-text{font-size:11.5px;line-height:1.45;color:var(--text)}
.simp-text b{color:var(--accent)}
.simp-detail{font-size:10px;color:var(--text-dim);font-family:var(--mono);line-height:1.5;
  max-height:44px;overflow:hidden;text-overflow:ellipsis}
.simp-actions{display:flex;gap:7px}
.simp-actions .btn{padding:6px 12px;font-size:11.5px}

/* ===== Guided assembly ===== */
.assembly-overlay{padding:0;align-items:stretch;justify-content:stretch;background:var(--bg-elev);backdrop-filter:none;-webkit-backdrop-filter:none}
body.asm-open{overflow:hidden}
.assembly{width:100%;max-width:none;height:100%;max-height:none;border-radius:0;border:0;
  display:flex;flex-direction:column;background:var(--bg-elev);overflow:hidden}
.asm-head{display:flex;align-items:center;gap:12px;padding:11px 16px;border-bottom:1px solid var(--border);flex-wrap:wrap}
.asm-head h2{font-family:var(--font-display);font-weight:700;font-size:17px}
.asm-pos{display:flex;align-items:center;gap:8px;font-family:var(--mono);font-size:13.5px;color:var(--accent);font-weight:600}
.asm-pos-sep{color:var(--text-mute)}
.asm-head-spacer{flex:1}
.asm-reset,.asm-tool{padding:6px 10px;font-size:11.5px}
.asm-tool.on{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}
/* focus mode: hide color bar + foot hint to maximize canvas */
.assembly.asm-focus .asm-colors,.assembly.asm-focus .asm-foot{display:none}
.asm-stage{flex:1;position:relative;overflow:hidden;background:#0a0908;min-height:0}
#asmCanvas{position:absolute;inset:0;display:block}
.asm-colors{display:flex;flex-wrap:wrap;gap:7px;padding:10px 16px;border-top:1px solid var(--border);
  min-height:46px;align-items:center;background:var(--bg-card)}
.asm-chip{display:flex;align-items:center;gap:6px;padding:5px 10px;border-radius:7px;
  background:var(--bg-elev);border:1px solid var(--border);cursor:pointer;transition:border-color .12s,background .12s}
.asm-chip:hover{border-color:var(--border-strong)}
.asm-chip.active{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 1px var(--accent)}
.asm-chip.active .asm-chip-code{color:var(--accent)}
.asm-chip-sw{width:16px;height:16px;border-radius:50%;box-shadow:inset 0 0 0 1px rgba(0,0,0,.3)}
.asm-chip-code{font-family:var(--mono);font-size:12px;font-weight:600}
.asm-chip-cnt{font-family:var(--mono);font-size:11px;color:var(--accent)}
.asm-color-empty{font-size:12px;color:var(--text-mute)}
.asm-controls{display:flex;align-items:center;gap:9px;padding:12px 16px;border-top:1px solid var(--border)}
.asm-nav{padding:12px 16px;font-size:14px;font-weight:600;white-space:nowrap}
.asm-big{flex:1;padding:14px 8px;font-size:15px;text-align:center}
.asm-progress{flex:1;height:9px;border-radius:5px;background:var(--bg-deep);overflow:hidden;min-width:50px;border:1px solid var(--border)}
.asm-progress-fill{height:100%;width:0;background:var(--accent);transition:width .2s var(--ease)}
.asm-foot{display:flex;align-items:center;padding:7px 16px;border-top:1px solid var(--border)}
.asm-hint{font-size:11.5px;color:var(--text-mute);font-family:var(--mono)}
/* (the former ≤640px asm overrides were dead code: the ≤780px block below
   restates .asm-nav/.asm-big/.asm-pos at equal specificity and later in the
   sheet, so those rules never took effect — removed) */
/* quality intelligence: fidelity score + deviation heatmap toggle */
.zoom-btn.on{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}
.stat-chip .num.warn{color:#e8b04e}
/* --danger (#e8554e) measures 4.26:1 on the chip surface — under AA's 4.5
   for 16px/700. The brightened tone below keeps the same hue family and
   clears the bar without touching --danger everywhere else (borders/icons
   have no text-contrast requirement) */
.stat-chip .num.hot{color:#f0685f}
.quality-hint{margin-top:6px;font-size:10.5px;line-height:1.4;color:var(--text-dim);
  padding:6px 8px;border-radius:var(--radius-sm);background:var(--bg-card);border:1px solid var(--border)}

/* quality-cost advisor (Pareto scan) */
.scan-sub{font-size:11px;color:var(--text-mute);line-height:1.5;margin-bottom:8px}
.scan-chart-wrap{background:var(--bg-deep);border:1px solid var(--border);border-radius:var(--radius-sm);padding:8px}
.scan-legend{display:flex;gap:12px;margin-top:8px;font-size:11px;color:var(--text-dim)}
.scan-legend .lg{display:flex;align-items:center;gap:4px}
.scan-legend .dot{width:8px;height:8px;border-radius:50%;display:inline-block}
.scan-rec{margin-top:10px;padding:10px 12px;border:1px solid var(--accent);border-radius:var(--radius-sm);background:var(--accent-soft);font-size:12px;line-height:1.6}
.scan-rec-main b{color:var(--accent)}
.scan-rec .scan-alt{color:var(--text-dim);font-size:11px;margin-top:2px}
.scan-progress{font-size:11px;color:var(--text-mute);margin-left:auto;align-self:center}

/* ======================================================================
   Mobile layout (≤780px)
   The three-pane desktop workspace is unusable on a phone (canvas would be
   squeezed between two scroll regions). Instead: canvas goes fullscreen,
   the sidebar becomes a LEFT off-canvas drawer, the palette panel a RIGHT
   drawer, both opened from a thumb-reachable bottom bar. Everything sits
   at the END of the sheet: media queries add no specificity, so these
   same-specificity overrides must come after the base rules they beat.
   ====================================================================== */
/* dvh: the collapsing URL bar made height:100% a lie — the shell must fill
   the VISUAL viewport or the bottom bar floats past the fold */
@supports(height:100dvh){html,body{height:100dvh}}
.mobile-bar,.drawer-scrim{display:none}
@media(max-width:780px){
  /* ---- topbar: compact, meta text dropped, safe-area aware ---- */
  .topbar{height:48px;padding-left:max(14px,env(safe-area-inset-left));padding-right:max(10px,env(safe-area-inset-right));gap:10px}
  .logo-mark{width:26px;height:26px;border-radius:6px}
  .logo-text{font-size:17px}
  .topbar-meta{display:none}
  .beginner-toggle{margin-right:0;padding:5px 10px;gap:6px}
  .beginner-toggle-label{font-size:11px}

  /* ---- side panels -> off-canvas drawers under the topbar ----
     bottom stops at the in-flow site footer (24px + safe-area tall, see the
     footer rules at the end of this media query) so drawers never slide under it */
  .sidebar,.palette-panel{position:fixed;top:48px;bottom:calc(24px + env(safe-area-inset-bottom));width:min(86vw,340px);max-height:none;z-index:40;
    box-shadow:0 0 40px rgba(0,0,0,.5);transition:transform .28s var(--ease),visibility 0s .28s;
    /* keep the last controls scrollable PAST the bottom bar */
    padding-bottom:calc(76px + env(safe-area-inset-bottom));
    /* off-canvas drawers must also be unfocusable while closed — transform
       alone leaves dozens of invisible tab stops */
    visibility:hidden}
  .sidebar{left:0;transform:translateX(-102%);border-radius:0 var(--radius-lg) var(--radius-lg) 0}
  .palette-panel{right:0;transform:translateX(102%);border-left:1px solid var(--border);
    border-radius:var(--radius-lg) 0 0 var(--radius-lg)}
  .shell.dw-left .sidebar,.shell.dw-right .palette-panel{transform:none;visibility:visible;
    transition:transform .28s var(--ease),visibility 0s}
  .drawer-scrim{display:block;position:fixed;top:48px;left:0;right:0;bottom:0;z-index:39;
    background:rgba(8,7,6,.55);opacity:0;pointer-events:none;transition:opacity .25s}
  .shell.dw-left .drawer-scrim,.shell.dw-right .drawer-scrim{opacity:1;pointer-events:auto}

  /* ---- bottom action bar (thumb zone); sits ON the footer, not over it ---- */
  .mobile-bar{display:flex;position:fixed;left:0;right:0;bottom:calc(24px + env(safe-area-inset-bottom));z-index:45;gap:8px;
    padding:8px max(12px,env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
    background:rgba(19,17,16,.94);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-top:1px solid var(--border)}
  .mb-btn{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
    min-height:50px;padding:6px 8px;border-radius:12px;background:var(--bg-card);
    border:1px solid var(--border);color:var(--text-dim);font-size:11px;font-weight:600;transition:color .15s,border-color .15s,background-color .15s,transform .15s}
  .mb-btn:active{transform:scale(.96)}
  .mb-btn[aria-expanded=true]{color:var(--accent);border-color:var(--accent);background:var(--accent-soft)}
  .mb-gen{flex:1.7;flex-direction:row;gap:7px;font-size:13.5px;border:none;color:#1a1208;
    background:linear-gradient(135deg,var(--accent),var(--accent-deep));box-shadow:0 4px 14px rgba(245,166,35,.28)}
  .mb-gen:not(:disabled):active{transform:scale(.97)}
  .mb-gen:disabled{opacity:.45;box-shadow:none;filter:grayscale(.4)}
  /* canvas gets the whole workspace; nothing may sit under the bar unnoticed */
  .canvas-toolbar{flex-wrap:wrap;row-gap:8px;gap:8px;padding:8px 12px;
    padding-left:max(12px,env(safe-area-inset-left))}
  .tb-info{min-width:100%;gap:6px}
  .tb-spacer{display:none}
  .zoom-ctrl{margin-left:auto}
  .zoom-btn{width:36px;height:36px}
  .zoom-display{min-width:42px;font-size:11px}
  .pill{padding:3px 8px;font-size:10.5px}
  .empty-state{padding:0 16px calc(58px + env(safe-area-inset-bottom))}
  .empty-state h2{font-size:19px}
  .empty-state p{max-width:280px;font-size:12.5px}

  /* ---- touch targets ≥44px-ish + iOS no-zoom font floor ---- */
  .btn{padding:12px 14px}
  .btn-ghost{font-size:12.5px}
  .mode-card{padding:12px}
  .tier-btn{padding:9px 0}
  .metric-btn{min-height:48px;justify-content:center;padding:9px 12px}
  .metric-name{font-size:12.5px}
  .metric-desc{font-size:11px}
  .slider-presets button{padding:9px 0}
  .modal-close{width:36px;height:36px}
  .pi-replace{width:30px;height:30px;font-size:11px}
  .toggle-row{padding:11px 12px}
  .img-remove{width:34px;height:34px}
  .zoom-btn svg{width:16px;height:16px}
  input[type=range]{height:28px;border-radius:14px;background:linear-gradient(var(--border),var(--border)) no-repeat center/100% 4px}
  input[type=range]::-webkit-slider-thumb{width:22px;height:22px}
  input[type=range]::-moz-range-thumb{width:20px;height:20px;border-width:3px}
  /* 16px floor: iOS Safari auto-zooms the page when focusing anything smaller */
  .text-input,select,textarea{font-size:16px}
  .cmp-select,.cmp-filter{font-size:16px}
  /* the 11px stock-count input rides the same floor: focusing it used to
     trip the viewport zoom on iPhone (rule added when the control was) */
  .stk-input{font-size:16px}
  /* conv trigger is a button now (no iOS zoom risk) — 44px touch target instead */
  .conv-select{min-height:44px}
  .cmp-filter{width:130px}
  .conv-opt{min-height:54px}
  .co-name{font-size:14px}
  .co-sub{font-size:11px}

  /* keyboard-only affordances are noise on touch */
  .kbd-hints{display:none}

  /* toast lifts above the bottom bar (+ its footer offset) */
  .toast{bottom:calc(102px + env(safe-area-inset-bottom));max-width:calc(100vw - 24px)}

  /* footer: brand is redundant (topbar carries the logo) — center the filing
     number alone; height is deterministic (24px + safe-area) so the fixed
     layers above can anchor their bottoms against it */
  .site-footer{height:calc(24px + env(safe-area-inset-bottom));justify-content:center;
    padding:0 12px env(safe-area-inset-bottom)}
  .sf-brand{display:none}

  /* ---- dialogs: small modals dock as bottom sheets (thumb-reachable ----
     action buttons), large galleries go edge-to-edge */
  .modal-overlay{padding:0;align-items:flex-end;justify-content:center}
  .modal{max-width:none;max-height:min(88dvh,720px);border-radius:var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom:none;padding-bottom:env(safe-area-inset-bottom)}
  /* tall sheets (crop / scan) scroll INSIDE the body — head & foot stay pinned */
  .modal-body{overflow-y:auto;min-height:0;flex:1;padding:14px}
  .gallery-overlay{padding:8px}
  .assembly-overlay{padding:0} /* stays edge-to-edge (beat the rule above) */
  .gallery{max-width:none;max-height:min(94dvh,900px)}
  .modal-foot{padding:12px 14px calc(12px + env(safe-area-inset-bottom))}
  .modal-foot .btn{min-height:46px}
  .gallery-grid{grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:10px;padding:10px}
  /* touch has no hover: the delete affordance must not hide behind :hover */
  .gal-del{opacity:.92}
  /* one-row toolbars wrap into full-width rows instead of overflowing */
  .compare-head,.shopping-head{padding:10px 12px}
  .compare-tools,.shopping-tools{margin-left:0;width:100%}
  .compare-tools .cmp-select{flex:1;min-width:0}
  /* “源” picker keeps its compact one-word face on touch too */
  .compare-tools .cmp-srcbtn .cmp-select{flex:0 0 auto}
  .stock-toolbar{padding:8px 10px;gap:6px}
  .compare-wrap{padding:0 10px 10px}
  .crop-stage{min-height:230px}
  /* the chart canvas carries a fixed 560px attribute width — cap it until
     (and regardless of) renderScanChart() restyling it */
  .scan-chart-wrap canvas{display:block;width:100%;height:auto}

  /* ---- guided assembly: keep the nav row usable at 320px ---- */
  .asm-head{padding:8px 10px;gap:8px}
  .asm-head h2{font-size:15px}
  .asm-nav{padding:12px 10px;font-size:13px}
  .asm-big{font-size:14px}
  .asm-pos{font-size:12px}
  .asm-controls{flex-wrap:wrap;gap:8px;padding:10px 12px}
  .asm-colors{padding:8px 12px}
  .asm-foot{padding:6px 12px calc(6px + env(safe-area-inset-bottom))}
}
@media(max-width:360px){
  /* very narrow: export rows split instead of truncating labels */
  .btn-row{flex-wrap:wrap}
  .btn-row .btn{flex:1 1 calc(50% - 8px)}
  .mb-btn span{font-size:10px}
}
