/* Import Pixel Art Fonts */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

/* Fallback: Local Poppins if pixel fonts fail to load */
@font-face {
    font-family: 'Poppins';
    src: url('fonts/Poppins-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'Poppins';
    src: url('fonts/Poppins-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: 'Poppins';
    src: url('fonts/Poppins-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
}

/* Reset dan styling dasar */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Press Start 2P', 'VT323', 'Poppins', monospace, sans-serif;
}

/* Root variables */
:root {
    --vw: 100vw;
    --vh: 100vh;
    --dvw: 100dvw;
    --dvh: 100dvh;
    --actual-vw: var(--dvw, var(--vw));
    --actual-vh: var(--dvh, var(--vh));

    --width-scale: calc(var(--actual-vw) / 1920);
    --height-scale: calc(var(--actual-vh) / 1080);
    --base-scale: min(var(--width-scale), var(--height-scale));

    --scale-factor: clamp(0.4, var(--base-scale), 1.2);
    --font-scale: clamp(0.5, var(--base-scale) * 1.1, 1.3);
    --padding-scale: clamp(0.4, var(--base-scale), 1.2);
    --button-scale: clamp(0.5, var(--base-scale) * 1.05, 1.25);
    --gap-scale: clamp(0.4, var(--base-scale), 1.2);

    --font-xs: clamp(0.7rem, 1.5vw, 0.9rem);
    --font-sm: clamp(0.875rem, 2vw, 1.1rem);
    --font-md: clamp(1rem, 2.5vw, 1.25rem);
    --font-lg: clamp(1.25rem, 3vw, 1.75rem);
    --font-xl: clamp(1.5rem, 3.5vw, 2.25rem);
    --font-2xl: clamp(2rem, 4vw, 3rem);
    --font-3xl: clamp(2.5rem, 5vw, 4rem);
}

/* Rotation Overlay */
#rotateOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #87CEEB;
    z-index: 99999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    text-align: center;
}

#rotateOverlay .icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
}

@keyframes rotatePhone {

    0%,
    100% {
        transform: rotate(-90deg);
    }

    50% {
        transform: rotate(0deg);
    }
}

/* Force Landscape on Mobile */
@media screen and (orientation: portrait) and (max-width: 768px) {
    #rotateOverlay {
        display: flex !important;
    }

    .game-container,
    .menu-screen,
    #homeBtn,
    #fullscreenBtn {
        display: none !important;
    }
}

html,
body {
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    width: 100dvw;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    /* Pixel art rendering */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #87CEEB 0%, #E0F7FA 100%);
    overscroll-behavior: none;
}

/* Fullscreen & Home Button */
.fullscreen-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(12px);
    padding: 0;
}

.home-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(12px);
    padding: 0;
}

.home-btn:hover,
.fullscreen-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    background: rgba(255, 255, 255, 0.6);
}

.home-btn:active,
.fullscreen-btn:active {
    transform: translateY(0) scale(0.98);
}

.home-icon,
.fullscreen-icon {
    width: 26px;
    height: 26px;
    color: #1a237e;
    object-fit: contain;
}

.fullscreen-icon.collapse {
    display: none;
}

body.fullscreen .fullscreen-icon.expand {
    display: none;
}

body.fullscreen .fullscreen-icon.collapse {
    display: block;
}

/* Menu Screens */
.menu-screen {
    display: none;
    width: 100vw;
    height: 100vh;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    padding: clamp(40px, 6vh, 100px);
}

.menu-container {
    --menu-vertical-padding: clamp(35px, 5vh, 70px);
    --menu-horizontal-padding: clamp(35px, 5vw, 80px);
    text-align: center;
    background: rgba(255, 255, 255, 0.4);
    padding: var(--menu-vertical-padding) var(--menu-horizontal-padding);
    border-radius: 0;
    /* Pixel art: no rounded corners */
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.3);
    /* Pixel art shadow */
    backdrop-filter: blur(20px);
    border: 4px solid #000;
    /* Thick pixel border */
    animation: fadeIn 0.5s ease-out;
    max-width: min(85vw, 900px);
    width: fit-content;
    min-width: clamp(280px, 40vw, 500px);
    max-height: calc(100vh - clamp(80px, 12vh, 200px));
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    image-rendering: pixelated;
}

