/* =====================================
   🎨 SoundMuse AI – Master CSS Stylesheet
   Includes: Base Styles, Sidebar, Panels, Dark/Light Mode, Starling Glow
   ===================================== */

/* === Base Styles === */
body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', sans-serif;
  color: #333;
  transition: background 0.5s, color 0.5s;
  background: linear-gradient(135deg, #eae6f9, #d6f4f1);
  background-image: url('Background-aurora.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
  background-color: #000; /* fallback */
}

body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: -1;
}

/* === Dark Mode === */
body.dark-theme {
  background: linear-gradient(135deg, #1f1f2f, #1a2c2c);
  color: #f1f1f1;
  background-image: url('Background-aurora.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
  background-color: #000;
}

body.dark-theme::before {
  background: rgba(0, 0, 0, 0.4);
}

body.dark-theme .panel,
body.dark-theme .popup,
body.dark-theme .spectrogram-box,
body.dark-theme .image-box,
body.dark-theme .input-box,
body.dark-theme .right-panel textarea {
  background-color: #2a2a3d;
  color: #eee;
  border-color: #666;
}

body.dark-theme .lyrics-snippet {
  background: rgba(32, 32, 48, 0.85);
  color: #f8f8f8;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.1);
}

body.dark-theme .toolbar {
  background: linear-gradient(180deg, #5b4d91, #3b7b7b);
  border-right: 1px solid #666;
}

body.dark-theme .toolbar button:hover {
  filter: brightness(1.2);
}

/* Splash loading screen */
#splash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: url('splash-background.png?v=2') no-repeat center center;
  background-size: cover;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 1s ease-out;
  opacity: 1;
}

#splash-text {
  font-family: 'Segoe UI', sans-serif;
  font-size: 2.2rem;
  font-weight: bold;
  color: #ffffff;
  text-align: center;
  text-shadow: 0 0 6px rgba(173, 216, 230, 0.8),
               0 0 20px rgba(185, 160, 255, 0.6);
  padding: 1rem 2rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  position: absolute;
  bottom: 60px;
  z-index: 10000;
}

/* === Toolbar (Sidebar) === */
.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100px;
  background: linear-gradient(180deg, #c3b3e5, #a3d6d6);
  border-right: 1px solid #bbb;
  padding-top: 10px;
  z-index: 10;
  transition: background 0.5s;
}

.toolbar button {
  background: none;
  border: none;
  margin: 10px 0;
  font-size: 24px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.toolbar button:hover {
  transform: scale(1.2);
}

/* Make linked icons behave like the old buttons */
.toolbar a {
  margin: 10px 0;
}

.toolbar img.icon {
  width: 28px;
  height: 28px;
  transition: transform 0.2s ease;
}

.toolbar img.icon:hover {
  transform: scale(1.2);
}
/* Aurora shimmer effect for icons in dark mode only */
body.dark-theme .toolbar img.icon:hover {
  transform: scale(1.2);
  filter: 
    drop-shadow(0 0 4px #7fffd4)      /* aqua glow */
    drop-shadow(0 0 8px #9370DB)      /* medium purple */
    drop-shadow(0 0 12px #00FF7F)     /* spring green */
    drop-shadow(0 0 16px #4682B4);    /* steel blue */;
  transition: filter 0.3s ease, transform 0.2s ease;
}

/* === Sidebar User Profile === */
.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  padding: 10px 0;
}

.profile-pic {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #d6c8f5;
  margin-bottom: 6px;
  transition: transform 0.3s, box-shadow 0.3s;
}

.sidebar-username {
  font-size: 14px;
  font-weight: bold;
  color: #333;
  text-align: center;
}
/* === Username Contrast & Hover Glow === */
body.dark-theme .sidebar-username {
  color: #f0f0f0;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.1);
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

body.dark-theme .sidebar-username:hover {
  color: #ffffff;
  text-shadow:
    0 0 4px rgba(150, 200, 255, 0.4),
    0 0 8px rgba(180, 240, 255, 0.5),
    0 0 12px rgba(200, 255, 255, 0.3);
  cursor: default;
}
/* Small timestamp label used on Saved pages */
.chat-date {
  font-size: 0.9rem;
  color: #ccc;
  white-space: nowrap;
}
body.dark-theme .chat-date {
  color: #cfd3ff;
}

/* === User Preference Controls === */
.user-preferences {
  margin-top: 30px;
}

.preferences-subtext {
  font-size: 0.9em;
  color: #ccc;
  margin-bottom: 10px;
}

.master-toggle {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.master-toggle input[type="checkbox"] {
  margin-left: 10px;
  transform: scale(1.2);
}

.preference-group {
  margin-bottom: 20px;
}

.preference-group label {
  color: #eee;
  margin-left: 4px;
}

/* === Starling Avatar Glow (dark mode only) === */
body.dark-theme .profile-pic {
  animation: avatarGlow 2.5s ease-in-out infinite alternate;
  box-shadow: 0 0 10px 3px rgba(150, 200, 255, 0.4);
}

@keyframes avatarGlow {
  0%   { box-shadow: 0 0 8px 2px rgba(150, 200, 255, 0.3); }
  100% { box-shadow: 0 0 16px 6px rgba(200, 240, 255, 0.6); }
}

/* === MAIN LAYOUT CONTAINER === */
.main-content {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  height: 100vh;
  padding: 20px;
  box-sizing: border-box;
  padding-bottom: 120px; /* PATCH: ensures content above audio bar */
}

/* === LEFT PANEL === */
.left-panel {
  flex: 1;
  max-width: 30%;
  display: flex;
  flex-direction: column;
  background: #f2f2f2;
  padding: 10px;
  border-radius: 6px;
  overflow-y: auto;
  margin-left: 100px;
}

.left-panel .chat-box {
  flex: 1;
  background: #f2f2f2;
  padding: 10px;
  border-radius: 6px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.input-box {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #ccc;
}

/* === CENTER PANEL === */
.center-panel {
  flex: 1;
  max-width: 34%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.spectrogram-box,
.image-box {
  flex: 1;
  background: #f9f9f9;
  border: 1px dashed #aaa;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 15px;
  text-align: center;
}

.upload-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 5px;
  position: relative;
  z-index: 1;
  padding-bottom: 8px;
}

/* === Album Art & Aspect Ratio Selector === */
.album-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
  padding-bottom: 60px; /* PATCH: prevent hidden title/ratio selector */
}

.album-art {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 10px;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.2);
}

.album-title {
  position: relative;
  z-index: 2; /* PATCH */
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 8px;
  text-align: center;
  color: var(--text-color, #ffffff); /* default white fallback */
}

.ratio-selector {
  position: relative;
  z-index: 3; /* PATCH */
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 14px;
  margin-bottom: 10px;
  border: 1px solid #888;
  text-align: center;
}

.ratio-selector select {
  background-color: #222;
  color: #fff;
  border: none;
  padding: 4px;
  margin-left: 6px;
}

.upload-controls select,
.upload-controls input[type="file"] {
  border-radius: 6px;
  border: 1px solid #ccc;
  padding: 5px;
  font-size: 14px;
}

.audio-upload {
  margin-top: 10px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(250, 250, 255, 0.2));
  border: 1px solid rgba(200, 200, 255, 0.3);
  border-radius: 10px;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(4px);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.audio-upload label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  color: #222;
  text-shadow: 0 0 1px rgba(255,255,255,0.4);
}

.audio-upload input[type="file"] {
  padding: 6px;
  border: 1px solid #aaa;
  border-radius: 6px;
  font-size: 14px;
  background: #f8f8f8;
  color: #333;
}

/* 🌙 Dark Mode Upgrade */
body.dark-theme .audio-upload {
  background: linear-gradient(135deg, rgba(40, 40, 60, 0.6), rgba(20, 20, 40, 0.4));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.07);
}

body.dark-theme .audio-upload label {
  color: #f1f1f1;
  text-shadow: 0 0 2px rgba(173, 216, 230, 0.5);
}

body.dark-theme .audio-upload input[type="file"] {
  background: #2a2a3d;
  color: #eee;
  border-color: #555;
}

/* 📱 Responsive (Tablet & below) */
@media (max-width: 768px) {
  .audio-upload {
    padding: 8px;
    font-size: 13px;
  }

  .audio-upload input[type="file"] {
    font-size: 13px;
  }
}

/* === Responsive: Tablet Landscape (e.g. 1024px) === */
@media (max-width: 1024px) {
  body {
    overflow-y: auto !important;
  }

  .main-content {
    max-height: none !important;
    overflow-y: auto;
    padding-bottom: 120px; /* PATCH: space for audio bar */
  }

  .left-panel,
  .center-panel,
  .right-panel {
    max-height: none !important;
    overflow: visible !important;
  }

  .audio-upload {
    margin-bottom: 80px; /* lift upload box */
  }

  .toolbar button:last-child {
    margin-bottom: 100px; /* move ... above audio bar */
  }

  /* FIX: Prevent audio bar from jumping to top */
  .music-player {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
  }

  .music-player audio {
    margin: 0 auto;
    display: block;
    max-width: 600px;
    width: 90%;
  }

  /* FIX: Ensure image ratio selector is always visible */
  .upload-controls {
    position: relative;
    z-index: 1;
    padding-bottom: 8px;
  }

  /* FIX: Lyrics panel width restore */
  .right-panel {
    flex: 1;
    min-width: 280px;
  }

  /* FIX: Allow GPT chat panel to show in portrait */
  .left-panel {
    display: block !important;
  }
     /* Ensure toolbar is scrollable on tablets */
  .toolbar {
    overflow-y: auto;
  }

  /* Limit left-panel from overflowing viewport on tablets */
  .left-panel {
    max-height: 80vh;
    overflow-y: auto;
  }

  /* Restore image-controls if hidden due to layout shift */
  .image-controls {
    display: block;
    padding-top: 10px;
  }
}

/* === RIGHT PANEL === */
.right-panel {
  flex: 1;
  max-width: 34%;
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #ccc;
  min-height: 300px;
  font-size: 14px;
}

/* === More Popup === */
.popup {
  display: none;
  position: fixed;
  left: 100px;
  top: 10px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
  padding: 10px;
  z-index: 20;
}

.popup ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.popup li {
  margin: 8px 0;
}

.popup a {
  text-decoration: none;
  color: #333;
}

/* === Music Player Bar === */
.music-player {
  width: 100%;
  background: #1e1e1e;
  padding: 10px;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.2);
  z-index: 100;
}

.music-player audio {
  width: 100%;
  margin-top: 10px;
  border-radius: 8px;
  max-width: 800px;
}

/* === Responsive === */
@media (max-width: 1000px) {
  .main-grid {
    grid-template-columns: 1fr;
    margin-left: 90px;
  }

  .panel {
    min-height: auto;
  }

  body {
    overflow-y: auto !important;
  }

  .main-content {
    max-height: none !important;
    overflow-y: auto;
    padding-bottom: 140px; /* space above audio player */
  }

  .left-panel, .center-panel, .right-panel {
    max-height: none !important;
    overflow: visible !important;
  }

  .audio-upload {
    margin-bottom: 120px;
  }

  .upload-controls {
    position: relative;
    z-index: 2;
    padding-bottom: 8px;
  }

  .upload-controls select {
    position: relative;
    z-index: 3;
  }
}

.lyrics-snippet {
  font-size: 15px;
  line-height: 1.6;
  padding: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  color: #222;
  max-height: 400px;
  overflow-y: auto;
}
/* === Quick Stability Patch: Hide ratio selector === */
.ratio-selector {
  display: none !important;
}
