/* testpattern.app — GitHub-style dark UI with squared pattern thumbnails */

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #30363d;
  --ink: #e6edf3;
  --ink2: #c9d1d9;
  --dim: #8b949e;
  --faint: #6e7681;
  --rule: #30363d;
  --rule2: #21262d;
  --accent: #58a6ff;
  --accent-bg: rgba(56, 139, 253, 0.15);
  --accent-border: rgba(56, 139, 253, 0.4);
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --font-ui: 'Manrope', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { height: 100%; }

button { font: inherit; color: inherit; cursor: pointer; }

input { font: inherit; color: inherit; }

/* ===== APP SHELL ===== */
.app {
  height: 100vh;
  /* Android Chrome's collapsing toolbar makes 100vh taller than the visual
     viewport, letting users scroll into a black gap below the footer. Cap to
     the dynamic viewport and clip so the shell can't scroll. */
  max-height: 100dvh;
  overflow: hidden;
  display: grid;
  /* Footer row is auto (not a fixed 28px) so the suite badges can wrap to a
     second line in a narrow window instead of being clipped out of view. */
  grid-template-rows: 54px 1fr auto;
}

/* ===== TOP BAR ===== */
.top {
  background: var(--bg2);
  border-bottom: 1px solid var(--rule);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand .mark {
  width: 26px;
  height: 26px;
  display: inline-block;
  line-height: 0;
  flex-shrink: 0;
}
.brand .mark svg {
  width: 100%;
  height: 100%;
  display: block;
}
.brand .ext {
  color: var(--dim);
  font-weight: 400;
  font-family: var(--font-mono);
  font-size: 13px;
  margin-left: 2px;
}
.crumbs {
  font-size: 13px;
  color: var(--ink2);
  font-weight: 500;
}
.crumbs .sep { color: var(--dim); padding: 0 6px; font-weight: 400; }
.crumbs .current { color: var(--ink); font-weight: 600; }

.top-right { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  background: var(--bg3);
  border: 1px solid var(--rule);
  color: var(--ink2);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.icon-btn:hover { background: var(--bg4); border-color: var(--rule); }
.icon-btn .ico { font-family: var(--font-mono); font-size: 11px; color: var(--dim); }

/* ===== MAIN GRID =====
   4-column grid: picker | preview | CUSTOMIZE chip | right panel
   The chip is always visible at the right edge. The right panel collapses to 0
   when state.rightPanelCollapsed is true (toggled via the chip). */
.main {
  display: grid;
  /* Column order: picker · CUSTOMIZE chip · controls · preview.
     Chip + panel sit together on the left; the panel slides out right where the
     chip is, pushing the preview to the right. Browse → customize → result. */
  grid-template-columns: 384px 44px 360px 1fr;
  min-height: 0;
}
.app.right-collapsed .main {
  /* With .ctrl display:none below, only 3 grid items remain — drop to 3 tracks
     so the preview's 1fr fills the freed space. */
  grid-template-columns: 384px 44px 1fr;
}
.app.right-collapsed .ctrl {
  display: none;
}

/* CUSTOMIZE chip — vertical text strip wedged between picker and preview.
   The bar itself is dark; the text sits inside an accent-blue pill for clear visibility. */
.customize-chip {
  background: var(--bg2);
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 0;
  user-select: none;
  font-family: var(--font-ui);
  transition: background 80ms ease;
}
.customize-chip:hover { background: var(--bg3); }
.customize-chip .chip-text {
  /* vertical-lr + rotate(180deg) → reads bottom-to-top, first letter at the bottom.
     Matches book-spine convention so the word is naturally legible when scanning. */
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  background: var(--accent);
  color: #001428;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  padding: 14px 6px;
  border-radius: 6px;
  box-shadow: 0 1px 6px rgba(56, 139, 253, 0.30);
  transition: background 80ms ease, box-shadow 80ms ease;
}
.customize-chip:hover .chip-text {
  background: #79b4ff;
  box-shadow: 0 2px 10px rgba(56, 139, 253, 0.45);
}
/* When the customize panel is open, drop the chip's right border so chip + panel
   read as one continuous surface. */
.app:not(.right-collapsed) .customize-chip {
  border-right: none;
}

/* ===== Preview-area RESOLUTION STRIP ===== */
.pv-res-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.pv-res-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pv-res-presets {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg2);
}
.pv-res-presets button {
  background: transparent;
  border: none;
  border-right: 1px solid var(--rule);
  color: var(--ink2);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 500;
}
.pv-res-presets button:last-child { border-right: none; }
.pv-res-presets button:hover:not(.active) { color: var(--ink); background: var(--bg3); }
.pv-res-presets button.active { background: var(--accent-bg); color: var(--accent); }
.pv-res-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg2);
  padding: 0 8px;
}
.pv-res-custom input {
  width: 60px;
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 4px;
  text-align: center;
  outline: none;
}
.pv-res-custom input:focus { color: var(--accent); }
.pv-res-custom .x { color: var(--dim); font-family: var(--font-mono); font-size: 11px; }

