:root {
  --bg: #05080f;
  --panel-bg: rgba(10, 15, 26, 0.72);
  --panel-border: rgba(148, 210, 255, 0.16);
  --text-main: #edf5ff;
  --text-dim: #8da4c4;
  --accent: #5cd4ff;
  --accent-soft: rgba(92, 212, 255, 0.16);
  --track: rgba(255, 255, 255, 0.11);
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-main);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#gl-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: grab;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
}

#gl-canvas:active {
  cursor: grabbing;
}

/* Ensure controls are on top and interactive */
.control-panel {
  position: fixed;
  top: 64px;
  right: 20px;
  bottom: 20px;
  width: 320px;
  z-index: 30; /* Increased z-index */
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
  pointer-events: auto; /* Explicitly ensure interactions are enabled */
}

.control-panel.collapsed {
  transform: translateX(calc(100% + 30px));
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-header h2 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.panel-subtitle {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--text-dim);
}

.btn-ghost {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid rgba(148, 210, 255, 0.22);
  background: rgba(92, 212, 255, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  background: rgba(92, 212, 255, 0.18);
  border-color: rgba(92, 212, 255, 0.5);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 18px;
}

.panel-scroll::-webkit-scrollbar {
  width: 5px;
}

.panel-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 210, 255, 0.2);
  border-radius: 4px;
}

.control-section + .control-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--accent);
  margin-bottom: 10px;
}

/* Preset Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(148, 210, 255, 0.35);
}

.preset-btn.active {
  background: rgba(92, 212, 255, 0.16);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(92, 212, 255, 0.25);
}

.preset-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

/* Sliders & Rows */
.control-row {
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 11.5px;
  color: #cfe0f5;
}

.control-label output {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 99px;
  background: var(--track);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #e9f9ff;
  border: 2px solid var(--accent);
  box-shadow: 0 0 8px rgba(92, 212, 255, 0.55);
  transition: transform 0.12s ease;
}

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

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #e9f9ff;
  border: 2px solid var(--accent);
  cursor: pointer;
}

.inline-color,
.inline-select,
.inline-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: #cfe0f5;
  margin-top: 8px;
}

.color-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-hex {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

input[type="color"] {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

select {
  background: rgba(15, 23, 39, 0.95);
  color: var(--text-main);
  border: 1px solid rgba(148, 210, 255, 0.24);
  border-radius: 7px;
  padding: 5px 8px;
  font-family: var(--font);
  font-size: 11.5px;
  outline: none;
  cursor: pointer;
}

select:hover {
  border-color: rgba(92, 212, 255, 0.5);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.slider-round::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider-round {
  background-color: var(--accent);
}

.switch input:checked + .slider-round::before {
  transform: translateX(16px);
}

@media (max-width: 720px) {
  .control-panel {
    width: calc(100vw - 24px);
    right: 12px;
    top: auto;
    height: 46vh;
    bottom: 12px;
  }
  .control-panel.collapsed {
    transform: translateY(calc(100% + 24px));
  }
}
