/* ═══════════════════════════════════════════════════════════
   DOTART PRO — Studio Layout (Fusion 360 / Figma style)
   ═══════════════════════════════════════════════════════════ */

/* Design tokens */
:root {
  --bg:            #0F0F0F;
  --surface:       #1A1A1A;
  --surface-2:     #222222;
  --surface-3:     #2C2C2C;
  --border:        #2E2E2E;
  --border-mid:    #3A3A3A;
  --text:          #C0C0C0;
  --text-muted:    #5A5A5A;
  --text-active:   #EBEBEB;
  --accent:        #FF6B00;
  --accent-hover:  #FF8533;
  --accent-dim:    rgba(255,107,0,0.12);
  --success:       #22C55E;
  --warning:       #F59E0B;
  --blue:          #3B82F6;
  --blue-dim:      rgba(59,130,246,0.12);

  --panel-w:  220px;
  --toggle-w: 18px;
  --bar-h:    40px;
  --footer-h: 24px;
  --radius:   3px;
  --font:     -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
}

/* ── Light theme: Fusion 360 / professional CAD palette ── */
[data-theme="light"] {
  --bg:          #E6E9EC;   /* cool-gray viewport — like F360 canvas */
  --surface:     #FFFFFF;   /* white panels */
  --surface-2:   #F4F5F7;   /* inputs, secondary surfaces */
  --surface-3:   #EAECEF;   /* hover states */
  --border:      #DDE1E7;   /* very subtle separators */
  --border-mid:  #C1C7D0;   /* visible but soft */
  --text:        #2C3E50;   /* dark blue-gray */
  --text-muted:  #6B7A8D;   /* medium gray */
  --text-active: #172B4D;   /* near black, blue-tinted */
  --accent:      #2563EB;   /* professional blue — replaces orange in light mode */
  --accent-hover:#1D4ED8;
  --accent-dim:  rgba(37,99,235,0.08);
  --success:     #16A34A;
  --warning:     #D97706;
  --blue:        #2563EB;
  --blue-dim:    rgba(37,99,235,0.08);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════
   STUDIO SHELL
═══════════════════════════════════ */

.studio {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* iOS Safari: dynamic viewport height excludes browser chrome */
  overflow: hidden;
}

/* ─── Status footer ─── */
.studio-footer {
  height: var(--footer-h);
  min-height: var(--footer-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.footer-indicator {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-mid);
  flex-shrink: 0;
  transition: background 0.3s;
}
.footer-indicator.pulse {
  background: var(--accent);
  animation: indicatorPulse 0.6s ease-out forwards;
}
@keyframes indicatorPulse {
  0%   { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1);   opacity: 0.5; }
}

.footer-status {
  font-size: 10px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* ─── Top bar ─── */

.studio-bar {
  height: var(--bar-h);
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  flex-shrink: 0;
}

.bar-sep {
  width: 1px;
  height: 14px;
  background: var(--border-mid);
  flex-shrink: 0;
}

.bar-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-active);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.bar-brand-icon {
  height: 18px;
  width: auto;
  flex-shrink: 0;
}

.bar-brand-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-active);
}

.bar-brand-name em {
  font-style: normal;
  color: var(--accent);
}

.bar-spacer { flex: 1; }

.nav-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-back:hover { color: var(--accent); background: var(--surface-3); }

.theme-toggle {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* Icon visibility: default = dark mode (show moon to switch to light) */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: flex; align-items: center; }
/* In light mode: swap — show sun to switch to dark */
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun  { display: flex; align-items: center; }

/* Lang picker */
.lang-picker { position: relative; flex-shrink: 0; }

.lang-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  height: 28px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.lang-btn:hover { color: var(--accent); border-color: var(--accent); }

.lang-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  min-width: 140px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
[data-theme="dark"] .lang-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,0.55); }
.lang-dropdown.open { display: block; }

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.lang-option:last-child { border-bottom: none; }
.lang-option:hover { background: var(--surface-3); color: var(--accent); }
.lang-flag { font-size: 14px; }

/* ═══════════════════════════════════
   WORKSPACE
═══════════════════════════════════ */

.studio-workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ═══════════════════════════════════
   PANELS
