body {
  font-family: 'Inter', sans-serif;
}

/* ContentEditable placeholder */
#text-editor:empty:before {
  content: attr(data-placeholder);
  color: #64748b;
  pointer-events: none;
}

/* Syntax highlighting colors with frames (pill/badge style) */
.tag-emotion {
  color: #4ade80;
  font-weight: 600;
  background: rgba(74, 222, 128, 0.15);
  border: 1.5px solid rgba(74, 222, 128, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-pause {
  color: #f97316;
  font-weight: 600;
  background: rgba(249, 115, 22, 0.15);
  border: 1.5px solid rgba(249, 115, 22, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-speed {
  color: #fb923c;
  font-weight: 600;
  background: rgba(251, 146, 60, 0.15);
  border: 1.5px solid rgba(251, 146, 60, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-emphasis {
  color: #c084fc;
  font-weight: 600;
  background: rgba(192, 132, 252, 0.15);
  border: 1.5px solid rgba(192, 132, 252, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-invalid {
  color: #ef4444;
  font-weight: 600;
  background: rgba(239, 68, 68, 0.15);
  border: 1.5px solid rgba(239, 68, 68, 0.5);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
  text-decoration: wavy underline;
}

.tag-closing {
  color: #4ade80;
  font-weight: 600;
  background: rgba(74, 222, 128, 0.1);
  border: 1.5px solid rgba(74, 222, 128, 0.3);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
  opacity: 0.9;
}

.tag-pitch {
  color: #fbbf24;
  font-weight: 600;
  background: rgba(251, 191, 36, 0.15);
  border: 1.5px solid rgba(251, 191, 36, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-volume {
  color: #a78bfa;
  font-weight: 600;
  background: rgba(167, 139, 250, 0.15);
  border: 1.5px solid rgba(167, 139, 250, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

.tag-voice {
  color: #38bdf8;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.15);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  display: inline-block;
}

/* Sidebar styles */
#sidebar {
  transition: transform 0.3s ease, width 0.3s ease;
}

#sidebar.collapsed {
  transform: translateX(-100%);
}

#main-content {
  transition: margin-left 0.3s ease;
}

#main-content.sidebar-open {
  margin-left: 288px;
}

/* Scrollbar styling */
.custom-scrollbar::-webkit-scrollbar {
  width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(71, 85, 105, 0.8);
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.9);
}

/* Voice Segment Cards */
.voice-segment-card {
  background: rgba(30, 41, 59, 0.5);
  border: 2px solid rgba(71, 85, 105, 0.5);
  border-radius: 10px;
  padding: 16px;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

.voice-segment-card:hover {
  background: rgba(30, 41, 59, 0.7);
  border-color: rgba(100, 116, 139, 0.9);
}

.voice-segment-card.active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.25) 0%, rgba(37, 99, 235, 0.15) 100%);
  border: 3px solid #3b82f6;
  box-shadow:
    0 0 0 4px rgba(59, 130, 246, 0.3),
    0 8px 16px rgba(59, 130, 246, 0.2),
    inset 0 0 20px rgba(59, 130, 246, 0.1);
  transform: scale(1.02);
}

.voice-segment-card.active::before {
  content: '';
  position: absolute;
  left: -3px;
  top: -3px;
  bottom: -3px;
  width: 6px;
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%);
  border-radius: 10px 0 0 10px;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.voice-segment-card.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.segment-drag-handle {
  cursor: grab;
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

.segment-drag-handle:hover {
  opacity: 1;
}

.segment-drag-handle:active {
  cursor: grabbing;
}

/* Range slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
}

input[type="range"]::-webkit-slider-track {
  background: rgba(71, 85, 105, 0.5);
  height: 6px;
  border-radius: 3px;
}

input[type="range"]::-moz-range-track {
  background: rgba(71, 85, 105, 0.5);
  height: 6px;
  border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: #3b82f6;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  margin-top: -5px;
}

input[type="range"]::-moz-range-thumb {
  background: #3b82f6;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  border: none;
}

input[type="range"]:hover::-webkit-slider-thumb {
  background: #2563eb;
}

input[type="range"]:hover::-moz-range-thumb {
  background: #2563eb;
}

/* Segment number badge */
.segment-number {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  display: inline-block;
}

/* Voice frame (includes #1 Jenny + emotion) */
.segment-voice-frame {
  transition: all 0.3s ease;
  position: relative;
  overflow: visible;
}

.voice-segment-card.active .segment-voice-frame {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(147, 51, 234, 0.2) 50%, rgba(236, 72, 153, 0.2) 100%);
  border: 3px solid transparent;
  background-clip: padding-box;
  box-shadow:
    0 0 0 2px #3b82f6,
    0 0 20px rgba(59, 130, 246, 0.6),
    0 0 40px rgba(147, 51, 234, 0.4),
    0 0 60px rgba(236, 72, 153, 0.3),
    inset 0 0 20px rgba(59, 130, 246, 0.15);
}

/* Gradient border using box-shadow trick */
.voice-segment-card.active .segment-voice-frame::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #9333ea 50%, #ec4899 100%);
  z-index: -1;
  filter: blur(1px);
}

.voice-segment-card.active .segment-voice-frame .text-slate-200 {
  color: #e0e7ff !important;
  font-weight: 600 !important;
}

.voice-segment-card.active .segment-voice-frame .text-slate-400 {
  color: #c7d2fe !important;
  font-weight: 500 !important;
}

/* Empty state centering */
#empty-state {
  min-height: 300px;
}

/* Prevent text selection on drag */
.voice-segment-card.dragging * {
  user-select: none;
}

/* ============================================
   LIGHT MODE THEME
   ============================================ */

.light-mode {
  /* Override Tailwind dark backgrounds */
  color-scheme: light;
}

/* Body & Background */
.light-mode body {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%) !important;
  color: #1e293b !important;
}

/* Navigation */
.light-mode nav {
  background: rgba(255, 255, 255, 0.9) !important;
  border-bottom-color: #e2e8f0 !important;
}

.light-mode nav .text-white {
  color: #1e293b !important;
}

.light-mode nav .text-slate-300,
.light-mode nav .text-slate-400 {
  color: #64748b !important;
}

/* Sidebar */
.light-mode #sidebar {
  background: rgba(255, 255, 255, 0.95) !important;
  border-right-color: #e2e8f0 !important;
}

.light-mode #sidebar .text-white {
  color: #1e293b !important;
}