/* ===== Preview-area DOWNLOAD ROW (always visible, even when right panel collapsed)
   Layout: shrunken Download button + labeled chip groups for Format / Range / Quality.
   Wraps to multiple rows on narrow widths. */
.pv-download-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pv-download-btn {
  flex: 1;
  min-width: 140px;
  background: var(--green);
  color: #000;
  border: none;
  padding: 10px 22px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.pv-download-btn:hover { background: #4cc962; }
.pv-download-btn:disabled { opacity: 0.5; cursor: wait; }
.pv-download-btn .ico {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 400;
}

/* Each chip group: label above (or beside) + the chip control */
.pv-chip-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: center;
}
.pv-chip-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  padding-left: 2px;
}
.pv-chip-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  min-width: 36px;
  text-align: right;
}

.pv-format-chip,
.pv-range-chip {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg2);
}
.pv-format-chip button,
.pv-range-chip button {
  background: transparent;
  border: none;
  border-right: 1px solid var(--rule);
  color: var(--ink2);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.pv-format-chip button:last-child,
.pv-range-chip button:last-child { border-right: none; }
.pv-format-chip button:hover:not(.active),
.pv-range-chip button:hover:not(.active) { color: var(--ink); background: var(--bg3); }
.pv-format-chip button.active,
.pv-range-chip button.active { background: var(--accent-bg); color: var(--accent); }

/* JPG quality control — sits in a chip-group (label above) like Format and Range.
   The outer .pv-chip-group is display:none by default; preview.js clears the inline
   style when format=jpg so it reverts to the flex-column layout from .pv-chip-group. */
.pv-quality {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--rule);
  background: var(--bg2);
  border-radius: 6px;
  padding: 0 10px;
  height: 30px;
  width: 220px;
}
.pv-quality input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  margin: 0;
}
.pv-quality .pv-chip-val {
  min-width: 36px;
  text-align: right;
}

/* ===== PICKER (LEFT) ===== */
.picker {
  background: var(--bg);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
}
.picker-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.picker-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.picker-sub {
  font-size: 12px;
  color: var(--dim);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.group { padding: 6px 0; }
.group:not(:first-of-type) { border-top: 1px solid var(--rule); }
/* <summary> with custom caret — hide the default disclosure marker */
.group-label {
  padding: 10px 18px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.group-label::-webkit-details-marker { display: none; }
.group-label:hover { color: var(--text); }
.group-caret {
  display: inline-block;
  font-size: 10px;
  transition: transform 80ms ease;
  width: 10px;
  text-align: center;
}
.group[open] > .group-label .group-caret { transform: rotate(90deg); }
.group-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--dim);
  font-weight: 500;
  letter-spacing: 0.04em;
}
/* "Under Development" group: dim the label to signal it's semi-hidden */
.group-new > .group-label {
  opacity: 0.6;
  font-style: italic;
}
/* Recent group — subtle accent-tinted label so it reads as "your history" */
.group-recent > .group-label .group-label-text { color: var(--accent); }
/* Placeholder shown inside the 'Under Development' group while its lazy-loaded
   pattern modules are being imported. Replaced with thumbnails on resolution. */
