#control-panel {
  /* The panel is an off-canvas drawer that only enters the layout when explicitly opened. */
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  padding: 18px 22px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(8rem + env(safe-area-inset-bottom, 0px));
  background: var(--panel-bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, "Helvetica Neue", Arial, sans-serif;
  z-index: 10;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
  scrollbar-width: none;
}

#control-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.panel-scroll-rail {
  /* A lightweight scroll rail gives the panel a visible position cue without a native scrollbar. */
  position: fixed;
  top: 0;
  left: 0;
  height: 0;
  width: 8px;
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.panel-scroll-rail.visible {
  opacity: 1;
}

.panel-scroll-rail::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--ink) 30%, transparent);
}

.panel-scroll-thumb {
  position: absolute;
  left: 2px;
  width: 3px;
  min-height: 24px;
  background: var(--ink);
  border-radius: 0;
  opacity: 0.88;
}

#control-panel.open {
  /* Opening the panel is a pure transform change so it stays smooth and cheap. */
  transform: translateX(0);
}

#control-panel .panel-header {
  /* Header keeps title and close affordance on one line for fast panel dismissal. */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px 0;
}

#control-panel h1 {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0;
}

#panel-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--ink);
  opacity: 0.85;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  border-radius: 0;
  flex-shrink: 0;
}

#panel-close-btn:hover {
  opacity: 1;
}

#panel-close-btn:focus-visible {
  outline: none;
}

#control-panel h2 {
  /* Section headings separate mode, color, and timing controls into readable clusters. */
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.55;
  margin: 21px 0 10px 0;
  border-top: 1px solid var(--ink);
  padding-top: 14px;
}

#control-panel h2:first-of-type {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}

#control-panel h2.no-divider {
  border-top: none;
  padding-top: 0;
}

.audio-player-wrap {
  /* Audio controls are visually boxed because they have distinct playback semantics. */
  margin: 0 0 18px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink);
}

.audio-player-label {
  display: block;
  margin: 0 0 8px 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.7;
}

#ambient-audio {
  display: block;
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--accent);
}

.control-row {
  /* Every control row keeps its label, value, and input aligned as a compact unit. */
  margin-bottom: 16px;
}

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

.control-row label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.control-row .value {
  font-variant-numeric: tabular-nums;
  color: #FFFFFF;
}

.control-row.checkbox-row label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  cursor: pointer;
}

.audio-player-wrap .checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.audio-player-wrap .checkbox-row label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.control-row.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}

.control-row input[type="color"] {
  display: block;
  width: 100%;
  height: 30px;
  min-height: 30px;
  border: 1px solid #4A453E;
  background: transparent;
  padding: 0;
  cursor: pointer;
  box-sizing: border-box;
}

.hue-control-row {
  /* Hue gets a custom layout because it has both a color swatch and a slider. */
  display: block;
}

.hue-control-label {
  display: block;
  margin: 0 0 6px 0;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.hue-picker-wrap {
  width: 100%;
  margin: 0 0 8px 0;
}

.hue-swatch {
  display: block;
  width: 100%;
  height: 30px;
  border: 1px solid var(--ink);
  box-sizing: border-box;
  margin-right: 0;
  flex-shrink: 0;
}

.preset-buttons {
  /* Save/load actions are grouped so preset persistence reads as a single operation. */
  display: flex;
  gap: 10px;
}

.preset-buttons button {
  flex: 1;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 7px 0;
  background: transparent;
  border: 1px solid #4A453E;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.preset-buttons button:hover {
  background: var(--ink);
  color: var(--bg);
}

.preset-library {
  /* Library selectors sit side by side because the pack and preset flows are related but distinct. */
  display: flex;
  gap: 10px;
  align-items: center;
}

.preset-library select,
.preset-library button {
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink);
  border: 1px solid #4A453E;
  background: transparent;
  min-height: 28px;
  border-radius: 4px;
}

.preset-library select {
  flex: 1;
  padding: 0 6px;
}

.preset-library button {
  padding: 0 9px;
  text-transform: uppercase;
  cursor: pointer;
}

#preset-status {
  /* Status text is intentionally small so it reads as feedback, not as a banner. */
  display: block;
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.6;
  min-height: 14px;
}

#control-hint {
  /* The footer hint is unobtrusive metadata, not an interactive affordance. */
  margin-top: 21px;
  font-size: 11px;
  opacity: 0.55;
  letter-spacing: 0.02em;
}