.light-mode #sidebar .text-slate-200 {
  color: #334155 !important;
}

.light-mode #sidebar .text-slate-300,
.light-mode #sidebar .text-slate-400 {
  color: #64748b !important;
}

.light-mode #sidebar .bg-slate-800\/50,
.light-mode #sidebar .bg-slate-900\/50 {
  background: rgba(241, 245, 249, 0.5) !important;
}

.light-mode #sidebar .border-slate-600,
.light-mode #sidebar .border-slate-700 {
  border-color: #cbd5e1 !important;
}

/* Input fields & selects */
.light-mode input,
.light-mode select,
.light-mode textarea {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #1e293b !important;
}

.light-mode input::placeholder,
.light-mode textarea::placeholder {
  color: #94a3b8 !important;
}

.light-mode input:focus,
.light-mode select:focus,
.light-mode textarea:focus {
  border-color: #3b82f6 !important;
  ring-color: #3b82f6 !important;
}

/* Content Editor */
.light-mode #text-editor {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #1e293b !important;
}

.light-mode #text-editor:empty:before {
  color: #94a3b8 !important;
}

/* Cards & Panels */
.light-mode .bg-slate-800\/50,
.light-mode .bg-slate-900\/50 {
  background: rgba(255, 255, 255, 0.8) !important;
}

.light-mode .bg-slate-800\/30,
.light-mode .bg-slate-900\/30 {
  background: rgba(241, 245, 249, 0.6) !important;
}

.light-mode .border-slate-600,
.light-mode .border-slate-700,
.light-mode .border-slate-800 {
  border-color: #cbd5e1 !important;
}

/* Text colors */
.light-mode .text-white {
  color: #0f172a !important;
}

.light-mode .text-slate-200 {
  color: #334155 !important;
}

.light-mode .text-slate-300 {
  color: #475569 !important;
}

.light-mode .text-slate-400 {
  color: #64748b !important;
}

.light-mode .text-slate-500 {
  color: #94a3b8 !important;
}

/* Voice Segment Cards */
.light-mode .voice-segment-card {
  background: rgba(255, 255, 255, 0.9) !important;
  border-color: #cbd5e1 !important;
}

.light-mode .voice-segment-card:hover {
  background: rgba(248, 250, 252, 1) !important;
  border-color: #94a3b8 !important;
}

.light-mode .voice-segment-card.active {
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.8) 0%, rgba(191, 219, 254, 0.6) 100%) !important;
  border-color: #3b82f6 !important;
}

/* Syntax Highlighting - Light Mode Variants */
.light-mode .tag-emotion {
  color: #059669 !important;
  background: rgba(16, 185, 129, 0.1) !important;
  border-color: rgba(16, 185, 129, 0.3) !important;
}

.light-mode .tag-pause {
  color: #ea580c !important;
  background: rgba(249, 115, 22, 0.1) !important;
  border-color: rgba(249, 115, 22, 0.3) !important;
}

