/* =====================================================================
   80 - FX (the "AAA" layer)
   One motion + depth system on top of the components, so every page
   (player and admin) gets the same feel without being rewritten:

     page change   cross-fade between pages (View Transitions, CSS only),
                   crimson loading bar while the next page loads (fx.js)
     scrolling     reading-progress line under the menu (CSS scroll timeline),
                   blocks rise in as they reach the screen (reveal.js "fx-rise")
     surfaces      cards / panels / stat boxes: top light edge, a soft light that
                   follows the pointer (fx.js sets --mx/--my), light sweep on hover
     controls      buttons: light sweep, press, busy spinner after submit (fx.js);
                   chips, badges, table rows, inputs, pagination, alerts, pop-ups
     page header   slow camera drift on the picture, title rising in, crimson bar
     admin         menu stays still while the page changes, header light sweep

   Rules: transform / opacity only for anything that runs often, nothing from
   other hosts, Thai text never gets letter-spacing or is cut by an effect.
   Everything that moves sits in (prefers-reduced-motion: no-preference), so
   people who asked their OS for less motion get a still site.
   ===================================================================== */

/* ---------- Surfaces ------------------------------------------------------
   The plate itself (charcoal gradient + top light, --plate / --plate-hi) is set in 30-components.css. */
.stat-box { position: relative; }

/* soft light that follows the pointer (position from fx.js; hidden until the pointer is over the box) */
:is(.card, .panel, .stat-box, .small-box, .shop-card, .news-card, .shop-cat-card, .apack, .acc-char)::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 0%), rgba(220, 31, 41, .1), rgba(220, 31, 41, .03) 40%, transparent 70%);
    opacity: 0;
    transition: opacity var(--dur) ease;
}
:is(.card, .panel, .stat-box, .small-box, .shop-card, .news-card, .shop-cat-card, .apack, .acc-char).fx-lit::after { opacity: 1; }

/* thin light running along the crimson top edge on hover */
:is(.card, .panel, .stat-box, .small-box)::before {
    content: '';
    position: absolute;
    left: -1px; right: -1px; top: -3px;
    z-index: 2;
    height: 3px;
    pointer-events: none;
    background: linear-gradient(90deg, transparent 0 35%, rgba(255, 220, 220, .95) 50%, transparent 65% 100%) 0 0 / 300% 100% no-repeat;
    background-position: 100% 0;
    opacity: 0;
}

/* ---------- Interactive surfaces lift ------------------------------------ */
@media (hover: hover) {
    :is(.stat-box, .small-box, a.card, .card.is-link) { transition: translate var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), border-color var(--dur); }
    :is(.stat-box, .small-box, a.card, .card.is-link):hover { translate: 0 -4px; box-shadow: var(--plate-hi), var(--lift-shadow); }
    .stat-box:hover .stat-icon { animation: fx-icon-pop .5s var(--ease-spring); }
}

/* ---------- Buttons ------------------------------------------------------ */
.btn { isolation: isolate; }
/* light sweep: under the label (isolation above), clipped by the button's torn-edge mask */
.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, .28) 48%, rgba(255, 255, 255, .06) 56%, transparent 70%) 0 0 / 250% 100% no-repeat;
    background-position: 140% 0;
    opacity: 0;
}
.btn:active:not(:disabled):not(.disabled) { transform: translateY(1px) scale(.97); transition-duration: .08s; }
.btn.is-busy { cursor: progress; }
.btn.is-busy::after {
    content: '';
    flex: none;
    width: 1em; height: 1em;
    margin: 0;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: middle;
    animation: spin .7s linear infinite;
}

/* ---------- Focus: one ring for every control ---------------------------- */
:is(a, button, [role="button"], .custom-control-input, .x-switch input, summary):focus-visible { outline: 2px solid var(--accent-hot); outline-offset: 2px; }
.form-control:focus-visible { outline: none; }

/* ---------- Forms -------------------------------------------------------- */
.form-control { transition: border-color var(--dur-fast), box-shadow var(--dur), background-color var(--dur); }
.form-control:hover:not(:focus):not(:disabled) { border-color: rgba(255, 255, 255, .26); }
.form-control:focus { background: rgba(10, 6, 7, .75) !important; }
.form-group:focus-within > label, .form-group:focus-within > .form-label { color: var(--accent-2); }
label { transition: color var(--dur-fast); }

/* ---------- Chips & badges ---------------------------------------------- */
.chip, .badge { transition: filter var(--dur-fast), background-color var(--dur-fast), border-color var(--dur-fast); }
.chip:hover { filter: brightness(1.2); }
.chip.ok .chip-dot { border-radius: 50%; }

