@import url('https://fonts.googleapis.com/css2?family=Bangers&family=Nunito:wght@700;800;900&display=swap');

/* ── CSS VARS (default theme; JS overrides per level) ────── */
:root {
    --bg: #f4a57a;
    --bg-dark: #e8875e;
    --accent: #ffca3a;
    --text-dark: #7a3a28;
    --btn-glow: rgba(0, 0, 0, 0.18);
    --outline-color: var(--bg);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg);
    min-height: 100vh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.6s ease;
    position: relative;
}

/* ── FLOATING DECO TILES ─────────────────────────────────── */
#deco-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

/* base float */
.deco-tile {
    position: absolute;
    pointer-events: none;
    user-select: none;
    --amp: 8px;
    animation: decoFloat ease-in-out infinite;
    will-change: transform;
}

@keyframes decoFloat {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(calc(var(--amp) * -1));
    }
}

/* Inset rounded squares — carved into the background */
.deco-square {
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
    box-shadow:
        inset 3px 3px 6px rgba(0, 0, 0, 0.12),
        inset -1px -1px 3px rgba(255, 255, 255, 0.1);
}

/* Restored 4-petal colorful flowers — center circle + 4 box-shadow petals */
.deco-flower {
    --p-color: rgba(255, 255, 255, 0.55);
    --c-color: rgba(255, 255, 255, 0.55);
    width: calc(var(--sz, 16px) * 0.45);
    height: calc(var(--sz, 16px) * 0.45);
    border-radius: 50%;
    background: var(--c-color);
    box-shadow:
        0 calc(var(--sz, 16px) * -0.52) 0 calc(var(--sz, 16px) * 0.18) var(--p-color),
        calc(var(--sz, 16px) * 0.52) 0 0 calc(var(--sz, 16px) * 0.18) var(--p-color),
        0 calc(var(--sz, 16px) * 0.52) 0 calc(var(--sz, 16px) * 0.18) var(--p-color),
        calc(var(--sz, 16px) * -0.52) 0 0 calc(var(--sz, 16px) * 0.18) var(--p-color);
}

.deco-flower.sunflower {
    --p-color: rgba(255, 215, 0, 0.6);
    --c-color: rgba(101, 67, 33, 0.6);
}

.deco-flower.pink {
    --p-color: rgba(255, 182, 193, 0.65);
    --c-color: rgba(255, 105, 180, 0.65);
}

.deco-flower.white {
    --p-color: rgba(255, 255, 255, 0.55);
    --c-color: rgba(255, 255, 255, 0.7);
}




/* ── SCREENS ─────────────────────────────────────────────── */
.screen {
    position: relative;
    z-index: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* ── MENU SCREEN ─────────────────────────────────────────── */
#menu-screen {
    gap: 20px;
    padding: 40px 24px;
    max-width: 420px;
    margin: auto;
    justify-content: center;
}

#menu-dog-canvas {
    width: 140px;
    height: 140px;
    margin: 10px 0;
    filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.1));
}

#menu-logo {
    font-size: 5rem;
    font-weight: 900;
    letter-spacing: -2px;
    color: #fff;
    text-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
    line-height: 0.9;
    text-align: center;
    margin-bottom: -10px;
}

#menu-logo span {
    color: var(--accent);
}

#menu-subtitle {
    color: rgba(255, 255, 255, 0.88);
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
}

#btn-play {
    background: var(--accent);
    color: var(--text-dark);
    font-weight: 900;
    font-size: 2.5rem;
    letter-spacing: 1px;
    border: none;
    border-radius: 28px;
    padding: 16px 64px;
    cursor: pointer;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2), 0 15px 20px rgba(0, 0, 0, 0.12);
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
    width: auto;
}

#btn-play:active {
    transform: translateY(8px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.2);
}

#btn-levels {
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-dark);
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 1.1rem;
    letter-spacing: 1.5px;
    border: none;
    border-radius: 20px;
    padding: 14px 40px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
    width: auto;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
}

#btn-levels:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.1);
}

#menu-how {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 20px;
    padding: 16px 20px;
    color: var(--text-dark);
    font-size: 0.85rem;
    font-weight: 800;
    line-height: 1.7;
    text-align: center;
    width: auto;
}

#menu-how h3 {
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 1px;
    margin-bottom: 8px;
    color: #c8705a;
    text-transform: uppercase;
}

/* ── LEVEL SELECT ─────────────────────────────────────────── */
#level-select-screen {
    gap: 20px;
    padding: 24px;
    max-width: 520px;
    width: 100%;
    max-height: 100vh;
    overflow-y: auto;
    margin: auto;
    justify-content: flex-start;
}

#level-select-screen::-webkit-scrollbar {
    width: 0;
}

#ls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

#ls-title {
    font-family: 'Bangers', cursive;
    font-size: 2.2rem;
    letter-spacing: 3px;
    color: #fff;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

