/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Arial', sans-serif;
    background: linear-gradient(135deg, #ff6b6b 0%, #4ecdc4 25%, #45b7d1 50%, #96ceb4 75%, #feca57 100%);
    background-size: 400% 400%;
    animation: gradientShift 8s ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

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

/* Loading Screen */
.loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }

    50% {
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.9);
    }

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

.loading-content {
    text-align: center;
    color: white;
    padding: 20px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-content img {
    width: min(60vw, 280px);
    height: auto;
    max-height: 280px;
}

.loading-text {
    font-size: clamp(20px, 6vw, 28px);
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4);
    color: #fff;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

.loading-progress {
    width: min(80vw, 300px);
    height: 12px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    overflow: hidden;
    margin: 0 auto;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
    background-size: 200% 100%;
    width: 0%;
    animation: loading 3s ease-in-out infinite, rainbow 2s linear infinite;
    border-radius: 15px;
}

@keyframes rainbow {
    0% {
        background-position: 0% 50%;
    }

    100% {
        background-position: 200% 50%;
    }
}

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

    50% {
        width: 70%;
    }

    100% {
        width: 100%;
    }
}

/* Level Start Screen */
.level-start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.level-start-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    padding: 40px;
    background: white;
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: slideUpBounce 0.6s ease-out;
}

@keyframes slideUpBounce {
    0% {
        transform: translateY(50px) scale(0.9);
        opacity: 0;
    }

    60% {
        transform: translateY(-10px) scale(1.02);
    }

    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.decorative-shapes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    border-radius: 30px;
}

.decorative-shape {
    position: absolute;
    opacity: 0.3;
    animation: floatShape 4s ease-in-out infinite;
}

@keyframes floatShape {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-20px) rotate(180deg);
    }
}

.decorative-shape.circle {
    border-radius: 50%;
}

.decorative-shape.square {
    border-radius: 10px;
}

.decorative-shape.triangle {
    width: 0;
    height: 0;
    border-style: solid;
    background: none !important;
}

.level-start-main {
    position: relative;
    z-index: 1;
}

.level-start-title {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 15px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.2);
    animation: titlePulse 2s ease-in-out infinite;
}

@keyframes titlePulse {

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

    50% {
        transform: scale(1.05);
    }
}

.level-start-counter {
    font-size: 20px;
    margin-bottom: 25px;
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.05);
    padding: 8px 20px;
    border-radius: 20px;
    display: inline-block;
}

.level-start-instructions {
    font-size: 22px;
    margin-bottom: 30px;
    color: #333;
    line-height: 1.6;
}

.level-start-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 35px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-label {
    font-size: 14px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #4CAF50;
}

.go-button {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    padding: 18px 50px;
    font-size: 28px;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
    transition: all 0.3s ease;
    animation: buttonGlow 2s ease-in-out infinite;
}

@keyframes buttonGlow {

    0%,
    100% {
        box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
    }

    50% {
        box-shadow: 0 8px 35px rgba(76, 175, 80, 0.6);
    }
}

.go-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 40px rgba(76, 175, 80, 0.5);
}

.go-button:active {
    transform: translateY(-1px) scale(1.02);
}

/* Countdown Overlay */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    animation: fadeIn 0.3s ease-out;
}

.countdown-number {
    font-size: 200px;
    font-weight: bold;
    font-family: 'Arial Black', 'Arial', sans-serif;
    color: white;
    text-shadow: 8px 8px 0 rgba(0, 0, 0, 0.3);
    letter-spacing: 10px;
    animation: countdownPop 1s ease-out;
    padding: clamp(20px, 6vw, 40px) clamp(35px, 8vw, 70px);
    border-radius: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.25);
}

@keyframes countdownPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

    50% {
        transform: scale(1.2) rotate(0deg);
    }

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

.countdown-number.go {
    font-size: 180px;
    color: #4CAF50;
    animation: goPop 0.8s ease-out;
}

@keyframes goPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

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

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

/* Floating Timer */
.floating-timer {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    pointer-events: none;
}

.floating-timer-content {
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    border-radius: 50px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    display: flex;
    gap: 25px;
    align-items: center;
    animation: slideUpFloat 0.5s ease-out;
}

@keyframes slideUpFloat {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.timer-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.timer-item.total {
    padding-left: 25px;
    border-left: 2px solid rgba(255, 255, 255, 0.3);
}

.timer-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
}

.timer-value {
    font-size: 20px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: white;
    min-width: 100px;
    text-align: left;
}

.timer-item.total .timer-value {
    color: #4CAF50;
}

.error-message {
    color: #ff6b6b;
    font-size: 18px;
    margin-bottom: 20px;
}

/* Game UI */
.game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    pointer-events: none;
}

/* When UI is above the canvas, make it part of normal flow */
.ui-above .game-ui {
    position: relative;
    pointer-events: auto;
}

