* {
    box-sizing: border-box;
}

body {
    font-family: sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    color: #333;
}

#app {
    max-width: 800px;
    margin: 2rem auto;
    padding: 1rem;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* --- Topics Sidebar --- */
#topics-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 85%;
    height: 100%;
    background: #fff;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    padding: 1.5rem;
    margin: 0;
    overflow-y: auto;
}

#topics-nav.visible {
    transform: translateX(0);
}

#topics-nav h2 {
    margin-top: 0;
    color: #4CAF50;
}

#topics-list a {
    display: block;
    padding: 0.5rem;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    margin-bottom: 0.25rem;
}

#topics-list a:hover {
    background-color: #f0f0f0;
}

/* Sidebar Overlay */
#sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1500;
    transition: opacity 0.3s ease;
}

/* --- Main Content Layout --- */
header {
    text-align: center;
    border-bottom: 1px solid #ddd;
    padding: 3rem 1rem 1rem 1rem; /* Top padding to avoid absolute button overlap */
    margin-bottom: 2rem;
    position: relative;
}

#topics-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    background: #4CAF50;
    color: white;
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

nav {
    margin: 1rem 0;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

nav a {
    text-decoration: none;
    color: #666;
    font-weight: bold;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.2s;
}

nav a:hover {
    color: #4CAF50;
    background: #f1f8e9;
}

nav a.active {
    color: white;
    background: #4CAF50;
}

#progress-container {
    width: 100%;
    background-color: #ddd;
    border-radius: 5px;
    margin-top: 1rem;
}

#progress-bar {
    width: 0%;
    height: 20px;
    background-color: #4CAF50;
    border-radius: 5px;
    text-align: center;
    color: white;
    line-height: 20px;
    transition: width 0.3s;
    font-size: 12px;
}

main {
    padding: 1rem 0;
}

main h2 {
    margin-top: 0;
    color: #333;
    font-size: 1.8rem;
}

main h3 {
    color: #4CAF50;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 0.5rem;
    margin-top: 2rem;
}

footer {
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
    margin-top: 1rem;
}

/* --- Shared Button Styles --- */
button {
    padding: 0.5rem 1rem;
    border: none;
    background-color: #4CAF50;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background-color: #45a049;
}

/* --- Quiz Styles --- */
.quiz-question {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-left: 3px solid #ddd;
}

.quiz-question p {
    font-weight: bold;
    margin-top: 0;
}

.quiz-options label {
    display: block;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.quiz-feedback {
    margin-top: 0.5rem;
    font-weight: bold;
}

/* --- Celebration Modal --- */
#celebration-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: white;
    padding: 2.5rem;
    border-radius: 15px;
    box-shadow: 0 0 50px rgba(0,0,0,0.3);
    z-index: 3000;
    text-align: center;
    visibility: hidden;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#celebration-modal.show {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

#celebration-modal h2 {
    color: #4CAF50;
    font-size: 2rem;
    margin-top: 0;
}

#celebration-modal .emoji {
    font-size: 4rem;
    display: block;
    margin: 1rem 0;
}

/* --- Toast Notification --- */
#toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.9rem;
    z-index: 2500;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

#toast-notification.show {
    opacity: 1;
}

/* --- Exam Mode Styles --- */
.mode-container {
    text-align: center;
    padding: 2rem;
}

.mode-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 2rem 0;
}

.large-btn {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 8px;
}

.mode-desc {
    color: #666;
    line-height: 1.8;
}

.mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.back-btn {
    background-color: #f44336;
}

.back-btn:hover {
    background-color: #d32f2f;
}

#timer {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
}

/* Read Mode Specifics */
.read-answer-correct {
    background-color: #e8f5e9;
    color: #2e7d32;
    padding: 2px 5px;
    border-radius: 3px;
    font-weight: bold;
}

.read-question-box {
    background: #f9f9f9;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    border-left: 4px solid #2196F3;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* --- Responsive Tweaks --- */
@media (max-width: 600px) {
    header {
        padding: 1rem; /* Smaller padding for mobile */
    }
    #topics-btn {
        position: relative;
        top: 0;
        left: 0;
        width: 100%;
        margin-bottom: 1rem;
        display: block;
    }
    #app {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        width: 100%;
    }
    nav {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px 5px;
        gap: 8px;
        scrollbar-width: none; /* Firefox */
        border-bottom: 1px solid #f0f0f0;
        margin: 0.5rem -1rem 1rem -1rem; /* Negative margin to touch edges */
    }
    nav::-webkit-scrollbar {
        display: none; /* Safari and Chrome */
    }
    nav a {
        flex: 0 0 auto;
        margin: 0;
        font-size: 0.85rem;
        white-space: nowrap;
        padding: 6px 12px;
        background: #f9f9f9;
        border: 1px solid #eee;
    }
    nav a.active {
        background: #4CAF50;
        color: white;
        border-color: #4CAF50;
    }
    #topics-nav {
        width: 280px;
    }
}