/* ========================================================================
   XBOT — Sunlit Glass
   Shared by the main site (_Layout) and the standalone Lucky Draw pages.
   Main site:  tokens.css → site.css → glass.css → atelier.css
   Game pages: tokens.css → glass.css → games/ls.css (→ games/ny.css)

   1. Tokens          — light "sun" palette + the glass recipe
   2. Scene           — the moving background the glass refracts
   3. Glass material  — pane / inlay / photo-frame tiers, applied by
                        selector list so server and JS markup both pick it up
   Mobile first: every size and blur here is the phone value; wider
   screens scale up in the media queries at the end.
   ======================================================================== */

/* Pointer position for the specular highlight (set by scene.js).
   Not inherited, so a lit pane never lights the inlays inside it. */
@property --mx { syntax: '<length>'; inherits: false; initial-value: -999px; }
@property --my { syntax: '<length>'; inherits: false; initial-value: -999px; }

/* ===== 1. TOKENS ===== */
:root {
    --sun-0: #FFF8DC;
    --sun-1: #FFEFA6;
    --sun-2: #FDDF72;
    --sun-3: #F7CF4E;
    --sun-4: #EDB52A;

    --ink:   #1C1606;
    --ink-2: rgba(28, 22, 6, 0.74);
    --ink-3: rgba(28, 22, 6, 0.55);
    --ink-4: rgba(28, 22, 6, 0.12);

    /* The cool edge light. Kept as a channel triplet so alpha can vary. */
    --ice-rgb: 116, 186, 255;
    --ice:     rgb(var(--ice-rgb));
    --ice-ink: #1F5FA8;

    --ember:      #F26B0F;
    --ember-soft: #FF9B3D;

    /* Glass recipe */
    --glass-blur: 16px;
    --glass-sat: 170%;
    --glass-radius: 22px;
    --glass-radius-sm: 16px;
    --glass-fill:
        radial-gradient(130% 80% at 0% 0%, rgba(255, 255, 255, 0.62) 0%, rgba(255, 255, 255, 0) 46%),
        linear-gradient(112deg, rgba(255, 255, 255, 0) 28%, rgba(255, 255, 255, 0.3) 36%, rgba(255, 255, 255, 0.05) 44%, rgba(255, 255, 255, 0) 52%),
        linear-gradient(180deg, rgba(255, 253, 244, 0.3) 0%, rgba(255, 251, 236, 0.12) 100%);
    --glass-inlay:
        radial-gradient(140% 90% at 0% 0%, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0) 52%),
        linear-gradient(180deg, rgba(255, 254, 248, 0.46) 0%, rgba(255, 252, 240, 0.24) 100%);
    --glass-rim: linear-gradient(150deg,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(255, 255, 255, 0.55) 18%,
        rgba(255, 255, 255, 0.1) 42%,
        rgba(var(--ice-rgb), 0.35) 70%,
        rgba(var(--ice-rgb), 0.8) 100%);
    /* Hairline edges: the rim pseudo is the only line; the blue is a soft
       halo around it, never a second stroke. */
    --glass-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        inset 0 -20px 30px -26px rgba(var(--ice-rgb), 0.55),
        0 0 14px rgba(var(--ice-rgb), 0.3),
        0 22px 44px -24px rgba(122, 74, 0, 0.45);
    --glass-shadow-hover:
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        inset 0 -20px 30px -24px rgba(var(--ice-rgb), 0.7),
        0 0 22px rgba(var(--ice-rgb), 0.48),
        0 28px 52px -24px rgba(122, 74, 0, 0.5);
    --inlay-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.6),
        inset 0 -0.5px 0 rgba(var(--ice-rgb), 0.55),
        0 8px 18px -12px rgba(122, 74, 0, 0.4);
    --inlay-shadow-hover:
        inset 0 1px 0 #fff,
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.75),
        inset 0 -0.5px 0 rgba(var(--ice-rgb), 0.7),
        0 0 14px rgba(var(--ice-rgb), 0.4),
        0 12px 24px -12px rgba(122, 74, 0, 0.45);

    /* Legacy tokens from tokens.css, remapped so untouched selectors in
       site.css / ls.css / ny.css read correctly on the light field. */
    --bg:            var(--sun-2);
    --bg-1:          var(--sun-1);
    --bg-2:          rgba(255, 255, 255, 0.4);
    --surface-1:     rgba(255, 255, 255, 0.34);
    --surface-2:     rgba(255, 255, 255, 0.48);
    --surface-3:     rgba(255, 255, 255, 0.62);
    --border:        rgba(255, 255, 255, 0.55);
    --border-hover:  rgba(var(--ice-rgb), 0.6);
    --border-accent: rgba(var(--ice-rgb), 0.6);
    --text:          var(--ink);
    --text2:         var(--ink-2);
    --text-mid:      var(--ink-2);
    --text-muted:    var(--ink-3);
    --text3:         var(--ink-3);
    --text-white:    #fff;
    --info:          var(--ice-ink);
    --info-light:    #2C6FBF;
    --info-dim:      rgba(var(--ice-rgb), 0.18);
    --reward:        var(--ember);
    --reward-light:  #C2540A;
    --reward-dark:   #B44A06;
    --reward-dim:    rgba(242, 107, 15, 0.14);
    --rank:          #FFC21A;
    --rank-ink:      #3A2600;
    --emerald:       #0E9F5B;
    --rose:          #E0244A;
    --gold:          #B07A00;
    --silver:        #7A8597;
    --bronze:        #B0612A;
}

