:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --correct: #10b981;
    --wrong: #ef4444;
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background: radial-gradient(circle at top left, #1e1b4b, #0f172a);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
}

.screen {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.subtopic-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 3rem;
}

.back-btn-wrapper {
    width: 100%;
    text-align: left;
    margin-bottom: 1rem;
}

.subtopic-header h1 {
    margin: 0;
}

.subtopic-header p {
    margin: 0;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.topic-card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.topic-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 0 15px rgba(99, 102, 241, 0.3);
}

.topic-card h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.topic-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.score-badge {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.score-badge.untouched {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.glass-panel {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 1.5rem;
    padding: 3rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    transition: color 0.2s;
    font-weight: 600;
}

.icon-btn:hover {
    color: var(--text-main);
}

.progress-container {
    flex-grow: 1;
    margin: 0 2rem;
    text-align: center;
}

#progress-text {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    width: 0%;
    transition: width 0.4s ease;
}

.score-display {
    font-weight: 600;
    color: #e0e7ff;
    background: rgba(99, 102, 241, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

#question-text {
    font-size: 1.5rem;
    line-height: 1.4;
    margin-bottom: 2rem;
    font-weight: 600;
}

.choices-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.choice-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 1.2rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 1.1rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.choice-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.01);
}

.choice-btn.correct {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--correct);
    color: #34d399;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.choice-btn.wrong {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--wrong);
    color: #f87171;
}

.choice-btn:disabled {
    cursor: default;
    opacity: 0.9;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1.2rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 2rem;
    width: 100%;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

#next-btn {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 4rem);
    max-width: 800px;
    margin: 0;
    z-index: 100;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#next-btn:hover {
    transform: translateX(-50%) translateY(-2px);
}

#quiz-screen {
    padding-bottom: 8rem; /* Extra space so choices don't hide behind the fixed button */
}

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.final-score {
    font-size: 4rem;
    font-weight: 700;
    background: linear-gradient(to right, #34d399, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 2rem 0;
}

#score-message {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.mode-description {
    margin: 1rem auto 0 auto;
    font-size: 0.95rem;
    color: var(--text-muted);
    max-width: 500px;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.8rem 1.2rem;
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    line-height: 1.5;
}

/* Toggle Switch Styles */
.mode-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    display: inline-flex;
    border: 1px solid var(--glass-border);
}

.mode-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color 0.3s, font-weight 0.3s;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--primary);
    transition: .4s;
}

input:checked + .slider {
    background-color: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
    transform: translateX(26px);
    background-color: #a855f7;
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.reset-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.reset-btn:hover {
    color: #ef4444;
    transform: rotate(-45deg) scale(1.1);
}

@media (max-width: 600px) {
    #question-text {
        font-size: 1.2rem;
    }
    .glass-panel {
        padding: 2rem;
    }
    header h1 {
        font-size: 2.5rem;
    }
}

/* Custom Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    max-width: 400px;
    width: 90%;
    padding: 2rem;
    text-align: center;
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 0.8rem 1.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.danger-btn {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
    padding: 0.8rem 1.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.danger-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