.menu-container.compact {
    --menu-vertical-padding: clamp(15px, 2.5vh, 35px);
    --menu-horizontal-padding: clamp(25px, 3.5vw, 55px);
    padding: var(--menu-vertical-padding) var(--menu-horizontal-padding);
    max-height: 95vh;
    height: auto;
    overflow: visible;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.menu-title {
    font-size: clamp(1rem, 3vw, 2rem);
    /* Reduced for pixel font */
    color: #1a237e;
    margin-top: 0;
    margin-bottom: clamp(8px, 1.5vh, 20px);
    font-family: 'Press Start 2P', monospace;
    line-height: 1.4;
    /* Better spacing for pixel font */
    text-transform: uppercase;
}

.compact .menu-title {
    font-size: clamp(1rem, 2.5vw, 1.8rem);
    margin-bottom: clamp(4px, 0.6vh, 8px);
}

.menu-subtitle {
    font-size: clamp(0.6rem, 1.5vw, 1rem);
    /* Reduced for pixel font */
    color: #666;
    margin-bottom: clamp(15px, 2.5vh, 35px);
    font-family: 'VT323', monospace;
    line-height: 1.2;
}

.compact .menu-subtitle {
    font-size: clamp(0.7rem, 1.5vw, 0.95rem);
    margin-bottom: clamp(10px, 1.8vh, 22px);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.2vh, 16px);
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.menu-btn {
    padding: clamp(12px, 2vh, 28px) clamp(20px, 3.5vw, 50px);
    font-size: clamp(0.6rem, 1.5vw, 1rem);
    /* Reduced for pixel font */
    font-weight: 400;
    /* Pixel fonts don't need bold */
    border: 4px solid #000;
    /* Pixel border */
    border-radius: 0;
    /* No rounded corners */
    cursor: pointer;
    transition: none;
    /* Instant pixel transitions */
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.4);
    /* Pixel shadow */
    background: #667eea;
    /* Solid color for pixel look */
    color: white;
    min-height: clamp(45px, 6vh, 70px);
    image-rendering: pixelated;
    font-family: 'Press Start 2P', monospace;
    line-height: 1.4;
    text-transform: uppercase;
}

.menu-btn:hover {
    transform: translateY(-2px) translateX(-2px);
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.4);
    background: #764ba2;
}

.menu-btn:active {
    transform: translateY(-1px) scale(0.98);
}

.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(3px, 0.6vh, 8px);
    padding: clamp(10px, 1.5vh, 20px) clamp(20px, 2.5vw, 35px);
    min-width: clamp(180px, 25vw, 280px);
}

.level-btn.beginner {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
}

.level-btn.amateur {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
}

.level-btn.pro {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.back-btn {
    padding: clamp(10px, 1.5vh, 18px) clamp(25px, 3vw, 45px);
    font-size: clamp(0.85rem, 1.8vw, 1.1rem);
    font-weight: 600;
    background: rgba(255, 255, 255, 0.5);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: clamp(10px, 1.5vw, 18px);
    cursor: pointer;
    margin-top: clamp(8px, 1.5vh, 20px);
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.7);
    transform: translateX(-3px);
}

/* Game Container */
.game-container {
    display: none;
    width: 100vw;
    height: 100vh;
    padding: clamp(10px, 2vh, 30px) clamp(20px, 3vw, 80px);
    gap: clamp(20px, 4vw, 100px);
    justify-content: space-between;
    box-sizing: border-box;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: linear-gradient(180deg, #87CEEB 0%, #98D8E8 100%);
}

.player-section {
    width: clamp(200px, 22vw, 400px);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.5vh, 20px);
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255, 0.35);
    padding: clamp(10px, 2vh, 25px);
    border-radius: 0;
    /* Pixel art: no rounded corners */
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.3);
    /* Pixel shadow */
    backdrop-filter: blur(12px);
    border: 4px solid #000;
    /* Thick pixel border */
    image-rendering: pixelated;
}