.thumbs-loading {
  grid-column: 1 / -1;
  padding: 18px 0;
  text-align: center;
  font-size: 11px;
  color: var(--ink3);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 18px 12px;
}
/* Squared cards — no border-radius, hairline border. Selection: accent border + ring. */
.thumb {
  aspect-ratio: 16 / 9;
  /* Subtle gradient placeholder shown until the IntersectionObserver renders
     the thumb's canvas. Once rendered, the canvas covers this background. */
  background:
    linear-gradient(135deg, rgba(255,255,255,0.04) 0%, transparent 50%),
    #0a0a0a;
  border: 1px solid var(--rule);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: border-color 80ms ease;
}
.thumb:hover { border-color: var(--bg4); }
.thumb.sel {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.thumb canvas, .thumb svg, .thumb .fill {
  width: 100%;
  height: 100%;
  display: block;
}
.thumb-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 30%, transparent);
  color: var(--ink);
  font-size: 10px;
  padding: 8px 4px 4px;
  text-align: center;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.thumb.sel .thumb-name { color: var(--accent); }

/* ===== PREVIEW (CENTER) ===== */
.pv {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;            /* prevent the 1:1 canvas from blowing out the grid cell */
  padding: 16px 20px;
}
.pv-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.pv-title-block { display: flex; flex-direction: column; gap: 2px; }
.pv-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.015em;
}
.pv-subtitle {
  font-size: 12px;
  color: var(--dim);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.pv-actions {
  display: flex;
  gap: 0;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.pv-actions button {
  background: transparent;
  border: none;
  border-right: 1px solid var(--rule);
  color: var(--ink2);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 6px 12px;
  font-weight: 500;
}
.pv-actions button:last-child { border-right: none; }
.pv-actions button:hover:not(.active) { background: var(--bg3); }
.pv-actions button.active { background: var(--accent-bg); color: var(--accent); }
.pv-actions .pv-share-btn { display: inline-flex; align-items: center; gap: 4px; }
.pv-actions .pv-share-btn .ico { font-size: 13px; line-height: 1; }
.pv-actions .pv-share-btn.ok { background: var(--accent-bg); color: var(--accent); }

.pv-frame {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;            /* allow canvas larger than frame to scroll, not expand */
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.pv-frame.scaled-1to1 {
  overflow: auto;
  padding: 0;
  /* In 1:1 the canvas shows at natural pixel size and the frame scrolls.
     Override centering so the canvas anchors at top-left of the scroll area. */
  display: block;
  align-items: initial;
  justify-content: initial;
}

.pv-status {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  color: var(--ink2);
  font-family: var(--font-mono);
  pointer-events: none;
  z-index: 1;
}
.pv-status .dot {
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
}
.pv-status.busy .dot { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.pv-canvas {
  background: #000;
  display: block;
}
.pv-frame:not(.scaled-1to1) .pv-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  /* Default (bilinear) downscale — thin lines stay visible as softer lines instead of
     vanishing entirely under nearest-neighbor sampling. The downloaded file is exact;
     the preview is allowed to interpolate. The "1:1" toggle shows true device pixels. */
  image-rendering: auto;
}
.pv-frame.scaled-1to1 .pv-canvas {
  /* No max constraints — canvas displays at its natural pixel size, frame scrolls. */
  max-width: none;
  max-height: none;
}

.pv-meta {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.pv-meta-cell {
  background: var(--bg);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pv-meta-label {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.pv-meta-value {
  font-size: 13px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.pv-note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--faint);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* ===== CONTROLS (RIGHT) ===== */
.ctrl {
  background: var(--bg);
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.ctrl-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--rule);
}
.ctrl-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-title .badge {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--dim);
  background: var(--bg2);
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--rule);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink2);
  margin-bottom: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-label .v {
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.seg {
  display: flex;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ink2);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 4px;
  font-weight: 500;
}
.seg button:hover:not(.active) { background: var(--bg3); color: var(--ink); }
.seg button.active { background: var(--accent); color: #000; font-weight: 600; }

.res-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.res-preset {
  background: var(--bg2);
  border: 1px solid var(--rule);
  color: var(--ink2);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 4px;
  font-weight: 500;
}
.res-preset:hover { border-color: var(--bg4); color: var(--ink); }
.res-preset.active {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--accent);
}

.res-select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%),
                    linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.res-select:hover { border-color: var(--bg4); color: var(--ink); }
.res-select:focus { border-color: var(--accent); }
.res-select.active { border-color: var(--accent-border); color: var(--accent); }
.res-select option { background: var(--bg2); color: var(--ink); }

.res-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.res-custom input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  text-align: center;
  outline: none;
}
.res-custom input:focus { border-color: var(--accent); }
.res-custom .x { color: var(--dim); }

.filename-box {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  letter-spacing: 0.02em;
  word-break: break-all;
  line-height: 1.5;
}
.filename-box .ext { color: var(--accent); }

.dl-btn {
  width: 100%;
  background: var(--green);
  color: #000;
  border: none;
  padding: 11px 14px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  border-radius: 6px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: -0.005em;
}
.dl-btn:hover { background: #4cc962; }
.dl-btn:disabled { opacity: 0.5; cursor: wait; }
.dl-btn .ico { font-family: var(--font-mono); font-size: 12px; }

.warn {
  margin-top: 10px;
  padding: 9px 12px;
  background: rgba(248, 81, 73, 0.08);
  border: 1px solid rgba(248, 81, 73, 0.35);
  border-radius: 6px;
  font-size: 11px;
  color: var(--ink2);
  line-height: 1.45;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.warn .dot {
  width: 6px;
  height: 6px;
  background: var(--red);
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.warn strong {
  color: var(--red);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  display: block;
  margin-bottom: 2px;
}

/* JPG quality slider */
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}
.range-row .v {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  min-width: 38px;
  text-align: right;
}

/* Color swatches (preset grid + optional custom picker) */
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 4px;
}
.swatch {
  aspect-ratio: 1;
  background: var(--bg2);
  border: 1px solid var(--rule);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 80ms ease;
}
.swatch:hover { border-color: var(--bg4); }
.swatch.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.swatch .color-fill {
  position: absolute;
  inset: 0;
}
.swatch.custom .color-fill {
  background: conic-gradient(from 0deg, #ff3030, #ffea30, #30ff30, #30ffea, #3060ff, #ea30ff, #ff3030);
}
.swatch .swatch-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  font-size: 9px;
  text-align: center;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 2px 1px;
  letter-spacing: 0.02em;
  font-weight: 500;
  pointer-events: none;
}
.swatch.active .swatch-name { color: var(--accent); }
.swatches-custom { margin-top: 8px; }

/* Color input */
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] {
  width: 38px;
  height: 32px;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
}
.color-row input[type="text"] {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  text-transform: uppercase;
}
.color-row input[type="text"]:focus { border-color: var(--accent); }

/* Numeric stepper */
.number-row {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
}
.number-row input {
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  text-align: center;
  outline: none;
  min-width: 0;
}
.number-row .steppers {
  display: grid;
  grid-template-rows: 1fr 1fr;
  border-left: 1px solid var(--rule);
}
.number-row .steppers button {
  background: transparent;
  border: none;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 0 8px;
  line-height: 1;
}
.number-row .steppers button:first-child { border-bottom: 1px solid var(--rule); }
.number-row .steppers button:hover { color: var(--ink); background: var(--bg3); }

/* ===== OVERLAYS ===== */
.overlays-empty {
  font-size: 12px;
  color: var(--dim);
  padding: 8px 0 12px;
  line-height: 1.5;
}
.overlay-list {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.overlay-item {
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg2);
}
.overlay-item.expanded {
  border-color: var(--accent-border);
}
.overlay-head {
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.overlay-head:hover { background: var(--bg3); }
.overlay-icon {
  width: 24px;
  height: 24px;
  background: var(--bg3);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}
.overlay-item.expanded .overlay-icon {
  background: var(--accent);
  color: #000;
}
.overlay-summary {
  font-size: 12px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.overlay-summary .type {
  color: var(--dim);
  margin-right: 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.overlay-remove {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 8px;
  border-radius: 4px;
  cursor: pointer;
}
.overlay-remove:hover {
  color: var(--red);
  border-color: var(--rule);
  background: var(--bg);
}
.overlay-body {
  padding: 12px;
  border-top: 1px solid var(--rule);
  background: var(--bg);
}

.overlay-row-pair {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}
.overlay-size-stack { min-width: 0; }

.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink2);
  cursor: pointer;
}
.overlay-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.overlay-add {
  display: flex;
  gap: 6px;
}
.overlay-add button {
  flex: 1;
  background: var(--bg2);
  border: 1px dashed var(--rule);
  color: var(--ink2);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 8px 4px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.overlay-add button:hover {
  border-color: var(--accent);
  color: var(--accent);
  border-style: solid;
}
.overlay-add button .ico {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* 9-point position grid */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: 90px;
  height: 90px;
}
.pos-grid button {
  background: var(--bg2);
  border: 1px solid var(--rule);
  cursor: pointer;
  padding: 0;
  border-radius: 3px;
  position: relative;
}
.pos-grid button:hover { border-color: var(--bg4); }
.pos-grid button.active {
  background: var(--accent);
  border-color: var(--accent);
}
.pos-grid button::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  background: var(--ink2);
  border-radius: 50%;
}
.pos-grid button.active::after { background: #000; }
.pos-grid button[data-pos="tl"]::after { top: 3px; left: 3px; }
.pos-grid button[data-pos="tc"]::after { top: 3px; left: 50%; transform: translateX(-50%); }
.pos-grid button[data-pos="tr"]::after { top: 3px; right: 3px; }
.pos-grid button[data-pos="ml"]::after { top: 50%; left: 3px; transform: translateY(-50%); }
.pos-grid button[data-pos="mc"]::after { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.pos-grid button[data-pos="mr"]::after { top: 50%; right: 3px; transform: translateY(-50%); }
.pos-grid button[data-pos="bl"]::after { bottom: 3px; left: 3px; }
.pos-grid button[data-pos="bc"]::after { bottom: 3px; left: 50%; transform: translateX(-50%); }
.pos-grid button[data-pos="br"]::after { bottom: 3px; right: 3px; }

.text-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  resize: vertical;
}
.text-input:focus { border-color: var(--accent); }

.file-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 8px;
}
.file-row .file-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.file-btn {
  background: var(--bg3);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}
.file-btn:hover { background: var(--bg4); }

/* photo-list (Reference Photos pattern) */
.photo-list {
  list-style: none;
  padding: 0;
  margin: 0 0 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.photo-list-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 4px;
}
.photo-thumb {
  width: 32px;
  height: 24px;
  object-fit: cover;
  background: #000;
  border-radius: 2px;
}
.photo-name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* color scheme presets — quick-pick combinations of text + pill */
.scheme-presets {
  display: flex;
  gap: 6px;
}
.scheme-preset {
  flex: 1;
  padding: 8px 6px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  background: transparent;
  color: var(--ink);
}
.scheme-preset.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* color picker row — compact picker pill + a few preset chips */
.color-pick-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.color-pick-row input[type="color"] {
  width: 32px;
  height: 28px;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}
.color-chip {
  width: 22px;
  height: 22px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.color-chip:hover { border-color: var(--ink2); }
.color-chip.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* font choice chips */
.font-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.font-choice {
  padding: 6px 8px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg2);
  color: var(--ink2);
  cursor: pointer;
  font-size: 12px;
  text-align: center;
}
.font-choice:hover { color: var(--ink); border-color: var(--bg4); }
.font-choice.active {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
}
.font-choice.font-sans    { font-family: 'Manrope', sans-serif; font-weight: 600; }
.font-choice.font-mono    { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.font-choice.font-display { font-family: 'Bebas Neue', sans-serif; letter-spacing: 0.06em; font-size: 14px; }
.font-choice.font-bold    { font-family: 'Archivo Black', sans-serif; font-size: 11px; }

/* Reset section — destructive action, called out by its red border */
.ctrl-section-reset {
  border-bottom: none;
  padding-top: 20px;
}
.reset-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 12px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-transform: uppercase;
}
.reset-btn:hover {
  background: rgba(248, 81, 73, 0.12);
}
.reset-btn:active {
  background: rgba(248, 81, 73, 0.20);
}
.reset-btn .ico {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
}
.reset-note {
  font-size: 11px;
  color: var(--dim);
  text-align: center;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

/* ===== FOOTER (mirrors videoloop.app — kept identical across the suite) ===== */
.foot{
  flex:0 0 auto;
  background:var(--bg2);border-top:1px solid var(--rule);
  min-height:28px;font-family:var(--font-mono);font-size:11px;color:var(--dim);
  padding:4px 16px;display:flex;align-items:center;justify-content:space-between;
  gap:8px;
}
.foot a{color:var(--dim);text-decoration:none}
.foot a:hover{text-decoration:underline;color:var(--ink2)}
.foot .right{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
.foot .right .sep{color:var(--faint)}
.foot .right [title^="App"],
.foot .right [title^="Git"],
.foot .right [title^="Build"]{color:var(--faint)}
.foot .right [title^="App"]:hover,
.foot .right [title^="Git"]:hover,
.foot .right [title^="Build"]:hover{color:var(--dim);cursor:help}
.foot .feedback-link{color:var(--dim);text-decoration:none}
.foot .feedback-link:hover{color:var(--ink2);text-decoration:underline}
.suite-badges{display:inline-flex;gap:5px;flex-wrap:wrap;align-items:center}
.suite-badges .badge{
  padding:2px 8px;border-radius:3px;
  font-family:var(--font-mono);font-size:10px;
  color:var(--dim);background:var(--bg3);
  border:1px solid var(--rule);text-decoration:none;
  white-space:nowrap;
  letter-spacing:0;
}
.suite-badges .badge:hover{color:var(--ink);border-color:var(--bg4);text-decoration:none}
.suite-badges .badge.current{
  background:rgba(63,185,80,0.15);
  border-color:rgba(63,185,80,0.4);
  color:var(--green);
  pointer-events:none;
}
.sw-status{display:inline-flex;align-items:center;gap:6px;cursor:help}
.sw-status .sw-dot{
  width:7px;height:7px;border-radius:50%;
  background:var(--faint);
  box-shadow:0 0 0 0 transparent;
  transition:background 0.2s ease, box-shadow 0.2s ease;
}
.sw-status .sw-text{color:var(--faint);transition:color 0.2s ease}
.sw-status.green .sw-dot{background:var(--green);box-shadow:0 0 6px rgba(63,185,80,0.5)}
.sw-status.green .sw-text{color:var(--green)}
.sw-status.amber .sw-dot{background:var(--amber);box-shadow:0 0 6px rgba(210,153,34,0.45)}
.sw-status.amber .sw-text{color:var(--amber)}
.sw-status.red .sw-dot{background:var(--red);box-shadow:0 0 6px rgba(248,81,73,0.45)}
.sw-status.red .sw-text{color:var(--red)}
@media (max-width:720px){
  .foot .right [title^="App"],
  .foot .right [title^="Git"],
  .foot .right [title^="Build"]{display:none}
  .foot .right .sep{display:none}
  .sw-status .sw-text{display:none}
}

/* ===== FULLSCREEN OVERLAY ===== */
.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Tap-to-exit was removed (accidental-tap protection); the overlay itself
     is no longer clickable, only the ✕ button is. */
  cursor: default;
}
.fullscreen-overlay .fs-exit {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fullscreen-overlay .fs-exit:hover { background: rgba(0, 0, 0, 0.7); }
.fullscreen-overlay canvas {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  /* Default smoothing — thin grid lines stay visible at non-integer fullscreen scales. */
  image-rendering: auto;
}
.fullscreen-overlay .hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.08em;
  pointer-events: none;
}

/* ===== SCROLLBARS ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--bg4); }

/* ===== RESPONSIVE (mobile drill-down) ===== */
/* ===== Mobile-only elements: hide on desktop ===== */
@media (min-width: 881px) {
  .mobile-bars,
  .size-sheet,
  .mobile-cta,
  .sheet-backdrop,
  .m-sheet-close-overlay {
    display: none !important;
  }
}

/* ===== MOBILE (≤880px) =====
   Layout transforms from desktop grid into a flex column:
   [top bar] → [preview (fixed ~42vh)] → [3 summary bars] → [sticky CTA].
   .picker and .ctrl are re-used as full-screen / bottom-sheet overlays that slide in
   from the bottom when their summary bar is tapped. .size-sheet is mobile-only DOM. */
@media (max-width: 880px) {
  html, body {
    overflow: hidden;
    height: 100%;
    height: 100svh;
  }
  .app {
    display: flex;
    flex-direction: column;
    height: 100svh;
    min-height: 0;
    /* Override the desktop grid template */
    grid-template-rows: none;
  }

  /* ---- Top bar ---- */
  .top {
    flex: 0 0 50px;
    padding: 0 14px;
    gap: 10px;
    padding-top: env(safe-area-inset-top);
    flex-basis: calc(50px + env(safe-area-inset-top));
  }
  .crumbs { display: none; }
  .top-right .icon-btn:not(.fs) { display: none; }
  .brand { font-size: 14px; }
  .brand .ext { font-size: 12px; }

  /* ---- Main becomes flex column anchoring the preview ---- */
  .main {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
    grid-template-columns: none;
  }
  .app.right-collapsed .main { grid-template-columns: none; }

  /* Hide the desktop customize chip on mobile (replaced by Customize summary bar) */
  .customize-chip { display: none; }

  /* ---- Preview anchored at top ---- */
  .pv {
    flex: 0 0 auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .pv-head {
    flex: 0 0 auto;
    margin-bottom: 6px;
  }
  .pv-title { font-size: 13px; line-height: 1.2; }
  .pv-subtitle { display: none; }
  /* Hide desktop-only preview chrome */
  .pv-res-strip,
  .pv-download-row,
  .pv-meta,
  .pv-note,
  .pv-actions { display: none; }
  .pv-frame {
    flex: 0 0 auto;
    height: 38vh;
    padding: 8px;
    border-radius: 6px;
  }
  .pv-status {
    top: 10px;
    left: 10px;
    font-size: 10px;
    padding: 3px 7px;
  }

  /* ---- Picker → full-screen Patterns sheet ---- */
  .picker {
    position: fixed;
    inset: 0;
    z-index: 110;
    background: var(--bg);
    transform: translateY(100%);
    transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
    max-height: none;
    border: none;
    padding-top: calc(env(safe-area-inset-top) + 56px);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app[data-active-sheet="patterns"] .picker { transform: translateY(0); }

  /* ---- Controls → bottom-sheet Customize sheet (preview stays fully visible above) ----
     Capped at 55vh so the preview canvas (38vh) + head + top bar fit comfortably
     above. The sheet itself scrolls internally for long content. */
  .ctrl {
    display: flex !important; /* override .app.right-collapsed { .ctrl display:none } */
    position: fixed;
    inset: auto 0 0 0;
    z-index: 110;
    max-height: 55vh;
    max-height: 55svh;
    background: var(--bg);
    transform: translateY(110%);
    transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
    border: none;
    border-top: 1px solid var(--rule);
    border-radius: 16px 16px 0 0;
    padding-top: 50px; /* leave room for the floating Done button */
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  }
  .app[data-active-sheet="customize"] .ctrl { transform: translateY(0); }

  /* ---- Size sheet (mobile-only DOM) ---- */
  .size-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 110;
    max-height: 70vh;
    max-height: 70svh;
    background: var(--bg);
    border-top: 1px solid var(--rule);
    border-radius: 16px 16px 0 0;
    transform: translateY(110%);
    transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app[data-active-sheet="size"] .size-sheet { transform: translateY(0); }

  /* Shared sheet header */
  .m-sheet-header {
    position: sticky;
    top: 0;
    background: var(--bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rule);
    z-index: 1;
  }
  .m-sheet-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
  }
  .m-sheet-done {
    background: var(--accent);
    color: #001428;
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    min-height: 44px;
    min-width: 80px;
    touch-action: manipulation;
  }
  .m-sheet-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  /* Size sheet specifics */
  .m-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .m-field-label {
    font-size: 11px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.10em;
    font-weight: 600;
  }
  .m-res-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .m-res-btn {
    background: var(--bg2);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--ink);
    font-family: var(--font-ui);
    text-align: left;
    cursor: pointer;
    min-height: 56px;
  }
  .m-res-btn.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
  }
  .m-res-label {
    font-size: 14px;
    font-weight: 600;
  }
  .m-res-dim {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--dim);
  }
  .m-res-btn.active .m-res-dim { color: var(--accent); }
  .m-res-custom {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .m-res-custom input {
    flex: 1;
    background: var(--bg2);
    border: 1px solid var(--rule);
    border-radius: 8px;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 16px; /* prevents iOS Safari auto-zoom */
    padding: 12px;
    text-align: center;
    outline: none;
    min-height: 48px;
  }
  .m-res-custom input:focus { border-color: var(--accent); }
  .m-res-custom .x {
    color: var(--dim);
    font-family: var(--font-mono);
    font-size: 16px;
  }

  /* ---- Summary bars (between preview and CTA) ---- */
  .mobile-bars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    overflow-y: auto;
    min-height: 0;
  }
  .m-bar {
    background: var(--bg2);
    border: 1px solid var(--rule);
    border-radius: 10px;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 100px 1fr auto;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-family: var(--font-ui);
    text-align: left;
    cursor: pointer;
    min-height: 60px;
    touch-action: manipulation;
  }
  .m-bar:active { background: var(--bg3); }
  .m-bar-label {
    font-size: 11px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.10em;
    font-weight: 600;
  }
  .m-bar-value {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--ink);
    font-weight: 500;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .m-bar-chev {
    font-family: var(--font-mono);
    color: var(--accent);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
  }

  /* ---- Sticky bottom CTA ---- */
  .mobile-cta {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(--bg2);
    border-top: 1px solid var(--rule);
  }
  .m-action {
    flex: 1;
    padding: 14px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 14px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 52px;
    touch-action: manipulation;
  }
  .m-action .ico {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 400;
  }
  .m-action-download {
    background: var(--green);
    color: #001408;
  }
  .m-action-download:active { filter: brightness(0.9); }
  .m-action-download:disabled { opacity: 0.55; }
  .m-action-fullscreen {
    background: var(--bg3);
    color: var(--ink);
    border: 1px solid var(--rule);
  }
  .m-action-fullscreen:active { background: var(--bg4); }

  /* ---- Sheet backdrop ---- */
  .sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 105;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
  }
  .app[data-active-sheet="size"] .sheet-backdrop,
  .app[data-active-sheet="customize"] .sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  /* Patterns sheet is full-screen — no backdrop needed */

  /* ---- Floating close button (shown for all sheets) ---- */
  .m-sheet-close-overlay {
    display: none;
    position: fixed;
    top: calc(env(safe-area-inset-top) + 10px);
    right: 14px;
    z-index: 120;
    background: var(--accent);
    color: #001428;
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    min-height: 44px;
    min-width: 90px;
    touch-action: manipulation;
  }
  .app[data-active-sheet] .m-sheet-close-overlay { display: block; }
  /* Hide overlay for Size sheet (it has its own Done button in the header) */
  .app[data-active-sheet="size"] .m-sheet-close-overlay { display: none; }
  /* For the Customize sheet, anchor the Done button to the sheet's top edge so it
     doesn't sit over the preview / top bar — straddles the sheet's rounded corner. */
  .app[data-active-sheet="customize"] .m-sheet-close-overlay {
    top: auto;
    bottom: calc(55vh - 22px);
    bottom: calc(55svh - 22px);
  }

  /* Footer hidden on mobile to reclaim space */
  .foot { display: none; }

  /* When a sheet is open, prevent inputs in the page underneath from accidentally
     getting focus through the backdrop (defensive — the backdrop catches taps). */
  .app[data-active-sheet] .main { pointer-events: none; }
  .app[data-active-sheet] .picker,
  .app[data-active-sheet] .ctrl,
  .app[data-active-sheet] .size-sheet,
  .app[data-active-sheet] .m-sheet-close-overlay,
  .app[data-active-sheet] .sheet-backdrop { pointer-events: auto; }
}

