/* --- LOCAL FONTS --- */
@font-face {
    font-family: 'Nunito';
    src: url('../assets/fonts/Nunito-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: 'Nunito';
    src: url('../assets/fonts/Nunito-Black.ttf') format('truetype');
    font-weight: 900;
    font-style: normal;
}

/* --- ROOT VARIABLES --- */
:root {
    --bg-gradient: linear-gradient(180deg, #FFBCD9 0%, #FFDFEB 100%);
    --text-color: #444444;
    --font-head: 'Nunito', cursive;
    --font-body: 'Nunito', sans-serif;
}

/* --- THEMES --- */
[data-theme="cotton_candy"] {
    --bg-gradient: linear-gradient(180deg, #FFBCD9 0%, #FFDFEB 100%);
}

[data-theme="mint_breeze"] {
    --bg-gradient: linear-gradient(180deg, #A8F0C6 0%, #E4F9EB 100%);
}

[data-theme="lavender_sky"] {
    --bg-gradient: linear-gradient(180deg, #D2C4FB 0%, #F3EEFE 100%);
}

[data-theme="lemonade"] {
    --bg-gradient: linear-gradient(180deg, #FFF199 0%, #FEFBDE 100%);
}

[data-theme="baby_blue"] {
    --bg-gradient: linear-gradient(180deg, #B4D8FE 0%, #EAF3FF 100%);
}

[data-theme="peach_puff"] {
    --bg-gradient: linear-gradient(180deg, #FFD6B3 0%, #FFEEE0 100%);
}

[data-theme="rose_water"] {
    --bg-gradient: linear-gradient(180deg, #FFB5B5 0%, #FFE5E5 100%);
}

[data-theme="seafoam"] {
    --bg-gradient: linear-gradient(180deg, #9EF0E9 0%, #E3FBFA 100%);
}

[data-theme="creamsicle"] {
    --bg-gradient: linear-gradient(180deg, #FFCBA4 0%, #FFF0E5 100%);
}

[data-theme="periwinkle"] {
    --bg-gradient: linear-gradient(180deg, #C4D4FF 0%, #EBF2FF 100%);
}

[data-theme="sugar_plum"] {
    --bg-gradient: linear-gradient(180deg, #E1B1FF 0%, #F3E8FF 100%);
}

[data-theme="honeydew"] {
    --bg-gradient: linear-gradient(180deg, #C1F2B0 0%, #EDFBE7 100%);
}

[data-theme="neon_dark"] {
    --bg-gradient: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
}

/* --- BASE STYLES --- */
html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #000;
    font-family: var(--font-body);
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#game-container {
    width: 100%;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    background: var(--bg-gradient);
    transition: background 0.8s ease;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

@media (min-width: 480px) {
    #game-container {
        /* Maintains a strict 9:16 aspect ratio on desktop to satisfy the <= 1:2 active field requirement */
        max-width: calc(100vh * 0.5625);
    }
}

/* --- FEVER BACKGROUND & VIGNETTE --- */
#game-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #ff4757 0%, #ff9f43 100%);
    opacity: 0;
    transition: opacity 0.6s ease;
    pointer-events: none;
    z-index: 0;
}

#game-container::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.6) 120%);
    opacity: 0;
    transition: opacity 0.6s ease;
    pointer-events: none;
    z-index: 2;
}

#game-container.fever-bg::before,
#game-container.fever-bg::after,
#game-container.bonus-bg::after {
    opacity: 1;
}

#bg-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

[data-pattern="clouds"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cpath fill='rgba(255,255,255,0.2)' d='M70,120 a20,20 0 0,1 20,-20 a30,30 0 0,1 50,0 a20,20 0 0,1 20,20 z' /%3E%3Cpath fill='rgba(255,255,255,0.1)' d='M200,220 a30,30 0 0,1 30,-30 a50,50 0 0,1 80,0 a30,30 0 0,1 30,30 z' /%3E%3C/svg%3E");
    background-size: auto;
}

[data-pattern="dots"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='6' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="stripes"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cline x1='-10' y1='50' x2='50' y2='-10' stroke='rgba(255,255,255,0.1)' stroke-width='8' /%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="grid"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='40' height='40' fill='none' stroke='rgba(255,255,255,0.15)' stroke-width='2'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="checkers"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='20' height='20' fill='rgba(255,255,255,0.08)'/%3E%3Crect x='20' y='20' width='20' height='20' fill='rgba(255,255,255,0.08)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="triangles"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpolygon points='20,10 30,30 10,30' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="diamonds"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpolygon points='20,0 40,20 20,40 0,20' fill='rgba(255,255,255,0.1)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="waves"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='20'%3E%3Cpath d='M0,10 Q15,0 30,10 T60,10' fill='none' stroke='rgba(255,255,255,0.15)' stroke-width='4'/%3E%3C/svg%3E");
    background-size: 60px 20px;
}

[data-pattern="stars"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpolygon points='30,5 37,22 55,22 40,33 46,50 30,40 14,50 20,33 5,22 23,22' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 80px 80px;
}

[data-pattern="hearts"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M30,20 a10,10 0 0,1 20,0 c0,10 -20,20 -20,30 c0,-10 -20,-20 -20,-30 a10,10 0 0,1 20,0' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 60px 60px;
}

[data-pattern="flower"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='5' fill='rgba(255,255,255,0.2)'/%3E%3Ccircle cx='20' cy='10' r='5' fill='rgba(255,255,255,0.1)'/%3E%3Ccircle cx='20' cy='30' r='5' fill='rgba(255,255,255,0.1)'/%3E%3Ccircle cx='10' cy='20' r='5' fill='rgba(255,255,255,0.1)'/%3E%3Ccircle cx='30' cy='20' r='5' fill='rgba(255,255,255,0.1)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="tree"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpolygon points='20,5 30,25 10,25' fill='rgba(255,255,255,0.15)'/%3E%3Crect x='17' y='25' width='6' height='10' fill='rgba(255,255,255,0.1)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="fish"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='40'%3E%3Cpath d='M40,20 C30,5 10,5 0,20 C10,35 30,35 40,20 Z' fill='rgba(255,255,255,0.15)'/%3E%3Cpolygon points='40,20 50,10 50,30' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 50px 40px;
}

[data-pattern="animal"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='22' r='8' fill='rgba(255,255,255,0.15)'/%3E%3Ccircle cx='10' cy='12' r='4' fill='rgba(255,255,255,0.15)'/%3E%3Ccircle cx='20' cy='8' r='4' fill='rgba(255,255,255,0.15)'/%3E%3Ccircle cx='30' cy='12' r='4' fill='rgba(255,255,255,0.15)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

[data-pattern="dessert"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M10,20 A10,10 0 0,1 30,20 Z' fill='rgba(255,255,255,0.15)'/%3E%3Cpolygon points='12,20 28,20 20,35' fill='rgba(255,255,255,0.1)'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

.text-preview svg {
    display: block;
    margin: 0 auto;
}

/* --- SPACE MODE --- */
[data-mode="space"] #game-container {
    background: linear-gradient(180deg, #1e272e 0%, #485460 100%) !important;
}

[data-mode="space"] #bg-pattern {
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Ccircle cx='20' cy='20' r='2' fill='rgba(255,255,255,0.8)'/%3E%3Ccircle cx='70' cy='60' r='1' fill='rgba(255,255,255,0.5)'/%3E%3Ccircle cx='40' cy='80' r='1.5' fill='rgba(255,255,255,0.6)'/%3E%3Ccircle cx='80' cy='10' r='2.5' fill='rgba(255,255,255,0.9)'/%3E%3Ccircle cx='10' cy='90' r='1' fill='rgba(255,255,255,0.4)'/%3E%3C/svg%3E") !important;
    background-size: 100px 100px !important;
}

#canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- SCREEN STYLES --- */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, backdrop-filter 0.4s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

.panel {
    width: 90%;
    max-width: 400px;
    margin: 20px auto;
    padding: 30px 24px;
    box-sizing: border-box;
    background: #ffffff;
    border-radius: 32px;
    border: 4px solid #ffffff;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2), 0 8px 0 rgba(0, 0, 0, 0.1);
    transform: translateY(80px) scale(0.9);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
    touch-action: pan-y;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    padding-top: calc(30px + env(safe-area-inset-top));
    padding-bottom: calc(30px + env(safe-area-inset-bottom));
}

/* Custom Scrollbar for Panels */
.panel::-webkit-scrollbar {
    width: 6px;
}

.panel::-webkit-scrollbar-track {
    background: #f1f2f6;
    border-radius: 10px;
}

.panel::-webkit-scrollbar-thumb {
    background: #ced6e0;
    border-radius: 10px;
}

.panel::-webkit-scrollbar-thumb:hover {
    background: #a4b0be;
}

.screen.active .panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* --- TYPOGRAPHY --- */
h1 {
    font-family: var(--font-head);
    font-size: 3.5rem;
    color: #ff4757;
    margin: 0 0 10px 0;
    line-height: 1;
    text-shadow: 0 5px 0 #c23616;
    text-align: center;
    letter-spacing: 1px;
}

h2 {
    font-family: var(--font-head);
    color: #444;
    font-size: 2rem;
    margin: 0 0 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.05);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 10px;
    width: 100%;
    text-align: center;
}

p {
    color: #666;
    font-weight: 800;
    margin: 0 0 15px 0;
    font-size: 1.1rem;
}

/* --- BUTTONS --- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 16px 15px;
    box-sizing: border-box;
    border-radius: 20px;
    border: none;
    font-family: var(--font-head);
    font-size: 1.3rem;
    font-weight: 900;
    color: white;
    cursor: pointer;
    background: #1e90ff;
    box-shadow: 0 6px 0 #0984e3, 0 10px 15px rgba(0, 0, 0, 0.1);
    transition: 0.1s;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    outline: none;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #0984e3, 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-small {
    width: 48%;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn svg,
.btn-small svg {
    display: block;
    flex-shrink: 0;
}

.btn span,
.btn-small span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transform: translateY(1px);
    /* Optical alignment for text baseline */
    min-width: 0;
}

.btn-green {
    background: #2ed573;
    box-shadow: 0 6px 0 #21a858;
}

.btn-green:active {
    box-shadow: 0 2px 0 #21a858;
}

.btn-secondary {
    background: #f1f2f6;
    color: #57606f;
    box-shadow: 0 6px 0 #ced6e0;
    text-shadow: none;
}

.btn-secondary:active {
    box-shadow: 0 2px 0 #ced6e0;
}

.btn-orange {
    background: #ffa502;
    box-shadow: 0 6px 0 #e17000;
}

.btn-orange:active {
    box-shadow: 0 2px 0 #e17000;
}

.btn-red {
    background: #ff4757;
    box-shadow: 0 6px 0 #c23616;
}

.btn-red:active {
    box-shadow: 0 2px 0 #c23616;
}

.btn-purple {
    background: #9b59b6;
    box-shadow: 0 6px 0 #8e44ad;
}

.btn-purple:active {
    box-shadow: 0 2px 0 #8e44ad;
}

.btn-disabled {
    opacity: 0.5;
    filter: grayscale(1);
    pointer-events: none;
}

.close-btn {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 50px;
    height: 50px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #c23616, 0 4px 10px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, box-shadow 0.1s;
    z-index: 100;
    padding: 0;
}

.close-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c23616, 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* Specialized styles for the shop panel to allow the close button to overflow */
#screen-shop .panel {
    padding: 0;
    overflow: visible;
    display: block;
}

.shop-content {
    padding: 30px 24px;
    max-height: calc(90vh - 8px);
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: calc(30px + env(safe-area-inset-top));
    padding-bottom: calc(30px + env(safe-area-inset-bottom));
}

.shop-content::-webkit-scrollbar {
    width: 6px;
}

.shop-content::-webkit-scrollbar-track {
    background: #f1f2f6;
    border-radius: 10px;
}

.shop-content::-webkit-scrollbar-thumb {
    background: #ced6e0;
    border-radius: 10px;
}

.shop-content::-webkit-scrollbar-thumb:hover {
    background: #a4b0be;
}

/* --- LAYOUT --- */
.row {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

/* Fire Particle Effects */
.fire-fx {
    position: absolute;
    bottom: 10px;
    left: 50%;
    width: 100%;
    height: 0;
    z-index: 1;
}

.flame-particle {
    position: absolute;
    bottom: 0;
    width: 25px;
    height: 25px;
    background: #f44336;
    border-radius: 50% 0 50% 50%;
    transform: translate(-50%, 0) rotate(-45deg) scale(1);
    animation: flameAnim 1.5s ease-in forwards;
    box-shadow: 0 0 10px #ff9800, inset 0 0 5px #ffeb3b;
}

@keyframes flameAnim {
    0% {
        transform: translate(-50%, 0) rotate(-45deg) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -120px) rotate(-45deg) scale(0);
        opacity: 0;
        background: #ffeb3b;
    }
}

/* Floating Coin */
.floating-coin {
    position: absolute;
    font-family: var(--font-head);
    font-size: clamp(1.8rem, 8vw, 2.5rem);
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 4px 0 #aaaaaa, 0 0 10px rgba(255, 255, 255, 0.5);
    pointer-events: none;
    z-index: 100;
    text-align: center;
}

/* Sparkle Trail Particle */
.sparkle-trail {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px #f1c40f, 0 0 4px #fff;
    pointer-events: none;
    z-index: 99;
    transform: translate(-50%, -50%);
    animation: sparkleAnim 0.6s ease-out forwards;
    will-change: transform, opacity;
}

@keyframes sparkleAnim {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, 20px) scale(0);
        opacity: 0;
    }
}

/* --- BONUS ZONE UI --- */
#bonus-meter-container {
    position: absolute;
    right: 20px;
    top: 30%;
    width: 15px;
    height: 100px;
    background: rgba(0, 0, 0, 0.3);
    border: 3px solid #fff;
    border-radius: 10px;
    z-index: 9999;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    transition: opacity 0.5s ease-out;
    opacity: 1;
}

.bonus-flash-active {
    animation: goldenFlash 1s ease-out forwards;
}

@keyframes goldenFlash {
    0% {
        box-shadow: inset 0 0 0 0 rgba(255, 215, 0, 0), 0 0 30px rgba(0, 0, 0, 0.8);
    }

    15% {
        box-shadow: inset 0 0 60px 20px rgba(255, 215, 0, 1), 0 0 30px rgba(0, 0, 0, 0.8);
    }

    100% {
        box-shadow: inset 0 0 0 0 rgba(255, 215, 0, 0), 0 0 30px rgba(0, 0, 0, 0.8);
    }
}

/* --- SEASONS --- */
.season-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    margin-top: 15px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
}

.season-grid:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.shop-card {
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 8px 0 #dfe4ea, 0 10px 15px rgba(0, 0, 0, 0.05);
    border: 3px solid #f1f2f6;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
    box-sizing: border-box;
}

.shop-card:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #dfe4ea, 0 5px 10px rgba(0, 0, 0, 0.05);
}

.shop-card.unlocked-item {
    border-color: #3498db;
    box-shadow: 0 8px 0 #2980b9, 0 10px 15px rgba(0, 0, 0, 0.1);
}

.shop-card.unlocked-item:active {
    box-shadow: 0 4px 0 #2980b9, 0 5px 10px rgba(0, 0, 0, 0.1);
}

.shop-card.active {
    border-color: #2ed573;
    box-shadow: 0 8px 0 #21a858, 0 10px 15px rgba(0, 0, 0, 0.1);
    background: #fafffb;
}

.shop-card.active:active {
    box-shadow: 0 4px 0 #21a858, 0 5px 10px rgba(0, 0, 0, 0.1);
}

.shop-card.locked-item {
    opacity: 0.6;
    filter: grayscale(0.8);
}

.shop-card-preview {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    background: #f1f2f6;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.05);
    overflow: hidden;
    border: 2px solid #fff;
    position: relative;
}

.color-preview {
    width: 100%;
    height: 100%;
}

.text-preview {
    font-family: var(--font-head);
    font-size: 2rem;
    color: #a4b0be;
}

.equipped-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(46, 213, 115, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
    z-index: 5;
    animation: popDot 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.shop-card-name {
    font-size: 0.9rem;
    font-weight: 900;
    color: #2f3542;
    text-transform: uppercase;
    margin-bottom: 12px;
    text-align: center;
    min-height: 2.4em;
    display: flex;
    align-items: center;
    line-height: 1.1;
}

.shop-card-desc {
    font-size: 0.65rem;
    color: #888;
    text-align: center;
    margin-bottom: 8px;
    line-height: 1.2;
    font-weight: bold;
    flex-grow: 1;
}

.shop-action {
    width: 100%;
    padding: 8px 5px;
    box-sizing: border-box;
    border-radius: 12px;
    font-family: var(--font-head);
    font-size: 0.8rem;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
    margin-top: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shop-action.buy {
    background: #ffa502;
    color: #fff;
    box-shadow: 0 4px 0 #e17000;
}

.shop-action.equip {
    background: #3498db;
    color: #fff;
    box-shadow: 0 4px 0 #2980b9;
}

.shop-action.selected {
    background: #2ed573;
    color: #fff;
    box-shadow: 0 4px 0 #21a858;
}

/* Unlock Pop Animation */
@keyframes unlockPop {
    0% {
        transform: scale(1);
        box-shadow: 0 8px 0 #21a858;
        border-color: #2ed573;
    }

    40% {
        transform: scale(1.1);
        box-shadow: 0 12px 0 #fdcb6e;
        border-color: #ffeaa7;
    }

    80% {
        box-shadow: 0 8px 0 #21a858;
        border-color: #2ed573;
    }

    100% {
        transform: scale(1);
        box-shadow: 0 8px 0 #21a858;
    }
}

.unlock-pop {
    animation: unlockPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    pointer-events: none;
    /* prevent double clicks during anim */
    z-index: 10;
    position: relative;
}

/* --- COLOR PICKER (ALT MODE) --- */
.color-picker-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
    padding: 10px;
    background: #f1f2f6;
    border-radius: 16px;
    box-shadow: inset 0 4px 0 rgba(0, 0, 0, 0.05);
}

.color-swatch {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    border: 4px solid transparent;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.color-swatch.active {
    border-color: #555;
    animation: swatchBounce 1.2s infinite ease-in-out;
}

@keyframes swatchBounce {

    0%,
    100% {
        transform: scale(1.15) translateY(0);
    }

    50% {
        transform: scale(1.15) translateY(-4px);
    }
}

.color-badge {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    font-size: 16px;
    font-family: var(--font-head);
    font-weight: 900;
    border-radius: 50%;
    padding: 2px 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* --- HUD --- */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    transition: transform 0.3s;
}

#hud.hidden {
    transform: translateY(-150px);
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(20px + env(safe-area-inset-top)) 20px 0 20px;
    width: 100%;
    box-sizing: border-box;
}

.hud-col {
    flex: 1;
    display: flex;
}

.hud-col.left {
    justify-content: flex-start;
}

.hud-col.center {
    justify-content: center;
    flex-direction: column;
    align-items: center;
}

.hud-col.right {
    justify-content: flex-end;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.pause-btn {
    width: clamp(40px, 12vw, 50px);
    height: clamp(40px, 12vw, 50px);
    background: #ffffff;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

.pause-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.pause-icon {
    width: clamp(14px, 4vw, 18px);
    height: clamp(14px, 4vw, 18px);
    border-left: clamp(4px, 1.2vw, 5px) solid #555;
    border-right: clamp(4px, 1.2vw, 5px) solid #555;
    box-sizing: border-box;
}

.high-score-box {
    background: #ffffff;
    width: clamp(40px, 12vw, 50px);
    height: clamp(40px, 12vw, 50px);
    border-radius: 12px;
    border: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    padding: 0;
}

.high-score-box span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    font-size: 0.55rem;
    font-weight: 900;
    color: #888;
    letter-spacing: 0;
    margin-bottom: 2px;
}

#high-score-display {
    font-family: var(--font-head);
    font-size: clamp(1rem, 4vw, 1.2rem);
    color: #444;
    text-align: center;
    line-height: 1;
}

.sprint-timer-bg {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-head);
    font-size: clamp(6rem, 30vw, 12rem);
    color: rgba(255, 255, 255, 0.35);
    font-weight: 900;
    z-index: 0;
    /* Between bg-pattern and canvas-container */
    pointer-events: none;
    text-align: center;
    line-height: 1;
    white-space: nowrap;
}

.new-record {
    color: #f1c40f !important;
    text-shadow: 0 0 10px rgba(241, 196, 15, 0.8), 0 0 20px rgba(243, 156, 18, 0.6) !important;
    animation: recordPulse 0.6s infinite alternate;
}

@keyframes recordPulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.1);
    }
}

