/* Mobile-First Apple Studio Aesthetic */
/* Zero AI clutter. Native iOS/macOS feel. */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", -system-ui, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, monospace;

  /* Deep Apple OLED palette */
  --bg-app: #000000;
  --bg-card: rgba(28, 28, 30, 0.88);
  --bg-card-elevated: rgba(44, 44, 46, 0.95);
  --bg-input: #151517;
  --bg-dock: rgba(18, 18, 20, 0.92);

  --text-primary: #ffffff;
  --text-secondary: rgba(235, 235, 245, 0.65);
  --text-tertiary: rgba(235, 235, 245, 0.40);

  --accent-blue: #0a84ff;
  --accent-blue-active: #0066cc;
  --accent-green: #30d158;
  --accent-red: #ff453a;
  --accent-red-subtle: rgba(255, 69, 58, 0.15);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(10, 132, 255, 0.5);

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 9999px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --shadow-dock: 0 -8px 32px rgba(0, 0, 0, 0.7);
  --transition-fast: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-app: #f2f2f7;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-card-elevated: #ffffff;
    --bg-input: #f8f8fa;
    --bg-dock: rgba(255, 255, 255, 0.94);

    --text-primary: #000000;
    --text-secondary: #6e6e73;
    --text-tertiary: #8e8e93;

    --border-subtle: rgba(0, 0, 0, 0.08);
    --shadow-dock: 0 -8px 28px rgba(0, 0, 0, 0.08);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* Mobile Viewport Wrapper */
.mobile-viewport {
  width: 100%;
  max-width: 580px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-app);
  margin: 0 auto;
}

/* Header */
.mobile-header {
  padding: calc(var(--safe-top) + 12px) 16px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-app);
  z-index: 20;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1c1c1e 0%, #2c2c2e 100%);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-blue);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-subtitle {
  font-size: 0.70rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 6px 11px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.engine-badge:active {
  transform: scale(0.96);
}

.engine-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(48, 209, 88, 0.4);
}

.touch-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.touch-icon-btn:active {
  transform: scale(0.92);
}

/* Segmented Mode Selector */
.mode-selector-wrapper {
  padding: 10px 16px 6px 16px;
}

.segmented-pill-bar {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.segmented-tab {
  flex: 1;
  padding: 9px 12px;
  border-radius: 13px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: center;
}

.segmented-tab.active {
  background: var(--bg-card-elevated);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* Scrollable Content Container */
.content-scroll {
  flex: 1;
  padding: 10px 16px 280px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Cards */
.mobile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-caption {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

/* Voice Picker Card */
.voice-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.voice-badge-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-blue);
  background: rgba(10, 132, 255, 0.12);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.voice-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.voice-avatar-display {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.voice-select-box {
  flex: 1;
  position: relative;
}

.mobile-native-select {
  width: 100%;
  height: 44px;
  appearance: none;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 34px 0 12px;
  font-size: 0.90rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: var(--transition-fast);
}

.mobile-native-select:focus {
  border-color: var(--accent-blue);
}

.voice-select-box::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-60%) rotate(45deg);
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  pointer-events: none;
}

/* Input Canvas Card */
.canvas-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.action-chips-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.action-chip:active {
  transform: scale(0.94);
}

/* DELETE / CLEAR BUTTON HIGHLIGHT */
.delete-chip {
  color: var(--accent-red);
  background: var(--accent-red-subtle);
  border-color: rgba(255, 69, 58, 0.3);
}

.delete-chip:active {
  background: rgba(255, 69, 58, 0.3);
}

.accent-chip {
  color: var(--accent-blue);
  background: rgba(10, 132, 255, 0.12);
}

/* Mobile Textarea (16px to prevent iOS auto-zoom) */
.mobile-textarea {
  width: 100%;
  min-height: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px; /* Crucial for iOS */
  line-height: 1.5;
  color: var(--text-primary);
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: var(--transition-fast);
}

.mobile-textarea:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
}

.canvas-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  padding: 0 2px;
}

