/* =====================================================================
   Chuyển động + nền cho trang công khai (trang chủ, trang donate). Đi cùng motion.js.
   - Nền aurora: các đốm màu trôi chậm + lưới mờ, nằm sau mọi nội dung (.fx-bg).
   - Hiện dần khi cuộn: [data-rv] do motion.js gắn, chỉ ẩn khi <html class="fx"> (có JS, không giảm chuyển động).
   - Hover: thẻ nhấc lên, viền sáng, đèn rọi theo chuột ([data-glow] + --mx/--my).
   Màu đi theo biến trong app.css nên dùng được cả nền tối lẫn sáng.
   ===================================================================== */

/* html giữ màu nền; body trong suốt để lớp nền cố định (z-index âm) hiện ra phía sau nội dung. */
body { background: transparent; }

/* ---------- Nền aurora ---------- */
.fx-bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; contain: strict;
    --fx1: var(--accent); --fx2: var(--accent-2, #ff8a65); --fx3: #8b5cf6; --fx-a: 30%; }
:root[data-theme="light"] .fx-bg { --fx-a: 22%; --fx2: #ffb199; }
.fx-bg i { position: absolute; display: block; width: 62vmax; height: 62vmax; border-radius: 50%; will-change: transform;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--c) var(--fx-a), transparent), transparent 72%); }
.fx-bg i:nth-child(1) { --c: var(--fx1); left: -18vmax; top: -24vmax; animation: fx-drift-a 26s ease-in-out infinite alternate; }
.fx-bg i:nth-child(2) { --c: var(--fx3); right: -22vmax; top: 8vh; animation: fx-drift-b 32s ease-in-out infinite alternate; }
.fx-bg i:nth-child(3) { --c: var(--fx2); left: 18vw; bottom: -34vmax; animation: fx-drift-c 38s ease-in-out infinite alternate; }
/* Lưới chấm mờ dần ra rìa, trôi nhẹ theo cuộn (parallax). */
.fx-bg::before { content: ""; position: absolute; inset: -40px; opacity: .5;
    background-image: radial-gradient(color-mix(in srgb, var(--text) 13%, transparent) 1px, transparent 1.4px); background-size: 26px 26px;
    mask-image: radial-gradient(120% 80% at 50% 0%, #000 20%, transparent 75%); -webkit-mask-image: radial-gradient(120% 80% at 50% 0%, #000 20%, transparent 75%);
    transform: translateY(calc(var(--sy, 0px) * -0.08)); }
/* Hạt lấp lánh nhỏ bay lên chậm. */
.fx-bg::after { content: ""; position: absolute; inset: 0; opacity: .55;
    background-image:
        radial-gradient(1.5px 1.5px at 12% 78%, color-mix(in srgb, var(--fx1) 80%, #fff), transparent),
        radial-gradient(1.5px 1.5px at 38% 62%, #fff, transparent),
        radial-gradient(2px 2px at 64% 84%, color-mix(in srgb, var(--fx3) 80%, #fff), transparent),
        radial-gradient(1.5px 1.5px at 86% 70%, #fff, transparent),
        radial-gradient(2px 2px at 24% 40%, color-mix(in srgb, var(--fx2) 80%, #fff), transparent),
        radial-gradient(1.5px 1.5px at 72% 30%, #fff, transparent);
    background-size: 100% 100%; animation: fx-rise 22s linear infinite; }
:root[data-theme="light"] .fx-bg::after { opacity: .25; }
@keyframes fx-drift-a { to { transform: translate(14vw, 10vh) scale(1.15); } }
@keyframes fx-drift-b { to { transform: translate(-12vw, 16vh) scale(.9); } }
@keyframes fx-drift-c { to { transform: translate(10vw, -14vh) scale(1.1); } }
@keyframes fx-rise { from { transform: translateY(0); } to { transform: translateY(-100vh); } }

/* Thanh tiến độ cuộn mảnh dưới thanh điều hướng. */
.fx-progress { position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 40; pointer-events: none; transform-origin: 0 50%;
    transform: scaleX(var(--scroll, 0)); background: linear-gradient(90deg, var(--accent), var(--accent-2, #ff8a65), #8b5cf6); }

/* Thanh điều hướng: trong hơn, có bóng khi đã cuộn. */
.fx .topnav { background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }

/* ---------- Hiện dần khi cuộn tới ---------- */
.fx [data-rv] { transition: opacity .7s cubic-bezier(.2, .7, .2, 1), transform .8s cubic-bezier(.2, .7, .2, 1), filter .7s ease;
    transition-delay: calc(min(var(--rv-i, 0), 6) * 80ms); }
.fx [data-rv=""] { opacity: 0; transform: translateY(28px) scale(.98); filter: blur(6px); }
.fx .hero-visual[data-rv=""] { transform: translateY(20px) scale(.94) rotate(-2deg); }
.fx .home-h2[data-rv=""] { transform: translateY(18px); }
.fx .rank-bars li[data-rv=""] { transform: translateX(-18px); filter: none; }
/* Thanh xếp hạng chạy từ 0 khi hiện ra. */
.fx .rank-bars li[data-rv] .rank-bar i { transition: transform 1.1s cubic-bezier(.2, .7, .2, 1) calc(150ms + min(var(--rv-i, 0), 8) * 70ms); transform-origin: 0 50%; }
.fx .rank-bars li[data-rv=""] .rank-bar i { transform: scaleX(0); }
/* Xong rồi thì bỏ trễ, để hover phản hồi ngay. */
.fx [data-rv="in"] { transition-delay: 0s; transition-duration: .25s, .35s, .25s; }
.fx [data-rv="in"].show-item, .fx [data-rv="in"].hero-visual { transition-duration: .7s, .8s, .7s; }

/* ---------- Đèn rọi theo chuột + hover ---------- */
/* :where = độ ưu tiên 0: khối đã có position riêng (vd cột lịch sử sticky) giữ nguyên. */
:where([data-glow]) { position: relative; isolation: isolate; }
/* Khối đang chứa cửa sổ nổi (vd chọn hiệu ứng WOW) mà bị isolation giam z-index bên trong thì cột lịch sử (sticky, vẽ sau) đè lên cửa sổ, che cả nút Áp dụng.
   Khi có cửa sổ mở, nâng cả khối lên trên thanh trên (30) và cột lịch sử; chỉ khi đang mở nên menu thả xuống của thanh trên không bị ảnh hưởng. */
[data-glow]:has(.sheet-backdrop), [data-glow]:has(.modal-backdrop) { position: relative; z-index: 70; }
[data-glow]::before { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 0; opacity: 0; transition: opacity .3s;
    background: radial-gradient(360px circle at var(--mx, 50%) var(--my, 0%), color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%); }
[data-glow]:hover::before { opacity: 1; }
[data-glow] > * { position: relative; z-index: 1; }
/* Các khối có nền/ảnh định vị tuyệt đối giữ nguyên vị trí của chúng. */
.profile-card[data-glow] > .profile-bg { position: absolute; z-index: 0; }
.home-streamer[data-glow] > .hs-badge { position: absolute; z-index: 2; }
.panel[data-glow]::before { background: radial-gradient(520px circle at var(--mx, 50%) var(--my, 0%), color-mix(in srgb, var(--accent) 7%, transparent), transparent 60%); }

@media (hover: hover) {
    .show-stage, .home-feature, .home-streamer, .home-step .hs-no, .premium-slot .slot-main, .segment, .amount-chip, .wow-box-pick {
        transition: transform .3s cubic-bezier(.2, .7, .2, 1), box-shadow .3s, border-color .3s, background-color .2s, color .2s; }
    .show-item:hover .show-stage { transform: translateY(-6px); border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
        box-shadow: 0 24px 50px -24px color-mix(in srgb, var(--accent) 55%, transparent); }
    .show-stage img { transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
    .show-item:hover .show-stage img { transform: scale(1.05); }
    .home .home-features .home-feature:hover, .home-streamer:hover { transform: translateY(-5px); border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
        box-shadow: 0 20px 40px -22px color-mix(in srgb, var(--accent) 50%, transparent); }
    .home-feature:hover .hf-icon { transform: rotate(-8deg) scale(1.12); }
    .home-step:hover .hs-no { transform: scale(1.12); background: var(--accent); color: #fff; box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent); }
    .premium-slot .slot-main:hover, .wow-box-pick:hover { transform: translateY(-2px); box-shadow: 0 12px 24px -16px color-mix(in srgb, var(--accent) 60%, transparent); }
    .amount-chip:hover:not(.active) { transform: translateY(-2px); }
    .segment:hover:not(.active) { background: color-mix(in srgb, var(--surface) 60%, transparent); }
    .rank-bars li { transition: transform .25s; }
    .rank-bars li:hover { transform: translateX(4px); }
}
.hf-icon { transition: transform .35s cubic-bezier(.2, 1.6, .4, 1); }
.amount-chip.active { animation: fx-pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes fx-pop { 40% { transform: scale(1.08); } }

/* Nút chính: vệt sáng quét qua khi rê, nút gửi donate có quầng sáng thở nhẹ. */
.btn-primary, .home-cta, .home-band .btn { position: relative; overflow: hidden; }
.btn-primary::after, .home-cta::after, .home-band .btn::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; pointer-events: none;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .35), transparent); transform: skewX(-20deg); transition: left .6s ease; }
.btn-primary:hover:not(:disabled)::after, .home-cta:hover::after, .home-band .btn:hover::after { left: 120%; }
.btn-primary:hover:not(:disabled), .home-cta:hover, .home-band .btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--accent) 75%, transparent); }
.btn-submit:not(:disabled) { background: linear-gradient(120deg, var(--accent), var(--accent-2, #ff8a65), var(--accent)); background-size: 220% 100%;
    animation: fx-breathe 3.2s ease-in-out infinite, fx-slide 6s linear infinite; }
@keyframes fx-breathe { 0%, 100% { box-shadow: 0 8px 22px -12px color-mix(in srgb, var(--accent) 70%, transparent); } 50% { box-shadow: 0 10px 34px -8px color-mix(in srgb, var(--accent) 85%, transparent); } }
@keyframes fx-slide { to { background-position: -220% 0; } }

/* ---------- Trang chủ ---------- */
.home { overflow: visible; overflow-x: clip; }
.home-glow { transform: translateY(calc(var(--sy, 0px) * .25)); }
.home-title { animation: none; }
.home-hl { background: linear-gradient(90deg, var(--ha1), var(--ha2), #c084fc, var(--ha1)); background-size: 300% 100%;
    -webkit-background-clip: text; background-clip: text; color: transparent; animation: fx-slide-hl 8s linear infinite; }
@keyframes fx-slide-hl { to { background-position: -300% 0; } }
.hero-visual { perspective: 1000px; }
.hero-visual .phone { transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg)); transition: transform .4s cubic-bezier(.2, .7, .2, 1); transform-style: preserve-3d; }
.hero-visual::before { content: ""; position: absolute; left: 50%; top: 50%; width: 380px; height: 380px; translate: -50% -50%; border-radius: 50%; z-index: -1; pointer-events: none;
    background: conic-gradient(from 0deg, var(--ha1), #8b5cf6, var(--ha2), var(--ha1)); filter: blur(70px); opacity: .35; animation: spin 14s linear infinite; }
:root[data-theme="light"] .hero-visual::before { opacity: .22; }

/* Tính năng: thành thẻ kính thay vì ô kẻ. */
.home .home-features { gap: 14px; border-top: none; }
.home .home-features .home-feature { padding: 24px; border: 1px solid var(--border); border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 72%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.home-feature p { max-width: none; }
.show-stage { position: relative; }
.home-band { position: relative; overflow: hidden;
    background: linear-gradient(120deg, color-mix(in srgb, var(--ha1) 18%, var(--surface)), color-mix(in srgb, #8b5cf6 14%, var(--surface))); border-color: color-mix(in srgb, var(--ha1) 30%, var(--border)); }
.home-faq details { transition: background .2s; }
.home-faq details[open] p { animation: fx-faq .35s ease; }
@keyframes fx-faq { from { opacity: 0; transform: translateY(-6px); } }
.home-streamer, .home-step .hs-no { background-color: var(--surface); }

/* ---------- Trang donate ---------- */
.donate-page .panel, .donate-page .profile-card { background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.donate-page .profile-card::after { background: linear-gradient(90deg, color-mix(in srgb, var(--surface) 92%, transparent) 30%, color-mix(in srgb, var(--surface) 45%, transparent)); }
/* Viền ảnh đại diện: vòng gradient xoay. */
.donate-page .profile-avatar { position: relative; box-shadow: 0 0 0 4px var(--surface); }
.donate-page .profile-avatar::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; z-index: -1;
    background: conic-gradient(var(--accent), var(--accent-2, #ff8a65), #8b5cf6, var(--accent)); animation: spin 6s linear infinite; }
.donate-page .profile-avatar { overflow: visible; }
.donate-page .profile-avatar img { border-radius: 50%; position: relative; }
.tl-item.fresh .tl-content { animation: fx-fresh .9s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes fx-fresh { 0% { transform: translateX(16px) scale(.94); opacity: 0; } 60% { transform: none; opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 12px; } }

/* Điện thoại: nút hồ sơ chia lưới đều, không lệch dòng. */
@media (max-width: 560px) {
    .donate-page .profile-row { padding: 20px 16px; gap: 14px; }
    .donate-page .profile-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .donate-page .profile-actions > .btn { justify-content: center; min-width: 0; }
    .donate-page .profile-actions > .btn-primary:first-of-type:nth-last-child(odd) { grid-column: 1 / -1; }
    .donate-page .profile-actions > :not(.btn) { grid-column: 1 / -1; }
    .donate-page .profile-actions > :empty { display: none; }
    .btn-submit { flex-basis: 100%; }
    .fx-bg i { width: 90vmax; height: 90vmax; }
}

/* ---------- Giảm chuyển động ---------- */
/* ---------- Điện thoại / màn cảm ứng: nhẹ cho mượt khi vuốt ----------
   Làm mờ nền phía sau (backdrop-filter), làm mờ thẻ khi hiện ra (filter: blur) và hoạt ảnh phải vẽ lại mỗi khung hình
   (box-shadow, background-position, quầng blur xoay) là những thứ điện thoại phải vẽ lại liên tục trong lúc cuộn. */
@media (hover: none), (pointer: coarse) {
    .fx .topnav { background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }
    .home .home-features .home-feature { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }
    .donate-page .panel, .donate-page .profile-card { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
    .fx [data-rv=""], .fx .home [data-rv=""] { filter: none; }
    .fx [data-rv] { transition-property: opacity, transform; }
    .hero-visual::before { animation: none; }
    .btn-submit:not(:disabled), .home-hl { animation: none; }
    .fx-bg::before { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .fx-bg i, .fx-bg::after, .hero-visual::before, .donate-page .profile-avatar::before, .btn-submit, .home-hl { animation: none !important; }
    .hero-visual .phone { transform: none !important; }
}

/* =====================================================================
   Trang chủ: mặt nước rẽ sóng theo chuột (fx-water.js vẽ lên canvas) + nổi lên mạnh hơn khi cuộn. Con trỏ mũi tên mập cho trang công khai.
   ===================================================================== */
.fx-water { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }

/* Thẻ trang chủ nổi lên từ dưới, hơi ngả ra sau rồi dựng thẳng (như nổi lên mặt nước). */
.fx .home [data-rv=""] { transform: perspective(900px) translateY(56px) rotateX(14deg) scale(.95); filter: blur(8px); }
.fx .home .home-h2[data-rv=""] { transform: translateY(26px) scale(.97); }
.fx .home [data-rv] { transition-duration: .8s, 1s, .8s; transition-timing-function: cubic-bezier(.2, .7, .2, 1), cubic-bezier(.16, 1.3, .3, 1), ease; transform-origin: 50% 100%; }
.fx .home [data-rv="in"] { transition-duration: .25s, .35s, .25s; transition-timing-function: ease; }
.fx .home [data-rv="in"].show-item, .fx .home [data-rv="in"].hero-visual { transition-duration: .8s, 1s, .8s; }

/* Con trỏ: vẫn là mũi tên nhọn nhưng mập, bo tròn, ruột đậm, viền trắng dày (img/cursor/*.svg, điểm bấm ở đầu mũi tên 7,5).
   Rê lên link / nút: mũi tên màu nhấn. Ô nhập chữ: con trỏ gõ chữ của hệ thống. Chỉ trên trang công khai có nền (.fx-bg). */
:root:has(.fx-bg) { cursor: url("img/cursor/arrow.svg") 7 5, auto; }
:root:has(.fx-bg) :is(a[href], button, summary, label, select, [role="button"], .btn, .pick-tile, .voice-row, .pick-chip, .pick-meme, input[type="checkbox"], input[type="radio"], input[type="range"], input[type="submit"], input[type="button"]) {
    cursor: url("img/cursor/pointer.svg") 7 5, pointer; }
:root:has(.fx-bg) :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="submit"], [type="button"]), textarea, [contenteditable="true"]) { cursor: text; }
:root:has(.fx-bg) :is(button:disabled, .btn:disabled, [aria-disabled="true"]) { cursor: url("img/cursor/arrow.svg") 7 5, not-allowed; }
@media (prefers-reduced-motion: reduce) { .fx-water { display: none; } }

/* =====================================================================
   Hiệu ứng trang chủ kiểu mới: lưới chấm sáng theo chuột, điện thoại nhiều lớp theo chuột, hiện dần + cuộn kiểu Apple.
   ===================================================================== */
/* Lưới chấm: canvas (fx-dots.js) vẽ thay lưới tĩnh; mờ dần ra phía dưới như lưới cũ. Script không chạy (giảm chuyển động / cảm ứng) thì lưới tĩnh giữ nguyên. */
.fx-dots { position: absolute; inset: 0; width: 100%; height: 100%; display: block;
    mask-image: radial-gradient(120% 80% at 50% 0%, #000 20%, transparent 75%); -webkit-mask-image: radial-gradient(120% 80% at 50% 0%, #000 20%, transparent 75%); }
.fx-bg.dots-on::before { display: none; }

/* Thẻ nổi quanh điện thoại dịch ngược chiều nhau theo chuột: gần hơn thì dịch nhiều hơn. Dùng thuộc tính translate riêng, không đụng animation nổi. */
@media (hover: hover) and (pointer: fine) {
    .fx .hero-visual .demo-chip.c1 { translate: calc(var(--px, 0) * -26px) calc(var(--py, 0) * -16px); transition: translate .5s cubic-bezier(.2, .7, .2, 1); }
    .fx .hero-visual .demo-chip.c2 { translate: calc(var(--px, 0) * 34px) calc(var(--py, 0) * 20px); transition: translate .5s cubic-bezier(.2, .7, .2, 1); }
}

/* Hiện dần kiểu Apple: trượt lên gọn rồi dừng, không mờ (blur) và không ngả 3D như bản "nổi lên mặt nước" trước. */
.fx .home [data-rv=""] { transform: translateY(40px); filter: none; }
.fx .home .home-h2[data-rv=""] { transform: translateY(24px); }
.fx .home [data-rv] { transition-duration: .9s, 1.1s, .9s; transition-timing-function: cubic-bezier(.16, 1, .3, 1); transform-origin: 50% 50%; }
.fx .home [data-rv="in"] { transition-duration: .25s, .35s, .25s; transition-timing-function: ease; }
.fx .home [data-rv="in"].show-item, .fx .home [data-rv="in"].hero-visual { transition-duration: .9s, 1.1s, .9s; }

/* Gắn với vị trí cuộn (CSS thuần, không JS; trình duyệt cũ bỏ qua và nội dung vẫn hiện bình thường). */
@supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
        /* Ảnh trong thẻ "Hiện lên live" phóng nhẹ rồi lùi về đúng cỡ khi cuộn tới. */
        .fx .home .show-stage img { animation: fx-img-in linear both; animation-timeline: view(); animation-range: entry 0% cover 45%; }
        /* Điện thoại hơi thu nhỏ và trôi lên khi cuộn rời khỏi phần đầu trang. */
        .fx .home .hero-visual .phone { animation: fx-phone-out linear both; animation-timeline: scroll(root); animation-range: 0 70vh; }
    }
}
@keyframes fx-img-in { from { scale: 1.14; } to { scale: 1; } }
@keyframes fx-phone-out { to { translate: 0 -48px; scale: .9; } }
