/* =============================================================================
   styles.css — Piper TTS Studio Design System (Modern Glassmorphism)
   ============================================================================= */

:root {
  --bg-dark: #070b14;
  --bg-surface: rgba(15, 23, 42, 0.75);
  --bg-surface-elevated: rgba(30, 41, 59, 0.85);
  --border-glass: rgba(255, 255, 255, 0.1);
  --border-glass-focus: rgba(56, 189, 248, 0.4);

  --accent-cyan: #38bdf8;
  --accent-indigo: #818cf8;
  --accent-purple: #c084fc;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --gradient-brand: linear-gradient(135deg, #38bdf8 0%, #818cf8 50%, #c084fc 100%);
  --gradient-glow: radial-gradient(circle, rgba(56, 189, 248, 0.25) 0%, rgba(129, 140, 248, 0) 70%);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(56, 189, 248, 0.35);

  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 15% 15%, rgba(56, 189, 248, 0.08) 0px, transparent 50%),
    radial-gradient(at 85% 85%, rgba(192, 132, 252, 0.08) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(15, 23, 42, 0.6) 0px, transparent 100%);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Base Layout Container */
.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  gap: 1.5rem;
}

/* Glassmorphism Card Style */
.glass-card {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

/* -----------------------------------------------------------------------------
   Header
   ----------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text h1 span {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-full);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulse-ring 2s infinite;
}

.pulse-dot.error {
  background: var(--accent-rose);
  box-shadow: 0 0 10px var(--accent-rose);
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.75; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.75; }
}

.status-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-emerald);
}

.status-indicator.error .status-label {
  color: var(--accent-rose);
}

.voice-picker-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border-glass);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  color: var(--accent-cyan);
  font-size: 0.82rem;
}

.voice-picker-pill select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.voice-picker-pill select option {
  background: #0f172a;
  color: #fff;
}

/* -----------------------------------------------------------------------------
   Main Grid Layout
   ----------------------------------------------------------------------------- */
.main-content {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  flex: 1;
}

/* -----------------------------------------------------------------------------
   LEFT PANEL: Avatar & Player
   ----------------------------------------------------------------------------- */
.avatar-panel {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 1.25rem;
}

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

.panel-header h2 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.panel-header h2 i {
  color: var(--accent-cyan);
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
}

.live-badge {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.live-badge.speaking {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
  animation: pulse-badge 1s infinite alternate;
}

@keyframes pulse-badge {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}

/* Avatar Visualizer Stage */
.avatar-stage {
  position: relative;
  width: 100%;
  height: 260px;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.95) 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.avatar-glow-ring {
  position: absolute;
  width: 210px;
  height: 210px;
  border-radius: 50%;
  background: var(--gradient-glow);
  opacity: 0.4;
  filter: blur(20px);
  pointer-events: none;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.avatar-stage.speaking .avatar-glow-ring {
  opacity: 0.85;
  transform: scale(1.15);
}

.avatar-viewport {
  width: 200px;
  height: 200px;
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease;
}

.avatar-stage.speaking .avatar-viewport {
  animation: avatar-nod 1.6s infinite ease-in-out;
}

@keyframes avatar-nod {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(0.5deg); }
}

.visualizer-wrapper {
  position: absolute;
  bottom: 8px;
  width: 90%;
  height: 48px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

#waveformCanvas {
  width: 100%;
  height: 100%;
}

/* Audio Controller Card */
.audio-controller {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-surface-elevated);
  padding: 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
}

.playback-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.time-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 32px;
}

.progress-bar-container {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--gradient-brand);
  border-radius: var(--radius-full);
  transition: width 0.1s linear;
}

.player-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

/* Button UI Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.15rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

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

.btn-primary {
  background: var(--accent-cyan);
  color: #070b14;
}

.btn-primary:not(:disabled):hover {
  background: #7dd3fc;
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
}

.btn-secondary:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-gradient {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: 0 4px 15px rgba(129, 140, 248, 0.3);
}

.btn-gradient:not(:disabled):hover {
  opacity: 0.95;
  box-shadow: 0 6px 20px rgba(129, 140, 248, 0.5);
  transform: translateY(-1px);
}

/* Slider Controls */
.audio-sliders-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.slider-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.slider-group label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.speed-toggle-group {
  display: flex;
  gap: 0.25rem;
  background: rgba(15, 23, 42, 0.6);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.speed-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-btn.active {
  background: var(--accent-cyan);
  color: #070b14;
  font-weight: 700;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 110px;
  height: 5px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.6);
}

/* Voice Details Card */
.voice-details-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.4);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.detail-key {
  color: var(--text-muted);
}

.detail-val {
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.detail-val.highlight {
  color: var(--accent-cyan);
  font-weight: 600;
}

/* -----------------------------------------------------------------------------
   RIGHT PANEL: Chat & Read Aloud
   ----------------------------------------------------------------------------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 1.25rem;
  height: calc(100vh - 120px);
}

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

.chat-header-title h2 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-header-title h2 i {
  color: var(--accent-indigo);
}

.chat-header-title p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Chat Stream */
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

/* Custom Scrollbar */
.chat-stream::-webkit-scrollbar {
  width: 6px;
}
.chat-stream::-webkit-scrollbar-track {
  background: transparent;
}
.chat-stream::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

/* Chat Bubbles */
.chat-bubble {
  display: flex;
  gap: 0.85rem;
  max-width: 88%;
  animation: fadeInMsg 0.3s ease forwards;
}

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

.user-bubble {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-bubble {
  align-self: flex-start;
}

.bubble-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.user-bubble .bubble-avatar {
  background: rgba(129, 140, 248, 0.2);
  color: var(--accent-indigo);
  border: 1px solid rgba(129, 140, 248, 0.3);
}

.ai-bubble .bubble-avatar {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.bubble-body {
  background: var(--bg-surface-elevated);
  padding: 0.95rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.user-bubble .bubble-body {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.25);
  border-bottom-right-radius: 4px;
}

.ai-bubble .bubble-body {
  border-bottom-left-radius: 4px;
}

/* Active Highlight when Read Aloud is playing this bubble */
.chat-bubble.active-speaking .bubble-body {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
}

.bubble-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.sender-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.user-bubble .sender-name {
  color: var(--accent-indigo);
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.bubble-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.6;
}

.bubble-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-read-bubble {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent-cyan);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-read-bubble:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent-cyan);
  transform: translateY(-1px);
}

.btn-read-bubble.playing {
  background: var(--accent-cyan);
  color: #070b14;
}

.bubble-voice-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Custom Synthesizer Sandbox Box */
.custom-synth-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.synth-input-wrapper textarea {
  width: 100%;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 0.65rem 0.85rem;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}

.synth-input-wrapper textarea:focus {
  border-color: var(--accent-cyan);
}

.synth-controls-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.quick-voices {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
}

.quick-voice-label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.quick-voices select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.quick-voices select option {
  background: #0f172a;
  color: #fff;
}

/* -----------------------------------------------------------------------------
   Toast Notifications
   ----------------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-glass-focus);
  backdrop-filter: blur(12px);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  color: var(--accent-cyan);
  font-size: 1.1rem;
}

.toast-message {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* -----------------------------------------------------------------------------
   Responsive Breakpoints
   ----------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  .avatar-panel {
    order: 1;
  }

  .chat-panel {
    order: 2;
    height: auto;
    min-height: 550px;
  }
}
