* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f8f9fa;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

#top-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(6px, 2vw, 12px) clamp(8px, 3vw, 16px);
    gap: clamp(4px, 1.5vw, 10px);
    z-index: 10;
    flex-wrap: nowrap;
}

#back-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

#back-btn:hover {
    background: rgba(0,0,0,0.05);
}

#level-text {
    font-size: clamp(14px, 4.5vw, 20px);
    font-weight: 700;
    color: #2d3436;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
}

#home-btn {
    background: #fff;
    border: 2px solid #94a3b8;
    color: #334155;
    width: clamp(32px, 9vw, 40px);
    height: clamp(32px, 9vw, 40px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s;
    box-shadow: 0 2px 10px rgba(100, 116, 139, 0.25);
    flex-shrink: 0;
}
#home-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(100,116,139,0.4); }
#home-btn:active { transform: translateY(0); }

#sound-btn {
    position: absolute;
    top: calc(clamp(6px, 2vw, 12px) + clamp(32px, 9vw, 40px) + 8px);
    left: clamp(8px, 3vw, 16px);
    z-index: 11;
    background: #fff;
    border: 2px solid #94a3b8;
    color: #334155;
    width: clamp(32px, 9vw, 40px);
    height: clamp(32px, 9vw, 40px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s;
    box-shadow: 0 2px 10px rgba(100, 116, 139, 0.25);
    flex-shrink: 0;
}
#sound-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(100,116,139,0.4); }
#sound-btn:active { transform: translateY(0); }

#hint-btn {
    position: relative;
    background: #fff;
    border: 2px solid #ffd166;
    color: #f59e0b;
    width: clamp(32px, 9vw, 40px);
    height: clamp(32px, 9vw, 40px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.25);
    flex-shrink: 0;
}

#home-btn > svg, #hint-btn > svg, #eraser-btn > svg, #sound-btn > svg {
    width: clamp(18px, 5.5vw, 22px);
    height: clamp(18px, 5.5vw, 22px);
}

#hint-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
}

#hint-btn:active {
    transform: translateY(0);
}

#hint-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hint-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

.hint-count.refill {
    top: auto;
    bottom: 0;
    right: 50%;
    transform: translate(50%, 50%);
    background: #10b981;
    width: auto;
    min-width: clamp(22px, 4vw, 30px);
    height: clamp(16px, 2.2vw, 22px);
    padding: 0 clamp(4px, 0.7vw, 6px);
    border-radius: 12px;
    font-size: clamp(8px, 1.2vw, 10px);
    gap: clamp(1px, 0.3vw, 2px);
}

.hint-count.refill svg {
    flex-shrink: 0;
    width: clamp(10px, 1.6vw, 14px);
    height: clamp(8px, 1.3vw, 11px);
}

.hint-count.refill .ad-get {
    font-weight: 700;
    letter-spacing: 0.3px;
}

#eraser-btn {
    position: relative;
    background: #fff;
    border: 2px solid #ec4899;
    color: #db2777;
    width: clamp(32px, 9vw, 40px);
    height: clamp(32px, 9vw, 40px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s;
    box-shadow: 0 2px 10px rgba(236, 72, 153, 0.25);
    flex-shrink: 0;
}

#eraser-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(236, 72, 153, 0.4);
}

#eraser-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#eraser-btn.active {
    background: #ec4899;
    color: #fff;
    box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.35);
}

#game-canvas.eraser-mode {
    cursor: crosshair;
}

#lives-container {
    display: flex;
    gap: clamp(2px, 0.8vw, 4px);
    flex-shrink: 0;
}

@media (orientation: portrait) {
    #hint-btn, #eraser-btn {
        position: fixed;
        bottom: clamp(30px, 5vh, 42px);
        width: clamp(44px, 12vw, 56px);
        height: clamp(44px, 12vw, 56px);
        z-index: 15;
    }
    #hint-btn { right: calc(50% + 10px); }
    #eraser-btn { left: calc(50% + 10px); }
    #hint-btn > svg, #eraser-btn > svg {
        width: clamp(22px, 6vw, 28px);
        height: clamp(22px, 6vw, 28px);
    }
    #hint-btn .hint-count.refill, #eraser-btn .hint-count.refill {
        min-width: clamp(32px, 8vw, 42px);
        height: clamp(22px, 5.5vw, 30px);
        padding: 0 clamp(6px, 1.8vw, 9px);
        font-size: clamp(10px, 2.6vw, 13px);
        gap: clamp(2px, 0.7vw, 4px);
        border-radius: 14px;
    }
    #hint-btn .hint-count.refill svg, #eraser-btn .hint-count.refill svg {
        width: clamp(13px, 3.4vw, 17px);
        height: clamp(11px, 2.8vw, 14px);
    }
}

#hint-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 50;
}

#hint-overlay line {
    stroke: #ffcc00;
    stroke-linecap: round;
    filter: drop-shadow(0 0 8px #ffcc00);
}

