/* Reset and Core Setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

:root {
    --bg-dark: #090d1a;
    --card-bg: rgba(26, 34, 52, 0.9);
    --card-border: rgba(255, 255, 255, 0.15);
    --accent-yellow: #fde047;
    --accent-gold: #eab308;
    --lava-red: #ef4444;
    --lava-orange: #f97316;
    --hoodie-teal: #06b6d4;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-main);
    touch-action: none;
}

/* Fullscreen Responsive Layout */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    background: radial-gradient(circle at 50% 30%, #1e1b4b 0%, #090d1a 100%);
    overflow: hidden;
}

/* Top Navigation & Status Header */
#top-bar {
    width: 100%;
    height: 56px;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 8px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--card-border);
    z-index: 20;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

#back-btn, .hud-action-btn {
    text-decoration: none;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

#back-btn:hover, .hud-action-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: translateY(-1px);
}

.hud-action-btn {
    background: rgba(234, 179, 8, 0.16);
    border-color: rgba(234, 179, 8, 0.45);
    color: #fef08a;
}

.hud-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 10px;
    min-width: 52px;
}

.hud-label {
    font-size: 0.58rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.hud-value {
    font-size: 0.9rem;
    font-weight: 900;
    color: var(--accent-yellow);
}

#theme-pill {
    flex-direction: row;
    gap: 5px;
    padding: 5px 12px;
    background: rgba(234, 179, 8, 0.14);
    border-color: rgba(234, 179, 8, 0.35);
    font-weight: 700;
    font-size: 0.8rem;
    color: #fef08a;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.06);
}

/* Fullscreen Canvas Area */
#canvas-wrapper {
    position: relative;
    width: 100vw;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    background-color: #0c1022;
}

/* Vertical Progress Bar */
#progress-container {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 65%;
    max-height: 480px;
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    z-index: 10;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

#progress-goal-icon, #progress-lava-icon {
    font-size: 16px;
    line-height: 1;
}

#progress-track {
    position: relative;
    flex: 1;
    width: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    margin: 8px 0;
    overflow: visible;
}

#progress-lava-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, var(--lava-red), var(--lava-orange));
    border-radius: 4px;
    box-shadow: 0 0 10px var(--lava-orange);
    transition: height 0.1s linear;
}

#progress-player-chick {
    position: absolute;
    left: 50%;
    bottom: 0%;
    transform: translate(-50%, 50%);
    font-size: 16px;
    transition: bottom 0.08s ease-out;
    filter: drop-shadow(0 0 5px rgba(253, 224, 71, 0.9));
}

/* Lava Warning Alert Flash */
#lava-warning {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.95);
    border: 2px solid #fee2e2;
    padding: 8px 22px;
    border-radius: 9999px;
    font-size: 0.88rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: 1px;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.8);
    animation: flashPulse 0.45s infinite alternate ease-in-out;
    pointer-events: none;
    z-index: 15;
}

@keyframes flashPulse {
    from { opacity: 0.8; transform: translateX(-50%) scale(0.96); }
    to { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

/* Mobile Touch Controls */
#touch-controls {
    width: 100vw;
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--card-border);
    z-index: 20;
}

@media (pointer: coarse), (max-width: 1024px) {
    #touch-controls {
        display: flex;
    }
}

/* Tablet Optimizations (768px - 1024px, iPads & Android Tablets) */
@media (min-width: 768px) and (max-width: 1024px) {
    #touch-controls {
        padding: 16px 40px;
        background: rgba(15, 23, 42, 0.94);
    }

    .touch-btn {
        width: 74px;
        height: 68px;
        font-size: 1.8rem;
        border-radius: 18px;
    }

    .hop-btn {
        width: 130px;
        height: 68px;
        font-size: 1.3rem;
    }

    .hop-btn small {
        font-size: 0.65rem;
    }

    #top-bar {
        padding: 0 24px;
    }

    .hud-pill {
        padding: 5px 14px;
        min-width: 64px;
    }

    .hud-value {
        font-size: 1.05rem;
    }

    #progress-container {
        right: 28px;
        width: 32px;
    }

    .modal-card {
        max-width: 560px;
        padding: 32px 28px;
    }

    .level-grid {
        max-height: 320px;
        gap: 12px;
    }
}

.touch-side {
    display: flex;
    gap: 14px;
}

.touch-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 1.5rem;
    width: 64px;
    height: 60px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    transition: transform 0.08s ease, background 0.12s ease;
}

.touch-btn:active {
    background: rgba(253, 224, 71, 0.35);
    border-color: var(--accent-yellow);
    transform: scale(0.92);
}

