@import url('https://fonts.googleapis.com/css2?family=Wix+Madefor+Display:wght@400..800&display=swap');

:root {
    --bg-main: #070b16;
    --bg-soft: #0b1220;
    --bg-panel: #0f172a;
    --bg-card: #111827;

    --text-main: #f8fafc;
    --text-soft: #cbd5e1;
    --text-muted: #94a3b8;

    --border: rgba(148, 163, 184, 0.18);
    --border-strong: rgba(148, 163, 184, 0.28);

    --primary: #f5c542;
    --primary-soft: rgba(245, 197, 66, 0.12);

    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, 0.12);

    --danger: #ef4444;

    --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.18);
    --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.36);

    --radius-xl: 20px;
    --radius-lg: 16px;
    --radius-md: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Wix Madefor Display", system-ui, sans-serif;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    min-height: 100vh;
    color: var(--text-main);
    overflow: hidden;
    background:
        radial-gradient(circle at 12% 0%, rgba(96, 165, 250, 0.16), transparent 28%),
        radial-gradient(circle at 88% 100%, rgba(245, 197, 66, 0.10), transparent 32%),
        linear-gradient(135deg, #050816 0%, #08111f 45%, #070b16 100%);
}

button,
select,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
}

.app {
    width: 100%;
    height: 100vh;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ================= TOPBAR ================= */

.topbar {
    width: 100%;
    max-width: 1640px;
    margin: 0 auto;
    padding: 10px;
    display: grid;
    grid-template-columns: minmax(320px, 1.35fr) minmax(250px, 0.9fr) 130px 82px 82px;
    gap: 10px;
    align-items: center;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.88));
    box-shadow: var(--shadow-md);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.logo {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 13px;
    font-size: 21px;
    background: linear-gradient(135deg, #f5c542, #ffe787);
    box-shadow: 0 10px 22px rgba(245, 197, 66, 0.20);
}

.brand > div:last-child {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.control {
    min-width: 0;
}

select,
input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
    background: #0b1220;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 750;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: 0.16s ease;
}

select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #94a3b8 50%),
        linear-gradient(135deg, #94a3b8 50%, transparent 50%);
    background-position:
        calc(100% - 17px) 16px,
        calc(100% - 12px) 16px;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 32px;
}

input::placeholder {
    color: #64748b;
}

select:hover,
input:hover {
    border-color: var(--border-strong);
    background-color: #0d1628;
}

select:focus,
input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(245, 197, 66, 0.12);
}

.topBtn {
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #ffe082);
    color: #171717;
    font-size: 12.5px;
    font-weight: 950;
    box-shadow: 0 10px 22px rgba(245, 197, 66, 0.16);
    transition: 0.16s ease;
}

.topBtn.light {
    background: #0b1220;
    color: var(--text-soft);
    border: 1px solid var(--border);
    box-shadow: none;
}

.topBtn:hover {
    transform: translateY(-1px);
}

.pageBadge,
.addQuestionBtn,
#aiPromptBTN {
    min-height: 34px;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--primary);
    color: #171717;
    border: 1px solid rgba(96, 165, 250, 0.25);
    font-size: 12px;
    font-weight: 950;
    white-space: nowrap;
}

/* ================= MAIN ================= */

.mainLayout {
    width: 100%;
    max-width: 1640px;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
}

.viewerCard {
    height: 100%;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.94);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.viewerHeader {
    height: 52px;
    padding: 0 14px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: #111827;
}

.viewerHeader h2 {
    font-size: 17px;
    max-width: 850px;
    color: var(--text-main);
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewerHeader p {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 650;
}

.contentGrid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--image-col-width, 360px) minmax(0, 1fr);
    transition: grid-template-columns 0.18s ease;
}

/* ================= IMAGE PANEL ================= */

.imagePanel {
    position: relative;
    min-height: 0;
    width: var(--image-col-width, 360px);
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-right: 1px solid var(--border);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
        linear-gradient(225deg, rgba(255, 255, 255, 0.02) 25%, transparent 25%),
        #070b16;
    background-size: 34px 34px;
}

.imagePanel::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 20%, rgba(96, 165, 250, 0.08), transparent 42%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.18), rgba(2, 6, 23, 0.35));
}

.pageImage {
    position: relative;
    z-index: 1;
    display: none;
    height: 100%;
    max-height: 100%;
    width: auto;
    max-width: calc(var(--image-col-width, 360px) - 20px);
    object-fit: contain;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid rgba(226, 232, 240, 0.18);
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.42);
}

.emptyBox {
    position: relative;
    z-index: 1;
    width: min(420px, 92%);
    text-align: center;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 22px;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.88);
    border: 1px dashed var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.emptyBox h3 {
    color: var(--text-main);
    font-size: 18px;
    font-weight: 900;
    margin-bottom: 6px;
}

.emptyBox p {
    font-size: 13px;
    font-weight: 650;
}

