:root {
  --card-shadow: 6px 0 18px rgba(0, 0, 0, 0.12),
                  2px 0 6px rgba(0, 0, 0, 0.06),
                  0 6px 16px rgba(0, 0, 0, 0.08);
  --card-shadow-hover: 8px 0 22px rgba(0, 0, 0, 0.14),
                       3px 0 10px rgba(0, 0, 0, 0.08),
                       0 8px 20px rgba(0, 0, 0, 0.10);
  --palette-width: 150px;
}

body {
  margin: 0;
  font-family: sans-serif;
  background: #000;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  position: relative;
}

/* Subtle frosted overlay above video, below UI */
#app::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0; /* video is -1, UI is 2 */
  pointer-events: none;
  background: rgba(254, 254, 254, 0.611);
  backdrop-filter: blur(3px) saturate(1.02);
  -webkit-backdrop-filter: blur(3px) saturate(1.02);
}

.background-video {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -1;
  opacity: 1;
}

#palette {
  width: var(--palette-width);
  background: rgba(255, 255, 255, 0.85);
  border-right: 1px solid #ddd;
  padding: 12px;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* subtle 3D effect casting to the right */
  box-shadow: var(--card-shadow);
}

#palette h3 {
  margin-top: 0;
  font-size: 14px;
  font-weight: bold;
}

#palette-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 10px 6px; /* extra right padding avoids shadow clipping */
  /* hide scrollbars while keeping scroll */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
#palette-list::-webkit-scrollbar { /* Chrome/Safari */
  width: 0;
  height: 0;
}

.palette-item {
  padding: 8px;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08); /* subtle separator */
  cursor: grab;
  user-select: none;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s ease;
  box-shadow: none; /* no shadows on element cards */
  position: relative;
}

.palette-item:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: none; /* no hover shadow */
  border-color: rgba(0, 0, 0, 0.15);
}

.palette-item .palette-thumb {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: none;
  background: transparent; /* no colored background behind images */
  pointer-events: none; /* ensure dragging works from parent */
  max-height: 72px;
  object-fit: contain;
}

.palette-item .label {
  margin-top: 4px;
  font-size: 11px;
  color: #333;
  text-align: center;
}

/* Video overlay play icon */
.palette-item.is-video::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0; height: 0;
  border-left: 14px solid rgba(0,0,0,0.75);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  pointer-events: none;
}

/* Palette navigation arrows */
.palette-nav {
  appearance: none;
  border: none;
  background: #fff;
  border-radius: 10px;
  box-shadow: none; /* remove shadows around nav arrows */
  width: 100%;
  height: 22px;
  position: relative;
  cursor: pointer;
}
.palette-nav::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 0; height: 0;
  border-left: 6px solid rgba(0,0,0,0.7);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}
.palette-nav.up::before { transform: translate(-50%, -50%) rotate(-90deg); }
.palette-nav.down::before { transform: translate(-50%, -50%) rotate(90deg); }

/* Zoom controls */
.zoom-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 6px 10px;
  z-index: 10; /* above canvas-actions */
  pointer-events: auto;
}
.zoom-controls button {
  appearance: none;
  border: 1px solid rgba(0,0,0,0.1);
  background: #fff;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.zoom-controls input[type="range"] {
  width: 140px;
}
.zoom-controls #zoom-label {
  font-size: 12px;
  color: #555;
  min-width: 40px;
  text-align: right;
}

/* Palette actions (e.g., Clear Canvas) */
.palette-action {
  appearance: none;
  border: none;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  width: 100%;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.palette-action:hover {
  box-shadow: var(--card-shadow-hover);
}

/* Canvas actions (fixed position under canvas area) */
.canvas-actions {
  position: absolute;
  left: calc(var(--palette-width) + 40px); /* align with canvas left (40px margin) */
  right: 40px; /* align with canvas right margin */
  bottom: 16px;
  z-index: 3;
  text-align: center; /* center the button horizontally under canvas */
  /* Let only the inner button receive pointer events so this wrapper
     doesn't block clicks on zoom controls at the bottom-right */
  pointer-events: none;
}
.canvas-action {
  appearance: none;
  border: none;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  pointer-events: auto; /* re-enable on the actual button */
}
.canvas-action:hover {
  box-shadow: var(--card-shadow-hover);
}

#canvas {
  flex: 1;
  margin: 40px; /* leaves video visible around edges */
  position: relative;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  overflow: hidden; /* stage larger than viewport, hidden edges */
  padding: 20px;
  box-sizing: border-box;
  z-index: 2;
  box-shadow: var(--card-shadow);
}

#canvas-viewport {
  position: absolute;
  inset: 20px; /* match canvas padding */
  overflow: visible;
}

#canvas-surface {
  --canvas-zoom: 1;
  --canvas-zoom-inverse: 1;
  position: relative;
  width: 2000px;
  height: 2000px;
  transform-origin: 0 0;
  will-change: transform;
  background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  border-radius: 12px;
}

.component {
  position: absolute;
  padding: 0; /* no internal padding; resizing affects content directly */
  border: 1px solid transparent;
  background: transparent; /* no background on placed components */
  user-select: none;
  border-radius: 10px;
  box-shadow: none; /* no shadow on placed components */
  transition: background 0.15s ease, box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.component:hover {
  border-color: transparent; /* cleaner look: rely on shadow only */
  background: transparent;
  box-shadow: none;
}

/* Resize handles (appear on hover) */
.component .resize-handle {
  position: absolute;
  width: calc(10px * var(--canvas-zoom-inverse, 1));
  height: calc(10px * var(--canvas-zoom-inverse, 1));
  background: #4a90e2;
  border: solid #fff;
  border-width: calc(2px * var(--canvas-zoom-inverse, 1));
  border-radius: calc(2px * var(--canvas-zoom-inverse, 1));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.component:hover .resize-handle {
  opacity: 1;
}

/* Corner and edge positions */
.resize-handle.se {
  right: calc(-6px * var(--canvas-zoom-inverse, 1));
  bottom: calc(-6px * var(--canvas-zoom-inverse, 1));
  cursor: se-resize;
}
.resize-handle.e {
  right: calc(-6px * var(--canvas-zoom-inverse, 1));
  top: 50%;
  transform: translateY(-50%);
  cursor: e-resize;
}
.resize-handle.s {
  left: 50%;
  bottom: calc(-6px * var(--canvas-zoom-inverse, 1));
  transform: translateX(-50%);
  cursor: s-resize;
}
/* Add remaining corner handles */
.resize-handle.ne {
  right: calc(-6px * var(--canvas-zoom-inverse, 1));
  top: calc(-6px * var(--canvas-zoom-inverse, 1));
  cursor: ne-resize;
}
.resize-handle.nw {
  left: calc(-6px * var(--canvas-zoom-inverse, 1));
  top: calc(-6px * var(--canvas-zoom-inverse, 1));
  cursor: nw-resize;
}
.resize-handle.sw {
  left: calc(-6px * var(--canvas-zoom-inverse, 1));
  bottom: calc(-6px * var(--canvas-zoom-inverse, 1));
  cursor: sw-resize;
}
/* Add remaining edge handles */
.resize-handle.n {
  top: calc(-6px * var(--canvas-zoom-inverse, 1));
  left: 50%;
  transform: translateX(-50%);
  cursor: n-resize;
}
.resize-handle.w {
  left: calc(-6px * var(--canvas-zoom-inverse, 1));
  top: 50%;
  transform: translateY(-50%);
  cursor: w-resize;
}