html {
    background-color: var(--sun-2);
    color-scheme: light;
}

body {
    background: transparent;
    color: var(--ink);
    font-family: var(--font);
    font-weight: 500;
}

/* The old grid / blob layers are replaced by the scene. */
body::before,
body::after { content: none !important; }

/* ===== 2. SCENE =====
   Back to front: the generated photo, sun rays, far orbs, near orbs and
   glass bubbles.

   Performance rule: whenever the scene changes, every glass pane over the
   changed area has to re-blur. So nothing full-screen animates on a timer.
   The photo and rays only move with scroll (scroll-driven CSS animations,
   run by the compositor); only the small orbs and bubbles drift on their
   own, and scene.js pauses them while the page is scrolling
   (.is-scrolling). Desktop pointer parallax uses `translate`, which
   composes with the scroll `transform`. */
.scene {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 0;
    width: 100%;
    height: 100vh;
    height: 100lvh;
    overflow: hidden;
    pointer-events: none;
    contain: strict;
    background:
        radial-gradient(120% 70% at 18% 0%, var(--sun-0) 0%, rgba(255, 248, 220, 0) 60%),
        linear-gradient(180deg, var(--sun-1) 0%, var(--sun-2) 45%, var(--sun-3) 100%);
}

.scene-photo {
    position: absolute;
    inset: -7%;
    background: url('../images/scene/sun-portrait.webp') center / cover no-repeat;
    transform: scale(1.04);
}
@media (min-aspect-ratio: 4/5) {
    .scene-photo { background-image: url('../images/scene/sun-landscape.webp'); }
}

/* Light shafts from the top-left sun in the photo. */
.scene-rays {
    position: absolute;
    top: -12vmax;
    left: -10vmax;
    width: 110vmax;
    height: 110vmax;
    transform-origin: 10vmax 12vmax;
    background: repeating-conic-gradient(from 96deg at 10vmax 12vmax,
        rgba(255, 255, 255, 0) 0deg 2deg,
        rgba(255, 255, 255, 0.1) 3deg,
        rgba(255, 255, 255, 0.3) 4.2deg,
        rgba(255, 255, 255, 0.1) 5.4deg,
        rgba(255, 255, 255, 0) 6.5deg 9deg);
    -webkit-mask-image: radial-gradient(circle at 10vmax 12vmax, #000 0%, rgba(0, 0, 0, 0.55) 26%, transparent 64%);
    mask-image: radial-gradient(circle at 10vmax 12vmax, #000 0%, rgba(0, 0, 0, 0.55) 26%, transparent 64%);
    opacity: 0.6;
}

.scene-depth {
    position: absolute;
    inset: 0;
}

/* Scroll parallax on the compositor where supported (Chromium 115+,
   Safari 26+). Other browsers keep the layers still. */
@supports (animation-timeline: scroll()) {
    .scene-photo,
    .scene-rays,
    .scene-depth {
        animation-duration: auto;
        animation-timing-function: linear;
        animation-fill-mode: both;
        animation-timeline: scroll(root block);
    }
    .scene-photo       { animation-name: parallaxPhoto; }
    .scene-rays        { animation-name: parallaxRays; }
    .scene-depth--far  { animation-name: parallaxFar; }
    .scene-depth--near { animation-name: parallaxNear; }
}
@keyframes parallaxPhoto {
    from { transform: scale(1.04) translate3d(0, 0, 0); }
    to   { transform: scale(1.04) translate3d(0, -5%, 0); }
}
@keyframes parallaxRays {
    from { transform: rotate(-3deg); }
    to   { transform: rotate(6deg); }
}
@keyframes parallaxFar {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(0, -90px, 0); }
}
@keyframes parallaxNear {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(0, -260px, 0); }
}

