/* ═══════════════════════════════════════════════════════════
   CHABAD BACKGROUND GENERATOR — style.css
   Matches the chabadlogo.com design system
═══════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Entrance animations — copied from chabadlogo.com ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes tabFade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeUp 0.4s ease-out both; }
.tab-fade { animation: tabFade 0.25s ease-out both; }
html { font-size: 16px; }
body {
  font-family: 'Mulish', sans-serif;
  background: var(--surround);
  color: var(--c-dark);
  min-height: 100vh;
}
button { cursor: pointer; font-family: inherit; }
.hidden { display: none !important; }

:root {
  /* brand — constant across themes */
  --c-primary:    #871a39;
  --c-secondary:  #f27730;
  --c-glow:       rgba(242,119,48,0.35);
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 2px 16px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.14);
  --transition:   0.2s ease;
  --panel-w:      400px;

  /* theme tokens — LIGHT defaults (neutral greys, no warm tint) */
  --c-dark:       #1a1a1a;          /* primary text/icon on panels */
  --c-bg:         #ffffff;          /* container surface: sidebar, drawer, sheets */
  --c-panel:      #f1f1f3;          /* recessed bits: chips, circles, seg tracks */
  --c-border:     #e3e3e6;
  --c-input-bg:   #ffffff;
  --c-muted:      #87878f;
  --c-accent:     #871a39;          /* selected-state ink (orange in dark) */
  --surround:     #e6e6ea;          /* preview backdrop */
  --chrome-bg:    rgba(255,255,255,0.62);  /* floating controls */
  --chrome-bd:    rgba(0,0,0,0.12);
  --chrome-fg:    #1a1a1a;
  --scrim:        rgba(0,0,0,0.32);
  --track:        #d7d7dc;          /* slider track */
  --tick:         #c3c3ca;
  --tick-major:   #9a9aa2;
}

/* DARK — follow the system unless a theme is explicitly chosen */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --c-dark:     #f0f0f3;
    --c-bg:       #1e1e21;
    --c-panel:    #2a2a2f;
    --c-border:   #3a3a41;
    --c-input-bg: #2a2a2f;
    --c-muted:    #9a9aa3;
    --c-accent:   #f27730;
    --surround:   #141416;
    --chrome-bg:  rgba(0,0,0,0.32);
    --chrome-bd:  rgba(255,255,255,0.28);
    --chrome-fg:  #ffffff;
    --scrim:      rgba(0,0,0,0.5);
    --track:      #45454d;
    --tick:       #55555e;
    --tick-major: #7c7c86;
  }
}
:root[data-theme="dark"] {
  --c-dark:     #f0f0f3;
  --c-bg:       #1e1e21;
  --c-panel:    #2a2a2f;
  --c-border:   #3a3a41;
  --c-input-bg: #2a2a2f;
  --c-muted:    #9a9aa3;
  --c-accent:   #f27730;
  --surround:   #141416;
  --chrome-bg:  rgba(0,0,0,0.32);
  --chrome-bd:  rgba(255,255,255,0.28);
  --chrome-fg:  #ffffff;
  --scrim:      rgba(0,0,0,0.5);
  --track:      #45454d;
  --tick:       #55555e;
  --tick-major: #7c7c86;
}

/* ══════════════════════════════════════════
   EDITOR SIDEBAR + shared controls
══════════════════════════════════════════ */
.controls-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: var(--panel-w);
  max-width: 88vw;
  background: var(--c-bg);
  padding: 56px 32px 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.28s ease;
  box-shadow: var(--shadow-lg);
  z-index: 45;
}
.controls-panel.open { transform: translateX(0); }
@media (max-width: 959px) {
  /* mobile edits through the bottom-sheet editor instead */
  .controls-panel { display: none; }
}
.panel-close {
  position: absolute;
  top: 14px; right: 18px;
  width: 30px; height: 30px;
  border: none; border-radius: 50%;
  background: var(--c-panel); color: var(--c-muted);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.panel-close:hover { color: var(--c-dark); }
.panel-close svg { width: 12px; height: 12px; }
.d-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 44;
}

