/* Tile Match Playable Ad Stylesheet */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Lilita+One&family=Outfit:wght@400;600;800&display=swap');

/* Global: prevent all drag ghosts and long-press image saves */
img, .game-tile, .tile-content, .tile-icon {
    -webkit-user-drag: none;
    -moz-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

/* Restore pointer-events for interactive tile wrappers */
.game-tile {
    pointer-events: auto;
}

:root {
    --bg-color: #55b2e8;
}

body {
    font-family: 'Fredoka', 'Outfit', system-ui, -apple-system, sans-serif;
    overscroll-behavior-y: none;
    touch-action: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    background-color: #55b2e8;
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.25) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.15) 0%, transparent 40%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6zM36 4V0h-2v4h-4v2h4v4h2V6h4V4h-4z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    cursor: auto;
    position: relative;
}

#app {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

/* Header with Safe Margins & Tight Vertical Gap */
.app-header {
    background-color: transparent;
    padding-top: 10px;
    padding-bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    flex-shrink: 0;
    width: 100%;
}

.header-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 360px;
    padding: 0 16px; /* Safe margin so UI never touches screen borders */
    gap: 6px;
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

/* Compact Timer Pill */
.timer-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    background-color: #ffffff;
    border: 2.5px solid #991b1b;
    border-radius: 9999px;
    height: 38px;
    width: 110px;
    padding-right: 1rem;
    font-family: 'Fredoka', 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    color: #000000;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-sizing: border-box;
    flex-shrink: 0;
}

.timer-icon {
    position: absolute;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    object-fit: contain;
}

.timer-pill.warning {
    color: #ef4444 !important;
    border-color: #ef4444 !important;
    animation: timerPulseRed 0.5s infinite alternate;
}

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

.progress-bar-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.progress-track {
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid #cbd5e1;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    border-radius: 9999px;
    height: 12px;
    overflow: hidden;
    width: 100%;
}

.progress-fill {
    background: linear-gradient(90deg, #10b981, #059669);
    height: 100%;
    border-radius: 9999px;
    transition: width 0.4s ease-out;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.4);
    padding: 0 0.2rem;
}

/* Board Viewport */
#board-viewport {
    flex: 1;
    position: relative;
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    box-sizing: border-box;
}

#board {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    transform-origin: center center;
    pointer-events: auto;
}

/* App Footer Layout: Brown Tray Plate above, CTA Button underneath */
.app-footer {
    flex-shrink: 0;
    padding: 4px 12px max(12px, env(safe-area-inset-bottom)) 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    z-index: 50;
    width: 100%;
    box-sizing: border-box;
}

.tray-container {
    width: fit-content;
    max-width: min(92vw, 340px);
    height: clamp(48px, 11vw, 60px);
    background-color: #5d3a1a;
    border-radius: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    gap: 5px;
    border-top: 4px solid #8b5e34;
    border-bottom: 3px solid #3e2711;
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
    box-sizing: border-box;
    margin: 0 auto;
}

.tray-slot {
    width: clamp(32px, 8vw, 42px);
    height: clamp(32px, 8vw, 42px);
    aspect-ratio: 1 / 1;
    background: rgba(0,0,0,0.3);
    border-radius: 10px;
    box-shadow: 
        inset 0 3px 8px rgba(0,0,0,0.45),
        inset 0 -1px 0 rgba(255,255,255,0.12);
    box-sizing: border-box;
    flex-shrink: 0;
}

.cta-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 2px;
    flex-shrink: 0;
}

.btn-play-img {
    max-width: min(65vw, 165px);
    max-height: clamp(34px, 7vh, 50px);
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: pointer;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-play-img:hover {
    transform: scale(1.05);
}

.btn-play-img:active {
    transform: scale(0.95);
}

.cta-pulse {
    animation: ctaPulse 1.6s infinite alternate ease-in-out;
}

@keyframes ctaPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.06); }
}

/* Game Tiles */
.game-tile {
    position: absolute;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center center;
    will-change: transform, left, top, width, height;
    cursor: pointer;
}

.tile-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #ffffff 0%, #f0f0f0 100%);
    border-radius: 22%; 
    border: 2px solid #fff;
    box-shadow: 
        inset 0 2px 0 rgba(255,255,255,0.8),
        inset 0 -2px 5px rgba(0,0,0,0.05),
        0 12px 0 #bebebe, 
        0 13px 0 1px #999,
        0 18px 24px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}

.game-tile.clickable:active .tile-content {
    transform: translateY(10px);
    box-shadow: 
        inset 0 1px 0 rgba(255,255,255,0.8),
        0 2px 0 #bebebe, 
        0 2px 0 1px #999, 
        0 4px 8px rgba(0,0,0,0.15);
}