.left-player {
    --player-color: #1a237e;
    --player-color-dark: #0d1642;
}

.right-player {
    --player-color: #b71c1c;
    --player-color-dark: #7f0000;
}

.question-box {
    background: var(--player-color);
    color: white;
    padding: clamp(12px, 2vh, 28px) clamp(10px, 1.5vw, 22px);
    border-radius: 0;
    font-size: clamp(1rem, 2.5vw, 1.8rem);
    /* Reduced for pixel font */
    font-weight: 400;
    text-align: center;
    min-height: clamp(60px, 10vh, 100px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #000;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.3);
    font-family: 'VT323', monospace;
    line-height: 1.2;
}

.answer-box {
    background: rgba(255, 255, 255, 0.95);
    width: 100%;
    height: clamp(50px, 8vh, 80px);
    border-radius: 0;
    /* No rounded corners */
    font-size: clamp(1.2rem, 3vw, 2rem);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 400;
    backdrop-filter: blur(5px);
    border: 3px solid #000;
    /* Pixel border */
    box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.1);
    font-family: 'VT323', monospace;
    letter-spacing: 2px;
}

.answer-box.wrong {
    background: #ffebee;
    color: #f44336;
    animation: shake 0.5s;
}

.answer-box.correct {
    background: #e8f5e9;
    color: #4caf50;
    animation: pulse 0.3s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25%,
    75% {
        transform: translateX(-10px);
    }

    50% {
        transform: translateX(10px);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.keypad {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1vh, 15px);
    background: rgba(255, 255, 255, 0.25);
    padding: clamp(8px, 1.5vh, 20px);
    border-radius: clamp(10px, 1.5vw, 25px);
}

.keypad-row {
    display: flex;
    gap: clamp(6px, 1vw, 15px);
    justify-content: space-between;
}

button.number-btn,
button.clear-btn,
button.decimal-btn,
button.minus-btn {
    flex: 1;
    height: clamp(35px, 5vh, 60px);
    font-size: clamp(1rem, 2vw, 1.6rem);
    border: 3px solid #000;
    /* Pixel border */
    border-radius: 0;
    /* No rounded corners */
    background: rgba(255, 255, 255, 0.8);
    color: #333;
    font-weight: 400;
    cursor: pointer;
    transition: none;
    /* Instant pixel transitions */
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
    /* Pixel shadow */
    image-rendering: pixelated;
    font-family: 'VT323', monospace;
    letter-spacing: 1px;
}

button.number-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.95);
}

button.clear-btn {
    background: #ffebee;
    color: #d32f2f;
}

button.go-btn,
button.go-btn-alt {
    flex: 1;
    background: #4caf50;
    /* Solid color */
    color: white;
    font-weight: 400;
    border: 3px solid #000;
    /* Pixel border */
    border-radius: 0;
    /* No rounded corners */
    font-size: clamp(0.8rem, 2vw, 1.4rem);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
    font-family: 'Press Start 2P', monospace;
    text-transform: uppercase;
}

.score-indicator {
    background: rgba(255, 255, 255, 0.9);
    padding: clamp(8px, 1.5vh, 16px);
    border-radius: clamp(8px, 1.2vw, 16px);
    text-align: center;
    font-weight: bold;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    color: #333;
}

/* Tembak Katapel Specifics */
/* Tembak Katapel Specifics */
.center-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 2vh, 30px);
    position: relative;
    z-index: 5;
}

.center-section h1 {
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    font-size: clamp(1.2rem, 3vw, 2.8rem);
    text-align: center;
    margin: 0;
}

