/* ========== FULL-SCREEN LYRICS VIEWER STYLES ========== */

#fullscreen-lyrics-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: radial-gradient(circle at top right, rgba(251, 140, 0, 0.08), transparent 28%),
              radial-gradient(circle at bottom left, rgba(59, 130, 246, 0.06), transparent 34%),
              linear-gradient(160deg, #08101d 0%, #0e1628 50%, #131a2f 100%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.light-mode #fullscreen-lyrics-container {
  background: linear-gradient(135deg, #f8f9fa 0%, #f0f1f3 100%);
}

.fullscreen-lyrics-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0;
  margin: 0;
  position: relative;
  transition: all 0.3s ease-out;
}

.fullscreen-lyrics-wrapper.controls-hidden .fullscreen-lyrics-header,
.fullscreen-lyrics-wrapper.controls-hidden .fullscreen-controls-bar,
.fullscreen-lyrics-wrapper.controls-hidden .fs-bottom-pill-wrapper {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-100%);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.fullscreen-lyrics-wrapper.controls-hidden .fullscreen-lyrics-header {
  transform: translateY(-100%);
}

.fullscreen-lyrics-wrapper.controls-hidden .fullscreen-controls-bar {
  transform: translateY(100%);
}

.fullscreen-lyrics-header {
  padding: 24px 20px 16px;
  background: rgba(15, 25, 45, 0.96); /* Solidified background for better readability */
  backdrop-filter: blur(20px); /* Increased blur for glass effect */
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
  visibility: visible;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

body.light-mode .fullscreen-lyrics-header {
  background: rgba(255, 255, 255, 0.95);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

.fullscreen-song-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.fullscreen-title {
  margin: 0 0 8px 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 900;
  color: var(--primary); /* Title pops with primary color */
  line-height: 1.1;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.fullscreen-composer {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dim);
  font-style: italic;
}

body.light-mode .fullscreen-title {
  text-shadow: none;
}

.fullscreen-singer {
  margin: 4px 0 0 0;
  font-size: 0.9rem;
  color: var(--primary);
  font-weight: 600;
}

.fullscreen-lyrics-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 130px 20px 160px; /* Increased padding to ensure content is never hidden under header/footer */
  scroll-padding-top: 130px;
  scroll-behavior: smooth; /* Smooth scrolling for programmatic scrolls */
  will-change: scroll-position; /* Hint to the browser for rendering optimization */
  display: block; /* Important: prevents vertical centering which clips top lines on overflow */
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
  box-sizing: border-box;
}

.fullscreen-lyrics-content .lyrics-container {
  width: 100%;
  max-width: 700px;
  background: rgba(10, 16, 31, 0.6);
  padding: 32px 28px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  margin: 0 auto;
}

.fullscreen-lyrics-content .lyrics-content {
  font-size: var(--lyrics-font-size-fs, clamp(1.2rem, 5vw, 2rem)); /* Use variable, fallback to clamp */
  line-height: 1.75;
  color: var(--text-main);
  white-space: normal;
  word-wrap: break-word;
  gap: 1rem; /* Tightened gap between sections for full-screen view */
  text-align: left; /* Enforce left alignment as per user input */
  letter-spacing: 0.02em;
  animation: fsLyricsFadeIn 0.4s ease-out; /* Smooth entrance for new song lyrics */
}

@keyframes fsLyricsFadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

@media print {
  #fullscreen-lyrics-container {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }

  .fullscreen-lyrics-wrapper {
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .fullscreen-lyrics-header,
  .fullscreen-controls-bar,
  .fs-bottom-pill-wrapper,
  .btn-back-full,
  .detail-lang-switch,
  .exit-reading-btn,
  .player {
    display: none !important;
  }

  .fullscreen-lyrics-content {
    overflow: visible !important;
    padding: 0 !important;
    max-width: none !important;
    margin: 0 auto !important;
  }

  .fullscreen-lyrics-content .lyrics-container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  .fullscreen-lyrics-content .lyrics-content {
    font-size: 14pt !important;
    line-height: 1.6 !important;
    color: black !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    white-space: pre-wrap !important;
  }

  .fullscreen-lyrics-content .lyrics-content p {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 0 0 10pt !important;
  }

  body {
    background: white !important;
    color: black !important;
  }
}

.fs-counter-pill {
  background: var(--primary);
  color: #fff; /* High visibility white text */
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fs-lang-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 4px 10px;
  border-radius: 15px;
  font-size: 0.75rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.fs-lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white; /* Ensure text is white on primary background */
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.3); /* Add a subtle glow */
  transform: translateY(-1px); /* Give it a slight lift */
}

body.light-mode .fs-lang-btn {
  color: #202124;
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .fs-lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white; /* Ensure text is white on primary background */
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.2); /* Adjust shadow for light mode */
}