/* ---------- Tables ------------------------------------------------------- */
.table tbody tr > :first-child { transition: box-shadow var(--dur) var(--ease-out); }
.table-hover tbody tr:hover > :first-child, .table tbody tr:hover > :first-child { box-shadow: inset 3px 0 0 var(--accent-hot); }
.table thead th { background: linear-gradient(180deg, rgba(255, 255, 255, .045), rgba(255, 255, 255, .015)); }

/* ---------- Pagination --------------------------------------------------- */
.pagination .page-link { transition: background-color var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast), translate var(--dur) var(--ease-out); }
.pagination .page-item:not(.active):not(.disabled) .page-link:hover { color: #fff; background: rgba(184, 19, 27, .25); border-color: rgba(220, 31, 41, .5); translate: 0 -2px; }
.pagination .page-item.active .page-link { box-shadow: 0 0 18px rgba(220, 31, 41, .45); }

/* ---------- Pop-ups ------------------------------------------------------ */
.modal-backdrop.show { backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal-content { box-shadow: 0 40px 90px rgba(0, 0, 0, .7), 0 0 0 1px rgba(220, 31, 41, .18); }

/* ---------- Loading bar + reading progress (elements made by fx.js / CSS) ---- */
.fx-loadbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 2100;
    height: 3px;
    pointer-events: none;
    background: linear-gradient(90deg, var(--accent-dark), var(--accent-hot) 70%, #ffb3b6);
    box-shadow: 0 0 12px rgba(220, 31, 41, .8);
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
}
.fx-leaving .fx-loadbar { opacity: 1; transform: scaleX(.85); transition: transform 6s cubic-bezier(.08, .8, .2, 1), opacity .2s; }

/* ---------- Ambient light behind every page ------------------------------- */
body::after {
    content: '';
    position: fixed;
    inset: -20% -10%;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(40% 35% at 15% 20%, rgba(184, 19, 27, .09), transparent 70%),
        radial-gradient(35% 30% at 85% 75%, rgba(120, 12, 18, .08), transparent 70%);
}

/* ---------- Admin -------------------------------------------------------- */
.admin-side-link > span { transition: translate var(--dur) var(--ease-out); }
.admin-side-link > i { transition: color .2s, scale var(--dur) var(--ease-spring); }
.admin-side-link.active > i { filter: drop-shadow(0 0 6px rgba(220, 31, 41, .8)); }
.admin-top { position: relative; overflow: hidden; }
.admin-top::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(100deg, transparent 35%, rgba(255, 255, 255, .07) 50%, transparent 65%);
    transform: translateX(-100%);
}
.admin-section::before { transition: scale var(--dur) var(--ease-spring); }

/* ---------- Page header ------------------------------------------------- */
.page-hero::after {
    content: '';
    position: absolute;
    left: 50%; bottom: 24px;
    width: 140px; height: 3px;
    margin-left: -70px;
    background: linear-gradient(90deg, transparent, var(--accent-hot) 30%, #ffd2d4 50%, var(--accent-hot) 70%, transparent) 0 0 / 200% 100%;
    box-shadow: 0 0 14px rgba(220, 31, 41, .6);
}
.page-hero h1 { text-shadow: 0 6px 30px rgba(0, 0, 0, .65), 0 0 40px rgba(184, 19, 27, .25); }

/* ---------- Thai text: even lines, no lone word on the last line ------------- */
.page-hero h1, .page-hero p, .admin-title, .card-header, .auth-art-copy h2 { text-wrap: balance; }
p, .text-muted, .kpi-sub, .admin-subtitle, li { text-wrap: pretty; }

/* ===================== everything that moves ===================== */
@media (prefers-reduced-motion: no-preference) {
    /* page change: the old page fades away, the new one comes in; the menu (and admin
       sidebar) are their own layers so they stay put instead of flashing */
    @view-transition { navigation: auto; }
    ::view-transition-old(root) { animation: fx-vt-out .24s var(--ease-in-out) both; }
    ::view-transition-new(root) { animation: fx-vt-in .42s var(--ease-out) .06s both; }
    .site-nav { view-transition-name: site-nav; }
    .admin-side { view-transition-name: admin-side; }
    main { animation-duration: .5s; }

    /* reading progress under the menu (browsers without scroll timelines just skip it) */
    @supports (animation-timeline: scroll()) {
        .site-nav::after {
            content: '';
            position: absolute;
            left: 0; right: 0; bottom: 0;
            height: 2px;
            pointer-events: none;
            background: linear-gradient(90deg, var(--accent-dark), var(--accent-hot), #ffb3b6);
            box-shadow: 0 0 10px rgba(220, 31, 41, .7);
            transform-origin: left;
            transform: scaleX(0);
            animation: fx-progress linear both;
            animation-timeline: scroll(root block);
        }
    }

    /* blocks below the fold rise in (classes set by reveal.js, removed again when done) */
    .fx-rise { opacity: 0; transform: translateY(28px) scale(.985); transition: opacity .75s var(--ease-out), transform .75s var(--ease-out); transition-delay: var(--fx-d, 0s); }
    .fx-rise.is-in { opacity: 1; transform: none; }

    /* surfaces */
    :is(.card, .panel, .stat-box, .small-box):hover::before { opacity: 1; animation: fx-edge 1.1s var(--ease-in-out) both; }

    /* buttons */
    @media (hover: hover) {
        .btn:hover::before { opacity: 1; animation: fx-sheen .8s var(--ease-out) both; }
        .admin-side-link:hover > span { translate: 3px 0; }
        .admin-side-link:hover > i { scale: 1.18; }
        .admin-section:hover::before { scale: 1.15 1.25; }
    }

    /* live dots, waiting badges */
    .chip.ok .chip-dot { animation: fx-dot 2.2s ease-in-out infinite; }
    .badge-pill, .nav-bell-count { animation: fx-pop .5s var(--ease-spring) backwards; }
    .admin-badge { animation: fx-pop .5s var(--ease-spring) backwards, pulse-accent 2s .5s infinite; }

    /* table rows come in one after another (first 12; the rest together) */
    .table tbody tr { animation: fx-row .5s var(--ease-out) backwards; animation-delay: calc(var(--fx-r, 12) * 28ms); }
    .table tbody tr:nth-child(1) { --fx-r: 0; } .table tbody tr:nth-child(2) { --fx-r: 1; } .table tbody tr:nth-child(3) { --fx-r: 2; }
    .table tbody tr:nth-child(4) { --fx-r: 3; } .table tbody tr:nth-child(5) { --fx-r: 4; } .table tbody tr:nth-child(6) { --fx-r: 5; }
    .table tbody tr:nth-child(7) { --fx-r: 6; } .table tbody tr:nth-child(8) { --fx-r: 7; } .table tbody tr:nth-child(9) { --fx-r: 8; }
    .table tbody tr:nth-child(10) { --fx-r: 9; } .table tbody tr:nth-child(11) { --fx-r: 10; } .table tbody tr:nth-child(12) { --fx-r: 11; }

    /* inline alerts slide in; pop-ups spring open */
    main .alert:not(.flash-wrap .alert) { animation: fx-alert .6s var(--ease-out) backwards; }
    .modal.fade .modal-dialog { transform: translateY(18px) scale(.95); transition: transform .4s var(--ease-spring), opacity .3s; opacity: 0; }
    .modal.show .modal-dialog { transform: none; opacity: 1; }

    /* page header: slow camera drift, title rises, bar grows then keeps a slow glint */
    .page-hero::before { animation: kenburns 26s ease-in-out infinite alternate; }
    .page-hero h1 { animation: fx-title 1s var(--ease-out) backwards; }
    .page-hero::after { animation: fx-bar .9s .35s var(--ease-out) backwards, fx-glint 4s 1.4s linear infinite; }

    /* ambient light drifts very slowly */
    body::after { animation: fx-ambient 38s ease-in-out infinite alternate; will-change: transform; }

    /* admin header: one light sweep when the page opens */
    .admin-top::after { animation: fx-sweep 1.4s .25s var(--ease-in-out) both; }
}

/* ---------- Keyframes (only used above) --------------------------------- */
@keyframes fx-vt-out { to { opacity: 0; transform: translateY(-10px); } }
@keyframes fx-vt-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes fx-progress { to { transform: scaleX(1); } }
@keyframes fx-edge { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes fx-sheen { from { background-position: 140% 0; } to { background-position: -40% 0; } }
@keyframes fx-icon-pop { 0% { transform: none; } 40% { transform: scale(1.12) rotate(-4deg); } 100% { transform: none; } }
@keyframes fx-dot { 0%, 100% { opacity: 1; filter: drop-shadow(0 0 0 transparent); } 50% { opacity: .55; filter: drop-shadow(0 0 4px currentColor); } }
@keyframes fx-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
@keyframes fx-row { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fx-alert { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
@keyframes fx-title { from { opacity: 0; transform: translateY(26px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fx-bar { from { opacity: 0; transform: scaleX(0); } to { opacity: 1; transform: none; } }
@keyframes fx-glint { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes fx-ambient { from { transform: translate3d(-3%, -2%, 0) scale(1); } to { transform: translate3d(4%, 3%, 0) scale(1.08); } }
@keyframes fx-sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
