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

:root {
  --bg: #0a0c10;
  --glass: rgba(18, 21, 26, 0.62);
  --glass-strong: rgba(18, 21, 26, 0.86);
  --glass-hover: rgba(255, 255, 255, 0.06);
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-bright: rgba(255, 255, 255, 0.14);
  --text: #ecedef;
  --text-muted: #8a8f99;
  --text-dim: #5b6068;
  --accent: #7aa8ff;
  --accent-hover: #95bcff;
  --accent-glow: rgba(122, 168, 255, 0.22);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255,255,255,0.04) inset;
  --shadow-elevated: 0 24px 60px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255,255,255,0.04) inset;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  /* Aliases — older form/modal CSS still references these names */
  --bg-input: rgba(0, 0, 0, 0.32);
  --border: var(--hairline);
  --border-light: var(--hairline-bright);
  --panel: rgba(18, 21, 26, 0.92);
  --panel-2: rgba(20, 23, 28, 0.94);
}

html, body { height: 100%; overflow: hidden; }

body {
  font: 13px/1.5 "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  position: relative;
  height: 100vh;
}

/* =====================================================================
   FLOATING CHROME — every element below floats over the full-screen stage
   ===================================================================== */

/* --- Brand mark (top-left) ---------------------------------------------- */
.brand-mark {
  position: fixed;
  top: 22px;
  left: 22px;
  z-index: 100;
  pointer-events: none;
  user-select: none;
}
.brand-text {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--text);
  line-height: 1;
}
.brand-sub {
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 3px;
}

/* --- Toolbar (top-right) ------------------------------------------------ */
.toolbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.seg {
  display: flex;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 2px;
  margin-right: 4px;
}
.seg-btn {
  padding: 5px 12px;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font: 600 11px/1 inherit;
  letter-spacing: 0.04em;
  transition: color 0.12s, background 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: rgba(255, 255, 255, 0.92);
  color: #0a0a0a;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--hairline);
  margin: 0 2px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.12s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--glass-hover); }
.icon-btn:active { transform: scale(0.94); }

/* --- Vertical icon rail (left) ----------------------------------------- */
.rail {
  position: fixed;
  top: 50%;
  left: 18px;
  transform: translateY(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.rail-btn {
  position: relative;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 9px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.14s, background 0.14s;
}
.rail-btn:hover { color: var(--text); background: var(--glass-hover); }
.rail-btn.active {
  color: var(--accent);
  background: var(--accent-glow);
  box-shadow: inset 0 0 0 1px rgba(122, 168, 255, 0.28);
}

.rail-spacer {
  height: 1px;
  background: var(--hairline);
  margin: 6px 6px;
}

/* --- Slide-in drawer (left, beside the rail) --------------------------- */
.drawer {
  position: fixed;
  top: 18px;
  left: 76px;
  bottom: 84px;
  width: 340px;
  z-index: 99;
  background: var(--glass-strong);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateX(-10px) scale(0.985);
  transform-origin: left center;
  pointer-events: none;
  transition: opacity 0.18s var(--ease-out),
              transform 0.24s var(--ease-out);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
}
.drawer.open {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.drawer-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}
.drawer-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  border-radius: 6px;
  transition: color 0.12s, background 0.12s;
}
.drawer-close:hover {
  color: var(--text);
  background: var(--glass-hover);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 22px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.drawer-body::-webkit-scrollbar { width: 8px; }
.drawer-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10);
  border-radius: 4px;
}
.drawer-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.18);
}

.panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
.panel.hidden { display: none; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* Single-column drawer layout — span 1 instead of 2. */
.field.wide { grid-column: span 1; }

.field > label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.005em;
  font-weight: 500;
  white-space: nowrap;
  text-transform: none;
}

.field > label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
  margin-top: 12px;
  cursor: pointer;
}

/* LED panel: header rows that introduce the Front / Wall glow sub-groups */
.field.led-group-header {
  grid-column: span 1;
  border-top: 1px solid var(--hairline);
  padding-top: 14px;
  margin-top: 8px;
}
.field.led-group-header:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.field.led-group-header > label.check {
  margin-top: 0;
  font-size: 13px;
  color: var(--text);
}
.field.led-group-header > label.check strong {
  font-weight: 600;
  letter-spacing: -0.005em;
}