/* ===== SUBMIT CARD ===== */
.submit-card {
  margin: 16px 12px 24px;
  padding: 16px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  background: var(--bg);
}
.submit-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.submit-card-icon {
  font-size: 16px;
  color: var(--accent);
  line-height: 1;
}
.submit-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink2);
  letter-spacing: 0.01em;
}
.submit-card-desc {
  font-size: 11px;
  color: var(--dim);
  margin: 0 0 12px;
  line-height: 1.5;
}
.submit-dropzone {
  border: 1px dashed var(--rule);
  border-radius: 6px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 10px;
}
.submit-dropzone:hover,
.submit-dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.submit-dz-icon {
  font-size: 20px;
  color: var(--dim);
  line-height: 1;
}
.submit-dz-label {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.03em;
}
.submit-dz-sub {
  font-size: 10px;
  color: var(--faint);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}
.submit-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink2);
}
.submit-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.submit-file-clear {
  background: none;
  border: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.submit-file-clear:hover { color: var(--red); }
.submit-notes,
.submit-email {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 7px 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.submit-notes:focus,
.submit-email:focus { border-color: var(--accent); }
.submit-notes::placeholder,
.submit-email::placeholder { color: var(--faint); }
.submit-btn {
  width: 100%;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 6px;
}
.submit-btn:hover:not(:disabled) { background: rgba(56,139,253,0.25); }
.submit-btn:disabled { opacity: 0.5; cursor: default; }
.submit-msg {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--dim);
  min-height: 16px;
}
.submit-msg.ok  { color: var(--green); }
.submit-msg.err { color: var(--red); }
.submit-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  text-align: center;
}
.submit-success-icon {
  font-size: 28px;
  color: var(--green);
}
.submit-success p {
  font-size: 12px;
  color: var(--ink2);
  margin: 0;
  line-height: 1.6;
}