/* Dialogue Cast & Turn Bubbles */
.dialogue-speakers-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dialogue-speaker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.dialogue-speaker-name {
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dialogue-bubbles-stream {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
}

.chat-bubble {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 0.85rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-bubble.speaker-a {
  align-self: flex-start;
  background: rgba(10, 132, 255, 0.16);
  border: 1px solid rgba(10, 132, 255, 0.25);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-bubble.speaker-b {
  align-self: flex-end;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.bubble-author {
  font-size: 0.70rem;
  font-weight: 700;
  color: var(--accent-blue);
  text-transform: uppercase;
}

.chat-bubble.speaker-b .bubble-author {
  color: var(--accent-green);
}

/* Tuning Details Card */
.parameters-card {
  padding: 12px 14px;
}

.tuning-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}

.tuning-summary::-webkit-details-marker {
  display: none;
}

.tuning-toggle-icon {
  font-size: 0.75rem;
  color: var(--accent-blue);
  font-weight: 600;
}

.tuning-controls-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding-top: 12px;
}

.tuning-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tuning-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.tuning-val {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.mobile-range-slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-pill);
  outline: none;
}

.mobile-range-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

/* Bottom Spacer */
.bottom-dock-spacer {
  height: 260px;
}

/* Bottom Docked Floating Action Bar */
.bottom-dock-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 580px;
  margin: 0 auto;
  background: var(--bg-dock);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border-top: 1px solid var(--border-subtle);
  padding: 10px 16px calc(var(--safe-bottom) + 12px) 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  box-shadow: var(--shadow-dock);
}

/* Generation Progress Banner */
.generation-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 132, 255, 0.15);
  border: 1px solid rgba(10, 132, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.80rem;
  color: var(--text-primary);
}

.generation-banner span:nth-child(2) {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cancel-text-btn {
  background: none;
  border: none;
  color: var(--accent-red);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 6px;
}

/* Docked Audio Player */
.docked-player-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-top-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.studio-play-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #ffffff;
  color: #000000;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.studio-play-btn:active {
  transform: scale(0.92);
}

.player-timeline-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.touch-scrubber-track {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-pill);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.touch-scrubber-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-blue);
  border-radius: var(--radius-pill);
}

.player-time-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.badge-mini {
  font-size: 0.65rem;
  background: var(--bg-card-elevated);
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  color: var(--accent-green);
}

.studio-download-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(48, 209, 88, 0.18);
  border: 1px solid rgba(48, 209, 88, 0.35);
  color: var(--accent-green);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.studio-download-btn:active {
  transform: scale(0.92);
}

/* Inspector */
.inspector-accordion {
  border-top: 1px solid var(--border-subtle);
  padding-top: 6px;
}

.inspector-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 0.74rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 4px 0;
}

.chunks-inspector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
  margin-top: 6px;
}

.chunk-clip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border-radius: var(--radius-xs);
  padding: 5px 8px;
  font-size: 0.75rem;
  gap: 8px;
}

.chunk-clip-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

/* Primary Generation Button */
.mobile-primary-btn {
  width: 100%;
  height: 52px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(10, 132, 255, 0.4);
  transition: var(--transition-fast);
}

.mobile-primary-btn:active {
  transform: scale(0.98);
  background: var(--accent-blue-active);
}

.mobile-primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Settings Bottom Sheet */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.mobile-sheet {
  width: 100%;
  max-width: 580px;
  background: var(--bg-card-elevated);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  padding: 12px 18px calc(var(--safe-bottom) + 20px) 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-drag-handle {
  width: 38px;
  height: 4px;
  background: var(--border-subtle);
  border-radius: var(--radius-pill);
  align-self: center;
  margin-bottom: 4px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-text-input {
  width: 100%;
  height: 44px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 15px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  outline: none;
}

.mobile-text-input:focus {
  border-color: var(--accent-blue);
}

.setting-hint {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  line-height: 1.35;
}

.sheet-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.connection-status-label {
  font-size: 0.76rem;
  color: var(--text-tertiary);
}

/* Spinner */
.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
