/* CSS Design System for Classroom Lucky Games - Light Mode Edition */
:root {
    --bg-main: #f0f4f8;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-card-hover: #ffffff;
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #1e293b;
    --text-muted: #64748b;
    
    /* Neon/Vibrant Accents for Light Theme */
    --accent-purple: #7c3aed;
    --accent-purple-glow: rgba(124, 58, 237, 0.3);
    --accent-pink: #ec4899;
    --accent-pink-glow: rgba(236, 72, 153, 0.3);
    --accent-cyan: #06b6d4;
    --accent-cyan-glow: rgba(6, 182, 212, 0.3);
    --accent-gold: #f59e0b;
    --accent-gold-glow: rgba(245, 158, 11, 0.4);
    
    /* Status Colors */
    --color-success: #10b981;
    --color-danger: #ef4444;
    
    /* Fonts */
    --font-thai: 'Kanit', sans-serif;
    --font-eng: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-thai);
    height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(6, 182, 212, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.8) 0%, transparent 100%);
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh; /* use dynamic viewport height to prevent clipping in iframes/mobile */
}

/* Settings Drawer (Hidden by default) */
.settings-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 360px;
    height: 100dvh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    padding: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.settings-drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
}

.btn-close-drawer {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s;
}
.btn-close-drawer:hover { color: var(--color-danger); }

.drawer-content {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px var(--accent-purple-glow));
}

.brand h2 {
    font-family: var(--font-eng);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #334155, var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Custom Styled Select and Inputs */
.styled-select {
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    padding: 12px 14px;
    font-family: var(--font-thai);
    font-size: 15px;
    outline: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.styled-select:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px var(--accent-purple-glow);
}

.class-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.styled-textarea {
    width: 100%;
    height: 220px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    padding: 14px;
    font-family: var(--font-thai);
    font-size: 16px;
    line-height: 1.6;
    resize: none;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.styled-textarea:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px var(--accent-purple-glow);
}

.list-section {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-danger);
    font-family: var(--font-thai);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.btn-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Styled Toggles */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 12px;
}

.toggle-switch input {
    display: none;
}

.slider {
    width: 48px;
    height: 26px;
    background-color: #cbd5e1;
    border-radius: 34px;
    position: relative;
    transition: .3s;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: .3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .slider {
    background-color: var(--accent-purple);
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(22px);
}

.label-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-family: var(--font-thai);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-block {
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

.btn-secondary {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: var(--color-danger);
}

.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-text-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-thai);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}

.btn-text-icon:hover {
    color: var(--text-primary);
}

.backup-actions {
    display: flex;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.main-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding: 12px 24px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.03);
    z-index: 500;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 200px;
}
.header-right {
    justify-content: flex-end;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}
.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.active-class-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.badge {
    background: rgba(124, 58, 237, 0.1);
    color: var(--accent-purple);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    align-self: flex-start;
}