.arrowBtn {
    display: none !important;
}

/* ================= QUESTION PANEL ================= */

.questionPanel {
    min-width: 0;
    min-height: 0;
    background: #0b1220;
    display: flex;
    flex-direction: column;
}

.questionHead {
    min-height: 44px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: #0f172a;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.questionHead h3 {
    font-size: 16px;
    color: var(--text-main);
    font-weight: 900;
    line-height: 1;
}

.refreshBtn {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: 10px;
    background: #111827;
    color: var(--text-soft);
    border: 1px solid var(--border);
    font-size: 16px;
    font-weight: 1000;
    transition: 0.16s ease;
}

.refreshBtn:hover {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: rgba(245, 197, 66, 0.32);
    transform: rotate(90deg);
}

.questionList {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 7px;
    background:
        radial-gradient(circle at top right, rgba(96, 165, 250, 0.05), transparent 30%),
        #0b1220;
}

.questionList::-webkit-scrollbar {
    width: 7px;
}

.questionList::-webkit-scrollbar-track {
    background: #0f172a;
}

.questionList::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 999px;
}

.questionList::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

.questionEmpty {
    color: var(--text-muted);
    text-align: center;
    padding: 24px 14px;
    line-height: 1.5;
    font-size: 13px;
    font-weight: 700;
}

.questionEmpty code {
    display: inline-block;
    margin-top: 8px;
    max-width: 100%;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
    color: #fde68a;
    background: rgba(2, 6, 23, 0.55);
    border: 1px solid var(--border);
    padding: 9px;
    border-radius: 10px;
}

/* ================= COMPACT RELATED QUESTION CARD ================= */

.questionCard,
.compactQuestionCard,
.questionCard.compactQuestionCard {
    padding: 7px 8px;
    margin-bottom: 6px;
    border-radius: 11px;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(8, 13, 25, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.14);
    box-shadow: 0 5px 13px rgba(0, 0, 0, 0.13);
    transition: 0.14s ease;
}

.questionCard:hover,
.compactQuestionCard:hover {
    border-color: rgba(96, 165, 250, 0.28);
    transform: none;
}

.rqTop,
.questionTopMeta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 7px;
    margin-bottom: 5px;
}

.rqBadges,
.questionMetaLeft {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: nowrap;
}

.questionNo,
.compactQuestionCard .questionNo {
    min-width: 30px;
    height: 21px;
    padding: 0 7px;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #facc15;
    background: rgba(245, 197, 66, 0.12);
    border: 1px solid rgba(245, 197, 66, 0.25);
    font-size: 10px;
    line-height: 1;
    font-weight: 1000;
}

.recordBadge,
.compactQuestionCard .recordBadge {
    max-width: 145px;
    height: 21px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    color: #bfdbfe;
    background: rgba(96, 165, 250, 0.10);
    border: 1px solid rgba(96, 165, 250, 0.20);
    font-size: 9.5px;
    line-height: 1;
    font-weight: 850;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.answerMini {
    flex: 0 0 auto;
    height: 21px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    color: #86efac;
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.23);
    font-size: 10px;
    line-height: 1;
    font-weight: 950;
}

.questionText,
.compactQuestionText,
.compactQuestionCard .questionText {
    margin: 0 0 5px;
    color: #f8fafc;
    font-size: 11.4px;
    line-height: 1.24;
    font-weight: 760;
}

.questionText p,
.compactQuestionText p,
.compactQuestionCard .questionText p {
    margin: 0 0 2px;
}

.questionText br,
.compactQuestionText br,
.compactQuestionCard .questionText br {
    line-height: 1.1;
}

.optionList,
.compactOptionList,
.compactQuestionCard .optionList {
    margin-top: 5px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
}

.optionItem,
.compactOptionItem,
.compactQuestionCard .optionItem {
    min-height: 25px;
    padding: 4px 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    color: #dbeafe;
    background: rgba(2, 6, 23, 0.30);
    border: 1px solid rgba(148, 163, 184, 0.12);
    font-size: 10.8px;
    line-height: 1.17;
    font-weight: 670;
}

.optionItem:hover {
    border-color: rgba(96, 165, 250, 0.22);
    background: rgba(96, 165, 250, 0.05);
}

.optionItem.correctOption,
.compactOptionItem.correctOption,
.compactQuestionCard .optionItem.correctOption {
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.34);
    color: #d1fae5;
}

.optionBadge,
.compactQuestionCard .optionBadge {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    color: #bfdbfe;
    background: rgba(37, 99, 235, 0.28);
    font-size: 10px;
    line-height: 1;
    font-weight: 1000;
}

.optionItem.correctOption .optionBadge,
.compactOptionItem.correctOption .optionBadge,
.compactQuestionCard .optionItem.correctOption .optionBadge {
    color: #bbf7d0;
    background: rgba(22, 163, 74, 0.40);
}

