/* ╔══════════════════════════════════════════════════════╗
   ║  SALA DE ESPERA — Gaming Hub CSS                    ║
   ║  ClickMenu SaaS | Mini-Games Modal                  ║
   ╚══════════════════════════════════════════════════════╝ */

/* ─── ROOT TOKENS ─── */
:root {
    --game-accent: var(--accent, #F59E0B);
    --game-accent-rgb: var(--accent-rgb, 245, 158, 11);
    --game-bg: #0a0a0f;
    --game-surface: rgba(255,255,255,0.04);
    --game-surface-hover: rgba(255,255,255,0.08);
    --game-border: rgba(255,255,255,0.08);
    --game-border-glow: rgba(var(--game-accent-rgb, 245,158,11), 0.4);
    --game-text: #f1f5f9;
    --game-muted: rgba(241,245,249,0.45);
    --game-radius: 20px;
    --game-radius-sm: 14px;
    --game-modal-z: 99999;
}

/* ─── OVERLAY ─── */
#sala-espera-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--game-modal-z);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#sala-espera-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* ─── MAIN MODAL ─── */
#sala-espera-modal {
    background: linear-gradient(145deg, #12121e 0%, #0e0e1a 100%);
    border: 1px solid var(--game-border);
    border-radius: var(--game-radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(30px) scale(0.95);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.05),
        0 30px 80px rgba(0,0,0,0.6),
        0 0 60px rgba(var(--game-accent-rgb, 245,158,11), 0.08);
    position: relative;
}

#sala-espera-overlay.open #sala-espera-modal {
    transform: translateY(0) scale(1);
}

/* ─── MODAL HEADER ─── */
.game-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--game-border);
    flex-shrink: 0;
    position: relative;
}

.game-modal-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 24px;
    right: 24px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--game-accent), transparent);
    opacity: 0.5;
}

.game-modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.game-modal-title-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--game-accent), color-mix(in srgb, var(--game-accent) 60%, #ff6b6b));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #000;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(var(--game-accent-rgb, 245,158,11), 0.35);
}

.game-modal-title h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--game-text);
    margin: 0;
    line-height: 1.2;
}

.game-modal-title p {
    font-size: 0.7rem;
    color: var(--game-muted);
    margin: 2px 0 0;
}

.game-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    color: var(--game-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.game-modal-close:hover {
    background: rgba(239,68,68,0.15);
    border-color: rgba(239,68,68,0.3);
    color: #ef4444;
    transform: rotate(90deg);
}

/* ─── GAME SELECTOR (Home Screen) ─── */
#game-selector {
    padding: 20px 24px 24px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--game-border) transparent;
}

.game-selector-subtitle {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--game-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
}

/* ─── GAMES GRID ─── */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

/* ─── GAME CARD ─── */
.game-card {
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    border-radius: var(--game-radius-sm);
    padding: 18px 14px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.game-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(var(--game-accent-rgb, 245,158,11), 0.08), transparent);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.game-card:hover::before,
.game-card:active::before {
    opacity: 1;
}

.game-card:hover {
    border-color: rgba(var(--game-accent-rgb, 245,158,11), 0.35);
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.4), 0 0 20px rgba(var(--game-accent-rgb, 245,158,11), 0.1);
}

.game-card:active {
    transform: translateY(0) scale(0.97);
}

.game-card-emoji {
    font-size: 2.4rem;
    line-height: 1;
    filter: drop-shadow(0 0 12px rgba(var(--game-accent-rgb, 245,158,11), 0.3));
    transition: transform 0.2s ease;
}

.game-card:hover .game-card-emoji {
    transform: scale(1.15);
}

.game-card-name {
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--game-text);
    line-height: 1.2;
}

.game-card-hs {
    font-size: 0.65rem;
    color: var(--game-muted);
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
    padding: 3px 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--game-border);
}

.game-card-hs i {
    color: var(--game-accent);
    font-size: 0.6rem;
}

/* ─── GAME SCREEN ─── */
#game-screen {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#game-screen.active {
    display: flex;
}

.game-screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--game-border);
    flex-shrink: 0;
    gap: 8px;
}

.game-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    border-radius: 10px;
    color: var(--game-text);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 7px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.game-back-btn:hover {
    background: var(--game-surface-hover);
    border-color: rgba(255,255,255,0.15);
}

.game-screen-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Outfit', sans-serif;
}

.game-current-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--game-text);
}

.game-score-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(var(--game-accent-rgb, 245,158,11), 0.12);
    border: 1px solid rgba(var(--game-accent-rgb, 245,158,11), 0.2);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--game-accent);
}

.game-score-badge i {
    font-size: 0.65rem;
}

/* ─── CANVAS WRAPPER ─── */
.game-canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at center, rgba(var(--game-accent-rgb, 245,158,11), 0.03) 0%, transparent 70%);
    min-height: 320px;
}

.game-canvas-wrap canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    display: block;
}

/* ─── MEMORY GAME ─── */
#memory-grid {
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

