/* =========================================================
   CubeX – Hiệu ứng & bộ màu (fx.js)
   - Nền động: mảng màu loang trôi chậm + khối Rubik nhỏ bay
   - Bộ màu: Thiên hà, Đại dương (tối) · Hoàng hôn, Kẹo ngọt (sáng)
   - Chuyển trang, khung hiện dần khi cuộn, tiêu đề lấp lánh
   Tự tắt khi: đang bấm giờ / tự giải khối, máy bật "giảm chuyển động", hoặc người dùng tắt.
   ========================================================= */

/* ---------- Màu mảng loang mặc định ---------- */
:root { --blob1: #5B3DF5; --blob2: #E2B246; --blob3: #18A64A; --blob-a: .16; --title-grad: linear-gradient(100deg, var(--text) 0%, var(--accent) 45%, #E2378D 70%, var(--text) 100%); }
[data-theme="dark"] { --blob1: #5B3DF5; --blob2: #1E5BFF; --blob3: #C8961E; --blob-a: .22; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --blob1: #5B3DF5; --blob2: #1E5BFF; --blob3: #C8961E; --blob-a: .22; } }

/* ---------- Bộ màu ---------- */
[data-palette="galaxy"] {
  --bg: #0B0820; --surface: #15112E; --surface-2: #1E1840; --surface-3: #282153;
  --border: #2C2557; --border-strong: #3D3470;
  --accent: #A78BFA; --accent-hover: #C4B5FD; --accent-soft: #2A1F55; --accent-ink: #DDD6FE; --on-accent: #0B0820;
  --sh-accent: 0 6px 22px rgba(167, 139, 250, .35);
  --blob1: #7C3AED; --blob2: #DB2777; --blob3: #2563EB; --blob-a: .30;
}
[data-palette="ocean"] {
  --bg: #04141F; --surface: #0A2030; --surface-2: #0F2B3F; --surface-3: #15364D;
  --border: #173A52; --border-strong: #22506E;
  --accent: #22D3EE; --accent-hover: #67E8F9; --accent-soft: #0B3444; --accent-ink: #A5F3FC; --on-accent: #04141F;
  --sh-accent: 0 6px 22px rgba(34, 211, 238, .30);
  --blob1: #0EA5E9; --blob2: #14B8A6; --blob3: #6366F1; --blob-a: .28;
}
[data-palette="sunset"] {
  --bg: #FFF4EC; --surface: #FFFFFF; --surface-2: #FFEBDF; --surface-3: #FFDCC8;
  --border: #F8D5C2; --border-strong: #F0B999;
  --accent: #EA4E14; --accent-hover: #C93F0C; --accent-soft: #FFE3D6; --accent-ink: #9A2E06; --on-accent: #FFFFFF;
  --sh-accent: 0 6px 20px rgba(234, 78, 20, .30);
  --blob1: #FB923C; --blob2: #F472B6; --blob3: #FACC15; --blob-a: .30;
}
[data-palette="candy"] {
  --bg: #F6F1FF; --surface: #FFFFFF; --surface-2: #F1E9FF; --surface-3: #E6DAFF;
  --border: #E5D9FB; --border-strong: #CDB8F5;
  --accent: #DB2777; --accent-hover: #BE185D; --accent-soft: #FCE7F3; --accent-ink: #9D174D; --on-accent: #FFFFFF;
  --sh-accent: 0 6px 20px rgba(219, 39, 119, .28);
  --blob1: #A78BFA; --blob2: #F472B6; --blob3: #38BDF8; --blob-a: .30;
}

/* ---------- Nền động ---------- */
.fx-bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; transition: opacity .4s; }
.fx-bg .blob { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; opacity: var(--blob-a); will-change: transform; }
.fx-bg .b1 { left: -25vmax; top: -30vmax; background: radial-gradient(circle at center, var(--blob1) 0%, transparent 62%); animation: fxDrift1 26s ease-in-out infinite alternate; }
.fx-bg .b2 { right: -30vmax; top: 10vh; background: radial-gradient(circle at center, var(--blob2) 0%, transparent 62%); animation: fxDrift2 32s ease-in-out infinite alternate; }
.fx-bg .b3 { left: 10vw; bottom: -40vmax; background: radial-gradient(circle at center, var(--blob3) 0%, transparent 62%); animation: fxDrift3 38s ease-in-out infinite alternate; }
@keyframes fxDrift1 { to { transform: translate(18vw, 14vh) scale(1.12); } }
@keyframes fxDrift2 { to { transform: translate(-16vw, 18vh) scale(.92); } }
@keyframes fxDrift3 { to { transform: translate(14vw, -16vh) scale(1.1); } }

/* Khối Rubik nhỏ bay lơ lửng */
.fx-cube { position: absolute; bottom: -80px; width: var(--sz); height: var(--sz); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: calc(var(--sz) * .07); padding: calc(var(--sz) * .09); box-sizing: border-box; border-radius: 22%; background: var(--cube-body); opacity: 0;
  animation: fxFloat var(--dur) linear var(--delay) infinite; will-change: transform, opacity; }
.fx-cube i { border-radius: 22%; }
@keyframes fxFloat {
  0% { transform: translate(0, 0) rotate(var(--r0)); opacity: 0; }
  8% { opacity: var(--op); }
  50% { transform: translate(var(--dx), -55vh) rotate(calc(var(--r0) + 180deg)); }
  92% { opacity: var(--op); }
  100% { transform: translate(0, calc(-100vh - 160px)) rotate(calc(var(--r0) + 360deg)); opacity: 0; }
}

/* Tắt nền động: người dùng tắt / đang bấm giờ / tự giải / giảm chuyển động */
html.fx-off .fx-bg { display: none; }
body.timing .fx-bg, body.play-mode .fx-bg { opacity: 0; }
body.timing .fx-bg *, body.play-mode .fx-bg * { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
  .fx-bg .blob { animation: none; }
  .fx-cube { display: none; }
}

/* ---------- Chuyển trang & hiện dần ---------- */
html:not(.fx-off) .view:not([hidden]) { animation: fxViewIn .45s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes fxViewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
html.fx-reveal .view .panel.fx-wait { opacity: 0; transform: translateY(22px) scale(.985); }
html.fx-reveal .view .panel.fx-in { opacity: 1; transform: none; transition: opacity .55s ease, transform .6s cubic-bezier(.2, .7, .2, 1); transition-delay: var(--fx-d, 0s); }

/* Tiêu đề trang lấp lánh */
html:not(.fx-off) .view > header h1, html:not(.fx-off) .page-head h1 {
  background: var(--title-grad); background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: fxShine 7s ease-in-out infinite;
}
@keyframes fxShine { 0%, 100% { background-position: 100% 0; } 50% { background-position: 0 0; } }

/* Logo khối Rubik đổi màu như đang xoay */
html:not(.fx-off) .logo i { animation: fxLogo 9s ease-in-out infinite; }
html:not(.fx-off) .logo i:nth-child(2) { animation-delay: -2.25s; }
html:not(.fx-off) .logo i:nth-child(3) { animation-delay: -4.5s; }
html:not(.fx-off) .logo i:nth-child(4) { animation-delay: -6.75s; }
@keyframes fxLogo {
  0%, 20% { background: var(--cube-r); } 25%, 45% { background: var(--cube-y); }
  50%, 70% { background: var(--cube-b); } 75%, 95% { background: var(--cube-g); } 100% { background: var(--cube-r); }
}
html:not(.fx-off) .brand:hover .logo { animation: fxSpin .8s cubic-bezier(.3, .7, .3, 1); }
@keyframes fxSpin { to { transform: rotate(360deg); } }

/* Nút chính: vệt sáng lướt qua khi rê chuột */
button.primary, button.gold, .vip-hero .big { position: relative; overflow: hidden; }
html:not(.fx-off) button.primary::after, html:not(.fx-off) button.gold::after, html:not(.fx-off) .vip-hero .big::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .45), transparent); transform: skewX(-20deg);
}
html:not(.fx-off) button.primary:hover::after, html:not(.fx-off) button.gold:hover::after, html:not(.fx-off) .vip-hero .big:hover::after { animation: fxSweep .8s ease; }
@keyframes fxSweep { to { left: 130%; } }
/* Nút VIP lớn tự lấp lánh mỗi vài giây */
html:not(.fx-off) .vip-hero .big::after { animation: fxSweep 1s ease 2s infinite; animation-duration: 4s; }