/* Small caption under file pickers, etc. */
.field > .hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.5;
}

input[type="file"] {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.row > input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 4px;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  height: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.row > input[type="number"] {
  width: 62px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.row > input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.row > input[type="number"]::-webkit-outer-spin-button,
.row > input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.row > input[type="number"] { -moz-appearance: textfield; }

.row > select {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12.5px;
  font: inherit;
  cursor: pointer;
}
.row > select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.row > input[type="color"] {
  flex: 1;
  height: 32px;
  background: var(--bg-input);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 3px;
  cursor: pointer;
}
.row > input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.row > input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.row > .unit {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-small {
  padding: 7px 14px;
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.005em;
  transition: background 0.12s, transform 0.08s;
}
.btn-small:hover { background: var(--accent-hover); }
.btn-small:active { transform: scale(0.96); }

.btn-block { display: flex; width: 100%; justify-content: center; align-items: center; }

.btn-outline {
  background: transparent !important;
  color: var(--text) !important;
  border: 1px solid var(--hairline-bright) !important;
}
.btn-outline:hover {
  background: var(--glass-hover) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* --------- Shape picker (Shape tab) --------- */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.shape-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, color 0.14s;
  color: var(--text-muted);
}
.shape-card:hover {
  border-color: var(--hairline-bright);
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
}
.shape-card.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(122, 168, 255, 0.32);
}
.shape-card svg {
  width: 48px;
  height: 36px;
  color: inherit;
}
.shape-card-name {
  font-size: 11px;
  font-weight: 500;
  color: inherit;
  letter-spacing: 0.005em;
}

/* --------- Gallery Builder progress (Generator tab) --------- */
.gen-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(122, 168, 255, 0.06);
  border: 1px solid rgba(122, 168, 255, 0.25);
  border-radius: 8px;
}
.gen-progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
.gen-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.18s ease-out;
}
.gen-progress-text {
  font-size: 11.5px;
  color: var(--text);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

/* --------- Custom pattern list (Generator tab) --------- */
.custom-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.custom-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 14px 12px;
  text-align: center;
  border: 1px dashed var(--hairline);
  border-radius: 8px;
}
.custom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  transition: border-color 0.12s, background 0.12s;
}
.custom-item:hover { border-color: var(--hairline-bright); background: rgba(0, 0, 0, 0.32); }
.custom-item-name {
  flex: 1;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.custom-item-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.custom-item-apply,
.custom-item-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  flex-shrink: 0;
}
.custom-item-apply:hover { color: var(--accent); border-color: var(--accent); }
.custom-item-del:hover { color: #ff7a7a; border-color: #ff7a7a; }

/* --------- Stage (view area) --------- */

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#canvas.hidden { display: none; }

#view2d {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
#view2d.hidden { display: none; }

#view2d svg {
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 4px 24px rgba(0, 0, 0, 0.5));
  border-radius: 4px;
}

/* --------- Camera button --------- */

.camera-btn {
  position: fixed;
  top: 74px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--glass);
  border: 1px solid var(--hairline);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-shadow: var(--shadow-soft);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.camera-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0a;
}
.camera-btn:active { transform: scale(0.95); }
.camera-btn.hidden { display: none; }
.camera-btn.flash {
  animation: cameraFlash 0.4s ease-out;
}
@keyframes cameraFlash {
  0%   { box-shadow: 0 0 0 0 var(--accent); background: var(--accent); color: #0a0a0a; }
  100% { box-shadow: 0 0 0 24px rgba(106, 169, 255, 0); }
}

/* --------- Gallery view --------- */

#galleryView {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
}
#galleryView.hidden { display: none; }

/* When the gallery panel is showing, hide the floating chrome — the top-right
   view-toggle + render/dxf buttons aren't relevant in the gallery, and the
   bottom light dock would float over the grid. Pad the left edge so the
   vertical nav rail (icon column) keeps its space and doesn't sit on top of
   the leftmost gallery cards. */
