:root {
    --bg-dark: #0f172a;
    --text-light: #f8fafc;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans KR', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at top, #1e293b, #0f172a);
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    position: relative;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
}

.phase {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column;
    padding: 2rem;
    transition: opacity 0.5s ease, transform 0.5s ease;
    opacity: 0; visibility: hidden; transform: scale(0.95);
}

.phase.active { opacity: 1; visibility: visible; transform: scale(1); }

.glass-panel { background: var(--glass-bg); backdrop-filter: blur(12px); border: 1px solid var(--glass-border); border-radius: 16px; padding: 1.5rem; }

.glass-btn { padding: 1rem 2rem; font-size: 1.2rem; font-weight: bold; color: white; border: none; border-radius: 12px; cursor: pointer; transition: all 0.3s ease; background: rgba(255, 255, 255, 0.15); border: 1px solid rgba(255,255,255,0.3); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.glass-btn:hover { background: rgba(255, 255, 255, 0.25); transform: translateY(-2px); box-shadow: 0 8px 15px rgba(0,0,0,0.2); }
.glass-btn.primary { background: rgba(59, 130, 246, 0.6); }
.glass-btn.danger { background: rgba(239, 68, 68, 0.6); }
.glass-btn.completed { background: rgba(220, 38, 38, 0.9) !important; border-color: #f87171 !important; color: #fee2e2 !important; }
.glass-btn.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.hidden { display: none !important; }

/* Realistic Gym & Tournament Bracket */
#phase-dodgeball { align-items: center; justify-content: center; text-align: center; background: #222; }

.bracket-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    align-items: center;
    background: rgba(0,0,0,0.4);
    padding: 3rem;
    border-radius: 20px;
    border: 2px solid rgba(255,255,255,0.1);
    position: relative;
    margin-bottom: 2rem;
}

.bracket-level { display: flex; flex-direction: column; gap: 1.5rem; align-items: center; }
.bracket-node {
    background: #334155;
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    min-width: 120px;
    font-weight: bold;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

.winner-node { background: #1e40af; border-color: #3b82f6; }
.loser-node { background: #7f1d1d; border-color: #ef4444; opacity: 0.7; }
.final-node { background: #ca8a04; border-color: #facc15; transform: scale(1.2); box-shadow: 0 0 20px rgba(234, 179, 8, 0.4); }
.survivor-node { background: #14532d; border-color: #22c55e; }

.bracket-connector { background: rgba(255,255,255,0.3); }
.bracket-connector.right-v { width: 2px; height: 30px; }
.bracket-connector.horizontal { width: 40px; height: 2px; }
.bracket-connector.up { width: 2px; height: 40px; }

.gym-court {
    width: 700px;
    height: 500px;
    background: #8b4513; /* Fallback */
    background: 
        linear-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 1px),
        repeating-linear-gradient(90deg, #5c3011, #5c3011 48px, #6b3a16 50px);
    border: 8px solid #334155;
    border-radius: 5px;
    position: relative;
    overflow: hidden;
    box-shadow: 
        inset 0 0 100px rgba(0,0,0,0.5),
        0 20px 50px rgba(0,0,0,0.5);
}

.court-lines {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    border: 10px solid rgba(255,255,255,0.15);
    pointer-events: none;
}

.gym-court::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.net-line {
    position: absolute;
    top: 50%; left: 0; width: 100%; height: 4px;
    background: rgba(255,255,255,0.5);
    border-top: 2px dashed rgba(0,0,0,0.3);
    z-index: 2;
}

/* Battle Royale Specific */
.br-header { width: 700px; }
.br-court-layout { background-color: #4a2c16; }

.koala-dodger {
    position: absolute;
    font-size: 5rem;
    z-index: 10;
    transition: all 0.05s linear;
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.4));
}

.br-char { transition: all 0.1s ease-out; }

#cpu-koala-active { top: 40px; left: 50%; transform: translateX(-50%) rotate(180deg); }
#player-koala-active { bottom: 40px; left: 50%; transform: translateX(-50%); }

.dodgeball-projectile {
    position: absolute;
    font-size: 2.5rem;
    z-index: 5;
    filter: drop-shadow(0 0 15px #facc15);
}

/* Transition Phase */
#phase-transition { justify-content: center; align-items: center; }
.transition-text { font-size: 2rem; margin-bottom: 4rem; text-align: center; color: #cbd5e1; }
.walking-koalas { position: relative; height: 150px; width: 100%; }
.koala-walker { font-size: 6rem; position: absolute; left: -150px; animation: walkStaggered 5s linear forwards; display: inline-block; filter: drop-shadow(0 5px 5px rgba(0,0,0,0.3)); }
#walker-1 { animation-delay: 0s; bottom: 0; }
#walker-2 { animation-delay: 0.3s; bottom: 30px; }

@keyframes walkStaggered {
    0% { transform: translateX(0) translateY(0) rotate(0deg); }
    10% { transform: translateX(11vw) translateY(-15px) rotate(10deg); }
    20% { transform: translateX(22vw) translateY(0) rotate(-10deg); }
    30% { transform: translateX(33vw) translateY(-15px) rotate(10deg); }
    40% { transform: translateX(44vw) translateY(0) rotate(-10deg); }
    50% { transform: translateX(55vw) translateY(-15px) rotate(10deg); }
    60% { transform: translateX(66vw) translateY(0) rotate(-10deg); }
    70% { transform: translateX(77vw) translateY(-15px) rotate(10deg); }
    80% { transform: translateX(88vw) translateY(0) rotate(-10deg); }
    90% { transform: translateX(99vw) translateY(-15px) rotate(10deg); }
    100% { transform: translateX(115vw) translateY(0) rotate(0deg); }
}

/* RPS Phase */
#phase-rps { padding: 0; }
.sky-background { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to bottom, #1e3a8a, #f97316 70%, #450a0a); z-index: 1; }
.scoreboard { position: relative; z-index: 10; display: flex; justify-content: space-between; padding: 2rem; background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent); }
.score-card { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.points { display: flex; gap: 0.5rem; }
.point-circle { width: 20px; height: 20px; border-radius: 50%; background: rgba(255,255,255,0.2); border: 2px solid white; }
.point-circle.won { background: #fde047; box-shadow: 0 0 10px #fde047; }
.score-center { text-align: center; }
.score-center h3 { color: #facc15; font-size: 2rem; }
.score-center p { font-size: 1.2rem; margin-top: 0.5rem; background: rgba(0,0,0,0.5); padding: 0.5rem 1rem; border-radius: 20px; }

.cliff-scene { position: absolute; bottom: 120px; left: 0; width: 100%; height: 400px; z-index: 5; display: flex; justify-content: space-between; align-items: flex-end; }
.cliff-edge { 
    width: 38%; 
    height: 300px; 
    background-image: url('cliff_texture.png'); 
    background-size: cover;
    background-position: center;
    position: absolute; 
    bottom: -150px; 
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    clip-path: polygon(0% 0%, 100% 5%, 95% 100%, 0% 100%);
}
.cliff-edge.left-edge { left: 0; }
.cliff-edge.right-edge { 
    right: 0; 
    clip-path: polygon(0% 5%, 100% 0%, 100% 100%, 5% 100%);
    transform: scaleX(-1); /* Flip texture for variety */
}
.cliff-ground { position: absolute; bottom: 0; left: 0; width: 100%; height: 120px; background: linear-gradient(to bottom, #111, #000); z-index: 4; }

.character-container { position: absolute; bottom: 30px; display: flex; flex-direction: column; align-items: center; width: 120px; transition: all 0.3s ease; }
.character-container#player-char-container { left: 15%; }
.character-container#cpu-char-container { right: 15%; }
.koala-char { font-size: 6rem; filter: drop-shadow(0 10px 10px rgba(0,0,0,0.5)); }

.speech-bubble { background: white; color: black; padding: 0.8rem 1.2rem; border-radius: 20px; font-weight: bold; font-size: 1.4rem; position: absolute; top: -60px; white-space: nowrap; transition: opacity 0.3s; z-index: 20;}
.speech-bubble::after { content: ''; position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); border-width: 10px 10px 0; border-style: solid; border-color: white transparent transparent transparent; }

.rps-battle-display { position: absolute; bottom: 200px; width: 100%; display: flex; justify-content: center; gap: 150px; pointer-events: none; z-index: 10;}
.choice-emoji { font-size: 5rem; opacity: 0; transform: translateY(20px); transition: all 0.3s; }
.choice-emoji.show { opacity: 1; transform: translateY(0) scale(1.2); }

.controls { position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%); z-index: 10; display: flex; gap: 1rem; width: 80%; justify-content: center; }
.rps-btn { font-size: 1.5rem; padding: 1rem 2rem; border-radius: 16px; border: none; background: rgba(255,255,255,0.2); color: white; cursor: pointer; backdrop-filter: blur(5px); border: 1px solid rgba(255,255,255,0.4); transition: all 0.2s; }
.rps-btn:hover { background: rgba(255,255,255,0.3); transform: translateY(-5px) scale(1.05); }

/* Animation FX */
/* Updated Forward Jump Falling FX */
.falling { animation: jumpAndFall 2.8s cubic-bezier(0.42, 0, 0.58, 1) forwards; }
@keyframes jumpAndFall {
    0% { transform: translateY(0) translateX(0) rotate(0); }
    15% { transform: translateY(-150px) translateX(100px) rotate(30deg); }
    30% { transform: translateY(-100px) translateX(200px) rotate(90deg); }
    100% { transform: translateY(1200px) translateX(400px) rotate(720deg) scale(0.1); opacity: 0; }
}

.falling.right-char { animation: jumpAndFallRight 2.8s cubic-bezier(0.42, 0, 0.58, 1) forwards; }
@keyframes jumpAndFallRight {
    0% { transform: translateY(0) translateX(0) rotate(0); }
    15% { transform: translateY(-150px) translateX(-100px) rotate(-30deg); }
    30% { transform: translateY(-100px) translateX(-200px) rotate(-90deg); }
    100% { transform: translateY(1200px) translateX(-400px) rotate(-720deg) scale(0.1); opacity: 0; }
}

.shake { animation: screenShake 0.6s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes screenShake {
    10%, 90% { transform: translate3d(-2px, 2px, 0); }
    20%, 80% { transform: translate3d(4px, -2px, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 4px, 0); }
    40%, 60% { transform: translate3d(6px, -4px, 0); }
}

/* GameOver Phase */
#phase-gameover { justify-content: center; align-items: center; z-index: 100; background: rgba(0,0,0,0.8); }
.gameover-modal { text-align: center; max-width: 500px; padding: 3rem;}
.gameover-modal h1 { font-size: 4rem; margin-bottom: 1rem; color: #f87171; }
.gameover-modal p { font-size: 1.5rem; margin-bottom: 2rem; color: #e2e8f0; }
