/* =============================================================================
   SÓNG — thanh phát

   Thanh phát nằm cố định dưới cùng và KHÔNG bị nạp lại khi chuyển trang: mọi
   liên kết nội bộ được app.js nạp bằng fetch rồi thay phần <main>. Nhờ vậy
   nhạc không đứt giữa chừng khi người nghe bấm sang trang khác — đây là điều
   phân biệt một trang nghe nhạc với một trang web có gắn thẻ audio.

   Ba dạng:
     - dải dưới cùng (mặc định)
     - khung MV nổi góc phải (khi phát video mà đang xem trang khác)
     - toàn màn hình (bấm mở rộng)
   ========================================================================== */

.player {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: var(--z-player);
    height: calc(var(--h-player) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);

    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
    align-items: center;
    gap: var(--s-4);
    padding-left: var(--s-4);
    padding-right: var(--s-4);

    background: color-mix(in srgb, var(--bg-2) 92%, transparent);
    backdrop-filter: saturate(160%) blur(20px);
    -webkit-backdrop-filter: saturate(160%) blur(20px);
    border-top: 1px solid var(--line);

    transform: translateY(100%);
    transition: transform var(--t) var(--ease);
}
@supports not (backdrop-filter: blur(1px)) { .player { background: var(--bg-2); } }

/* Chỉ trượt lên khi đã có bài — thanh phát rỗng chỉ tổ chiếm chỗ */
.player--on { transform: translateY(0); }

@media (max-width: 1079px) {
    .player {
        bottom: calc(var(--h-tabbar) + env(safe-area-inset-bottom, 0px));
        height: var(--h-player-m);
        padding-bottom: 0;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: var(--s-3);
        padding-left: var(--s-3);
        padding-right: var(--s-3);
    }
}

/* ---- Bên trái: bài đang phát -------------------------------------------- */

.player__now {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-width: 0;
}

.player__art {
    width: 52px; height: 52px;
    border-radius: var(--r-sm);
    overflow: hidden;
    background: var(--surface-2);
    flex-shrink: 0;
    box-shadow: var(--sh-1);
}
.player__art img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 1079px) { .player__art { width: 42px; height: 42px; } }

.player__meta { min-width: 0; }
.player__title {
    font-size: var(--fs-sm);
    font-weight: 600;
    margin: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.player__artist {
    font-size: var(--fs-xs);
    color: var(--text-2);
    margin: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Giữa: điều khiển --------------------------------------------------- */

.player__center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-2);
    min-width: 0;
    width: 100%;
}
@media (max-width: 1079px) { .player__center { display: none; } }

.player__btns { display: flex; align-items: center; gap: var(--s-2); }

.player__play {
    display: inline-grid;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--r-full);
    background: var(--text);
    color: var(--bg);
    flex-shrink: 0;
    transition: transform var(--t-fast) var(--ease);
}
.player__play svg { width: 18px; height: 18px; }
.player__play:hover { transform: scale(1.07); }
.player__play:active { transform: scale(.95); }

/* ---- Thanh tiến độ ------------------------------------------------------
   Không dùng <input type=range>: mỗi trình duyệt vẽ một kiểu, và cần vẽ được
   cả phần đã đệm sẵn. Tự dựng bằng div thì kiểm soát được hết, đổi lại phải
   tự lo bàn phím và ARIA — xem role/aria-* trong parts/player.html.        */

.pbar {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    width: 100%;
    font-size: var(--fs-xs);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.pbar__track {
    position: relative;
    flex: 1;
    height: 4px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    cursor: pointer;

    /*  Vùng bấm cao 4px thì không ai trúng. Nới vùng chạm lên 14px bằng lớp
        giả trong suốt, mà nhìn vẫn là một sợi mảnh.                          */
}
.pbar__track::before {
    content: '';
    position: absolute;
    inset: -6px 0;
}

.pbar__buf {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    border-radius: var(--r-full);
    background: var(--surface-3);
    filter: brightness(1.5);
    width: 0;
}
.pbar__fill {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    border-radius: var(--r-full);
    background: var(--brand-grad);
    width: 0;
}
.pbar__knob {
    position: absolute;
    top: 50%;
    width: 12px; height: 12px;
    border-radius: var(--r-full);
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.5);
    transform: translate(-50%, -50%);
    left: 0;
    opacity: 0;
    transition: opacity var(--t-fast) var(--ease);
}
.pbar__track:hover .pbar__knob,
.pbar__track:focus-visible .pbar__knob { opacity: 1; }

/* ---- Bên phải: âm lượng và phụ trợ -------------------------------------- */

.player__right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--s-1);
}

.vol { display: flex; align-items: center; gap: var(--s-2); width: 120px; }
@media (max-width: 1200px) { .vol { width: auto; } .vol .pbar__track { display: none; } }
@media (max-width: 1079px) { .vol { display: none; } }

/* Trên điện thoại chỉ giữ nút phát và nút sau */
.player__mobile { display: none; align-items: center; gap: var(--s-1); }
@media (max-width: 1079px) { .player__mobile { display: flex; } }

/* =============================================================================
   KHUNG MV NỔI

   Khi đang xem MV mà người dùng bấm sang trang khác, video thu nhỏ về góc phải
   thay vì dừng hẳn — giống YouTube. Vẫn là CÙNG một thẻ <video>, chỉ đổi vị
   trí bằng CSS; tạo thẻ mới sẽ làm video tải lại từ đầu.
   ========================================================================== */