body.gallery-mode .toolbar { display: none; }
body.gallery-mode #dock { display: none; }
body.gallery-mode #galleryView { padding-left: 80px; }
body.gallery-mode #cameraBtn { display: none; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* Shape-filter tab bar — sits above the grid; each tab shows the shape name
   and a count badge so the user can see at a glance how many designs exist
   per shape. */
.gallery-shape-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.shape-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 12px 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  letter-spacing: 0.02em;
}
.shape-tab:hover {
  color: var(--text);
  border-color: var(--border-light);
}
.shape-tab.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}
.shape-tab-count {
  background: rgba(255, 255, 255, 0.07);
  color: inherit;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.shape-tab.active .shape-tab-count {
  background: rgba(122, 168, 255, 0.18);
}

.gallery-item {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.gallery-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.gallery-item-thumb {
  position: relative;
}
.gallery-item img {
  width: 100%;
  display: block;
  background: #15181d;
  aspect-ratio: 1;
  object-fit: contain;
  transition: background 0.18s;
}

/* Locked-for-production: dark blue thumbnail background + border accent so
   approved designs stand out at a glance in a long gallery. */
.gallery-item.locked {
  border-color: #2447a8;
  box-shadow: 0 0 0 1px rgba(36, 71, 168, 0.4) inset;
}
.gallery-item.locked img {
  background: #0e2148;
}
.gallery-item.locked .gallery-item-meta {
  background: #16213d;
  border-top-color: #2447a8;
}

.gallery-item-lock {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.gallery-item-lock svg { fill: none; stroke: currentColor; stroke-width: 2; }
.gallery-item-lock:hover {
  background: rgba(0, 0, 0, 0.75);
  transform: scale(1.08);
}
.gallery-item-lock.locked {
  color: #fff;
  background: #2447a8;
}
.gallery-item-lock.locked:hover { background: #2e58c7; }

.gallery-item-locked-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 10px;
  letter-spacing: 0.08em;
  font-weight: 600;
  text-transform: uppercase;
  background: #2447a8;
  color: #fff;
  padding: 3px 8px;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.gallery-item-labels {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.gallery-item-labels strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-item-sub {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-item-like {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.gallery-item-like svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.gallery-item-like:hover {
  background: rgba(0, 0, 0, 0.75);
  transform: scale(1.08);
}
.gallery-item-like.liked {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.18);
}
.gallery-item-like.liked svg {
  fill: currentColor;
}
.gallery-item-like.pop svg {
  animation: heartPop 0.35s ease-out;
}
@keyframes heartPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.4); }
  70%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.gallery-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.gallery-item-meta strong {
  color: var(--text);
  font-weight: 500;
}
.gallery-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.gallery-item-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
}
.gallery-item-delete:hover { color: #f87171; background: rgba(248,113,113,0.1); }

.gallery-item-rerender {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.gallery-item-rerender svg { display: block; }
.gallery-item-rerender:hover:not(:disabled) {
  color: var(--accent);
  background: var(--accent-glow);
}
.gallery-item-rerender:disabled { cursor: default; opacity: 0.7; }
.gallery-item-rerender.spinning svg { animation: rerenderSpin 0.9s linear infinite; }

@keyframes rerenderSpin {
  to { transform: rotate(360deg); }
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.gallery-empty p { margin-top: 6px; font-size: 12px; }

.gallery-info {
  font-size: 12.5px;
  color: var(--text-muted);
}

.btn-danger {
  background: #3a2326 !important;
  color: #f87171 !important;
  border: 1px solid #5a3338 !important;
}
.btn-danger:hover { background: #4a2a2e !important; }

/* --------- Modal --------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 12, 0.85);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: min(1600px, 96vw);
  height: 96vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  overflow: hidden;
}
.modal-preview svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.modal-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.modal-meta { font-size: 13px; color: var(--text); }
.modal-meta strong { font-weight: 500; }
.modal-meta .meta-sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.modal-actions { display: flex; gap: 8px; align-items: center; }

/* "LOCKED" pill next to the modal headline */
.modal-lock-pill {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  background: #2447a8;
  color: #fff;
  padding: 2px 7px;
  border-radius: 3px;
  vertical-align: middle;
}

/* Lock toggle button in the modal — active state matches the gallery accent */
.modal-lock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.modal-lock-btn.locked {
  background: #2447a8 !important;
  color: #fff !important;
  border-color: #2e58c7 !important;
}
.modal-lock-btn.locked:hover { background: #2e58c7 !important; }

/* Re-render button — matches the rest of the action row, animates while busy */
.modal-rerender-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.modal-rerender-btn.spinning svg { animation: rerenderSpin 0.9s linear infinite; }
.modal-rerender-btn:disabled { cursor: default; opacity: 0.75; }

/* Production metadata form lives inside the modal-info footer. Use CSS
   order to slot it on its own row below meta + actions while preserving a
   sensible DOM order for keyboard / screen-reader navigation. */
.modal-prod-form {
  order: 2;  /* meta=default(0), actions=default(0), form below both */
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 12px;
}
.modal-actions { order: 1; }
.modal-meta { order: 0; }
.modal-prod-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.modal-prod-row label {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}
.modal-prod-row label.full-width { flex: 1 1 100%; }
.modal-prod-row input[type="text"],
.modal-prod-row textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12.5px;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  min-height: 0;
}
.modal-prod-row input[type="text"]:focus,
.modal-prod-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.modal-prod-row textarea { line-height: 1.4; }

.modal-prod-status {
  font-size: 11px;
  color: #6ee7b7;
  min-height: 14px;
  letter-spacing: 0.02em;
}

/* Side-by-side 2D / 3D preview pair inside the modal. The pair fills the
   modal preview area; each cell stretches equally and has a small label
   above the rendered image so the user knows which is which. */
.modal-preview-pair {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 18px;
  background: var(--bg);
}
.modal-preview-cell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  gap: 8px;
}
.modal-preview-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
  padding-left: 2px;
}
.modal-preview-pair .modal-preview {
  flex: 1;
  min-height: 0;
  padding: 12px;
  background: #0f1116;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.modal-preview-3d img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
}
.modal-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
}
.modal-preview-empty .meta-sub { font-size: 11px; }
.modal-preview-spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: modalSpin 0.8s linear infinite;
}
@keyframes modalSpin {
  to { transform: rotate(360deg); }
}

/* "Set render position" button flash — confirms a click captured the camera */
#setRenderPos.flash {
  background: var(--accent) !important;
  color: #0a0a0a !important;
  box-shadow: 0 0 0 3px var(--accent-glow);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.btn-primary-small {
  background: var(--accent) !important;
  color: #0a0a0a !important;
  border: none !important;
  font-weight: 500;
}
.btn-primary-small:hover { background: var(--accent-hover) !important; }

.btn-like {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #23272e !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.btn-like svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.btn-like:hover { background: #2c3038 !important; }
.btn-like.liked {
  background: rgba(244, 63, 94, 0.15) !important;
  color: #f43f5e !important;
  border-color: rgba(244, 63, 94, 0.4) !important;
}
.btn-like.liked svg { fill: currentColor; }
.btn-like.pop svg { animation: heartPop 0.35s ease-out; }

.modal-close,
.modal-arrow {
  position: absolute;
  z-index: 2;
  background: rgba(26, 29, 34, 0.92);
  border: 1px solid var(--border-light);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.modal-close {
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
}
.modal-arrow {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
}
.modal-arrow-prev { left: 24px; }
.modal-arrow-next { right: 24px; }
.modal-close:hover,
.modal-arrow:not(:disabled):hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0a;
}
.modal-close:active { transform: scale(0.94); }
.modal-arrow:active:not(:disabled) { transform: translateY(-50%) scale(0.94); }
.modal-arrow:disabled { opacity: 0.3; cursor: default; }


/* --------- Floating bottom dock (lighting) --------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-soft);
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  min-width: 0;
}

.dock-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  min-width: 38px;
}

.dock-dim {
  width: 130px;
  height: 4px;
}

.dock-value {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
}

.dock-divider {
  width: 1px;
  height: 20px;
  background: var(--hairline);
}

/* Toggle switch — premium pill style */
.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline);
  transition: background 0.18s var(--ease-out), border-color 0.18s;
}
.switch-track::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: #d0d3d8;
  border-radius: 50%;
  transition: left 0.18s var(--ease-out), background 0.18s, box-shadow 0.18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .switch-track::before {
  left: 16px;
  background: #ffffff;
}