* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    cursor: url('assets/cursor_paw.png') 38 38, auto;
}
*::selection { background: transparent; }
*::-moz-selection { background: transparent; }

img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif;
    background: #5c3d2e;
    position: fixed;
    top: 0; left: 0;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: none;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ========== MENU ========== */
#menu-screen {
    background: url('assets/bg_menu.png') center/cover no-repeat;
    background-color: #faf5ef;
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.menu-btn:active { transform: scale(0.9); }
.menu-btn img {
    width: 80px;
    height: auto;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,0.2));
}
.menu-btn.play-main img {
    width: 288px;
    filter: drop-shadow(0 6px 16px rgba(0,0,0,0.25));
    animation: bounce 2s ease-in-out infinite;
}

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

.menu-title {
    font-size: 46px;
    color: #8B5E3C;
    text-shadow: 0 3px 6px rgba(0,0,0,0.15);
    letter-spacing: 2px;
    font-weight: 900;
}

.menu-best-score {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.7);
    padding: 12px 38px;
    border-radius: 40px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.star-icon { width: 51px; height: 51px; object-fit: contain; }
.menu-best-score span { font-size: 38px; font-weight: 800; color: #C27530; }

/* Language toggle */
.lang-btn {
    background: rgba(139, 94, 60, 0.15);
    border: 2px solid rgba(139, 94, 60, 0.3);
    color: #8B5E3C;
    font-size: 18px;
    font-weight: 800;
    padding: 8px 24px;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s;
    letter-spacing: 1px;
}
.lang-btn:hover { background: rgba(139, 94, 60, 0.25); }
.lang-btn:active { transform: scale(0.9); }

/* Pause button */
.pause-btn {
    border: none;
    cursor: pointer;
    transition: transform 0.15s;
    padding: 4px 12px !important;
}
.pause-btn:active { transform: scale(0.9); }
.pause-icon {
    font-size: 22px;
    line-height: 1;
    color: #fff;
}

/* ========== HELPER CAT ========== */
#helper {
    position: fixed;
    bottom: 10px;
    right: 5px;
    z-index: 50;
    pointer-events: none;
    transition: opacity 0.4s, transform 0.4s;
}
#helper.hidden {
    opacity: 0;
    transform: translateY(30px);
    pointer-events: none;
}
#helper-cat-wrap {
    position: relative;
    display: inline-block;
}
#helper-body {
    width: 326px;
    height: auto;
    display: block;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.2));
}
#helper-paw {
    width: 93px;
    height: auto;
    position: absolute;
    top: 32%;
    left: 30px;
    transform-origin: 85% 95%;
    animation: wavePaw 0.8s ease-in-out infinite;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
    z-index: 2;
}
@keyframes wavePaw {
    0%, 100% { transform: rotate(-50deg); }
    50% { transform: rotate(-20deg); }
}

/* Helper speech bubble */
#helper-bubble {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: #fff;
    color: #5c3d2e;
    font-size: 18px;
    font-weight: 700;
    padding: 14px 18px;
    border-radius: 16px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.15);
    max-width: 260px;
    text-align: center;
    line-height: 1.4;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
#helper-bubble.show {
    opacity: 1;
    transform: translateY(0);
}
#helper-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 30px;
    border: 8px solid transparent;
    border-top-color: #fff;
}

/* ========== GAME SCREEN ========== */
#game-screen {
    background: url('assets/bg_game_new.png') center/cover no-repeat;
    background-color: #5c3d2e;
    position: relative;
    overflow: hidden;
}
#game-screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Score bar */
#score-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    width: 100%;
    z-index: 10;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(74, 55, 40, 0.85);
    padding: 8px 22px;
    border-radius: 24px;
}
.score-icon { width: 38px; height: 38px; object-fit: contain; }
.score-item span {
    font-size: 28px;
    font-weight: 800;
    color: #fff;
    min-width: 40px;
    text-align: center;
}
.score-label {
    font-size: 14px !important;
    font-weight: 700 !important;
    color: rgba(255,255,255,0.85) !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: auto !important;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Home button */
.home-btn {
    border: none;
    cursor: pointer;
    transition: transform 0.15s;
    padding: 6px 14px !important;
}
.home-btn:active { transform: scale(0.9); }
.home-arrow {
    font-size: 28px;
    font-weight: 900;
    color: #fff;
    line-height: 1;
}

.bomb-item {
    border: 2px solid rgba(255, 180, 80, 0.5);
    cursor: pointer;
    transition: transform 0.15s;
}
.bomb-item:active { transform: scale(0.9); }
.bomb-item.disabled {
    opacity: 0.85;
    cursor: pointer;
    border-color: rgba(100, 220, 100, 0.6);
}
.bomb-ad-hint {
    font-size: 13px !important;
    font-weight: 800 !important;
    color: #90ee90 !important;
    min-width: auto !important;
    letter-spacing: 0.5px;
    animation: adPulse 1.5s ease-in-out infinite;
}
@keyframes adPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Game layout */
#game-layout {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
    position: relative;
}