.coin-display,
#run-coin-display {
    font-family: var(--font-head);
    font-size: 1.5rem;
    color: #f39c12;
    text-align: center;
    line-height: 1;
    -webkit-text-stroke: 0px;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
    display: inline-block;
}

@keyframes coinBump {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.4);
        color: #ffeb3b;
    }

    100% {
        transform: scale(1);
    }
}

.bump {
    animation: coinBump 0.3s ease-out;
}

@keyframes coinShake {
    0% {
        transform: scale(1) rotate(0deg);
    }

    25% {
        transform: scale(1.3) rotate(-10deg);
        color: #ffeb3b;
    }

    50% {
        transform: scale(1.3) rotate(10deg);
    }

    75% {
        transform: scale(1.3) rotate(-10deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

.shake {
    animation: coinShake 0.4s ease-out;
}

#shop-alert {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-250px);
    background: #2ed573;
    color: #fff;
    padding: 12px 24px;
    border-radius: 20px;
    font-family: var(--font-head);
    font-size: 1.2rem;
    font-weight: 900;
    box-shadow: 0 6px 0 #21a858, 0 10px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    text-transform: uppercase;
    text-align: center;
    max-width: 80%;
    line-height: 1.4;
}

#shop-alert.error {
    background: #ff4757;
    box-shadow: 0 6px 0 #c23616, 0 10px 20px rgba(0, 0, 0, 0.2);
}

@keyframes errorShake {

    0%,
    100% {
        margin-left: 0;
    }

    20%,
    60% {
        margin-left: -8px;
    }

    40%,
    80% {
        margin-left: 8px;
    }
}

#shop-alert.error.show {
    animation: errorShake 0.4s 0.3s;
}

