/* ==========================================================================
   ScriptToVideo - Modern Dark Theme Stylesheet
   ========================================================================== */

:root {
  --bg-main: #121216;
  --bg-card: #1a1a24;
  --bg-card-subtle: #14141c;
  --bg-input: #0e0e13;
  --border-subtle: #2a2a3a;
  --border-hover: #3d3d52;
  --border-focus: #00d2ff;
  
  --text-main: #f5f5f9;
  --text-muted: #9696ab;
  --text-faint: #606076;
  
  --accent-cyan: #00e5ff;
  --accent-amber: #ffb300;
  --accent-green: #00e676;
  --accent-red: #ff3b3b;
  --accent-blue: #3b82f6;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(0, 229, 255, 0.2);

  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-caption: 'Anton', sans-serif;
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: 0;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Container */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem 1rem;
  width: 100%;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-cyan), #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.25rem;
  color: #000;
  box-shadow: 0 2px 10px rgba(0, 229, 255, 0.3);
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #c7d2fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Mode Switcher Segmented Control */
.mode-segmented {
  display: inline-flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  min-height: 38px;
}

.mode-btn.active {
  background: var(--bg-card);
  color: var(--accent-cyan);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-hover);
}

.mode-btn:hover:not(.active) {
  color: var(--text-main);
}

.badge-tag {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 179, 0, 0.2);
  color: var(--accent-amber);
  border: 1px solid rgba(255, 179, 0, 0.3);
}

/* Settings Button */
.btn-settings {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-settings:hover {
  background: var(--border-subtle);
  border-color: var(--border-hover);
}

/* Section Cards Layout */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-card);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.step-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.step-number {
  background: var(--accent-cyan);
  color: #000;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
}

.step-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Script Input */
.script-textarea-wrapper {
  position: relative;
  margin-bottom: 1rem;
}

.script-textarea {
  width: 100%;
  min-height: 180px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-main);
  resize: vertical;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.2s ease;
}

.script-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(0, 210, 255, 0.2);
}

.script-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.script-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.script-quick-buttons {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 46px;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), #00a8cc);
  color: #000;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 229, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(0, 229, 255, 0.4);
}

.btn-secondary {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border-subtle);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-main);
  background: var(--border-subtle);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

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

.spinner-light {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
}

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

/* Progress bar */
.progress-bar-container {
  height: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
  transition: width 0.3s ease;
}

/* Status Banner */
.status-banner {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-banner.info {
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.3);
  color: #e0f9ff;
}

.status-banner.error {
  background: rgba(255, 59, 59, 0.1);
  border: 1px solid rgba(255, 59, 59, 0.3);
  color: #ffc2c2;
}

.status-banner.success {
  background: rgba(0, 230, 118, 0.1);
  border: 1px solid rgba(0, 230, 118, 0.3);
  color: #c9ffe1;
}

/* ==========================================================================
   Interactive Video Player Preview
   ========================================================================== */
.player-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #000;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow: hidden;
}

.canvas-responsive-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 360px; /* Short default */
  aspect-ratio: 9 / 16;
  max-height: 65vh;
  margin: 0 auto;
  background: #121216;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.8);
}

.canvas-responsive-container.longform {
  max-width: 680px;
  aspect-ratio: 16 / 9;
  max-height: 48vh;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 580px;
  margin-top: 1rem;
}

.player-seek {
  flex: 1;
  accent-color: var(--accent-cyan);
  cursor: pointer;
  height: 6px;
}

.player-time {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ==========================================================================
   Scene Cards & Asset Swap UI
   ========================================================================== */
.scenes-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 1rem;
}

.scene-item-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: border-color 0.2s ease;
}

.scene-item-card:hover {
  border-color: var(--border-hover);
}

.scene-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.scene-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent-cyan);
}

.scene-order-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover:not(:disabled) {
  color: var(--text-main);
  border-color: var(--border-hover);
}

.btn-icon.btn-danger:hover {
  background: rgba(255, 59, 59, 0.2);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* Scene Fields Grid */
.scene-fields-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .scene-fields-grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input-text, .input-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s ease;
}

.input-textarea {
  resize: vertical;
  min-height: 85px;
  line-height: 1.45;
}

.input-text:focus, .input-textarea:focus {
  border-color: var(--border-focus);
}

/* Emphasis Tags Editor */
.emphasis-tags-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  min-height: 42px;
}

.emphasis-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 59, 59, 0.15);
  color: #ff8c8c;
  border: 1px solid rgba(255, 59, 59, 0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.emphasis-tag-remove {
  background: none;
  border: none;
  color: #ff8c8c;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 2px;
}

.emphasis-input-inline {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  flex: 1;
  min-width: 100px;
}

/* Scene Asset Swap Box */
.scene-asset-box {
  display: flex;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  align-items: center;
}

.scene-photo-thumb {
  width: 72px;
  height: 96px;
  border-radius: 6px;
  object-fit: cover;
  background: #000;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.scene-asset-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.scene-asset-btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.78rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
}

.scene-list-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* Modal Dialog */
dialog#settingsDialog {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 90%;
  max-width: 580px;
  margin: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  outline: none;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.dialog-title {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.dialog-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
}

.dialog-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.settings-note-banner {
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: #b3f2ff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-pickers-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
}

.color-picker-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}

.input-color {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
}

.color-hex-label {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.voice-test-row {
  display: flex;
  gap: 0.5rem;
}

.select-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 90vw;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  color: var(--text-main);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
  .app-container {
    padding: 0.75rem 0.75rem 3rem 0.75rem;
  }
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }
  .header-controls {
    justify-content: space-between;
  }
  .script-actions-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .script-actions-bar .btn {
    width: 100%;
  }
  .script-quick-buttons {
    width: 100%;
  }
  .script-quick-buttons .btn {
    flex: 1;
  }
}
