:root {
  color-scheme: dark;
  --bg-solid: #262827;
  --scene-scale: 1;
  --cursor-size: 30px;
  --accent: #ff6a48;
  --panel: rgba(22, 24, 26, 0.86);
  --text: #f7f7f7;
  --muted: #a9acb0;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: transparent;
}

button,
input,
select {
  font: inherit;
}

/* ---------- Stage + backgrounds ---------- */

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-width: 760px;
  min-height: 350px;
  overflow: hidden;
  color: var(--text);
  background-color: transparent;
}

.stage.has-demo-cursor {
  cursor: none;
}

.stage.has-demo-cursor * {
  cursor: none !important;
}

.stage.bg-grid {
  background:
    linear-gradient(rgba(0, 0, 0, 0.24) 2px, transparent 2px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.24) 2px, transparent 2px),
    var(--bg-solid);
  background-size: calc(126px * var(--scene-scale)) calc(82px * var(--scene-scale));
}

.stage.bg-green {
  background: #00b140;
}

.stage.bg-solid {
  background: var(--bg-solid);
}

.stage.bg-transparent {
  background: transparent;
}

/* ---------- Demo cursor ---------- */

.demo-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  width: var(--cursor-size);
  height: var(--cursor-size);
  pointer-events: none;
  opacity: 0;
  --cursor-x: -999px;
  --cursor-y: -999px;
  transform: translate(var(--cursor-x), var(--cursor-y));
  transition: opacity 120ms ease;
}

.stage.has-demo-cursor .demo-cursor {
  opacity: 1;
}

.demo-cursor.cursor-arrow {
  width: calc(var(--cursor-size) * 0.72);
  height: var(--cursor-size);
  transform-origin: 0 0;
}

.demo-cursor.cursor-arrow::before {
  content: "";
  position: absolute;
  inset: 0;
  background: white;
  clip-path: polygon(0 0, 0 83%, 24% 62%, 38% 100%, 54% 94%, 40% 58%, 72% 58%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.75));
}

.demo-cursor.cursor-ring {
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.demo-cursor.cursor-dot {
  width: calc(var(--cursor-size) * 0.52);
  height: calc(var(--cursor-size) * 0.52);
  border-radius: 50%;
  background: white;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.demo-cursor.click-shrink {
  transform: translate(var(--cursor-x), var(--cursor-y)) scale(0.72);
}

.demo-cursor.cursor-arrow.click-shrink {
  transform-origin: 0 0;
}

.demo-cursor.click-pulse::after {
  content: "";
  position: absolute;
  inset: -10px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  animation: cursor-pulse 360ms ease-out;
}

.demo-cursor.cursor-arrow.click-pulse::after {
  left: 0;
  top: 0;
  width: var(--cursor-size);
  height: var(--cursor-size);
  inset: auto;
  transform: translate(-50%, -50%);
  transform-origin: center;
  animation: cursor-arrow-tip-pulse 360ms ease-out;
}

@keyframes cursor-pulse {
  from {
    opacity: 0.9;
    transform: scale(0.4);
  }

  to {
    opacity: 0;
    transform: scale(1.45);
  }
}

@keyframes cursor-arrow-tip-pulse {
  from {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.35);
  }

  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.35);
  }
}

/* ---------- Control panel ---------- */

.panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms ease;
}

.stage[data-controls="hidden"] .panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
}

.panel-head {
  position: sticky;
  top: -14px;
  z-index: 5;
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  gap: 8px;
  align-items: center;
  margin: -14px -14px 12px;
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(22, 24, 26, 0.96);
  backdrop-filter: blur(18px);
}

.panel-head strong {
  font-size: 13px;
}

.icon-button,
.floating-toggle {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  text-decoration: none;
}

.icon-button {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.floating-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 160ms ease;
}

.stage[data-controls="hidden"] .floating-toggle {
  opacity: 1;
  visibility: visible;
}

/* ---------- Control groups ---------- */

.control-group {
  display: grid;
  gap: 8px;
  padding: 10px 0 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.control-group:last-of-type {
  border-bottom: 0;
}

.group-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.segmented button {
  min-height: 28px;
  padding: 0 6px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button:hover {
  color: white;
  background: rgba(255, 255, 255, 0.07);
}

.segmented button.active {
  color: white;
  background: rgba(255, 255, 255, 0.17);
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: var(--swatch-color, #444);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.active {
  box-shadow: 0 0 0 2px rgba(10, 10, 10, 0.9), 0 0 0 4px white;
}

.swatch.custom {
  position: relative;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background:
    conic-gradient(#ff5e5e, #ffc24a, #7fe04b, #41bdf0, #b56df5, #ff5e5e);
}

.swatch.custom input[type="color"] {
  position: absolute;
  inset: -6px;
  min-height: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.zoom-row {
  display: grid;
  grid-template-columns: 28px 1fr 28px 44px;
  align-items: center;
  gap: 8px;
}

.zoom-row button {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.zoom-row button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.zoom-value {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.slider-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 8px;
}

.slider-row label,
.field-row label {
  color: var(--muted);
  font-size: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 8px;
}

input[type="text"],
input[type="color"] {
  width: 100%;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  color: white;
  background: rgba(0, 0, 0, 0.22);
}

input[type="text"] {
  padding: 0 8px;
}

input[type="range"] {
  width: 100%;
}

.file-row {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.file-row input[type="file"] {
  width: 100%;
  color: var(--muted);
  font-size: 11px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 7px;
  color: white;
  font-size: 12px;
}

.panel-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.panel-actions button {
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.panel-actions button:hover,
.icon-button:hover,
.floating-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

@media (max-width: 860px) {
  .stage {
    min-width: 0;
  }

  .panel {
    left: 12px;
    right: 12px;
    top: 12px;
    width: auto;
  }
}