@keyframes hintDashFlow {
    to { stroke-dashoffset: -40; }
}

.heart {
    width: clamp(16px, 5vw, 24px);
    height: clamp(16px, 5vw, 24px);
    transition: transform 0.3s, opacity 0.3s;
    filter: drop-shadow(0 0 6px rgba(255, 71, 87, 0.8));
}

.heart.lost {
    opacity: 0.2;
    transform: scale(0.8);
    filter: grayscale(100%);
}

.heart.breaking {
    animation: heartBreak 0.6s ease-out forwards;
}

@keyframes heartBreak {
    0%   { transform: scale(1); filter: drop-shadow(0 0 6px rgba(255, 71, 87, 0.8)); }
    20%  { transform: scale(1.6) rotate(-5deg); filter: drop-shadow(0 0 24px rgba(255, 71, 87, 1)) brightness(2); }
    35%  { transform: scale(1.4) rotate(8deg); }
    55%  { transform: scale(0.5) rotate(-15deg) translateY(6px); }
    75%  { transform: scale(0.7) translateY(2px); }
    100% { transform: scale(0.8); opacity: 0.2; filter: grayscale(100%); }
}

#game-container.shake {
    animation: shakeBody 0.32s ease-out both;
}

@keyframes shakeBody {
    0%   { transform: translate(0, 0); }
    20%  { transform: translate(-3px, 0); }
    40%  { transform: translate(3px, 0); }
    60%  { transform: translate(-2px, 0); }
    80%  { transform: translate(2px, 0); }
    100% { transform: translate(0, 0); }
}

#game-canvas {
    flex: 1;
    width: 100%;
    touch-action: none;
    transform-origin: center center;
    transition: transform 300ms ease;
}

#game-canvas.hint-active {
    transform: scale(0.92);
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(248, 249, 250, 0.97);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: clamp(16px, 5vw, 40px);
    width: 100%;
    max-width: 500px;
}

.theme-label {
    font-size: 14px;
    color: #7a8090;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 24px 0 12px;
}

.theme-row {
    display: flex;
    gap: 18px;
    justify-content: center;
    margin-bottom: 28px;
}

.theme-option {
    cursor: pointer;
    padding: 10px 14px 8px;
    border-radius: 14px;
    border: 3px solid #e2e6ed;
    background: #fff;
    transition: all 0.18s ease;
    user-select: none;
    -webkit-user-select: none;
}

.theme-option:hover {
    transform: translateY(-2px);
    border-color: #c4cad6;
}

.theme-option.selected {
    border-color: #4263eb;
    box-shadow: 0 4px 16px rgba(66, 99, 235, 0.25);
    transform: translateY(-2px);
}

.theme-preview {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    justify-content: center;
    height: 36px;
    margin-bottom: 6px;
}

.theme-preview .bar {
    display: inline-block;
    width: 8px;
    height: 100%;
    border-radius: 3px;
}

.theme-preview .bar:nth-child(1) { height: 60%; }
.theme-preview .bar:nth-child(2) { height: 90%; }
.theme-preview .bar:nth-child(3) { height: 50%; }
.theme-preview .bar:nth-child(4) { height: 75%; }

.theme-name {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    letter-spacing: 1px;
}

.overlay-content h1 {
    font-size: clamp(32px, 9vw, 56px);
    font-weight: 800;
    color: #2d3436;
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.overlay-content h2 {
    font-size: clamp(22px, 6vw, 36px);
    font-weight: 700;
    color: #2d3436;
    margin-bottom: 16px;
}

.subtitle {
    font-size: clamp(13px, 3.5vw, 18px);
    color: #636e72;
    margin-bottom: 32px;
}

.btn-primary {
    background: #ec4899;
    color: #fff;
    border: none;
    padding: clamp(10px, 2.8vw, 16px) clamp(24px, 7vw, 48px);
    font-size: clamp(14px, 4vw, 20px);
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
    display: block;
    margin: 8px auto;
    position: relative;
    z-index: 1;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(236, 72, 153, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: #ec4899;
    border: 2px solid #ec4899;
    padding: clamp(9px, 2.5vw, 14px) clamp(20px, 6vw, 40px);
    font-size: clamp(13px, 3.5vw, 18px);
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: block;
    margin: 8px auto;
    position: relative;
    z-index: 1;
}

.btn-secondary:hover {
    background: rgba(236, 72, 153, 0.08);
    transform: translateY(-1px);
}

.watch-ad-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 36px;
    border-radius: 50px;
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    border: none;
    cursor: pointer;
    color: #1a1a00;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 1px;
    box-shadow: 0 4px 18px rgba(255,215,0,0.5);
    margin: 8px auto;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s, box-shadow 0.15s;
}
.watch-ad-btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(255,215,0,0.6); }
.watch-ad-btn:active { transform: scale(0.95); }

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
