/* ============================================================
   Good News Radio — Premium Dark Theme
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Base palette */
  --bg-deep: #160B2A; /* Rich, warm indigo */
  --bg-surface: rgba(40, 20, 65, 0.5); /* Deep, slightly tinted glass */
  --bg-surface-hover: rgba(55, 30, 85, 0.7);
  --bg-input: rgba(10, 5, 25, 0.6);

  /* Accent gradient */
  --accent-start: #FF416C; /* Vibrant crimson/pink */
  --accent-end: #FF4B2B;   /* Blazing orange */
  --accent-mid: #FFB75E;   /* Warm gold */
  --accent-gradient: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  --accent-glow: rgba(255, 65, 108, 0.35);

  /* CTA */
  --cta-start: #00F2FE;
  --cta-end: #4FACFE;
  --cta-gradient: linear-gradient(135deg, var(--cta-start), var(--cta-end));

  /* Text - High Contrast */
  --text-primary: #FFFFFF;
  --text-secondary: #E9D5FF; /* Soft purple-white */
  --text-muted: #A78BFA;

  /* Glass */
  --glass-border: rgba(255, 255, 255, 0.15);
  --glass-blur: 24px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Shadows */
  --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.05), 0 0 0 1px var(--glass-border);
  --shadow-glow: 0 0 30px var(--accent-glow), 0 0 60px rgba(255, 65, 108, 0.2);

  /* Fonts */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.2s var(--ease-out);
  --transition-med: 0.35s var(--ease-out);
  --transition-slow: 0.5s var(--ease-out);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* --- Animated Background Glows --- */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
  animation: glow-drift 15s ease-in-out infinite alternate;
}

.bg-glow--1 {
  width: 600px;
  height: 600px;
  background: var(--accent-start);
  top: -15%;
  left: -10%;
  animation-duration: 18s;
}

.bg-glow--2 {
  width: 500px;
  height: 500px;
  background: var(--accent-end);
  bottom: -10%;
  right: -8%;
  animation-duration: 22s;
  animation-delay: -5s;
}

.bg-glow--3 {
  width: 400px;
  height: 400px;
  background: var(--cta-start);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.12;
  animation-duration: 25s;
  animation-delay: -10s;
}

@keyframes glow-drift {
  0% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
  100% { transform: translate(10px, -10px) scale(1.02); }
}

/* --- App Container --- */
.app-container {
  width: 95%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Layout --- */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 2rem;
  align-items: start;
  transition: max-height 0.6s var(--ease-out), opacity 0.6s var(--ease-out), margin 0.6s var(--ease-out), gap 0.6s var(--ease-out);
  max-height: 2000px;
  opacity: 1;
  overflow: hidden;
}

.main-layout.collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0;
  gap: 0;
}

@media (min-width: 860px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 2rem;
  }
}

.layout-left, .layout-right {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* --- Header --- */
.app-header {
  margin-bottom: 2rem;
}

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

.logo-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  animation: pulse-subtle 4s ease-in-out infinite;
}

@keyframes pulse-subtle {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px var(--accent-glow)); }
  50% { transform: scale(1.05); filter: drop-shadow(0 0 14px var(--accent-glow)); }
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
  margin-top: 2px;
}

.settings-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.settings-link:hover {
  color: var(--accent-start);
  border-color: rgba(255, 65, 108, 0.3);
  box-shadow: 0 0 20px rgba(255, 65, 108, 0.15);
  transform: rotate(45deg);
}

/* --- Glass Panels --- */
.glass-panel {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  animation: panel-enter 0.5s var(--ease-out) both;
}

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Controls Panel --- */
.controls-panel {
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 560px) {
  .controls-grid { grid-template-columns: 1fr; }
}
.control-group, .field-group {
  margin-bottom: 0.5rem;
}

.control-group:last-child, .field-group:last-child {
  margin-bottom: 0;
}
.control-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.length-input-wrapper {
  position: relative;
}

.length-input-wrapper input {
  width: 100%;
  padding: 0.75rem 5rem 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -moz-appearance: textfield;
}

.length-input-wrapper input::-webkit-inner-spin-button,
.length-input-wrapper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.length-input-wrapper input:focus {
  outline: none;
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(255, 65, 108, 0.15);
}

.input-suffix {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--text-muted);
  pointer-events: none;
}

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

.voice-row select {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

.voice-row select:focus {
  outline: none;
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(255, 65, 108, 0.15);
}

.voice-row select option {
  background: #281441;
  color: var(--text-primary);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.icon-btn:hover:not(:disabled) {
  color: var(--accent-start);
  border-color: rgba(255, 65, 108, 0.3);
  background: rgba(255, 65, 108, 0.08);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.distribution-section {
}

.section-subtitle {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.sliders-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.slider-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-start);
  min-width: 3rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Custom range slider */
.dist-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  outline: none;
  transition: background var(--transition-fast);
}

.dist-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gradient);
  cursor: pointer;
  border: 2px solid var(--bg-deep);
  box-shadow: 0 0 8px var(--accent-glow);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.dist-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 16px var(--accent-glow);
}