/* Glossy sun spheres: specular dot, warm body, shadowed rim. */
.orb {
    position: absolute;
    display: block;
    width: var(--d);
    height: var(--d);
    left: var(--x);
    top: var(--y);
    border-radius: 50%;
    background:
        radial-gradient(circle at 31% 26%, rgba(255, 255, 255, 0.98) 0 5%, rgba(255, 255, 255, 0) 19%),
        radial-gradient(circle at 38% 34%, #FFF7C9 0%, #FFE36A 30%, #FFC928 62%, #E8A10C 100%);
    box-shadow:
        inset -0.14em -0.2em 0.5em rgba(176, 104, 0, 0.32),
        inset 0.1em 0.12em 0.4em rgba(255, 255, 255, 0.5),
        0 1.4em 2.4em -1.2em rgba(150, 90, 0, 0.42);
    font-size: calc(var(--d) / 6);
    animation: orbDrift var(--t, 20s) ease-in-out var(--delay, 0s) infinite alternate;
    will-change: transform;
}
.orb--cream {
    background:
        radial-gradient(circle at 31% 26%, #fff 0 5%, rgba(255, 255, 255, 0) 19%),
        radial-gradient(circle at 38% 34%, #FFFFFF 0%, #FFF8E2 38%, #F4E3B2 78%, #DCC489 100%);
}
/* Out of focus: drawn soft, not filter: blur (a filter on a moving layer
   is re-applied every frame). */
.scene-depth--far .orb {
    background: radial-gradient(circle at 42% 40%, rgba(255, 246, 200, 0.95) 0%, rgba(255, 222, 110, 0.75) 38%, rgba(255, 205, 60, 0.3) 62%, rgba(255, 200, 50, 0) 72%);
    box-shadow: none;
}
.scene-depth--far .orb--cream {
    background: radial-gradient(circle at 42% 40%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 250, 230, 0.75) 38%, rgba(250, 236, 196, 0.3) 62%, rgba(250, 236, 196, 0) 72%);
}

@keyframes orbDrift {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(var(--dx), var(--dy), 0); }
}

/* Soap-glass bubbles: the cool light the glass edges pick up. */
.bubble {
    position: absolute;
    bottom: -14vh;
    left: var(--x);
    display: block;
    width: var(--d);
    height: var(--d);
    border-radius: 50%;
    background:
        radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.95) 0 6%, rgba(255, 255, 255, 0) 18%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.04) 52%, rgba(var(--ice-rgb), 0.28) 68%, rgba(255, 255, 255, 0.75) 76%, rgba(var(--ice-rgb), 0.5) 82%, rgba(var(--ice-rgb), 0) 86%);
    box-shadow: 0 0 22px rgba(var(--ice-rgb), 0.35);
    opacity: 0;
    animation: bubbleRise var(--t, 22s) linear var(--delay, 0s) infinite;
    will-change: transform, opacity;
}
@keyframes bubbleRise {
    0%   { transform: translate3d(0, 0, 0); opacity: 0; }
    8%   { opacity: 0.95; }
    50%  { transform: translate3d(var(--sway, 4vw), -62vh, 0); }
    88%  { opacity: 0.9; }
    100% { transform: translate3d(calc(var(--sway, 4vw) * -0.5), -128vh, 0); opacity: 0; }
}

/* Hold the drift while the page scrolls: scrolling already re-blurs every
   pane, the background should not add work on top of it. */
.scene.is-scrolling .orb,
.scene.is-scrolling .bubble { animation-play-state: paused; }

