* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans Thai', 'Noto Sans', sans-serif;
    background: transparent !important;
    background-color: transparent !important;
    overflow: hidden;
}

/* ── Root wrapper ───────────────────────────────── */
.overlay-root {
    width: 100vw;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* ── Overlay title ──────────────────────────────── */
#overlay-title {
    font-family: 'Noto Sans Thai', 'Noto Sans', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.03em;
    padding: 0 16px;
    margin-bottom: 16px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    /* border-radius matching sticker-cell */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: titleAppear 0.4s ease forwards;

    width: 100%;
    /* max-width set dynamically via JS to match grid width */
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    height: 48px;
    /* reduced height */
}

#overlay-title span {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#overlay-title span.marquee {
    position: absolute;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    animation: titleMarqueeScroll 12s linear infinite;
    padding-left: 20px;
    padding-right: 20px;
}

@keyframes titleMarqueeScroll {
    0% {
        transform: translateX(80px);
    }

    100% {
        transform: translateX(-100%);
    }
}

@keyframes titleAppear {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.overlay-root.disconnected .sticker-grid {
    opacity: 0.3;
    transition: opacity 0.4s;
}

/* ── Grid ───────────────────────────────────────── */
.sticker-grid {
    display: grid;
    /* columns / rows set dynamically via JS (fixed px per cell) */
    gap: 4px;
    /* Sized to its content; fitGrid() in script.js then transform-scales the
       whole grid to fill the OBS source, so stickers grow/shrink with the
       Width/Height the streamer sets (e.g. 2500×2500) instead of staying tiny
       at the base 140px cell size. */
    justify-content: center;
    align-content: center;
    overflow: visible;
    transition: opacity 0.4s;
    transform-origin: center center;
    will-change: transform;
}

/* ── Cell card ──────────────────────────────────── */
/* --cell-scale is set by fitGrid() in script.js (1 = the base 140px cell).
   Inner art / padding / fonts multiply by it so a cell stays proportional at
   any OBS source size. The grid track itself sizes the cell box (width/height
   100%), so we no longer hard-code a 140px width here. */
.sticker-grid { --cell-scale: 1; }
.sticker-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: rgba(0, 0, 0, 0.40);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: calc(16px * var(--cell-scale));
    padding: calc(10px * var(--cell-scale)) calc(6px * var(--cell-scale)) calc(8px * var(--cell-scale));
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    will-change: transform;
    overflow: visible;
}

.sticker-cell.empty {
    opacity: 0;
    pointer-events: none;
}

/* In-cell layout for V (image beside label, left→right) lives in the
   "Vertical Layout Mode" block below — single source, no duplicate here. */

.sticker-cell.has-custom-bg {
    background: transparent;
    border: none;
    box-shadow: none;
}

/* ── Background Video ───────────────────────────── */
.cell-bg-wrap {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    overflow: hidden;
    z-index: -2;
    pointer-events: none;
}

.cell-bg-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: .8;
}

/* ── Image wrapper ──────────────────────────────── */
.cell-img-wrap {
    width: calc(90px * var(--cell-scale));
    height: calc(90px * var(--cell-scale));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.cell-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
    display: none;
    /* shown only when src is set */
    position: relative;
    z-index: 2;
}

.cell-img.loaded {
    display: block;
    animation: imgAppear 0.3s ease forwards;
}

@keyframes imgAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Empty cell dot */
.cell-img-wrap .empty-dot {
    /* width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 1px dashed rgba(255, 255, 255, 0.25); */
}

/* ── Custom Ring Video ──────────────────────────── */
.cell-ring-video {
    position: absolute;
    inset: -12px;
    width: calc(100% + 24px);
    height: calc(100% + 24px);
    object-fit: contain;
    z-index: 1;
    pointer-events: none;
}

/* ── Label ──────────────────────────────────────── */
.cell-label {
    width: 100%;
    height: calc(36px * var(--cell-scale));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-top: calc(6px * var(--cell-scale));
    position: relative;
}

.cell-label span {
    display: inline-block;
    white-space: nowrap;
    font-family: 'Noto Sans Thai', 'Noto Sans', sans-serif;
    font-size: calc(20px * var(--cell-scale));
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    padding: 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.cell-label span.marquee {
    overflow: visible;
    text-overflow: unset;
    max-width: unset;
    position: absolute;
    animation: marqueeScroll 8s linear infinite;
    will-change: transform;
}

@keyframes marqueeScroll {
    0% {
        transform: translateX(80px);
    }

    100% {
        transform: translateX(-100%);
    }
}

/* ── Vertical Layout Mode ─────────────────────────
   The cell FILLS its grid track (sized by fitGrid() in script.js: V track is
   ~246×88). Do NOT hard-code width/height here — a fixed 240×80 fought the
   track size and made cards misalign/overlap. width/height:100% inherits from
   the base .sticker-cell; here we only set the row arrangement + spacing. */
.sticker-grid.layout-vertical .sticker-cell {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 12px;
    gap: 12px;
}

/* Image fills the (shorter) card height so the gift stays large on a compact
   strip; auto width keeps it square via aspect-ratio. */
.sticker-grid.layout-vertical .cell-img-wrap {
    width: auto;
    height: 72px;
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
}

.sticker-grid.layout-vertical .cell-ring-video {
    inset: -8px;
    width: calc(100% + 16px);
    height: calc(100% + 16px);
}

.sticker-grid.layout-vertical .cell-label {
    flex: 1;
    height: 100%;
    margin-top: 0;
    justify-content: flex-start;
    text-align: left;
}

.sticker-grid.layout-vertical .cell-label span {
    font-size: 18px;
    text-align: left;
    max-width: 100%;
}

.sticker-grid.layout-vertical .cell-label span.marquee {
    position: absolute;
    text-align: left;
}

/* ── Trigger animation ──────────────────────────── */
@keyframes cellTrigger {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 215, 50, 0);
    }

    15% {
        transform: scale(1.18);
        box-shadow:
            0 0 0 3px rgba(255, 215, 50, 0.9),
            0 0 24px 8px rgba(255, 160, 0, 0.7);
    }

    50% {
        transform: scale(1.10);
        box-shadow:
            0 0 0 2px rgba(255, 215, 50, 0.6),
            0 0 14px 4px rgba(255, 160, 0, 0.4);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 215, 50, 0);
    }
}

.sticker-cell.triggered {
    animation: cellTrigger 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.3) forwards;
    z-index: 10;
}

/* Glow ring that pulses continuously on triggered cells */
@keyframes glowPulse {

    0%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }

    50% {
        opacity: 0.9;
        transform: scale(1.05);
    }
}

.sticker-cell.triggered .cell-img-wrap::after {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: conic-gradient(#ff0000, #ff8800, #ffee00,
            #00cc44, #0088ff, #8800ff,
            #ff0088, #ff0000);
    filter: blur(8px);
    opacity: 0.5;
    z-index: -1;
    animation: glowPulse 0.8s ease-in-out 2;
}

/* ── Update flash (whole grid received new data) ── */
@keyframes gridFlash {
    0% {
        outline: 0px solid rgba(100, 200, 255, 0);
    }

    30% {
        outline: 2px solid rgba(100, 200, 255, 0.5);
    }

    100% {
        outline: 0px solid rgba(100, 200, 255, 0);
    }
}

.sticker-grid.updated {
    animation: gridFlash 0.5s ease forwards;
}