/* Soccer Stars 3D - Styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #081406;
    display: flex;
    justify-content: center;
    align-items: center;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Outer Game Wrapper - Focused Mobile Experience */
#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic mobile viewport height */
    max-width: 440px; /* Portrait smartphone proportion */
    max-height: 920px;
    background: #0f240b;
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.85);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Real mobile devices: edge-to-edge native app feel */
@media (max-width: 540px) {
    #game-wrapper {
        max-width: 100% !important;
        max-height: 100% !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
}

/* Desktop/Tablet view: Sleek Smartphone Bezel Frame */
@media (min-width: 541px) {
    #game-wrapper {
        border-radius: 38px;
        border: 11px solid #1a2718;
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16), 0 24px 60px rgba(0, 0, 0, 0.95);
        height: 94vh;
        aspect-ratio: 9 / 18.8;
    }

    /* Phone Speaker / Dynamic Island Top Notch */
    #game-wrapper::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 90px;
        height: 18px;
        background: #000000;
        border-radius: 12px;
        z-index: 100;
        pointer-events: none;
    }
}

/* Three.js Canvas Container */
#canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    touch-action: none;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* UI Overlay Layer */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Top HUD & Scoreboard */
.top-hud {
    pointer-events: auto;
    background: linear-gradient(180deg, rgba(8, 18, 8, 0.88) 0%, rgba(8, 18, 8, 0.45) 75%, transparent 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 24px 12px 10px;
    padding-top: max(24px, env(safe-area-inset-top, 24px));
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 20;
}

@media (max-width: 540px) {
    .top-hud {
        padding: 8px 10px 8px;
        padding-top: max(8px, env(safe-area-inset-top, 8px));
    }
    .score-box {
        padding: 2px 12px;
    }
    .score-num {
        font-size: 22px;
    }
    .team-name {
        font-size: 10px;
    }
    .flag-icon {
        width: 28px;
        height: 28px;
    }
    .turn-pill {
        font-size: 10px;
        padding: 2px 9px;
    }
}

.scoreboard {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.team-card {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.team-card.team-right {
    justify-content: flex-end;
}

.flag-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    background-size: cover;
    background-position: center;
}

/* Procedural CSS Flag Previews for Header Icons */
.flag-germany {
    background: linear-gradient(#111 33%, #d00 33%, #d00 66%, #fc0 66%);
}

.flag-malaysia {
    background: repeating-linear-gradient(#cc0000 0px, #cc0000 2.2px, #fff 2.2px, #fff 4.4px);
    position: relative;
    overflow: hidden;
}
.flag-malaysia::before {
    content: '★';
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 50%;
    background: #000066;
    color: #ffcc00;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-brazil {
    background: radial-gradient(circle at center, #012169 35%, transparent 36%),
                linear-gradient(45deg, #009739 50%, #fedd00 50%);
}

.flag-argentina {
    background: linear-gradient(#74acdf 33%, #fff 33%, #fff 66%, #74acdf 66%);
}

.flag-france {
    background: linear-gradient(90deg, #002654 33%, #fff 33%, #fff 66%, #ed2939 66%);
}

.flag-england {
    background: radial-gradient(circle, transparent 40%, transparent 40%),
                linear-gradient(90deg, #fff 42%, #cf081f 42%, #cf081f 58%, #fff 58%),
                linear-gradient(#fff 42%, #cf081f 42%, #cf081f 58%, #fff 58%);
}

.team-meta {
    display: flex;
    flex-direction: column;
}

.team-name {
    color: #e0e0e0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
}

.score-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.45);
    padding: 4px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.score-num {
    font-size: 26px;
    font-weight: 900;
    color: #ffffff;
    min-width: 20px;
    text-align: center;
}

.score-divider {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.4);
    font-weight: bold;
}

/* Turn Banner & Timer */
.turn-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.turn-pill {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.6px;
    padding: 3px 12px;
    border-radius: 12px;
    text-transform: uppercase;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.turn-pill.your-turn {
    background: #00ff88;
    color: #0d2811;
}

.turn-pill.ai-turn {
    background: #ffaa00;
    color: #3d2400;
}

.turn-pill.team1-turn {
    background: #00d2ff;
    color: #002538;
}

.turn-pill.team2-turn {
    background: #00ff88;
    color: #0d2811;
}

.timer-bar-container {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
}

.timer-bar-fill {
    width: 100%;
    height: 100%;
    background: #00ff88;
    border-radius: 4px;
    transition: width 0.1s linear, background-color 0.3s;
}

/* Top Action Buttons (Sound, Camera, Settings) */
.hud-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon {
    pointer-events: auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* Emote Smiley Button - Matches the Yellow Circle in screenshot! */
.emote-btn-wrapper {
    position: absolute;
    right: 4px;
    top: 62%;
    transform: translateY(-50%);
    pointer-events: auto;
    z-index: 25;
}

.btn-emote-trigger {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd12b 0%, #ff9e00 100%);
    border: 3px solid #ffffff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-emote-trigger:hover {
    transform: scale(1.1) rotate(6deg);
}

.btn-emote-trigger:active {
    transform: scale(0.92);
}

/* Circular Emote Drawer / Wheel */
.emote-drawer {
    position: absolute;
    right: 56px;
    top: 50%;
    transform: translateY(-50%) scale(0.8);
    background: rgba(20, 30, 20, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px;
    border-radius: 28px;
    display: grid;
    grid-template-columns: repeat(4, 38px);
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.emote-drawer.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) scale(1);
}

.emote-item {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.15s, background-color 0.15s;
}

.emote-item:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.25);
}

/* Floating Animated Speech Bubble Emote */
.floating-emote {
    position: absolute;
    transform: translate(-50%, -50%) scale(0);
    background: #ffffff;
    border: 3px solid #333333;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 32px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    animation: popAndFade 2.2s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 25;
}

@keyframes popAndFade {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    15% {
        transform: translate(-50%, -80%) scale(1.2);
        opacity: 1;
    }
    25% {
        transform: translate(-50%, -90%) scale(1);
        opacity: 1;
    }
    80% {
        transform: translate(-50%, -120%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -150%) scale(0.6);
        opacity: 0;
    }
}

/* Goal Celebration Overlay */
#goal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
    z-index: 50;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.5) 0%, transparent 80%);
}

#goal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.goal-banner {
    text-align: center;
    animation: goalPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.goal-title {
    font-size: 64px;
    font-weight: 900;
    color: #ffea00;
    text-shadow: 0 0 10px #ff0055, 0 0 30px #ffaa00, 0 6px 15px rgba(0,0,0,0.8);
    letter-spacing: 4px;
    transform: rotate(-3deg);
}

.goal-team {
    font-size: 20px;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    margin-top: 6px;
    letter-spacing: 2px;
}

@keyframes goalPop {
    0% { transform: scale(0.3) rotate(-15deg); opacity: 0; }
    70% { transform: scale(1.15) rotate(4deg); opacity: 1; }
    100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}

/* Confetti Canvas */
#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 45;
}

/* Modals (Settings, Winner) */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
    pointer-events: none;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-content {
    background: #182818;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    color: #ffffff;
    font-size: 20px;
    font-weight: 800;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    color: #a8d5a8;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.segmented-control {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.seg-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #cccccc;
    padding: 6px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.seg-btn.active {
    background: #00ff88;
    color: #0b240e;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, #00ff88 0%, #00b4d8 100%);
    border: none;
    border-radius: 12px;
    color: #05260f;
    font-size: 15px;
    font-weight: 800;
    padding: 12px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.35);
}

.btn-primary:hover {
    transform: scale(1.02);
}

.btn-primary:active {
    transform: scale(0.98);
}
