body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
canvas {
  display: block;
}

/* shadcn/ui design tokens (zinc dark theme) */
#controls {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --border: 240 3.7% 15.9%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --accent: 240 3.7% 15.9%;
  --destructive: 0 72% 51%;
  --ring: 240 4.9% 83.9%;
  --radius: 0.65rem;

  /* Floating card */
  position: fixed;
  top: 20px;
  left: 20px;
  width: 264px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: hsl(var(--card) / 0.92);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  color: hsl(var(--card-foreground));
  font-size: 14px;
  line-height: 1.4;
  user-select: none;
  z-index: 10;
  box-shadow: 0 10px 38px -10px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02);
}

/* Floating button to reopen the hidden panel */
.controls-fab {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid hsl(240 3.7% 15.9%);
  border-radius: 9999px;
  background: hsl(240 10% 3.9% / 0.92);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  color: hsl(0 0% 98%);
  font-size: 18px;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 10px 38px -10px rgba(0, 0, 0, 0.55);
  transition: background 0.15s, transform 0.1s ease;
}

.controls-fab:hover {
  background: hsl(240 3.7% 15.9%);
  transform: scale(1.05);
}

#controls * {
  box-sizing: border-box;
}

/* CardHeader */
.controls-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid hsl(var(--border));
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-description {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

/* Ghost icon button (collapse toggle) */
.controls-header .toggle {
  flex: none;
  width: 28px;
  height: 28px;
  margin-top: -2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: calc(var(--radius) - 0.25rem);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.controls-header .toggle:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

/* CardContent */
.controls-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.label-row label {
  font-size: 13px;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.label-row .value {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

/* shadcn Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: 4px 0;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  cursor: pointer;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 9999px;
  background: hsl(var(--background));
  border: 2px solid hsl(var(--primary));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px hsl(var(--ring) / 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 9999px;
  background: hsl(var(--background));
  border: 2px solid hsl(var(--primary));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-moz-range-track {
  background: transparent;
}

/* shadcn Switch */
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex: none;
  padding: 0;
  border: none;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  cursor: pointer;
  transition: background 0.15s;
}

.switch.on {
  background: hsl(var(--primary));
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 9999px;
  background: hsl(var(--background));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.switch.on .switch-thumb {
  transform: translateX(16px);
}

/* Nested controls under a section toggle */
.sub-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
  transition: opacity 0.15s;
}

.sub-controls.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* Colors */
.colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  position: relative;
  width: 32px;
  height: 32px;
}

.swatch input[type="color"] {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.25rem);
  background: none;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.swatch input[type="color"]:hover {
  transform: scale(1.06);
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: calc(var(--radius) - 0.35rem); }
.swatch input[type="color"]::-moz-color-swatch { border: none; border-radius: calc(var(--radius) - 0.35rem); }

.swatch .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 17px;
  height: 17px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1.5px solid hsl(var(--card));
  border-radius: 9999px;
  background: hsl(var(--destructive));
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.swatch:hover .remove { display: inline-flex; }

/* Ghost icon button (add color) */
.mini {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.25rem);
  background: transparent;
  color: hsl(var(--foreground));
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s;
}

.mini:hover {
  background: hsl(var(--accent));
}

/* Buttons */
.actions {
  display: flex;
  gap: 8px;
  padding-top: 2px;
}

.actions .action {
  flex: 1;
  height: 36px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 0.2rem);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.actions .action.primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.actions .action.primary:hover {
  opacity: 0.9;
}

.actions .action.secondary {
  background: transparent;
  border-color: hsl(var(--border));
  color: hsl(var(--secondary-foreground));
}

.actions .action.secondary:hover {
  background: hsl(var(--accent));
}
