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

:root {
    --bg-dark: #0a0e17;
    --bg-field: #1e3c2b;
    --primary: #00ff88;
    --primary-glow: rgba(0, 255, 136, 0.4);
    --secondary: #00e5ff;
    --danger: #ff4757;
    --card-bg: rgba(20, 30, 48, 0.65);
    --card-border: rgba(255, 255, 255, 0.1);
    --text-light: #ffffff;
    --text-muted: #a0aec0;
    
    /* Player specific colors */
    --player-1: #ff4757;
    --player-2: #2ed573;
    --player-3: #1e90ff;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed; /* Lock viewport and prevent mobile scroll bounce */
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Titles and Headers */
h1, h2, h3, .game-title {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
}

/* App Viewport Container */
#app-container {
    width: 100%;
    height: 100%;
    max-width: 600px; /* Keep game vertical, phone/tablet layout friendly */
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at center, #1b2845 0%, #09101d 100%);
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
}

/* Screen Transitions */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    z-index: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Butter-smooth momentum scrolling on iOS */
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 5;
}

/* Glassmorphism Cards */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.header-card {
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.15), rgba(0, 255, 136, 0.15));
    border: 1px solid rgba(0, 255, 136, 0.25);
    margin-top: 20px;
}

.game-title {
    font-size: 2.2rem;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 15px var(--primary-glow);
}

.game-title .highlight {
    color: var(--primary);
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-weight: 500;
}

.section-title {
    font-size: 1.3rem;
    margin-bottom: 15px;
    text-align: left;
    border-left: 4px solid var(--primary);
    padding-left: 8px;
    color: #ffffff;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #00ff88 0%, #00e5ff 100%);
    color: #05140b;
    padding: 16px 32px;
    font-size: 1.2rem;
    width: 100%;
    box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.3);
}

.btn-primary:active {
    transform: scale(0.95);
    box-shadow: 0 4px 10px rgba(0, 255, 136, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    padding: 14px 24px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.96);
}

.btn-danger {
    background: var(--danger);
    color: white;
    padding: 14px 24px;
    box-shadow: 0 5px 15px rgba(255, 71, 87, 0.3);
}

.btn-danger:active {
    transform: scale(0.96);
}

.btn-toggle {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 10px 16px;
    font-size: 0.9rem;
    flex: 1;
}

.btn-toggle.active {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.2) 0%, rgba(0, 229, 255, 0.2) 100%);
    border-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 0 10px var(--primary-glow);
}

.btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1.1rem;
}

/* Animations */
.pulse {
    animation: btnPulse 2s infinite;
}

@keyframes btnPulse {
    0% {
        box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3);
    }
    50% {
        box-shadow: 0 8px 35px rgba(0, 255, 136, 0.7);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3);
    }
}

/* Player setup styles */
.player-count-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

#profiles-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.profile-setup-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 14px;
    text-align: left;
    animation: slideIn 0.3s ease-out;
}

