/* =====================================================================
   THEME — sáng / tối (10/2026, mmoshenqi W1)
   - <html data-theme="light|dark">, đặt TRƯỚC khi vẽ trang bằng script inline trong <head> (không nháy màu):
     lựa chọn đã lưu (localStorage 'mmo-theme') > cài đặt hệ thống (prefers-color-scheme) > tối.
   - Tối = bảng màu gốc trong style.css (:root). File này GHI ĐÈ bảng màu cho chế độ sáng,
     vẽ bầu trời trong header (.sky: sao + cực quang ban đêm, mây ban ngày — KHÔNG còn mặt trời/trăng
     cạnh nút, vì nút chuyển đã có biểu tượng mặt trời/trăng) và nút chuyển giao diện (.theme-switch).
   - Đổi giao diện: cả trang lan ra theo vòng tròn từ nút bấm (View Transitions API, theme.js);
     trình duyệt không hỗ trợ → đổi màu mượt (html.theme-fade). prefers-reduced-motion → đổi tức thì.
   - Đã gỡ 2 chốt TEMP-ROLLOUT (ẩn nút + tắt prefers-color-scheme).
   ===================================================================== */

/* ---------- Bảng màu sáng (biến cũ của style.css — các trang đang dùng) ---------- */
html[data-theme="light"] {
    color-scheme: light;
    --bg-body: #f3f6fb;
    --bg-primary: #ffffff;
    --bg-secondary: #eef2f8;
    --bg-tertiary: #e8edf5;
    --bg-card: #ffffff;
    --bg-nav: #1f7bff;
    --bg-white: #ffffff;
    --bg-dark: #0f172a;
    --bg-card-hover: #f1f5fb;
    --glass-bg: rgba(255, 255, 255, 0.82);
    --glass-bg-light: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(15, 23, 42, 0.10);
    --glass-shadow: 0 4px 14px -4px rgba(15, 23, 42, 0.10);
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #2563eb;
    --primary-glow: rgba(37, 99, 235, 0.12);
    --secondary: #64748b;
    --accent: #2563eb;
    --accent-cyan: #0891b2;
    --accent-light: rgba(37, 99, 235, 0.10);
    --gradient-hero: linear-gradient(135deg, #eaf2ff 0%, #ffffff 100%);
    --gradient-card: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0) 100%);
    --gradient-gold: linear-gradient(135deg, rgba(245, 158, 11, 0.14) 0%, rgba(217, 119, 6, 0.06) 100%);
    --gradient-border: linear-gradient(135deg, rgba(15, 23, 42, 0.10), rgba(15, 23, 42, 0.04));
    --success: #059669;
    --success-light: rgba(5, 150, 105, 0.12);
    --warning: #d97706;
    --warning-light: rgba(217, 119, 6, 0.12);
    --danger: #dc2626;
    --danger-light: rgba(220, 38, 38, 0.10);
    --info: #2563eb;
    --info-light: rgba(37, 99, 235, 0.10);
    --error: #dc2626;
    --text-main: #0f172a;
    --text-primary: #0b1220;
    --text-secondary: #475569;
    --text-muted: #5b6b80;
    --text-light: #94a3b8;
    --border: rgba(15, 23, 42, 0.10);
    --border-color: rgba(15, 23, 42, 0.10);
    --border-light: rgba(15, 23, 42, 0.06);
    --border-focus: rgba(37, 99, 235, 0.45);
    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 12px 24px -8px rgba(15, 23, 42, 0.14), 0 4px 8px -4px rgba(15, 23, 42, 0.06);
    --shadow-xl: 0 24px 40px -12px rgba(15, 23, 42, 0.18), 0 8px 12px -6px rgba(15, 23, 42, 0.08);
    --shadow-nav: 0 1px 0 rgba(15, 23, 42, 0.06);
    --shadow-glow: 0 0 18px rgba(37, 99, 235, 0.10);
    --shadow-card-hover: 0 0 0 1px rgba(37, 99, 235, 0.25), 0 12px 28px -10px rgba(15, 23, 42, 0.18);
}
html[data-theme="dark"] { color-scheme: dark; }

