:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-2: #f9fbfd;
    --text: #111827;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #4f46e5;
    --primary-strong: #4338ca;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --ink: #0f172a;
    --shadow: 0 18px 45px rgba(15, 23, 42, .08);
    --soft-shadow: 0 10px 28px rgba(15, 23, 42, .06);
}

[data-theme="dark"] {
    --bg: #0b1020;
    --surface: #121a2b;
    --surface-2: #172033;
    --text: #f8fafc;
    --muted: #a5b4c8;
    --line: #273449;
    --shadow: 0 18px 45px rgba(0, 0, 0, .32);
    --soft-shadow: 0 10px 28px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 10% 0%, rgba(79, 70, 229, .08), transparent 26rem),
        linear-gradient(180deg, var(--bg), var(--bg));
    font-family: "Hind Siliguri", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    line-height: 1.58;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 14px 30px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--primary); font-size: 22px; font-weight: 800; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); font-weight: 700; }
.nav a { padding: 9px 12px; border-radius: 8px; }
.nav a:hover { color: var(--primary); background: rgba(79, 70, 229, .08); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0; }
.narrow { width: min(840px, calc(100% - 40px)); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel, .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--soft-shadow);
}
.panel { padding: 26px; }
.center { text-align: center; }
.notice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 20px;
    margin: 8px 0 30px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--success) 30%, var(--line));
    border-radius: 8px;
    box-shadow: var(--soft-shadow);
}
.notice h2 { margin: 0 0 4px; font-size: clamp(20px, 3vw, 28px); line-height: 1.25; }
.notice p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.notice-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 999px; color: #047857; background: #d1fae5; font-weight: 900; }
.notice .btn { white-space: nowrap; }
.course-card {
    position: relative;
    min-height: 270px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
    overflow: hidden;
    border-bottom: 0;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.course-card:before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 7px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--success));
}
.course-card:hover, .exam-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--primary), var(--line)); }
.course-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; min-height: 48px; }
.course-icon {
    width: 76px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(79, 70, 229, .14), rgba(6, 182, 212, .14));
    color: var(--primary);
    font-size: 30px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0;
    overflow: hidden;
    white-space: nowrap;
}
.doc-icon {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(79, 70, 229, .14), rgba(6, 182, 212, .14));
    color: var(--primary);
    font-size: 30px;
    font-weight: 900;
}
.course-card h2, .exam-card h2 { margin: 6px 0 0; font-size: 26px; line-height: 1.2; }
.course-card p, .exam-card p { margin: 0; }
.course-description {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
    overflow-wrap: anywhere;
}
.course-description p { margin: 0 0 8px; }
.course-description p:last-child { margin-bottom: 0; }
.course-description ul,
.course-description ol { margin: 8px 0 8px 20px; padding: 0; }
.course-description li { margin: 4px 0; }
.course-description img { max-width: 100%; height: auto; border-radius: 8px; }
.course-description table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.course-description th,
.course-description td { border: 1px solid var(--line); padding: 6px 8px; }
.course-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.course-search { display: flex; justify-content: center; margin: 0 auto 26px; }
.course-search input { width: min(620px, 100%); min-height: 52px; padding: 0 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--soft-shadow); }
.price { font-size: 24px; font-weight: 900; color: var(--ink); }
[data-theme="dark"] .price { color: var(--text); }
.exam-card {
    min-height: 245px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 14px;
    padding: 26px;
    text-align: center;
}
.muted { color: var(--muted); }
.badge, .chip, .role-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    border-radius: 999px;
    padding: 7px 12px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--line);
    font-size: 13px;
    font-weight: 800;
}
.badge.green { color: #047857; background: #d1fae5; border-color: #a7f3d0; }
.badge.red { color: #be123c; background: #ffe4e6; border-color: #fecdd3; }
.badge.gold { color: #a16207; background: #fef3c7; border-color: #fde68a; }
.btn, .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 8px;
    min-height: 44px;
    padding: 0 18px;
    cursor: pointer;
    font-weight: 800;
    transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
.btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-strong)); box-shadow: 0 10px 24px rgba(79, 70, 229, .2); }
.btn.ghost { color: var(--primary); background: rgba(79, 70, 229, .1); }
.btn.danger { color: #fff; background: var(--danger); }
.btn.blue { color: #fff; background: #0284c7; }
.btn.block { width: 100%; }
.result-actions { gap: 10px; flex-wrap: wrap; }
.result-actions .btn { min-width: 130px; justify-content: center; }
.result-action-btn {
    border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
    box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 12%, transparent);
}
.course-links { display: grid; gap: 8px; margin-top: 12px; }
.icon-btn { width: 44px; padding: 0; color: var(--primary); background: rgba(79, 70, 229, .1); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; font-weight: 800; }
.field input, .field select, .field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--text);
    background: var(--surface);
    font-weight: 500;
    outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, .1); }
