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

html, body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

body {
    font-family: 'Comic Sans MS', 'Trebuchet MS', cursive;
    background: #000;
    color: white;
    touch-action: none;
    position: relative;
}

/* Full-screen canvas */
#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    touch-action: none;
    z-index: 1;
}

/* Overlay system */
.overlay {
    position: absolute;
    pointer-events: auto;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* Overlay blocking backdrop */
.overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    z-index: 5;
}

.overlay-backdrop.hidden {
    pointer-events: none;
}

/* Score Overlay - Top */
.score-overlay {
    top: env(safe-area-inset-top, 20px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    border-radius: 25px;
    padding: 15px 25px;
    backdrop-filter: blur(20px);
    border: 3px solid rgba(255, 255, 255, 0.3);
    animation: scoreFloat 3s ease-in-out infinite alternate;
    z-index: 20;
}

@keyframes scoreFloat {
    from { transform: translateX(-50%) translateY(0px); }
    to { transform: translateX(-50%) translateY(-5px); }
}

.score-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

.player-score-display, .keeper-score-display {
    text-align: center;
    min-width: 60px;
}

.score-emoji {
    font-size: 1.8em;
    margin-bottom: 5px;
    animation: scoreEmojiBounce 2s ease-in-out infinite;
}

@keyframes scoreEmojiBounce {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(10deg); }
}

.score-number {
    font-size: 2.5em;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    color: #FFD700;
}

.score-label {
    font-size: 0.7em;
    opacity: 0.8;
    font-weight: bold;
}

.vs-animation {
    font-size: 1.2em;
    font-weight: bold;
    color: #FF4081;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: vsFlash 1.5s ease-in-out infinite alternate;
}