/* ─── Accordions ─── */
.accordion { border-bottom: 1px solid var(--c-border); }
.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  padding: 18px 0;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--c-dark);
  font-family: inherit;
}
.accordion-chevron {
  width: 18px; height: 18px;
  color: var(--c-muted);
  transition: transform var(--transition);
}
.accordion.open .accordion-chevron { transform: rotate(180deg); }
.accordion-body {
  display: none;
  flex-direction: column;
  gap: 18px;
  padding: 4px 0 22px;
}
.accordion.open .accordion-body { display: flex; }

.ctrl-group { display: flex; flex-direction: column; gap: 18px; }
.ctrl-row-2 { flex-direction: row; gap: 10px; }
.ctrl-row-2 .form-field { flex: 1; }

.ctrl-subheading {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 6px;
}
.ctrl-subheading:first-child { margin-top: 0; }

.ctrl-hint {
  font-size: 0.78rem;
  color: var(--c-muted);
  line-height: 1.5;
}
.ctrl-hint.no-mt { margin-top: 0; }

/* ─── Look pill — one rounded control: ‹  Look n  › ─── */
.look-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  background: var(--c-panel);
  border-radius: 999px;
  padding: 3px;
  height: 40px;
}
.look-pill .look-arrow {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--c-dark);
  font-size: 1.15rem;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.look-pill .look-arrow:hover { color: var(--c-accent); }
.look-label {
  flex: 1;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--c-dark);
  font-variant-numeric: tabular-nums;
}

/* ─── Color drag handle ─── */
.drag-handle {
  width: 12px;
  height: 18px;
  margin-right: 8px;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
  background-image: radial-gradient(circle, #bdbdbd 1.2px, transparent 1.4px);
  background-size: 6px 6px;
  background-position: 0 1px;
}
.color-row.dragging { background: rgba(135,26,57,0.05); border-radius: 6px; }
.color-row .color-label { flex: 1; }

/* ─── Pattern thumbnail tiles ─── */
.pattern-tiles { display: flex; gap: 10px; }
.pattern-tile {
  flex: 1;
  background: var(--c-panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 6px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.pattern-tile:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.12); }
.pattern-tile.active { border-color: var(--c-accent); }
.pattern-tile .tile-art { width: 100%; }
.pattern-tile .tile-art svg,
.pattern-tile .tile-art img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 8 / 5;
  object-fit: cover;
  border-radius: 6px;
  /* grayscale: the tiles show the pattern's shape, not its colors */
  filter: grayscale(1);
}
.tile-label { font-size: 0.78rem; font-weight: 500; color: var(--c-muted); }
.pattern-tile.active .tile-label { color: var(--c-accent); }

/* ─── Sliders — one line: name · track · value (Paper-style) ─── */
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-name {
  width: 92px;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-family: 'Mulish', sans-serif;
  font-weight: 300;
  color: var(--c-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slider-track-wrap { flex: 1; display: flex; align-items: center; min-width: 0; }
.slider-val {
  width: 46px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.74rem;
  color: var(--c-muted);
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--track);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--c-secondary);
  border: none;
  box-shadow: 0 1px 5px rgba(0,0,0,0.18);
  cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--c-secondary);
  border: none;
  box-shadow: 0 1px 5px rgba(0,0,0,0.18);
  cursor: grab;
}
input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }

.btn-inline-reset {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 2px 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--c-secondary);
  transition: opacity var(--transition);
}
.btn-inline-reset:hover { opacity: 0.7; }