#shop-alert.show {
    transform: translateX(-50%) translateY(0);
}

#score-display {
    font-family: var(--font-head);
    font-size: clamp(3rem, 15vmin, 5rem);
    color: white;
    text-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
    -webkit-text-stroke: 0px;
    line-height: 0.8;
    margin-top: 10px;
    align-items: center;
    /* Centers score horizontally */
}

/* --- FEEDBACK --- */
#feedback-msg {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-family: var(--font-head);
    font-size: 3.5rem;
    color: #fff;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    z-index: 20;
    pointer-events: none;
    white-space: nowrap;
    will-change: transform, opacity;
}

@keyframes popMsg {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -100%) scale(1);
        opacity: 0;
    }
}

/* --- LOADERS & TOGGLES --- */
.loader-track {
    width: 100%;
    height: 15px;
    background: #eee;
    border-radius: 10px;
    margin-top: 20px;
    overflow: hidden;
}

.loader-fill {
    height: 100%;
    width: 0%;
    background: #ff4757;
    transition: width 0.1s;
}

.theme-grid {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.theme-dot {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.theme-dot.selected {
    border-color: #555;
    transform: scale(1.15);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    background: #f1f2f6;
    padding: 12px 15px;
    border-radius: 16px;
    width: 100%;
    box-sizing: border-box;
    border: none;
    box-shadow: 0 4px 0 #ced6e0;
    color: #555;
    font-weight: 900;
}

.toggle {
    position: relative;
    width: 45px;
    height: 24px;
    background: #dfe4ea;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.3s;
    border: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toggle.on {
    background: #2ed573;
}

.toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: left 0.3s;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle.on .toggle-knob {
    left: 23px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    background: #ddd;
    border-radius: 5px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #1e90ff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* --- UTILITY & EXTRACTED CLASSES --- */
#loading-text {
    color: #ff4757;
}

#btn-resume,
#btn-restart-pause {
    display: none;
    margin-bottom: 10px;
}

.privacy-link {
    display: block;
    margin-top: 15px;
    color: #888;
    font-size: 0.8rem;
    text-decoration: none;
}

.gameover-title {
    color: #ff4757;
}

.score-box {
    background: #f1f2f6;
    padding: 10px;
    border-radius: 16px;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    border: none;
    box-shadow: 0 4px 0 #ced6e0;
}

.score-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #555;
    display: block;
    margin-bottom: 5px;
}

#final-score {
    font-family: var(--font-head);
    font-size: 3.5rem;
    color: #444;
    line-height: 1;
}