#board-area {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#game-board {
    display: block;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3), inset 0 0 0 3px rgba(255,255,255,0.08);
}

/* Pieces tray */
#pieces-tray {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 12px 8px;
    background: rgba(74, 55, 40, 0.55);
    border-radius: 16px;
    min-width: 220px;
    width: 220px;
    flex-shrink: 0;
    max-height: 100%;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.piece-container {
    cursor: grab;
    touch-action: none;
    -webkit-touch-callout: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.3s ease;
    padding: 8px;
    background: rgba(255,255,255,0.25);
    border-radius: 10px;
}
.piece-container:active { cursor: grabbing; }
.piece-container.used {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.piece-canvas {
    display: block;
    pointer-events: none;
}

/* Drag ghost — GPU-accelerated, smooth scale */
#drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    will-change: transform, left, top;
    transform: scale(0.5);
    transition: transform 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
}
#drag-ghost.grown {
    transform: scale(1);
}

/* Cell animations — GPU accelerated */
.cell-anim {
    position: fixed;
    pointer-events: none;
    z-index: 5;
    border-radius: 6px;
    background-size: 80%;
    background-repeat: no-repeat;
    background-position: center;
    will-change: transform, opacity;
}

.cell-anim.place-pop {
    animation: placePop 0.3s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
@keyframes placePop {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.cell-anim.clear-shrink {
    animation: clearShrink 0.35s ease-in both;
}
@keyframes clearShrink {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

/* ========== OVERLAYS (Pause + Game Over) ========== */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s;
}
.overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-content {
    background: #faf5ef;
    border-radius: 24px;
    padding: 28px 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    min-width: 240px;
    max-width: 400px;
    animation: popIn 0.3s ease-out;
}
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.gameover-cat { width: 72px; height: auto; }
.overlay-content h2 { font-size: 30px; color: #8B5E3C; font-weight: 900; }
.gameover-scores { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.go-score-row {
    display: flex; align-items: center; gap: 8px;
    background: rgba(0,0,0,0.05); padding: 6px 20px; border-radius: 16px;
}
.go-icon { width: 26px; height: 26px; object-fit: contain; }
.go-score-row span { font-size: 22px; font-weight: 800; color: #8B5E3C; }
.restart-btn { background: rgba(92,61,46,0.1); padding: 10px 28px; border-radius: 30px; }
.restart-btn img { width: 34px; }
.restart-btn span { font-size: 19px; font-weight: 800; color: #8B5E3C; }
.menu-back-btn { opacity: 0.7; }
.menu-back-btn .small-icon { width: 38px; }

/* Combo text */
.combo-text {
    position: fixed;
    font-size: 36px;
    font-weight: 900;
    color: #FF6B35;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3), 0 0 10px rgba(255,200,0,0.5);
    pointer-events: none;
    z-index: 20;
    animation: comboFloat 0.8s ease-out forwards;
}
@keyframes comboFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-60px) scale(1.4); }
}

/* ================================================
   MOBILE — portrait (max-width: 768px)
   UI scale ~0.92x — reduced to prevent overlapping
   ================================================ */
@media (max-width: 768px) {

    /* --- Menu (scale 0.92) --- */
    .menu-btn.play-main img { width: clamp(120px, 34vw, 200px); }
    .menu-title { font-size: clamp(24px, 6.2vw, 38px); }
    .menu-best-score { padding: 7px 20px; }
    .star-icon { width: clamp(28px, 7vw, 44px); height: clamp(28px, 7vw, 44px); }
    .menu-best-score span { font-size: clamp(22px, 5.5vw, 32px); }
    .menu-content { gap: clamp(12px, 2.5vh, 22px); }
    .lang-btn { font-size: clamp(14px, 3.5vw, 18px); padding: 6px clamp(16px, 4vw, 24px); }

    /* --- Helper cat (smaller, no overlap) --- */
    #helper { bottom: 6px; right: 4px; z-index: 5; }
    #helper-body { width: clamp(100px, 26vw, 160px); }
    #helper-paw { width: clamp(30px, 7.5vw, 50px); left: 10px; }
    #helper-bubble { font-size: clamp(11px, 2.8vw, 15px); padding: 7px 10px; max-width: clamp(140px, 42vw, 200px); }

    /* --- Score bar: compact, no right padding shift --- */
    #score-bar {
        padding: clamp(4px, 0.8vh, 8px) clamp(6px, 1.2vw, 12px);
        padding-right: clamp(6px, 1.2vw, 12px);
        gap: clamp(4px, 0.9vw, 10px);
        flex-wrap: wrap;
    }
    .score-item {
        padding: clamp(3px, 0.6vh, 6px) clamp(7px, 1.8vw, 14px);
        gap: clamp(3px, 0.8vw, 8px);
        border-radius: 16px;
    }
    .score-icon { width: clamp(20px, 5vw, 30px); height: clamp(20px, 5vw, 30px); }
    .score-item span { font-size: clamp(14px, 3.6vw, 22px); min-width: clamp(18px, 4.5vw, 32px); }
    .score-label { font-size: clamp(8px, 2vw, 12px) !important; letter-spacing: 0.5px; }
    .home-arrow { font-size: clamp(16px, 4vw, 24px); }
    .home-btn { padding: clamp(3px, 0.6vh, 6px) clamp(7px, 1.8vw, 14px) !important; }
    .pause-icon { font-size: clamp(16px, 4vw, 22px); }

    /* --- Game layout: VERTICAL on mobile --- */
    #game-layout {
        flex-direction: column;
        gap: clamp(4px, 0.8vh, 10px);
        padding: 4px;
    }

    /* --- Pieces tray: horizontal row at bottom --- */
    #pieces-tray {
        flex-direction: row;
        width: auto;
        min-width: auto;
        max-width: 100%;
        min-height: clamp(48px, 12vw, 72px);
        max-height: none;
        padding: clamp(4px, 1vw, 8px) clamp(6px, 1.5vw, 12px);
        gap: clamp(5px, 1.2vw, 10px);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
    }

    .piece-container {
        padding: clamp(3px, 0.7vw, 6px);
        flex-shrink: 0;
    }

    /* --- Overlays — proper spacing, no overlap --- */
    .overlay-content {
        padding: clamp(16px, 3.5vw, 28px) clamp(20px, 5vw, 36px);
        min-width: clamp(200px, 55vw, 300px);
        max-width: 85vw;
        border-radius: clamp(16px, 4vw, 24px);
        gap: clamp(10px, 2.5vw, 16px);
    }
    .overlay-content h2 { font-size: clamp(20px, 5vw, 28px); }
    .gameover-cat { width: clamp(48px, 12vw, 72px); }
    .go-score-row span { font-size: clamp(16px, 4vw, 22px); }
    .go-icon { width: clamp(22px, 5.5vw, 28px); height: clamp(22px, 5.5vw, 28px); }
    .restart-btn { padding: clamp(7px, 1.8vw, 12px) clamp(20px, 5vw, 30px); border-radius: clamp(20px, 5vw, 30px); }
    .restart-btn img { width: clamp(26px, 6.5vw, 36px); }
    .restart-btn span { font-size: clamp(15px, 3.8vw, 20px); }
    .menu-back-btn .small-icon { width: clamp(30px, 7.5vw, 40px); }

    /* --- Combo text --- */
    .combo-text { font-size: clamp(20px, 5.5vw, 32px); }
}

