* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Oswald', 'Bebas Neue', sans-serif;
    background: #0a0806;
    overflow: hidden;
    color: #fff;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

#scene-container {
    width: 100%;
    height: 100%;
}

#scene-container canvas {
    display: block;
}

.screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, rgba(30, 25, 15, 0.95) 0%, rgba(8, 6, 4, 0.98) 70%);
    z-index: 100;
    backdrop-filter: blur(8px);
}

.hidden { display: none !important; }

.title-container {
    text-align: center;
    margin-bottom: 2.5rem;
}

.game-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(3rem, 10vw, 6rem);
    color: #d4af37;
    text-shadow: 0 0 40px rgba(212, 175, 55, 0.3), 0 4px 8px rgba(0,0,0,0.5);
    letter-spacing: 0.15em;
    line-height: 1;
}

.title-subtitle {
    font-family: 'Oswald', sans-serif;
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    color: rgba(212, 175, 55, 0.6);
    letter-spacing: 0.3em;
    margin-top: 0.5rem;
    font-weight: 300;
}

.player-inputs {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.input-group label {
    font-size: 1rem;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.2em;
}

.input-group input {
    padding: 0.8rem 1.2rem;
    font-size: 1.1rem;
    font-family: 'Oswald', sans-serif;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 4px;
    color: #fff;
    text-align: center;
    width: 180px;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #d4af37;
    background: rgba(255,255,255,0.08);
}

.arcade-btn {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-family: 'Bebas Neue', sans-serif;
    background: linear-gradient(180deg, #2a6a2a 0%, #1a4a1a 100%);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 4px;
    color: #d4af37;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

.arcade-btn:hover {
    background: linear-gradient(180deg, #3a8a3a 0%, #2a6a2a 100%);
    box-shadow: 0 4px 20px rgba(42, 106, 42, 0.3);
    transform: translateY(-1px);
}

.arcade-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.arcade-btn.secondary {
    background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
    border-color: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
}

.arcade-btn.secondary:hover {
    background: linear-gradient(180deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.08) 100%);
}

.rules-btn-small {
    margin-top: 0.8rem;
    padding: 0.6rem 1.5rem !important;
    font-size: 0.9rem !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal.hidden { display: none; }

.modal-content {
    background: linear-gradient(180deg, #1a1812 0%, #0d0b08 100%);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 8px;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(212, 175, 55, 0.05);
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
    position: absolute;
    top: 10px; right: 15px;
    background: none; border: none;
    color: rgba(255,255,255,0.4);
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.modal-close:hover { color: #ef4444; }

.rules-title, .graphics-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.8rem;
    color: #d4af37;
    text-align: center;
    margin-bottom: 1.5rem;
    letter-spacing: 0.1em;
}

.rules-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(255,255,255,0.02);
    border-left: 2px solid #d4af37;
    border-radius: 0 4px 4px 0;
}

.rules-section h3 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.1rem;
    color: #d4af37;
    margin-bottom: 0.6rem;
    letter-spacing: 0.1em;
}

.rules-section p, .rules-section li {
    font-family: 'Oswald', sans-serif;
    font-size: 0.95rem;
    color: rgba(255,255,255,0.8);
    line-height: 1.6;
    font-weight: 300;
}

.rules-section ul {
    list-style: none; padding: 0;
}

.rules-section li {
    padding: 0.3rem 0 0.3rem 1.5rem;
    position: relative;
}

.rules-section li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: #d4af37;
}

.rules-section li strong { color: #fbbf24; }

.foul-penalty {
    margin-top: 0.8rem;
    padding: 0.5rem;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 4px;
    color: #fca5a5 !important;
    text-align: center;
}

/* Graphics Modal */
.graphics-content { max-width: 400px; padding: 1.5rem 2rem; }

.graphics-section { display: flex; flex-direction: column; gap: 1rem; }

.graphics-option {
    padding: 0.8rem 1rem;
    background: rgba(255,255,255,0.02);
    border-left: 2px solid #d4af37;
    border-radius: 0 4px 4px 0;
}

.toggle-label, .select-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-family: 'Oswald', sans-serif;
    font-size: 1rem;
    color: rgba(255,255,255,0.85);
    font-weight: 300;
}

.toggle-label input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
    position: relative;
    width: 44px; height: 24px;
    background: #333;
    border: 1px solid #555;
    border-radius: 12px;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    background: #888;
    border-radius: 50%;
    top: 2px; left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.toggle-label input:checked + .toggle-slider {
    background: #1a5c28;
    border-color: #4ade80;
}

.toggle-label input:checked + .toggle-slider::after {
    transform: translateX(20px);
    background: #4ade80;
}

.graphics-select {
    background: rgba(0,0,0,0.4);
    color: #d4af37;
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    font-family: 'Oswald', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

.graphics-select:focus { border-color: #d4af37; }

.graphics-select option { background: #111; color: #d4af37; }

.graphics-footer {
    text-align: center;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.3);
    font-size: 0.75rem;
    font-family: 'Oswald', sans-serif;
    font-weight: 300;
}

/* Scrollbar */
.modal-content::-webkit-scrollbar { width: 6px; }
.modal-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.modal-content::-webkit-scrollbar-thumb { background: rgba(212, 175, 55, 0.3); border-radius: 3px; }

/* Game UI */
#game-ui {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.5rem;
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    backdrop-filter: blur(4px);
    opacity: 0.5;
    transition: all 0.3s;
}

.player-info.active {
    opacity: 1;
    border-color: rgba(212, 175, 55, 0.4);
    background: rgba(0,0,0,0.6);
}

.player-name {
    font-family: 'Bebas Neue', sans-serif;
    font-weight: 400;
    font-size: 1.4rem;
    letter-spacing: 0.05em;
}

.ball-type {
    font-family: 'Oswald', sans-serif;
    font-size: 0.9rem;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    background: rgba(0,0,0,0.4);
    white-space: nowrap;
    font-weight: 300;
}

.ball-type.solids-type { color: #ffd700; border: 1px solid rgba(255,215,0,0.3); }
.ball-type.stripes-type { color: #60a5fa; border: 1px solid rgba(96,165,250,0.3); }
.ball-type.open-type { color: rgba(255,255,255,0.4); font-style: italic; }
.remaining-count { opacity: 0.7; }

#turn-display { text-align: center; }

#current-turn {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.5rem;
    letter-spacing: 0.1em;
    padding: 0.4rem 1.2rem;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

#current-turn.p1-turn { color: #ef4444; }
#current-turn.p2-turn { color: #60a5fa; }

#power-meter {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 200px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    overflow: hidden;
    backdrop-filter: blur(4px);
}

#power-fill {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%; height: 0%;
    background: #4ade80;
    transition: height 0.03s linear, background-color 0.1s;
    border-radius: 2px;
}

#power-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Oswald', sans-serif;
    font-size: 0.6rem;
    font-weight: 300;
    color: rgba(255,255,255,0.4);
    white-space: nowrap;
    letter-spacing: 0.15em;
}

/* Crosshair */
#crosshair {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 15;
}

.crosshair-dot {
    width: 3px; height: 3px;
    background: rgba(255,255,255,0.8);
    border-radius: 50%;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 6px rgba(255,255,255,0.3);
}

.crosshair-ring {
    width: 28px; height: 28px;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
}

.crosshair-ring::before, .crosshair-ring::after {
    content: '';
    position: absolute;
    background: rgba(255,255,255,0.3);
}

.crosshair-ring::before {
    width: 12px; height: 1px;
    top: 50%; left: -16px;
    transform: translateY(-50%);
}

.crosshair-ring::after {
    width: 12px; height: 1px;
    top: 50%; right: -16px;
    transform: translateY(-50%);
}

#game-ui.top-view #crosshair { display: none; }

#controls-hint {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Oswald', sans-serif;
    font-size: 0.75rem;
    font-weight: 300;
    color: rgba(255,255,255,0.35);
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 0.5rem 1rem;
    text-align: center;
    line-height: 1.5;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}

#controls-hint.hints-hidden { opacity: 0; visibility: hidden; }

#controls-hint-mobile {
    font-family: 'Oswald', sans-serif;
    font-size: 0.6rem;
    font-weight: 300;
    color: rgba(255,255,255,0.35);
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    text-align: center;
    display: none;
    order: 3;
    transition: opacity 0.3s;
}