@keyframes vsFlash {
    from { color: #FF4081; transform: scale(1); }
    to { color: #FFEB3B; transform: scale(1.1); }
}

/* Goalkeeper Info Overlay - Center */
.goalkeeper-overlay {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 350px;
    z-index: 40;
}

.goalkeeper-overlay.hidden {
    transform: translate(-50%, -50%) scale(0.5) rotateY(180deg);
}

.keeper-card-full {
    background: linear-gradient(135deg, #9C27B0, #673AB7, #3F51B5);
    border-radius: 30px;
    padding: 25px;
    border: 4px solid #E91E63;
    box-shadow: 0 15px 50px rgba(156, 39, 176, 0.6);
    text-align: center;
    position: relative;
    animation: keeperCardFloat 4s ease-in-out infinite alternate;
}

@keyframes keeperCardFloat {
    from { transform: translateY(0px) rotate(0deg); }
    to { transform: translateY(-10px) rotate(1deg); }
}

.keeper-avatar {
    font-size: 4em;
    margin-bottom: 15px;
    animation: avatarSpin 3s ease-in-out infinite;
}

@keyframes avatarSpin {
    0%, 100% { transform: scale(1) rotate(0deg); }
    33% { transform: scale(1.1) rotate(5deg); }
    66% { transform: scale(1.1) rotate(-5deg); }
}

.keeper-card-full h2 {
    font-size: 1.5em;
    margin-bottom: 10px;
    color: #FFD700;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
}

.personality {
    font-size: 1em;
    color: #FF4081;
    margin-bottom: 20px;
    font-style: italic;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.stat-icon {
    font-size: 1.8em;
    animation: statIconPulse 2s ease-in-out infinite alternate;
}

@keyframes statIconPulse {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.9em;
    color: #FFEB3B;
    margin-bottom: 5px;
    font-weight: bold;
}

.stat-bar {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    height: 12px;
    width: 100%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.stat-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A, #CDDC39);
    border-radius: 8px;
    transition: width 1s ease;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.8);
    animation: statFillGlow 2s ease-in-out infinite alternate;
}

@keyframes statFillGlow {
    from { box-shadow: 0 0 15px rgba(76, 175, 80, 0.8); }
    to { box-shadow: 0 0 25px rgba(76, 175, 80, 1), 0 0 35px rgba(139, 195, 74, 0.6); }
}

.close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #FF4081;
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid #C2185B;
}

.close-button:active {
    transform: scale(0.9);
    background: #E91E63;
}

/* Controls Overlay - Bottom */
.controls-overlay {
    bottom: env(safe-area-inset-bottom, 20px);
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 15;
}

.mega-button {
    background: linear-gradient(45deg, #FF4081, #E91E63, #9C27B0);
    color: white;
    border: none;
    padding: 20px 40px;
    font-size: 1.3em;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 10px 30px rgba(233, 30, 99, 0.6);
    border: 4px solid #C2185B;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    animation: megaButtonPulse 2s ease-in-out infinite alternate;
}

@keyframes megaButtonPulse {
    from { 
        transform: scale(1);
        box-shadow: 0 10px 30px rgba(233, 30, 99, 0.6);
    }
    to { 
        transform: scale(1.05);
        box-shadow: 0 15px 40px rgba(233, 30, 99, 0.9), 0 0 30px rgba(255, 64, 129, 0.8);
    }
}

.mega-emoji {
    font-size: 1.5em;
    animation: megaEmojiSpin 3s linear infinite;
}

@keyframes megaEmojiSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.mega-button:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(233, 30, 99, 0.8);
}

.bottom-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.control-button {
    background: linear-gradient(45deg, #4ECDC4, #45B7D1);
    color: white;
    border: 3px solid #0288D1;
    padding: 12px 15px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    font-size: 0.8em;
    box-shadow: 0 5px 15px rgba(69, 183, 209, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 70px;
    font-family: inherit;
}

.control-emoji {
    font-size: 1.3em;
}

.control-text {
    font-size: 0.7em;
}

.control-button:active {
    transform: translateY(2px) scale(0.95);
    box-shadow: 0 3px 10px rgba(69, 183, 209, 0.6);
}

/* Message Overlay - Center */
.message-overlay {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 90%;
    max-width: 300px;
    z-index: 25;
}

.game-message {
    background: linear-gradient(45deg, #FF4081, #E91E63);
    padding: 25px 30px;
    border-radius: 30px;
    border: 4px solid #C2185B;
    box-shadow: 0 15px 50px rgba(233, 30, 99, 0.8);
    font-weight: bold;
    font-size: 1.3em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: messageExplosion 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes messageExplosion {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    50% { transform: scale(1.2) rotate(-90deg); opacity: 0.8; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.game-message.goal {
    background: linear-gradient(45deg, #4CAF50, #8BC34A, #CDDC39);
    border-color: #2E7D32;
    box-shadow: 0 15px 50px rgba(76, 175, 80, 0.8);
}

.game-message.save {
    background: linear-gradient(45deg, #FF5722, #FF7043, #FF9800);
    border-color: #BF360C;
    box-shadow: 0 15px 50px rgba(255, 87, 34, 0.8);
}

.game-message.info {
    background: linear-gradient(45deg, #2196F3, #03A9F4, #00BCD4);
    border-color: #0277BD;
    box-shadow: 0 15px 50px rgba(33, 150, 243, 0.8);
}

.game-message.countdown-number {
    background: linear-gradient(45deg, #FF9800, #FFC107, #FFEB3B);
    border-color: #FF8F00;
    box-shadow: 0 20px 60px rgba(255, 152, 0, 0.9);
    font-size: 4em;
    padding: 40px 50px;
    animation: countdownPulse 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    color: #1B5E20;
    text-shadow: 4px 4px 8px rgba(255, 255, 255, 0.8);
}

.game-message.countdown-go {
    background: linear-gradient(45deg, #4CAF50, #8BC34A, #CDDC39);
    border-color: #2E7D32;
    box-shadow: 0 25px 70px rgba(76, 175, 80, 1);
    font-size: 3em;
    padding: 35px 45px;
    animation: countdownGo 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    color: white;
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
}

@keyframes countdownPulse {
    0% { 
        transform: scale(0) rotate(-180deg); 
        opacity: 0;
    }
    50% { 
        transform: scale(1.3) rotate(-90deg); 
        opacity: 0.8;
    }
    100% { 
        transform: scale(1) rotate(0deg); 
        opacity: 1;
    }
}

@keyframes countdownGo {
    0% { 
        transform: scale(0.5) rotateY(180deg); 
        opacity: 0;
        filter: hue-rotate(180deg);
    }
    50% { 
        transform: scale(1.4) rotateY(90deg); 
        opacity: 0.9;
        filter: hue-rotate(90deg);
    }
    100% { 
        transform: scale(1) rotateY(0deg); 
        opacity: 1;
        filter: hue-rotate(0deg);
    }
}

/* Instructions Overlay - Initial */
.instructions-overlay {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 300px;
    animation: instructionsSlideIn 1s ease-out;
    z-index: 30;
}

@keyframes instructionsSlideIn {
    from { transform: translate(-50%, -50%) translateY(100px) scale(0.5); opacity: 0; }
    to { transform: translate(-50%, -50%) translateY(0px) scale(1); opacity: 1; }
}

.instructions-overlay.hidden {
    transform: translate(-50%, -50%) translateY(-100px) scale(0.5);
}

.instructions-content {
    background: linear-gradient(135deg, #673AB7, #9C27B0, #E91E63);
    border-radius: 25px;
    padding: 25px;
    border: 4px solid #4A148C;
    box-shadow: 0 15px 50px rgba(103, 58, 183, 0.7);
    text-align: center;
    animation: instructionsGlow 3s ease-in-out infinite alternate;
}

@keyframes instructionsGlow {
    from { box-shadow: 0 15px 50px rgba(103, 58, 183, 0.7); }
    to { box-shadow: 0 20px 60px rgba(103, 58, 183, 0.9), 0 0 40px rgba(156, 39, 176, 0.6); }
}

.instruction-title {
    font-size: 1.4em;
    font-weight: bold;
    margin-bottom: 15px;
    color: #FFD700;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    animation: titleWiggle 2s ease-in-out infinite alternate;
}

@keyframes titleWiggle {
    from { transform: rotate(-1deg); }
    to { transform: rotate(1deg); }
}

.instruction-text {
    margin: 8px 0;
    font-size: 1em;
    opacity: 0.9;
    animation: textFade 3s ease-in-out infinite alternate;
}

@keyframes textFade {
    from { opacity: 0.9; }
    to { opacity: 1; }
}

/* Victory Overlay */
.victory-overlay {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    max-width: 350px;
    z-index: 35;
}

.victory-overlay.hidden {
    transform: translate(-50%, -50%) scale(0) rotate(360deg);
}

.victory-content {
    background: linear-gradient(45deg, #FFD700, #FFA000, #FF8F00);
    border-radius: 30px;
    padding: 30px;
    border: 5px solid #FF6F00;
    box-shadow: 0 20px 60px rgba(255, 193, 7, 0.8);
    text-align: center;
    animation: victoryDance 1s ease-out;
}

@keyframes victoryDance {
    0% { transform: scale(0) rotate(-180deg); }
    50% { transform: scale(1.2) rotate(-90deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.victory-icon {
    font-size: 4em;
    margin-bottom: 15px;
    animation: victoryIconBounce 1s ease-in-out infinite;
}

@keyframes victoryIconBounce {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.2) rotate(-10deg); }
    75% { transform: scale(1.2) rotate(10deg); }
}

.victory-title {
    font-size: 2em;
    font-weight: bold;
    color: #1B5E20;
    text-shadow: 3px 3px 6px rgba(255, 255, 255, 0.8);
    margin-bottom: 10px;
}

.victory-subtitle {
    font-size: 1.1em;
    color: #2E7D32;
    margin-bottom: 20px;
    font-weight: bold;
}

.victory-button {
    background: linear-gradient(45deg, #4CAF50, #8BC34A);
    color: white;
    border: 4px solid #2E7D32;
    padding: 15px 30px;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 auto;
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.6);
    font-family: inherit;
}

.victory-emoji {
    font-size: 1.3em;
    animation: victoryEmojiCelebrate 1s ease-in-out infinite;
}

@keyframes victoryEmojiCelebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3) rotate(20deg); }
}

.victory-button:active {
    transform: scale(0.95);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.8);
}

/* Coach Speech Balloon - Side positioned */
.coach-balloon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 28;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.coach-balloon.hidden {
    opacity: 0;
    transform: translateY(-50%) translateX(-100px) scale(0.8);
}

.coach-avatar {
    font-size: 3em;
    margin-bottom: 10px;
    text-align: center;
    animation: coachBob 2s ease-in-out infinite alternate;
}

@keyframes coachBob {
    from { transform: translateY(0px) rotate(-2deg); }
    to { transform: translateY(-8px) rotate(2deg); }
}

.speech-bubble {
    background: rgba(255, 255, 255, 0.95);
    color: #1B5E20;
    padding: 15px 20px;
    border-radius: 20px;
    border: 3px solid #4CAF50;
    box-shadow: 0 10px 30px rgba(76, 175, 80, 0.5);
    position: relative;
    max-width: 200px;
    font-weight: bold;
    font-size: 1em;
    text-shadow: none;
    animation: speechBubblePulse 1.5s ease-in-out infinite alternate;
}

@keyframes speechBubblePulse {
    from { transform: scale(1); box-shadow: 0 10px 30px rgba(76, 175, 80, 0.5); }
    to { transform: scale(1.02); box-shadow: 0 12px 35px rgba(76, 175, 80, 0.7); }
}

.speech-bubble::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 30px;
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-bottom: 15px solid #4CAF50;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: -5px;
    left: 32px;
    width: 0;
    height: 0;
    border-left: 13px solid transparent;
    border-right: 13px solid transparent;
    border-bottom: 13px solid rgba(255, 255, 255, 0.95);
}

.coach-message {
    margin: 0;
    line-height: 1.3;
}

.coach-message.info {
    color: #2196F3;
}

.coach-message.goal {
    color: #4CAF50;
}

.coach-message.save {
    color: #FF5722;
}

/* Auto-hide overlays during gameplay */
.game-active .score-overlay {
    opacity: 0.5;
    transform: translateX(-50%) translateY(-20px) scale(0.8);
}

.game-active .controls-overlay {
    transform: translateX(-50%) translateY(100px) scale(0.8);
    opacity: 0;
}

.game-active .instructions-overlay {
    opacity: 0;
    transform: translate(-50%, -50%) translateY(-100px) scale(0.5);
}

/* Make countdown more transparent */
.game-message.countdown-number {
    background: linear-gradient(45deg, rgba(255, 152, 0, 0.7), rgba(255, 193, 7, 0.7), rgba(255, 235, 59, 0.7));
    border-color: #FF8F00;
    box-shadow: 0 20px 60px rgba(255, 152, 0, 0.6);
    font-size: 4em;
    padding: 40px 50px;
    animation: countdownPulse 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    color: #1B5E20;
    text-shadow: 4px 4px 8px rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
}

.game-message.countdown-go {
    background: linear-gradient(45deg, rgba(76, 175, 80, 0.8), rgba(139, 195, 74, 0.8), rgba(205, 220, 57, 0.8));
    border-color: #2E7D32;
    box-shadow: 0 25px 70px rgba(76, 175, 80, 0.7);
    font-size: 3em;
    padding: 35px 45px;
    animation: countdownGo 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    color: white;
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
    backdrop-filter: blur(5px);
}

/* Responsive adjustments */
@media (max-height: 600px) {
    .score-overlay {
        padding: 10px 20px;
    }
    
    .score-number {
        font-size: 2em;
    }
    
    .keeper-card-full {
        padding: 20px;
    }
    
    .victory-content {
        padding: 25px;
    }
    
    .mega-button {
        padding: 15px 30px;
        font-size: 1.1em;
    }
}

@media (max-width: 350px) {
    .score-container {
        gap: 15px;
    }
    
    .keeper-card-full {
        padding: 20px;
    }
    
    .keeper-avatar {
        font-size: 3em;
    }
    
    .mega-button {
        padding: 15px 25px;
    }
    
    .control-button {
        min-width: 60px;
        padding: 10px 12px;
    }
}