#btn-revive {
    background: #ff9f43;
    box-shadow: 0 6px 0 #e67e22;
    display: none;
    margin-bottom: 10px;
}

#btn-revive:active {
    box-shadow: 0 2px 0 #e67e22;
}

#btn-back-to-top {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: none;
    padding: 0;
    font-size: 1.5rem;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.mt-5 {
    margin-top: 5px;
}

.mt-15 {
    margin-top: 15px;
}

.mb-10 {
    margin-bottom: 10px;
}

.mb-20 {
    margin-bottom: 20px;
}

.gap-8 {
    gap: 8px;
}

.flex-1 {
    flex: 1;
}

.py-10 {
    padding: 10px 0;
}

.shop-coin {
    font-size: 2rem;
}

.btn-reset {
    margin: 0;
    min-width: 80px;
    width: auto;
    padding: 5px 10px;
    font-size: 0.8rem;
}

.ad-icon {
    font-size: 5rem;
    margin-top: 20px;
}

.text-center {
    text-align: center;
}

.fade-out {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* --- SPLASH SCREEN --- */
#screen-splash {
    background: #1e90ff;
    z-index: 2000;
    overflow: hidden;
}

#screen-splash h1 {
    position: relative;
    z-index: 10;
    color: white;
    font-size: 5rem;
    animation: splashPulse 1.5s infinite alternate;
    text-shadow: 0 8px 0 rgba(0, 0, 0, 0.15);
}