.field textarea { min-height: 130px; resize: vertical; }
.password-wrap { position: relative; display: block; width: 100%; }
.password-wrap input { padding-right: 86px; }
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    min-width: 42px;
    min-height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--primary);
    background: var(--surface-2);
    cursor: pointer;
    font-weight: 800;
    font-size: 18px;
}
.password-toggle:hover { background: rgba(79, 70, 229, .1); }
.math-preview { min-height: 76px; padding: 14px; margin: 8px 0 16px; border: 1px dashed var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); }
.jodit-editor { min-height: 180px; }
.jodit-fallback { min-height: 180px; resize: vertical; }
.jodit-container {
    width: 100% !important;
    border-color: var(--line) !important;
    border-radius: 8px !important;
    overflow: hidden;
    color: #111827;
    font-weight: 500;
}
.jodit-toolbar__box {
    background: linear-gradient(180deg, #f8fbff, #e7eef5) !important;
    border-color: var(--line) !important;
}
.jodit-workplace,
.jodit-wysiwyg {
    min-height: 180px !important;
}
.jodit-container:focus-within {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, .1);
}
.hint { font-size: 13px; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stacked-actions { display: grid; gap: 8px; min-width: 220px; }
.stacked-actions input { min-height: 40px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--surface); }
.tabs { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 22px; }
.tabs a { padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); font-weight: 800; color: var(--muted); }
.tabs a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.tab-count {
    min-width: 24px;
    height: 24px;
    display: inline-grid;
    place-items: center;
    margin-left: 8px;
    padding: 0 7px;
    border-radius: 999px;
    color: #fff;
    background: #ef4444;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
}
.tabs a.active .tab-count {
    color: #ef4444;
    background: #fff;
}
.auth-page { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 34px 18px; background: linear-gradient(135deg, #312e81, #4f46e5 48%, #06b6d4); }
.auth-card { width: min(520px, 100%); padding: 34px; background: #fff; color: #17202a; border-radius: 8px; box-shadow: var(--shadow); }
.google-login-wrap,
.google-login-fallback {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    box-shadow: 0 10px 24px rgba(79, 70, 229, .2);
}
.google-login-wrap {
    position: relative;
    overflow: hidden;
}
.google-login-wrap:before {
    content: "G";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    margin-left: -120px;
    color: #4285f4;
    background: #fff;
    border: 1px solid rgba(255,255,255,.7);
    font-weight: 900;
    pointer-events: none;
}
.google-login-wrap:after {
    content: "Sign in with Google";
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    color: #ffffff;
    border: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    font-weight: 900;
    pointer-events: none;
}
.google-login-wrap > div {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: center;
    width: 100%;
    opacity: 0.01;
}
.google-login-fallback {
    gap: 12px;
    padding: 13px 16px;
    color: #ffffff;
    font-weight: 900;
}
.google-login-fallback span {
    width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    color: #4285f4;
    background: #fff;
    border: 1px solid #dbe3f0;
    font-weight: 900;
}
.exam-shell { padding-bottom: 130px; }
.exam-header { position: sticky; top: 69px; z-index: 10; background: var(--surface); padding: 18px 28px; border-bottom: 1px solid var(--line); }
.exam-header.compact { padding: 6px 20px 8px; }
.exam-header.compact h1 { margin: 0; font-size: 18px; line-height: 1.15; }
.exam-header.compact h1 + .badge { margin-left: 0; }
.exam-header.compact .spaced { align-items: center; gap: 12px; }
.exam-header.compact .spaced > div:first-child { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.exam-header.compact .spaced > div:first-child .muted { font-size: 14px; }
.exam-header.compact .badge { padding: 4px 8px; font-size: 12px; }
.exam-header.compact .icon-btn { width: 36px; min-height: 36px; }
.exam-header.compact p { margin: 4px 0 0; font-size: 15px; }
.exam-header.compact .progress-track { margin-top: 6px; }
.progress-track { height: 5px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.question-card { width: min(900px, calc(100% - 36px)); margin: 28px auto; padding: 30px; border-radius: 12px; box-shadow: 0 12px 34px rgba(15, 23, 42, .06); }
.question-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.question-title { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; font-size: 20px; font-weight: 900; line-height: 1.45; }
.question-title .question-text p { margin: 0; }
.question-description { margin: -6px 0 16px; }
.question-text { white-space: normal; overflow-wrap: anywhere; }
.question-text p { margin: 0 0 8px; }
.question-text p:last-child { margin-bottom: 0; }
.question-text table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.question-text th, .question-text td { border: 1px solid var(--line); padding: 8px; }
.question-text img { max-width: 100%; height: auto; border-radius: 8px; }
.question-description img,
.explanation img,
.rich-snippet img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}
.question-media {
    margin: 12px 0 16px;
}
.question-media img {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
.question-video {
    width: 100%;
    margin-top: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #000;
    aspect-ratio: 16 / 9;
}
.question-video iframe,
.question-video video {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}
.rich-snippet { max-width: 520px; max-height: 4.2em; overflow: hidden; line-height: 1.4; }
.rich-snippet p { margin: 0; }
.option { display: grid; grid-template-columns: auto auto 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 13px 14px; margin: 11px 0; cursor: pointer; background: var(--surface); min-height: 58px; }
.option input { width: 22px; height: 22px; }
.option:not(:has(input)) { grid-template-columns: auto 1fr auto; }
.option:has(input:checked) { border-color: var(--success); background: rgba(16, 185, 129, .1); }
.option.is-locked-answer {
    border-color: var(--success);
    background: rgba(16, 185, 129, .13);
}
.option.answer-limit-disabled {
    opacity: .55;
    cursor: not-allowed;
}
.answer-locked-note,
.exam-answer-limit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0 12px;
    padding: 7px 11px;
    border: 1px solid #a7f3d0;
    border-radius: 999px;
    color: #047857;
    background: #d1fae5;
    font-size: 13px;
    font-weight: 900;
}
.option-letter { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 2px solid #d1d5db; border-radius: 999px; background: #fff; color: #111827; font-weight: 900; font-size: 14px; }
.floating-submit { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); display: flex; align-items: center; gap: 18px; padding: 14px 20px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); z-index: 15; }
.result-score { width: 136px; height: 136px; display: grid; place-items: center; margin: 18px auto; border: 6px solid var(--primary); border-radius: 999px; color: var(--primary); font-size: 34px; font-weight: 900; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 24px 0; }
.stat { padding: 18px; border: 1px solid var(--line); border-bottom: 4px solid var(--line); text-align: center; background: var(--surface-2); border-radius: 8px; font-weight: 900; }
.leaderboard-hero {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 22px 0;
}
.leader-card {
    position: relative;
    min-height: 190px;
    display: grid;
    place-items: center;
    gap: 6px;
    padding: 24px 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    text-align: center;
    background: var(--surface);
    box-shadow: var(--soft-shadow);
    overflow: hidden;
}
.leader-card:before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 7px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}
.leader-card.rank-1 { transform: translateY(-8px); border-color: #facc15; background: linear-gradient(180deg, #fffbeb, var(--surface)); }
.leader-card.rank-2 { border-color: #cbd5e1; background: linear-gradient(180deg, #f8fafc, var(--surface)); }
.leader-card.rank-3 { border-color: #fdba74; background: linear-gradient(180deg, #fff7ed, var(--surface)); }
.leader-medal {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    font-weight: 900;
    font-size: 20px;
}
.leader-card.rank-1 .leader-medal { background: linear-gradient(135deg, #f59e0b, #facc15); }
.leader-card.rank-2 .leader-medal { background: linear-gradient(135deg, #64748b, #cbd5e1); }
.leader-card.rank-3 .leader-medal { background: linear-gradient(135deg, #c2410c, #fdba74); }
.leader-card h2 { margin: 0; font-size: 22px; }
.leader-card strong { color: var(--primary); font-size: 32px; }
.leader-card small { color: var(--muted); font-weight: 800; text-transform: uppercase; }
.leader-table {
    display: grid;
    gap: 8px;
}
.leader-row {
    display: grid;
    grid-template-columns: 110px 1fr 120px;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
.leader-head {
    color: var(--muted);
    background: var(--surface-2);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}
.leader-row.top-row {
    border-color: color-mix(in srgb, var(--primary) 30%, var(--line));
    background: color-mix(in srgb, var(--primary) 7%, var(--surface));
}
.answer-correct { border-color: var(--success); background: rgba(16, 185, 129, .12); color: #065f46; font-weight: 800; }
.answer-wrong { border-color: var(--danger); background: rgba(239, 68, 68, .12); }
.answer-correct .option-letter { border-color: var(--success); background: #ecfdf5; color: #047857; }
.answer-wrong .option-letter { border-color: var(--danger); background: #fff1f2; color: #be123c; }
.answer-icon { width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 999px; color: #fff; font-size: 13px; font-weight: 900; }
.answer-icon.correct { background: var(--success); }
.answer-icon.wrong { background: var(--danger); }
.explanation { padding: 16px; margin-top: 14px; border-left: 4px solid var(--primary); border-radius: 8px; background: var(--surface-2); }
.toast { position: fixed; top: 92px; right: 18px; z-index: 50; padding: 12px 16px; color: #fff; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .3s ease, transform .3s ease; }
.policy-check { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0 18px; font-weight: 800; }
.policy-check input { width: 20px; height: 20px; margin-top: 3px; }
.policy-check a { color: var(--primary); text-decoration: underline; }
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
.help { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spaced { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.check-tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 8px; }
.course-choice-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); max-height: 260px; overflow: auto; padding-right: 4px; }
.check-tile { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: center; min-height: 58px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); cursor: pointer; transition: border-color .18s ease, background .18s ease, transform .18s ease; }
.check-tile:hover { border-color: rgba(79, 70, 229, .45); transform: translateY(-1px); }
.check-tile input { position: absolute; opacity: 0; pointer-events: none; }
.check-tile .tick { width: 28px; height: 28px; display: inline-grid; place-items: center; border: 2px solid #cbd5e1; border-radius: 999px; color: transparent; background: var(--surface); font-weight: 900; }
.check-tile strong { color: var(--text); line-height: 1.15; }
.check-tile small { grid-column: 2; color: var(--muted); font-weight: 800; margin-top: -8px; }
.check-tile:has(input:checked) { border-color: var(--primary); background: rgba(79, 70, 229, .1); }
.check-tile:has(input:checked) .tick { border-color: var(--success); background: var(--success); color: #fff; }
.site-footer { width: min(1440px, calc(100% - 40px)); margin: 30px auto 90px; padding: 26px; display: flex; justify-content: space-between; gap: 22px; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--soft-shadow); }
.site-footer p { margin: 4px 0 0; color: var(--muted); }
.footer-links { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-weight: 800; }
.footer-links a { padding: 8px 10px; border-radius: 8px; }
.footer-links a:hover { color: var(--primary); background: rgba(79, 70, 229, .08); }
.order-list { display: grid; gap: 10px; margin: 14px 0; }
.order-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); cursor: grab; }
.order-item.dragging { opacity: .55; border-color: var(--primary); }
.drag-handle { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--primary); background: rgba(79, 70, 229, .1); }
.compact-field { max-width: 120px; margin-left: auto; }
.compact-field input { min-height: 42px; padding: 8px 10px; }
.payment-number { display: inline-flex; align-items: center; justify-content: center; min-width: min(100%, 360px); padding: 18px 24px; margin: 14px 0; border: 2px dashed var(--primary); border-radius: 8px; color: var(--primary); background: rgba(79, 70, 229, .08); font-size: 32px; font-weight: 900; letter-spacing: .04em; }
.mathlive-panel {
    display: grid;
    gap: 10px;
    margin: 0 0 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}
.mathlive-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; color: var(--text); }
.mathlive-head span { color: var(--muted); font-size: 13px; font-weight: 700; }
math-field {
    width: 100%;
    min-height: 56px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-size: 22px;
}
.selected-question-box {
    display: grid;
    gap: 8px;
    margin: 12px 0 14px;
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}
.selected-question {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
.selected-question small { color: var(--muted); font-weight: 800; }
.selected-question button { border: 0; border-radius: 8px; padding: 8px 10px; color: #be123c; background: #ffe4e6; font-weight: 900; cursor: pointer; }
.subadmin-list {
    display: grid;
    gap: 10px;
}
.subadmin-item {
    display: grid;
    gap: 3px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
.subadmin-item span {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}
.subadmin-item.active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 9%, var(--surface));
}
.privilege-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0 18px;
}
.privilege-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: flex-start;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    cursor: pointer;
}
.privilege-card input {
    width: 20px;
    height: 20px;
    margin-top: 2px;
}
.privilege-card strong {
    display: block;
}
.privilege-card small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    line-height: 1.45;
}
.privilege-card:has(input:checked) {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}
.result-filter-bar {
    position: sticky;
    top: 82px;
    z-index: 9;
    width: min(900px, calc(100% - 36px));
    margin: 22px auto;
    padding: 12px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    box-shadow: var(--soft-shadow);
    backdrop-filter: blur(12px);
}
.result-filter-bar .active { color: #fff; background: var(--primary); }
.chat-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 22px; align-items: start; }
.admin-chat-layout { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); min-height: 680px; }
.chat-list { padding: 18px; }
.admin-chat-list { padding: 0; overflow-y: auto; overflow-x: hidden; max-height: calc(100vh - 230px); scrollbar-gutter: stable; }
.chat-list-head, .chat-room-head { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.chat-list-head { justify-content: space-between; }
.chat-list-head h2, .chat-room-head h1 { margin: 0; }
.chat-list-head p, .chat-room-head p { margin: 2px 0 0; }
.chat-list-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.chat-list-item:hover { background: var(--surface-2); }
.chat-list-item.active { border-left: 4px solid var(--primary); background: rgba(79, 70, 229, .08); }
.chat-avatar { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 999px; color: #fff; background: linear-gradient(135deg, var(--primary), var(--accent)); font-weight: 900; flex: 0 0 auto; }
.chat-avatar.large { width: 52px; height: 52px; font-size: 20px; }
.verified-avatar { background: linear-gradient(135deg, #059669, #0f766e); }
.verified-badge { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 4px 8px; border-radius: 999px; color: #047857; background: #d1fae5; border: 1px solid #a7f3d0; font-size: 12px; font-weight: 900; vertical-align: middle; }
.verified-badge:before { content: "✓"; }
.verified-badge.small { padding: 2px 7px; font-size: 11px; }
.chat-list-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-list-main strong { color: var(--text); }
.chat-list-main span { color: var(--muted); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-list-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chat-list-meta small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chat-list-meta em { min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 999px; color: #fff; background: #10b981; font-style: normal; font-size: 12px; font-weight: 900; }
.chat-panel { overflow: hidden; }
.admin-chat-panel { padding: 0; display: flex; flex-direction: column; min-height: 680px; }
.chat-thread { min-height: 380px; max-height: 65vh; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; gap: 12px; }
.admin-chat-panel .chat-thread { flex: 0 1 auto; height: min(58vh, 560px); max-height: min(58vh, 560px); min-height: 360px; overflow-y: scroll; padding: 18px; padding-right: 12px; background: color-mix(in srgb, var(--surface-2) 65%, var(--surface)); scrollbar-gutter: stable; overscroll-behavior: contain; }
.chat-thread::-webkit-scrollbar,
.admin-chat-list::-webkit-scrollbar { width: 14px; }
.chat-thread::-webkit-scrollbar-track,
.admin-chat-list::-webkit-scrollbar-track { background: color-mix(in srgb, var(--surface-2) 75%, var(--surface)); border-radius: 999px; }
.chat-thread::-webkit-scrollbar-thumb,
.admin-chat-list::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--primary) 54%, #94a3b8); border: 4px solid color-mix(in srgb, var(--surface-2) 75%, var(--surface)); border-radius: 999px; }
.chat-thread::-webkit-scrollbar-thumb:hover,
.admin-chat-list::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.chat-thread,
.admin-chat-list { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--primary) 58%, #94a3b8) color-mix(in srgb, var(--surface-2) 75%, var(--surface)); }
.chat-message { display: flex; }
.chat-message.mine { justify-content: flex-end; }
.chat-message.theirs { justify-content: flex-start; }
.chat-bubble { position: relative; max-width: min(76%, 680px); padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.chat-message.mine .chat-bubble { color: #fff; background: var(--primary); border-color: var(--primary); }
.chat-message.admin-sender.theirs .chat-bubble { color: #042f2e; background: #ccfbf1; border-color: #5eead4; box-shadow: 0 10px 24px rgba(15, 118, 110, .12); }
.chat-message.admin-sender.mine .chat-bubble { color: #fff; background: linear-gradient(135deg, #0f766e, #059669); border-color: #0f766e; box-shadow: 0 10px 24px rgba(15, 118, 110, .2); }
.user-chat-panel .chat-message.admin-sender .chat-bubble { color: #fff; background: linear-gradient(135deg, #0f766e, #059669); border-color: #0f766e; box-shadow: 0 10px 24px rgba(15, 118, 110, .18); }
.user-chat-panel .chat-message.user-sender .chat-bubble { color: var(--text); background: var(--surface); border-color: var(--line); }
.user-chat-panel .chat-message.admin-sender .verified-badge { color: #dcfce7; background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); }
.chat-message.mine .verified-badge { color: #dcfce7; background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); }
.chat-bubble p { margin: 8px 0; overflow-wrap: anywhere; }
.chat-bubble small { display: block; opacity: .75; margin-top: 6px; }
.message-menu { position: absolute; top: 8px; right: 8px; z-index: 2; }
.message-menu summary { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 999px; cursor: pointer; list-style: none; color: inherit; background: rgba(255,255,255,.18); font-size: 20px; line-height: 1; }
.message-menu summary::-webkit-details-marker { display: none; }
.message-menu[open] summary { background: rgba(15, 23, 42, .12); }
.message-menu form { position: absolute; top: 34px; right: 0; min-width: 120px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.message-menu button { width: 100%; min-height: 34px; border: 0; border-radius: 6px; color: #fff; background: var(--danger); cursor: pointer; font-weight: 800; }
.chat-bubble:has(.message-menu) { padding-right: 48px; }
.chat-attachment { margin-top: 10px; }
.chat-attachment img, .chat-attachment video { display: block; max-width: min(100%, 420px); border-radius: 8px; border: 1px solid var(--line); }
.chat-attachment audio { width: min(100%, 360px); }
.chat-compose { border-top: 1px solid var(--line); padding-top: 16px; }
.admin-chat-panel .chat-compose { padding: 16px; background: var(--surface); }
.user-chat-panel { padding: 0; display: flex; flex-direction: column; min-height: 680px; }
.user-chat-panel .chat-thread { flex: 0 1 auto; height: min(58vh, 560px); max-height: min(58vh, 560px); min-height: 360px; overflow-y: scroll; padding: 18px; padding-right: 12px; background: color-mix(in srgb, var(--surface-2) 65%, var(--surface)); scrollbar-gutter: stable; overscroll-behavior: contain; }
.user-chat-panel .chat-compose { padding: 16px; background: var(--surface); }
.chat-compose textarea { width: 100%; min-height: 96px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; color: var(--text); background: var(--surface); }
.chat-pagination {
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-top: 1px solid var(--line);
}
.admin-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.chat-search {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.chat-search input {
    min-width: 0;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: var(--surface-2);
}

@media (max-width: 980px) {
    .topbar { flex-wrap: wrap; padding: 14px 18px; }
    .nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
    .grid, .grid.two, .form-grid, .stat-grid, .chat-layout { grid-template-columns: 1fr; }
    .notice { grid-template-columns: auto 1fr; text-align: left; align-items: start; }
    .notice .btn { grid-column: 1 / -1; justify-content: center; }
    .question-card { padding: 24px 18px; }
    .exam-header.compact { top: 0; padding: 6px 12px; }
    .floating-submit { width: min(92vw, 560px); justify-content: space-between; }
    .site-footer { flex-direction: column; align-items: flex-start; }
    .footer-links { width: 100%; }
    .chat-list { max-height: 280px; overflow-y: auto; }
    .admin-chat-layout { min-height: auto; }
    .admin-chat-panel, .user-chat-panel { min-height: 560px; }
}

@media (max-width: 560px) {
    .brand { font-size: 18px; }
    .top-actions { width: 100%; overflow-x: auto; }
    .shell { padding: 28px 0; }
    .panel { padding: 20px; }
    .notice { grid-template-columns: 1fr; text-align: center; padding: 18px; }
    .notice-icon { margin: 0 auto; }
    .notice .btn { width: 100%; }
    .exam-header.compact h1 { width: 100%; font-size: 16px; }
    .exam-header.compact .spaced { align-items: flex-start; }
    .exam-header.compact .badge { padding: 3px 7px; font-size: 11px; }
    .exam-header.compact p { font-size: 14px; }
    .progress-track { height: 4px; }
    .chat-bubble { max-width: 92%; }
    .chat-compose .actions { flex-direction: column; align-items: stretch; }
    .course-card, .exam-card { min-height: 210px; }
}

/* Modern UI refresh */
:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef4ff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe4ef;
    --primary: #4f46e5;
    --primary-strong: #3730a3;
    --accent: #0ea5e9;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --ink: #0f172a;
    --shadow: 0 20px 60px rgba(15, 23, 42, .12);
    --soft-shadow: 0 10px 30px rgba(15, 23, 42, .07);
    --radius: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --bg: #101624;
    --surface: #182133;
    --surface-2: #202b3e;
    --surface-3: #1d3141;
    --text: #eef4ff;
    --muted: #a9b7cc;
    --line: #334157;
    --primary: #8b8cf6;
    --primary-strong: #6d6ee8;
    --accent: #38bdf8;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #fb7185;
    --ink: #f8fafc;
    --shadow: 0 24px 70px rgba(0, 0, 0, .38);
    --soft-shadow: 0 12px 34px rgba(0, 0, 0, .26);
}

html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body {
    background:
        radial-gradient(circle at 14% -8%, rgba(79, 70, 229, .12), transparent 24rem),
        radial-gradient(circle at 92% 8%, rgba(14, 165, 233, .12), transparent 22rem),
        linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg) 92%, var(--surface-2)));
    color: var(--text);
}

.topbar {
    min-height: 68px;
    padding: 12px clamp(16px, 3vw, 34px);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    box-shadow: 0 1px 0 var(--line), 0 12px 28px rgba(15, 23, 42, .04);
}
.brand {
    font-size: clamp(20px, 2.2vw, 30px);
    color: var(--primary);
    letter-spacing: 0;
}
.nav a, .top-actions .btn, .top-actions .role-pill, .tabs a {
    min-height: 40px;
    border-radius: var(--radius-sm);
}
.nav a {
    color: var(--muted);
    padding: 8px 11px;
}
.nav a:hover {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
}
.shell {
    width: min(1320px, calc(100% - 36px));
    padding: clamp(24px, 4vw, 42px) 0;
}
.narrow { width: min(880px, calc(100% - 32px)); }

.panel, .card, .auth-card {
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--line) 88%, transparent);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    box-shadow: var(--soft-shadow);
}
.panel { padding: clamp(18px, 2.4vw, 28px); }
.panel h1, .panel h2, .panel h3 { letter-spacing: 0; }
.panel h1:first-child, .panel h2:first-child { margin-top: 0; }

.notice {
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--success) 12%, var(--surface)), var(--surface));
    border-color: color-mix(in srgb, var(--success) 34%, var(--line));
}
.notice-icon {
    color: #fff;
    background: linear-gradient(135deg, var(--success), var(--accent));
}

.course-card, .exam-card {
    border-radius: var(--radius);
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--surface) 98%, var(--surface-3)), var(--surface));
    min-height: 235px;
}
.course-card {
    padding: 22px;
    border-top: 0;
}
.course-card:before {
    height: 5px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--success), #f59e0b);
}
.course-icon {
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--primary) 12%, var(--surface-2));
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line));
}
.doc-icon {
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--primary) 12%, var(--surface-2));
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line));
}
.course-card h2, .exam-card h2 {
    font-size: clamp(21px, 2vw, 26px);
}
.course-search input,
.field input, .field select, .field textarea,
.chat-compose textarea,
table input, table select, table textarea {
    border-radius: var(--radius-sm);
    border-color: var(--line);
    background: var(--surface);
    color: var(--text);
}
.course-search input:focus,
.field input:focus, .field select:focus, .field textarea:focus,
.chat-compose textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}

.btn, .icon-btn {
    border-radius: var(--radius-sm);
    min-height: 42px;
}
.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 12px 24px color-mix(in srgb, var(--primary) 22%, transparent);
}
.btn.ghost, .icon-btn {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--primary) 12%, var(--line));
}
.btn.blue { background: linear-gradient(135deg, #0284c7, var(--accent)); }
.btn.danger { background: linear-gradient(135deg, #dc2626, #f43f5e); }
.badge, .chip, .role-pill {
    border-radius: 999px;
    background: var(--surface-2);
}
[data-theme="dark"] .badge.green {
    color: #bbf7d0;
    background: rgba(16, 185, 129, .16);
    border-color: rgba(52, 211, 153, .26);
}
[data-theme="dark"] .badge.red {
    color: #fecdd3;
    background: rgba(244, 63, 94, .16);
    border-color: rgba(251, 113, 133, .28);
}
[data-theme="dark"] .badge.gold {
    color: #fde68a;
    background: rgba(245, 158, 11, .16);
    border-color: rgba(251, 191, 36, .28);
}

.tabs {
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.tabs a {
    white-space: nowrap;
    background: var(--surface);
    box-shadow: 0 8px 18px rgba(15, 23, 42, .04);
}
.tabs a.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

.table-wrap {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.table-wrap table { min-width: 680px; }
th {
    background: var(--surface-2);
    color: var(--muted);
}
td, th { border-bottom-color: var(--line); }
tr:last-child td { border-bottom: 0; }

.auth-page {
    background:
        radial-gradient(circle at 10% 10%, rgba(14, 165, 233, .22), transparent 22rem),
        linear-gradient(135deg, #1e1b4b, #3730a3 52%, #0f766e);
}
.auth-card {
    border-radius: var(--radius);
}

.question-card {
    border-radius: var(--radius);
    width: min(980px, calc(100% - 28px));
    padding: clamp(18px, 2.4vw, 30px);
}
.question-title {
    font-size: clamp(18px, 2vw, 22px);
}
.option {
    border-radius: var(--radius-sm);
    background: var(--surface);
}
[data-theme="dark"] .option-letter {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--line);
}
.floating-submit {
    border: 1px solid var(--line);
    border-radius: 999px;
}
.result-filter-bar {
    border-radius: 999px;
}

.chat-layout, .admin-chat-layout {
    gap: 18px;
}
.admin-chat-list, .admin-chat-panel, .user-chat-panel {
    border-radius: var(--radius);
}
.chat-list-head, .chat-room-head {
    background: color-mix(in srgb, var(--surface) 94%, var(--surface-2));
}
.chat-list-item {
    background: var(--surface);
}
.chat-list-item.active, .chat-list-item:hover {
    background: color-mix(in srgb, var(--primary) 9%, var(--surface));
}
.chat-bubble {
    border-radius: 14px;
}
.admin-chat-panel .chat-thread,
.user-chat-panel .chat-thread {
    background:
        radial-gradient(circle at 0% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 22rem),
        var(--surface-2);
}
.chat-message.mine .chat-bubble {
    background: linear-gradient(135deg, var(--primary), var(--accent));
}
.chat-message.admin-sender.mine .chat-bubble,
.user-chat-panel .chat-message.admin-sender .chat-bubble {
    background: linear-gradient(135deg, #0f766e, #059669);
}
.chat-compose {
    background: var(--surface);
}

.site-footer {
    border-radius: var(--radius);
    margin-bottom: 42px;
}

[data-theme="dark"] .jodit-container,
[data-theme="dark"] .jodit-wysiwyg,
[data-theme="dark"] .jodit-workplace {
    background: #ffffff !important;
    color: #111827 !important;
}
[data-theme="dark"] math-field {
    background: #ffffff;
    color: #111827;
}
[data-theme="dark"] .auth-card {
    background: var(--surface);
    color: var(--text);
}
[data-theme="dark"] .notice-icon,
[data-theme="dark"] .verified-avatar,
[data-theme="dark"] .chat-avatar {
    color: #ffffff;
}
[data-theme="dark"] .verified-badge {
    color: #bbf7d0;
    background: rgba(16, 185, 129, .18);
    border-color: rgba(52, 211, 153, .34);
}
[data-theme="dark"] .answer-correct {
    color: #bbf7d0;
    background: rgba(16, 185, 129, .16);
}
[data-theme="dark"] .answer-wrong {
    color: #fecdd3;
    background: rgba(244, 63, 94, .14);
}
[data-theme="dark"] .answer-correct .option-letter {
    background: rgba(16, 185, 129, .18);
    color: #bbf7d0;
}
[data-theme="dark"] .answer-wrong .option-letter {
    background: rgba(244, 63, 94, .16);
    color: #fecdd3;
}
[data-theme="dark"] .message-menu form {
    background: var(--surface);
    border-color: var(--line);
}
[data-theme="dark"] .payment-number {
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}
[data-theme="dark"] .leader-card.rank-1,
[data-theme="dark"] .leader-card.rank-2,
[data-theme="dark"] .leader-card.rank-3,
[data-theme="dark"] .leader-row {
    background: var(--surface);
}
[data-theme="dark"] .leader-row.top-row {
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

@media (max-width: 980px) {
    .topbar {
        gap: 10px;
        padding: 10px 14px;
    }
    .brand {
        width: 100%;
        justify-content: center;
        font-size: 22px;
    }
    .nav {
        order: 2;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }
    .top-actions {
        order: 3;
        width: 100%;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 2px;
    }
    .shell {
        width: min(100% - 24px, 1320px);
        padding: 24px 0;
    }
    .panel { padding: 18px; }
    .grid { gap: 16px; }
    .leaderboard-hero {
        grid-template-columns: 1fr;
    }
    .leader-card.rank-1 {
        transform: none;
    }
    .course-card, .exam-card { min-height: 205px; }
    .table-wrap table { min-width: 620px; }
    .chat-layout, .admin-chat-layout {
        gap: 14px;
    }
    .admin-chat-list {
        max-height: 320px;
    }
}

@media (max-width: 560px) {
    body { line-height: 1.52; }
    .brand { font-size: 20px; }
    .auth-page {
        min-height: calc(100vh - 64px);
        place-items: start center;
        padding: 18px 10px 26px;
        overflow-x: hidden;
    }
    .auth-card {
        width: min(100%, 430px);
        padding: 22px 16px;
        border-radius: 14px;
    }
    .auth-card h1 {
        font-size: clamp(28px, 8vw, 36px);
        line-height: 1.22;
        margin: 16px 0 12px;
    }
    .auth-card .doc-icon {
        margin-inline: auto;
    }
    .auth-card .field {
        text-align: left;
    }
    .auth-card .field input {
        min-height: 56px;
    }
    .auth-card .btn.block,
    .google-login-wrap,
    .google-login-fallback {
        min-height: 56px;
        width: 100%;
    }
    .google-login-wrap:before {
        left: 50%;
        margin-left: -112px;
        width: 28px;
        height: 28px;
    }
    .google-login-wrap > div {
        position: absolute;
        inset: 0;
        width: 100%;
        min-width: 0;
    }
    .google-login-wrap iframe {
        max-width: 100% !important;
    }
    .google-login-fallback {
        font-size: 17px;
    }
    .nav a, .top-actions .btn, .top-actions .role-pill {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 14px;
    }
    .icon-btn {
        width: 38px;
        min-height: 38px;
    }
    .shell, .narrow {
        width: calc(100% - 18px);
    }
    .panel { padding: 15px; }
    .notice { gap: 12px; }
    .notice-icon { width: 42px; height: 42px; }
    .course-card { padding: 18px; }
    .course-top { align-items: center; }
    .course-icon { width: 64px; height: 50px; font-size: 25px; }
    .doc-icon { width: 48px; height: 48px; font-size: 22px; }
    .course-meta, .actions { gap: 8px; }
    .btn.block { width: 100%; }
    .question-card {
        width: calc(100% - 14px);
        margin: 18px auto;
        padding: 16px;
    }
    .question-heading {
        flex-direction: column;
    }
    .option {
        grid-template-columns: auto auto 1fr;
        gap: 9px;
        padding: 11px;
    }
    .floating-submit {
        bottom: 12px;
        padding: 10px 12px;
        gap: 10px;
    }
    .result-filter-bar {
        width: calc(100% - 16px);
        border-radius: var(--radius);
    }
    .leader-row {
        grid-template-columns: 72px 1fr 86px;
        padding: 11px;
    }
    .chat-room-head, .chat-list-head {
        padding: 12px;
    }
    .chat-avatar.large {
        width: 44px;
        height: 44px;
    }
    .chat-bubble {
        max-width: 94%;
        padding: 11px 12px;
    }
    .user-chat-panel, .admin-chat-panel {
        min-height: calc(100vh - 210px);
    }
    .user-chat-panel .chat-thread,
    .admin-chat-panel .chat-thread {
        height: min(56vh, 460px);
        max-height: min(56vh, 460px);
        min-height: 320px;
        padding: 12px;
        padding-right: 8px;
    }
    .chat-compose {
        padding-top: 12px;
    }
    .site-footer {
        width: calc(100% - 18px);
        padding: 18px;
    }
}

@media (max-width: 380px) {
    .auth-card {
        padding-inline: 14px;
    }
    .auth-card h1 {
        font-size: 27px;
    }
    .google-login-wrap:before {
        margin-left: -102px;
    }
    .google-login-wrap:after,
    .google-login-fallback {
        font-size: 15px;
    }
}

/* Exam/result polish */
.exam-start-meta {
    display: grid;
    gap: 12px;
    margin: 18px 0;
    padding: clamp(18px, 3vw, 30px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--primary) 10%, var(--surface)), color-mix(in srgb, var(--accent) 8%, var(--surface)));
    color: var(--text);
}
.exam-start-meta p {
    margin: 0;
    color: var(--text);
    font-weight: 800;
}
.exam-start-meta p[style] {
    color: var(--danger) !important;
}
[data-theme="dark"] .exam-start-meta {
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--primary) 18%, var(--surface)), color-mix(in srgb, var(--accent) 12%, var(--surface)));
    border-color: var(--line);
}
[data-theme="dark"] .exam-start-meta p {
    color: #e5e7eb;
}
[data-theme="dark"] .exam-start-meta p[style] {
    color: #fca5a5 !important;
}

.result-filter-bar {
    position: static;
    top: auto;
    z-index: auto;
    width: min(900px, calc(100% - 36px));
    margin: 24px auto;
    padding: 14px;
    background: var(--surface);
    backdrop-filter: none;
}
.result-filter-bar .btn {
    border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 9%, var(--surface));
    box-shadow: none;
}
.result-filter-bar .btn.active,
.result-filter-bar .btn.primary.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
}
.result-filter-bar .btn.ghost:not(.active) {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 9%, var(--surface));
}

