/* =============================================================================
   SFX Generator
   ============================================================================= */

/* ── Layout ─────────────────────────────────────────────────────────────────── */


.sfx-section {
  margin-bottom: var(--space-md);
  padding: 0 var(--space-xl);
}

.sfx-section-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

.sfx-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.sfx-section-header .sfx-section-label {
  margin-bottom: 0;
}

.sfx-section-header .sfx-icon-btn {
  margin-left: auto;
}

.sfx-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.sfx-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--color-text);
  transform: scale(1.1);
}

.sfx-icon-btn:active {
  transform: scale(0.95);
}

.sfx-icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* ── Collapsible sections (hidden until preset is selected) ─────────────────── */

.sfx-collapsible {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin-bottom: 0 !important;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.35s ease,
              margin-bottom 0.4s ease,
              padding 0.4s ease,
              border-color 0.4s ease;
}

/* Export section: fade only, no accordion. max-height is 0 when collapsed
   so the invisible content doesn't occupy DOM space. The frame (padding +
   1px border from .sfx-export) sits OUTSIDE max-height in the box model,
   so we zero those out here too — otherwise each collapsed export block
   still renders ~34px of empty framed space and pushes the documentation
   section below it down. Scoped with :not(.sfx-revealed) so revealing the
   section naturally snaps the frame back via the default .sfx-export rule. */
.sfx-export.sfx-collapsible:not(.sfx-revealed) {
  max-height: 0;
  padding: 0;
  border-width: 0;
  overflow: hidden;
  transition: opacity 0.4s ease;
}

.sfx-collapsible.sfx-revealed {
  max-height: none;
  opacity: 1;
  overflow: visible;
  margin-bottom: var(--space-md) !important;
}

.sfx-section-presets {
  padding-left: 0;
  padding-right: 0;
}

/* ── Preset Buttons ─────────────────────────────────────────────────────────── */

.sfx-presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.sfx-preset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.sfx-preset-btn:hover {
  background: rgba(139, 45, 180, 0.15);
  border-color: var(--color-primary);
  color: var(--color-primary-light);
}

.sfx-preset-btn.active {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(139, 45, 180, 0.3);
}

.sfx-preset-paste {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--color-text-secondary);
}

.sfx-preset-paste:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--color-text);
}

/* ── Visualization Canvas ───────────────────────────────────────────────────── */

.sfx-canvas-wrap {
  position: relative;
  margin-bottom: var(--space-md);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-subtle);
  transition: border-color 0.2s ease;
}

.sfx-canvas-wrap.has-data {
  cursor: pointer;
}

.sfx-canvas-wrap.has-data:hover {
  border-color: var(--color-accent);
}

.sfx-canvas {
  display: block;
  width: 100%;
  height: 120px;
}

.sfx-canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  pointer-events: none;
}

/* ── Action Buttons ─────────────────────────────────────────────────────────── */

.sfx-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
  align-items: center;
}

.sfx-actions-spacer {
  flex: 1;
}

/* ── Controls (Sliders) ─────────────────────────────────────────────────────── */

.sfx-controls {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  gap: var(--space-xs) var(--space-sm);
  align-items: center;
  margin-bottom: var(--space-md);
}

.sfx-control-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.sfx-control-slider {
  --val: 0%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}

.sfx-control-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, var(--color-primary) var(--val), rgba(255, 255, 255, 0.12) var(--val));
}

.sfx-control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--color-primary-light);
  margin-top: -2px;
  cursor: pointer;
}

.sfx-control-slider::-moz-range-track {
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
}

.sfx-control-slider::-moz-range-progress {
  height: 10px;
  border-radius: 5px;
  background: var(--color-primary);
}

.sfx-control-slider::-moz-range-thumb {
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--color-primary-light);
  border: none;
  cursor: pointer;
}

.sfx-control-value {
  font-size: var(--font-size-xs);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  text-align: right;
  white-space: nowrap;
}

/* Direction segmented control */
.sfx-direction-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sfx-direction-row .sfx-control-label {
  width: 80px;
  flex-shrink: 0;
}

