body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Brand / style — floats next to the cog when settings is open. */
#bar.topbar {
  position: fixed;
  top: 8px;
  right: 44px;
  left: auto;
  width: auto;
  z-index: 90;
  max-width: calc(100vw - 100px);
  background: transparent;
  border: none;
  border-bottom: none;
  padding: 0;
  flex-wrap: nowrap;
}
body:not(.bar-open) #bar.topbar { display: none !important; }

/* Side-by-side front / back grid */
main#views {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

/* Per-view panel — canvas fills it; label + controls overlay on top */
.view {
  position: relative;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
  overflow: hidden;
}
.view:last-child { border-right: none; }
.view .canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.view canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
  transform-origin: 0 0;
}
.view.zoomed canvas { cursor: grab; }
.view.zoomed canvas:active { cursor: grabbing; }

/* Per-view layers panel — top-right corner, shows when there's more than one layer */
.view .layers-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: none;
}
.view .layer-row {
  position: relative;
  width: var(--ctrl-h);
  height: var(--ctrl-h);
  padding: 0;
  border: 1px solid var(--border);
  background-color: var(--panel);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  border-radius: var(--radius);
}
.view .layer-row:hover { border-color: var(--fg); }
.view .layer-row.active { outline: 2px solid var(--fg); outline-offset: 1px; }
.view .layer-row .layer-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--panel);
  font-size: 10px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.view .layer-row:hover .layer-remove { display: flex; }
body:not(.bar-open) .view .layers-panel { display: none !important; }

/* Size popover — anchored next to the active design's TR handle */
.view .size-popover {
  position: absolute;
  z-index: 4;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0;
  background: transparent;
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.view .size-popover input.width-cm {
  width: 56px;
  font: inherit;
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  border-radius: var(--radius);
  letter-spacing: 0;
  text-transform: none;
}

/* When the settings cog is off, hide all chrome — only canvas + cog visible. */
body:not(.bar-open) .view .controls,
body:not(.bar-open) .view .size-popover { display: none !important; }

/* Floating left rail — garment color swatches + design tint */
#color-rail {
  position: fixed;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: none;
}
body:not(.bar-open) #color-rail { display: none !important; }
#color-rail .rail-swatches {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#color-rail .rail-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
#color-rail input.design-color {
  width: var(--ctrl-s);
  height: var(--ctrl-s);
  padding: 0;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--panel);
  border-radius: 50%;
  overflow: hidden;
}
#color-rail input.design-color::-webkit-color-swatch-wrapper { padding: 0; }
#color-rail input.design-color::-webkit-color-swatch { border: none; border-radius: 50%; }
#color-rail input.design-color::-moz-color-swatch { border: none; border-radius: 50%; }
#color-rail button.design-color-clear {
  font: inherit;
  font-size: 12px;
  padding: 0;
  width: var(--ctrl-s);
  height: var(--ctrl-s);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  line-height: 1;
}
#color-rail button.design-color-clear:hover { color: var(--fg); background: var(--hover); }

/* Per-view controls row — overlay at the bottom of the canvas */
.view .controls {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  z-index: 3;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 12px;
  color: var(--muted);
}
.view .controls label { display: flex; gap: 8px; align-items: center; }
.view .controls input.text-input { min-width: 140px; }
.view .controls input[type="range"] { width: 100px; }

/* Recent designs — thumbnails for quick re-pick */
.view .controls .recent {
  display: flex;
  gap: 4px;
  margin-left: 4px;
}
.view .controls .recent-item {
  width: var(--ctrl-h);
  height: var(--ctrl-h);
  padding: 0;
  border: 1px solid var(--border);
  background-color: var(--panel);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  border-radius: var(--radius);
}
.view .controls .recent-item:hover { border-color: var(--fg); }
.view .controls .recent-item.active { outline: 2px solid var(--fg); outline-offset: 1px; }
.view .controls .recent-item .recent-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--panel);
  font-size: 10px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.view .controls .recent-item:hover .recent-remove { display: flex; }
.view .controls .recent-item { position: relative; }

/* Colorize / blend toggle groups */
.view .controls .colorize,
.view .controls .blend { display: flex; gap: 0; margin-left: 4px; }
.view .controls .colorize-btn {
  font: inherit;
  font-size: 11px;
  height: var(--ctrl-h);
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--muted);
  border-right-width: 0;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.view .controls .colorize-btn:last-child { border-right-width: 1px; }
.view .controls .colorize-btn.active { background: var(--fg); color: var(--panel); border-color: var(--fg); }
.view .controls .colorize-btn:hover:not(.active) { background: var(--hover); color: var(--fg); }
.view .controls .colorize-picker {
  width: var(--ctrl-h);
  height: var(--ctrl-h);
  padding: 0;
  margin-left: 0;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--panel);
  border-radius: 50%;
  overflow: hidden;
}
.view .controls .colorize-picker::-webkit-color-swatch-wrapper { padding: 0; }
.view .controls .colorize-picker::-webkit-color-swatch { border: none; border-radius: 50%; }
.view .controls .colorize-picker::-moz-color-swatch { border: none; border-radius: 50%; }
.view .controls .colorize-picker.active { outline: 2px solid var(--fg); outline-offset: 1px; }