.question-card .option.answer-correct,
.question-card .option.answer-wrong {
    border-width: 1.5px;
    font-weight: 900;
}
.question-card .option.answer-correct {
    border-color: #10b981;
    background: #e7fff7;
    color: #047857;
}
.question-card .option.answer-wrong {
    border-color: #ef4444;
    background: #fff1f2;
    color: #dc2626;
}
.question-card .answer-correct .option-letter {
    border-color: #10b981;
    background: #ffffff;
    color: #047857;
}
.question-card .answer-wrong .option-letter {
    border-color: #ef4444;
    background: #ffffff;
    color: #dc2626;
}
.question-card .answer-icon {
    margin-left: auto;
    width: 20px;
    height: 20px;
    font-size: 13px;
    line-height: 1;
}
.question-card .answer-icon.correct {
    background: #10b981;
}
.question-card .answer-icon.wrong {
    background: #ff6b6b;
}
[data-theme="dark"] .question-card .option.answer-correct {
    border-color: #34d399;
    background: rgba(16, 185, 129, .18);
    color: #bbf7d0;
}
[data-theme="dark"] .question-card .option.answer-wrong {
    border-color: #fb7185;
    background: rgba(244, 63, 94, .18);
    color: #fecdd3;
}
[data-theme="dark"] .question-card .answer-correct .option-letter {
    border-color: #34d399;
    background: rgba(16, 185, 129, .14);
    color: #bbf7d0;
}
[data-theme="dark"] .question-card .answer-wrong .option-letter {
    border-color: #fb7185;
    background: rgba(244, 63, 94, .14);
    color: #fecdd3;
}