/* Orb + bubble placement (phone first: fewer, larger). */
.orb--1 { --d: 34vw; --x: -12vw; --y: 58vh; --dx: 6vw;  --dy: -5vh; --t: 23s; }
.orb--2 { --d: 18vw; --x: 78vw;  --y: 14vh; --dx: -5vw; --dy: 6vh;  --t: 19s; --delay: -6s; }
.orb--3 { --d: 12vw; --x: 64vw;  --y: 70vh; --dx: -7vw; --dy: -9vh; --t: 17s; --delay: -3s; }
.orb--4 { --d: 26vw; --x: 82vw;  --y: 44vh; --dx: -4vw; --dy: 8vh;  --t: 21s; --delay: -9s; }
.orb--5 { --d: 15vw; --x: 8vw;   --y: 22vh; --dx: 6vw;  --dy: 7vh;  --t: 18s; --delay: -4s; }
.orb--6 { --d: 9vw;  --x: 40vw;  --y: 88vh; --dx: 5vw;  --dy: -12vh; --t: 15s; --delay: -7s; display: none; }

.bubble--1 { --d: 15vw; --x: 12vw; --t: 24s; --sway: 6vw;  --delay: -2s; }
.bubble--2 { --d: 9vw;  --x: 70vw; --t: 19s; --sway: -5vw; --delay: -11s; }
.bubble--3 { --d: 12vw; --x: 46vw; --t: 27s; --sway: 4vw;  --delay: -17s; }
.bubble--4 { --d: 7vw;  --x: 86vw; --t: 21s; --sway: -6vw; --delay: -6s;  display: none; }
.bubble--5 { --d: 10vw; --x: 28vw; --t: 30s; --sway: 5vw;  --delay: -23s; display: none; }
.bubble--6 { --d: 6vw;  --x: 58vw; --t: 17s; --sway: -3vw; --delay: -9s;  display: none; }

@media (min-width: 768px) {
    .orb--1 { --d: 18vw; --x: -6vw;  --y: 54vh; }
    .orb--2 { --d: 9vw;  --x: 84vw;  --y: 10vh; }
    .orb--3 { --d: 6vw;  --x: 70vw;  --y: 72vh; }
    .orb--4 { --d: 13vw; --x: 90vw;  --y: 46vh; }
    .orb--5 { --d: 7vw;  --x: 6vw;   --y: 18vh; }
    .orb--6 { --d: 4.5vw; --x: 44vw; --y: 86vh; display: block; }
    .bubble--1 { --d: 6vw; }
    .bubble--2 { --d: 4vw; }
    .bubble--3 { --d: 5vw; }
    .bubble--4 { --d: 3vw; display: block; }
    .bubble--5 { --d: 4.5vw; display: block; }
    .bubble--6 { --d: 2.6vw; display: block; }
}

html[data-motion="off"] .scene *,
html[data-motion="off"] .scene { animation: none !important; }
html[data-motion="off"] .bubble { opacity: 0.8; bottom: auto; top: 70vh; }

/* ===== 3. GLASS MATERIAL ===== */

/* --- Tier A: panes. Real backdrop blur, gradient rim, cool edge glow. --- */
.topbar,
.arena-card:not(.arena-card--featured),
.tweet-card,
.stat-card,
.ld-stat-card,
.ld-countdown-card,
.pstat,
.modal-content,
.site-foot,
.error-card,
.xm-header,
.tweet-finder,
.tab-bar,
.x-input,
.x-select,
.tweet-clear-filter,
.ls-winners,
.ls-modal-card,
.ls-rules,
.msgbox,
.scratch-hint,
.slot-machine,
.mystery-hint {
    color: var(--ink);
    background:
        radial-gradient(240px circle at var(--mx, -999px) var(--my, -999px), rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 70%),
        var(--glass-fill);
    border: 0;
    box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat)) brightness(1.04);
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat)) brightness(1.04);
}

/* Panes need a containing block for the rim; zero specificity so the
   fixed topbar / tab bar / toast keep their own positioning. */
:where(.arena-card, .tweet-card, .stat-card, .ld-stat-card, .ld-countdown-card,
       .pstat, .site-foot, .error-card, .xm-header, .tweet-finder, .tab-bar, .tweet-clear-filter,
       .ls-winners, .ls-modal-card, .ls-rules, .scratch-hint, .slot-machine,
       .mystery-hint, .user-card, .glass-rim) {
    position: relative;
}

/* Gradient rim: bright where the sun hits (top-left), ice-blue on the
   far edge. Drawn inside the box so overflow:hidden never clips it. */
