/* General Resets and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    /* background-color: var(--tg-theme-bg-color); */
    /* color: var(--tg-theme-text-color); */
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background-color: #fff; /* Fallback */
    /* background-color: var(--tg-theme-secondary-bg-color, #fff); */
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Screen Styles */
.screen {
    display: none; /* Initially hidden */
    flex-direction: column;
    align-items: center;
    /* justify-content: center; /* Removed to allow natural flow, add per-screen if needed */
    padding: 20px;
    width: 100%;
}

.screen.active {
    display: flex; /* Show active screen */
}

/* Start Screen */
#topic-screen h1, /* Corrected from #start-screen if your HTML ID is topic-screen */
#start-screen h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    /* color: var(--tg-theme-text-color, #2c3e50); */
    margin-bottom: 10px;
    text-align: center;
}

#topic-screen h2, /* Corrected from #start-screen */
#start-screen h2 {
    font-size: 1.8rem;
    color: #3498db;
    /* color: var(--tg-theme-link-color, #3498db); */
    margin-bottom: 30px;
    text-align: center;
}

#topic-screen p, /* Corrected from #start-screen */
#start-screen p {
    font-size: 1.2rem;
    margin-bottom: 20px;
    text-align: center;
    /* color: var(--tg-theme-hint-color, #333); */
}

.subtopics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    width: 100%;
    margin-bottom: 20px;
}

.subtopic-btn {
    padding: 15px;
    background-color: #3498db;
    /* background-color: var(--tg-theme-button-color, #3498db); */
    color: white;
    /* color: var(--tg-theme-button-text-color, white); */
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s; /* Added box-shadow transition */
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* PAPER STYLE */
}

.subtopic-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); /* Enhanced shadow */
}

.subtopic-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.subtopic-btn.all-topics {
    grid-column: 1 / -1;
    background-color: #2c3e50;
}

.subtopic-btn.all-topics:hover {
    background-color: #1a252f;
}

/* Quiz Screen (#subtopic-screen) */
#subtopic-screen #subtopic-title { /* Targeting h2 inside subtopic screen */
    font-size: 1.8rem;
    color: #2c3e50;
    /* color: var(--tg-theme-text-color, #2c3e50); */
    margin-bottom: 15px;
    text-align: center;
}

.progress-container {
    width: 100%;
    height: 10px;
    background-color: #ecf0f1;
    /* background-color: var(--tg-theme-secondary-bg-color, #ecf0f1); */
    border-radius: 5px;
    margin-bottom: 10px;
    overflow: hidden;
}

.progress-bar { /* For #progress-bar */
    height: 100%;
    background-color: #3498db;
    /* background-color: var(--tg-theme-link-color, #3498db); */
    width: 0%; /* Initial width, JS will update */
    transition: width 0.3s ease;
}

.quiz-header { /* Container for question number and score */
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    font-size: 1.1rem;
    color: #7f8c8d;
    /* color: var(--tg-theme-hint-color, #7f8c8d); */
}

#question-container {
    width: 100%;
    margin-bottom: 20px;
}

#question-text {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: #2c3e50;
    /* color: var(--tg-theme-text-color, #2c3e50); */
    text-align: center; /* Or left if preferred for questions */
}

.btn-grid { /* For #answer-buttons */
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.answer-btn {
    padding: 15px;
    background-color: #ecf0f1;
    /* background-color: var(--tg-theme-secondary-bg-color, #ecf0f1); */
    border: 1px solid #bdc3c7; /* Slightly less prominent border */
    /* border: 1px solid var(--tg-theme-hint-color, #bdc3c7); */
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s, border-color 0.3s, color 0.3s, transform 0.2s, box-shadow 0.3s; /* Added transitions */
    text-align: left;
    color: #333;
    /* color: var(--tg-theme-text-color, #333); */
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); /* Subtle paper style */
}

.answer-btn:hover:not([disabled]) {
    background-color: #e0e6e8; /* Lighter hover */
    border-color: #a5b1b1;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.12);
}

.answer-btn.correct {
    background-color: #2ecc71 !important;
    color: white !important;
    border-color: #27ae60 !important;
    box-shadow: 0 2px 4px rgba(46, 204, 113, 0.4) !important;
}