/* Thẻ nổi lên khi rê chuột */
@media (hover: hover) {
  .case-card, .puzzle-grid > *, .panel.vip-register { transition: transform .2s ease, box-shadow .2s ease; }
  .case-card:hover, .puzzle-grid > *:hover { transform: translateY(-4px); box-shadow: var(--sh-2); }
}
/* Thanh điều hướng: biểu tượng nảy khi chọn */
html:not(.fx-off) .nav-tabs a.active .ni { animation: fxPop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes fxPop { 40% { transform: scale(1.25) translateY(-2px); } }

/* ---------- Bảng chọn giao diện ---------- */
.fx-picker { position: fixed; z-index: 60; width: min(320px, calc(100vw - 24px)); padding: 14px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-3); color: var(--text); animation: fxPickIn .22s ease both; }
.fx-picker[hidden] { display: none; }
@keyframes fxPickIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
.fx-picker h3 { margin: 0 0 10px; font-size: 1rem; }
.fx-swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fx-sw { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 2px; min-height: 0; border-radius: 12px;
  background: transparent; border: 2px solid transparent; font-size: .72rem; font-weight: 600; color: var(--text-2); line-height: 1.2; }
.fx-sw .dot { width: 34px; height: 34px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.15); }
.fx-sw.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.fx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: .9rem; }
.fx-row small { display: block; color: var(--muted); font-size: .76rem; }
.fx-picker { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }
/* ✏️ Tự tạo giao diện + mã giao diện */
.fx-cust { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); font-size: .88rem; }
.fx-cust summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.fx-colors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 10px 0 6px; }
.fx-col { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .7rem; font-weight: 600; color: var(--text-2); text-align: center; line-height: 1.15; }
.fx-col input { width: 40px; height: 40px; padding: 0; border: 2px solid var(--border-strong); border-radius: 50%; background: none; cursor: pointer; overflow: hidden; }
.fx-col input::-webkit-color-swatch-wrapper { padding: 0; }
.fx-col input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.fx-col input::-moz-color-swatch { border: 0; border-radius: 50%; }
.fx-radius { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-weight: 600; }
.fx-radius input { flex: 1; accent-color: var(--accent); }
.fx-note { margin: 4px 0; padding: 6px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); font-size: .78rem; }
.fx-codebox { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.fx-codebox small { width: 100%; color: var(--muted); }
.fx-codebox code { flex: 1 1 100%; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); font: 600 .74rem ui-monospace, Consolas, monospace; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
.fx-codebox button, .fx-paste button { min-height: 36px; padding: 0 12px; font-size: .82rem; }
.fx-paste { display: flex; gap: 6px; }
.fx-paste input { flex: 1; min-width: 0; min-height: 36px; padding: 0 10px; font: .8rem ui-monospace, Consolas, monospace; }
.fx-paste input::placeholder { color: var(--muted); opacity: 1; }
.fx-msg { margin: 6px 0 0; font-size: .8rem; min-height: 0; }
.fx-msg:empty { display: none; }
.fx-msg.ok { color: var(--success); } .fx-msg.bad { color: var(--danger); }
.fx-safe { margin: 6px 0; color: var(--muted); font-size: .74rem; line-height: 1.4; }
.fx-reset { font-size: .82rem; }

/* Nút "Giao diện" có chữ */
.icon-btn.theme-btn { width: auto; min-width: 0; gap: 6px; padding: 0 12px 0 6px; border: 1px solid var(--border); }
.theme-btn .tb-ico { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: conic-gradient(from 200deg, #F472B6, #A78BFA, #22D3EE, #FACC15, #FB923C, #F472B6); color: #fff; }
.theme-btn .tb-ico svg { width: 18px; height: 18px; }
.theme-btn .tb-label { font-size: .85rem; font-weight: 700; white-space: nowrap; }
@media (max-width: 640px) {
  .icon-btn.theme-btn { flex-direction: column; gap: 1px; padding: 3px 6px; height: auto; min-height: var(--tap-sm); border-radius: 14px; }
  .theme-btn .tb-ico { width: 22px; height: 22px; }
  .theme-btn .tb-ico svg { width: 15px; height: 15px; }
  .theme-btn .tb-label { font-size: .62rem; line-height: 1.1; }
}