.light-mode .tag-speed {
  color: #dc2626 !important;
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

.light-mode .tag-emphasis {
  color: #9333ea !important;
  background: rgba(147, 51, 234, 0.1) !important;
  border-color: rgba(147, 51, 234, 0.3) !important;
}

.light-mode .tag-pitch {
  color: #ca8a04 !important;
  background: rgba(234, 179, 8, 0.1) !important;
  border-color: rgba(234, 179, 8, 0.3) !important;
}

.light-mode .tag-volume {
  color: #7c3aed !important;
  background: rgba(124, 58, 237, 0.1) !important;
  border-color: rgba(124, 58, 237, 0.3) !important;
}

.light-mode .tag-voice {
  color: #0284c7 !important;
  background: rgba(2, 132, 199, 0.1) !important;
  border-color: rgba(2, 132, 199, 0.3) !important;
}

.light-mode .tag-invalid {
  color: #dc2626 !important;
  background: rgba(220, 38, 38, 0.1) !important;
  border-color: rgba(220, 38, 38, 0.4) !important;
}

.light-mode .tag-closing {
  color: #059669 !important;
  background: rgba(16, 185, 129, 0.08) !important;
  border-color: rgba(16, 185, 129, 0.25) !important;
  opacity: 0.85;
}

/* Scrollbar - Light Mode */
.light-mode .custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(241, 245, 249, 0.5) !important;
}

.light-mode .custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6) !important;
}

.light-mode .custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.8) !important;
}

/* Buttons - Keep accent colors, just adjust backgrounds */
.light-mode button:not([class*="bg-gradient"]):not([class*="bg-blue"]):not([class*="bg-green"]):not([class*="bg-orange"]):not([class*="bg-purple"]):not([class*="bg-emerald"]) {
  background: #f1f5f9 !important;
}

.light-mode button:hover:not([class*="bg-gradient"]) {
  background: #e2e8f0 !important;
}

/* Modals */
.light-mode .bg-black\/60 {
  background: rgba(0, 0, 0, 0.4) !important;
}

.light-mode #ai-modal .bg-slate-800,
.light-mode .bg-slate-800 {
  background: #ffffff !important;
}

/* Code blocks */
.light-mode code {
  background: #f1f5f9 !important;
  color: #1e293b !important;
}

.light-mode .bg-slate-950,
.light-mode .bg-slate-950\/50,
.light-mode .bg-slate-950\/80 {
  background: #f8fafc !important;
}

/* Empty state */
.light-mode #empty-state {
  color: #64748b !important;
}

/* Range sliders - Light mode */
.light-mode input[type="range"]::-webkit-slider-track {
  background: rgba(203, 213, 225, 0.7) !important;
}

.light-mode input[type="range"]::-moz-range-track {
  background: rgba(203, 213, 225, 0.7) !important;
}

/* Tip/Info Banner - Light mode */
.light-mode .bg-amber-500\/10 {
  background: rgba(251, 191, 36, 0.15) !important;
}

.light-mode .border-amber-500\/30 {
  border-color: rgba(245, 158, 11, 0.4) !important;
}

.light-mode .text-amber-200 {
  color: #92400e !important;
}

.light-mode .text-amber-100 {
  color: #78350f !important;
}

/* ===========================
   REFINED MOBILE-FIRST DESIGN
   =========================== */

/* Mobile: Bottom Sheet for Sidebar */
@media (max-width: 1024px) {
  #sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-radius: 24px 24px 0 0;
    border-right: none;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
  }

  #sidebar.active {
    transform: translateY(0);
  }

  /* Bottom sheet handle */
  #sidebar::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(148, 163, 184, 0.5);
    border-radius: 2px;
  }

  /* Adjust sidebar padding for handle */
  #sidebar > div {
    padding-top: 2rem;
  }

  /* Backdrop overlay */
  body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
  }

  body.sidebar-open::before {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main content full width on mobile */
  #main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding-bottom: 5rem;
  }
}

/* Floating Action Button (Mobile Only) */
@media (max-width: 1024px) {
  .mobile-fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobile-fab:active {
    transform: scale(0.92);
  }

  .mobile-fab svg {
    width: 24px;
    height: 24px;
    color: white;
  }

  .mobile-fab.active {
    transform: rotate(45deg);
  }

  /* Hide desktop sidebar toggle on mobile */
  .sidebar-open #main-content {
    margin-left: 0 !important;
  }
}