body.light-mode .fs-counter-pill {
  border-color: rgba(0, 0, 0, 0.05);
}

body.light-mode .fullscreen-lyrics-content .lyrics-container {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);
}

.fullscreen-controls-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: max(24px, env(safe-area-inset-bottom) + 16px);
  background: rgba(15, 25, 45, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
  visibility: visible;
}

body.light-mode .fullscreen-controls-bar {
  background: rgba(255, 255, 255, 0.95);
  border-top-color: rgba(0, 0, 0, 0.1);
}

.fullscreen-control-btn {
  appearance: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 183, 77, 0.2);
  color: var(--text-main);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.fullscreen-control-btn:hover:not(.disabled):not(.close-btn) {
  background: rgba(255, 183, 77, 0.35);
  box-shadow: 0 12px 28px rgba(255, 152, 0, 0.25);
  transform: translateY(-2px);
}

.fullscreen-control-btn:active:not(.disabled) {
  transform: scale(0.92);
}

.fullscreen-control-btn.close-btn {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.fullscreen-control-btn.close-btn:hover {
  background: rgba(239, 68, 68, 0.35);
  box-shadow: 0 12px 28px rgba(239, 68, 68, 0.25);
  transform: translateY(-2px);
}

.fullscreen-control-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.08);
}

.fullscreen-control-btn.disabled:hover {
  transform: none;
}

body.light-mode .fullscreen-control-btn {
  background: rgba(251, 140, 0, 0.15);
  border-color: rgba(251, 140, 0, 0.2);
  color: #202124;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

body.light-mode .fullscreen-control-btn:hover:not(.disabled):not(.close-btn) {
  background: rgba(251, 140, 0, 0.25);
  box-shadow: 0 12px 24px rgba(251, 140, 0, 0.2);
}

body.light-mode .fullscreen-control-btn.close-btn {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.2);
}

body.light-mode .fullscreen-control-btn.close-btn:hover {
  background: rgba(239, 68, 68, 0.25);
  box-shadow: 0 12px 24px rgba(239, 68, 68, 0.15);
}

.offline-badge {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  padding: 10px 16px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.4);
  border-radius: 999px;
  color: #60a5fa;
  font-size: 0.85rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Download Playlist Button Styles */
.btn-download-playlist {
  appearance: none;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.btn-download-playlist:hover:not(.downloaded) {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(16, 185, 129, 0.3));
  border-color: rgba(34, 197, 94, 0.5);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.15);
  transform: translateY(-1px);
}

.btn-download-playlist:active:not(.downloaded) {
  transform: scale(0.96);
}

.btn-download-playlist.downloaded {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(16, 185, 129, 0.15));
  border-color: rgba(34, 197, 94, 0.25);
  color: #10b981;
  cursor: default;
  opacity: 0.9;
}

.btn-download-playlist.downloading {
  opacity: 0.7;
  cursor: wait;
}

.btn-download-playlist.error {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.2));
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

body.light-mode .btn-download-playlist {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(16, 185, 129, 0.1));
  border-color: rgba(34, 197, 94, 0.25);
  color: #047857;
}

body.light-mode .btn-download-playlist:hover:not(.downloaded) {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(16, 185, 129, 0.2));
  border-color: rgba(34, 197, 94, 0.4);
  box-shadow: 0 8px 16px rgba(34, 197, 94, 0.12);
}