/* ─── Inputs & selects ─── */
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 0.78rem; color: var(--c-dark); }
.ctrl-input {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--c-input-bg);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--c-dark);
  outline: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: box-shadow var(--transition);
}
.ctrl-input:focus {
  box-shadow: 0 0 0 3px rgba(135,26,57,0.12), 0 2px 8px rgba(0,0,0,0.1);
}
.select-row { display: flex; align-items: center; gap: 10px; }
.select-row .form-label { width: 92px; flex-shrink: 0; }
.select-row .ctrl-select { flex: 1; }
.ctrl-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='%23888'%3E%3Cpath d='M0.979 0.01L5 4.024 9.021 0.01 10 0.989 5 5.989 0 0.989z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 10px;
  padding-right: 34px;
  cursor: pointer;
}

/* ─── Toggle switch ─── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--track);
  border-radius: 24px;
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-track::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track { background: var(--c-secondary); }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(20px); }

/* ─── Color rows ─── */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1px 0;
}
.color-label { font-size: 0.82rem; }
.color-swatch-wrap { display: flex; align-items: center; gap: 8px; }
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 32px; height: 32px;
  border: 2px solid var(--c-border);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: none;
  overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }
.color-hex-input {
  font-size: 0.78rem;
  font-family: 'Mulish', monospace;
  color: var(--c-muted);
  width: 72px;
  padding: 5px 6px;
  border: none;
  border-radius: 4px;
  background: var(--c-input-bg);
  outline: none;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.color-hex-input:focus {
  color: var(--c-dark);
  box-shadow: 0 0 0 3px rgba(135,26,57,0.12), 0 2px 8px rgba(0,0,0,0.1);
}

.color-list { display: flex; flex-direction: column; gap: 2px; }
.color-list .color-row { justify-content: flex-start; gap: 8px; padding: 2px 0; }
.color-list input[type="color"] {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
}
.color-list input[type="color"]::-webkit-color-swatch { border-radius: 5px; }
.color-list input[type="color"]::-moz-color-swatch { border-radius: 5px; }
.color-list .color-hex-input { width: 84px; text-align: left; padding: 7px 9px; }
.color-spacer { flex: 1; }
.color-remove {
  border: none;
  background: none;
  color: var(--c-muted);
  font-size: 1.45rem;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}
.color-remove:hover { color: #b03030; }
.color-add-row { display: flex; justify-content: space-between; margin-bottom: -6px; }
.color-add svg { width: 13px; height: 13px; }
.color-add {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: var(--c-panel);
  color: var(--c-muted);
  font-size: 1.05rem;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  cursor: pointer;
}
.color-add:hover { color: var(--c-accent); }

/* ─── Preset gradient carousel — bleeds to the panel edges ─── */
.preset-carousel {
  display: flex;
  gap: 14px;
  margin: 0 -32px;
  padding: 7px 32px 7px;
  overflow-x: auto;
  scrollbar-width: none;
}
.preset-carousel::-webkit-scrollbar { display: none; }
.preset-circle-wrap {
  background: none;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.preset-circle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.1);
  transition: transform var(--transition);
}
.preset-circle-wrap:hover .preset-circle { transform: scale(1.07); }
.preset-circle.active { outline: 2.5px solid var(--c-accent); outline-offset: 2px; }
.preset-label { font-size: 0.7rem; color: var(--c-muted); }
.preset-circle.active + .preset-label,
.preset-circle-wrap:has(.active) .preset-label { color: var(--c-accent); font-weight: 500; }

/* ─── Bottom link ─── */
.panel-back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--c-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.panel-back-link:hover { color: var(--c-dark); }
.form-bottom-link { margin-top: auto; padding: 24px 0 12px; }
.panel-links { display: flex; justify-content: space-between; align-items: center; }

/* ─── Preview canvas ─── */
.canvas-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #ddd;
}
.canvas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.record-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  backdrop-filter: blur(2px);
}
.record-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ff4d4d;
  animation: pulse 1s ease-in-out infinite;
}
.record-cancel {
  margin-left: 8px;
  width: 28px; height: 28px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.record-cancel:hover { background: rgba(255,255,255,0.22); }
.record-cancel svg { width: 11px; height: 11px; }
@keyframes pulse { 50% { opacity: 0.35; } }

.gl-error {
  padding: 40px;
  text-align: center;
  color: var(--c-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-dark);
  color: var(--c-bg);
  font-size: 0.82rem;
  padding: 10px 18px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ══════════════════════════════════════════
   APP SHELL — full-bleed preview + floating cluster (all widths)
══════════════════════════════════════════ */
  /* pin the shell to the visual viewport — on iOS Chrome 100vh includes
     the browser chrome, making the page scroll past the top bar */
  html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  #m-root {
    position: fixed;
    inset: 0;
    background: var(--surround);   /* immersive preview backdrop */
    overflow: hidden;
  }

  /* full-bleed preview fills the whole shell; chrome floats over it */
  .m-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
  }

  /* floating glass controls — chrome ink on a subtle theme-aware scrim */
  .m-float {
    position: absolute;
    width: 44px; height: 44px;
    border: 1px solid var(--chrome-bd);
    border-radius: 50%;
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    display: flex; align-items: center; justify-content: center;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: 10;
  }
  .m-float svg { width: 20px; height: 20px; }
  .m-float-tl { top: max(12px, env(safe-area-inset-top)); left: 14px; }
  .m-float-tr { top: max(12px, env(safe-area-inset-top)); right: 14px; }

  /* centered product title, vertically aligned with the 44px chrome.
     z-index sits BELOW the preview so a tall pattern covers it rather
     than the title floating over the artwork. */
  .m-title {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    height: 44px;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--chrome-fg);
    white-space: nowrap;
    pointer-events: none;
    z-index: -1;
  }

  /* bottom cluster: format chip stacked above the action row */
  .m-cluster {
    position: absolute;
    left: 0; right: 0;
    bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 10;
    pointer-events: none;
  }
  .m-cluster > * { pointer-events: auto; }
  .m-cluster-row {
    display: flex;
    align-items: center;
    gap: 14px;
  }
  .m-float.m-dl-fab,
  .m-float.m-edit-fab {
    position: static;
  }
  /* logo toggle — glass pill top-right: label + mini switch, keyed off
     the same .off class the old FAB used */
  .m-logo-switch {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    right: 14px;
    display: flex;
    align-items: center;
    gap: 9px;
    height: 44px;
    padding: 0 13px 0 16px;
    border: 1px solid var(--chrome-bd);
    border-radius: 22px;
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: 10;
  }
  .m-switch {
    position: relative;
    width: 36px; height: 20px;
    border-radius: 10px;
    background: var(--c-secondary);
    transition: background var(--transition);
    flex-shrink: 0;
  }
  .m-switch-knob {
    position: absolute;
    top: 2px; left: 18px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    transition: left var(--transition);
  }
  .m-logo-switch.off .m-switch { background: var(--track); }
  .m-logo-switch.off .m-switch-knob { left: 2px; }
  .m-shuffle {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: none;
    border-radius: 26px;
    padding: 0 22px;
    height: 52px;
    background: var(--c-secondary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 4px 16px var(--c-glow);
  }
  .m-shuffle svg { width: 19px; height: 19px; }
  .m-shuffle:active { transform: scale(0.97); }

  .m-format-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--chrome-bd);
    border-radius: 20px;
    padding: 9px 15px;
    background: var(--chrome-bg);
    color: var(--chrome-fg);
    font-size: 0.8rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .m-fmt-ico { width: 17px; height: 17px; color: var(--chrome-fg); flex-shrink: 0; }
  .m-fmt-caret { width: 10px; height: 6px; color: var(--chrome-fg); opacity: 0.6; flex-shrink: 0; }

  /* hamburger drawer — slides in from the left */
  .m-drawer {
    position: absolute;
    inset: 0;
    background: var(--scrim);
    z-index: 40;
    display: flex;
  }
  .m-drawer-card {
    position: relative;
    width: min(78%, 300px);
    height: 100%;
    background: var(--c-bg);
    padding: max(20px, env(safe-area-inset-top)) 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow-lg);
    animation: drawerIn 0.22s ease-out both;
  }
  @keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
  .m-drawer-close {
    position: absolute;
    top: 14px; right: 14px;
    width: 30px; height: 30px;
    border: none; border-radius: 50%;
    background: var(--c-panel); color: var(--c-muted);
    display: flex; align-items: center; justify-content: center;
  }
  .m-drawer-close svg { width: 12px; height: 12px; }
  /* brand icon atop the drawer — same mark/size as the guide sidebar;
     links home, replacing the old chabadbrand.com footer link */
  .m-drawer-brand { display: block; padding: 6px 6px 20px; }
  .m-drawer-brand img { height: 48px; width: auto; display: block; }
  .m-drawer-brand .db-white { display: none; }
  .m-drawer-title {
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--c-muted);
    padding: 4px 6px 10px;
  }
  .m-drawer-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 13px 14px;
    border-radius: var(--radius);
    font-size: 0.92rem;
    color: var(--c-dark);
    text-decoration: none;
  }
  .m-drawer-link .pill-ext { width: 11px; height: 11px; opacity: 0.4; margin-left: 2px; }
  .m-drawer-link.active { background: var(--c-primary); color: #fff; font-weight: 500; }
  .m-drawer-theme { margin-top: 18px; padding: 0 8px; }
  .m-drawer-sub {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--c-muted);
    margin-bottom: 9px;
  }
  .m-theme-seg {
    display: flex;
    background: var(--c-panel);
    border-radius: 12px;
    padding: 3px;
    gap: 2px;
  }
  .m-theme-seg button {
    flex: 1;
    border: none;
    background: none;
    padding: 9px 0;
    border-radius: 9px;
    font-size: 0.8rem;
    color: var(--c-muted);
    font-family: inherit;
    cursor: pointer;
  }
  .m-theme-seg button.active {
    background: var(--c-bg);
    color: var(--c-accent);
    font-weight: 500;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  }

  /* customize editor — bottom sheet holding the full control set */
  .m-edit {
    position: absolute;
    inset: 0;
    background: var(--scrim);
    z-index: 40;
    display: flex;
    align-items: flex-end;
  }
  .m-edit-card {
    position: relative;
    width: 100%;
    max-height: 82%;
    overflow-y: auto;
    background: var(--c-bg);
    border-radius: 18px 18px 0 0;
    padding: 34px 0 max(12px, env(safe-area-inset-bottom));
    animation: sheetIn 0.24s ease-out both;
  }
  @keyframes sheetIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
  /* subtle iOS-style sheet handle — a thin bar, not a button shape
     (tapping off the sheet also closes, so it can stay quiet) */
  .m-grabber {
    position: absolute;
    top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 52px; height: 16px;
    border: none; background: none; padding: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
  }
  .m-grabber::before {
    content: '';
    width: 38px; height: 5px;
    border-radius: 3px;
    background: var(--c-border);
  }
  .m-context { display: flex; flex-direction: column; }

  .m-choice {
    display: flex;
    gap: 14px;
    padding: 7px 16px 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .m-choice::-webkit-scrollbar { display: none; }
  /* center rows whose content fits; left-align only once they scroll */
  .m-choice > :first-child, .m-chips > :first-child { margin-left: auto; }
  .m-choice > :last-child, .m-chips > :last-child { margin-right: auto; }
  .m-circle-wrap {
    background: none; border: none; padding: 0;
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    flex-shrink: 0;
  }
  .m-circle {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: var(--c-panel);
    color: var(--c-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem;
    font-weight: 500;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  }
  .m-circle img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(1); }
  .m-circle.active { outline: 2.5px solid var(--c-accent); outline-offset: 2px; }
  .m-circle-label { font-size: 0.66rem; color: var(--c-muted); }
  .m-circle svg { width: 20px; height: 20px; }
  .m-swatches { padding-top: 0; align-items: center; }
  .m-swatch {
    width: 34px; height: 34px;
    border: none; padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
    touch-action: none;
  }
  .m-swatch-input {
    position: absolute;
    width: 0; height: 0;
    opacity: 0;
    pointer-events: none;
  }
  .m-qty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    margin-left: 4px;
    flex-shrink: 0;
  }
  .m-qty-btn {
    border: none;
    background: none;
    color: var(--c-muted);
    font-size: 0.62rem;
    padding: 1px 8px;
    line-height: 1;
  }
  .m-qty-n { font-size: 0.72rem; font-weight: 500; color: var(--c-dark); line-height: 1; }

  /* Look pill gets its own full-width row under the pattern thumbnails */
  .m-look-row { padding: 2px 16px 12px; }
  .m-look-row .look-pill { height: 44px; }
  .m-look-row .look-arrow { width: 38px; height: 38px; }

  .m-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 16px 14px;
  }
  .m-toggle-label { font-size: 0.9rem; color: var(--c-dark); }

  .m-chips {
    display: flex;
    gap: 8px;
    padding: 4px 16px 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .m-chips::-webkit-scrollbar { display: none; }

  .m-scrub {
    position: relative;
    height: 48px;
    margin: 0 16px 6px;
    overflow: hidden;
    touch-action: none;
    cursor: ew-resize;
  }
  .m-scrub-strip {
    position: absolute;
    left: 50%;
    top: 0; bottom: 0;
    display: flex;
    align-items: center;
  }
  .m-tick {
    width: 2px;
    height: 15px;
    margin-right: 7px;
    border-radius: 1px;
    background: var(--tick);
    flex-shrink: 0;
    transition: transform 0.25s ease;
    transform-origin: center;
  }
  .m-tick.major { height: 24px; background: var(--tick-major); }
  .m-scrub-marker {
    position: absolute;
    left: 50%; top: 4px; bottom: 4px;
    width: 3px;
    margin-left: -1.5px;
    border-radius: 2px;
    background: var(--c-secondary);
    pointer-events: none;
  }

  .m-cats {
    display: flex;
    justify-content: space-around;
    padding: 6px 8px 2px;
    border-top: 1px solid var(--c-border);
  }
  .m-cat {
    background: none; border: none;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 4px 6px;
    color: var(--c-muted);
  }
  .m-cat-icon {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--c-panel);
    display: flex; align-items: center; justify-content: center;
  }
  .m-cat-icon svg { width: 18px; height: 18px; }
  .m-cat-label { font-size: 0.62rem; }
  .m-cat.active { color: var(--c-accent); }
  .m-cat.active .m-cat-icon { background: var(--c-accent); color: #fff; }

/* ══════════════════════════════════════════
   FORMAT PANEL — shared sheet/dialog (both shells)
══════════════════════════════════════════ */
.m-export {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.m-export-card {
  position: relative;
  background: var(--c-bg);
  border-radius: 18px 18px 0 0;
  padding: 34px 16px max(16px, env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: sheetIn 0.24s ease-out both;
}
.m-export-lengths { display: flex; gap: 8px; justify-content: center; }

/* Meta-style format groups: a label above a full-width segmented row */
.m-fmt-group { display: flex; flex-direction: column; gap: 7px; }
.m-fmt-label { font-size: 0.78rem; font-weight: 500; color: var(--c-muted); padding-left: 2px; }
.m-fmt-group .m-seg { width: 100%; }
.m-fmt-group .m-seg-btn { flex: 1; padding: 10px 0; }
.m-fmt-group .m-shape-row { justify-content: space-between; }
/* X is desktop-only; mobile uses the same top grabber as the editor sheet */
.m-export-close {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--c-panel);
  color: var(--c-muted);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.m-export-close:hover { color: var(--c-dark); }
.m-export-close svg { width: 11px; height: 11px; }
@media (min-width: 960px) {
  /* desktop: centered dialog over a dimmed backdrop */
  .m-export { align-items: center; }
  .m-export .m-grabber { display: none; }
  .m-export-close { display: flex; }
  .m-export-card {
    width: 460px;
    border-radius: 16px;
    padding: 40px 24px 24px;
    box-shadow: var(--shadow-lg);
    animation: popIn 0.18s ease-out both;
  }
}
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

.m-chip {
  border: none;
  border-radius: 16px;
  padding: 8px 11px;
  font-size: 0.8rem;
  background: none;
  color: var(--c-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.m-chip.active { color: var(--c-accent); font-weight: 600; }

.m-seg-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.m-seg {
  display: flex;
  background: var(--c-panel);
  border-radius: 17px;
  padding: 3px;
  gap: 2px;
}
.m-seg-btn {
  border: none;
  background: none;
  padding: 8px 16px;
  border-radius: 14px;
  font-size: 0.8rem;
  color: var(--c-muted);
  cursor: pointer;
}
.m-seg-btn.active {
  background: var(--c-bg);
  color: var(--c-accent);
  font-weight: 500;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.m-shape-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.m-shape-row::-webkit-scrollbar { display: none; }
.m-shape {
  border: none;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  cursor: pointer;
}
.m-shape-art {
  width: 46px; height: 42px;
  color: var(--c-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-shape-art svg { width: 30px; height: 30px; }
.m-shape.active .m-shape-art { color: var(--c-accent); }
.m-shape-label { font-size: 0.66rem; color: var(--c-muted); }
.m-shape.active .m-shape-label { color: var(--c-accent); font-weight: 500; }

/* ─── Logo handoff chooser ─── */
.m-import-title { font-size: 1rem; font-weight: 500; text-align: center; color: var(--c-dark); }
.m-import-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 124px;
  padding: 14px;
  margin: 2px 0;
  background: var(--c-panel);
  border-radius: 12px;
}
/* the lockup arrives solid black; show it as ink on light, white on dark
   (so people don't read the brand two-tone as how the shader will render) */
.m-import-preview svg { max-width: 80%; max-height: 100%; height: auto; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .m-import-preview svg { filter: invert(1); } }
:root[data-theme="dark"] .m-import-preview svg { filter: invert(1); }
/* brand swatches sit small, inline with the "Use my brand colors" label */
.m-import-colors-left { display: flex; align-items: center; gap: 9px; }
.m-import-swatches { display: inline-flex; gap: 5px; }
.m-import-sw { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18); }
.m-import-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 6px;
}
.m-import-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.m-import-apply {
  border: none;
  border-radius: 22px;
  height: 46px;
  background: var(--c-secondary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 3px 12px var(--c-glow);
}
.m-import-dismiss {
  border: none;
  background: none;
  color: var(--c-muted);
  font-size: 0.85rem;
  padding: 6px;
}

/* logo source picker — desktop sidebar row + mobile row */
.logo-src-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo-src-seg { flex: 1; max-width: 230px; }
.logo-src-seg .m-seg-btn { flex: 1; padding: 7px 0; font-size: 0.76rem; }
.m-import-srcrow { padding: 2px 16px 8px; }
.m-import-srcrow .m-seg { display: flex; width: 100%; }
.m-import-srcrow .m-seg-btn { flex: 1; padding: 9px 0; }

/* freeform resize grip — both shells */
.m-resize-handle {
  display: none;
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 12px 0 10px 0;
  background: var(--c-bg);
  color: var(--c-accent);
  box-shadow: 0 1px 6px rgba(0,0,0,0.18);
  touch-action: none;
  cursor: nwse-resize;
  z-index: 5;
}
.m-resize-handle:not(.hidden) { display: flex; }
.m-resize-handle svg { width: 16px; height: 16px; }

/* narrow screens: the Show Logo pill needs the top-right, so the title
   docks beside the hamburger instead of centering behind it */
@media (max-width: 600px) {
  .m-title { left: 74px; transform: none; }
}

/* drawer brand icon: white variant on dark theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .m-drawer-brand .db-color { display: none; }
  :root:not([data-theme]) .m-drawer-brand .db-white { display: block; }
}
:root[data-theme="dark"] .m-drawer-brand .db-color { display: none; }
:root[data-theme="dark"] .m-drawer-brand .db-white { display: block; }