/* Extra small phones (under 400px width) */
@media (max-width: 400px) {
    .menu-btn.play-main img { width: clamp(100px, 30vw, 140px); }
    .menu-title { font-size: clamp(20px, 5.8vw, 28px); }
    #helper-body { width: clamp(80px, 22vw, 110px); }
    #helper-paw { width: clamp(22px, 6vw, 34px); left: 7px; }
    .score-label { display: none !important; }
    .score-item span { font-size: clamp(12px, 3.4vw, 18px); }
    .score-icon { width: clamp(16px, 4.5vw, 24px); height: clamp(16px, 4.5vw, 24px); }
    .overlay-content { padding: clamp(12px, 3vw, 20px) clamp(16px, 4vw, 28px); }
}

/* Very small phones (under 340px width) */
@media (max-width: 340px) {
    .menu-btn.play-main img { width: 28vw; }
    .menu-title { font-size: 5.5vw; }
    .score-item { padding: 2px 5px; gap: 2px; }
    .home-arrow { font-size: 3.8vw; }
    .pause-icon { font-size: 3.8vw; }
    #helper-body { width: 20vw; }
    #helper-paw { width: 5.5vw; }
    .overlay-content { padding: 10px 14px; gap: 8px; }
    .overlay-content h2 { font-size: 4.5vw; }
}

/* Landscape mobile — prevent tiny UI */
@media (max-height: 500px) and (orientation: landscape) {
    #score-bar { padding: 2px 6px; gap: 4px; }
    .score-item { padding: 2px 8px; }
    .score-icon { width: 20px; height: 20px; }
    .score-item span { font-size: 14px; min-width: 18px; }
    .score-label { display: none !important; }
    #game-layout { gap: 4px; padding: 2px; }
    #pieces-tray { min-height: 36px; padding: 3px 6px; }
    .overlay-content { padding: 10px 18px; gap: 8px; }
    .overlay-content h2 { font-size: 18px; }
    .gameover-cat { width: 36px; }
}