.tembak-katapel-field {
    position: relative;
    width: 100%;
    max-width: clamp(500px, 60vw, 900px);
    height: clamp(350px, 45vh, 600px);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Sky background color for the field itself */
    background: linear-gradient(180deg, #ADD8E6 0%, #87CEEB 100%);
    border-radius: clamp(15px, 2vw, 30px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    /* Ensure ground stays inside */
}

/* Ground/Grass */
.ground-bg {
    position: absolute;
    width: 100%;
    height: 25%;
    /* Occupy bottom 25% */
    bottom: 0;
    left: 0;
    object-fit: cover;
    image-rendering: pixelated;
    z-index: 1;
}

/* Shooters */
.shooter-container {
    position: absolute;
    width: clamp(80px, 10vw, 150px);
    height: clamp(80px, 10vw, 150px);
    z-index: 10;
    /* Above ground */
}

/* Adjust bottom position to stand ON the grass */
/* Grass is 25%. Player bottom should be slightly inside or just on top. */
.shooter-container.left-shooter {
    left: clamp(30px, 8%, 80px);
    bottom: 22%;
}

.shooter-container.right-shooter {
    right: clamp(30px, 8%, 80px);
    bottom: 22%;
}

.shooter-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.3));
}

/* Targets */
.target-container {
    position: absolute;
    width: clamp(60px, 8vw, 100px);
    height: clamp(60px, 8vw, 100px);
    z-index: 5;
}

.target-container.left-target {
    left: clamp(30px, 5%, 60px);
    top: clamp(30px, 8%, 80px);
}

.target-container.right-target {
    right: clamp(30px, 5%, 60px);
    top: clamp(30px, 8%, 80px);
}

.target-board {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #FF4444 0%, #FF4444 30%, transparent 30%),
        radial-gradient(circle at center, #FFFFFF 30%, #FFFFFF 50%, transparent 50%),
        radial-gradient(circle at center, #4444FF 50%, #4444FF 70%, transparent 70%),
        radial-gradient(circle at center, #FFFF44 70%, #FFFF44 100%);
    border-radius: 50%;
    border: 3px solid #333;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.target-bullseye {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    background: #FF0000;
    border-radius: 50%;
    border: 2px solid #990000;
}

/* Projectiles */
.projectiles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

.projectile {
    position: absolute;
    width: clamp(20px, 2.5vw, 35px);
    height: clamp(20px, 2.5vw, 35px);
    background: url('assets/peluru.png') no-repeat center center;
    background-size: contain;
    /* border-radius: 50%; remove border radius if using irregular image, or keep if ball */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    border: none;
    box-shadow: none;
    image-rendering: pixelated;
    z-index: 20;
    /* Ensure strictly above everything */
}

.instruction {
    color: #fff;
    text-align: center;
    margin: 0;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 20000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.play-again-btn {
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(33, 150, 243, 0.3);
}

/* Countdown */
.countdown-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 30000;
    align-items: center;
    justify-content: center;
}

.countdown-overlay.show {
    display: flex;
}

.countdown-content {
    text-align: center;
    color: white;
}

.countdown-number {
    font-size: 8rem;
    font-weight: bold;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.countdown-text {
    font-size: 2rem;
    margin-top: 20px;
    text-transform: uppercase;
    letter-spacing: 5px;
}

/* Responsive Media Queries for small landscape */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .game-container {
        padding: 5px 10px;
        gap: 10px;
    }

    .player-section {
        width: 220px;
        padding: 8px;
        gap: 6px;
    }

    .question-box {
        font-size: 1em;
        min-height: 42px;
    }


    .tembak-katapel-field {
        height: 180px;
    }

    .shooter-container {
        width: 60px;
        height: 60px;
    }

    .target-container {
        width: 50px;
        height: 50px;
    }
}

/* Hit Effect Animation */
@keyframes opponentHit {
    0% {
        transform: translateX(0) scale(1);
        filter: brightness(1) sepia(0) hue-rotate(0deg) saturate(100%);
    }

    20% {
        transform: translateX(-5px) scale(0.95);
        filter: brightness(0.8) sepia(1) hue-rotate(-50deg) saturate(300%) drop-shadow(0 0 10px red);
    }

    40% {
        transform: translateX(5px) scale(1.05);
    }

    60% {
        transform: translateX(-5px) scale(0.95);
    }

    80% {
        transform: translateX(5px) scale(1.05);
    }


    100% {
        transform: translateX(0) scale(1);
        filter: brightness(1) sepia(0) hue-rotate(0deg) saturate(100%);
    }
}

.hit-animation {
    animation: opponentHit 0.5s ease-in-out;
}