.profile-setup-card.hidden {
    display: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.player-badge {
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 6px;
    color: #000;
}

.player-1-color { background-color: var(--player-1); color: #fff; }
.player-2-color { background-color: var(--player-2); color: #fff; }
.player-3-color { background-color: var(--player-3); color: #fff; }

.player-name-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: 'Outfit', sans-serif;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 10px;
}

.player-name-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(0, 255, 136, 0.3);
}

.avatar-selector, .color-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.avatar-opt {
    flex: 1;
    font-size: 1.3rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.avatar-opt.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: white;
    transform: scale(1.1);
}

.color-opt {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.color-opt.active {
    border-color: white;
    transform: scale(1.15);
    box-shadow: 0 0 8px currentColor;
}

/* Horizontal setup settings grid */
.flex-row {
    display: flex;
    gap: 12px;
}

.mode-select-group {
    flex: 2;
    text-align: left;
}

.shots-select-group {
    flex: 1;
    text-align: left;
}

.input-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.mode-buttons, .shots-buttons {
    display: flex;
    gap: 6px;
}

.action-bar {
    margin-top: auto;
    margin-bottom: 20px;
}

/* SCREEN 2: Gameplay Layout */
#game-screen {
    padding: 0;
    overflow: hidden;
}

.game-hud {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    z-index: 10;
    display: flex;
    gap: 10px;
    height: 70px;
}

.game-hud .glass-card {
    margin-bottom: 0;
    padding: 10px;
    display: flex;
    align-items: center;
    border-radius: 14px;
}

.hud-player-card {
    flex: 2.2;
    gap: 8px;
    text-align: left;
    justify-content: flex-start;
}

.hud-avatar {
    font-size: 1.8rem;
    background: rgba(255, 255, 255, 0.1);
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid var(--player-color, var(--primary));
}

.hud-player-details {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.hud-name {
    font-weight: 700;
    font-size: 1rem;
    color: white;
}

.hud-score-value {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.hud-score-value strong {
    color: var(--primary);
    font-size: 1.05rem;
}

.hud-center {
    flex: 3;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.hud-title-mode {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--secondary);
}

.hud-round-tracker {
    display: flex;
    gap: 4px;
    justify-content: center;
    align-items: center;
}

.shot-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.3s ease;
}

.shot-light.goal {
    background: var(--primary);
    box-shadow: 0 0 6px var(--primary);
}

.shot-light.miss {
    background: var(--danger);
    box-shadow: 0 0 6px var(--danger);
}

.shot-light.active {
    background: white;
    box-shadow: 0 0 8px white;
    transform: scale(1.2);
}

.hud-controls {
    flex: 2.2;
    justify-content: space-between;
    gap: 6px;
}

/* Wind display */
.wind-gauge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.wind-label {
    font-weight: 600;
    margin-bottom: 2px;
}

.wind-arrow-wrap {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.wind-arrow {
    font-size: 0.8rem;
    font-weight: 800;
    color: white;
    transition: transform 0.4s ease;
}

.wind-speed {
    font-weight: 700;
    color: #fff;
    margin-top: 2px;
}

/* Gameplay Canvas Screen Area */
#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* Prevent phone page drag/scroll while aiming */
}

/* Hand Swipe Guide */
#kick-helper-overlay {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

#kick-helper-overlay.fade-out {
    opacity: 0;
}

.hand-swipe-animation {
    font-size: 2.5rem;
    margin-bottom: 10px;
    animation: swipeAnim 2.2s infinite ease-in-out;
}

@keyframes swipeAnim {
    0% {
        transform: translateY(30px) scale(1) rotate(0deg);
        opacity: 0.3;
    }
    15% {
        opacity: 1;
    }
    50% {
        transform: translateY(-80px) scale(0.85) rotate(-15deg);
        opacity: 0.8;
    }
    75% {
        transform: translateY(-90px) scale(0.8) rotate(-15deg);
        opacity: 0;
    }
    100% {
        transform: translateY(30px) scale(1) rotate(0deg);
        opacity: 0;
    }
}

.helper-text {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    max-width: 250px;
    background: rgba(0,0,0,0.5);
    padding: 6px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Announcer Overlay Banner (Goal! / Saved! / Post!) */
#game-announcer-overlay {
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 80%;
    padding: 24px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid var(--primary);
    border-radius: 24px;
    box-shadow: 0 0 40px rgba(0, 255, 136, 0.4);
    z-index: 15;
    pointer-events: none;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#game-announcer-overlay.show-announcer {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

#announcer-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.8rem;
    color: white;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

#announcer-subtitle {
    font-size: 1.1rem;
    color: var(--secondary);
    font-weight: 700;
    margin-top: 6px;
}

/* SCREEN 3: Results screen / Podium */
.podium-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 180px;
    margin-top: 20px;
    margin-bottom: 25px;
    padding-bottom: 10px;
}

.podium-stand {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 90px;
    margin: 0 6px;
    transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.podium-avatar {
    font-size: 2.2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    margin-bottom: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.podium-name {
    font-weight: 700;
    font-size: 0.85rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 80px;
    overflow: hidden;
}

.podium-score {
    font-weight: 800;
    font-size: 0.9rem;
    color: var(--primary);
    margin-bottom: 6px;
}

.podium-block {
    width: 100%;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.podium-number {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
}

/* Places specifics */
.place-1 .podium-block {
    height: 100px;
    background: linear-gradient(180deg, #ffd700 0%, #d4af37 100%);
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}
.place-1 .podium-avatar {
    border-color: #ffd700;
    transform: scale(1.15);
}
.place-1 .crown {
    position: absolute;
    top: -15px;
    font-size: 1.2rem;
    animation: float 2s infinite ease-in-out;
}

.place-2 .podium-block {
    height: 70px;
    background: linear-gradient(180deg, #cccccc 0%, #999999 100%);
    box-shadow: 0 4px 10px rgba(200, 200, 200, 0.2);
}
.place-2 .podium-avatar { border-color: #cccccc; }

.place-3 .podium-block {
    height: 50px;
    background: linear-gradient(180deg, #cd7f32 0%, #a0522d 100%);
    box-shadow: 0 4px 10px rgba(205, 127, 50, 0.2);
}
.place-3 .podium-avatar { border-color: #cd7f32; }

@keyframes float {
    0% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
    100% { transform: translateY(0); }
}

/* Results leaderboard detailed list */
.results-list-card {
    text-align: left;
    padding: 16px;
    margin-bottom: 20px;
    max-height: 250px;
    overflow-y: auto;
}

.leaderboard-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px 14px;
}

.rank-badge {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    width: 25px;
    color: var(--text-muted);
}

.row-avatar {
    font-size: 1.3rem;
    margin-right: 10px;
}

.row-name {
    font-weight: 600;
    flex-grow: 1;
}

.row-stats {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.row-stats strong {
    color: white;
}

.row-score {
    font-weight: 800;
    color: var(--primary);
    font-size: 1.1rem;
    margin-left: 10px;
}

/* Modals */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 10, 20, 0.85);
    backdrop-filter: blur(8px);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-card {
    width: 80%;
    max-width: 320px;
    margin-bottom: 0;
}

.modal-card h2 {
    font-size: 1.6rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Helper hidden states */
.hidden {
    display: none !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --- MOBILE COMPATIBILITY: Compresses spacing on shorter screens (iPhone SE, etc.) --- */
@media (max-height: 740px) {
    .screen {
        padding: 10px;
    }
    .glass-card {
        padding: 10px;
        margin-bottom: 6px;
        border-radius: 12px;
    }
    .header-card {
        margin-top: 2px;
    }
    .game-title {
        font-size: 1.4rem;
    }
    .subtitle {
        font-size: 0.75rem;
        margin-top: 1px;
    }
    .section-title {
        font-size: 1rem;
        margin-bottom: 6px;
    }
    .player-name-input {
        padding: 6px 8px;
        font-size: 0.85rem;
        margin-bottom: 4px;
    }
    .avatar-selector, .color-selector {
        margin-bottom: 4px;
        gap: 4px;
    }
    .avatar-opt {
        font-size: 1.1rem;
        padding: 1px;
    }
    .color-opt {
        width: 18px;
        height: 18px;
    }
    .btn-primary {
        padding: 10px 20px;
        font-size: 0.95rem;
    }
    .profile-setup-card {
        padding: 6px;
        border-radius: 8px;
        margin-bottom: 4px;
    }
    .flex-row {
        gap: 6px;
    }
    .action-bar {
        margin-top: 3px;
        margin-bottom: 3px;
    }
    .podium-container {
        height: 120px;
        margin-top: 6px;
        margin-bottom: 6px;
    }
    .podium-avatar {
        font-size: 1.5rem;
        width: 32px;
        height: 32px;
    }
    .place-1 .podium-block { height: 60px; }
    .place-2 .podium-block { height: 40px; }
    .place-3 .podium-block { height: 28px; }
}

/* --- IPAD/TABLET VIEWPORT ENHANCEMENTS: Centers the layout inside a high-end console container --- */
@media (min-width: 768px) {
    #app-container {
        max-width: 500px;
        height: 90vh;
        border-radius: 28px;
        border: 2px solid rgba(255, 255, 255, 0.15);
        box-shadow: 0 25px 65px rgba(0, 0, 0, 0.65);
    }
}

/* Audio setting row and HUD buttons styling */
.hud-btn-group {
    display: flex;
    gap: 6px;
}

.audio-setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    text-align: left;
}

.audio-setting-row span {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-light);
}

.audio-setting-row .btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    width: auto;
    flex-grow: 0;
}