.memory-card {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.memory-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.4s cubic-bezier(0.4,0,0.2,1);
    border-radius: 10px;
}

.memory-card.flipped .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card-front,
.memory-card-back {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.memory-card-back {
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    font-size: 1.5rem;
    color: var(--game-muted);
}

.memory-card-back:hover {
    background: var(--game-surface-hover);
    border-color: rgba(var(--game-accent-rgb, 245,158,11), 0.25);
}

.memory-card-front {
    background: linear-gradient(135deg, rgba(var(--game-accent-rgb, 245,158,11), 0.15), rgba(var(--game-accent-rgb, 245,158,11), 0.05));
    border: 1px solid rgba(var(--game-accent-rgb, 245,158,11), 0.3);
    transform: rotateY(180deg);
    font-size: clamp(1.2rem, 4vw, 1.8rem);
}

.memory-card.matched .memory-card-front {
    background: linear-gradient(135deg, rgba(34,197,94,0.2), rgba(34,197,94,0.05));
    border-color: rgba(34,197,94,0.4);
    animation: matchPop 0.4s ease;
}

@keyframes matchPop {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.15); }
    100% { transform: rotateY(180deg) scale(1); }
}

/* ─── 2048 GAME ─── */
#game-2048-wrap {
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
}

#game-2048-board {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--game-border);
    border-radius: 12px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    aspect-ratio: 1;
}

.cell-2048 {
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1rem;
    transition: all 0.12s ease;
    aspect-ratio: 1;
}

/* 2048 tile colors */
.tile-2    { background: #3d2e0b; color: #fbbf24; border: 1px solid rgba(251,191,36,0.3); }
.tile-4    { background: #4a3410; color: #f59e0b; border: 1px solid rgba(245,158,11,0.3); }
.tile-8    { background: #7c3300; color: #fb923c; border: 1px solid rgba(251,146,60,0.3); }
.tile-16   { background: #7c2800; color: #f97316; border: 1px solid rgba(249,115,22,0.3); }
.tile-32   { background: #7c1d00; color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }
.tile-64   { background: #6d0b0b; color: #dc2626; font-size: 0.9rem; border: 1px solid rgba(220,38,38,0.3); }
.tile-128  { background: #5b1d8a; color: #c084fc; font-size: 0.8rem; border: 1px solid rgba(192,132,252,0.3); }
.tile-256  { background: #4c1d95; color: #a78bfa; font-size: 0.75rem; border: 1px solid rgba(167,139,250,0.3); }
.tile-512  { background: #1e3a5f; color: #60a5fa; font-size: 0.7rem; border: 1px solid rgba(96,165,250,0.3); }
.tile-1024 { background: #164e63; color: #22d3ee; font-size: 0.6rem; border: 1px solid rgba(34,211,238,0.3); }
.tile-2048 { background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; font-size: 0.55rem; box-shadow: 0 0 20px rgba(245,158,11,0.5); }

/* ─── TAP TARGET ─── */
#tap-wrap {
    width: 100%;
    height: 100%;
    position: relative;
    min-height: 280px;
}

.tap-target-circle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(var(--game-accent-rgb, 245,158,11), 0.9), rgba(var(--game-accent-rgb, 245,158,11), 0.4));
    border: 3px solid var(--game-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 0 25px rgba(var(--game-accent-rgb, 245,158,11), 0.4);
    transition: transform 0.1s ease;
    animation: tapPulse 1s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tap-target-circle:active {
    transform: scale(0.85);
}

@keyframes tapPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(var(--game-accent-rgb, 245,158,11), 0.4); }
    50% { box-shadow: 0 0 40px rgba(var(--game-accent-rgb, 245,158,11), 0.7); }
}

.tap-shrink-ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 3px solid rgba(var(--game-accent-rgb, 245,158,11), 0.3);
}

/* ─── GAME OVERLAY MESSAGES ─── */
.game-overlay-msg {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    padding: 20px;
    background: rgba(10, 10, 15, 0.4);
    backdrop-filter: blur(4px);
    border-radius: 12px;
    z-index: 10;
}

.game-overlay-msg.hidden {
    display: none;
}

.game-overlay-emoji {
    font-size: 3.5rem;
    animation: floatEmoji 2s ease-in-out infinite;
}

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

.game-overlay-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--game-text);
}

.game-overlay-sub {
    font-size: 0.8rem;
    color: var(--game-muted);
    line-height: 1.5;
}

.game-start-btn, .game-restart-btn {
    background: var(--game-accent);
    color: #000;
    border: none;
    border-radius: 12px;
    padding: 12px 28px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 4px;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.game-start-btn:hover, .game-restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(var(--game-accent-rgb, 245,158,11), 0.4);
}

.game-start-btn:active, .game-restart-btn:active {
    transform: scale(0.97);
}

/* ─── LIVE STATS ROW ─── */
.game-stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px 20px 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.game-stat-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    border-radius: 20px;
    padding: 5px 14px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--game-text);
}

.game-stat-pill i {
    color: var(--game-accent);
    font-size: 0.7rem;
}

.game-stat-value {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--game-accent);
}

/* ─── DINO STYLES ─── */
#dino-canvas {
    border-radius: 12px;
    image-rendering: pixelated;
    max-width: 100%;
}

