:root {
    --primary: #ff6b81;
    --primary-dark: #fa556c;
    --background: #fbf1ef;
    --surface: #ffffff;
    --text-main: #3d3b3c;
    --text-light: #7a7677;
    --board-bg: #e6cec8;
    --cell-bg: #f8e9e4;
    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-premium: 0 15px 45px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 100px;
    /* Space for the sticky ad */
}

h1,
h2,
h3,
.logo {
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.02em;
}

header {
    width: 100%;
    padding: 15px 5%;
    background: var(--surface);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-soft);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    cursor: pointer;
}

nav a {
    text-decoration: none;
    color: var(--text-light);
    margin-left: 20px;
    font-weight: 600;
    transition: all 0.2s;
}

nav a:hover {
    color: var(--primary);
}

/* LAYOUT SYSTEM */
.layout-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 20px;
    gap: 40px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 600px;
}

.sidebar {
    width: 160px;
    display: block;
    position: sticky;
    top: 100px;
}

/* AD SLOT GLOBAL ENGINE */
.ad-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    overflow: visible;
    text-align: center;
}

.ad-slot iframe {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

.ad-slot-sidebar {
    width: 160px;
    min-height: 600px;
}

.ad-slot-top-full {
    width: 100%;
    margin-bottom: 30px;
    min-height: 90px;
}

.ad-slot-middle {
    width: 90%;
    margin: 60px auto;
    border-radius: 20px;
    padding: 30px 20px;
    background: var(--surface);
    box-shadow: var(--shadow-premium);
    border: 2px solid #f0f0f0;
}

.ad-slot-native-inline {
    width: 100%;
    margin: 50px auto;
}

/* In-ARTICLE AND BANNER AD SLOTS */
.ad-slot-banner-middle {
    width: 100%;
    margin: 25px 0;
    min-height: 60px;
    display: flex;
    justify-content: center;
}

.ad-slot-content {
    width: 100%;
    min-height: 250px;
    margin: 30px 0;
    background: #fdfdfd;
    border: 1px dashed #ddd;
    /* Subtle placeholder for Adsense */
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    color: #bbb;
}

.ad-placeholder {
    display: block;
    padding: 10px;
}

/* GAME UI */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 25px;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
}

.scores-container {
    display: flex;
    gap: 12px;
}

.score-box {
    background: var(--surface);
    padding: 12px 18px;
    border-radius: 14px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    min-width: 95px;
}

.score-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-light);
    text-transform: uppercase;
}

#score,
#best-score {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-main);
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(255, 107, 129, 0.3);
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 129, 0.4);
}

/* BOARD SYSTEM */
.board-wrapper {
    position: relative;
    background: var(--board-bg);
    border-radius: 18px;
    padding: 15px;
    margin: 0 auto 30px;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    grid-gap: 14px;
    width: 100%;
    height: 100%;
}

.tile {
    background: var(--cell-bg);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: min(3.8rem, 9vw);
    transition: transform 0.1s ease, background 0.2s;
    user-select: none;
    width: 100%;
    height: 100%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.04);
}


/* Animations */
@keyframes pop {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes merge {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.tile-new {
    animation: pop 0.2s ease;
}

.tile-merged {
    animation: merge 0.2s ease;
}

/* Overlay */
.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(251, 241, 239, 0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    z-index: 10;
}

.game-message p {
    font-size: 3rem;
    margin-bottom: 20px;
    font-weight: 900;
    color: var(--primary);
}

/* SEO Content Area */
.seo-content {
    background: var(--surface);
    padding: 30px;
    border-radius: 16px;
    margin-top: 40px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    width: 100%;
}

/* When seo-content is a direct body child — center it like a proper column */
.seo-content-outer {
    width: 90%;
    max-width: 860px;
    margin: 0 auto 50px auto;
    margin-top: 0;
}

.seo-content h2 {
    margin: 30px 0 15px;
    color: var(--primary);
}

.seo-content p,
.seo-content ul {
    line-height: 1.8;
    margin-bottom: 15px;
    color: #555;
}

.seo-content ul {
    padding-left: 20px;
}

.strategy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.strategy-card {
    background: var(--background);
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.strategy-card h3 {
    margin-bottom: 10px;
    font-size: 1.1rem;
}

footer {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 40px;
}

/* Responsive Ad optimizations */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }

    .layout-container {
        margin: 15px auto;
        padding: 0 15px;
    }
}

@media (max-width: 650px) {
    header {
        padding: 12px 15px;
    }

    nav {
        display: none;
    }

    h1 {
        font-size: 2.2rem;
    }

    .score-box {
        min-width: 80px;
        padding: 8px 12px;
    }

    #score,
    #best-score {
        font-size: 1.3rem;
    }

    .board-wrapper {
        padding: 10px;
        border-radius: 14px;
    }

    .game-board {
        grid-gap: 8px;
    }

    .tile {
        font-size: min(2.8rem, 10vw);
    }
}

/* Universal Sticky Bottom Ad — Premium View */
.ad-slot-sticky-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 90px;
    z-index: 999;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
}

.ad-slot-sticky-bottom>div {
    margin: 0 auto !important;
    display: flex;
    justify-content: center;
}

.close-ad-btn {
    position: absolute;
    top: -12px;
    right: 15px;
    background: #fff;
    color: #333;
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    font-family: inherit;
    font-weight: bold;
}

.close-ad-btn:hover {
    background: #ffe0e6;
    color: #ff6b81;
    border-color: #ff6b81;
}

body {
    padding-bottom: 100px;
    /* Space for the sticky ad */
}

/* Interstitial Game-Over Popup Ad */
.popup-overlay {
    display: none;
    /* Initially hidden */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 9999;
    /* Ensure it's above everything */
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.popup-overlay.active {
    display: flex;
    opacity: 1;
}

.popup-content {
    background: #fff;
    padding: 40px 20px 30px;
    border-radius: 20px;
    max-width: 400px;
    width: 90%;
    position: relative;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: popupScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popupScale {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.close-popup-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    color: #666;
}

.close-popup-btn:hover {
    background: #ff6b81;
    color: #fff;
}

.popup-ad-slot {
    margin: 20px auto;
    width: 300px;
    height: 250px;
    background: #f9f9f9;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    overflow: hidden;
}

.popup-content p {
    margin: 20px 0;
    color: #444;
    font-size: 1.1rem;
    font-weight: 600;
}

#popup-retry-btn {
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
    border-radius: 10px;
}