.ui-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.9), rgba(78, 205, 196, 0.9));
    color: white;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    0% {
        transform: translateY(-100%);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.level-info h2 {
    font-size: 26px;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: pulse 2s infinite;
}

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

    50% {
        transform: scale(1.05);
    }

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

.level-counter {
    font-size: 16px;
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    display: inline-block;
}

.timer {
    font-size: 18px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
    padding: 15px 20px;
    border-radius: 25px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

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

    50% {
        transform: translateY(-5px);
    }
}

.timer-row {
    margin: 2px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 200px;
}

.timer-row.penalty {
    color: #ff6b6b;
}

.timer-row.total {
    color: #4CAF50;
    font-weight: bold;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    padding-top: 5px;
    margin-top: 5px;
}

.instructions {
    text-align: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, rgba(254, 202, 87, 0.9), rgba(255, 107, 107, 0.9));
    color: white;
    font-size: 18px;
    font-weight: bold;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.6s ease-out 0.2s both;
    transition: opacity 0.6s ease;
}

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

@keyframes slideUp {
    0% {
        transform: translateY(100%);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Canvas Container */
.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f0f0f0;
}

canvas {
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3), 0 5px 15px rgba(0, 0, 0, 0.2);
    cursor: grab;
    touch-action: none;
    /* Prevent default touch behaviors */
    border: 4px solid rgba(255, 255, 255, 0.3);
    animation: canvasFloat 4s ease-in-out infinite;
}

@keyframes canvasFloat {

    0%,
    100% {
        transform: translateY(0px) rotate(0deg);
    }

    25% {
        transform: translateY(-3px) rotate(0.5deg);
    }

    75% {
        transform: translateY(3px) rotate(-0.5deg);
    }
}

canvas:active {
    cursor: grabbing;
    transform: scale(0.98);
    transition: transform 0.1s ease;
}


/* Game Complete Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
    padding: 30px;
    border-radius: 25px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3), 0 10px 20px rgba(0, 0, 0, 0.2);
    border: 3px solid #ff6b6b;
    animation: modalBounce 0.6s ease-out;
}

@keyframes modalBounce {
    0% {
        transform: scale(0.3) rotate(-10deg);
        opacity: 0;
    }

    50% {
        transform: scale(1.05) rotate(2deg);
    }

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

.modal-content h2 {
    color: #ff6b6b;
    margin-bottom: 15px;
    font-size: 32px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    animation: titleBounce 1s ease-out;
}

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

    50% {
        transform: scale(1.1);
    }

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

.modal-content p {
    margin-bottom: 15px;
    font-size: 16px;
    color: #333;
}

.score-breakdown {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    border-left: 4px solid #4CAF50;
}

.score-breakdown p {
    margin: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.total-score {
    font-weight: bold;
    font-size: 18px;
    color: #4CAF50;
    border-top: 2px solid #4CAF50;
    padding-top: 10px;
    margin-top: 10px;
}

.accuracy {
    color: #2196F3;
    font-weight: bold;
}

/* Penalty Notification */
.penalty-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ff6b6b;
    color: white;
    padding: 15px 25px;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    z-index: 2000;
    box-shadow: 0 10px 30px rgba(255, 107, 107, 0.4);
    opacity: 0;
    transition: all 0.3s ease;
}

.penalty-notification.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
}

.penalty-notification.hide {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
}

.name-input {
    margin: 20px 0;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 10px;
}

.name-input label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    color: #333;
}

.name-input input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    margin-bottom: 10px;
}

.name-input input:focus {
    outline: none;
    border-color: #4CAF50;
}

.name-input button {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.name-input button:hover {
    background: linear-gradient(135deg, #45a049, #4CAF50);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.name-input button:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(76, 175, 80, 0.3);
}

.leaderboard-section {
    margin: 20px 0;
    text-align: left;
}

.leaderboard-section h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #333;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin: 5px 0;
    background: #f9f9f9;
    border-radius: 5px;
    border-left: 4px solid #ddd;
}

.leaderboard-entry.first-place {
    background: linear-gradient(90deg, #FFD700, #FFF8DC);
    border-left-color: #FFD700;
}

.leaderboard-entry .rank {
    font-weight: bold;
    font-size: 18px;
    color: #666;
    min-width: 30px;
}

.leaderboard-entry .name {
    flex: 1;
    margin: 0 15px;
    font-weight: bold;
    color: #333;
}

.leaderboard-entry .time {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #4CAF50;
}

.no-scores {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 20px;
}

.modal-buttons {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons button {
    padding: 15px 30px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.modal-buttons button:first-child {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
}

.modal-buttons button:first-child:hover {
    background: linear-gradient(135deg, #45a049, #4CAF50);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.modal-buttons button:last-child {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
}

.modal-buttons button:last-child:hover {
    background: linear-gradient(135deg, #ff5252, #ff6b6b);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.modal-buttons button:active {
    transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 768px) {
    .ui-top {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .timer {
        font-size: 20px;
    }

    .level-info h2 {
        font-size: 20px;
    }

    .modal-content {
        padding: 20px;
        margin: 20px;
    }

    .dev-mode-toggle {
        top: 10px;
        right: 10px;
    }

    .dev-info {
        font-size: 10px;
        padding: 8px;
    }
}

@media (max-width: 480px) {
    .instructions {
        font-size: 14px;
        padding: 8px 15px;
    }

    .modal-content h2 {
        font-size: 24px;
    }

    .leaderboard-entry {
        font-size: 14px;
    }

    .leaderboard-entry .rank {
        font-size: 16px;
    }
}