═══════════════════════════════════ */

.studio-panel {
  width: var(--panel-w);
  min-width: var(--panel-w);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.22s cubic-bezier(0.4,0,0.2,1),
              min-width 0.22s cubic-bezier(0.4,0,0.2,1);
  z-index: 10;
}

.studio-panel--left  { border-right: 1px solid var(--border); }
.studio-panel--right { border-left:  1px solid var(--border); }

/* Collapsed via workspace class */
.studio-workspace.left-collapsed  .studio-panel--left  { width: 0; min-width: 0; }
.studio-workspace.right-collapsed .studio-panel--right { width: 0; min-width: 0; }

/* Panel body: scrollable content */
.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 2px; }

/* Panel sections */
.panel-section {
  margin-bottom: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }

.panel-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 10px;
  gap: 4px;
}

/* When section has no toggle (Generate section), keep label spacing normal */
.panel-section.no-toggle .panel-section-label { margin-bottom: 8px; }

/* Collapsible section body */
.section-body {
  overflow: hidden;
  max-height: 800px;
  opacity: 1;
  transition: max-height 0.22s cubic-bezier(0.4,0,0.2,1),
              opacity 0.15s ease;
}

.panel-section.collapsed .section-body {
  max-height: 0;
  opacity: 0;
}

.panel-section.collapsed .panel-section-label {
  margin-bottom: 0;
}

/* Section toggle chevron button */
.section-toggle {
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0;
  flex-shrink: 0;
  opacity: 0.7;
  transition: color 0.15s, opacity 0.15s;
}
.section-toggle:hover { color: var(--accent); opacity: 1; }
.section-toggle svg { transition: transform 0.2s ease; }
.panel-section.collapsed .section-toggle svg { transform: rotate(-90deg); }

/* Label actions group (right side of label with multiple elements) */
.label-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ─── Panel toggle tabs ─── */

.panel-toggle {
  width: var(--toggle-w);
  min-width: var(--toggle-w);
  background: var(--surface-2);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 11;
  transition: color 0.15s, background 0.15s;
}
.panel-toggle:hover { color: var(--accent); background: var(--surface-3); }

.panel-toggle--left  { border-right: 1px solid var(--border); }
.panel-toggle--right { border-left:  1px solid var(--border); }

/* Flip chevron icon on collapse */
.panel-toggle svg { transition: transform 0.22s cubic-bezier(0.4,0,0.2,1); }
.panel-toggle--left.flipped  svg { transform: rotate(180deg); }
.panel-toggle--right.flipped svg { transform: rotate(180deg); }

/* ═══════════════════════════════════
   VIEWPORT (the canvas workspace)
═══════════════════════════════════ */

.studio-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
  /* Dark: line grid */
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: center center;
}

/* Light theme: subtle dot grid (more modern, design-tool feel) */
[data-theme="light"] .studio-viewport {
  background-image: radial-gradient(circle, var(--border-mid) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* Main canvas container — fills entire viewport */
.map-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}
.map-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.map-scroll::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 3px; }

#dotCanvas { display: block; }