.sfx-direction-group {
  display: inline-flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.sfx-direction-btn {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
  font-family: var(--font-family);
  color: var(--color-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.sfx-direction-btn:not(:last-child) {
  border-right: 1px solid var(--color-border);
}

.sfx-direction-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
}

.sfx-direction-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* ── Export Section ──────────────────────────────────────────────────────────── */

.sfx-export {
  position: relative;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.sfx-export h3 {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 var(--space-sm) 0;
}

.sfx-code-copy-btn {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
}

.sfx-export-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.sfx-export-header label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.sfx-export-header select,
.sfx-export-header input[type="text"] {
  font-size: var(--font-size-sm);
  font-family: var(--font-mono);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.sfx-export-header input[type="text"] {
  width: 120px;
}

.sfx-export-header input[type="text"].sfx-input-disabled {
  opacity: 0.4;
  cursor: default;
}

.sfx-code-wrap {
  position: relative;
  margin-bottom: var(--space-xs);
}

.sfx-code-output {
  display: block;
  width: 100%;
  max-height: 160px;
  overflow: auto;
  padding: var(--space-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  white-space: pre;
  word-break: break-all;
  line-height: 1.5;
  cursor: text;
}

#sfx-usage-output {
  margin-bottom: var(--space-md);
}

.sfx-export-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
}

/* Right-align the Push to Code button within its actions row */
.sfx-export-actions #btn-sfx-push-code,
.sfx-export-actions #btn-sfx-push-sketch {
  margin-left: auto;
}

.sfx-export-info {
  display: block;
  text-align: right;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  margin-bottom: var(--space-md);
  margin-right: var(--space-sm);
}

/* Checkbox accent color */
.sfx-checkbox-label input[type="checkbox"] {
  accent-color: var(--color-primary);
}

.sfx-checkbox-label input[type="checkbox"]#sfx-show-complete-sketch {
  accent-color: var(--color-accent);
}

.sfx-checkbox-label {
  margin-left: var(--space-sm);
  cursor: pointer;
}

.sfx-export-divider {
  width: 1px;
  align-self: stretch;
  background: var(--color-border);
  margin: 0 var(--space-sm);
}

/* ── Warnings ───────────────────────────────────────────────────────────────── */

.sfx-warnings {
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--radius-sm);
  color: var(--color-danger);
  font-size: var(--font-size-xs);
}

.sfx-warnings[hidden] {
  display: none;
}

/* ── Input flash (validation feedback) ─────────────────────────────────────── */

.sfx-input-flash {
  animation: sfx-flash 0.4s ease;
}

@keyframes sfx-flash {
  0%, 100% { border-color: var(--color-border); }
  25%, 75% { border-color: var(--color-danger); box-shadow: 0 0 6px rgba(248, 113, 113, 0.4); }
}

/* ── Favorites Sidebar ─────────────────────────────────────────────────────── */

#panel-sfx {
  position: relative;
  overflow: visible;
}

.sfx-favorites-sidebar {
  display: none;
  position: absolute;
  top: 7.1em;
  left: 102%;
  width: 180px;
}

.sfx-favorites-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 1.4em 0;
}

.sfx-favorites-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.sfx-favorites-clear {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}

.sfx-favorites-clear:hover {
  opacity: 1;
  color: var(--color-danger, #e74c3c);
}

.sfx-favorites-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--space-md);
}

.sfx-favorite-item {
  position: relative;
  flex-shrink: 0;
}

.sfx-favorite-thumb {
  display: block;
  width: 100%;
  height: 40px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  position: relative;
  z-index: 1;
  transition: border-color 0.2s ease;
}

.sfx-favorite-thumb:hover {
  border-color: var(--color-accent);
}

.sfx-favorite-name-wrap {
  display: flex;
  justify-content: center;
  padding: var(--space-xs) 0;
}

.sfx-favorite-name {
  display: inline-block;
  padding: 1px var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
  cursor: text;
  background: transparent;
  border-radius: var(--radius-sm);
  max-width: 100%;
}

.sfx-favorite-name:focus {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.05);
}

/* ── Add-to-favorites entrance animation ── */

.sfx-favorite-name-wrap.sfx-anim-label .sfx-favorite-name {
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* ── Delete button ── */

.sfx-favorite-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.sfx-favorite-item:hover .sfx-favorite-delete {
  opacity: 1;
}

.sfx-favorite-delete:hover {
  background: rgba(248, 113, 113, 0.6);
  color: #fff;
}

/* ── Responsive: narrow screens (≤1250px) ──────────────────────────────────
   The absolute-positioned right-side favorites sidebar has nowhere to go
   on narrow screens, so it in-flows between the action buttons and the
   parameters section as a horizontally-scrolling strip of pills. Canvas
   previews are dropped in this mode — the variable name alone is enough
   to pick a favorite at a glance, and the × delete still appears on hover.
   ========================================================================= */
@media (max-width: 1250px) {
  .sfx-favorites-sidebar {
    position: static;
    width: auto;
    margin-bottom: var(--space-md);
  }

  .sfx-favorites-header {
    margin-bottom: var(--space-xs);
  }

  .sfx-favorites-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    max-height: none;
    padding-bottom: var(--space-xs);
  }

  .sfx-favorite-item {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px 2px 10px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
  }

  .sfx-favorite-item:hover {
    border-color: var(--color-accent);
  }

  .sfx-favorite-thumb {
    display: none;
  }

  .sfx-favorite-name-wrap {
    padding: 0;
  }

  .sfx-favorite-name {
    padding: 2px 0;
    max-width: none;
  }

  .sfx-favorite-name:focus {
    background: transparent;
  }

  /* In pill mode the × is a flex sibling of the name, not absolutely
     positioned — reserve a fixed size and fade in on item hover. */
  .sfx-favorite-delete {
    position: static;
    width: 16px;
    height: 16px;
    background: transparent;
    font-size: 13px;
  }
}