.active-class-info h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Game Tabs Navigation (Pill style) */
.game-tabs {
    display: flex;
    gap: 6px;
    background: rgba(0, 0, 0, 0.04);
    padding: 6px;
    border-radius: 100px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 100px;
    padding: 10px 20px;
    font-family: var(--font-thai);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn i {
    font-size: 16px;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background: #ffffff;
    color: var(--accent-purple);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Game Stage (Viewport Area) */
.game-stage {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    /* Smooth theme transitions between modes */
    transition: background 0.8s ease;
    /* Default comfortable theme */
    background: radial-gradient(circle at center, #ffffff 0%, #f1f5f9 100%);
}

/* --- DYNAMIC GAME THEMES --- */
.game-stage.theme-wheel {
    background: radial-gradient(circle at center, #ffffff 0%, #f1f5f9 100%);
}
.game-stage.theme-slot {
    background: radial-gradient(circle at center, #0f172a 0%, #020617 100%); /* Casino Dark */
}
.game-stage.theme-race {
    background: linear-gradient(180deg, #dcfce7 0%, #86efac 100%); /* Grass Track */
}
.game-stage.theme-gacha {
    background: radial-gradient(circle at center, #1e1b4b 0%, #020617 100%); /* Cosmic Dark */
}
.game-stage.theme-battle {
    background: radial-gradient(circle at center, #450a0a 0%, #000000 100%); /* Danger Dark */
}
.game-stage.theme-group {
    background: radial-gradient(circle at center, #f0f9ff 0%, #e0f2fe 100%); /* Calm Blue */
}

.stage-pane {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
}

.stage-pane.active {
    display: flex;
}

.stage-actions {
    display: flex;
    justify-content: center;
    margin-top: 30px;
    z-index: 10;
}

.btn-giant {
    padding: 20px 48px;
    font-size: 24px;
    font-weight: 800;
    border-radius: 20px;
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
    letter-spacing: 1px;
}

/* --- GAME MODE 1: SPINNING WHEEL (GIANT WHEEL + SPOTLIGHT POINTER ARM) --- */
/* Background SVG Rays */
.wheel-bg-rays {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.svg-rays-spin {
    width: min(130vh, 130vw);
    height: min(130vh, 130vw);
    animation: rotateRays 80s linear infinite;
    color: var(--accent-purple);
}

@keyframes rotateRays {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.wheel-box {
    position: relative;
    width: min(86vh, 75vw);
    height: min(86vh, 75vw);
    max-width: 850px;
    max-height: 850px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 
        0 35px 70px rgba(0, 0, 0, 0.22),
        0 0 0 16px rgba(255, 255, 255, 1),
        0 0 50px rgba(236, 72, 153, 0.4);
    z-index: 5;
    margin-left: -80px; /* Slight left shift so pointer arm fits right edge */
    transition: transform 0.3s ease;
}

/* Integrated Spotlight Pointer Arm attached to right edge (3 o'clock) */
.wheel-spotlight-pointer-arm {
    position: absolute;
    right: -245px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    z-index: 30;
    pointer-events: none;
}

.pointer-arrow-tip-svg {
    z-index: 2;
    margin-right: -4px;
    filter: drop-shadow(-4px 0 10px rgba(244, 63, 94, 0.8));
    transform-origin: 90% 50%;
    transition: transform 0.04s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pointer-arrow-tip-svg.flick {
    transform: rotate(-22deg) scale(1.15);
}

@keyframes arrowPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); }
}

.pointer-spotlight-badge {
    background: #0f172a; /* Solid Deep Midnight for 100% High Contrast */
    border: 3px solid #f43f5e; /* Crisp border */
    border-radius: 22px;
    padding: 14px 24px;
    position: relative;
    box-shadow: 
        0 20px 45px rgba(15, 23, 42, 0.8),
        0 0 25px rgba(244, 63, 94, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 230px;
    max-width: 340px;
    z-index: 1;
    transition: border-color 0.3s, box-shadow 0.3s;
}

/* Dynamic Badge States */
.pointer-spotlight-badge.state-idle {
    border-color: #38bdf8;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.8), 0 0 20px rgba(56, 189, 248, 0.3);
}
.pointer-spotlight-badge.state-idle .spotlight-mini-tag {
    color: #38bdf8;
}

.pointer-spotlight-badge.state-spinning {
    border-color: #f43f5e;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.8), 0 0 30px rgba(244, 63, 94, 0.5);
}
.pointer-spotlight-badge.state-spinning .spotlight-mini-tag {
    color: #fbbf24;
}

.pointer-spotlight-badge.state-winner {
    border-color: #fbbf24;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.8), 0 0 40px rgba(251, 191, 36, 0.7);
}
.pointer-spotlight-badge.state-winner .spotlight-mini-tag {
    color: #f59e0b;
}

.spotlight-mini-tag {
    color: #fbbf24;
    font-size: 13px;
    font-weight: 800;
    font-family: var(--font-thai);
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.5px;
    background: rgba(255, 255, 255, 0.08);
    padding: 4px 10px;
    border-radius: 12px;
}

.spotlight-name-display {
    font-family: var(--font-thai);
    font-size: clamp(26px, 2.8vw, 42px);
    font-weight: 900;
    background: linear-gradient(135deg, #ffffff 0%, #fef08a 60%, #fbbf24 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.9));
    min-height: 48px;
    display: flex;
    align-items: center;
    transition: transform 0.05s ease-out;
    word-break: break-word;
    line-height: 1.2;
}

.spotlight-name-display.bump {
    transform: scale(1.15);
}

#wheelCanvas {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    z-index: 5;
}

/* Giant Center Spin Button */
.btn-spin-center-giant {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 27%;
    height: 27%;
    border-radius: 50%;
    background: linear-gradient(135deg, #f43f5e, #8b5cf6);
    border: 8px solid white;
    box-shadow: 
        0 12px 30px rgba(139, 92, 246, 0.5),
        inset 0 -5px 15px rgba(0,0,0,0.2);
    color: white;
    font-family: var(--font-thai);
    cursor: pointer;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 0;
}

.btn-spin-center-giant:hover {
    transform: translate(-50%, -50%) scale(1.08);
    box-shadow: 
        0 18px 40px rgba(244, 63, 94, 0.6),
        inset 0 -5px 15px rgba(0,0,0,0.2);
}

.btn-spin-center-giant:active {
    transform: translate(-50%, -50%) scale(0.95);
}

.spin-main-text {
    font-size: clamp(20px, 3.2vw, 42px);
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.spin-sub-text {
    font-size: clamp(10px, 1.1vw, 15px);
    font-weight: 700;
    opacity: 0.9;
    margin-top: 2px;
}


/* --- GAME MODE 2: SLOT MACHINE (LAS VEGAS GOLD & CYBER NEON) --- */
.slot-game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1100px;
    margin: 0 auto;
    overflow: hidden;
    padding: 20px;
    box-sizing: border-box;
}

/* Background SVG Rays for Slot */
.slot-bg-rays {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.svg-slot-rays {
    width: min(130vh, 130vw);
    height: min(130vh, 130vw);
    animation: rotateRays 70s linear infinite;
}

.slot-machine {
    display: flex;
    align-items: center;
    background: linear-gradient(145deg, #1e1b4b 0%, #0f172a 100%);
    border: 5px solid #fbbf24;
    border-radius: 36px;
    padding: 55px 70px 45px 70px;
    box-shadow: 
        0 35px 70px rgba(0, 0, 0, 0.45),
        0 0 45px rgba(245, 158, 11, 0.35),
        inset 0 0 40px rgba(0, 0, 0, 0.8);
    width: 100%;
    position: relative;
    z-index: 5;
}

/* Marquee Crown Badge Header */
.slot-marquee-header {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    border: 3px solid #fbbf24;
    border-radius: 20px;
    padding: 6px 24px;
    color: #fbbf24;
    font-size: 15px;
    font-weight: 900;
    font-family: var(--font-thai);
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.4);
    z-index: 10;
}

/* Casino LED Bulbs Row */
.slot-led-row {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 40px;
    z-index: 8;
}

.led-bulb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 10px #ffffff, 0 0 20px #fbbf24;
    animation: ledBlink 1.2s infinite alternate;
}

.led-bulb:nth-child(even) {
    animation-delay: 0.6s;
    background: #fbbf24;
}

@keyframes ledBlink {
    0% { opacity: 0.4; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1.2); }
}

.slot-window {
    flex-grow: 1;
    height: 280px;
    background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
    border: 6px solid #fbbf24;
    border-radius: 24px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        inset 0 0 40px rgba(0, 0, 0, 0.25),
        0 0 25px rgba(251, 191, 36, 0.3);
}

.slot-reel {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.1s linear;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.slot-name-item {
    width: 100%;
    height: 280px; /* Must match slot window exactly */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(38px, 6vw, 85px); /* Massive Font */
    font-weight: 900;
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
    padding: 0 30px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-name-item.placeholder {
    color: var(--text-muted);
    font-size: 32px;
    font-weight: 700;
    -webkit-text-fill-color: initial;
    filter: none;
}

.slot-frame-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: linear-gradient(to bottom, 
        rgba(15,23,42,0.15) 0%, 
        rgba(255,255,255,0) 25%, 
        rgba(255,255,255,0) 75%, 
        rgba(15,23,42,0.15) 100%
    );
    border-radius: 18px;
}

/* 3D Handle animation */
.slot-handle-container {
    width: 90px;
    height: 240px;
    position: absolute;
    right: -75px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    justify-content: center;
}

.slot-handle {
    width: 28px;
    height: 170px;
    background: linear-gradient(to right, #f43f5e, #fbbf24, #f43f5e);
    border-radius: 15px;
    position: relative;
    transform-origin: bottom center;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    box-shadow: 6px 0 20px rgba(244, 63, 94, 0.4);
}

.handle-shaft {
    width: 100%;
    height: 100%;
    border-radius: 15px;
}

.handle-ball {
    width: 64px;
    height: 64px;
    background: radial-gradient(circle at 30% 30%, #fbbf24, #f43f5e);
    border-radius: 50%;
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 20px rgba(244, 63, 94, 0.8), inset -3px -3px 8px rgba(0,0,0,0.3);
    border: 3px solid #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot-handle.pulled {
    transform: rotateX(65deg) scaleY(0.7);
}

/* Gold Slot Spin Button */
.btn-spin-slot-gold {
    padding: 20px 45px;
    font-size: 26px;
    font-weight: 900;
    border-radius: 22px;
    background: linear-gradient(135deg, #f59e0b, #ec4899);
    color: white;
    box-shadow: 0 15px 35px rgba(245, 158, 11, 0.45);
    border: none;
    cursor: pointer;
    font-family: var(--font-thai);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-spin-slot-gold:hover {
    transform: translateY(-4px) scale(1.04);
    box-shadow: 0 20px 40px rgba(245, 158, 11, 0.6);
}

.btn-spin-slot-gold:active {
    transform: translateY(2px) scale(0.97);
}

.pulled {
    transform: rotateX(60deg) translateY(40px);
}

.btn-slot-effect {
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    color: white;
    margin-top: -20px; /* Pull it up into the slot machine */
    position: relative;
    z-index: 10;
    padding: 24px 60px;
    font-size: 28px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-left-radius: 30px;
    border-bottom-right-radius: 30px;
    border: 8px solid #94a3b8;
    border-top: none;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.btn-slot-effect:hover {
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    transform: translateY(5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

/* --- GAME MODE 3: RACING LANE --- */
.race-game-container {
    width: 100%;
    max-width: 95vw;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.08);
}

.track-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    padding: 0 20px;
    color: #065f46;
}

.track-title {
    font-size: 24px;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(255,255,255,0.5);
}

.track-status {
    font-size: 18px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.8);
    padding: 4px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.race-track {
    display: flex;
    flex-direction: column;
    height: 75vh; /* Take up much more vertical space */
    max-height: 800px;
    min-height: 400px;
    background: #e11d48; /* Athletics track red */
    border: 6px solid #f1f5f9;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.3);
    isolation: isolate; /* PREVENT Z-INDEX LEAKING OVER MODALS */
}

.race-lane {
    flex: 1; /* Automatically squish to fit */
    min-height: 0; /* Prevents overflow */
    display: flex;
    align-items: center;
    border-bottom: 2px dashed rgba(255, 255, 255, 0.3);
    position: relative;
    container-type: size; /* Enable container queries for dynamic sizing */
}

/* Remove bottom border for the last lane */
.race-lane:last-child {
    border-bottom: none;
}

.lane-num {
    font-family: var(--font-eng);
    font-weight: 900;
    font-size: min(60cqh, 32px);
    color: rgba(255,255,255,0.75);
    text-shadow: 0 2px 4px rgba(0,0,0,0.4);
    width: 55px;
    text-align: center;
    z-index: 2;
}

.runner-path {
    flex-grow: 1;
    position: relative;
    height: 100%;
    margin-right: 40px; /* Finish line area */
}

.runner-avatar-wrapper {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: left 0.1s linear, top 0.8s ease-in-out;
    z-index: 5;
}

.runner-emoji {
    font-size: min(90cqh, 64px);
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}

.runner-emoji.running {
    animation: runBounce 0.3s infinite alternate;
}

@keyframes runBounce {
    0% { transform: translateY(0) rotate(-5deg); }
    100% { transform: translateY(min(-15cqh, -10px)) rotate(10deg); }
}

.runner-name {
    font-size: min(50cqh, 26px);
    font-weight: 900;
    color: #0f172a;
    background: #ffffff;
    border: 2px solid #0f172a;
    border-radius: 6px;
    padding: 3px 10px;
    white-space: nowrap;
    margin-top: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    display: block;
    letter-spacing: 0.5px;
}

/* Shrink names if height is tiny instead of hiding */
@container (max-height: 25px) {
    .runner-name {
        font-size: min(38cqh, 14px);
        padding: 1px 4px;
        border-width: 1px;
    }
}

.finish-line {
    position: absolute;
    right: 30px;
    top: 0;
    bottom: 0;
    width: 25px;
    background-image: repeating-conic-gradient(#fff 0% 25%, #0f172a 0% 50%);
    background-size: 20px 20px;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
    z-index: 1;
    opacity: 0; /* Hidden during survival mode */
    transition: opacity 1s ease-in;
}

.finish-line.show {
    opacity: 1;
}

.runner-avatar-wrapper.eliminated {
    transform: scale(0) rotate(-720deg) translateY(-100px) !important;
    opacity: 0;
    transition: all 1s cubic-bezier(0.5, 0, 1, 0.5) !important;
}

.btn-race-effect {
    background: linear-gradient(135deg, #10b981, #06b6d4);
}

.btn-race-effect:hover {
    transform: scale(1.05) translateY(-4px);
    box-shadow: 0 12px 30px rgba(16, 189, 129, 0.4);
}

/* --- GAME MODE 4: GACHA DRAW --- */
.gacha-game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
}

.gacha-machine-decor {
    position: relative;
    width: 400px;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gacha-orb-container {
    position: relative;
    z-index: 2;
}

.gacha-orb {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    color: white;
    cursor: pointer;
    box-shadow: 
        0 0 50px rgba(139, 92, 246, 0.6),
        inset 0 -20px 40px rgba(0, 0, 0, 0.2);
    animation: floatingOrb 4s ease-in-out infinite;
}

.crystal-orb {
    background: radial-gradient(circle at 30% 30%, #a78bfa, #7c3aed);
    border: 6px solid rgba(255, 255, 255, 0.8);
}

.gacha-question {
    text-shadow: 0 0 20px rgba(255,255,255,0.9);
    animation: pulseGlow 2s ease-in-out infinite;
}

.gacha-magic-circle {
    position: absolute;
    width: 350px;
    height: 350px;
    border: 3px dashed rgba(6, 182, 212, 0.6);
    border-radius: 50%;
    animation: rotateCircle 25s linear infinite;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 30px rgba(6, 182, 212, 0.2);
}

.gacha-magic-circle:before {
    content: "";
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border: 2px solid rgba(236, 72, 153, 0.5);
    border-radius: 50%;
    transform: rotate(45deg);
}

@keyframes floatingOrb {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}

@keyframes rotateCircle {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.btn-gacha-effect {
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-pink));
}

.btn-gacha-effect:hover {
    transform: scale(1.05) translateY(-4px);
    box-shadow: 0 12px 30px rgba(245, 158, 11, 0.4);
}

/* --- GAME MODE 5: BATTLE ROYALE --- */
.battle-game-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin: 0 auto;
}

.battle-header {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.9) 0%, rgba(30, 27, 75, 0.9) 100%);
    border: 2px solid rgba(168, 85, 247, 0.5);
    color: white;
    padding: 12px 24px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 18px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4), 0 0 20px rgba(168, 85, 247, 0.25);
    backdrop-filter: blur(10px);
}

.battle-title-tag {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #c084fc;
    font-family: var(--font-thai);
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 1px;
}

.battle-alive-tag {
    background: rgba(168, 85, 247, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.4);
    padding: 6px 16px;
    border-radius: 14px;
    font-size: 16px;
    font-family: var(--font-eng);
}

.battle-alive-tag strong {
    color: #f43f5e;
    font-size: 20px;
}

.battle-arena-wrapper {
    background: #090d16;
    border: 5px solid #a855f7;
    border-radius: 28px;
    overflow: hidden;
    width: 100%;
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.5),
        0 0 35px rgba(168, 85, 247, 0.35),
        inset 0 0 40px rgba(0, 0, 0, 0.9);
    position: relative;
}

#battleCanvas {
    display: block;
    width: 100%;
    height: auto;
}

.btn-battle-effect {
    padding: 18px 40px;
    font-size: 24px;
    font-weight: 900;
    border-radius: 20px;
    background: linear-gradient(135deg, #ef4444 0%, #a855f7 100%);
    color: white;
    box-shadow: 0 12px 30px rgba(239, 68, 68, 0.45);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-thai);
    transition: all 0.25s ease;
}

.btn-battle-effect:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 18px 40px rgba(168, 85, 247, 0.6);
}

.btn-gacha-x5-effect {
    background: linear-gradient(45deg, #f59e0b, #fbbf24);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.6);
    color: #451a03;
    animation: goldPulse 2s infinite alternate;
}
.btn-gacha-x5-effect:hover {
    transform: scale(1.05);
    box-shadow: 0 0 40px rgba(245, 158, 11, 0.9);
}
@keyframes goldPulse {
    0% { box-shadow: 0 0 15px rgba(245, 158, 11, 0.5); }
    100% { box-shadow: 0 0 30px rgba(245, 158, 11, 0.9), inset 0 0 10px rgba(255,255,255,0.8); }
}

.btn-gacha-x10-effect {
    background: linear-gradient(90deg, #ec4899, #8b5cf6, #3b82f6, #ec4899);
    background-size: 300% 100%;
    animation: rainbowPan 3s infinite linear, intensePulse 1s infinite alternate;
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.8);
    color: white;
    border: 2px solid white;
}
.btn-gacha-x10-effect:hover {
    transform: scale(1.08);
    box-shadow: 0 0 50px rgba(236, 72, 153, 1), 0 0 20px rgba(59, 130, 246, 0.8);
}
@keyframes rainbowPan {
    0% { background-position: 100% 0; }
    100% { background-position: -200% 0; }
}
@keyframes intensePulse {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.02); filter: brightness(1.2); }
}

/* --- GAME MODE 6: GROUP GENERATOR --- */
.group-game-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.group-config-row {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

.input-unit {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-unit label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.styled-input-num {
    background: #f8fafc;
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    color: var(--text-primary);
    padding: 12px;
    font-size: 18px;
    width: 120px;
    outline: none;
    font-family: var(--font-eng);
    font-weight: bold;
    transition: all 0.3s ease;
}

.styled-input-num:focus {
    border-color: var(--accent-purple);
}

.select-sm {
    padding: 12px 16px;
    font-size: 16px;
}

.groups-display-area {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    min-height: 300px;
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
    opacity: 0.8;
}

.empty-state i {
    font-size: 64px;
    color: #cbd5e1;
}

/* Group Card Design */
.group-card {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    animation: scaleIn 0.4s ease-out;
}

.group-card:hover {
    transform: translateY(-6px);
    border-color: var(--accent-cyan);
    box-shadow: 0 15px 35px rgba(6, 182, 212, 0.15);
}

.group-card-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-bottom: 2px dashed #e2e8f0;
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.group-team-name {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-purple);
}

.group-team-meta {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

.group-card-members {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.group-member-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

.group-member-item:before {
    content: "🌟";
    font-size: 18px;
}

@keyframes scaleIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes slideIn {
    0% { transform: translateX(-10px); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}


/* --- CINEMATIC OVERLAYS --- */
.cinematic-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    /* Beautiful cosmic gradient */
    background: radial-gradient(circle at center, #1e1b4b 0%, #020617 100%);
    z-index: 99999; /* Top level above all headers and sidebars */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.4s ease;
    overflow: hidden;
}

.cinematic-overlay.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#gachaSkyCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Gacha Stage layout */
.gacha-game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.gacha-multi-actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Fix Gacha Overflow with max limits and scaling */
.gacha-summon-card-wrapper {
    perspective: 1200px;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    align-content: center;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
    height: 100%;
    padding: 40px 20px 80px 20px; /* Leave room for absolute button at bottom */
}

/* Layout modifiers for multi-pulls using CSS Grid for absolute column enforcement */
.gacha-summon-card-wrapper.layout-x5 {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 130px)); /* span 2 = max 260px + gap */
    justify-content: center;
    gap: 15px;
}
.gacha-summon-card-wrapper.layout-x5 .gacha-card-animator {
    grid-column: span 2;
    width: 100%;
    max-width: 260px;
    max-height: calc(50vh - 40px);
}
/* Center the bottom row of 2 items by offsetting the 4th item */
.gacha-summon-card-wrapper.layout-x5 .gacha-card-animator:nth-child(4) {
    grid-column-start: 2;
}

.gacha-summon-card-wrapper.layout-x10 {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    justify-content: center;
    gap: 24px 24px; /* Guaranteed 24px clear gap vertically and horizontally */
    width: 95%;
    max-width: 1240px;
    margin: 0 auto;
    padding-top: 50px;
    padding-bottom: 95px;
    align-content: center;
}
.gacha-summon-card-wrapper.layout-x10 .gacha-card-animator {
    width: 100%;
    max-width: 200px;
    aspect-ratio: 2.5 / 3.4; /* Slightly shorter aspect ratio to guarantee card separation */
    max-height: calc(36vh);
}

/* Animator handles 2D entrance, scale, and shaking */
.gacha-card-animator {
    width: 100%;
    max-width: 380px;
    aspect-ratio: 2.5 / 4;
    position: relative;
    /* Initial state hidden/shrunk */
    transform: scale(0.01) translateY(-1000px);
    transition: transform 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gacha-card-animator.entered {
    transform: scale(1) translateY(0);
}

/* RARITY SPECIFIC SHAKING ANIMATIONS */
.gacha-card-animator.shaking-r { animation: cardShakeR 0.1s infinite; }
.gacha-card-animator.shaking-sr { animation: cardShakeSR 0.07s infinite; filter: brightness(1.1); }
.gacha-card-animator.shaking-ssr { animation: cardShakeSSR 0.04s infinite; filter: brightness(1.3); }

@keyframes cardShakeR {
    0%, 100% { transform: scale(1.01) translate(1px, 0) rotate(0deg); }
    50% { transform: scale(1.01) translate(-1px, 0) rotate(1deg); }
}

@keyframes cardShakeSR {
    0% { transform: scale(1.03) translate(2px, 1px) rotate(0deg); }
    25% { transform: scale(1.03) translate(-2px, -1px) rotate(-1deg); }
    50% { transform: scale(1.03) translate(-1px, 2px) rotate(1deg); }
    75% { transform: scale(1.03) translate(1px, -2px) rotate(0deg); }
    100% { transform: scale(1.03) translate(2px, 1px) rotate(-1deg); }
}

@keyframes cardShakeSSR {
    0% { transform: scale(1.05) translate(4px, 2px) rotate(0deg); box-shadow: 0 0 20px rgba(245, 158, 11, 0.5); }
    25% { transform: scale(1.05) translate(-4px, -2px) rotate(-2deg); box-shadow: 0 0 40px rgba(245, 158, 11, 0.8); }
    50% { transform: scale(1.05) translate(-2px, 4px) rotate(2deg); box-shadow: 0 0 20px rgba(245, 158, 11, 0.5); }
    75% { transform: scale(1.05) translate(2px, -4px) rotate(0deg); box-shadow: 0 0 50px rgba(245, 158, 11, 1); }
    100% { transform: scale(1.05) translate(4px, 2px) rotate(-2deg); box-shadow: 0 0 20px rgba(245, 158, 11, 0.5); }
}

/* 3D Gacha Card Flip */
.gacha-card {
    /* Responsive sizing to avoid clipping */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    cursor: pointer;
    border-radius: 28px;
    transition: transform 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 1.2s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
    transform: translateZ(0); /* Force containing block for absolute faces */
}

/* Base box shadow when landed (depends on rarity) */
.gacha-card-animator.entered .gacha-card.rarity-r {
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.9), 0 0 50px rgba(59, 130, 246, 0.5);
}
.gacha-card-animator.entered .gacha-card.rarity-sr {
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.9), 0 0 60px rgba(168, 85, 247, 0.6);
}
.gacha-card-animator.entered .gacha-card.rarity-ssr {
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.9), 0 0 80px rgba(245, 158, 11, 0.6);
}

.gacha-card.flipped.rarity-r {
    animation: none;
    transform: scale(1.1) rotateY(180deg) !important;
    box-shadow: 0 60px 120px rgba(0, 0, 0, 0.95), 0 0 100px rgba(59, 130, 246, 0.7);
}
.gacha-card.flipped.rarity-sr {
    animation: none;
    transform: scale(1.1) rotateY(180deg) !important;
    box-shadow: 0 60px 120px rgba(0, 0, 0, 0.95), 0 0 120px rgba(168, 85, 247, 0.8);
}
.gacha-card.flipped.rarity-ssr {
    animation: none;
    transform: scale(1.1) rotateY(180deg) !important;
    box-shadow: 0 60px 120px rgba(0, 0, 0, 0.95), 0 0 150px rgba(245, 158, 11, 0.9);
}

.gacha-card-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Front Face Base */
.gacha-card-front {
    transform: rotateY(180deg);
    padding: 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

/* RARITY SPECIFIC STYLES */
/* R Rarity (Blue) */
.gacha-card.rarity-r .gacha-card-front {
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    border: 6px solid #3b82f6;
    box-shadow: inset 0 0 30px rgba(59, 130, 246, 0.2);
}
.gacha-card.rarity-r .rarity-badges span { color: #2563eb; text-shadow: 0 0 10px rgba(59, 130, 246, 0.4); }
.gacha-card.rarity-r .stars { color: #3b82f6; }
.gacha-card.rarity-r .card-winner-title { color: #1e3a8a; }

/* SR Rarity (Purple) */
.gacha-card.rarity-sr .gacha-card-front {
    background: linear-gradient(135deg, #fae8ff 0%, #e9d5ff 100%);
    border: 6px solid #a855f7;
    box-shadow: inset 0 0 40px rgba(168, 85, 247, 0.3);
}
.gacha-card.rarity-sr .rarity-badges span { color: #9333ea; text-shadow: 0 0 12px rgba(168, 85, 247, 0.5); }
.gacha-card.rarity-sr .stars { color: #a855f7; }
.gacha-card.rarity-sr .card-winner-title { color: #581c87; }

/* SSR Rarity (Gold) */
.gacha-card.rarity-ssr .gacha-card-front {
    background: linear-gradient(135deg, #fff 0%, #fef3c7 100%);
    border: 6px solid var(--accent-gold);
    box-shadow: inset 0 0 50px rgba(245, 158, 11, 0.3);
}
.gacha-card.rarity-ssr .rarity-badges span { color: var(--accent-gold); text-shadow: 0 0 15px rgba(245, 158, 11, 0.6); }
.gacha-card.rarity-ssr .stars { color: var(--accent-gold); }
.gacha-card.rarity-ssr .card-winner-title { color: #b45309; }

/* Holographic Foil overlay */
.gacha-card-front::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(125deg, 
        rgba(255,255,255,0) 0%, 
        rgba(255,255,255,0) 35%, 
        rgba(255,255,255,0.9) 50%, 
        rgba(255,255,255,0) 65%, 
        rgba(255,255,255,0) 100%);
    background-size: 200% 200%;
    animation: holoShine 3s infinite linear;
    pointer-events: none;
    z-index: 10;
    mix-blend-mode: overlay;
}

@keyframes holoShine {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.gacha-glow-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(245, 158, 11, 0.3) 0%, transparent 60%);
    pointer-events: none;
    animation: rotateGlow 10s linear infinite;
}

@keyframes rotateGlow {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.card-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 2;
}

.rarity-badges {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Scale down font sizes when in multi layout so text fits with generous padding */
.layout-x5 .rarity-badges span { font-size: 32px; }
.layout-x10 .rarity-badges span { font-size: 18px; line-height: 1; letter-spacing: 1.5px; }
.layout-x10 .stars { font-size: 11px; gap: 2px; }
.layout-x5 .card-character-icon { font-size: 60px; margin: 5px 0; }
.layout-x10 .card-character-icon { font-size: 28px; margin: 2px 0; }
.layout-x5 .card-winner-title { font-size: 12px; }
.layout-x10 .card-winner-title { font-size: 8px; letter-spacing: 0.5px; opacity: 0.7; }
.layout-x5 .card-winner-name { font-size: 34px; font-weight: 900; color: #0f172a; }
.layout-x10 .card-winner-name { font-size: 28px; font-weight: 900; margin: 3px 0; line-height: 1.1; color: #0f172a; text-shadow: 0 1px 2px rgba(255,255,255,0.8); }
.layout-x5 .card-quote { font-size: 12px; }
.layout-x10 .card-quote { font-size: 8px; opacity: 0.6; margin-top: 0; }
.layout-x5 .gacha-card-front { padding: 15px; }
.layout-x10 .gacha-card-front { padding: 12px 10px; border-width: 3px; }
.layout-x10 .card-inner { gap: 2px; justify-content: space-between; }
.layout-x10 .card-meteor-icon { font-size: 48px; }
.layout-x10 .card-back-pattern span { font-size: 11px; letter-spacing: 2px; }

.rarity-badges span {
    font-family: var(--font-eng);
    font-size: 48px;
    font-weight: 900;
    letter-spacing: 3px;
}

.stars {
    font-size: 20px;
    display: flex;
    gap: 6px;
}

.card-character-icon {
    font-size: 90px; /* HUGE ICON */
    margin: 15px 0;
    filter: drop-shadow(0 0 25px var(--accent-gold-glow));
    animation: scalePulse 2s ease-in-out infinite;
}

@keyframes scalePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.card-winner-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.card-winner-name {
    font-size: 52px; /* HUGE WINNER NAME */
    font-weight: 900;
    color: #1e293b;
    text-align: center;
    text-shadow: 2px 2px 0px rgba(255,255,255,1);
    margin-bottom: 10px;
    font-family: var(--font-thai);
}

.card-quote {
    font-style: italic;
    font-weight: 600;
    color: #475569;
    font-size: 16px;
    text-align: center;
}

/* Back Face */
.gacha-card-back {
    background: linear-gradient(135deg, #4c1d95 0%, #312e81 100%);
    border: 6px solid var(--accent-cyan);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 60px rgba(0,0,0,0.6);
}

/* Sweep energy on the back of the card */
.gacha-card-back::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(0deg, transparent 0%, rgba(6, 182, 212, 0.2) 50%, transparent 100%);
    background-size: 100% 200%;
    animation: sweepEnergy 2s infinite linear;
    pointer-events: none;
}

@keyframes sweepEnergy {
    0% { background-position: 0 200%; }
    100% { background-position: 0 -200%; }
}

.card-back-pattern {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--accent-cyan);
    z-index: 2;
    text-align: center;
    width: 100%;
    padding: 10px;
}

.card-meteor-icon {
    font-size: 90px;
    filter: drop-shadow(0 0 30px var(--accent-cyan-glow));
    animation: floatBack 2s ease-in-out infinite;
}

.card-back-pattern span {
    font-family: var(--font-eng);
    font-weight: bold;
    letter-spacing: 4px;
    font-size: 16px;
    color: rgba(255,255,255,0.9);
    text-align: center;
    white-space: nowrap;
}

@keyframes floatBack {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(-5deg); }
}

.gacha-actions {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 15px;
}
.gacha-actions.hidden {
    display: none;
}
.gacha-actions .btn {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* --- WINNER OVERLAY --- */
.winner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    z-index: 99999; /* Top level above all elements */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.winner-overlay.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#confettiCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.winner-card {
    background: #ffffff;
    border: 4px solid var(--accent-pink);
    border-radius: 40px;
    padding: 50px 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    box-shadow: 
        0 30px 60px rgba(0, 0, 0, 0.15),
        0 0 80px rgba(236, 72, 153, 0.2);
    z-index: 2;
    text-align: center;
    max-width: 700px;
    width: 90%;
    animation: winnerCardPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes winnerCardPop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.winner-trophy {
    font-size: 100px;
    animation: trophyBounce 1.5s ease infinite;
}

@keyframes trophyBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.1); }
}

.winner-card h2 {
    font-size: 28px;
    color: var(--text-muted);
    font-weight: 700;
}

.winner-name-banner {
    font-size: 64px; /* HUGE TEXT FOR WINNER */
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    padding: 10px 40px;
    border-bottom: 4px dashed #e2e8f0;
    margin: 15px 0;
    word-break: break-word;
}

.winner-actions {
    display: flex;
    gap: 20px;
    margin-top: 15px;
}

/* Audio Banner Alert */
.audio-banner {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    border: none;
    border-radius: 16px;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 99;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    font-size: 16px;
    font-weight: 600;
    color: white;
}

.audio-banner.hidden {
    display: none;
}

.btn-xs {
    padding: 6px 12px;
    font-size: 14px;
    border-radius: 8px;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
}
.btn-xs:hover {
    background: white;
    color: var(--accent-purple);
}

/* Scrollbar styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.02);
}
::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        display: flex; /* Sidebar can be toggled by JS */
    }
    body {
        overflow-y: auto;
    }
    .main-content {
        height: auto;
        min-height: 800px;
    }
    .game-stage {
        min-height: 700px;
    }
    
    .gacha-summon-card-wrapper {
        padding: 20px 10px 70px 10px;
    }
    .gacha-card {
        max-width: 350px;
        max-height: 500px;
    }
    .card-winner-name {
        font-size: 36px;
    }
    .slot-name-item {
        font-size: 48px;
    }
    .winner-name-banner {
        font-size: 42px;
    }
}