/* Refined Navigation for Mobile */
@media (max-width: 1024px) {
  nav {
    padding: 0;
  }

  nav .max-w-7xl {
    padding: 0.75rem 1rem;
  }

  /* Simplified nav - hide desktop sidebar toggle */
  #sidebar-toggle {
    display: none;
  }

  /* Hide non-essential nav items on mobile */
  #nav-usage,
  #upgrade-btn,
  #user-greeting {
    display: none !important;
  }

  /* Make logout button icon-only on mobile */
  nav a[href="/login"] {
    padding: 0.5rem;
    font-size: 0;
  }

  nav a[href="/login"]::before {
    content: '→';
    font-size: 1.125rem;
    font-weight: 600;
  }

  /* Tier badge more prominent */
  #user-tier {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 8px;
  }

  /* Logo slightly smaller */
  nav .text-lg {
    font-size: 1rem;
  }

  nav img.w-6 {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* Refined Converter Interface for Mobile */
@media (max-width: 1024px) {
  /* Full-width, optimized spacing */
  #main-content {
    padding: 1rem 0.75rem 6rem 0.75rem;
    min-height: 100vh;
  }

  /* Main converter card - full height optimization */
  #main-content .bg-slate-800\/50 {
    padding: 1rem;
    border-radius: 16px;
    height: calc(100vh - 7rem);
    display: flex;
    flex-direction: column;
  }

  /* Converter title - more compact */
  #main-content h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }

  #main-content > section > div > div > p {
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
  }

  /* Mode toggle - refined */
  #mode-visual,
  #mode-ssml {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
  }

  /* Editor/builder takes available space */
  #convert-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #visual-builder-container,
  #ssml-editor-container {
    flex: 1;
    min-height: 0;
  }

  /* Segment cards - cleaner mobile design */
  .segment-card {
    padding: 0.875rem !important;
    border-radius: 12px;
    margin-bottom: 0.75rem;
  }

  /* Action buttons - sticky at bottom */
  #action-buttons {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.98) 80%, transparent);
    padding: 1rem 0 0.5rem 0;
    margin: 0 -1rem -1rem -1rem;
    display: flex;
    gap: 0.75rem;
    z-index: 10;
  }

  #action-buttons button[type="submit"] {
    flex: 1;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.3);
  }

  #action-buttons button:not([type="submit"]) {
    padding: 1rem;
    border-radius: 12px;
    min-width: 56px;
  }

  /* Character counter - always visible */
  #charCounter,
  #charCounter-ssml {
    font-size: 0.875rem;
    font-weight: 600;
  }
}

/* AI Modal mobile optimization */
@media (max-width: 640px) {
  #ai-modal .bg-slate-800 {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
    max-width: calc(100vw - 2rem);
  }

  #ai-modal .p-6 {
    padding: 1rem;
  }

  #ai-modal .grid-cols-1 {
    grid-template-columns: 1fr;
  }

  #ai-modal .flex.gap-3 {
    flex-direction: column;
    gap: 0.75rem;
  }

  #ai-modal button {
    width: 100%;
  }
}

/* SSML Reference - Mobile Optimized */
@media (max-width: 1024px) {
  /* Hide SSML reference and info banner on mobile to reduce clutter */
  #main-content + section {
    display: none;
  }

  /* If we want to show it, make it compact */
  .lg\\:grid-cols-3 {
    grid-template-columns: 1fr;
  }

  .lg\\:col-span-2 {
    grid-column: span 1;
  }

  /* Make SSML reference collapsible and compact */
  #ssml-reference {
    max-height: 300px;
    overflow-y: auto;
  }

  #ssml-reference .bg-slate-900\/50 {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
  }

  #ssml-reference code {
    font-size: 0.6875rem;
    overflow-x: auto;
    padding: 0.5rem;
  }

  #ssml-reference h4 {
    font-size: 0.875rem;
  }

  #ssml-reference p {
    font-size: 0.75rem;
  }
}

@media (max-width: 768px) {
  .md\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
}

/* Footer mobile optimization */
@media (max-width: 768px) {
  footer .grid-cols-1 {
    gap: 1.5rem;
  }

  footer {
    padding-top: 2rem;
  }

  footer .py-12 {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
}

/* Voice controls sidebar section mobile */
@media (max-width: 1024px) {
  #sidebar {
    width: 85vw;
    max-width: 320px;
  }

  #sidebar .space-y-4 {
    padding-bottom: 2rem;
  }
}

/* Text size adjustments for small screens */
@media (max-width: 640px) {
  h1 {
    font-size: 1.5rem;
    line-height: 2rem;
  }

  h2 {
    font-size: 1.25rem;
    line-height: 1.75rem;
  }

  h3 {
    font-size: 1rem;
    line-height: 1.5rem;
  }

  /* Converter title */
  #main-content h2 {
    font-size: 1rem;
  }

  #main-content p {
    font-size: 0.75rem;
  }
}

/* Prevent horizontal scroll */
body {
  overflow-x: hidden;
}

#main-content,
#sidebar,
.max-w-7xl {
  max-width: 100vw;
}

/* Touch target sizes - make buttons easier to tap */
@media (max-width: 768px) {
  button,
  a,
  select,
  input[type="range"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Exception for icon-only buttons */
  button svg {
    width: 1.25rem;
    height: 1.25rem;
  }
}
