        /* --- CSS STYLES --- */
        :root {
            --primary: #f97316;
            /* Orange */
            --primary-hover: #ea580c;
            --secondary: #2563eb;
            /* Blue */
            --bg-body: #f8fafc;
            /* Light Mode BG */
            --bg-card: #ffffff;
            --text-main: #1e293b;
            --text-muted: #64748b;
            --border: #e2e8f0;
            --success: #22c55e;
            --error: #ef4444;
            --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
            --radius: 12px;
        }

        [data-theme="dark"] {
            --bg-body: #0f172a;
            /* Dark Mode BG */
            --bg-card: #1e293b;
            --text-main: #f1f5f9;
            --text-muted: #94a3b8;
            --border: #334155;
            --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
        }

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

        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--bg-body);
            color: var(--text-main);
            transition: background 0.3s, color 0.3s;
            min-height: 100vh;
        }

        /* Header */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 2rem;
            background: var(--bg-card);
            box-shadow: var(--shadow);
            position: sticky;
            top: 0;
            z-index: 10;
        }

        /* Updated Logo Style: Clickable */
        .logo {
            font-family: 'Poppins', sans-serif;
            font-weight: 700;
            font-size: 1.5rem;
            cursor: pointer;
            user-select: none;
        }

        .highlight {
            color: var(--primary);
        }

        .icon-btn {
            background: none;
            border: none;
            cursor: pointer;
            color: var(--text-main);
            padding: 0.5rem;
            border-radius: 50%;
        }

        .icon-btn:hover {
            background: rgba(0, 0, 0, 0.1);
        }

        /* Layout */
        main {
            max-width: 800px;
            margin: 2rem auto;
            padding: 0 1rem;
        }

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

        .screen.active {
            display: block;
        }

        .hidden {
            display: none !important;
        }

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

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .header-section {
            margin-bottom: 2rem;
            text-align: center;
        }

        .header-section h1 {
            font-family: 'Poppins', sans-serif;
            color: var(--secondary);
            margin-bottom: 0.5rem;
        }

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

        /* Cards & Buttons */
        .card-btn {
            background: var(--bg-card);
            border: 1px solid var(--border);
            padding: 1.5rem;
            border-radius: var(--radius);
            text-align: center;
            font-weight: 600;
            cursor: pointer;
            box-shadow: var(--shadow);
            transition: all 0.2s;
            color: var(--text-main);
            text-transform: capitalize;
        }

        .card-btn:hover {
            transform: translateY(-3px);
            border-color: var(--primary);
            color: var(--primary);
        }

        /* Only normal cards change text color on hover */
        .card-btn:not(.random-card):hover {
            color: var(--primary);
        }

        .btn {
            padding: 0.75rem 1.5rem;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            font-size: 1rem;
            transition: 0.2s;
        }

        .btn-primary {
            background: var(--primary);
            color: white;
        }

        .btn-primary:hover {
            background: var(--primary-hover);
        }

        .btn-secondary {
            background: var(--secondary);
            color: white;
        }

        /* Outline button for Previous to distinguish it */
        .btn-outline {
            background: transparent;
            border: 2px solid var(--secondary);
            color: var(--secondary);
        }

        .btn-outline:hover {
            background: rgba(37, 99, 235, 0.1);
        }

        .btn-back {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            margin-bottom: 1rem;
            font-size: 0.9rem;
        }

        .btn-back:hover {
            color: var(--primary);
        }

        .btn-large {
            width: 100%;
            margin-top: 1rem;
            padding: 1rem;
        }

        /* Subtopic Selection */
        .config-card {
            background: var(--bg-card);
            padding: 2rem;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
        }

        .checkbox-list {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
            margin-top: 1rem;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.75rem;
            border: 1px solid var(--border);
            border-radius: 8px;
            cursor: pointer;
        }

        .checkbox-item:hover {
            background: rgba(0, 0, 0, 0.02);
        }

        input[type="checkbox"] {
            accent-color: var(--primary);
            transform: scale(1.2);
        }

        .number-input {
            margin-top: 1rem;
            display: flex;
            flex-direction: column;
            gap: 0.4rem;
        }

        .number-input label {
            font-weight: 600;
            font-size: 0.9rem;
        }

        .number-input input {
            padding: 0.6rem 0.75rem;
            border-radius: 8px;
            border: 1px solid var(--border);
            font-size: 1rem;
            background: var(--bg-card);
            color: var(--text-main);
        }

        .number-input input:focus {
            outline: none;
            border-color: var(--primary);
        }

        .random-quiz-section {
            margin-top: 2.5rem;
            padding-top: 1.5rem;
            border-top: 1px dashed var(--border);
            display: flex;
            justify-content: center;
        }

        .random-card {
            max-width: 320px;
            width: 100%;
            background: linear-gradient(135deg,
                    var(--primary),
                    var(--primary-hover));
            color: white;
            font-weight: 700;
        }

        /* ✅ override says "stay white" */
        .random-card:hover {
            transform: translateY(-3px) scale(1.02);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
            color: white;
        }

        .maths-card {
            background: linear-gradient(135deg, #2563eb, #1d4ed8);
        }

        .maths-card:hover {
            color: white;
        }



        /* Quiz Interface */
        .progress-wrapper {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .progress-bar {
            flex: 1;
            height: 8px;
            background: var(--border);
            border-radius: 4px;
            overflow: hidden;
        }

        #progress-fill {
            height: 100%;
            background: var(--primary);
            width: 0%;
            transition: width 0.3s;
        }

        .question-card {
            background: var(--bg-card);
            padding: 2rem;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            margin-bottom: 2rem;
        }

        .question-card h2 {
            margin-bottom: 1.5rem;
            line-height: 1.5;
            font-size: 1.2rem;
        }

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

        .option-label {
            display: flex;
            padding: 1rem;
            border: 2px solid var(--border);
            border-radius: 8px;
            cursor: pointer;
            transition: 0.2s;
        }

        .option-label:hover {
            border-color: var(--secondary);
            background: rgba(37, 99, 235, 0.05);
        }

        .option-label.selected {
            border-color: var(--secondary);
            background: rgba(37, 99, 235, 0.1);
            font-weight: 600;
        }

        /* Updated Quiz Footer for 3 buttons */
        .quiz-footer {
            display: flex;
            justify-content: space-between;
            gap: 1rem;
        }

        /* Results */
        .result-card {
            text-align: center;
            background: var(--bg-card);
            padding: 3rem 1rem;
            border-radius: var(--radius);
            margin-bottom: 2rem;
        }

        .score-circle {
            width: 120px;
            height: 120px;
            background: var(--secondary);
            color: white;
            border-radius: 50%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            margin: 2rem auto;
        }

        .score-rule {
            margin-top: -0.8rem;
            margin-bottom: 1.2rem;
            font-size: 0.85rem;
            color: var(--text-muted);
            font-style: italic;
        }


        #score-text {
            font-size: 2.5rem;
            font-weight: 700;
        }

        .stats-row {
            display: flex;
            justify-content: center;
            gap: 2rem;
            margin-bottom: 2rem;
        }

        .stat {
            font-weight: 600;
            font-size: 1.2rem;
        }

        .stat.green {
            color: var(--success);
        }

        .stat.red {
            color: var(--error);
        }

        /* Review Section */
        .review-item {
            background: var(--bg-card);
            padding: 1rem;
            margin-bottom: 1rem;
            border-radius: 8px;
            border-left: 4px solid var(--border);
        }

        .review-item.correct {
            border-left-color: var(--success);
        }

        .review-item.wrong {
            border-left-color: var(--error);
        }

        .ans-row {
            margin-top: 0.5rem;
            font-size: 0.9rem;
        }

        .ans-row span {
            font-weight: 600;
        }

        .text-green {
            color: var(--success);
        }

        .text-red {
            color: var(--error);
        }

        .q-images {
            margin-top: 1rem;
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }

        .q-img {
            max-width: 100%;
            border-radius: 8px;
            border: 1px solid var(--border);
            box-shadow: var(--shadow);
        }

        .question-image img,
        .inline-image {
            max-width: 100%;
            margin-top: 10px;
            border-radius: 8px;
            border: 1px solid var(--border);
        }

        .explanation-box img {
            max-width: 100%;
            margin-top: 6px;
            border-radius: 6px;
        }




        /* Loader */
        .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid var(--border);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 1rem;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        #loader {
            text-align: center;
            margin-top: 4rem;
        }

        /* Mobile */
        @media (max-width: 600px) {
            .checkbox-list {
                grid-template-columns: 1fr;
            }

            .header-section h1 {
                font-size: 1.5rem;
            }

            .quiz-footer {
                flex-direction: column-reverse;
            }

            /* Stack buttons on mobile */
            .btn {
                width: 100%;
            }
        }