@keyframes splashPulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.1);
    }
}

.splash-loader-track {
    position: relative;
    z-index: 10;
    width: 60%;
    max-width: 240px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    margin-top: 40px;
    overflow: hidden;
}

.splash-loader-fill {
    width: 0%;
    height: 100%;
    background: #ffffff;
    border-radius: 4px;
    animation: splashLoad 2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes splashLoad {
    0% {
        width: 0%;
    }

    100% {
        width: 100%;
    }
}

.splash-particle {
    position: absolute;
    bottom: -50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: none;
    will-change: transform, opacity;
    animation: splashFloat 3s linear infinite;
}

@keyframes splashFloat {
    0% {
        transform: translateY(0) scale(0.5);
        opacity: 0;
    }

    20% {
        opacity: 1;
    }

    80% {
        opacity: 1;
    }

    100% {
        transform: translateY(-100vh) scale(1.2);
        opacity: 0;
    }
}

/* --- ONBOARDING --- */
#screen-onboarding {
    z-index: 1500;
}

.onboarding-img {
    width: 80px;
    height: 80px;
    background: #f1f2f6;
    border-radius: 20px;
    margin: 15px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1);
}

/* --- OH NO ANIMATION --- */
.oh-no-text {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    text-align: center;
    transform: translate(-50%, -50%) scale(0);
    font-family: var(--font-head);
    font-size: 4.5rem;
    font-weight: 900;
    color: #ff4757;
    -webkit-text-stroke: 3px #fff;
    text-shadow: 0 8px 0 rgba(0, 0, 0, 0.25), 0 15px 20px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: ohNoPop 2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    will-change: transform, opacity;
}