#btn-back-menu {
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-dark);
    border: none;
    border-radius: 16px;
    padding: 10px 20px;
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15);
    text-transform: uppercase;
    transition: transform 0.1s, box-shadow 0.1s;
}

#btn-back-menu:active {
    transform: translateY(5px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.1);
}

#level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
}

.level-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 18px;
    padding: 14px 8px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
    transition: transform 0.1s, box-shadow 0.1s;
}

.level-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.15);
}

.level-card:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.1);
}

.level-card.locked {
    opacity: 0.7;
    background: rgba(0, 0, 0, 0.12);
    cursor: not-allowed;
    pointer-events: none;
}

.level-card.locked .lc-num,
.level-card.locked .lc-name {
    color: #7a3a28;
    /* Force a darker, more visible color for locked elements */
}

.level-card.completed {
    background: #e8fff0;
}

.level-card.current {
    border: 3px solid #ffca3a;
    box-sizing: border-box;
    /* Ensure border doesn't expand card size */
}

.level-card.current:not(.completed) {
    background: #fff0e8;
}

.level-card .lc-num {
    font-family: 'Bangers', cursive;
    font-size: 1.5rem;
    color: #c8705a;
    line-height: 1;
}

.level-card .lc-name {
    font-size: 0.6rem;
    font-weight: 800;
    color: #7a3a28;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.level-card .lc-icon {
    font-size: 1.1rem;
}

/* ── GAME SCREEN — FULL SCREEN LAYOUT ───────────────────── */
#game-screen {
    position: relative;
    width: 100vw;
    height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 0;
    gap: 0;
}

/* ── CANVAS ─────────────────────────────────────────────── */
#canvas-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#gameCanvas {
    display: block;
    touch-action: none;
}

/* ── LEVEL FLASH (brief stage label on level change) ────── */
#level-flash {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 24px;
    z-index: 300;
    pointer-events: none;
    font-family: 'Bangers', cursive;
    font-size: 2rem;
    letter-spacing: 5px;
    color: #ffffff;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: scale(0.6) translateY(-16px);
}

#level-flash.flash-in {
    animation: flashIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#level-flash.flash-out {
    animation: flashOut 0.3s ease-in forwards;
}

@keyframes flashIn {
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes flashOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }

    to {
        opacity: 0;
        transform: scale(0.85) translateY(-20px);
    }
}

/* ── HUD ICON BUTTONS ───────────────────────────────────── */
.hud-top-left {
    position: fixed;
    top: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    z-index: 100;
}

.hud-top-right {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    z-index: 100;
}

@media (max-width: 600px) {

    .hud-top-left,
    .hud-top-right {
        gap: 12px;
        top: 15px;
    }

    .hud-top-left {
        left: 15px;
    }

    .hud-top-right {
        right: 15px;
    }

    .icon-btn {
        width: 54px;
        height: 54px;
        border-radius: 14px;
        font-size: 1.8rem;
        box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22);
    }

    .icon-bars span {
        width: 4px;
        height: 16px;
        gap: 4px;
    }
}

/* ── ICON BARS (two-bar pause/menu icon) ───────────────── */
.icon-bars {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.icon-bars span {
    display: block;
    width: 5px;
    height: 22px;
    background: #ffffff;
    border-radius: 3px;
}

.icon-btn {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    font-size: 2.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.45);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.22);
    color: #ffffff;
    cursor: pointer;
    transition: transform 0.1s, background 0.1s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(6px);
}


@media (hover: hover) {
    .icon-btn:hover {
        background: rgba(0, 0, 0, 0.28);
    }
}

.icon-btn:active {
    transform: scale(0.88);
    background: rgba(0, 0, 0, 0.2);
}

/* ── FILL PROGRESS BAR (top center) ────────────────────── */
#fill-hud {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#fill-bar-wrap {
    width: 140px;
    height: 10px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 10px;
    overflow: hidden;
}

#fill-bar-inner {
    height: 100%;
    width: 0%;
    background: #ffffff;
    border-radius: 10px;
    transition: width 0.3s ease;
}

#fill-label {
    font-family: 'Bangers', cursive;
    font-size: 0.85rem;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.85);
}

/* ── HINT ───────────────────────────────────────────────── */
#hint-panel {
    position: fixed;
    bottom: 108px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 16px;
    padding: 10px 20px;
    font-size: 0.85rem;
    color: #7a3a28;
    font-weight: 700;
    display: none;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.2s ease;
}

#hint-panel.visible {
    display: block;
}

#hint-panel b {
    color: #c8705a;
}

/* ── LEVEL COMPLETE POPUP ───────────────────────────────── */
#level-complete-popup {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#level-complete-popup::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.lcp-show::before {
    opacity: 1;
}

