
 :root {
            --ink: #1a1a2e;
            --mid: #4a4a6a;
            --muted: #9090a8;
            --border: #e2e2ee;
            --bg: #f7f7fc;
            --card: #ffffff;
            --accent: #4f46e5;
            --accent2: #7c3aed;
            --success: #059669;
            --warn: #d97706;
            --danger: #dc2626;
            --radius: 12px;
            --shadow: 0 2px 12px rgba(79, 70, 229, .08);
        }

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

        body {
            background: var(--bg);
            color: var(--ink);
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        /* Hero */
        .lms-hero {
            background: linear-gradient(135deg, #1e1b4b 0%, #4c1d95 50%, #6d28d9 100%) !important;
            position: relative;
            overflow: hidden;
            padding: 72px 24px 100px;
            text-align: center;
            isolation: isolate;
        }

        .lms-hero::before {
            content: '';
            position: absolute;
            inset: 0;
            background: radial-gradient(ellipse 55% 70% at 15% 50%, rgba(124, 58, 237, .45) 0%, transparent 60%), radial-gradient(ellipse 45% 55% at 85% 25%, rgba(56, 189, 248, .2) 0%, transparent 55%), radial-gradient(ellipse 40% 50% at 50% 110%, rgba(167, 139, 250, .18) 0%, transparent 50%);
            pointer-events: none;
            z-index: 0;
        }

        .lms-hero::after {
            content: '';
            position: absolute;
            inset: 0;
            background-image: radial-gradient(circle, rgba(255, 255, 255, .06) 1px, transparent 1px);
            background-size: 28px 28px;
            pointer-events: none;
            z-index: 0;
        }

        .lms-hero-inner {
            position: relative;
            z-index: 1;
            max-width: 700px;
            margin: 0 auto;
        }

        .lms-badge {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            background: rgba(167, 139, 250, .18);
            border: 1px solid rgba(167, 139, 250, .4);
            color: #c4b5fd;
            padding: 6px 18px;
            border-radius: 30px;
            font-size: .75rem;
            font-weight: 700;
            letter-spacing: .6px;
            text-transform: uppercase;
            margin-bottom: 22px;
        }

        .lms-title {
            font-size: clamp(2.1rem, 5vw, 3.4rem);
            font-weight: 800;
            color: #fff !important;
            line-height: 1.15;
            margin: 0 0 16px;
            text-shadow: 0 2px 24px rgba(0, 0, 0, .3);
        }

        .lms-title .lms-accent {
            color: #a78bfa !important;
        }

        .lms-subtitle {
            color: rgba(255, 255, 255, .65) !important;
            font-size: 1rem;
            margin: 0;
        }

        .lms-stats {
            display: flex;
            justify-content: center;
            gap: 40px;
            flex-wrap: wrap;
            margin-top: 40px;
        }

        .lms-stat-n {
            font-size: 2.1rem;
            font-weight: 800;
            color: #fff !important;
            line-height: 1;
        }

        .lms-stat-l {
            font-size: .72rem;
            color: rgba(255, 255, 255, .5) !important;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: .6px;
            margin-top: 5px;
        }

        /* Layout */
        .pg-wrap {
            max-width: 1380px;
            margin: 0 auto;
            padding: 2rem 1.25rem 4rem;
        }

        .pg-grid {
            display: grid;
            grid-template-columns: 1fr 320px;
            gap: 1.5rem;
            align-items: start;
        }

        .pg-left {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }

        /* Card */
        .card {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            overflow: hidden;
        }

        .card-head {
            display: flex;
            align-items: center;
            gap: .65rem;
            padding: 1.1rem 1.4rem;
            border-bottom: 1px solid var(--border);
            background: #fafafe;
        }

        .card-head .icon {
            font-size: 1.2rem;
        }

        .card-head h2 {
            font-size: 1rem;
            font-weight: 700;
        }

        .card-head p {
            font-size: .78rem;
            color: var(--muted);
            margin-top: .1rem;
        }

        .card-body {
            padding: 1.4rem;
        }

        /* Forms */
        .form-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: .35rem;
        }

        .form-group.full {
            grid-column: 1/-1;
        }

        label {
            font-size: .8rem;
            font-weight: 600;
            color: var(--mid);
            text-transform: uppercase;
            letter-spacing: .05em;
        }

        input[type=text],
        input[type=number],
        select,
        textarea {
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: .55rem .85rem;
            font-size: .92rem;
            color: var(--ink);
            background: #fff;
            transition: border .15s, box-shadow .15s;
            width: 100%;
        }

        input:focus,
        select:focus,
        textarea:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
        }

        textarea {
            resize: vertical;
            min-height: 60px;
        }

        /* Question type sections */
        .qtype-section {
            border: 1px solid var(--border);
            border-radius: 10px;
            overflow: hidden;
            margin-bottom: 1rem;
        }

        .qtype-section:last-child {
            margin-bottom: 0;
        }

        .qtype-header {
            display: flex;
            align-items: center;
            gap: .75rem;
            padding: .8rem 1.1rem;
            background: #f4f4fb;
            cursor: pointer;
            user-select: none;
            border-bottom: 1px solid var(--border);
        }

        .qtype-header input[type=checkbox] {
            width: 18px;
            height: 18px;
            accent-color: var(--accent);
            cursor: pointer;
        }

        .qtype-header .qtype-title {
            font-weight: 700;
            font-size: .92rem;
            flex: 1;
        }

        .qtype-header .qtype-badge {
            background: var(--accent);
            color: #fff;
            font-size: .72rem;
            font-weight: 700;
            padding: .2rem .55rem;
            border-radius: 999px;
            min-width: 70px;
            text-align: center;
        }

        .qtype-body {
            padding: 1.1rem;
            display: none;
        }

        .qtype-body.open {
            display: block;
        }

        /* Chapter tables */
        .chapter-table {
            width: 100%;
            border-collapse: collapse;
            font-size: .88rem;
            margin-top: .75rem;
        }

        .chapter-table th {
            text-align: left;
            padding: .4rem .6rem;
            color: var(--muted);
            font-size: .75rem;
            text-transform: uppercase;
            letter-spacing: .06em;
            border-bottom: 2px solid var(--border);
        }

        .chapter-table td {
            padding: .45rem .6rem;
            border-bottom: 1px solid var(--border);
            vertical-align: middle;
        }

        .chapter-table tr:last-child td {
            border-bottom: none;
        }

        .chapter-table tr:hover td {
            background: #f9f9fe;
        }

        .alloc-input {
            width: 70px;
            text-align: center;
            padding: .35rem .45rem;
            border: 1px solid var(--border);
            border-radius: 7px;
            font-size: .88rem;
        }

        .alloc-input:focus {
            border-color: var(--accent);
            outline: none;
            box-shadow: 0 0 0 2px rgba(79, 70, 229, .1);
        }

        .avail-badge {
            display: inline-block;
            font-size: .74rem;
            color: var(--muted);
            background: #f0f0f8;
            padding: .15rem .5rem;
            border-radius: 6px;
        }

        .avail-badge.zero {
            color: var(--danger);
            background: #fff0f0;
        }

        /* Manual questions */
        .manual-list {
            display: flex;
            flex-direction: column;
            gap: .75rem;
            margin-top: .75rem;
        }

        .manual-item {
            border: 1px solid var(--border);
            border-radius: 9px;
            padding: .85rem 1rem;
            display: grid;
            grid-template-columns: 1fr auto;
            gap: .5rem;
            align-items: start;
            background: #fafafe;
        }

        .manual-item textarea {
            font-size: .88rem;
            min-height: 52px;
        }

        .btn-remove {
            background: none;
            border: none;
            color: var(--danger);
            cursor: pointer;
            font-size: 1.1rem;
            padding: .15rem;
            border-radius: 6px;
            transition: background .15s;
        }

        .btn-remove:hover {
            background: #fff0f0;
        }

        .btn-add-manual {
            margin-top: .75rem;
            display: inline-flex;
            align-items: center;
            gap: .4rem;
            background: none;
            border: 1.5px dashed var(--accent);
            color: var(--accent);
            border-radius: 8px;
            padding: .45rem 1rem;
            font-size: .85rem;
            font-weight: 600;
            cursor: pointer;
            transition: background .15s;
        }

        .btn-add-manual:hover {
            background: rgba(79, 70, 229, .06);
        }

        /* Sidebar */
        .sidebar {
            display: flex;
            flex-direction: column;
            gap: 1.25rem;
            position: sticky;
            top: 1.5rem;
        }

        .summary-card {
            background: var(--card);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 1.25rem;
            box-shadow: var(--shadow);
        }

        .summary-card h3 {
            font-size: .85rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: .06em;
            color: var(--muted);
            margin-bottom: 1rem;
        }

        .summary-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: .45rem 0;
            border-bottom: 1px dashed var(--border);
            font-size: .88rem;
        }

        .summary-row:last-of-type {
            border-bottom: none;
        }

        .summary-row .label {
            color: var(--mid);
        }

        .summary-row .value {
            font-weight: 700;
        }

        .summary-total {
            margin-top: .75rem;
            padding-top: .75rem;
            border-top: 2px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .summary-total .label {
            font-weight: 700;
            font-size: .95rem;
        }

        .summary-total .value {
            font-size: 1.3rem;
            font-weight: 800;
            color: var(--accent);
        }

        .btn-generate {
            width: 100%;
            padding: .85rem;
            border: none;
            border-radius: 10px;
            font-size: 1rem;
            font-weight: 700;
            cursor: pointer;
            background: linear-gradient(135deg, var(--accent), var(--accent2));
            color: #fff;
            box-shadow: 0 4px 16px rgba(79, 70, 229, .35);
            transition: opacity .2s, transform .1s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: .5rem;
        }

        .btn-generate:hover {
            opacity: .92;
            transform: translateY(-1px);
        }

        .btn-generate:active {
            transform: translateY(0);
        }

        .btn-generate:disabled {
            opacity: .5;
            cursor: not-allowed;
            transform: none;
        }

        .alert {
            padding: .75rem 1rem;
            border-radius: 8px;
            font-size: .85rem;
            margin-top: .5rem;
            display: none;
        }

        .alert-warn {
            background: #fffbeb;
            border: 1px solid #fde68a;
            color: #92400e;
        }

        .alert-danger {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: #991b1b;
        }

        /* Preview */
        .preview-wrap {
            margin-top: 2rem;
            display: none;
        }

        .preview-wrap.visible {
            display: block;
        }

        .preview-toolbar {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: .75rem 1.25rem;
            background: var(--ink);
            border-radius: var(--radius) var(--radius) 0 0;
        }

        .preview-toolbar h3 {
            color: #fff;
            font-size: .9rem;
            font-weight: 700;
            flex: 1;
        }

        .btn-toolbar {
            display: inline-flex;
            align-items: center;
            gap: .35rem;
            background: rgba(255, 255, 255, .12);
            border: 1px solid rgba(255, 255, 255, .2);
            color: #fff;
            border-radius: 7px;
            padding: .4rem .9rem;
            font-size: .82rem;
            font-weight: 600;
            cursor: pointer;
            transition: background .15s;
        }

        .btn-toolbar:hover {
            background: rgba(255, 255, 255, .22);
        }

        /* Paper output */
        #paper-output {
            background: #fff;
            border: 1px solid var(--border);
            border-top: none;
            border-radius: 0 0 var(--radius) var(--radius);
            padding: 2rem 2.8rem 2.5rem;
            font-family: 'Times New Roman', serif;
            font-size: 13pt;
            line-height: 1.6;
            color: #000;
        }

        .p-school-name {
            text-align: center;
            font-size: 15pt;
            font-weight: 700;
            line-height: 1.3;
        }

        .p-school-addr {
            text-align: center;
            font-size: 11pt;
            font-weight: 700;
        }

        .p-exam-title {
            text-align: center;
            font-size: 12pt;
            font-weight: 700;
        }

        .p-divider {
            border: none;
            border-top: 1.5px solid #000;
            margin: .4rem 0 .25rem;
        }

        .p-divider2 {
            border: none;
            border-top: 1px solid #000;
            margin: .35rem 0 .45rem;
        }

        .p-meta-row {
            display: flex;
            justify-content: space-between;
            font-size: 11pt;
            font-weight: 700;
            margin: .1rem 0;
        }

        .p-subject-row {
            font-size: 11pt;
            font-weight: 700;
            margin: .1rem 0;
        }

        .p-instructions {
            font-size: 10pt;
            font-style: italic;
            margin-bottom: .85rem;
        }

        .p-group-label {
            text-align: center;
            font-size: 12pt;
            font-weight: 700;
            margin: 1rem 0 .1rem;
        }

        .p-group-desc {
            display: flex;
            justify-content: space-between;
            align-items: baseline;
            font-size: 11pt;
            font-weight: 700;
            border-bottom: 1px solid #000;
            padding-bottom: .2rem;
            margin-bottom: .55rem;
        }

        .p-question {
            margin-bottom: .5rem;
            font-size: 12pt;
            position: relative;
        }

        .p-qbody {
            display: flex;
            gap: .3rem;
        }

        .p-qnum {
            min-width: 1.9rem;
            flex-shrink: 0;
        }

        .p-qtext {
            flex: 1;
        }

        .p-opts {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: .05rem .4rem;
            margin: .15rem 0 .35rem 1.9rem;
            font-size: 11.5pt;
        }

        .p-opts.opts-1col {
            grid-template-columns: 1fr;
        }

        .p-lines {
            margin: .25rem 0 .55rem 1.9rem;
        }

        .p-line {
            display: block;
            border-bottom: 1px solid #bbb;
            height: 1.5rem;
        }

        .p-end {
            text-align: center;
            font-size: 11pt;
            margin-top: 1.5rem;
            padding-top: .6rem;
            border-top: 2px double #000;
        }

        /* ══ Replace button -- visible on screen, hidden in print ══ */
        .p-replace-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 2px;
        }

        .p-chapter-tag {
            font-size: 9pt;
            color: var(--muted);
            font-family: 'Segoe UI', sans-serif;
            font-style: normal;
        }

        .p-replace-btn {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            background: rgba(79, 70, 229, .07);
            border: 1px solid rgba(79, 70, 229, .22);
            color: var(--accent);
            border-radius: 6px;
            padding: 2px 10px;
            font-size: 9pt;
            font-weight: 600;
            cursor: pointer;
            font-family: 'Segoe UI', sans-serif;
            transition: background .15s, border-color .15s;
            line-height: 1.6;
            white-space: nowrap;
        }

        .p-replace-btn:hover {
            background: rgba(79, 70, 229, .14);
            border-color: var(--accent);
        }

        .p-replaced-tag {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            background: rgba(5, 150, 105, .08);
            border: 1px solid rgba(5, 150, 105, .28);
            color: var(--success);
            border-radius: 6px;
            padding: 2px 9px;
            font-size: 9pt;
            font-family: 'Segoe UI', sans-serif;
            margin-left: 6px;
        }

        /* ══ Swap drawer ══ */
        .swap-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, .42);
            z-index: 900;
            opacity: 0;
            pointer-events: none;
            transition: opacity .22s;
        }

        .swap-overlay.open {
            opacity: 1;
            pointer-events: all;
        }

        .swap-drawer {
            position: fixed;
            right: 0;
            top: 0;
            bottom: 0;
            width: min(500px, 100vw);
            background: #fff;
            box-shadow: -6px 0 36px rgba(0, 0, 0, .16);
            z-index: 901;
            display: flex;
            flex-direction: column;
            transform: translateX(100%);
            transition: transform .26s cubic-bezier(.4, 0, .2, 1);
        }

        .swap-drawer.open {
            transform: translateX(0);
        }

        .swap-head {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            padding: 18px 20px 14px;
            border-bottom: 1px solid var(--border);
            flex-shrink: 0;
        }

        .swap-head-text {
            flex: 1;
        }

        .swap-head-text h3 {
            font-size: 1rem;
            font-weight: 700;
        }

        .swap-head-meta {
            font-size: .75rem;
            color: var(--muted);
            margin-top: 3px;
        }

        .swap-close {
            width: 30px;
            height: 30px;
            border: 1px solid var(--border);
            background: #fff;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: .95rem;
            color: var(--mid);
            flex-shrink: 0;
            transition: background .15s;
        }

        .swap-close:hover {
            background: #f5f5f5;
        }

        .swap-body {
            flex: 1;
            overflow-y: auto;
            padding: 16px 20px;
        }

        .swap-loading,
        .swap-empty {
            text-align: center;
            padding: 40px 0;
            color: var(--muted);
            font-size: .88rem;
        }

        /* Current question card */
        .swap-current {
            background: #fffdf0;
            border: 1px solid #e8d878;
            border-radius: 9px;
            padding: 12px 14px;
            margin-bottom: 16px;
            font-size: .84rem;
            line-height: 1.55;
            font-family: 'Segoe UI', sans-serif;
        }

        .swap-current-lbl {
            font-size: .7rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: .5px;
            color: #9a7a00;
            margin-bottom: 6px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .swap-current-lbl::after {
            content: '';
            flex: 1;
            height: 1px;
            background: #e8d878;
        }

        .swap-opts-mini {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1px 10px;
            font-size: .78rem;
            color: var(--mid);
            margin-top: 5px;
        }

        /* Alternative cards */
        .swap-alt {
            border: 1.5px solid var(--border);
            border-radius: 10px;
            padding: 12px 14px 12px 14px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: border-color .15s, background .15s, box-shadow .15s;
            font-size: .84rem;
            line-height: 1.55;
            font-family: 'Segoe UI', sans-serif;
            position: relative;
        }

        .swap-alt:hover {
            border-color: var(--accent);
            background: #f8f7ff;
            box-shadow: 0 2px 10px rgba(79, 70, 229, .1);
        }

        .swap-alt:hover .swap-pick {
            opacity: 1;
        }

        .swap-alt.picked {
            border-color: var(--success);
            background: #f0fdf4;
        }

        .swap-alt-meta {
            font-size: .7rem;
            color: var(--muted);
            margin-bottom: 4px;
            display: flex;
            justify-content: space-between;
        }

        .swap-alt-text {
            color: var(--ink);
        }

        .swap-pick {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            background: var(--accent);
            color: #fff;
            border: none;
            border-radius: 7px;
            padding: 4px 13px;
            font-size: .78rem;
            font-weight: 700;
            cursor: pointer;
            opacity: 0;
            transition: opacity .15s;
            font-family: 'Segoe UI', sans-serif;
        }

        .swap-foot {
            padding: 14px 20px;
            border-top: 1px solid var(--border);
            flex-shrink: 0;
        }

        .swap-foot-close {
            width: 100%;
            padding: .6rem;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: #fff;
            color: var(--mid);
            font-size: .88rem;
            font-weight: 600;
            cursor: pointer;
            transition: background .15s;
        }

        .swap-foot-close:hover {
            background: #f5f5f5;
        }

        /* Print: hide interactive chrome */
        @media print {
            .pg-wrap>*:not(.preview-wrap) {
                display: none !important;
            }

            .preview-wrap {
                display: block !important;
            }

            .preview-toolbar {
                display: none !important;
            }

            #paper-output {
                border: none;
                padding: 0;
                border-radius: 0;
            }

            .p-replace-bar {
                display: none !important;
            }

            .swap-overlay,
            .swap-drawer {
                display: none !important;
            }
        }

        @media (max-width:900px) {
            .pg-grid {
                grid-template-columns: 1fr;
            }

            .sidebar {
                position: static;
            }

            .swap-drawer {
                width: 100vw;
            }
        }