/* Floating stats — top center of viewport */
.stats-float {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

/* HUD: bottom-right zoom controls */
.viewport-hud {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 3px;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 4px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
[data-theme="dark"] .viewport-hud { box-shadow: 0 2px 8px rgba(0,0,0,0.5); }

.hud-hint {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.hud-sep {
  width: 1px;
  height: 12px;
  background: var(--border-mid);
  margin: 0 2px;
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-family: inherit;
  line-height: 1;
}
.hud-btn:hover:not(:disabled)  { color: var(--accent); border-color: var(--accent); }
.hud-btn:disabled { opacity: 0.3; cursor: default; }

.hud-btn--3d { color: var(--text); background: var(--surface-3); }
.hud-btn--3d svg { flex-shrink: 0; }

/* Eye icon toggle button */
.hud-btn--eye .eye-open { display: block !important; }
.hud-btn--eye .eye-hidden { display: none !important; }
.hud-btn--eye.hud-btn--active .eye-open { display: none !important; }
.hud-btn--eye.hud-btn--active .eye-hidden { display: block !important; }

/* Active/pressed state for toggle buttons */
.hud-btn--active {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  background: var(--accent-dim) !important;
}

.hud-zoom-label {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Crop hint (used in right panel too) */
.crop-hint {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ═══════════════════════════════════
   FORM CONTROLS
═══════════════════════════════════ */

input[type="file"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
input[type="file"]:focus { border-color: var(--accent); }

select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%235A5A5A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
select:focus { border-color: var(--accent); }

.control-group { margin-bottom: 10px; }
.control-group:last-child { margin-bottom: 0; }

.control-group label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Sliders */
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.slider-header label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 0;
}

.slider-val {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.slider-stepper {
  display: flex;
  align-items: center;
  gap: 3px;
}

.stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid var(--border-mid);
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  user-select: none;
}
.stepper-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.stepper-btn:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border-mid);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  background: var(--accent);
  border-radius: 50%;
  cursor: grab;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 0 0 0 transparent;
}
.slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: grab;
}

.hint {
  display: block;
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.5;
}

/* Geo warning */
.geo-warning {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.4);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 10px;
  color: var(--warning);
  margin-top: 8px;
  line-height: 1.5;
}
.geo-warning.hidden { display: none; }

/* ═══════════════════════════════════
   BUTTONS
═══════════════════════════════════ */

.btn {
  border: none;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* Generate button */
.generate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.btn-generate {
  gap: 6px;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-generate:hover:not(:disabled) { background: var(--accent-hover); }
.btn-generate svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-secondary-action {
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-mid);
  font-size: 9px;
  white-space: nowrap;
}
.btn-secondary-action:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-secondary-action svg { width: 14px; height: 14px; }

/* Icon-style action buttons */
.action-group-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.btn-icon-action {
  flex: 1 1 calc(50% - 2px);
  flex-direction: column;
  gap: 4px;
  padding: 9px 4px;
  border-radius: var(--radius);
  font-size: 9px;
  background: var(--surface-2);
  color: var(--text);
  min-width: 0;
  border: 1px solid var(--border);
}
.btn-icon-action:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-mid);
}
.btn-icon-action svg { width: 15px; height: 15px; }

.btn-blue {
  background: var(--blue-dim);
  color: #3B82F6;
  border-color: rgba(59,130,246,0.2);
}
[data-theme="light"] .btn-blue {
  color: #1D4ED8;
  border-color: rgba(37,99,235,0.25);
}
.btn-blue:hover:not(:disabled) { background: rgba(59,130,246,0.18) !important; }
[data-theme="light"] .btn-blue:hover:not(:disabled) { background: rgba(37,99,235,0.14) !important; }

.btn-accent {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(255,107,0,0.25);
}
.btn-accent:hover:not(:disabled) { background: rgba(255,107,0,0.2) !important; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-mid); }

/* Status panel (legacy — now lives in footer; keep for non-pro pages) */
.panel-status {
  font-size: 10px;
  color: var(--text-muted);
  padding: 8px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 1.6;
  min-height: 34px;
  word-break: break-word;
}

/* Pro: #status is in the footer — reset any panel-status visual */
.studio-footer #status {
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  min-height: 0;
  line-height: 1.4;
}

/* ═══════════════════════════════════
   RIGHT PANEL: UNIT PREVIEW
═══════════════════════════════════ */

.unit-preview-wrap {
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  min-height: 90px;
}

#dotPreviewCanvas {
  display: block;
  max-width: 100%;
  max-height: 150px;
}

/* ─── Source canvas ─── */
.source-canvas-wrap {
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
}

#sourceCanvas {
  display: block;
  max-width: 100%;
}

.btn-crop-reset {
  padding: 2px 6px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.btn-crop-reset:hover { color: var(--accent); border-color: var(--accent); }

/* ═══════════════════════════════════
   PALETTE LIST
═══════════════════════════════════ */

.palette-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}