/* Admin mobile workspace */
@media (max-width: 760px) {
    .shell {
        width: calc(100% - 16px);
        padding: 18px 0;
    }

    .shell > .spaced,
    main.shell > .spaced {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .shell h1 {
        font-size: clamp(28px, 8vw, 38px);
        line-height: 1.14;
        margin-bottom: 14px;
    }

    .tabs {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        margin: 0 -8px 18px;
        padding: 0 8px 6px;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .tabs::-webkit-scrollbar {
        height: 6px;
    }

    .tabs::-webkit-scrollbar-thumb {
        border-radius: 999px;
        background: color-mix(in srgb, var(--primary) 45%, var(--line));
    }

    .tabs a {
        flex: 0 0 auto;
        min-height: 44px;
        padding: 9px 13px;
        border-radius: 10px;
        white-space: nowrap;
        scroll-snap-align: start;
    }

    .tab-count {
        min-width: 22px;
        height: 22px;
        margin-left: 6px;
        font-size: 11px;
    }

    .panel {
        padding: 16px;
        border-radius: 12px;
    }

    .grid,
    .grid.two,
    .form-grid,
    .privilege-grid,
    .stat-grid,
    .chat-layout,
    .admin-chat-layout {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .field,
    .stacked-actions {
        min-width: 0;
    }

    .field input,
    .field select,
    .field textarea,
    .stacked-actions input,
    table input,
    table select,
    table textarea,
    .chat-compose textarea {
        width: 100%;
        min-height: 44px;
        font-size: 16px;
    }

    .actions {
        width: 100%;
        align-items: stretch;
    }

    .actions .btn,
    .actions button,
    .actions input,
    .actions select,
    .actions a {
        min-width: 0;
    }

    .table-wrap {
        margin-inline: -6px;
        border-radius: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-wrap table {
        min-width: 720px;
    }

    th,
    td {
        padding: 11px 10px;
        font-size: 14px;
    }

    td .actions,
    td form.actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    td .actions .btn,
    td form.actions .btn {
        min-height: 38px;
        padding: 0 12px;
        font-size: 13px;
    }

    .admin-chat-layout {
        min-height: auto;
    }

    .admin-chat-list {
        max-height: 300px;
        overflow-y: auto;
    }

    .admin-chat-panel,
    .user-chat-panel {
        min-height: auto;
    }

    .admin-chat-panel .chat-thread,
    .user-chat-panel .chat-thread {
        height: min(58vh, 460px);
        max-height: min(58vh, 460px);
        min-height: 320px;
    }

    .chat-room-head,
    .chat-list-head {
        padding: 12px;
    }

    .chat-room-head h1,
    .chat-list-head h2 {
        font-size: 21px;
    }

    .chat-bubble {
        max-width: 94%;
    }

    .chat-compose {
        padding: 12px;
    }

    .chat-compose .actions {
        flex-direction: column;
    }

    .chat-search {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 430px) {
    .shell {
        width: calc(100% - 12px);
    }

    .panel {
        padding: 14px;
    }

    .tabs a {
        min-height: 42px;
        padding: 8px 11px;
        font-size: 14px;
    }

    .table-wrap table {
        min-width: 660px;
    }
}

[data-theme="dark"] .google-login-wrap,
[data-theme="dark"] .google-login-fallback {
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    border-color: transparent;
}
[data-theme="dark"] .stacked-actions input {
    color: var(--text);
    background: var(--surface);
    border-color: var(--line);
}
[data-theme="dark"] .google-login-wrap:after {
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    border-color: transparent;
}

/* Result and dashboard action polish */
.result-actions {
    gap: 10px;
    flex-wrap: wrap;
}
.result-actions .btn {
    min-width: 132px;
    justify-content: center;
}
.result-action-btn {
    border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
    box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 12%, transparent);
}
.course-links {
    display: flex;
    flex-direction: column;
    margin-top: 12px;
}

.course-links .btn {
    width: 100%;
    margin-top: 10px;
}

.course-links .btn:first-child {
    margin-top: 0;
}

/* Solve sheet paper layout */
@font-face {
    font-family: "Purno Web";
    src: url("fonts/BCC-Purno.woff2") format("woff2"), url("fonts/BCC-Purno.woff") format("woff");
    font-weight: 400 900;
    font-style: normal;
    font-display: swap;
}

.solve-sheet-body {
    margin: 0;
    min-height: 100vh;
    background: #f4f6f9;
    color: #121826;
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
}

.solve-sheet-page .bn {
    font-family: "Purno Web", "Hind Siliguri", sans-serif;
    font-size: 1em;
    line-height: inherit;
}

.solve-sheet-page {
    position: relative;
    width: min(980px, calc(100% - 32px));
    min-height: 1260px;
    margin: 22px auto;
    padding: 44px 48px 40px;
    background: #ffffff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .08);
    font-size: 16.4px;
}

.solve-sheet-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 18px;
}

.solve-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    margin: 0;
    padding: 0 16px;
    border: 1px solid #d8dee8;
    border-radius: 6px;
    color: #344054;
    background: #ffffff;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .06);
}

.solve-download-btn {
    cursor: pointer;
    font-family: inherit;
}

.solve-back-btn:hover {
    color: #2563eb;
    border-color: #b8c4d6;
}

.solve-sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 16px;
    border-bottom: 4px solid #121826;
}

.solve-sheet-brand {
    font-family: "Inter", Arial, sans-serif;
    font-size: 31px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: 1px;
}

.solve-sheet-header p {
    margin: 8px 0 0;
    color: #667085;
    font-size: 14px;
}

.solve-sheet-header time {
    flex: 0 0 auto;
    padding: 11px 12px;
    border: 1px solid #d7dde5;
    border-radius: 5px;
    color: #536171;
    font: 800 13px/1 "Inter", Arial, sans-serif;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.solve-sheet-title {
    margin: 14px 0 12px;
    font-size: 23px;
    line-height: 1.1;
    font-weight: 900;
}

.solve-sheet-meta {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.solve-sheet-meta div {
    min-height: 52px;
    padding: 9px 11px;
    border: 1px solid #d8dee8;
    border-radius: 5px;
}

.solve-sheet-meta span {
    display: block;
    margin-bottom: 5px;
    color: #64748b;
    font: 800 11px/1 "Inter", Arial, sans-serif;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.solve-sheet-meta strong {
    display: block;
    font-size: 15.5px;
    line-height: 1.2;
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
}

.solve-sheet-columns {
    column-count: 2;
    column-gap: 24px;
    column-rule: 1px solid #e3e8ef;
}

.solve-sheet-item {
    break-inside: avoid;
    page-break-inside: avoid;
    margin: 0 0 10px;
}

.solve-sheet-item h2 {
    display: block;
    margin: 0 0 6px;
    font-size: 16.8px;
    line-height: 1.35;
    font-weight: 700;
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
}

.solve-sheet-item h2 > span {
    display: inline;
    min-width: 0;
    margin-right: 4px;
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
    font-weight: 700;
}

.solve-sheet-item h2 .bn,
.solve-sheet-item h2 mjx-container,
.solve-sheet-item h2 span:not(.MathJax) {
    display: inline;
}

.solve-sheet-item h2 mjx-container,
.solve-options mjx-container,
.solve-explanation mjx-container {
    font-weight: 400;
}

.solve-sheet-item h2 p,
.solve-sheet-item h2 div {
    display: inline;
    margin: 0;
}

.solve-sheet-image img {
    max-width: 100%;
    max-height: 190px;
    object-fit: contain;
    margin: 4px 0 8px;
}

.solve-question-description {
    margin: 3px 0 7px;
    color: #52627a;
    font-size: 15.6px;
    line-height: 1.34;
}

.solve-question-description p {
    margin: 0 0 4px;
}

.solve-question-description img,
.solve-explanation img,
.solve-sheet-item .question-media img {
    max-width: 100%;
    max-height: 190px;
    object-fit: contain;
    border-radius: 5px;
}

.solve-sheet-item .question-media {
    margin: 5px 0 8px;
}

.solve-sheet-item .question-video {
    max-width: 100%;
    margin-top: 7px;
    border-color: #aeb5bf;
}

.solve-options {
    list-style: none;
    margin: 0;
    padding: 0;
}

.solve-options li {
    display: grid;
    grid-template-columns: 26px 1fr;
    gap: 5px;
    align-items: start;
    margin: 3px 0;
    font-size: 16.2px;
    line-height: 1.24;
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
}

.solve-options li span {
    font-family: "Purno Web", "Hind Siliguri", "Inter", Arial, sans-serif;
    font-weight: 700;
}

.solve-options li div,
.solve-options li p {
    margin: 0;
}

.solve-options li.is-correct {
    color: #07845f;
    font-weight: 400;
}

.solve-options li.is-correct > span {
    font-weight: 700;
}

.solve-question-id {
    display: inline-flex;
    align-items: center;
    margin: 3px 0 6px;
    padding: 3px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: #475569;
    background: #f8fafc;
    font-size: 12px;
    font-family: "Inter", Arial, sans-serif;
    font-weight: 800;
}

.solve-explanation {
    margin-top: 8px;
    padding: 8px 10px;
    border: 1.5px solid #aeb5bf;
    border-radius: 5px;
    color: #172033;
    font-size: 15.8px;
    line-height: 1.36;
}

.solve-explanation p {
    margin: 0;
}

.solve-sheet-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #d8dee8;
    color: #8792a2;
    text-align: center;
    font: 500 13px/1.2 "Inter", Arial, sans-serif;
}

.solve-warning {
    margin-top: 34px;
    padding: 13px 15px;
    border: 1.5px solid #f59e0b;
    border-left-width: 6px;
    border-radius: 8px;
    background: #fff7ed;
    color: #7c2d12;
}

.solve-warning strong {
    display: block;
    margin-bottom: 5px;
    color: #b45309;
    font: 900 14px/1 "Inter", Arial, sans-serif;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.solve-warning p {
    margin: 0;
    font-size: 15px;
    line-height: 1.45;
}

.solve-sheet-page mjx-container[jax="SVG"] {
    margin: 0 .05em;
    font-size: 1em !important;
}

@media (max-width: 820px) {
    .solve-sheet-body {
        background: #ffffff;
    }

    .solve-sheet-page {
        width: 100%;
        min-height: auto;
        margin: 0;
        padding: 16px 12px 28px;
        box-shadow: none;
    }

    .solve-sheet-actions {
        margin-bottom: 14px;
    }

    .solve-back-btn {
        min-height: 34px;
        padding: 0 12px;
        font-size: 13px;
    }

    .solve-sheet-header {
        gap: 14px;
        padding-bottom: 12px;
        border-bottom-width: 3px;
    }

    .solve-sheet-brand {
        font-size: 24px;
    }

    .solve-sheet-header p {
        font-size: 12.5px;
    }

    .solve-sheet-header time {
        font-size: 11px;
        padding: 9px 10px;
    }

    .solve-sheet-title {
        font-size: 20px;
    }

    .solve-sheet-meta {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .solve-sheet-columns {
        column-count: 1;
        column-rule: 0;
    }

    .solve-sheet-item h2 {
        font-size: 16.2px;
        line-height: 1.38;
    }

    .solve-sheet-item h2 > span {
        min-width: 0;
    }

    .solve-options li {
        grid-template-columns: 25px 1fr;
        font-size: 15.8px;
    }

    .solve-explanation {
        font-size: 15px;
    }

    .solve-warning {
        margin-top: 24px;
        padding: 11px 12px;
    }

    .solve-warning p {
        font-size: 14px;
    }
}

@media (max-width: 520px) {
    .solve-sheet-header {
        flex-direction: column;
    }

    .solve-sheet-meta {
        grid-template-columns: 1fr;
    }

    .solve-sheet-header time {
        align-self: flex-start;
    }

    .solve-sheet-meta div {
        min-height: 46px;
    }
}

@media print {
    .solve-sheet-body {
        background: #ffffff;
    }

    .solve-sheet-actions {
        display: none;
    }

    .solve-sheet-page {
        width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }
}

/* Hosting-safe leaderboard and mobile auth fixes */
.leaderboard-hero {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 18px 0 22px;
}

.leader-card {
    min-height: 190px;
    padding: 24px 20px;
    border: 1px solid #dbe4f0;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 18px 45px rgba(31, 41, 55, .08);
    text-align: center;
}

.leader-card.rank-1 {
    transform: translateY(-10px);
    border-color: #facc15;
    background: linear-gradient(180deg, #fff7cc 0%, #ffffff 68%);
}

.leader-card.rank-2 {
    border-color: #cbd5e1;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 68%);
}

.leader-card.rank-3 {
    border-color: #fdba74;
    background: linear-gradient(180deg, #ffedd5 0%, #ffffff 68%);
}

.leader-medal {
    width: 58px;
    height: 58px;
    margin: 0 auto 12px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: #ffffff;
    background: linear-gradient(135deg, #4f46e5, #0ea5e9);
    font-size: 24px;
    font-weight: 900;
}

.leader-card.rank-1 .leader-medal {
    background: linear-gradient(135deg, #f59e0b, #eab308);
}

.leader-card.rank-2 .leader-medal {
    background: linear-gradient(135deg, #64748b, #94a3b8);
}

.leader-card.rank-3 .leader-medal {
    background: linear-gradient(135deg, #c2410c, #fb923c);
}

.leader-card h2 {
    margin: 0 0 8px;
    font-size: 26px;
    line-height: 1.12;
}

.leader-card strong {
    display: block;
    color: var(--primary);
    font-size: 24px;
    line-height: 1;
}

.leader-card small {
    color: var(--muted);
    font-weight: 700;
}

.leader-table {
    width: 100%;
    overflow: hidden;
    border: 1px solid #dbe4f0;
    border-radius: 14px;
}

.leader-row {
    display: grid;
    grid-template-columns: 120px 1fr 150px;
    gap: 14px;
    align-items: center;
    padding: 15px 18px;
    border-top: 1px solid #dbe4f0;
}

.leader-row.with-time {
    grid-template-columns: 120px 1fr 150px 140px;
}

/* Course page header and mobile chat scroll polish */
.course-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.course-page-head h1 {
    margin: 0;
    min-width: 0;
}

@media (max-width: 640px) {
    .course-page-head {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: 10px;
        padding: 14px 0 4px;
    }

    .course-page-head .btn {
        min-height: 52px;
        padding-inline: 14px;
    }

    .course-page-head h1 {
        font-size: clamp(24px, 7vw, 31px);
        line-height: 1.12;
        overflow-wrap: anywhere;
    }

    .course-page-head .badge:last-child {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .admin-chat-panel .chat-thread,
    .user-chat-panel .chat-thread {
        height: min(62vh, 520px);
        max-height: min(62vh, 520px);
        min-height: 280px;
        overflow-y: auto;
        padding-right: 14px;
        scrollbar-gutter: stable;
        overscroll-behavior: auto;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
}

.question-tools-head {
    display: grid;
    grid-template-columns: minmax(140px, 0.34fr) minmax(0, 1fr);
    align-items: start;
    gap: 18px;
    margin-bottom: 18px;
    min-width: 0;
}

.question-tools-head h2 {
    margin: 0;
}

.question-tools-head .muted {
    margin: 6px 0 0;
}

.question-search-form {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(150px, 0.9fr) minmax(190px, 1fr) max-content max-content;
    align-items: end;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface-2) 78%, var(--surface));
}

.question-search-form .field {
    min-width: 0;
    margin: 0;
    gap: 7px;
    font-size: 13px;
    color: var(--muted);
}

.question-search-form select,
.question-search-form input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    color: var(--text);
    background: var(--surface);
}

.question-search-form .btn {
    min-height: 48px;
    white-space: nowrap;
}

@media (max-width: 1280px) {
    .question-tools-head {
        display: grid;
        grid-template-columns: 1fr;
    }

    .question-search-form {
        grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) auto auto;
    }
}

@media (max-width: 640px) {
    .question-search-form {
        grid-template-columns: 1fr;
    }

    .question-search-form .btn {
        width: 100%;
    }
}

.leader-row:first-child {
    border-top: 0;
}

.leader-head {
    background: #f8fafc;
    color: #52627a;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.leader-row strong {
    color: var(--text);
}

[data-theme="dark"] .leader-card,
[data-theme="dark"] .leader-table {
    border-color: #334155;
    background: #172033;
}

[data-theme="dark"] .leader-card.rank-1 {
    background: linear-gradient(180deg, rgba(234, 179, 8, .18) 0%, #172033 70%);
}

[data-theme="dark"] .leader-card.rank-2 {
    background: linear-gradient(180deg, rgba(148, 163, 184, .18) 0%, #172033 70%);
}

[data-theme="dark"] .leader-card.rank-3 {
    background: linear-gradient(180deg, rgba(251, 146, 60, .18) 0%, #172033 70%);
}

[data-theme="dark"] .leader-head {
    background: #111827;
}

[data-theme="dark"] .leader-row {
    border-color: #334155;
}

@media (max-width: 760px) {
    .auth-page {
        width: 100%;
        min-width: 0;
        overflow-x: hidden;
        padding: 14px 8px 24px;
    }

    .auth-card {
        width: 100%;
        max-width: calc(100vw - 20px);
        min-width: 0;
        margin: 0 auto;
        padding: 20px 12px;
        overflow: hidden;
    }

    .auth-card form,
    .auth-card .field,
    .auth-card input,
    .auth-card .btn.block,
    .google-login-wrap,
    .google-login-fallback {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .google-login-wrap {
        overflow: hidden;
    }

    .google-login-wrap > div,
    .google-login-wrap iframe {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .google-login-wrap:after,
    .google-login-fallback {
        white-space: nowrap;
    }

    .auth-card h1 {
        font-size: clamp(25px, 7.4vw, 34px);
        overflow-wrap: anywhere;
    }

    .leaderboard-hero {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .leader-card,
    .leader-card.rank-1 {
        min-height: 0;
        transform: none;
    }

    .leader-row {
        grid-template-columns: 74px 1fr 92px;
        gap: 8px;
        padding: 13px 12px;
    }

    .leader-row.with-time {
        grid-template-columns: 52px minmax(0, 1fr) 66px 72px;
        gap: 7px;
        padding: 12px 10px;
    }

    .leader-row.with-time > span,
    .leader-row.with-time > strong {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .leader-row.with-time > span:nth-child(3),
    .leader-row.with-time > span:nth-child(4) {
        font-size: 14px;
        white-space: nowrap;
    }

    .leader-row.with-time.leader-head > span {
        font-size: 10px;
        letter-spacing: .02em;
    }
}

/* Polished responsive header and welcome card */
.topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: clamp(18px, 3vw, 34px);
    row-gap: 10px;
}

.brand {
    min-width: max-content;
    width: auto;
    font-size: clamp(30px, 2.5vw, 42px);
    line-height: 1;
    font-weight: 900;
    letter-spacing: .01em;
}

.brand span {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav {
    justify-content: flex-end;
    margin-left: 0;
}

.top-actions {
    justify-content: flex-end;
}

.notice {
    padding: clamp(22px, 3.2vw, 36px);
    gap: clamp(14px, 2vw, 22px);
}

.notice-icon {
    width: clamp(54px, 5vw, 72px);
    height: clamp(54px, 5vw, 72px);
    font-size: clamp(22px, 2vw, 30px);
}

.notice h2 {
    font-size: clamp(28px, 3.2vw, 44px);
    line-height: 1.15;
    letter-spacing: 0;
}

.notice p {
    font-size: clamp(17px, 1.45vw, 23px);
    line-height: 1.45;
}

@media (max-width: 980px) {
    .topbar {
        grid-template-columns: 1fr;
        justify-items: center;
        padding: 16px 14px 18px;
    }

    .brand {
        justify-content: center;
        font-size: clamp(32px, 7vw, 46px);
    }

    .nav {
        order: 2;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        overflow: visible;
        gap: 6px;
        padding: 0;
    }

    .nav a {
        padding: 8px 10px;
        font-size: clamp(15px, 3.6vw, 18px);
    }

    .top-actions {
        order: 3;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        overflow: visible;
        padding: 0;
        gap: 8px;
    }

    .notice {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
        padding: 28px 18px;
    }

    .notice .btn {
        width: min(100%, 520px);
        min-height: 54px;
        font-size: 17px;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 14px 10px 16px;
        row-gap: 12px;
    }

    .brand {
        font-size: clamp(34px, 9vw, 44px);
    }

    .nav {
        gap: 4px 8px;
    }

    .nav a,
    .top-actions .btn,
    .top-actions .role-pill {
        min-height: 42px;
        padding: 8px 12px;
        font-size: 15px;
    }

    .notice {
        margin-top: 10px;
        padding: 26px 16px;
        border-radius: 14px;
    }

    .notice h2 {
        font-size: clamp(26px, 7.2vw, 34px);
    }

    .notice p {
        font-size: clamp(18px, 5vw, 22px);
    }
}

/* Mobile result page fit and summary polish */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

.result-meta-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 18px auto 14px;
    max-width: 100%;
}

.result-meta-chips .badge,
.result-mode-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
}

.result-stat-grid {
    max-width: 100%;
}

@media (max-width: 760px) {
    main.shell.narrow {
        width: 100%;
        max-width: 100%;
        padding-inline: 10px;
    }

    main.shell.narrow > .panel.center {
        width: 100%;
        margin-inline: auto;
        overflow: hidden;
    }

    main.shell.narrow .question-card {
        width: 100%;
        max-width: 100%;
    }

    .result-meta-chips {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
        width: min(100%, 420px);
    }

    .result-meta-chips .badge:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        justify-self: center;
        min-width: min(100%, 180px);
    }

    .result-stat-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

@media (max-width: 430px) {
    main.shell.narrow {
        padding-inline: 6px;
    }

    main.shell.narrow > .panel.center {
        padding-inline: 12px;
        border-radius: 12px;
    }

    main.shell.narrow > .panel.center h1 {
        font-size: clamp(25px, 7.6vw, 34px);
        line-height: 1.18;
        overflow-wrap: anywhere;
    }

    .result-meta-chips {
        grid-template-columns: 1fr;
        gap: 8px;
        width: 100%;
        margin-top: 16px;
    }

    .result-meta-chips .badge,
    .result-mode-badge {
        width: 100%;
        min-height: 40px;
        padding: 9px 10px;
        font-size: 14px;
    }

    .result-score {
        width: 122px;
        height: 122px;
        font-size: 30px;
        border-width: 5px;
    }
}
