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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0d3d1a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* --- App shell: mobile stack, desktop side-by-side --- */
.app-shell {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.game-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
    background: #1a6a30;
}

#gameCanvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: default;
}

#gameCanvas.hidden {
    display: none;
}

/* --- Game controls (mobile: bottom bar) --- */
.game-ui {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.75);
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 50;
    border-radius: 12px 12px 0 0;
}

.game-ui.hidden {
    display: none;
}

.game-ui-stats {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

#scoreDisplay,
#moveCounter {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.ad-banner,
#adBanner {
    min-height: 44px;
    background: #1a5a2e;
    border-radius: 6px;
    margin: 4px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.action-buttons,
#actionButtons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.action-buttons button,
#actionButtons button {
    flex: 1;
    max-width: 120px;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: #2d8a3e;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background 0.15s, transform 0.1s;
}

.action-buttons button:hover,
#actionButtons button:hover {
    background: #3a9a4a;
}

.action-buttons button:active,
#actionButtons button:active {
    background: #1a6a30;
    transform: scale(0.98);
}

.desktop-hint {
    display: none;
    color: #8be8a0;
    font-size: 12px;
    text-align: center;
    margin-top: 10px;
    line-height: 1.4;
}

#videoad {
    position: fixed;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
}

/* --- Menus / overlays --- */
.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.menu-content {
    text-align: center;
    padding: 28px 32px;
    max-width: 360px;
    width: 90%;
    background: rgba(26, 106, 48, 0.35);
    border-radius: 16px;
    border: 1px solid rgba(139, 232, 160, 0.25);
}

.menu-content h1 {
    color: #fff;
    font-size: 28px;
    margin-bottom: 8px;
}

.menu-content h2 {
    color: #fff;
    font-size: 20px;
    margin-bottom: 12px;
}

.menu-content .subtitle {
    color: #8be8a0;
    font-size: 14px;
    margin-bottom: 20px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    background: #2d8a3e;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.menu-btn:hover {
    background: #3a9a4a;
}

.menu-btn:active {
    background: #1a6a30;
}

.continue-btn {
    background: #3a7a4a;
}

.daily-btn {
    background: #2a6a5a;
}

.cancel-btn {
    background: #666;
}

.win-overlay {
    background: rgba(0, 0, 0, 0.9);
}

.game-toast {
    position: fixed;
    left: 50%;
    bottom: max(24px, env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(12px);
    max-width: min(90vw, 360px);
    padding: 12px 18px;
    background: rgba(0, 0, 0, 0.88);
    color: #e8ffe8;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    border-radius: 10px;
    border: 1px solid rgba(139, 232, 160, 0.35);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.game-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (min-width: 768px) {
    .game-toast {
        bottom: auto;
        top: 24px;
        transform: translateX(-50%) translateY(-8px);
    }

    .game-toast.visible {
        transform: translateX(-50%) translateY(0);
    }
}

/* --- Tablet / desktop --- */
@media (min-width: 768px) {
    body {
        overflow: auto;
    }

    .app-shell {
        flex-direction: row;
        align-items: stretch;
        justify-content: center;
        gap: 0;
        max-width: 1100px;
        margin: 0 auto;
        padding: 20px;
        height: 100%;
        min-height: 100vh;
    }

    .game-stage {
        flex: 1;
        min-width: 0;
        border-radius: 14px;
        overflow: hidden;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
        border: 1px solid rgba(139, 232, 160, 0.15);
    }

    .game-ui {
        position: relative;
        width: 220px;
        flex-shrink: 0;
        margin-left: 16px;
        border-radius: 14px;
        padding: 16px;
        padding-bottom: 16px;
        border: 1px solid rgba(139, 232, 160, 0.15);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
        justify-content: flex-start;
    }

    .game-ui-stats {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 12px;
    }

    #scoreDisplay,
    #moveCounter {
        font-size: 15px;
        padding: 8px 10px;
        background: rgba(0, 0, 0, 0.25);
        border-radius: 8px;
    }

    .action-buttons,
    #actionButtons {
        flex-direction: column;
        gap: 10px;
    }

    .action-buttons button,
    #actionButtons button {
        max-width: none;
        width: 100%;
        font-size: 14px;
        min-height: 48px;
    }

    .ad-banner,
    #adBanner {
        min-height: 40px;
        margin: 12px 0;
    }

    .desktop-hint {
        display: block;
    }

    .menu-content {
        max-width: 420px;
        padding: 36px 40px;
    }

    .menu-content h1 {
        font-size: 32px;
    }

    .menu-btn {
        font-size: 17px;
        padding: 16px 24px;
    }
}

/* Large desktop: cap card area width feel */
@media (min-width: 1200px) {
    .app-shell {
        max-width: 1200px;
    }

    .game-ui {
        width: 240px;
    }
}