.dist-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gradient);
  cursor: pointer;
  border: 2px solid var(--bg-deep);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* --- Buttons --- */
.action-row {
  display: flex;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 2rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all var(--transition-med);
  text-decoration: none;
  line-height: 1;
}

.btn--primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 65, 108, 0.2);
}

.btn--primary:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 30px rgba(255, 65, 108, 0.35);
}

.btn--primary:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.btn--glow {
  position: relative;
}

.btn--glow::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: var(--accent-gradient);
  filter: blur(14px);
  opacity: 0;
  z-index: -1;
  transition: opacity var(--transition-med);
}

.btn--glow:hover::before {
  opacity: 0.5;
}

.btn--secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

.btn--secondary:hover {
  border-color: rgba(255, 65, 108, 0.3);
  box-shadow: 0 0 20px rgba(255, 65, 108, 0.1);
  transform: translateY(-1px);
}

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

/* --- Status Area --- */
.status-area {
  text-align: center;
  padding: 1rem 0;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.status-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: color var(--transition-fast);
}

.status-text strong {
  color: var(--accent-start);
  font-weight: 600;
}

.status-text.status-error {
  color: #f87171;
}

/* --- Loader: Radio Wave Animation --- */
.loader-wave {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
}

.loader-wave span {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: var(--accent-gradient);
  animation: wave-bounce 1.2s ease-in-out infinite;
}

.loader-wave span:nth-child(1) { animation-delay: 0s; height: 10px; }
.loader-wave span:nth-child(2) { animation-delay: 0.1s; height: 18px; }
.loader-wave span:nth-child(3) { animation-delay: 0.2s; height: 28px; }
.loader-wave span:nth-child(4) { animation-delay: 0.1s; height: 18px; }
.loader-wave span:nth-child(5) { animation-delay: 0s; height: 10px; }

@keyframes wave-bounce {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* --- Editor Panel --- */
.editor-panel {
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.panel-title svg {
  color: var(--accent-start);
  flex-shrink: 0;
}

#script-editor {
  width: 100%;
  flex: 1;
  min-height: 280px;
  padding: 1rem 1.25rem;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.7;
  resize: vertical;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
}

#generate-action-area {
  transition: max-height 0.6s var(--ease-out), opacity 0.6s var(--ease-out), margin 0.6s var(--ease-out);
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
}

#generate-action-area.collapsed {
  max-height: 0 !important;
  opacity: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#script-editor:focus {
  outline: none;
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(255, 65, 108, 0.12);
}

#script-editor::placeholder {
  color: var(--text-muted);
}

/* --- Output Panel --- */
.output-panel {
}

.audio-player-wrapper {
  margin: 1rem 0;
}

#audio-player {
  width: 100%;
  border-radius: var(--radius-sm);
  outline: none;
}

/* Style native audio controls in supported browsers */
audio::-webkit-media-controls-panel {
  background: var(--bg-input);
}

/* --- Footer --- */
.app-footer {
  text-align: center;
  padding: 2rem 0 1rem;
  border-top: 1px solid var(--glass-border);
  margin-top: 1rem;
}

.app-footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

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

.toast {
  pointer-events: auto;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  background: rgba(15, 20, 45, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.4s var(--ease-out);
  max-width: 360px;
}

.toast--error {
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

.toast--success {
  border-color: rgba(52, 211, 153, 0.3);
  color: #6ee7b7;
}

.toast.toast-out {
  animation: toast-out 0.3s var(--ease-out) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* --- Generation Overlay --- */
.generation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 10, 20, 0.9);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease-out);
}

.generation-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.animated-text-container {
  text-align: center;
  font-family: var(--font-sans);
  font-size: 3rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
}

.animated-phrase {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(30px);
  opacity: 0;
  width: 100%;
  padding: 0 2rem;
  animation: slidePhrase 2.5s var(--ease-out) forwards;
}

@keyframes slidePhrase {
  0% { opacity: 0; transform: translate(-50%, -50%) translateY(30px); }
  10% { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
  90% { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-30px); }
}


/* --- Responsive --- */
@media (max-width: 480px) {
  .app-container {
    padding: 1rem 0.75rem 2rem;
  }

  .app-header h1 {
    font-size: 1.4rem;
  }

  .glass-panel {
    padding: 1.25rem;
    border-radius: var(--radius-md);
  }

  .btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
  }

  .logo-icon {
    width: 40px;
    height: 40px;
  }
}