.answer-btn.wrong { /* JS uses .wrong */
    background-color: #e74c3c !important;
    color: white !important;
    border-color: #c0392b !important;
    box-shadow: 0 2px 4px rgba(231, 76, 60, 0.4) !important;
}

.answer-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

#feedback-container {
    margin-top: 15px;
    padding: 15px;
    border-radius: 5px;
    background-color: #f9f9f9;
    /* background-color: var(--tg-theme-secondary-bg-color, #f9f9f9); */
    border: 1px solid #eee;
    font-size: 1rem;
    color: #333;
    /* color: var(--tg-theme-text-color, #333); */
    text-align: left;
    line-height: 1.5;
}

.controls { /* This is the div containing next and exit buttons in your HTML */
    display: flex;
    justify-content: space-between; /* Or center, or flex-end depending on desired alignment */
    gap: 10px; /* Space between buttons */
    width: 100%;
    margin-top: 20px;
}

/* Common style for control buttons like Next, Exit, Restart, Home, Share */
/* Apply .control-btn class to these buttons in HTML for this style */
.control-btn {
    padding: 12px 25px;
    background-color: #3498db;
    /* background-color: var(--tg-theme-button-color, #3498db); */
    color: white;
    /* color: var(--tg-theme-button-text-color, white); */
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s; /* Added transitions */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* PAPER STYLE */
    flex-grow: 1; /* Allows buttons to share space if in a flex container */
    text-align: center;
}

.control-btn:hover:not([disabled]) {
    background-color: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); /* Enhanced shadow */
}

.control-btn:active:not([disabled]) {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.control-btn:disabled {
    background-color: #bdc3c7 !important;
    color: #7f8c8d !important;
    cursor: not-allowed;
    opacity: 0.8;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important; /* Flatter shadow for disabled */
}

.btn {
    display: inline-block;
    padding: 12px 25px;
    background-color: #3498db;
    color: white;
    text-decoration: none;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    text-align: center;
}

.btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.btn.secondary { /* For less prominent actions, e.g., change topic */
    background-color: #95a5a6;
}
.btn.secondary:hover {
    background-color: #7f8c8d;
}


/* Results Screen */
#results-screen h2 {
    font-size: 2rem;
    color: #2c3e50;
    /* color: var(--tg-theme-text-color, #2c3e50); */
    margin-bottom: 30px;
    text-align: center;
}

#results-message { /* Targets the <p id="results-message"> */
    font-size: 1.3rem;
    text-align: center;
    color: #2c3e50;
    /* color: var(--tg-theme-text-color, #2c3e50); */
    margin-bottom: 30px; /* Added margin */
    white-space: pre-wrap; /* To respect newlines from JS if any */
}

.results-buttons { /* Renamed from .results-actions to match your HTML */
    display: flex;
    flex-direction: column; /* Stack buttons vertically */
    gap: 15px;
    width: 100%;
    max-width: 300px; /* Optional: constrain width of results buttons */
    margin: 0 auto; /* Center if max-width is set */
}

/* Specific button in results if needed (e.g., share button) */
.control-btn.share { /* Assuming #share-button also has .control-btn */
    background-color: #2ecc71; /* Green for share */
}

.control-btn.share:hover:not([disabled]) {
    background-color: #27ae60;
}

/* Global Helper class */
.hidden {
    display: none !important;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
    .container {
        padding: 15px;
        min-height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }

    #topic-screen h1,
    #start-screen h1 {
        font-size: 2rem;
    }

    #topic-screen h2,
    #start-screen h2 {
        font-size: 1.5rem;
    }

    .subtopics-grid {
        grid-template-columns: 1fr;
    }

    .controls { /* Parent of next/exit buttons */
        flex-direction: column; /* Stack next/exit vertically */
        gap: 10px;
    }

    .control-btn { /* All buttons with .control-btn */
        width: 100%; /* Make control buttons full width on small screens */
    }

    .results-buttons { /* Also stack results buttons vertically (already column, this reinforces for specificity if needed) */
        flex-direction: column;
    }
}