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

:root {
    --table-green: #0a4d0a;
    --table-dark: #063306;
    --ball-white: #ffffff;
    --ball-cue: #f0f0f0;
    --ball-red: #e74c3c;
    --ball-blue: #3498db;
    --ball-yellow: #f1c40f;
    --ball-purple: #9b59b6;
    --ball-orange: #e67e22;
    --ball-black: #2c3e50;
    --ball-pink: #ff6b9d;
    --ball-teal: #1abc9c;
    --accent: #27ae60;
    --text-light: #ecf0f1;
    --card-bg: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--table-dark);
    color: var(--text-light);
}

.game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, var(--table-green) 0%, var(--table-dark) 100%);
}

.game-header {
    min-height: 80px;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.game-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(90deg, #fff, #ffd700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stats-bar {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 10px;
    min-width: 80px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffd700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 15px 20px;
    gap: 15px;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: var(--table-green);
    border-radius: 20px;
    border: 8px solid #4a2c2a;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.5), var(--shadow);
    overflow: hidden;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay {
    position: absolute;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 15px;
    border-radius: 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.overlay.show {
    opacity: 1;
}

.power-bar-container {
    width: 10px;
    height: 150px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 10px;
}

.power-bar {
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #2ecc71, #f1c40f, #e74c3c);
    position: absolute;
    bottom: 0;
    left: 0;
    transition: height 0.1s;
    border-radius: 5px;
}

.power-text {
    font-size: 0.8rem;
    text-align: center;
}

.math-panel {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border-radius: 15px;
    padding: 15px 20px;
    border: 2px solid var(--accent);
    max-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.math-question {
    flex: 1;
}

.math-question h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #ffd700;
}

.question-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.question-option {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.question-option:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.question-option.correct {
    background: #2ecc71;
    border-color: #27ae60;
}

.question-option.incorrect {
    background: #e74c3c;
    border-color: #c0392b;
}

.math-hint p {
    font-size: 0.8rem;
    text-align: center;
    opacity: 0.8;
    margin-top: 8px;
}

.math-panel.hidden {
    display: none;
}

.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.3);
}

.instructions .help-btn {
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.instructions .help-btn:hover {
    background: #219150;
}

.controls-hint {
    font-size: 0.85rem;
    opacity: 0.8;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    padding: 30px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border: 2px solid var(--accent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.modal-close:hover {
    opacity: 1;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #ffd700;
}

.help-section {
    margin: 15px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    border-left: 4px solid var(--accent);
}

.help-section h3 {
    margin-bottom: 10px;
    color: var(--accent);
}

.help-section p, .help-section li {
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 5px 0;
}

.help-section ul {
    margin-left: 20px;
}

.modal-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 20px;
    transition: background 0.2s;
}

.modal-btn:hover {
    background: #219150;
}

.final-score {
    text-align: center;
    margin: 20px 0;
}

.final-score p {
    font-size: 1.1rem;
    margin: 10px 0;
}

.final-score span {
    color: #ffd700;
    font-weight: 700;
}

@media (max-width: 768px) {
    .game-header h1 {
        font-size: 1.4rem;
    }
    
    .stat-item {
        min-width: 60px;
        padding: 6px 12px;
    }
    
    .stats-bar {
        gap: 10px;
    }
    
    .overlay {
        left: 10px;
    }
    
    .math-panel {
        max-height: 120px;
        padding: 12px 15px;
    }
    
    .math-question h3 {
        font-size: 0.95rem;
    }
    
    .question-option {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
    
    .modal-content {
        padding: 20px;
    }
}