.topbar::before,
.tabbar::before,
.arena-card:not(.arena-card--featured)::before,
.tweet-card::before,
.stat-card::before,
.ld-stat-card::before,
.ld-countdown-card::before,
.pstat::before,
.modal-content::before,
.site-foot::before,
.error-card::before,
.tweets-paused::before,
.xm-header::before,
.tweet-finder::before,
.tweet-clear-filter::before,
.ls-winners::before,
.ls-modal-card::before,
.ls-rules::before,
.msgbox::before,
.scratch-hint::before,
.slot-machine::before,
.mystery-hint::before,
.cover-card::before,
.profile-cover::before,
.user-card::before,
.glass-rim::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    padding: 1px;
    border-radius: inherit;
    background: var(--glass-rim);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

/* --- Tier B: inlays. Glass laid on glass: no second blur (a nested
   backdrop only sees its parent), so it is whiter and edge-lit. --- */
.user-card,
.lb-row,
.pd-item,
.profile-link-item,
.rt-original,
.tweet-replies,
.xm-row,
.like-row,
.ls-winner-row,
.mystery-back,
.slot-reel-wrapper {
    background:
        radial-gradient(200px circle at var(--mx, -999px) var(--my, -999px), rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 70%),
        var(--glass-inlay);
    border: 0;
    box-shadow: var(--inlay-shadow);
    color: var(--ink);
}

/* --- Photo frames: the picture stays sharp, a glass sheet lies on top. --- */
.cover-card,
.profile-cover {
    position: relative;
    border: 0;
    box-shadow:
        0 0 14px rgba(var(--ice-rgb), 0.32),
        0 24px 44px -22px rgba(122, 74, 0, 0.5);
}
.cover-card::after,
.profile-cover::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(260px circle at var(--mx, -999px) var(--my, -999px), rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 70%),
        radial-gradient(120% 60% at 0% 0%, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0) 45%),
        linear-gradient(118deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.22) 38%, rgba(255, 255, 255, 0.04) 46%, rgba(255, 255, 255, 0) 54%);
}

/* Interactive glass lifts and its edge light brightens. */
a.user-card,
.cover-card,
.lb-row,
.profile-link-item,
.like-row,
.xm-row {
    /* transform only: animating a large blurred box-shadow repaints the
       whole card every frame. The glow changes, the lift animates. */
    transition: transform 0.3s var(--ease-out);
}
@media (hover: hover) {
    a.user-card:hover,
    a.lb-row:hover,
    .profile-link-item:hover,
    .like-row:hover,
    .xm-row:hover {
        box-shadow: var(--inlay-shadow-hover);
        background:
            radial-gradient(200px circle at var(--mx, -999px) var(--my, -999px), rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 70%),
            var(--glass-inlay);
    }
    .cover-card:hover {
        box-shadow:
            0 0 24px rgba(var(--ice-rgb), 0.5),
            0 30px 52px -22px rgba(122, 74, 0, 0.55);
    }
}
a.user-card:active,
.cover-card:active,
.lb-row:active,
.profile-link-item:active { transform: scale(0.98); }

/* Fallbacks */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .topbar, .tabbar, .arena-card:not(.arena-card--featured), .tweet-card,
    .stat-card, .ld-stat-card, .ld-countdown-card, .pstat, .modal-content,
    .site-foot, .error-card, .xm-header, .tab-bar, .x-input, .x-select, .ls-winners,
    .ls-modal-card, .ls-rules, .msgbox, .scratch-hint, .slot-machine, .mystery-hint {
        background: rgba(255, 251, 236, 0.9);
    }
}
@media (prefers-reduced-transparency: reduce) {
    .topbar, .tabbar, .arena-card:not(.arena-card--featured), .tweet-card,
    .stat-card, .ld-stat-card, .ld-countdown-card, .pstat, .modal-content,
    .site-foot, .error-card, .xm-header, .tab-bar, .x-input, .x-select, .ls-winners,
    .ls-modal-card, .ls-rules, .msgbox, .scratch-hint, .slot-machine, .mystery-hint {
        background: #FFFBEA;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

@media (min-width: 768px) {
    :root {
        --glass-blur: 26px;
        --glass-radius: 26px;
        --glass-radius-sm: 18px;
    }
}