/* Mobile Fullscreen Responsive */
@media (max-width: 640px) {
  .fullscreen-lyrics-header {
    padding: 16px 16px 12px;
  }

  .fullscreen-title {
    font-size: clamp(1.2rem, 3vw, 1.6rem);
  }

  .fullscreen-lyrics-content {
    padding: 110px 16px 136px; /* Increased mobile padding to clear sticky header and footer */
  }

  .fullscreen-lyrics-content .lyrics-container {
    padding: 24px 20px;
    max-width: 95vw;
    border-radius: 24px;
  }

  .fullscreen-lyrics-content .lyrics-content {
    font-size: clamp(1rem, 4vw, 1.8rem);
    line-height: 1.95;
  }

  .fullscreen-controls-bar {
    gap: 16px;
    padding: max(16px, env(safe-area-inset-bottom) + 12px);
  }

  .fullscreen-control-btn {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .fullscreen-lyrics-header {
    padding: 12px 12px 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .fs-header-controls {
    width: 100%;
    align-items: flex-start !important; /* Override inline flex-end from JS */
  }

  .fs-font-controls {
    align-self: stretch;
    justify-content: center;
  }

  .fullscreen-title {
    font-size: clamp(1rem, 2.5vw, 1.4rem);
    margin-bottom: 6px;
  }

  .fullscreen-composer,
  .fullscreen-singer {
    font-size: 0.85rem;
  }

  .fullscreen-lyrics-content {
    padding: 145px 12px 120px; /* Increased small mobile padding to prevent overlap */
  }

  .fullscreen-lyrics-content .lyrics-container {
    padding: 20px 16px;
    border-radius: 20px;
  }

  .fullscreen-lyrics-content .lyrics-content {
    font-size: clamp(0.95rem, 3.5vw, 1.6rem);
    line-height: 1.85;
  }

  .fullscreen-controls-bar {
    gap: 12px;
    padding: max(12px, env(safe-area-inset-bottom) + 10px);
  }

  .fullscreen-control-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }
}

/* Support for notches/safe areas */
@supports (padding: max(0px)) {
  .fullscreen-controls-bar {
    padding-bottom: max(24px, env(safe-area-inset-bottom) + 16px);
  }
  
  @media (max-width: 640px) {
    .fullscreen-controls-bar {
      padding-bottom: max(16px, env(safe-area-inset-bottom) + 12px);
    }
  }
  
  @media (max-width: 480px) {
    .fullscreen-controls-bar {
      padding-bottom: max(12px, env(safe-area-inset-bottom) + 10px);
    }
  }
}

/* Scrollbar styling for fullscreen lyrics */
#fullscreen-lyrics-container ::-webkit-scrollbar {
  width: 6px;
}

#fullscreen-lyrics-container ::-webkit-scrollbar-track {
  background: transparent;
}

#fullscreen-lyrics-container ::-webkit-scrollbar-thumb {
  background: rgba(255, 183, 77, 0.4);
  border-radius: 10px;
}

#fullscreen-lyrics-container ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 183, 77, 0.6);
}

body.light-mode #fullscreen-lyrics-container ::-webkit-scrollbar-thumb {
  background: rgba(251, 140, 0, 0.3);
}

body.light-mode #fullscreen-lyrics-container ::-webkit-scrollbar-thumb:hover {
  background: rgba(251, 140, 0, 0.5);
}

/* Prevent zoom on iOS when controls are hidden */
#fullscreen-lyrics-container input,
#fullscreen-lyrics-container button {
  font-size: 16px;
}

/* Print styles for fullscreen */
@media print {
  #fullscreen-lyrics-container {
    display: block !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #000 !important;
    z-index: auto !important;
  }

  .fullscreen-lyrics-wrapper {
    position: static !important;
    min-height: auto !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .fullscreen-lyrics-header {
    position: static !important;
    background: transparent !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    padding: 0 0 8px !important;
    margin-bottom: 8px !important;
    color: #000 !important;
  }

  .fs-header-controls,
  .fullscreen-controls-bar,
  .fs-bottom-pill-wrapper,
  .exit-reading-btn,
  .offline-badge,
  .fs-lang-switch,
  .fs-font-controls {
    display: none !important;
  }

  .fullscreen-lyrics-content {
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
    scroll-padding-top: 0 !important;
  }

  .fullscreen-lyrics-content .lyrics-content {
    margin-top: 0 !important;
    font-size: 14pt !important;
    line-height: 1.9 !important;
    color: #000 !important;
  }

  .fullscreen-lyrics-content .lyrics-content p {
    margin: 0 0 0.75em 0 !important;
  }

  .fullscreen-lyrics-header h2,
  .fullscreen-lyrics-header p,
  .fullscreen-lyrics-content .lyrics-content {
    page-break-inside: avoid !important;
  }
}