.optionText,
.compactQuestionCard .optionText {
    min-width: 0;
}

.optionText p,
.compactQuestionCard .optionText p {
    margin: 0;
}

.answerBox {
    margin-top: 6px;
    padding: 6px 8px;
    border-radius: 9px;
    color: #86efac;
    background: var(--green-soft);
    border: 1px solid rgba(34, 197, 94, 0.25);
    font-size: 11px;
    font-weight: 850;
}

/* ================= SOLUTION COMPACT ================= */

.solutionBox {
    margin-top: 6px;
    padding: 8px;
    border-radius: 9px;
    background: rgba(2, 6, 23, 0.30);
    border: 1px solid rgba(148, 163, 184, 0.12);
}

.solutionTitle {
    margin-bottom: 4px;
    color: #f8fafc;
    font-size: 11px;
    font-weight: 950;
}

.solutionContent {
    color: #cbd5e1;
    font-size: 10.8px;
    line-height: 1.3;
    font-weight: 620;
}

.solutionDetails {
    margin-top: 5px;
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.25);
    border: 1px solid rgba(148, 163, 184, 0.11);
    overflow: hidden;
}

.solutionDetails summary {
    cursor: pointer;
    padding: 4px 7px;
    color: #cbd5e1;
    font-size: 10.5px;
    line-height: 1.2;
    font-weight: 850;
    list-style: none;
}

.solutionDetails summary::-webkit-details-marker {
    display: none;
}

.solutionDetails summary::after {
    content: " View";
    color: #facc15;
    font-weight: 1000;
}

.solutionDetails[open] summary::after {
    content: " Hide";
}

.solutionDetails .solutionContent {
    padding: 0 7px 6px;
}

.solutionContent p,
.solutionDetails .solutionContent p {
    margin: 0 0 3px;
}

.solutionContent ol,
.solutionContent ul,
.solutionDetails .solutionContent ol,
.solutionDetails .solutionContent ul {
    margin: 3px 0 3px 15px;
}

.solutionContent li,
.solutionDetails .solutionContent li {
    margin-bottom: 2px;
}

/* ================= TABLE / MATHJAX COMPACT ================= */

.questionCard table,
.compactQuestionCard table,
.questionText table,
.solutionContent table {
    width: 100%;
    border-collapse: collapse;
    margin: 4px 0;
    font-size: 10px;
}

.questionCard th,
.questionCard td,
.compactQuestionCard th,
.compactQuestionCard td,
.questionText th,
.questionText td,
.solutionContent th,
.solutionContent td {
    padding: 3px 5px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    color: #e5e7eb;
}

.questionCard mjx-container,
.compactQuestionCard mjx-container,
.questionText mjx-container,
.optionText mjx-container,
.solutionContent mjx-container {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    font-size: 92% !important;
}

/* ================= LOADING ================= */

.loading {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 0.55;
    }

    50% {
        opacity: 1;
    }
}

/* ================= RESPONSIVE ================= */

@media (max-width: 1150px) {
    body {
        overflow: auto;
    }

    .app {
        height: auto;
        min-height: 100vh;
    }

    .topbar {
        grid-template-columns: 1fr 1fr;
    }

    .brand {
        grid-column: 1 / -1;
    }

    .contentGrid {
        grid-template-columns: 1fr;
    }

    .imagePanel {
        width: 100%;
        height: 68vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .pageImage {
        max-width: 100%;
    }

    .questionPanel {
        min-height: 380px;
    }
}

@media (max-width: 760px) {
    .app {
        padding: 10px;
        gap: 10px;
    }

    .topbar {
        grid-template-columns: 1fr 1fr;
        border-radius: 16px;
        padding: 10px;
    }

    .brand,
    .control {
        grid-column: 1 / -1;
    }

    .logo {
        width: 40px;
        height: 40px;
        border-radius: 13px;
        font-size: 20px;
    }

    select,
    input,
    .topBtn {
        height: 38px;
    }

    .viewerCard {
        border-radius: 16px;
    }

    .viewerHeader {
        height: auto;
        min-height: 58px;
        align-items: flex-start;
        flex-direction: column;
        padding: 12px;
    }

    .viewerHeader h2 {
        font-size: 17px;
        white-space: normal;
    }

    .imagePanel {
        padding: 10px;
        height: 66vh;
    }

    .questionList {
        padding: 8px;
    }

    .optionList,
    .compactOptionList,
    .compactQuestionCard .optionList {
        grid-template-columns: 1fr;
    }

    .questionText,
    .compactQuestionText,
    .compactQuestionCard .questionText {
        font-size: 12px;
    }

    .optionItem,
    .compactOptionItem,
    .compactQuestionCard .optionItem {
        font-size: 11.4px;
    }

    .recordBadge,
    .compactQuestionCard .recordBadge {
        max-width: 145px;
    }
}