/*
  Swatch grid — 2 rows × 4 cols:
  ┌──────┬──────────────┬───────┬──────┐
  │ box  │ name / hex   │ count │  ×   │  row 1
  │ box  ├──────────────┴───────┴──────┤
  │      │ H label  ──── slider ──────  │  row 2
  └──────┴────────────────────────────┘

  The anonymous <div> (name+hex) auto-places at row 1 col 2
  because box/count/erase-btn/height all have explicit placement.
*/
.swatch {
  display: grid;
  grid-template-columns: 26px 1fr auto 22px;
  grid-template-rows: auto auto;
  column-gap: 7px;
  row-gap: 4px;
  align-items: start;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.swatch:hover { border-color: var(--border-mid); }
.swatch--erased { opacity: 0.45; }

/* Color box — spans both rows */
.swatch-box {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: stretch;
  width: 26px;
  min-height: 40px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.08);
  position: relative;
  cursor: pointer;
}
[data-theme="dark"] .swatch-box { border-color: rgba(255,255,255,0.07); }
.swatch-box:hover { outline: 2px solid var(--accent); outline-offset: 1px; }

.swatch-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}

.swatch-color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Anonymous div (name + hex) — auto-places at row 1, col 2 */
.swatch-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-active);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swatch-hex {
  font-size: 9px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Count — row 1, col 3 */
.swatch-count {
  grid-column: 3;
  grid-row: 1;
  text-align: right;
  line-height: 1;
}
.swatch-count strong {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-active);
  display: block;
}
.swatch-count span {
  font-size: 9px;
  color: var(--text-muted);
}

/* Erase / restore button — row 1, col 4 */
.swatch-erase-btn {
  grid-column: 4;
  grid-row: 1;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}
.swatch-erase-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Height control — row 2, spanning cols 2-4 */
.swatch-height {
  grid-column: 2 / 5;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch-height-label {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: default;
  user-select: none;
}

.swatch-height-val {
  color: var(--accent);
  font-weight: 700;
}

.swatch-height-input {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border-mid);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.swatch-height-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  cursor: grab;
}
.swatch-height-input::-webkit-slider-thumb:active { cursor: grabbing; }
.swatch-height-input::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: grab;
}

/* ═══════════════════════════════════
   STATS CHIPS (floating in viewport)
═══════════════════════════════════ */

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 5px 10px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
[data-theme="dark"] .stat-card { box-shadow: 0 2px 8px rgba(0,0,0,0.5); }

.stat-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-active);
  line-height: 1.2;
}

/* ═══════════════════════════════════
   3D PREVIEW MODAL
═══════════════════════════════════ */

/* 3D modal: appears inside the studio viewport, not full screen */
#p3d-modal {
  position: fixed;
  top: var(--bar-h);
  left: calc(var(--panel-w) + var(--toggle-w));
  right: calc(var(--panel-w) + var(--toggle-w));
  bottom: var(--footer-h);
  z-index: 50;
  /* Match studio viewport grid — visible for the brief moment before canvas paints */
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  display: flex;
  flex-direction: column;
}

/* Adjust when panels are collapsed */
body:has(.studio-workspace.left-collapsed) #p3d-modal  { left: var(--toggle-w); }
body:has(.studio-workspace.right-collapsed) #p3d-modal { right: var(--toggle-w); }

#p3d-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#p3d-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--bar-h);
  flex-shrink: 0;
  /* Seamless with the studio bar */
  border-top: 1px solid var(--border);
}

#p3d-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-active);
}

#p3d-hint {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

/* Close button: pulled out of the header and placed at bottom-right
   matching the exact position/style of the HUD (where the 3D button lives) */
#p3d-close-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 10;
  /* Match .hud-btn style */
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  height: 28px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#p3d-close-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#p3d-canvas { flex: 1; display: block; min-height: 0; }

#p3d-loader { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: rgba(0,0,0,0.6); }
#p3d-loader.active { display: flex; }

#p3d-loader-card {
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 24px 32px;
  text-align: center;
}

#p3d-loader-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-active);
  margin-bottom: 12px;
}

#p3d-loader-bar-track {
  width: 160px;
  height: 3px;
  background: var(--border-mid);
  margin: 0 auto 12px;
  border-radius: 2px;
}

#p3d-loader-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s;
}

#p3d-loader-sub {
  font-size: 10px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════
   DOT COLOR PICKER (dynamic overlay)
═══════════════════════════════════ */

#dot-color-picker {
  position: fixed;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