#controls-hint-mobile.hints-hidden { opacity: 0; visibility: hidden; }

/* Mobile power meter */
#power-meter-mobile {
    display: none;
    order: 1;
    position: relative;
    height: 10px;
    width: 130px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 5px;
    overflow: hidden;
}

#power-fill-mobile {
    position: absolute;
    bottom: 0; left: 0;
    width: 0%; height: 100%;
    background: #4ade80;
    transition: width 0.03s linear, background-color 0.1s;
    border-radius: 4px;
}

#power-label-mobile {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Oswald', sans-serif;
    font-size: 0.55rem;
    font-weight: 300;
    color: rgba(255,255,255,0.4);
    white-space: nowrap;
    letter-spacing: 0.15em;
}

#message-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    padding: 1rem 2rem;
    border: 1px solid #d4af37;
    border-radius: 6px;
    backdrop-filter: blur(8px);
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#message-text {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.3rem;
    color: #d4af37;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Ball notifications */
.ball-pocketed-notification {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0,0,0,0.8);
    border: 1px solid #d4af37;
    border-radius: 6px;
    padding: 12px 20px;
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.2s;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.ball-pocketed-notification.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.ball-pocketed-notification:nth-child(2) { top: calc(50% + 70px); }
.ball-pocketed-notification:nth-child(3) { top: calc(50% + 140px); }

.pocketed-ball-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Bebas Neue', sans-serif;
    font-size: 18px;
    color: #000;
    box-shadow: inset -2px -2px 4px rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.3);
    position: relative;
}

.pocketed-ball-icon .stripe-mark {
    position: absolute;
    width: 100%; height: 8px;
    background: #fff;
    top: 50%; left: 0;
    transform: translateY(-50%);
    opacity: 0.85;
    border-radius: 0;
}

