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

body {
    background: #11071c;
    background-image: radial-gradient(circle at 50% 50%, #2c123d 0%, #0d0414 100%);
    font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

/* --- PRELOADER OVERLAY --- */
#preloader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #180924;
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease;
}

.loader-title {
    color: #ffd700;
    font-size: 32px;
    margin-bottom: 20px;
    text-shadow: 0 4px 10px rgba(255, 183, 0, 0.4), 0 3px 0 #8c1c00;
    letter-spacing: 1.5px;
    font-weight: 900;
}

.loader-bar-container {
    width: 240px;
    height: 18px;
    background: #0f0517;
    border-radius: 12px;
    border: 3px solid #ffd700;
    overflow: hidden;
    margin-bottom: 25px;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
}

.loader-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #00ff87 0%, #60efff 100%);
    transition: width 0.1s linear;
}

.start-btn {
    background: linear-gradient(180deg, #2ecc71 0%, #27ae60 100%);
    border: 3px solid #fff;
    padding: 14px 45px;
    font-size: 22px;
    color: white;
    border-radius: 35px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(46, 204, 113, 0.4), inset 0 -4px 0 #1e8449;
    font-weight: bold;
    display: none;
    animation: pulse 1.5s infinite;
}

/* --- HOW TO PLAY MODAL --- */
#instructions-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 5, 20, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    z-index: 50;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.modal-card {
    background: linear-gradient(135deg, #32114c 0%, #1c082b 100%);
    border: 4px solid #ffd700;
    border-radius: 32px;
    padding: 35px 24px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 215, 0, 0.1);
}

.modal-card h3 {
    color: #ffd700;
    font-size: 30px;
    margin-bottom: 24px;
    text-shadow: 0 3px 0 #bc3a00, 0 4px 10px rgba(0, 0, 0, 0.5);
}

.rule-box {
    text-align: left;
    margin-bottom: 28px;
}

.rule-step {
    font-size: 15px;
    margin-bottom: 20px;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 14px;
    color: #e2d7ec;
}

.rule-icon {
    font-size: 22px;
    background: #0f0517;
    border: 2px solid #ffd700;
    border-radius: 50%;
    min-width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.rule-step strong {
    color: #ffd700;
}

.modal-play-btn {
    background: linear-gradient(180deg, #2ecc71 0%, #27ae60 100%);
    color: white;
    border: 2px solid #fff;
    padding: 14px 50px;
    font-size: 24px;
    font-weight: bold;
    border-radius: 35px;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(46, 204, 113, 0.4), inset 0 -4px 0 #1e8449;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* --- LEVEL COMPLETED MODAL --- */
#level-clear-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 3, 16, 0.92);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 55;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#level-clear-modal.active {
    display: flex;
    opacity: 1;
}

.clear-card {
    background: linear-gradient(135deg, #44146a 0%, #1e0633 100%);
    border: 5px solid #00ff66;
    border-radius: 36px;
    padding: 40px 24px;
    width: 85%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(0, 255, 102, 0.2);
    transform: scale(0.6);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#level-clear-modal.active .clear-card {
    transform: scale(1);
}

.clear-title {
    color: #00ff66;
    font-size: 34px;
    font-weight: 900;
    margin-bottom: 5px;
    text-shadow: 0 0 20px rgba(0, 255, 102, 0.4), 0 3px 0 #004d1a;
    letter-spacing: 1px;
}

.clear-subtitle {
    color: #ffffff;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 25px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.clear-stat-box {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #331452;
    border-radius: 20px;
    padding: 15px;
    margin-bottom: 30px;
}

.clear-stat-row {
    display: flex;
    justify-content: space-between;
    color: #e2d7ec;
    font-size: 16px;
    margin: 6px 0;
}

.clear-stat-row strong {
    color: #ffd700;
}

.next-lvl-btn {
    background: linear-gradient(180deg, #00ff66 0%, #00b347 100%);
    color: #082400;
    border: 3px solid #fff;
    padding: 14px 45px;
    font-size: 22px;
    font-weight: 900;
    border-radius: 35px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 255, 102, 0.4), inset 0 -4px 0 #008033;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5);
    animation: pulse 1.6s infinite;
}

/* --- MAIN GAME CONTAINER --- */
#game-container {
    position: relative;
    width: 440px;
    height: 740px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8), 0 0 40px rgba(142, 68, 173, 0.2);
    border-radius: 40px;
    border: 10px solid #ffd700;
    background-color: #140522;
    overflow: hidden;
}

canvas {
    display: block;
}

/* --- UI HEADER PANEL --- */
#ui-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    background: linear-gradient(180deg, #2f1347 0%, #170725 100%);
    border: 3px solid #4a1f6d;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px;
    z-index: 5;
    border-radius: 24px;
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.5);
}

.level-row {
    display: flex;
    align-items: center;
    background: #0b0212;
    padding: 6px 18px;
    border-radius: 20px;
    border: 2px solid #ffd700;
    margin-bottom: 14px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6);
}

.level-star {
    color: #ffd700;
    font-size: 16px;
    margin-right: 8px;
    text-shadow: 0 0 8px #ffd700;
}

.level-label {
    color: #ffd700;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 1px;
}

.score-row {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: 10px;
}

.score-card {
    flex: 1;
    background: linear-gradient(180deg, #ff9600 0%, #d35400 100%);
    border: 2px solid #ffeb3b;
    border-radius: 16px;
    padding: 6px 0;
    text-align: center;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 6px 12px rgba(0, 0, 0, 0.4);
}

.score-card.best-card {
    background: linear-gradient(180deg, #ffd700 0%, #f39c12 100%);
    border-color: #fff;
}

.score-card.moves-card {
    background: linear-gradient(180deg, #00b0ff 0%, #007bb6 100%);
    border-color: #e0f7fa;
}

.score-card .title {
    font-size: 11px;
    color: #fff;
    font-weight: 900;
    letter-spacing: 0.8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    margin-bottom: 2px;
}

.score-card .value {
    font-size: 24px;
    color: #fff;
    font-weight: 900;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.target-badge-panel {
    background: #ffffff;
    border: 3px solid #ffd700;
    border-top: none;
    border-radius: 0 0 16px 16px;
    padding: 4px 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.target-badge-value {
    font-size: 15px;
    color: #ff0055;
    font-weight: 900;
    letter-spacing: 0.5px;
}

/* --- GAME OVER SCREEN --- */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 5, 22, 0.98);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    z-index: 60;
}

#game-over-screen h2 {
    font-size: 48px;
    color: #ff3366;
    margin-bottom: 15px;
    text-shadow: 0 4px 15px rgba(255, 51, 102, 0.3), 0 3px 0 #000;
    font-weight: 900;
}

#game-over-screen p {
    font-size: 26px;
    margin-bottom: 35px;
    color: #ffd700;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#game-over-screen button {
    background: linear-gradient(180deg, #ff9600 0%, #e67e22 100%);
    border: 2px solid #fff;
    padding: 15px 45px;
    font-size: 24px;
    color: white;
    border-radius: 35px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(230, 126, 34, 0.4), inset 0 -4px 0 #d35400;
    font-weight: bold;
}

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

    50% {
        transform: scale(1.05);
    }

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