/* ─── SNAKE STYLES ─── */
#snake-canvas {
    border-radius: 12px;
    max-width: 100%;
}

/* Mobile touch controls */
.game-touch-controls {
    display: none;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
    padding: 8px 20px 16px;
    max-width: 200px;
    margin: 0 auto;
    flex-shrink: 0;
}

@media (pointer: coarse) {
    .game-touch-controls {
        display: grid;
    }
}

.touch-btn {
    background: var(--game-surface);
    border: 1px solid var(--game-border);
    border-radius: 10px;
    color: var(--game-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    height: 42px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.touch-btn:active {
    background: rgba(var(--game-accent-rgb, 245,158,11), 0.2);
    border-color: rgba(var(--game-accent-rgb, 245,158,11), 0.4);
    color: var(--game-accent);
    transform: scale(0.93);
}

.touch-up    { grid-column: 2; grid-row: 1; }
.touch-left  { grid-column: 1; grid-row: 2; }
.touch-down  { grid-column: 2; grid-row: 2; }
.touch-right { grid-column: 3; grid-row: 2; }

/* ─── SALA ESPERA BUTTON (navbar) ─── */
.sala-espera-btn {
    position: relative;
    overflow: visible;
}

.sala-espera-btn::after {
    content: 'NUEVO';
    position: absolute;
    top: -6px;
    right: 0px;
    background: #ef4444;
    color: #fff;
    font-size: 0.45rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 6px;
    letter-spacing: 0.05em;
    animation: newBadge 2s ease-in-out infinite;
}

@keyframes newBadge {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

/* ─── LINK.PHP BUTTON (button element reset) ─── */
button.lt-btn {
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: inherit;
    background: var(--lt-card);
    border: 1px solid var(--lt-border);
    color: var(--lt-text);
}

.lt-btn-games .lt-btn-icon {
    background: rgba(139, 92, 246, 0.15) !important;
    color: #a78bfa !important;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 480px) {
    #sala-espera-overlay {
        padding: 0;
        align-items: flex-start; /* Avoids centering pushing the header out of screen */
    }

    #sala-espera-modal {
        max-width: 100%;
        width: 100%;
        height: 100%; /* More reliable than 100vh on mobile Safari */
        max-height: 100%;
        border-radius: 0;
        border: none;
        transform: translateY(100%);
    }

    #sala-espera-overlay.open #sala-espera-modal {
        transform: translateY(0);
    }

    .game-modal-header {
        padding: 16px 20px 14px;
    }

    #game-selector {
        padding: 16px 16px 20px;
    }

    .games-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .game-card {
        padding: 14px 10px 12px;
        gap: 8px;
    }

    .game-card-emoji {
        font-size: 2rem;
    }

    .game-card-name {
        font-size: 0.75rem;
    }

    .game-card-hs {
        font-size: 0.6rem;
    }

    .game-canvas-wrap {
        padding: 10px;
        min-height: 240px;
    }

    #game-2048-wrap {
        max-width: 290px;
    }

    .cell-2048 {
        font-size: 0.85rem;
    }

    .tile-128, .tile-256 { font-size: 0.7rem; }
    .tile-512, .tile-1024 { font-size: 0.6rem; }
    .tile-2048 { font-size: 0.5rem; }
}

@media (max-width: 360px) {
    .games-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .game-card-emoji {
        font-size: 1.8rem;
    }

    #game-2048-wrap {
        max-width: 260px;
    }

    .cell-2048 {
        font-size: 0.75rem;
    }
}

/* (Removed Drag Indicator) */
/* ─── SCROLLBAR ─── */
#game-selector::-webkit-scrollbar {
    width: 4px;
}

#game-selector::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

/* ─── VICTORY SPARKLE ─── */
.sparkle {
    position: absolute;
    pointer-events: none;
    font-size: 1.5rem;
    animation: sparkleAnim 0.8s ease forwards;
    z-index: 20;
}

@keyframes sparkleAnim {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-60px) scale(0.3); opacity: 0; }
}

/* ─── SCORE POPUP ─── */
.score-pop {
    position: absolute;
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--game-accent);
    pointer-events: none;
    animation: scorePopAnim 0.7s ease forwards;
    z-index: 20;
    text-shadow: 0 0 10px rgba(var(--game-accent-rgb, 245,158,11), 0.6);
}

@keyframes scorePopAnim {
    0% { transform: translateY(0) scale(0.5); opacity: 0; }
    30% { transform: translateY(-10px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-40px) scale(0.8); opacity: 0; }
}

/* ─── DESKTOP ENHANCEMENTS ─── */
@media (min-width: 768px) {
    #sala-espera-modal {
        max-width: 800px;
        height: 85vh;
        max-height: 900px;
    }
    
    .games-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 16px;
    }

    .game-canvas-wrap {
        min-height: 500px;
    }
}
