/* ==========================================================================
   2048 Cupcakes Deluxe Edition - Modern all2048.com/cupcakes Stylesheet
   Pastel bakery styling, authentic gourmet cupcake PNGs, calorie counter & cookbook
   ========================================================================== */

/* Theme Container */
.g2048-wrapper.theme-bakery {
    --bakery-bg: #fff6ee;
    --bakery-surface: #ffffff;
    --bakery-border: #f2d9c8;
    --bakery-accent: #ff6b8b;
    --bakery-accent-light: #ffe3ea;
    --bakery-text: #4a2e2b;
    --bakery-gold: #f59e0b;
    max-width: 530px;
    margin: 0 auto;
}

/* Header & Intro */
.theme-bakery .g2048-badge {
    background: linear-gradient(135deg, #ff758c 0%, #ff7eb3 100%);
    color: #ffffff;
    border: none;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(255, 117, 140, 0.35);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
}

.theme-bakery .cupcake-intro-banner {
    margin: 0.2rem 0 0.8rem;
    text-align: center;
    font-size: clamp(1rem, 2.8vw, 1.25rem);
    color: #5a3d36;
    font-weight: 600;
}

.theme-bakery .cupcake-intro-banner strong {
    color: #e04b73;
    font-weight: 800;
}

/* Header (Badge + Score Cards) positioned right above board */
.theme-bakery .g2048-header {
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

/* Toolbar positioned directly below the board */
.theme-bakery .g2048-toolbar {
    margin-top: 0.85rem;
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* Hints below the toolbar */
.theme-bakery .g2048-mobile-hints {
    margin-top: 0.4rem;
}

/* Bakery Score Cards */
.theme-bakery .score-card {
    background: #ffffff;
    border: 2px solid #f6ded0;
    box-shadow: 0 4px 12px rgba(220, 160, 140, 0.12);
    border-radius: 12px;
}

.theme-bakery .score-card.calorie-card {
    border-color: #ffd6e0;
    background: linear-gradient(180deg, #ffffff 0%, #fff7f9 100%);
}

.theme-bakery .score-card.calorie-card .score-label {
    color: #e04b73;
}

.theme-bakery .score-card.calorie-card .score-val {
    color: #c9184a;
    font-weight: 900;
}

/* Board Styling with Touch Action and Overscroll Prevention */
.theme-bakery .g2048-board-container {
    background: #f7e6db !important;
    border: 6px solid #edd5c5 !important;
    border-radius: 18px !important;
    box-shadow: 0 10px 30px rgba(180, 130, 110, 0.18), inset 0 2px 8px rgba(0, 0, 0, 0.05);
    touch-action: none !important;
    overscroll-behavior: contain !important;
    -webkit-user-select: none;
    user-select: none;
}

.theme-bakery .grid-cell {
    background: rgba(255, 255, 255, 0.6) !important;
    border-radius: 12px !important;
    box-shadow: inset 0 2px 4px rgba(180, 130, 110, 0.1);
}

/* Cupcake Tile Inner */
.theme-bakery .cupcake-tile-inner {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 4px 10px rgba(180, 130, 110, 0.15);
    background: #ffffff;
    border: 2px solid rgba(255, 117, 140, 0.25);
    transition: transform 0.12s ease;
}

/* Cupcake Artwork Image */
.theme-bakery .cupcake-art-img {
    position: absolute;
    inset: 0;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 85% 85%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.12));
    z-index: 1;
}

/* Badges and Labels */
.theme-bakery .cupcake-badge-strip {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 6px;
    font-size: clamp(0.58rem, 1.7vw, 0.72rem);
    font-weight: 800;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.theme-bakery .cupcake-kcal-pill {
    background: #ffe3ea;
    color: #c9184a;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 800;
}

.theme-bakery .cupcake-val-pill {
    background: rgba(255, 255, 255, 0.9);
    color: #4a2e2b;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 900;
    font-size: 0.68rem;
}

.theme-bakery .cupcake-title-bar {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2px 4px;
    font-size: clamp(0.6rem, 1.8vw, 0.72rem);
    font-weight: 800;
    color: #4a2e2b;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(2px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

/* When labels are hidden (clean tiles: hide name and kcal, keep numeric badge at bottom-right) */
.theme-bakery.labels-hidden .cupcake-title-bar,
.theme-bakery.labels-hidden .cupcake-kcal-pill {
    display: none !important;
}

.theme-bakery.labels-hidden .cupcake-badge-strip {
    position: absolute;
    inset: 0;
    padding: 0;
    pointer-events: none;
    display: block !important;
    z-index: 3;
}

.theme-bakery.labels-hidden .cupcake-val-pill {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: rgba(15, 23, 42, 0.78);
    color: #ffffff;
    font-size: clamp(0.62rem, 2vw, 0.72rem);
    font-weight: 900;
    padding: 2px 5px;
    border-radius: 5px;
    line-height: 1;
    backdrop-filter: blur(2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 4;
}

.theme-bakery.labels-hidden .cupcake-art-img {
    background-size: 88% 88% !important;
}

/* Individual Tile Glow & Palettes */
.theme-bakery .tile-2 .cupcake-tile-inner { background: #fffbf5; border-color: #ffe8d6; }
.theme-bakery .tile-4 .cupcake-tile-inner { background: #fff5f7; border-color: #ffd6e0; }
.theme-bakery .tile-8 .cupcake-tile-inner { background: #fffcf0; border-color: #ffeedb; }
.theme-bakery .tile-16 .cupcake-tile-inner { background: #f5fbf7; border-color: #d1fae5; }
.theme-bakery .tile-32 .cupcake-tile-inner { background: #fff5f5; border-color: #fed7aa; }
.theme-bakery .tile-64 .cupcake-tile-inner { background: #f5f3ff; border-color: #e9d5ff; }
.theme-bakery .tile-128 .cupcake-tile-inner { background: #fefce8; border-color: #fef08a; }
.theme-bakery .tile-256 .cupcake-tile-inner { background: #fff1f2; border-color: #fecdd3; }
.theme-bakery .tile-512 .cupcake-tile-inner { background: #fdf4ff; border-color: #f5d0fe; }
.theme-bakery .tile-1024 .cupcake-tile-inner { background: #f0fdf4; border-color: #bbf7d0; box-shadow: 0 0 15px rgba(245, 158, 11, 0.25); }
.theme-bakery .tile-2048 .cupcake-tile-inner {
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    border-color: #f59e0b;
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.45);
    animation: cupcake-crown-pulse 2s infinite ease-in-out;
}
.theme-bakery .tile-4096 .cupcake-tile-inner,
.theme-bakery .tile-8192 .cupcake-tile-inner,
.theme-bakery .tile-super .cupcake-tile-inner {
    background: linear-gradient(135deg, #fdf4ff 0%, #fae8ff 100%);
    border-color: #c084fc;
    box-shadow: 0 0 30px rgba(192, 132, 252, 0.5);
}

@keyframes cupcake-crown-pulse {
    0%, 100% { box-shadow: 0 0 20px 4px rgba(245, 158, 11, 0.4); }
    50% { box-shadow: 0 0 35px 10px rgba(255, 117, 140, 0.6); }
}

/* Pastry Book Modal */
.pastry-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(74, 46, 43, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.pastry-modal-backdrop.is-open {
    display: flex;
}

.pastry-modal {
    background: #ffffff;
    color: #4a2e2b;
    width: 100%;
    max-width: 580px;
    max-height: 85vh;
    border-radius: 18px;
    border: 4px solid #ff758c;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    padding: 1.5rem;
}

.pastry-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #f6ded0;
    padding-bottom: 0.8rem;
    margin-bottom: 1rem;
}

.pastry-modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
    color: #e04b73;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pastry-modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    color: #8b5e56;
    line-height: 1;
    padding: 0 0.3rem;
}

.pastry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
    gap: 0.75rem;
}

.pastry-item {
    background: #fffcf9;
    border: 1.5px solid #f6ded0;
    border-radius: 12px;
    padding: 0.6rem 0.4rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.15s ease;
}

.pastry-item:hover {
    transform: translateY(-2px);
    border-color: #ff758c;
    background: #fff5f7;
}

.pastry-item img {
    width: 65px;
    height: 65px;
    object-fit: contain;
    margin-bottom: 0.25rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}

.pastry-item .pastry-item-name {
    font-size: 0.8rem;
    font-weight: 800;
    color: #4a2e2b;
    margin: 2px 0;
}

.pastry-item .pastry-item-kcal {
    font-size: 0.7rem;
    font-weight: 800;
    color: #c9184a;
    background: #ffe3ea;
    padding: 1px 6px;
    border-radius: 999px;
}

.pastry-item .pastry-item-val {
    font-size: 0.72rem;
    font-weight: 900;
    color: #f59e0b;
    margin-top: 2px;
}

/* ==========================================================================
   Dark Mode Overrides for 2048 Cupcakes
   ========================================================================== */
[data-theme="dark"] .g2048-wrapper.theme-bakery {
    --bakery-bg: #0b1328;
    --bakery-surface: #1e293b;
    --bakery-border: #334155;
    --bakery-text: #f8fafc;
}

[data-theme="dark"] .theme-bakery .cupcake-intro-banner {
    color: #cbd5e1;
}

[data-theme="dark"] .theme-bakery .cupcake-intro-banner strong {
    color: #ff758c;
}

/* Fix Dark Mode Score Cards (SCORE & BEST: #1E293B background with bright high-contrast text) */
[data-theme="dark"] .theme-bakery .score-card {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .theme-bakery .score-card .score-label {
    color: #94a3b8 !important;
    font-weight: 700;
}

[data-theme="dark"] .theme-bakery .score-card.current-score .score-val,
[data-theme="dark"] .theme-bakery .score-card.best-score .score-val {
    color: #f8fafc !important;
    font-weight: 900;
}

/* Calorie Card in Dark Mode */
[data-theme="dark"] .theme-bakery .score-card.calorie-card {
    background: linear-gradient(180deg, #1e293b 0%, #2a1b28 100%) !important;
    border: 1px solid #f43f5e !important;
}

[data-theme="dark"] .theme-bakery .score-card.calorie-card .score-label {
    color: #fb7185 !important;
    font-weight: 800;
}

[data-theme="dark"] .theme-bakery .score-card.calorie-card .score-val {
    color: #fda4af !important;
    font-weight: 900;
}

[data-theme="dark"] .theme-bakery .g2048-board-container {
    background: #0f172a !important;
    border: 5px solid #1e293b !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), inset 0 2px 8px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .theme-bakery .grid-cell {
    background: rgba(30, 41, 59, 0.75) !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4) !important;
}

/* Modal Dark Mode */
[data-theme="dark"] .pastry-modal {
    background: #0f172a;
    color: #f8fafc;
    border-color: #f43f5e;
}

[data-theme="dark"] .pastry-modal-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .pastry-item {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .pastry-item:hover {
    background: #334155;
    border-color: #f43f5e;
}

[data-theme="dark"] .pastry-item .pastry-item-name {
    color: #f8fafc;
}

[data-theme="dark"] .pastry-item .pastry-item-kcal {
    background: rgba(244, 63, 94, 0.2);
    color: #fda4af;
}

/* ==========================================================================
   Mobile Responsive Layout (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Reorder Sections so Board sits cleanly in the center of the mobile viewport */
    .g2048-wrapper.theme-bakery {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        padding: 0 0.25rem;
    }

    /* Intro banner sits above stats compactly */
    .theme-bakery .cupcake-intro-banner {
        order: 1;
        font-size: 0.82rem;
        margin: 0.15rem 0 0.4rem;
        line-height: 1.35;
        max-width: 440px;
        padding: 0 0.5rem;
    }

    /* Move top stats/badge section (Section 1) down to Section 2 (right above the board) */
    .theme-bakery .g2048-header {
        order: 2;
        width: 100%;
        max-width: 440px;
        margin-bottom: 0.5rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.45rem;
    }

    .theme-bakery .g2048-title-area {
        flex-shrink: 0;
    }

    .theme-bakery .g2048-badge {
        font-size: 0.72rem;
        padding: 0.28rem 0.65rem;
        white-space: nowrap;
    }

    .theme-bakery .g2048-scores {
        gap: 0.35rem;
        flex: 1;
        justify-content: flex-end;
    }

    .theme-bakery .score-card {
        min-width: 0;
        flex: 1;
        padding: 0.3rem 0.35rem;
        border-radius: 9px;
    }

    .theme-bakery .score-label {
        font-size: 0.58rem;
    }

    .theme-bakery .score-val {
        font-size: 1.05rem;
    }

    /* 4x4 Game Grid cleanly centered in viewport */
    .theme-bakery .g2048-board-container {
        order: 3;
        width: 100%;
        max-width: min(92vw, 420px);
        margin: 0 auto 0.55rem;
        touch-action: none !important;
        overscroll-behavior: contain !important;
        border-width: 4px !important;
        border-radius: 14px !important;
    }

    /* Move action buttons bar from Section 2 to Section 3 (below the game board) */
    .theme-bakery .g2048-toolbar {
        order: 4;
        width: 100%;
        max-width: min(92vw, 420px);
        margin: 0.2rem auto 0.45rem;
        display: flex;
        justify-content: space-between;
        gap: 0.35rem;
    }

    .theme-bakery .btn-game-tool {
        padding: 0.45rem 0.3rem;
        font-size: 0.78rem;
        border-radius: 8px;
        gap: 0.25rem;
    }

    .theme-bakery .btn-game-tool svg {
        width: 15px;
        height: 15px;
    }

    /* Hints banner at bottom */
    .theme-bakery .g2048-mobile-hints {
        order: 5;
        margin-top: 0.15rem;
        margin-bottom: 0.5rem;
        font-size: 0.8rem;
        padding: 0.45rem 0.75rem;
        max-width: min(92vw, 420px);
    }

    /* 3. Clean Mobile Tiles: Hide text name & kcal label, cupcake artwork fills tile cleanly with small right-down corner numeric badge */
    .theme-bakery .cupcake-title-bar,
    .theme-bakery .cupcake-kcal-pill {
        display: none !important;
    }

    .theme-bakery .cupcake-badge-strip {
        position: absolute;
        inset: 0;
        padding: 0;
        pointer-events: none;
        display: block !important;
        z-index: 3;
    }

    .theme-bakery .cupcake-val-pill {
        position: absolute;
        bottom: 4px;
        right: 4px;
        background: rgba(15, 23, 42, 0.78);
        color: #ffffff;
        font-size: clamp(0.6rem, 2.2vw, 0.72rem);
        font-weight: 900;
        padding: 2px 5px;
        border-radius: 5px;
        line-height: 1;
        backdrop-filter: blur(2px);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
        border: 1px solid rgba(255, 255, 255, 0.2);
        z-index: 4;
    }

    .theme-bakery .cupcake-art-img {
        background-size: 88% 88% !important;
    }
}

@media (max-width: 411px) {
    .theme-bakery .g2048-header { flex-wrap: wrap; justify-content: center; row-gap: 0.45rem; }
    .theme-bakery .g2048-title-area { flex: 0 1 auto; max-width: 100%; display: flex; justify-content: center; }
    .theme-bakery .g2048-badge { max-width: 100%; }
    .theme-bakery .g2048-scores { flex: 1 1 100%; min-width: 0; width: 100%; justify-content: space-between; }
    .theme-bakery .score-card { flex: 1 1 0; min-width: 0; }
}