.vstage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--sh-2);
}
.vstage video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }

.vstage--float {
    position: fixed;
    right: var(--s-4);
    bottom: calc(var(--h-player) + var(--s-4));
    width: 320px;
    z-index: var(--z-player);
    border-radius: var(--r);
    box-shadow: var(--sh-3);
}
@media (max-width: 1079px) {
    .vstage--float {
        width: 200px;
        right: var(--s-3);
        bottom: calc(var(--h-player-m) + var(--h-tabbar) + var(--s-3));
    }
}

.vstage__bar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: var(--s-5) var(--s-3) var(--s-3);
    background: linear-gradient(180deg, transparent, rgba(0,0,0,.85));
    opacity: 0;
    transition: opacity var(--t) var(--ease);
}
.vstage:hover .vstage__bar,
.vstage:focus-within .vstage__bar,
.vstage--paused .vstage__bar { opacity: 1; }

.vstage__row { display: flex; align-items: center; gap: var(--s-3); color: #fff; }
.vstage__row .icon-btn { color: rgba(255,255,255,.85); }
.vstage__row .icon-btn:hover { background: rgba(255,255,255,.16); color: #fff; }
.vstage__row .pbar { color: rgba(255,255,255,.75); }
.vstage__row .pbar__track { background: rgba(255,255,255,.25); }

.vstage__close {
    position: absolute;
    top: var(--s-2); right: var(--s-2);
    display: none;
    background: rgba(0,0,0,.6);
    color: #fff;
}
.vstage--float .vstage__close { display: inline-grid; }

/* Vòng quay chờ đệm */
.vstage__spin {
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
    background: rgba(0,0,0,.35);
}
.vstage--busy .vstage__spin { display: grid; }

.spin {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,.25);
    border-top-color: #fff;
    border-radius: var(--r-full);
    animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================================
   BẢNG DANH SÁCH CHỜ
   ========================================================================== */

.queue {
    position: fixed;
    right: 0;
    top: 0;
    bottom: var(--h-player);
    width: 340px;
    max-width: 88vw;
    z-index: var(--z-player);
    background: var(--bg-2);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--t) var(--ease);
    box-shadow: var(--sh-3);
}
.queue--on { transform: translateX(0); }
@media (max-width: 1079px) {
    .queue { bottom: calc(var(--h-player-m) + var(--h-tabbar)); }
}

.queue__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-4);
    border-bottom: 1px solid var(--line);
}
.queue__head h3 { margin: 0; font-size: var(--fs-md); }
.queue__body { flex: 1; overflow-y: auto; padding: var(--s-2); }

/* =============================================================================
   TOÀN MÀN HÌNH
   ========================================================================== */

.stage {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    background: var(--bg);
    display: none;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: var(--s-5);
    gap: var(--s-5);
}
.stage--on { display: grid; }

.stage__art {
    justify-self: center;
    align-self: center;
    width: min(60vh, 100%);
    aspect-ratio: 1;
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--sh-3);
}
.stage__art img { width: 100%; height: 100%; object-fit: cover; }

.stage__title { font-size: var(--fs-xl); text-align: center; margin-bottom: var(--s-1); }
.stage__artist { color: var(--text-2); text-align: center; }

/*  Khi mở toàn màn hình thì khoá cuộn trang nền. Thiếu dòng này, vuốt trên
    điện thoại sẽ cuộn trang phía sau — cảm giác hỏng hẳn.                   */
body.no-scroll { overflow: hidden; }

/* =============================================================================
   ĐỔI BIỂU TƯỢNG THEO TRẠNG THÁI

   Cả hai biểu tượng đều nằm sẵn trong HTML, CSS chỉ ẩn cái không dùng. Rẻ hơn
   nhiều so với dựng lại thẻ svg bằng JavaScript mỗi lần bấm — mà thanh phát
   thì đổi trạng thái liên tục.
   ========================================================================== */

[data-state="paused"]  .ico-pause,
[data-state="playing"] .ico-play  { display: none; }

[data-mode="off"] .ico-rep1,
[data-mode="all"] .ico-rep1,
[data-mode="one"] .ico-rep   { display: none; }

.icon-btn--on .ico-vol,
.icon-btn:not(.icon-btn--on) .ico-vol-off { display: none; }

/* Nút phát trên thanh phát chứa hai svg chồng nhau — ô lưới giữ chúng đúng tâm */
.player__play { display: inline-grid; place-items: center; }
.player__play svg { grid-area: 1 / 1; }
.icon-btn svg { grid-area: 1 / 1; }

/* =============================================================================
   VẠCH TIẾN TRÌNH KHI ĐANG NẠP TRANG

   app.js gắn .is-loading lên <html> trong lúc chờ trang mới. Một vạch mảnh
   chạy ngang đỉnh màn hình là đủ để người dùng biết hệ thống đang làm việc —
   thiếu nó, cú bấm trông như rơi vào hư không.
   ========================================================================== */

html.is-loading::after {
    content: '';
    position: fixed;
    top: 0; left: 0;
    height: 2px;
    width: 100%;
    z-index: var(--z-toast);
    background: var(--brand-grad);
    transform-origin: 0 50%;
    animation: load-bar 1.2s var(--ease) infinite;
}
@keyframes load-bar {
    0%   { transform: scaleX(0);   opacity: 1; }
    70%  { transform: scaleX(.85); opacity: 1; }
    100% { transform: scaleX(1);   opacity: 0; }
}