.dcp-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.dcp-colors { display: flex; flex-wrap: wrap; gap: 4px; }

.dcp-color {
  width: 22px;
  height: 22px;
  border-radius: 2px;
  border: 1px solid var(--border-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  transition: outline-offset 0.1s;
}
.dcp-color:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.dcp-color--active { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ═══════════════════════════════════
   RESPONSIVE
═══════════════════════════════════ */

@media (max-width: 960px) {
  :root { --panel-w: 200px; }
}

@media (max-width: 700px) {
  .studio-workspace.right-auto .studio-panel--right { width: 0; min-width: 0; }
  :root { --panel-w: 188px; }
  .hud-hint { display: none; }
  .hud-sep:first-of-type { display: none; }
}

/* ── Progress bars: thin top stripe in the viewport ── */
.generate-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
}
.generate-progress.hidden { display: none; }

.progress-track {
  height: 2px;
  width: 100%;
  background: transparent;
  overflow: hidden;
  border-radius: 0;
}
.progress-fill {
  height: 2px;
  width: 0%;
  background: var(--accent);
  border-radius: 0;
  animation: progressFakePro 2.5s ease-in-out infinite;
}
/* progress-text hidden — status now in footer */
.progress-text { display: none; }

@keyframes progressFakePro {
  0%   { width: 0%;  margin-left: 0%; }
  40%  { width: 25%; margin-left: 0%; }
  60%  { width: 40%; margin-left: 35%; }
  80%  { width: 20%; margin-left: 70%; }
  100% { width: 30%; margin-left: 100%; opacity: 0; }
}

/* ═══════════════════════════════════════════════
   Assembly Guide modal
═══════════════════════════════════════════════ */

#guide-modal {
  position: fixed;
  top: var(--bar-h);
  left: calc(var(--panel-w) + var(--toggle-w));
  right: calc(var(--panel-w) + var(--toggle-w));
  bottom: var(--footer-h);
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

body:has(.studio-workspace.left-collapsed)  #guide-modal { left: var(--toggle-w); }
body:has(.studio-workspace.right-collapsed) #guide-modal { right: var(--toggle-w); }

#guide-inner {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Map canvas area */
#guide-map-area {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#guide-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Animated arrow pointing at the current dot */
@keyframes guide-bounce-up {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}
@keyframes guide-bounce-down {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(6px); }
}

#guide-arrow {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  color: #f59e0b;
  filter: drop-shadow(0 0 8px #f59e0baa);
  line-height: 0;
}
#guide-arrow.guide-arrow--up   { animation: guide-bounce-up   0.85s ease-in-out infinite; }
#guide-arrow.guide-arrow--down { animation: guide-bounce-down 0.85s ease-in-out infinite; }

/* Sidebar */
#guide-sidebar {
  width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 16px 16px;
  gap: 14px;
  overflow-y: auto;
}

#guide-sidebar-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Dot info card */
#guide-dot-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

#guide-swatch {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25), inset 0 0 0 2px rgba(255,255,255,0.1);
}

#guide-dot-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#guide-color-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-active);
  line-height: 1.1;
}

#guide-hex-code {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

#guide-position {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Keyboard hint */
#guide-kbd-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.7;
}

/* Progress */
#guide-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#guide-progress-track {
  height: 5px;
  background: var(--border-mid);
  border-radius: 3px;
  overflow: hidden;
}

#guide-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.22s ease;
}

#guide-progress-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Navigation */
#guide-nav {
  display: flex;
  gap: 8px;
  flex: 1;
  align-items: flex-end;
}

.guide-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 40px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.guide-nav-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.guide-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.guide-nav-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.guide-nav-btn--primary:hover:not(:disabled) {
  filter: brightness(1.1);
  color: #fff;
}

/* Close button */
#guide-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  width: 100%;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}

#guide-close-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Responsive */
@media (max-width: 680px) {
  #guide-inner    { flex-direction: column; }
  #guide-sidebar  { width: auto; border-left: none; border-top: 1px solid var(--border); padding: 12px; gap: 10px; flex-shrink: 0; }
  #guide-nav      { align-items: stretch; }
  #guide-swatch   { width: 44px; height: 44px; }
}
