/* ============================================================================
 * Settings drawer — right-side panel on desktop, bottom sheet on phones.
 * Tab bar + close in .panel-head, one .panel-page per tab in .panel-body.
 * Also: drop targets for art/video, free-form text inputs (lyrics + API
 * key), scrollbar styling.
 * ========================================================================== */

#panel {
  position: fixed;
  /* Sit below the unified header so the mode pill + settings ⚙ remain
     reachable while the drawer is open. */
  top: var(--vizzy-header-height, 52px);
  right: 0;
  bottom: 0;
  width: 392px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-left: 1px solid var(--hairline);
  z-index: 30;
  transform: translateX(100%);
  transition: transform 0.32s var(--ease-out);
}
#panel.open { transform: translateX(0); }
#panel.dragging { transition: none; }

/* Head: tab bar + close. Pages scroll underneath in .panel-body. */
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) 0 var(--space-4);
  border-bottom: 1px solid var(--hairline);
  padding-right: max(var(--space-3), env(safe-area-inset-right));
  flex-shrink: 0;
}
.panel-tabs {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.panel-tabs::-webkit-scrollbar { display: none; }
.panel-tab {
  flex-shrink: 0;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 12px 5px 10px;
  min-height: 40px;
  cursor: pointer;
  transition: color 0.15s var(--ease-out), border-color 0.15s var(--ease-out);
}
.panel-tab:hover { color: var(--ink); }
.panel-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.panel-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5) var(--space-6) var(--space-8);
  padding-right: max(var(--space-6), env(safe-area-inset-right));
  padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom));
}
.panel-page[hidden] { display: none; }

/* Grab handle — phone bottom sheet only (drawer.js wires the drag). */
.panel-grab { display: none; }

/* Phone: the drawer becomes a bottom sheet — full width, slides up from
   below, matches CapCut / native iOS sheet patterns. Reuses the same DOM and
   `.open` class so JS doesn't have to branch by viewport. The tab bar
   scrolls horizontally; the grab handle + tab bar drag the sheet down to
   close (drawer.js). Every control is ≥44px tall. */
@media (max-width: 767px) {
  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 78dvh;
    max-height: calc(100dvh - var(--vizzy-header-height, 48px) - 8px);
    border-left: none;
    border-top: 1px solid var(--hairline-2);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  #panel.open { transform: translateY(0); }
  .panel-grab {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
  }
  .panel-grab span {
    width: 40px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--ink-5);
  }
  .panel-head {
    padding: 0 var(--space-2) 0 var(--space-3);
    /* Vertical drags on the head move the sheet; horizontal ones scroll
       the tab bar. */
    touch-action: pan-x;
  }
  .panel-tab {
    min-height: 44px;
    padding: 12px 10px;
    font-size: 11px;
  }
  .panel-body {
    padding: var(--space-4) var(--space-5) calc(28px + env(safe-area-inset-bottom));
  }
  #panel .panel-close {
    width: 44px;
    height: 44px;
  }
  /* The six tabs don't fit a phone's width — fade the right edge so it's
     obvious the bar scrolls sideways (Export sits off-screen at first). */
  .panel-tabs {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    padding-right: 28px;
  }
  /* Landscape phones: the 78dvh sheet leaves almost no room under the
     header — let it use the full height below the header. */
  @media (orientation: landscape) {
    #panel { height: calc(100dvh - var(--vizzy-header-height, 48px)); max-height: none; }
  }
}

/* Section headers — each h3 acts as a quiet divider between groups within a
   tab. The ::before line gives each page structural rhythm. The line uses position:relative so it
   extends edge-to-edge regardless of whether we're in the desktop 24px
   gutter or the mobile 20px gutter. */
#panel h3 {
  position: relative;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin: var(--space-7) 0 var(--space-3);
  padding-top: var(--space-4);
  font-weight: 700;
}
#panel h3::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--hairline);
}
#panel h3:first-child,
#panel .panel-page > h3:first-child {
  margin-top: 0;
  padding-top: 0;
}
#panel .panel-page > h3:first-child::before { display: none; }

.panel-close {
  flex-shrink: 0;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none;
  border-radius: var(--radius-pill);
  color: var(--ink-3);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  transition: color 0.15s var(--ease-out), background 0.15s var(--ease-out);
}
.panel-close:hover { color: var(--ink); }

/* Drop targets (audio / art / video) ---------------------------------------- */
.file-drop {
  display: block;
  position: relative;
  border: 1px dashed var(--ink-5);
  padding: var(--space-4);
  border-radius: var(--radius-4);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s var(--ease-out),
              background 0.2s var(--ease-out);
  font-size: 13px;
  color: var(--ink-3);
}
.file-drop:hover,
.file-drop.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink-2);
}
.file-drop .filename {
  display: block;
  margin-top: var(--space-1);
  font-weight: 600;
  color: var(--ink);
  font-size: 12px;
}
/* Hide the underlying file input visually but keep it accessible to clicks
   bubbled up from the parent <label>. */
.file-drop input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Free-form inputs ---------------------------------------------------------- */
textarea {
  width: 100%;
  min-height: 140px;
  background: var(--surface-3);
  color: var(--ink);
  border: 1px solid var(--hairline-2);
  border-radius: var(--radius-3);
  padding: var(--space-3);
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.15s var(--ease-out),
              background 0.15s var(--ease-out);
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 60, 120, 0.04);
}
textarea::placeholder { color: var(--ink-4); }

.tts-input,
.tts-select {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface-3);
  color: var(--ink);
  border: 1px solid var(--hairline-2);
  border-radius: var(--radius-2);
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  margin-top: var(--space-2);
  transition: border-color 0.15s var(--ease-out);
}
.tts-input:focus,
.tts-select:focus {
  outline: none;
  border-color: var(--accent);
}
.tts-select option { background: #111; color: var(--ink); }
/* Custom-drawn select: Safari/iOS ignores height on native selects, which
   left these 23px tall on iPhone. Same chevron as .row-select. */
.tts-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.tts-status {
  font-size: 11px;
  color: var(--ink-4);
  margin-top: var(--space-2);
  min-height: 14px;
}
.tts-status.err { color: var(--err); }
.tts-status.ok  { color: var(--ok); }

/* Panel scrollbar — thin + ghosted so the scrollable area doesn't dominate. */
.panel-body::-webkit-scrollbar       { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb {
  background: var(--ink-5);
  border-radius: var(--radius-1);
}
.panel-body::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

/* Touch screens wider than the phone breakpoint (landscape phones, tablets):
   keep the desktop drawer but with finger-sized tabs and close button. */
@media (pointer: coarse) {
  .panel-tab { min-height: 44px; padding: 12px 8px; font-size: 11px; }
  .panel-tabs {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    padding-right: 28px;
  }
  #panel .panel-close { width: 44px; height: 44px; }
}
/* Desktop-width drawer: pull the transport in so the scrubber and times
   aren't hidden underneath the open drawer. */
@media (min-width: 768px) {
  body:has(#panel.open) #controls { right: 392px; }
}
/* Phone bottom sheet: the transport sits under the translucent sheet and
   showed through it — hide it while the sheet is open. */
@media (max-width: 767px) {
  body:has(#panel.open) #controls { opacity: 0; pointer-events: none; }
}
.tts-select + .action-btn { margin-top: var(--space-2); }