.lcp-hide::before {
    opacity: 0 !important;
}

.lcp-stars,
.lcp-num,
.lcp-label {
    position: relative;
    z-index: 1;
    transform: scale(0.4) translateY(40px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.lcp-show .lcp-stars {
    transform: scale(1) translateY(0);
    opacity: 1;
    transition-delay: 0.00s;
}

.lcp-show .lcp-num {
    transform: scale(1) translateY(0);
    opacity: 1;
    transition-delay: 0.08s;
}

.lcp-show .lcp-label {
    transform: scale(1) translateY(0);
    opacity: 1;
    transition-delay: 0.15s;
}

.lcp-hide .lcp-stars,
.lcp-hide .lcp-num,
.lcp-hide .lcp-label {
    transform: scale(0.7) translateY(-20px);
    opacity: 0;
    transition: transform 0.35s ease-in, opacity 0.3s ease-in;
}

.lcp-stars {
    font-size: 2rem;
    letter-spacing: 8px;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
    margin-bottom: 8px;
}

.lcp-num {
    font-family: 'Bangers', cursive;
    font-size: 5rem;
    letter-spacing: 6px;
    color: #ffffff;
    text-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 2px 30px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

.lcp-label {
    font-family: 'Bangers', cursive;
    font-size: 2.4rem;
    letter-spacing: 8px;
    color: var(--accent, #ffeb14);
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

/* ── WIN OVERLAY (all-clear only) ───────────────────────── */
#overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
    z-index: 200;
    background: rgba(0, 0, 0, 0);
}

#overlay.show {
    opacity: 1;
    pointer-events: all;
}

#overlay.win {
    background: radial-gradient(circle, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.6) 100%);
    backdrop-filter: blur(4px);
}

#overlay.stuck {
    background: rgba(0, 0, 0, 0.35);
}

#overlay-dog-canvas {
    width: 200px;
    height: 350px;
    margin-bottom: 5px;
    filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.15));
}

#overlay-title {
    font-family: 'Nunito', sans-serif;
    font-size: 4rem;
    font-weight: 900;
    letter-spacing: -2px;
    color: #fff;
    text-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
    line-height: 0.9;
    text-align: center;
    margin: 12px 0 10px;
}

#overlay-sub {
    font-family: 'Nunito', sans-serif;
    color: rgba(255, 255, 255, 0.95);
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 30px;
    line-height: 1.5;
}

.overlay-btns {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
}

.overlay-btn {
    background: var(--accent);
    color: var(--text-dark);
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 1.4rem;
    letter-spacing: 1px;
    border: none;
    border-radius: 26px;
    padding: 14px 36px;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
}

.overlay-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.2);
}

.overlay-btn.secondary {
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
}

/* ── SPARKLE CANVAS ─────────────────────────────────────── */
#sparkleCanvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    width: 100%;
    height: 100%;
}

/* ── HIDDEN TRACKING SPANS ──────────────────────────────── */
#hid {
    display: none;
}

/* ── ANIMATIONS ─────────────────────────────────────────── */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes popBounce {
    from {
        transform: scale(0.88) translateY(2px);
    }

    to {
        transform: scale(1.12) translateY(-10px);
    }
}

@keyframes floatBob {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-14px);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-8px);
    }

    40% {
        transform: translateX(8px);
    }

    60% {
        transform: translateX(-5px);
    }

    80% {
        transform: translateX(5px);
    }
}

@keyframes shake-small {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    50% {
        transform: translateX(3px);
    }

    75% {
        transform: translateX(-2px);
    }
}

.shake {
    animation: shake 0.38s ease;
}

.shake-small {
    animation: shake-small 0.25s ease;
}

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 600px) {
    #menu-logo {
        font-size: 3.4rem;
    }

    #level-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .level-card {
        padding: 10px 6px 8px;
    }

    .level-card .lc-num {
        font-size: 1.3rem;
    }

    /* Win Overlay Scaling */
    #overlay-dog-canvas {
        width: 150px;
        height: 260px;
        margin-bottom: 0;
    }

    #overlay-title {
        font-size: 2.4rem;
        letter-spacing: -1px;
        margin: 10px 0 8px;
    }

    #overlay-sub {
        font-size: 0.95rem;
        margin-bottom: 24px;
        padding: 0 20px;
        max-width: 320px;
        /* Keep text contained */
        line-height: 1.4;
    }

    .overlay-btns {
        gap: 12px;
        width: 100%;
        max-width: 300px;
        padding: 0 20px;
    }

    .overlay-btn {
        font-size: 1.15rem;
        padding: 12px 20px;
        border-radius: 20px;
        flex: 1 1 130px;
        /* Allow buttons to wrap or sit side-by-side */
        text-align: center;
    }
}

@media (max-height: 680px) {
    #menu-dog-emoji {
        display: none;
    }
}