/* Listener Interface Responsive Styling (Mobile Split & Desktop Side-by-Side) */

/* Global container */
.listener-page {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--bg-color);
}

.listener-container {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Global player card background & ambient blur (both mobile & desktop) */
.player-card {
  position: relative;
  overflow: hidden;
  background: rgba(15, 19, 28, 0.7);
}

.player-bg {
  position: absolute !important;
  inset: -35px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(35px) brightness(0.32) saturate(1.4);
  transform: scale(1.15);
  z-index: 0;
  pointer-events: none;
  opacity: 0.88;
  transition: background-image 0.8s ease-in-out, opacity 0.5s ease;
}

.player-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(15, 19, 28, 0.35) 0%, rgba(10, 13, 20, 0.75) 100%);
  z-index: 1;
  pointer-events: none;
}

.player-card > :not(.player-bg) {
  position: relative;
  z-index: 2;
}

/* ========================================================
   1. MOBILE LAYOUT (< 769px): EXACT HALF-AND-HALF FIT
   ======================================================== */
@media (max-width: 768px) {
  .listener-container {
    height: 100dvh;
    max-height: 100dvh;
    width: 100vw;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  /* NỬA TRÊN: KHUNG PHÁT (PLAYER CARD) */
  .player-card {
    flex: 0 0 auto;
    height: 48vh;
    height: 48dvh;
    max-height: 49dvh;
    width: 100%;
    padding: 8px 12px 6px 12px;
    border-radius: 0 0 18px 18px;
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 5;
  }

  /* Header: Nút LIVE căn lề TRÁI, Tiêu đề MINHTAMLIVE ở GIỮA, Số người nghe căn lề PHẢI */
  .player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    flex: 0 0 auto;
  }

  .player-header-left {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
  }

  .player-header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  .brand-title {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #ffffff 0%, #e2e8f0 60%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    user-select: none;
    line-height: 1;
  }

  .player-header-right {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
  }

  /* Kích thước nút LIVE và nút số người nghe bằng nhau cho đồng bộ */
  .status-badge,
  .listener-info-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 28px;
    min-height: 28px;
    padding: 0 12px;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    box-sizing: border-box;
    white-space: nowrap;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .listener-info-pill {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
  }

  .listener-info-pill svg {
    color: var(--accent-blue);
  }

  /* 2. Tiêu đề và ca sĩ ở TRÊN (dịch lên cao hơn) */
  .track-header-box {
    width: 100%;
    text-align: center;
    flex: 0 0 auto;
    padding: 0 6px;
    margin: 0 0 2px 0;
  }

  .song-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0px;
    line-height: 1.25;
  }

  .artist-name {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
  }

  /* 3. Thumbnail ở GIỮA (to hơn) */
  .cover-wrapper {
    flex: 0 0 135px;
    width: 135px;
    height: 135px;
    margin: 2px auto;
    border-radius: 18px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 18px;
    border: 1px solid var(--border-active);
    background: #11141c;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  }

  .cover-glow {
    position: absolute;
    inset: -6px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(255, 51, 85, 0.4), rgba(56, 189, 248, 0.35));
    filter: blur(12px);
    opacity: 0;
    transition: opacity 0.4s ease;
  }

  .playing .cover-glow {
    opacity: 1;
  }

  /* 4. Visualizer ở DƯỚI (nhô cao hơn) */
  .visualizer-wrapper {
    width: 100%;
    height: 38px;
    flex: 0 0 auto;
    margin-top: 2px;
  }

  #visualizerCanvas {
    width: 100%;
    height: 100%;
    border-radius: 4px;
  }

  /* Ẩn thanh âm lượng trên mobile */
  .volume-box.desktop-only {
    display: none !important;
  }

  /* NỬA DƯỚI: KHUNG CHAT */
  .listener-chat-card {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    background: rgba(10, 13, 20, 0.98);
    border-radius: 18px 18px 0 0;
    border-top: 1px solid var(--border-color);
    border-left: none;
    border-right: none;
    border-bottom: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: auto;
  }

  .chat-header {
    padding: 7px 12px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
  }

  .chat-title {
    font-size: 0.86rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
  }

  .quick-emoji-bar {
    flex: 0 0 auto;
    padding: 4px 10px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.35);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
  }

  .chat-input-bar {
    flex: 0 0 auto;
    padding: 8px 10px;
    background: rgba(12, 16, 24, 1);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .chat-input {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .btn-send-chat {
    padding: 8px 14px;
    font-size: 0.85rem;
  }
}

/* ========================================================
   2. DESKTOP LAYOUT (>= 769px): PRO SIDE-BY-SIDE CONSOLE
   ======================================================== */
@media (min-width: 769px) {
  .listener-container {
    max-width: 960px;
    height: 86vh;
    max-height: 720px;
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    margin: auto;
    padding: 0;
  }

  .player-card {
    padding: 16px 20px 18px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    height: 100%;
    justify-content: space-between;
  }

  .player-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    margin-top: 0;
  }

  .player-header-left {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
  }

  .player-header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  .brand-title {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 60%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    user-select: none;
    line-height: 1;
  }

  .player-header-right {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
  }

  /* Kích thước nút LIVE và nút số người nghe bằng nhau cho đồng bộ */
  .status-badge,
  .listener-info-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    min-height: 32px;
    padding: 0 14px;
    font-size: 0.84rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    box-sizing: border-box;
    white-space: nowrap;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .listener-info-pill {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
  }

  .listener-info-pill svg {
    color: var(--accent-blue);
  }

  /* 2. Tiêu đề và ca sĩ ở TRÊN (dịch lên cao hơn) */
  .track-header-box {
    width: 100%;
    text-align: center;
    margin: 4px 0 2px 0;
  }

  .song-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .artist-name {
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 500;
  }

  /* 3. Thumbnail ở GIỮA (to hơn) */
  .cover-wrapper {
    position: relative;
    width: 195px;
    height: 195px;
    margin: 4px auto;
    border-radius: 22px;
    cursor: pointer;
  }

  .cover-glow {
    position: absolute;
    inset: -8px;
    border-radius: 26px;
    background: linear-gradient(135deg, rgba(255, 51, 85, 0.4), rgba(56, 189, 248, 0.3));
    filter: blur(18px);
    opacity: 0;
    transition: opacity 0.5s ease;
  }

  .playing .cover-glow {
    opacity: 1;
  }

  .cover-img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
    object-fit: cover;
    border: 1px solid var(--border-active);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    background: #11141c;
  }

  /* 4. Visualizer ở DƯỚI (nhô cao hơn) */
  .visualizer-wrapper {
    width: 100%;
    height: 48px;
    margin: 6px 0;
  }

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

  /* Volume slider visible on desktop */
  .volume-box.desktop-only {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-full);
  }

  .mute-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: var(--transition);
  }
  .mute-btn:hover {
    color: var(--text-main);
  }

  .volume-slider {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.15);
    outline: none;
    cursor: pointer;
  }
  .volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-main);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
  }

  /* Chat on Desktop */
  .listener-chat-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
}

/* ========================================================
   THUMBNAIL PLAY BUTTON HOVER / ACTIVE BEHAVIOR
   ======================================================== */
/* Khi chưa phát: nút Play LUÔN hiển thị */
.cover-wrapper:not(.playing) .thumb-play-btn {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Khi đang phát:
   - Nút tạm dừng hiển thị
   - Sau 2 giây tự động ẩn với class .controls-hidden */
.cover-wrapper.playing .thumb-play-btn {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, transform 0.2s ease, visibility 0.35s;
}

.cover-wrapper.playing.controls-hidden .thumb-play-btn {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ========================================================
   COMMON COMPONENTS
   ======================================================== */
.reconnect-toast {
  position: fixed !important;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245, 158, 11, 0.96);
  color: #111;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 18px;
  border-radius: var(--radius-full);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99999 !important;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reconnect-toast.hidden {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateX(-50%) translateY(-20px) scale(0.95) !important;
}

.nickname-badge {
  font-size: 0.76rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.07);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border-color);
  transition: var(--transition);
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.nickname-badge:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-main);
  border-color: var(--border-active);
}