.hop-btn {
    width: 110px;
    height: 60px;
    background: linear-gradient(135deg, #0284c7 0%, #06b6d4 100%);
    border-color: #38bdf8;
    font-weight: 900;
    font-size: 1.15rem;
    box-shadow: 0 4px 18px rgba(6, 182, 212, 0.45);
}

.hop-btn small {
    font-size: 0.55rem;
    opacity: 0.85;
    letter-spacing: 0.5px;
}

.hop-btn:active {
    background: linear-gradient(135deg, #0369a1 0%, #0891b2 100%);
}

/* Modals & Overlays */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 28, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
}

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 26px;
    padding: 26px 22px;
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.modal-header-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.modal-header-row h2 {
    font-family: 'Fredoka', cursive, sans-serif;
    color: var(--accent-yellow);
    font-size: 1.5rem;
}

.modal-actions-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reset-btn {
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fca5a5;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.reset-btn:hover {
    background: rgba(239, 68, 68, 0.35);
    border-color: #ef4444;
    color: #ffffff;
    transform: scale(1.04);
}

.close-modal-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}
.close-modal-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.selector-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: -4px;
}

/* Progressive 20-Level Grid (5 Columns x 4 Rows) */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
    max-height: 270px;
    overflow-y: auto;
    padding: 4px 2px;
    margin: 4px 0;
}

.level-grid::-webkit-scrollbar {
    width: 6px;
}
.level-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.level-slot {
    aspect-ratio: 1.1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 900;
    cursor: not-allowed;
    color: #64748b;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.level-slot.unlocked {
    cursor: pointer;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.level-slot.unlocked:hover {
    background: rgba(253, 224, 71, 0.2);
    border-color: var(--accent-yellow);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(253, 224, 71, 0.3);
}

.level-slot.selected {
    border-color: var(--accent-gold);
    background: rgba(234, 179, 8, 0.3);
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.5);
    transform: scale(1.05);
}

.level-slot.locked .lock-icon {
    font-size: 0.8rem;
    opacity: 0.6;
}

.star-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.65rem;
    color: #eab308;
}

/* Level Meta Info Box */
.level-meta-panel {
    width: 100%;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.meta-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--accent-yellow);
}

.meta-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.modal-card.lava-heat {
    border-color: rgba(239, 68, 68, 0.6);
    background: radial-gradient(circle at 50% 20%, rgba(239, 68, 68, 0.25) 0%, rgba(26, 34, 52, 0.95) 100%);
}

.modal-card.victory-glow {
    border-color: rgba(234, 179, 8, 0.6);
    background: radial-gradient(circle at 50% 20%, rgba(234, 179, 8, 0.3) 0%, rgba(26, 34, 52, 0.95) 100%);
}

.chick-hero {
    position: relative;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(253, 224, 71, 0.3), rgba(249, 115, 22, 0.3));
    border: 2px solid var(--accent-yellow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    box-shadow: 0 0 30px rgba(253, 224, 71, 0.4);
    animation: chickBob 1.6s infinite ease-in-out;
}

@keyframes chickBob {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.04); }
}

.game-title {
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--accent-yellow);
    letter-spacing: 0.5px;
    text-shadow: 0 4px 12px rgba(234, 179, 8, 0.4);
    line-height: 1;
}

.game-subtitle {
    font-size: 1.18rem;
    font-weight: 800;
    color: var(--lava-orange);
    letter-spacing: 1.2px;
}

.story-desc {
    font-size: 0.92rem;
    line-height: 1.45;
    color: #cbd5e1;
}

.controls-guide {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.82rem;
    color: #e2e8f0;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.key-badge {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 3px 8px;
    font-weight: 800;
    font-size: 0.75rem;
    color: #f8fafc;
}

.primary-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #eab308 0%, #f97316 100%);
    border: none;
    border-radius: 14px;
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    font-size: 1.05rem;
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(249, 115, 22, 0.45);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

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

.secondary-btn {
    width: 100%;
    padding: 11px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    color: #cbd5e1;
    cursor: pointer;
    transition: background 0.15s ease;
}
.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-top: 4px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    margin: 6px 0;
}

.stat-box {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 10px;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 700;
}

.stat-val {
    font-size: 0.95rem;
    font-weight: 900;
    color: var(--accent-yellow);
}

.celebration-badge, .trophy-badge, .danger-title {
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
}

.danger-title {
    color: #f87171;
}

.lava-skull {
    font-size: 50px;
    animation: skullShake 0.6s infinite alternate ease-in-out;
}

@keyframes skullShake {
    0% { transform: rotate(-5deg) scale(0.95); }
    100% { transform: rotate(5deg) scale(1.05); }
}

.bounce-in {
    animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}
