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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0f;
  font-family: 'DM Sans', system-ui, sans-serif;
}

canvas {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ── Settings dropdown wrapper ── */
#settingsDropdown {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  width: 250px;
  /* Ensure the whole dropdown never exceeds the viewport */
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}

/* ── Toggle button ── */
#settingsBtn {
  flex-shrink: 0;        /* never squished */
  width: 100%;
  background: rgba(20,20,28,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 10px 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
  z-index: 1;            /* sits above the panel so border-radius shows cleanly */
}
#settingsBtn:hover {
  background: rgba(30,30,42,0.94);
  border-color: rgba(255,255,255,0.2);
}
#settingsBtn .text  { flex: 1; text-align: left; }
#settingsBtn .arrow {
  font-size: 10px;
  opacity: 0.5;
  transition: transform 0.25s ease;
}

/* ── Panel (scrollable when content overflows) ── */
#settingsContent {
  /* Collapsed state */
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;

  background: rgba(16,16,24,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.09);
  border-top: none;
  border-radius: 0 0 10px 10px;
}

#settingsContent:not(.open) {
  /* keep collapsed controls out of the tab order */
  visibility: hidden;
  transition: max-height 0.35s ease, visibility 0s linear 0.35s;
}

#settingsContent.open {
  /* Expand to fill remaining viewport space below the button */
  max-height: calc(100vh - 64px - 32px); /* 64px ≈ button height + gap */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
}

/* Thin custom scrollbar so it doesn't look clunky */
#settingsContent::-webkit-scrollbar { width: 4px; }
#settingsContent::-webkit-scrollbar-track { background: transparent; }
#settingsContent::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}
#settingsContent::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.28);
}

/* ── Section label ── */
.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-bottom: 8px;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 12px 0;
}

/* ── Slider group ── */
.slider-group { margin-bottom: 10px; }
.slider-group label {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 4px;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}
.slider-row input[type="range"]:hover { background: rgba(255,255,255,0.22); }
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
.slider-row input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-row span {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Toggle row ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  margin-bottom: 4px;
}
.pill-toggle { position: relative; display: block; }
/* Visually hidden but still focusable / announced (display:none removed it
   from the keyboard and accessibility tree) */
.pill-toggle input {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.pill-toggle input:focus-visible + .pill-track {
  outline: 2px solid rgba(100,180,255,0.9);
  outline-offset: 2px;
}
.pill-track {
  display: block;
  width: 34px; height: 18px;
  background: rgba(255,255,255,0.15);
  border-radius: 100px;
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
}
.pill-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.pill-toggle input:checked + .pill-track { background: rgba(100,180,255,0.6); }
.pill-toggle input:checked + .pill-track::after { transform: translateX(16px); }

/* ── Barrier buttons ── */
.barrier-btns { display: flex; gap: 6px; margin-bottom: 6px; }
.tool-btn {
  flex: 1;
  padding: 7px 0;
  font-size: 11px; font-weight: 500;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  transition: all 0.2s;
}
.tool-btn:hover { background: rgba(255,255,255,0.13); color: #fff; }
.tool-btn.active {
  background: rgba(100,180,255,0.2);
  border-color: rgba(100,180,255,0.5);
  color: rgb(160,210,255);
}
.clear-btn {
  width: 100%;
  padding: 6px;
  font-size: 11px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: all 0.2s;
}
.clear-btn:hover { border-color: rgba(255,80,80,0.4); color: rgba(255,120,120,0.8); }

/* ── Reset button ── */
.reset-btn {
  width: 100%;
  padding: 8px;
  font-size: 12px; font-weight: 500;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all 0.2s;
}
.reset-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* ── Mode indicator ── */
.mode-indicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16,16,24,0.82);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(100,180,255,0.3);
  border-radius: 100px;
  padding: 6px 18px;
  font-size: 12px;
  color: rgba(160,210,255,0.9);
  pointer-events: none;
  z-index: 10;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ════════════════════════════════════════════════
   PALETTE UI
   ════════════════════════════════════════════════ */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.palette-chip {
  position: relative;
  height: 38px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.palette-chip:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.35); }
.palette-chip.active {
  border-color: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.2);
}
.palette-chip span {
  font-size: 9px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  padding: 3px 4px;
  letter-spacing: 0.03em;
  text-align: center;
  width: 100%;
  background: rgba(0,0,0,0.6);   /* solid enough for white 9px text on the brightest palette stop */
  line-height: 1.3;
}

/* ── Custom editor ── */
.custom-editor {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.custom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.custom-label {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  flex: 1;
}
.color-pick {
  -webkit-appearance: none;
  appearance: none;
  width: 36px; height: 22px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 1px;
  overflow: hidden;
}
.color-pick::-webkit-color-swatch-wrapper { padding: 0; }
.color-pick::-webkit-color-swatch { border: none; border-radius: 3px; }

/* ── Back link ── */
#backLink {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: rgba(20,20,28,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 10px 14px;
  color: rgba(255,255,255,0.75);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#backLink:hover { background: rgba(30,30,42,0.94); border-color: rgba(255,255,255,0.2); color: #fff; }

/* ── Shortcuts list ── */
.shortcuts { display: flex; flex-direction: column; gap: 5px; }
.shortcuts div { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.shortcuts dt { font-size: 11px; color: rgba(255,255,255,0.55); }
.shortcuts dd { font-size: 11px; color: rgba(255,255,255,0.6); text-align: right; }
.shortcuts kbd {
  font-family: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid rgba(255,255,255,0.15);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: rgba(255,255,255,0.7);
}

/* ── Keyboard focus ── */
button:focus-visible,
a:focus-visible,
input[type="range"]:focus-visible,
input[type="color"]:focus-visible {
  outline: 2px solid rgba(100,180,255,0.9);
  outline-offset: 2px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #settingsDropdown { width: calc(100vw - 32px - 56px); }
  #backLink { padding: 10px 13px; }
  .back-text { display: none; }
  #settingsContent:not(.open) {
  /* keep collapsed controls out of the tab order */
  visibility: hidden;
  transition: max-height 0.35s ease, visibility 0s linear 0.35s;
}

#settingsContent.open { max-height: calc(100vh - 80px); }
  .palette-grid { grid-template-columns: repeat(3, 1fr); }
}