.pocketed-text {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.2rem;
    color: #d4af37;
    letter-spacing: 0.1em;
}

/* Game Over */
#game-over-screen {
    background: radial-gradient(ellipse at center, rgba(30, 25, 15, 0.95) 0%, rgba(8, 6, 4, 0.98) 70%);
}

.winner-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2rem, 8vw, 4rem);
    color: #d4af37;
    text-shadow: 0 0 40px rgba(212, 175, 55, 0.4);
    margin-bottom: 2rem;
    animation: winnerPulse 2s ease-in-out infinite;
    letter-spacing: 0.1em;
}

@keyframes winnerPulse {
    0%, 100% { transform: scale(1); text-shadow: 0 0 40px rgba(212, 175, 55, 0.4); }
    50% { transform: scale(1.03); text-shadow: 0 0 60px rgba(212, 175, 55, 0.6); }
}

.final-stats {
    background: rgba(255,255,255,0.05);
    padding: 1.5rem 3rem;
    border-radius: 6px;
    border: 1px solid rgba(212, 175, 55, 0.2);
    margin-bottom: 2rem;
    backdrop-filter: blur(4px);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 3rem;
    padding: 0.5rem 0;
    font-family: 'Oswald', sans-serif;
    font-size: 1rem;
    font-weight: 300;
}

.end-buttons { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }

.confetti-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    width: 8px; height: 8px;
    border-radius: 1px;
    animation: confettiFall 3s linear infinite;
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

footer {
    position: fixed;
    bottom: 0.5rem;
    right: 1rem;
    z-index: 1000;
}

footer a {
    color: rgba(255,255,255,0.2);
    text-decoration: none;
    font-size: 0.7rem;
    font-family: 'Oswald', sans-serif;
    font-weight: 300;
    transition: color 0.3s;
}

footer a:hover { color: rgba(255,255,255,0.5); }

/* Mobile Controls */
.mobile-controls { display: none; }

#mobile-controls {
    display: none;
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 200px;
    pointer-events: none;
    z-index: 20;
}

#shoot-btn-zone {
    position: absolute;
    right: 20px;
    bottom: 30px;
    pointer-events: auto;
}

#shoot-btn {
    width: 100px; height: 50px;
    border-radius: 6px;
    background: linear-gradient(180deg, #c41e1e 0%, #8a1010 100%);
    border: 1px solid rgba(255,100,100,0.4);
    color: #fff;
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: all 0.1s;
    letter-spacing: 0.1em;
}

#shoot-btn:active, #shoot-btn.charging {
    transform: translateY(2px);
    background: linear-gradient(180deg, #ff4444 0%, #c41e1e 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

#top-view-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 20px;
    width: 100px; height: 36px;
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
    font-family: 'Bebas Neue', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.1s;
    letter-spacing: 0.1em;
}

#top-view-btn:active, #top-view-btn.active {
    background: rgba(42, 106, 42, 0.4);
    border-color: rgba(74, 222, 128, 0.4);
    color: #4ade80;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    #top-bar {
        flex-direction: column;
        gap: 0.3rem;
        padding: 0.4rem 0.8rem;
    }
    
    .player-info { padding: 0.25rem 0.5rem; }
    .player-name { font-size: 1rem; }
    
    #mobile-controls {
        display: flex;
        flex-direction: column;
        align-items: center;
        bottom: 70px;
        gap: 8px;
    }
    
    #top-view-btn {
        order: 4;
        position: static;
        transform: none !important;
        width: 140px; height: 44px;
        font-size: 0.8rem;
    }
    
    #controls-hint { display: none !important; }
    #controls-hint-mobile { display: block; order: 3; }
    
    #shoot-btn {
        width: 140px !important;
        height: 64px !important;
        font-size: 0.9rem !important;
    }
    
    #power-meter-mobile {
        width: 180px !important;
        height: 16px !important;
    }
    
    #shoot-btn-zone { order: 2; position: static; }
    #power-meter { display: none !important; }
    #power-meter-mobile { display: block; order: 1; }
    
    .desktop-controls { display: none; }
    .mobile-controls { display: inline; }
    
    .player-inputs { gap: 1rem; }
    .input-group input { width: 140px; }
    .arcade-btn { padding: 0.8rem 2rem; font-size: 1rem; }
    
    #current-turn { font-size: 1rem; padding: 0.3rem 0.8rem; }
}

@media (max-width: 480px) {
    #mobile-controls { bottom: 60px; gap: 6px; }
    #shoot-btn { width: 120px !important; height: 54px !important; }
    #top-view-btn { width: 120px !important; height: 38px !important; }
    #power-meter-mobile { width: 150px !important; height: 14px !important; }
    .player-name { font-size: 0.85rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
    #mobile-controls { bottom: 40px; gap: 4px; }
    #shoot-btn { width: 100px !important; height: 44px !important; font-size: 0.7rem !important; }
    #top-view-btn { width: 100px !important; height: 32px !important; font-size: 0.65rem !important; }
    #top-bar { flex-direction: row; padding: 0.3rem 0.5rem; }
}