/* ===================================================================
   සංස්කෘත අකුරු ක්‍රීඩාව - සම්පූර්ණ CSS (Fixed & Enhanced)
   Version: 2.0 - All Click Issues Fixed + Beautiful Animations
   =================================================================== */

/* ============ 1. GENERAL RESET ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans Sinhala', sans-serif;
    background: radial-gradient(circle at top, #2e0249 0%, #570a57 50%, #1a0033 100%);
    background-attachment: fixed;
    color: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ============ 2. SCREEN MANAGEMENT (Critical Fix) ============ */
.screen {
    display: none; /* Hide by default */
    width: 100%;
    min-height: 100vh;
    padding: 20px;
    animation: fadeIn 0.5s ease-in-out;
    text-align: center;
    position: relative;
    z-index: 1;
}

/* Active screen එක show කරන්න */
.screen.active {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Fade In Animation */
@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: scale(0.95) translateY(20px); 
    }
    to { 
        opacity: 1; 
        transform: scale(1) translateY(0); 
    }
}

/* ============ 3. LOGIN BOX / RULES BOX / RESULT BOX ============ */
.login-box, .rules-box, .result-box {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
    padding: 40px;
    border-radius: 30px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 8px rgba(169, 16, 121, 0.2);
    max-width: 650px;
    width: 100%;
    color: #333;
    border: 5px solid #a91079;
    margin: auto;
    position: relative;
    z-index: 10;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from { 
        opacity: 0; 
        transform: translateY(50px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

.login-box h1, .rules-box h1, .result-box h1 {
    font-family: 'Chewy', cursive;
    color: #a91079;
    font-size: 2.5rem;
    margin-bottom: 25px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============ 4. RULES BOX SPECIFIC STYLES ============ */
.rules-box {
    max-width: 700px;
}

.rule-item {
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    border-left: 5px solid #a91079;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: left;
}

.rule-item h3 {
    color: #a91079;
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.rule-item p {
    color: #555;
    line-height: 1.6;
    font-size: 1.05rem;
}

/* ============ 5. FORM ELEMENTS ============ */
.section-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #a91079;
    margin-top: 20px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-label {
    color: #570a57;
    font-weight: bold;
    display: block;
    margin-bottom: 8px;
    text-align: left;
    font-size: 1rem;
}

.form-control, .form-select {
    border-radius: 12px;
    padding: 12px 15px;
    border: 2px solid #ddd;
    margin-bottom: 15px;
    width: 100%;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: white;
}

.form-control:focus, .form-select:focus {
    border-color: #a91079;
    outline: none;
    box-shadow: 0 0 0 3px rgba(169, 16, 121, 0.1);
}

.form-control:hover, .form-select:hover {
    border-color: #a91079;
}

/* ============ 6. GAME SCREEN LAYOUT ============ */
.game-content {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ============ 7. GAME HEADER (Score/Timer/Question Number) ============ */
.game-header {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    width: 100%;
    max-width: 800px;
    justify-content: center;
    flex-wrap: wrap;
}

.stat-box {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.08));
    backdrop-filter: blur(15px);
    padding: 15px 25px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    text-align: center;
    min-width: 140px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
}

.stat-box:hover {
    transform: translateY(-3px);
}

.stat-box .label {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #f1c40f;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 5px;
}

.stat-box .value {
    font-size: 1.8rem;
    font-weight: 900;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.timer {
    font-size: 2rem;
    font-weight: 900;
    color: #2ecc71;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* ============ 8. INSTRUCTION TEXT ============ */
.instruction {
    font-size: 1.3rem;
    font-weight: bold;
    color: #f1c40f;
    margin-bottom: 25px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

/* ============ 9. QUESTION BOX ============ */
.question-box {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    width: 90%;
    max-width: 450px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 40px;
    margin: 0 auto 40px auto;
    box-shadow: 
        0 15px 0px #a91079, 
        0 20px 50px rgba(0, 0, 0, 0.4),
        inset 0 2px 10px rgba(255, 255, 255, 0.8);
    position: relative;
    overflow: hidden;
}

.question-box::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

.question-letter {
    font-size: 6rem;
    color: #2e0249;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 2;
}

/* ============ 10. OPTIONS GRID (Critical - Click Fix) ============ */
.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    position: relative;
    z-index: 20; /* Ensure buttons are on top */
}

/* ============ 11. OPTION BUTTONS (Critical - Click Fix) ============ */
.option-btn {
    background: linear-gradient(145deg, #ffffff, #f5f5f5);
    color: #2e0249;
    border: 3px solid #ddd;
    padding: 25px 20px;
    font-size: 2.5rem;
    font-weight: bold;
    border-radius: 20px;
    cursor: pointer; /* Critical for clickability */
    transition: all 0.2s ease;
    box-shadow: 
        0 8px 0px #bbb,
        0 10px 20px rgba(0, 0, 0, 0.2);
    width: 100%;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto; /* Critical - ensures clicks work */
    position: relative;
    user-select: none;
}

.option-btn:hover:not(:disabled) {
    transform: translateY(-6px);
    background: linear-gradient(145deg, #f8f9fa, #ffffff);
    border-color: #a91079;
    box-shadow: 
        0 12px 0px #a91079,
        0 15px 30px rgba(169, 16, 121, 0.3);
}

.option-btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 
        0 2px 0px #999,
        0 4px 10px rgba(0, 0, 0, 0.2);
}

.option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Correct Answer Style */
.option-btn.correct {
    background: linear-gradient(145deg, #2ecc71, #27ae60) !important;
    color: white !important;
    border-color: #27ae60 !important;
    animation: correctPulse 0.6s ease;
    box-shadow: 
        0 8px 0px #1e8449,
        0 0 30px rgba(46, 204, 113, 0.6) !important;
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Wrong Answer Style */
.option-btn.wrong {
    background: linear-gradient(145deg, #e74c3c, #c0392b) !important;
    color: white !important;
    border-color: #c0392b !important;
    animation: shake 0.5s ease;
    box-shadow: 
        0 8px 0px #922b21,
        0 0 30px rgba(231, 76, 60, 0.6) !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* ============ 12. BUTTONS (General) ============ */
.btn {
    border: none;
    padding: 14px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(145deg, #a91079, #8a0c5f);
    color: white;
    box-shadow: 0 6px 0px #570a57, 0 8px 20px rgba(169, 16, 121, 0.4);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 0px #570a57, 0 12px 25px rgba(169, 16, 121, 0.5);
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0px #570a57, 0 4px 10px rgba(169, 16, 121, 0.4);
}

.btn-lg {
    padding: 18px 40px;
    font-size: 1.3rem;
}

.btn-warning {
    background: linear-gradient(145deg, #f39c12, #e67e22);
    color: white;
    box-shadow: 0 6px 0px #c87f0a, 0 8px 20px rgba(243, 156, 18, 0.4);
}

.btn-warning:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 0px #c87f0a, 0 12px 25px rgba(243, 156, 18, 0.5);
}

.btn-info {
    background: linear-gradient(145deg, #3498db, #2980b9);
    color: white;
    box-shadow: 0 6px 0px #1f5f8b, 0 8px 20px rgba(52, 152, 219, 0.4);
}

.btn-info:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 0px #1f5f8b, 0 12px 25px rgba(52, 152, 219, 0.5);
}

.btn-outline-secondary {
    background: transparent;
    color: #666;
    border: 3px solid #666;
    box-shadow: none;
}

.btn-outline-secondary:hover {
    background: #666;
    color: white;
}

.btn-outline-primary {
    background: transparent;
    color: #a91079;
    border: 3px solid #a91079;
    box-shadow: none;
}

.btn-outline-primary:hover {
    background: #a91079;
    color: white;
}

/* ============ 13. ALERTS ============ */
.alert {
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    font-size: 1.05rem;
    line-height: 1.6;
}

.alert-success {
    background: linear-gradient(145deg, #d4edda, #c3e6cb);
    border: 2px solid #28a745;
    color: #155724;
}

.alert-danger {
    background: linear-gradient(145deg, #f8d7da, #f5c6cb);
    border: 2px solid #dc3545;
    color: #721c24;
}

/* ============ 14. RESULT BOX SPECIFIC ============ */
.result-stats {
    text-align: left;
    line-height: 2;
}

.result-stats .stat {
    font-size: 1.15rem;
    color: #333;
    border-bottom: 1px solid #eee;
    padding: 10px 0;
}

.result-stats .stat:last-child {
    border-bottom: none;
}

/* ============ 15. ANIMATIONS ============ */
@keyframes questionPop {
    0% { 
        transform: scale(0.7) rotate(-5deg); 
        opacity: 0; 
    }
    50% { 
        transform: scale(1.05) rotate(2deg); 
    }
    100% { 
        transform: scale(1) rotate(0deg); 
        opacity: 1; 
    }
}

.question-box-animated {
    animation: questionPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.timer-warning {
    animation: pulseRed 1s infinite;
    color: #ff4757 !important;
}

@keyframes pulseRed {
    0%, 100% { 
        transform: scale(1); 
        filter: brightness(1);
    }
    50% { 
        transform: scale(1.15); 
        filter: brightness(1.3);
    }
}

/* ============ 16. UTILITY CLASSES ============ */
.text-center { text-align: center; }
.text-start { text-align: left; }
.text-primary { color: #a91079 !important; }
.text-success { color: #28a745 !important; }
.text-danger { color: #dc3545 !important; }
.text-white { color: white !important; }

.fw-bold { font-weight: bold; }
.shadow-sm { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }
.shadow { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); }
.shadow-lg { box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3); }

.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 1rem; padding-bottom: 1rem; }
.px-4 { padding-left: 1.5rem; padding-right: 1.5rem; }
.px-5 { padding-left: 3rem; padding-right: 3rem; }
.p-4 { padding: 1.5rem; }

.w-100 { width: 100%; }
.d-grid { display: grid; }
.gap-2 { gap: 0.5rem; }

.rounded-4 { border-radius: 20px; }
.bg-light { background-color: #f8f9fa; }
.border-0 { border: none; }

/* ============ 17. RESPONSIVE DESIGN ============ */

/* Tablet - 768px to 1024px */
@media (max-width: 1024px) {
    .login-box, .rules-box, .result-box {
        padding: 30px;
        max-width: 90%;
    }
    
    .question-letter {
        font-size: 5rem;
    }
    
    .option-btn {
        font-size: 2.2rem;
        padding: 20px 15px;
    }
}

/* Mobile - 481px to 767px */
@media (max-width: 767px) {
    body {
        padding: 10px;
    }
    
    .login-box, .rules-box, .result-box {
        padding: 25px;
        border-radius: 20px;
    }
    
    .login-box h1, .rules-box h1 {
        font-size: 1.8rem;
    }
    
    .game-header {
        gap: 10px;
    }
    
    .stat-box {
        min-width: 100px;
        padding: 10px 15px;
    }
    
    .stat-box .value, .timer {
        font-size: 1.4rem;
    }
    
    .question-box {
        height: 160px;
        max-width: 95%;
    }
    
    .question-letter {
        font-size: 4rem;
    }
    
    .instruction {
        font-size: 1.1rem;
        padding: 8px 15px;
    }
    
    .options-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        max-width: 95%;
    }
    
    .option-btn {
        padding: 18px 12px;
        font-size: 2rem;
        min-height: 85px;
    }
    
    .btn-lg {
        padding: 14px 30px;
        font-size: 1.1rem;
    }
}

/* Small Mobile - up to 480px */
@media (max-width: 480px) {
    .login-box, .rules-box, .result-box {
        padding: 20px;
        border: 3px solid #a91079;
    }
    
    .login-box h1, .rules-box h1 {
        font-size: 1.6rem;
        margin-bottom: 20px;
    }
    
    .question-box {
        height: 140px;
        border-radius: 30px;
    }
    
    .question-letter {
        font-size: 3.5rem;
    }
    
    .options-grid {
        gap: 10px;
    }
    
    .option-btn {
        padding: 15px 10px;
        font-size: 1.8rem;
        min-height: 75px;
        border-radius: 15px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 1rem;
    }
    
    .btn-lg {
        padding: 12px 25px;
        font-size: 1rem;
    }
}

/* Extra Small Mobile - up to 360px */
@media (max-width: 360px) {
    .options-grid {
        grid-template-columns: 1fr; /* Single column on very small screens */
        max-width: 100%;
    }
    
    .option-btn {
        font-size: 2rem;
        min-height: 70px;
    }
    
    .question-letter {
        font-size: 3rem;
    }
}

/* ============ 18. LANDSCAPE MODE (Mobile) ============ */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        min-height: auto;
        padding: 10px;
    }
    
    .question-box {
        height: 120px;
        margin-bottom: 20px;
    }
    
    .question-letter {
        font-size: 3rem;
    }
    
    .game-header {
        margin-bottom: 15px;
    }
    
    .options-grid {
        gap: 8px;
    }
    
    .option-btn {
        min-height: 60px;
        padding: 10px;
        font-size: 1.6rem;
    }
}

/* ============ 19. PRINT STYLES ============ */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .screen:not(.active) {
        display: none !important;
    }
    
    .btn {
        display: none;
    }
}

/* ============ 20. ACCESSIBILITY ============ */
.option-btn:focus-visible {
    outline: 4px solid #f1c40f;
    outline-offset: 4px;
}

.btn:focus-visible {
    outline: 3px solid #f1c40f;
    outline-offset: 3px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============ END OF CSS ============ */