.game-tile.obscured .tile-content {
    background: #d4d4d8;
    border-color: #cbd5e1;
    box-shadow: 
        0 8px 0 #94a3b8,
        0 8px 0 1px #64748b,
        0 10px 12px rgba(0,0,0,0.2);
    transform: translateY(4px);
    filter: grayscale(0.6) brightness(0.8);
}

.tile-icon {
    width: 85%;
    height: 85%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
    object-fit: contain;
}

.game-tile.matched {
    transform: scale(0) rotate(45deg) !important;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.6, -0.28, 0.735, 0.045);
}

/* Particle System */
#particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.particle {
    position: absolute;
    pointer-events: none;
    will-change: transform, opacity;
}

/* Guiding Hand */
.guide-hand {
    position: fixed;
    z-index: 999999;
    pointer-events: none;
    transition: opacity 0.3s ease;
    opacity: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    transform: translate(-50%, -50%);
}

.guide-hand.hidden {
    display: none !important;
    opacity: 0 !important;
}

.guide-hand img {
    width: clamp(38px, 9vw, 50px);
    height: auto;
    position: relative;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

.guide-hand.pulse {
    animation: tapPulse 1.2s infinite ease-in-out;
}

@keyframes tapPulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(0.85); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* Red Fog Vignette on Lose/Warning */
.lose-fog-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    box-shadow: inset 0 0 0px rgba(239, 68, 68, 0);
    transition: box-shadow 1.5s ease-in-out;
}

.lose-fog-overlay.active {
    box-shadow: inset 0 0 80px rgba(239, 68, 68, 0.85), inset 0 0 40px rgba(239, 68, 68, 0.65);
    animation: fogPulse 2.5s infinite alternate ease-in-out;
}

@keyframes fogPulse {
    0% {
        box-shadow: inset 0 0 60px rgba(239, 68, 68, 0.7), inset 0 0 30px rgba(239, 68, 68, 0.5);
    }
    100% {
        box-shadow: inset 0 0 100px rgba(239, 68, 68, 0.95), inset 0 0 50px rgba(239, 68, 68, 0.75);
    }
}

/* Badge Overlay & Custom Graphics */
.badge-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 165, 233, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.badge-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.badge-img-graphic {
    max-width: min(85vw, 340px);
    height: auto;
    opacity: 0;
    pointer-events: none;
}

.badge-overlay.visible #win-badge-img:not(.hidden) {
    animation: winBadgePop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, winBadgeHover 2s ease-in-out 0.8s infinite alternate;
}

@keyframes winBadgePop {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-15deg);
    }
    60% {
        opacity: 1;
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
        filter: drop-shadow(0 15px 30px rgba(255, 215, 0, 0.45));
    }
}

@keyframes winBadgeHover {
    0% {
        transform: scale(1) translateY(0);
        filter: drop-shadow(0 15px 30px rgba(255, 215, 0, 0.45));
    }
    100% {
        transform: scale(1.03) translateY(-8px);
        filter: drop-shadow(0 25px 40px rgba(255, 215, 0, 0.7));
    }
}

.badge-overlay.visible #lose-badge-img:not(.hidden) {
    animation: loseBadgeDrop 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards, loseBadgeShake 4s ease-in-out 0.8s infinite;
}

@keyframes loseBadgeDrop {
    0% {
        opacity: 0;
        transform: translateY(-80px) scale(0.9) rotate(10deg);
    }
    50% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(-5deg);
    }
    75% {
        transform: translateY(-12px) scale(1.02) rotate(2deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0deg);
        filter: drop-shadow(0 15px 30px rgba(239, 68, 68, 0.4));
    }
}

@keyframes loseBadgeShake {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    5% {
        transform: translateY(3px) rotate(-2deg);
    }
    10% {
        transform: translateY(-3px) rotate(2deg);
    }
    15% {
        transform: translateY(3px) rotate(-2deg);
    }
    20% {
        transform: translateY(0) rotate(0deg);
    }
}

/* Minimalist PlayableADGame Style End Screen */
.end-screen {
    position: fixed;
    inset: 0;
    background-color: rgba(14, 165, 233, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    z-index: 999999;
    transition: opacity 0.6s ease-in-out;
    text-align: center;
    cursor: pointer;
}

.end-screen.hidden {
    display: none;
    opacity: 0;
}

.simple-end-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    animation: simplePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes simplePop {
    0% {
        transform: scale(0.6);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.game-logo-text {
    font-family: 'Lilita One', 'Outfit', sans-serif;
    font-size: 3.5rem;
    font-weight: 900;
    color: #ffffff;
    letter-spacing: 0.04em;
    text-shadow: 
        0 4px 0 #0284c7,
        0 8px 0 #0369a1,
        0 12px 24px rgba(0, 0, 0, 0.4);
    line-height: 1;
}

.game-logo-sub {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: #bae6fd;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin: 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}