/* ====================== BẦU TRỜI (lớp riêng, tự cắt — header KHÔNG overflow:hidden để menu thả xuống không bị cắt) ====================== */
.navbar .sky { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; contain: strict; border-radius: inherit;
    /* vùng logo: sao/mây không chạy sau chữ thương hiệu */
    --bz: max(250px, calc(50% - var(--shell-w, 1240px) / 2 + 270px)); }
.navbar .sky > span { position: absolute; inset: 0; display: block; }

/* Đêm: xanh than + cực quang mờ */
.sky .sky-night {
    background:
        radial-gradient(520px 120px at 72% -30px, rgba(110, 130, 255, 0.22), transparent 70%),
        radial-gradient(380px 90px at 18% 110%, rgba(60, 120, 255, 0.10), transparent 70%),
        linear-gradient(180deg, #050816 0%, #0a1230 62%, #111b42 100%);
    opacity: 1;
}
/* Ngày: dải xanh đủ ĐẬM sau chữ trắng (chữ thương hiệu ≥3:1, chữ nút trên kính tối ≥4.5:1) */
.sky .sky-day {
    background:
        radial-gradient(420px 90px at 62% -36px, rgba(255, 255, 255, 0.20), transparent 70%),
        linear-gradient(180deg, #1f7bff 0%, #2581ff 55%, #3a8dff 100%);
    opacity: 0;
}
/* Ráng chiều / bình minh — chỉ loé lên trong lúc chuyển */
.sky .sky-dusk {
    background:
        radial-gradient(90% 140% at 64% 120%, rgba(255, 170, 90, 0.85) 0%, rgba(255, 110, 120, 0.45) 35%, rgba(130, 80, 200, 0) 70%),
        linear-gradient(180deg, rgba(60, 50, 140, 0) 0%, rgba(255, 140, 110, 0.30) 100%);
    opacity: 0;
}

/* Sao: 2 lớp chấm thưa, lấp lánh lệch nhịp; che khỏi vùng logo */
.sky .stars {
    opacity: 0; background-repeat: repeat;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, transparent var(--bz), #000 calc(var(--bz) + 110px));
            mask-image: linear-gradient(90deg, transparent 0, transparent var(--bz), #000 calc(var(--bz) + 110px));
}
.sky .stars-1 {
    background-image:
        radial-gradient(1.2px 1.2px at 14px 16px, #fff 98%, transparent),
        radial-gradient(1px 1px at 70px 44px, rgba(255, 255, 255, .8) 98%, transparent),
        radial-gradient(1.3px 1.3px at 122px 8px, #fff 98%, transparent),
        radial-gradient(1px 1px at 168px 52px, rgba(255, 255, 255, .7) 98%, transparent),
        radial-gradient(1px 1px at 212px 28px, #fff 98%, transparent);
    background-size: 240px 64px;
}
.sky .stars-2 {
    background-image:
        radial-gradient(1px 1px at 40px 34px, rgba(200, 215, 255, .9) 98%, transparent),
        radial-gradient(1.5px 1.5px at 96px 56px, #fff 98%, transparent),
        radial-gradient(1px 1px at 146px 20px, rgba(255, 255, 255, .8) 98%, transparent),
        radial-gradient(1px 1px at 300px 12px, #fff 98%, transparent);
    background-size: 330px 64px;
    background-position: 70px 4px;
}
@keyframes sky-twinkle { 0%, 100% { opacity: .38; } 50% { opacity: .8; } }

/* Mây: ảnh SVG mờ mềm, lặp ngang, trôi chậm; chỉ ở dải dưới header + tránh vùng logo (giữ tương phản chữ) */
.sky .sky-clouds {
    opacity: 0; background-repeat: repeat-x;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, transparent var(--bz), #000 calc(var(--bz) + 140px)),
                        linear-gradient(180deg, transparent 0, transparent 38%, #000 92%);
    -webkit-mask-composite: source-in;
            mask-image: linear-gradient(90deg, transparent 0, transparent var(--bz), #000 calc(var(--bz) + 140px)),
                        linear-gradient(180deg, transparent 0, transparent 38%, #000 92%);
            mask-composite: intersect;
}
.sky .sky-clouds-back {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='760' height='64'%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='3'/%3E%3C/filter%3E%3Cg fill='%23fff' fill-opacity='.45' filter='url(%23b)'%3E%3Cellipse cx='90' cy='54' rx='70' ry='12'/%3E%3Cellipse cx='120' cy='46' rx='32' ry='14'/%3E%3Cellipse cx='430' cy='58' rx='78' ry='10'/%3E%3Cellipse cx='460' cy='50' rx='34' ry='11'/%3E%3Cellipse cx='650' cy='60' rx='60' ry='10'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 760px 100%;
}
.sky .sky-clouds-front {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1100' height='64'%3E%3Cfilter id='b'%3E%3CfeGaussianBlur stdDeviation='2.2'/%3E%3C/filter%3E%3Cg fill='%23fff' filter='url(%23b)'%3E%3Cellipse cx='170' cy='62' rx='96' ry='13' fill-opacity='.85'/%3E%3Cellipse cx='140' cy='54' rx='40' ry='16' fill-opacity='.85'/%3E%3Cellipse cx='196' cy='52' rx='32' ry='15' fill-opacity='.85'/%3E%3Cellipse cx='720' cy='60' rx='66' ry='9' fill-opacity='.6'/%3E%3Cellipse cx='744' cy='54' rx='28' ry='10' fill-opacity='.6'/%3E%3Cellipse cx='990' cy='64' rx='88' ry='13' fill-opacity='.8'/%3E%3Cellipse cx='1016' cy='54' rx='38' ry='15' fill-opacity='.8'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 1100px 100%;
}
@keyframes sky-drift-back { from { background-position: 0 0; } to { background-position: -760px 0; } }
@keyframes sky-drift-front { from { background-position: 0 0; } to { background-position: -1100px 0; } }

/* ---------- Trạng thái SÁNG ---------- */
html[data-theme="light"] .sky .sky-day { opacity: 1; }
html[data-theme="light"] .sky .sky-night { opacity: 0; }
html[data-theme="light"] .sky .stars { opacity: 0; }
html[data-theme="light"] .sky .sky-clouds-back { opacity: .8; }
html[data-theme="light"] .sky .sky-clouds-front { opacity: .55; }
/* ---------- Trạng thái TỐI ---------- */
html[data-theme="dark"] .sky .stars-1 { opacity: .55; }
html[data-theme="dark"] .sky .stars-2 { opacity: .4; }

@media (max-width: 767px) {
    .navbar .sky { --bz: 170px; }
}

/* ---------- Chuyển động (bỏ hết nếu người dùng muốn giảm chuyển động) ---------- */
@media (prefers-reduced-motion: no-preference) {
    html[data-theme] .sky .sky-day { transition: opacity 1.1s ease .05s; }
    html[data-theme] .sky .sky-night { transition: opacity 1.2s ease .1s; }
    html[data-theme] .sky .sky-clouds { transition: opacity 1s ease; }
    html[data-theme] .sky .sky-clouds-back { animation: sky-drift-back 110s linear -40s infinite; }
    html[data-theme] .sky .sky-clouds-front { animation: sky-drift-front 80s linear -30s infinite; }
    html[data-theme="dark"] .sky .stars { transition: opacity 1s ease .55s; }
    html[data-theme="dark"] .sky .stars-1 { animation: sky-twinkle 4s ease-in-out infinite; }
    html[data-theme="dark"] .sky .stars-2 { animation: sky-twinkle 5.5s ease-in-out -2s infinite; }
    html[data-theme="light"] .sky .stars { transition: opacity .5s ease; }
    /* Ráng chiều/bình minh loé lên trong ~1.4s lúc đang chuyển */
    html.theme-switching .sky .sky-dusk { animation: sky-dusk 1.45s ease-in-out; }
    @keyframes sky-dusk { 0% { opacity: 0; } 45% { opacity: .75; } 100% { opacity: 0; } }

    /* Trình duyệt KHÔNG có View Transitions: đổi màu cả trang mượt (chỉ trong lúc chuyển) */
    html.theme-fade :where(body, body *:not(.sky):not(.sky *)) {
        transition: background-color .45s ease, border-color .45s ease, color .45s ease, fill .45s ease, box-shadow .45s ease !important;
    }
}

/* View Transitions: vòng tròn lan ra từ nút bấm (theme.js điều khiển animate) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }

/* ====================== NÚT CHUYỂN GIAO DIỆN (.theme-toggle.theme-switch) ======================
   Rãnh kính 62×36, mặt trời (trái) + trăng (phải) vẽ bằng SVG nội tuyến; núm trượt mang biểu tượng
   chế độ hiện tại. role=switch, aria-checked="true" = đang TỐI (theme.js cập nhật + nhãn theo ngôn ngữ). */
.theme-switch {
    position: relative; flex: 0 0 auto; width: 62px; height: 36px; padding: 0; margin: 0;
    border-radius: 999px; border: 1px solid var(--hglass-line, rgba(255, 255, 255, .12));
    background: var(--hglass, rgba(255, 255, 255, .06)); color: inherit; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    -webkit-backdrop-filter: blur(10px) saturate(1.3); backdrop-filter: blur(10px) saturate(1.3);
    transition: background .2s ease, border-color .2s ease;
}
.theme-switch:hover { background: var(--hglass-hover, rgba(255, 255, 255, .11)); }
.theme-switch:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.theme-switch .tsw-ic {
    position: absolute; top: 50%; width: 14px; height: 14px; margin-top: -7px;
    color: var(--hglass-text, rgba(226, 232, 255, .8)); opacity: .8; transition: opacity .25s ease;
}
.theme-switch .tsw-sun { left: 10px; }
.theme-switch .tsw-moon { right: 10px; }
.theme-switch .knob {
    position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center; background: #eef1ff; color: #4338ca;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .35), inset 0 -1px 0 rgba(0, 0, 0, .06);
    transform: translateX(26px);
    transition: transform .38s cubic-bezier(.45, 1.35, .55, 1), background .3s ease, color .3s ease, box-shadow .2s ease;
}
.theme-switch .knob .ico { width: 16px; height: 16px; display: block; }
.theme-switch .knob .k-sun { display: none; }
.theme-switch:hover .knob { box-shadow: 0 0 0 4px rgba(255, 255, 255, .10), 0 2px 6px rgba(0, 0, 0, .35); }
.theme-switch:active .knob { transform: translateX(26px) scale(.94); }
html[data-theme="dark"] .theme-switch .tsw-moon { opacity: 0; }
html[data-theme="light"] .theme-switch .tsw-sun { opacity: 0; }
html[data-theme="light"] .theme-switch .knob { transform: none; background: #fff; color: #d97706; box-shadow: 0 2px 8px rgba(10, 50, 140, .35); }
html[data-theme="light"] .theme-switch:active .knob { transform: scale(.94); }
html[data-theme="light"] .theme-switch .knob .k-sun { display: block; }
html[data-theme="light"] .theme-switch .knob .k-moon { display: none; }
@media (prefers-reduced-motion: reduce) {
    .theme-switch, .theme-switch * { transition: none !important; }
}
@media (max-width: 767px) {
    .theme-switch { width: 54px; height: 34px; }
    .theme-switch .knob { width: 26px; height: 26px; top: 3px; left: 3px; transform: translateX(20px); }
    .theme-switch:active .knob { transform: translateX(20px) scale(.94); }
    .theme-switch .knob .ico { width: 15px; height: 15px; }
    .theme-switch .tsw-sun { left: 8px; }
    .theme-switch .tsw-moon { right: 8px; }
    .theme-switch .tsw-ic { width: 13px; height: 13px; margin-top: -6.5px; }
}
@media (max-width: 369px) {
    .theme-switch { width: 50px; }
    .theme-switch .knob { width: 24px; height: 24px; top: 4px; left: 3px; transform: translateX(18px); }
    .theme-switch:active .knob { transform: translateX(18px) scale(.94); }
    .theme-switch .tsw-sun { left: 7px; }
    .theme-switch .tsw-moon { right: 7px; }
}