@keyframes ohNoPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-10deg);
        opacity: 0;
    }

    15% {
        transform: translate(-50%, -50%) scale(1.1) rotate(5deg);
        opacity: 1;
    }

    30% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 1;
    }

    80% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1.2) rotate(0deg);
        opacity: 0;
    }
}

#screen-gameover {
    background: rgba(0, 0, 0, 0.7);
}

/* --- MEDIA QUERIES --- */
@media (max-height: 600px) {
    .hud-top {
        padding: 10px 15px 0 15px;
    }
}

@media (max-width: 400px) {
    .btn {
        font-size: 1.1rem;
        padding: 12px 10px;
        gap: 8px;
    }

    .btn-small {
        font-size: 0.7rem;
        gap: 4px;
        padding: 8px 5px !important;
    }

    .btn svg {
        width: 20px;
        height: 20px;
    }

    .btn-small svg {
        width: 14px;
        height: 14px;
    }

    h1 {
        font-size: 2.8rem;
    }

    h2 {
        font-size: 1.6rem;
    }
}

/* --- POST-GAME STATS --- */
.stats-grid {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    gap: 8px;
}

.stat-box {
    background: #f1f2f6;
    border-radius: 12px;
    padding: 10px 5px;
    flex: 1;
    text-align: center;
    box-shadow: 0 4px 0 #ced6e0;
}

.stat-value {
    font-family: var(--font-head);
    font-size: 1.5rem;
    color: #f39c12;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.65rem;
    font-weight: 900;
    color: #888;
    text-transform: uppercase;
    margin-top: 2px;
}

/* --- NOTIFICATIONS --- */
.notification-dot {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background: #ff4757;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: none;
    z-index: 10;
}

.notification-dot.active {
    display: block;
    animation: popDot 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popDot {
    0% {
        transform: scale(0);
    }

    100% {
        transform: scale(1);
    }
}