/* Maths DoNow Multi-Quadrant & Vertical Toolbar Styles */

:root {
    --mwn-primary: #2563eb;
    --mwn-primary-hover: #1d4ed8;
    --mwn-success: #059669;
    --mwn-bg: #f8fafc;
    --mwn-card-bg: #ffffff;
    --mwn-border: #cbd5e1;
    --mwn-text: #0f172a;
    --mwn-text-muted: #64748b;
    --mwn-star-active: #d97706;
    --mwn-radius: 8px;
    --mwn-card-font-scale: 1;
}

/* App Root Container */
.mwn-app-root {
    position: relative;
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    background: #f1f5f9;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--mwn-text);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Master Left Rail (Global Actions) */
.mwn-master-bar {
    width: 38px;
    flex-shrink: 0;
    background: #ffffff;
    border-right: 1px solid var(--mwn-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 3px;
    gap: 4px;
    box-sizing: border-box;
    z-index: 10000;
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.04);
}

/* Touch Isolation & Button Touch Actions (Prevents PowerPoint gesture stealing) */
button,
.mwn-rail-btn,
.mwn-sidebar-btn,
.mwn-card-action-btn,
.mwn-font-widget-btn,
.mwn-topic-modal-close {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mwn-topic-pill {
    touch-action: pan-x;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mwn-rail-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #475569;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: all 0.15s ease;
    user-select: none;
}

.mwn-rail-btn:hover:not(:disabled) {
    background: #e2e8f0;
    color: #0f172a;
}

.mwn-rail-btn-sidebars.mwn-active {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
}

.mwn-rail-btn-sidebars.mwn-active .mwn-sidebar-toggle-fill,
.mwn-rail-btn-sidebars.mwn-active .mwn-sidebar-toggle-divider {
    display: none;
}

.mwn-rail-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.mwn-rail-btn-add {
    color: #2563eb;
    font-weight: 700;
    font-size: 1.1rem;
}

.mwn-rail-btn-add:hover:not(:disabled) {
    background: #dbeafe;
    color: #1d4ed8;
}

.mwn-rail-btn-remove {
    color: #dc2626;
    font-weight: 700;
    font-size: 1.1rem;
}

.mwn-rail-btn-remove:hover:not(:disabled) {
    background: #fee2e2;
    color: #b91c1c;
}

.mwn-rail-count-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: #e2e8f0;
    color: #334155;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
    user-select: none;
}

.mwn-rail-divider {
    width: 22px;
    height: 1px;
    background: #e2e8f0;
    margin: 2px 0;
}

.mwn-rail-spacer {
    flex: 1 1 auto;
    min-height: 4px;
}

.mwn-rail-info {
    font-size: 0.6rem;
    font-weight: 700;
    color: #94a3b8;
    user-select: none;
    padding: 2px 0;
}

/* Quadrants Grid Area */
.mwn-quadrants-grid {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: grid;
    gap: 4px;
    padding: 4px;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
}

/* 1 Quadrant */
.mwn-grid-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

/* 2 Quadrants */
.mwn-grid-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

/* 3 Quadrants */
.mwn-grid-3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: 1fr;
}

/* 4 Quadrants */
.mwn-grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* 5 Quadrants */
.mwn-grid-5 {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: 1fr 1fr;
}
.mwn-grid-5 > .mwn-quadrant-card:nth-child(1),
.mwn-grid-5 > .mwn-quadrant-card:nth-child(2),
.mwn-grid-5 > .mwn-quadrant-card:nth-child(3) {
    grid-column: span 2;
}
.mwn-grid-5 > .mwn-quadrant-card:nth-child(4),
.mwn-grid-5 > .mwn-quadrant-card:nth-child(5) {
    grid-column: span 3;
}

/* 6 Quadrants */
.mwn-grid-6 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: 1fr 1fr;
}

/* 7 Quadrants */
.mwn-grid-7 {
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 1fr 1fr;
}
.mwn-grid-7 > .mwn-quadrant-card:nth-child(1),
.mwn-grid-7 > .mwn-quadrant-card:nth-child(2),
.mwn-grid-7 > .mwn-quadrant-card:nth-child(3),
.mwn-grid-7 > .mwn-quadrant-card:nth-child(4) {
    grid-column: span 3;
}
.mwn-grid-7 > .mwn-quadrant-card:nth-child(5),
.mwn-grid-7 > .mwn-quadrant-card:nth-child(6),
.mwn-grid-7 > .mwn-quadrant-card:nth-child(7) {
    grid-column: span 4;
}

/* 8 Quadrants */
.mwn-grid-8 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 1fr 1fr;
}
.mwn-grid-8 .mwn-question-container {
    padding: 6px 10px;
    font-size: calc(0.85rem * var(--mwn-card-font-scale, 1));
    line-height: 1.45;
}
.mwn-grid-8 .mwn-answer-drawer {
    padding: 6px 10px;
    font-size: calc(0.95rem * var(--mwn-card-font-scale, 1));
}

/* Responsive Overrides for Tall (Portrait) Windows */
.mwn-app-root.mwn-h-tall .mwn-grid-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
}
.mwn-app-root.mwn-h-tall .mwn-grid-3 {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
}
.mwn-app-root.mwn-h-tall .mwn-grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
.mwn-app-root.mwn-h-tall .mwn-grid-5 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, 1fr);
}
.mwn-app-root.mwn-h-tall .mwn-grid-5 > .mwn-quadrant-card {
    grid-column: span 1 !important;
}
.mwn-app-root.mwn-h-tall .mwn-grid-5 > .mwn-quadrant-card:nth-child(5) {
    grid-column: span 2 !important;
}
.mwn-app-root.mwn-h-tall .mwn-grid-6 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, 1fr);
}
.mwn-app-root.mwn-h-tall .mwn-grid-7 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, 1fr);
}
.mwn-app-root.mwn-h-tall .mwn-grid-7 > .mwn-quadrant-card {
    grid-column: span 1 !important;
}
.mwn-app-root.mwn-h-tall .mwn-grid-7 > .mwn-quadrant-card:nth-child(7) {
    grid-column: span 2 !important;
}
.mwn-app-root.mwn-h-tall .mwn-grid-8 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, 1fr);
}

/* Individual Quadrant Card (Unrounded corners) */
.mwn-quadrant-card {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    background: #ffffff;
    border: 2.5px solid var(--mwn-pane-color, var(--mwn-border));
    border-radius: 0 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Distinct Pane Border Colors: Blue, Red, Purple, Orange, Green, Silver, Pink, Black */
.mwn-quadrant-card.mwn-pane-blue {
    border-color: #2563eb !important;
}
.mwn-quadrant-card.mwn-pane-red {
    border-color: #dc2626 !important;
}
.mwn-quadrant-card.mwn-pane-purple {
    border-color: #7c3aed !important;
}
.mwn-quadrant-card.mwn-pane-orange {
    border-color: #ea580c !important;
}
.mwn-quadrant-card.mwn-pane-green {
    border-color: #059669 !important;
}
.mwn-quadrant-card.mwn-pane-silver {
    border-color: #64748b !important;
}
.mwn-quadrant-card.mwn-pane-pink {
    border-color: #db2777 !important;
}
.mwn-quadrant-card.mwn-pane-black {
    border-color: #0f172a !important;
}

/* Spotlight / Enlarge Mode */
.mwn-quadrant-card.mwn-enlarged {
    position: absolute !important;
    top: 4px !important;
    left: 4px !important;
    right: 4px !important;
    bottom: 4px !important;
    z-index: 9999 !important;
    border-radius: 0 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3) !important;
}

/* Card Left Vertical Toolbar - Matches Pane Color */
.mwn-card-sidebar {
    width: 26px;
    flex-shrink: 0;
    background: var(--mwn-pane-color, #2563eb);
    border-right: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 1px;
    gap: 2px;
    box-sizing: border-box;
    z-index: 5;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

.mwn-card-sidebar::-webkit-scrollbar {
    display: none;
}

.mwn-app-root.mwn-sidebars-hidden .mwn-card-sidebar {
    display: none !important;
}

.mwn-sidebar-btn {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    color: #ffffff;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: all 0.15s ease;
    user-select: none;
}

.mwn-sidebar-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}

.mwn-sidebar-btn.active {
    background: #ffffff !important;
    color: var(--mwn-pane-color, #0f172a) !important;
    font-weight: 700;
}

.mwn-sidebar-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    color: #ffffff;
}

.mwn-sidebar-btn-font {
    font-size: 0.68rem;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.mwn-btn-prev {
    font-size: 0.95rem;
    color: #ffffff;
}

.mwn-sidebar-divider {
    width: 18px;
    height: 1px;
    background: rgba(255, 255, 255, 0.3);
    margin: 1px 0;
}

.mwn-icon-select-wrapper {
    position: relative;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.mwn-icon-select-wrapper .mwn-sidebar-btn {
    width: 100%;
    height: 100%;
}

/* Compact Grid Sidebar Overrides (4, 5, 6, 7, 8 Quadrants) */
.mwn-grid-4 .mwn-sidebar-btn,
.mwn-grid-5 .mwn-sidebar-btn,
.mwn-grid-6 .mwn-sidebar-btn,
.mwn-grid-7 .mwn-sidebar-btn,
.mwn-grid-8 .mwn-sidebar-btn {
    width: 20px;
    height: 20px;
    font-size: 0.72rem;
}

.mwn-grid-4 .mwn-icon-select-wrapper,
.mwn-grid-5 .mwn-icon-select-wrapper,
.mwn-grid-6 .mwn-icon-select-wrapper,
.mwn-grid-7 .mwn-icon-select-wrapper,
.mwn-grid-8 .mwn-icon-select-wrapper {
    width: 20px;
    height: 20px;
}

.mwn-grid-4 .mwn-card-sidebar,
.mwn-grid-5 .mwn-card-sidebar,
.mwn-grid-6 .mwn-card-sidebar,
.mwn-grid-7 .mwn-card-sidebar,
.mwn-grid-8 .mwn-card-sidebar {
    width: 24px;
    padding: 2px 1px;
    gap: 1.5px;
}

.mwn-sidebar-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.mwn-star-btn {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--mwn-star-active);
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 5px;
}

.mwn-star-btn:hover {
    background: #fde68a;
}

.mwn-bulb-icon {
    display: inline-block;
    vertical-align: middle;
    pointer-events: none;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.mwn-btn-answer.active,
.mwn-rail-btn-answers.active {
    background: #fef9c3;
    color: #854d0e;
    border-color: #facc15;
}

.mwn-btn-answer.active .mwn-bulb-glass,
.mwn-rail-btn-answers.active .mwn-bulb-glass {
    fill: #facc15;
    stroke: #ca8a04;
}

.mwn-btn-answer.active .mwn-bulb-icon,
.mwn-rail-btn-answers.active .mwn-bulb-icon {
    filter: drop-shadow(0 0 5px rgba(250, 204, 21, 0.8));
    transform: scale(1.08);
}

.mwn-btn-solution.active {
    background: #e0e7ff;
    color: #4338ca;
    border-color: #a5b4fc;
}

.mwn-btn-enlarge.active {
    background: #fef08a;
    color: #854d0e;
    border-color: #fde047;
}

.mwn-sidebar-spacer {
    flex: 1 1 auto;
    min-height: 4px;
}

/* Card Main Area */
.mwn-card-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: #ffffff;
    container-type: size;
}

/* Question Container - Top Aligned to Maximise White Space Below */
.mwn-question-container {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 12px;
    box-sizing: border-box;
    font-size: calc(0.95rem * var(--mwn-card-font-scale, 1));
    line-height: 1.6;
    color: #0f172a;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    min-height: 0;
    min-width: 0;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.mwn-question-body {
    display: block;
    width: 100%;
    text-align: center;
    margin-top: 2px;
    margin-bottom: auto;
    white-space: normal;
    word-break: normal;
    line-height: 1.5;
}

/* Ensure line breaks in questions provide clear separation for formulas and fractions */
.mwn-line-break {
    display: block;
    height: 6px;
    width: 100%;
}

.mwn-line-break-large {
    display: block;
    height: 12px;
    width: 100%;
}

/* Collapse redundant <br/> spacers immediately preceding diagrams or scale subtitles */
.mwn-line-break:has(+ img),
.mwn-line-break:has(+ svg),
.mwn-line-break:has(+ p),
.mwn-line-break:has(+ div img),
.mwn-line-break:has(+ div svg) {
    display: none;
}

.mwn-question-body br {
    display: block;
    content: "";
    margin-top: 6px;
    margin-bottom: 2px;
}

.mwn-question-body br + br {
    display: none;
}

/* Ensure equation and formula containers have dedicated vertical breathing room */
.mwn-question-body > div,
.mwn-question-body div[style*="margin:0 auto"],
.mwn-question-body div[style*="margin: 0 auto"],
.mwn-question-body div[style*="margin:auto"],
.mwn-question-body div[style*="margin: auto"] {
    margin-top: 6px !important;
    margin-bottom: 6px !important;
}

/* Keep diagram wrapper divs compact between prompt text and diagram */
.mwn-question-body div:has(> img),
.mwn-question-body div:has(> svg),
.mwn-question-body div:has(> div > img),
.mwn-question-body div:has(> div > svg) {
    margin-top: 2px !important;
    margin-bottom: 2px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.mwn-question-body p {
    margin: 2px 0;
    display: block;
    line-height: 1.25;
}

.mwn-question-body span:not([class*="katex"]):not([class*="katex"] *):not([style*="display"]):not([class*="mwn-"]),
.mwn-question-body sub:not([class*="katex"]):not([class*="katex"] *),
.mwn-question-body sup:not([class*="katex"]):not([class*="katex"] *) {
    display: inline;
}

/* KaTeX math presentation tweaks for Maths DoNow */
.katex-display {
    margin: 0.75em 0 !important;
}

.mwn-question-body .katex-display {
    margin: 16px 0 !important;
}

/* Protect fraction bars and give numerators/denominators vertical clearance */
.mwn-question-body .katex-display .mfrac,
.mwn-question-body .mwn-math-block .mfrac {
    padding-top: 4px;
    padding-bottom: 4px;
}

.mwn-question-body .mfrac,
.mwn-question-body .mwn-frac {
    padding-top: 1px;
    padding-bottom: 1px;
}

/* Ensure multiline centered question text (e.g. fractions with text) has proper line height */
.mwn-question-body div[style*="text-align:center"] {
    line-height: 2.2;
}

.mwn-answer-drawer .katex-display {
    margin: 6px 0 !important;
}

.mwn-exam-step .katex-display {
    margin: 2px 0 !important;
}

/* Protect KaTeX math formulas from host CSS overrides */
.katex {
    text-rendering: auto;
    line-height: normal;
    white-space: normal;
    text-indent: 0;
}

.katex .vlist-t {
    border-collapse: collapse !important;
    table-layout: fixed !important;
}

.katex .vlist > span {
    display: block !important;
    height: 0 !important;
    position: relative !important;
}

.katex .vlist > span > .pstrut {
    overflow: hidden !important;
    width: 0 !important;
}

/* Ensure KaTeX fraction bars and vinculums never vanish at small sizes */
.katex .mfrac .frac-line {
    border-bottom-width: max(1.5px, 0.05em) !important;
    border-bottom-style: solid !important;
    border-bottom-color: currentColor !important;
    min-height: 0 !important;
    height: 0 !important;
}

/* Ensure all KaTeX fractions have comfortable vertical clearance between numerator, bar, and denominator */
.katex .mfrac .vlist > span:first-child {
    transform: translateY(max(2px, 0.1em)) !important;
}
.katex .mfrac .vlist > span:nth-child(3) {
    transform: translateY(calc(-1 * max(2px, 0.1em))) !important;
}

/* Proportional superscript & subscript sizing across all KaTeX formulas
   Ensures powers (integers, letters, and expressions) are clearly legible and slightly smaller than their base */
.katex .msupsub {
    font-size: 1.00em !important;
}

/* Ensure fractions within superscripts remain legible, clear, and well-spaced */
.katex .msupsub .mfrac {
    font-size: 1.15em !important;
}

/* Numbers accompanying roots (e.g. 3 in \sqrt[3]{x}) enlarged 25% to match powers while sitting in radical crook */
.katex .katex-root .mord,
.katex .root .mord {
    font-size: 1.25em !important;
}

/* Ensure root index/degree sits perfectly in the crook of the radical sign */
.katex .sqrt > .root,
.katex .sqrt > .katex-root {
    margin-left: 0.2777777778em !important;
    margin-right: -0.5555555556em !important;
}

/* Ensure SVG radicals (square roots) render cleanly without overflow clipping or card zoom overrides */
.katex svg,
.katex .sqrt svg {
    margin: 0 !important;
    cursor: inherit !important;
    max-width: none !important;
    max-height: none !important;
    position: absolute !important;
    overflow: visible !important;
}

.mwn-question-body .mwn-frac {
    display: inline-block;
}

.mwn-question-body .mwn-surd {
    display: inline-flex;
}

/* Mathematical symbols & table stylings */
.mwn-question-container table,
.mwn-working-drawer table {
    border-collapse: collapse;
    margin: 6px auto;
    font-size: 0.9em;
}

.mwn-question-container th,
.mwn-question-container td,
.mwn-working-drawer th,
.mwn-working-drawer td {
    border: 1px solid #94a3b8;
    padding: 4px 8px;
    text-align: center;
}

.mwn-question-container svg:not(.katex svg),
.mwn-question-container img:not([style*="position:absolute"]):not([style*="position: absolute"]):not([style*="height:80px"]):not([style*="height: 80px"]),
.mwn-question-container canvas {
    width: auto !important;
    height: auto !important;
    max-width: min(calc(260px * var(--mwn-card-font-scale, 1)), 94cqw) !important;
    max-height: min(calc(155px * var(--mwn-card-font-scale, 1)), calc(100cqh - 52px)) !important;
    margin: 2px auto;
    display: block;
    transition: max-width 0.15s ease, max-height 0.15s ease, transform 0.2s ease, filter 0.2s ease;
    cursor: zoom-in;
}

.mwn-question-container div[id^="my-shape"],
.mwn-question-container div[id^="my-node"] {
    position: relative !important;
    margin: 2px auto !important;
    zoom: min(var(--mwn-card-font-scale, 1), 1.35);
}

/* Dedicated Zoom Mode for Diagrams */
.mwn-quadrant-card.mwn-diagram-zoomed .mwn-question-container svg,
.mwn-quadrant-card.mwn-diagram-zoomed .mwn-question-container img,
.mwn-quadrant-card.mwn-diagram-zoomed .mwn-question-container canvas {
    max-height: calc(260px * var(--mwn-card-font-scale, 1)) !important;
    max-width: 98% !important;
    transform: scale(1.25);
    cursor: zoom-out;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    position: relative;
    z-index: 20;
    background: #ffffff;
    border-radius: 4px;
}

/* Answer Drawer */
.mwn-answer-drawer {
    display: none;
    background: #f0fdf4;
    border-top: 1.5px solid #86efac;
    color: #15803d;
    padding: 8px 12px;
    font-size: calc(1rem * var(--mwn-card-font-scale, 1));
    font-weight: 700;
    line-height: 1.45;
    white-space: normal !important;
    overflow-wrap: break-word;
    word-break: break-word;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden !important;
    max-height: 40%;
    border-radius: 0;
    box-sizing: border-box;
    contain: content;
}

.mwn-answer-drawer > div,
.mwn-answer-drawer .katex,
.mwn-answer-drawer .katex-html,
.mwn-answer-drawer .katex-base {
    white-space: normal !important;
    width: auto !important;
    max-width: 100% !important;
    display: inline !important;
    overflow-wrap: break-word !important;
}

.mwn-answer-drawer.mwn-show {
    display: block;
    animation: mwnFadeIn 0.15s ease-out;
}

/* Working Out Full-Pane Overlay */
.mwn-working-drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    background: #ffffff;
    border-top: none;
    border-radius: 0;
    box-shadow: none;
    padding: 10px 14px;
    overflow-y: auto;
    z-index: 25;
    display: none;
    font-size: calc(0.88rem * var(--mwn-card-font-scale, 1));
    line-height: 1.5;
    color: #1e293b;
    box-sizing: border-box;
    contain: content;
}

.mwn-working-drawer.mwn-show {
    display: flex;
    flex-direction: column;
    animation: mwnFadeIn 0.15s ease-out;
}

.mwn-working-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
    margin-bottom: 8px;
    border-bottom: 1.5px solid #e2e8f0;
    flex-shrink: 0;
}

.mwn-working-drawer-title {
    font-weight: 800;
    font-size: 0.8rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mwn-working-drawer-close {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    font-size: 1.25rem;
    line-height: 1;
    color: #475569;
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.mwn-working-drawer-close:hover {
    color: #dc2626;
    background: #fee2e2;
    border-color: #fca5a5;
}

.mwn-working-drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 2px 2px 8px 2px;
}

/* Test-style Step-by-Step Working Lines */
.mwn-exam-step {
    font-size: calc(0.95rem * var(--mwn-card-font-scale, 1));
    line-height: 1.8;
    color: #0f172a;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 4px;
    border-left: 3px solid #cbd5e1;
    display: block;
    box-sizing: border-box;
    word-break: normal;
    overflow: visible;
}

.mwn-exam-step .mwn-math-block {
    margin: 2px 0;
    width: 100%;
}

.mwn-exam-step.mwn-step-final {
    background: #f0fdf4;
    border-left-color: #22c55e;
    color: #15803d;
    font-weight: 700;
}

/* Math HTML elements in questions and solutions */
.mwn-frac {
    display: inline-block;
    vertical-align: middle;
    text-align: center;
    margin: 0 0.15em;
    font-size: 0.9em;
    line-height: 1.1;
}

.mwn-frac-num {
    display: block;
    border-bottom: 1.5px solid currentColor;
    padding: 0 0.15em;
    line-height: 1.1;
}

.mwn-frac-den {
    display: block;
    padding: 0 0.15em;
    line-height: 1.1;
}

/* Fractional Indices and Superscripts Alignment (over brackets & terms) */
.mwn-question-body .rightbracketstyling + sup,
.mwn-question-container .rightbracketstyling + sup,
.mwn-question-body div[style*="position:relative"] > sup,
.mwn-question-container div[style*="position:relative"] > sup,
.mwn-question-body sup[style*="position:absolute"],
.mwn-question-container sup[style*="position:absolute"] {
    position: relative !important;
    top: 0 !important;
    vertical-align: top !important;
    display: inline-block !important;
    margin-left: 2px !important;
    transform: none !important;
}

.mwn-question-body div[style*="position:relative"],
.mwn-question-container div[style*="position:relative"] {
    margin-top: 6px !important;
    margin-bottom: 6px !important;
}

.mwn-question-body sup,
.mwn-question-container sup,
.mwn-working-drawer sup,
.mwn-answer-drawer sup,
.mwn-exam-step sup {
    font-size: 0.72em;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
    top: -0.48em;
    display: inline;
}

.mwn-question-body sub,
.mwn-question-container sub,
.mwn-working-drawer sub,
.mwn-answer-drawer sub,
.mwn-exam-step sub {
    font-size: 0.72em;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
    bottom: -0.25em;
    display: inline;
}

.mwn-question-body sup .mwn-frac,
.mwn-question-container sup .mwn-frac {
    font-size: 0.85em;
    vertical-align: middle;
    margin: 0 1px;
}

.mwn-question-body sup span[style*="inline-block"],
.mwn-question-container sup span[style*="inline-block"],
.mwn-working-drawer sup span[style*="inline-block"],
.mwn-answer-drawer sup span[style*="inline-block"] {
    vertical-align: middle !important;
    font-size: 0.85em !important;
}

/* Ensure top alignment in question body to maximize white space below */
.mwn-question-body > div:first-child,
.mwn-question-body > p:first-child {
    margin-top: 0 !important;
}

.mwn-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.88rem;
    margin: 6px 0;
}

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

@keyframes mwnSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Master Rail Reorder & Lock Button Styles */
.mwn-rail-btn-settings {
    font-size: 1.05rem;
    color: #475569;
}

.mwn-rail-btn-settings.mwn-active {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
    border-color: #93c5fd !important;
}

.mwn-rail-btn-font {
    font-size: 0.72rem;
    font-weight: 800;
    color: #475569;
    letter-spacing: -0.5px;
}

.mwn-rail-btn-font:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #cbd5e1;
}

.mwn-rail-btn-lock {
    color: #64748b;
    font-size: 1rem;
}

.mwn-rail-btn-lock.mwn-locked-active {
    background: #fef3c7;
    color: #b45309;
    border-color: #fcd34d;
}

/* Locked Board Mode: disable edit controls and reveal only answers/solution/font resize/fullscreen */
.mwn-app-root.mwn-locked .mwn-card-actions,
.mwn-app-root.mwn-locked .mwn-card-rearrange-btn,
.mwn-app-root.mwn-locked .mwn-card-remove-btn,
.mwn-app-root.mwn-locked .mwn-btn-topic,
.mwn-app-root.mwn-locked .mwn-icon-select-wrapper,
.mwn-app-root.mwn-locked .mwn-btn-reroll,
.mwn-app-root.mwn-locked .mwn-btn-prev,
.mwn-app-root.mwn-locked .mwn-sidebar-divider,
.mwn-app-root.mwn-locked .mwn-rail-btn-add,
.mwn-app-root.mwn-locked .mwn-rail-btn-settings,
.mwn-app-root.mwn-locked .mwn-rail-btn-reroll-all,
.mwn-app-root.mwn-locked .mwn-rail-btn-reset {
    display: none !important;
}

/* Panel Actions Cluster (Top-Right of Each Panel: Rearrange & Remove) */
.mwn-card-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    z-index: 15;
}

.mwn-card-action-btn {
    width: 24px;
    height: 24px;
    border-radius: 5px;
    border: 1px solid #cbd5e1;
    background: rgba(255, 255, 255, 0.95);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: all 0.15s ease;
}

.mwn-card-rearrange-btn {
    color: #475569;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.mwn-card-rearrange-btn:hover {
    background: #eff6ff;
    color: #2563eb;
    border-color: #93c5fd;
    transform: scale(1.08);
}

.mwn-card-rearrange-btn:active {
    cursor: grabbing;
}

.mwn-drag-icon {
    pointer-events: none;
}

.mwn-card-remove-btn {
    color: #dc2626;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
}

.mwn-card-remove-btn:hover {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fca5a5;
    transform: scale(1.08);
}

/* Pane Drag-and-Drop Reorder Feedback */
.mwn-quadrant-card.mwn-pane-dragging {
    opacity: 0.45;
    transform: scale(0.98);
    box-shadow: 0 0 0 2px var(--mwn-pane-color, #2563eb), 0 8px 24px rgba(0, 0, 0, 0.22);
    transition: transform 0.12s ease, opacity 0.12s ease;
}

.mwn-quadrant-card.mwn-drop-hover {
    outline: 3px dashed var(--mwn-pane-color, #2563eb) !important;
    outline-offset: -3px;
    background: #f8fafc;
    transform: scale(1.015);
    transition: transform 0.12s ease, outline 0.12s ease;
}

/* Font Size Popover Widget (+ and - only) */
.mwn-popover,
.mwn-font-size-widget {
    position: absolute;
    z-index: 10005 !important;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    padding: 8px 10px;
    min-width: 96px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    animation: mwnFadeIn 0.12s ease-out;
}

.mwn-font-widget-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.mwn-font-widget-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mwn-font-widget-btn {
    width: 36px;
    height: 32px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #f8fafc;
    color: #1e293b;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.mwn-font-widget-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.mwn-star-widget-btn {
    font-size: 0.9rem;
    padding: 0 4px;
    min-width: 38px;
    color: #b45309;
}

.mwn-star-widget-btn.mwn-active {
    background: #fef3c7;
    border-color: #d97706;
    color: #92400e;
    box-shadow: 0 0 0 1px #d97706;
}

/* Topic Search Modal Overlay */
.mwn-topic-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 10010 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    animation: mwnFadeIn 0.15s ease-out;
}

.mwn-topic-modal-card {
    width: 100%;
    max-width: 580px;
    max-height: 90%;
    height: 520px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #cbd5e1;
}

.mwn-topic-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.mwn-topic-modal-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mwn-topic-modal-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}

.mwn-topic-modal-close:hover {
    background: #fee2e2;
    color: #dc2626;
}

.mwn-topic-search-bar {
    position: relative;
    display: flex;
    align-items: center;
    padding: 10px 16px 6px 16px;
    background: #ffffff;
}

.mwn-topic-search-input {
    width: 100%;
    padding: 8px 36px 8px 12px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.92rem;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.mwn-topic-search-clear {
    position: absolute;
    right: 22px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.mwn-topic-search-clear:hover {
    background: #cbd5e1;
    color: #0f172a;
}

.mwn-topic-search-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.mwn-topic-cat-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px 10px 16px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid #e2e8f0;
    scrollbar-width: none;
    min-height: 44px;
    box-sizing: border-box;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
}

.mwn-topic-cat-pills::-webkit-scrollbar {
    display: none;
}

.mwn-topic-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    min-height: 28px;
    line-height: 28px;
    padding: 0 12px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #475569;
    cursor: pointer;
    transition: all 0.12s;
    user-select: none;
    flex-shrink: 0;
    box-sizing: border-box;
    white-space: nowrap;
}

.mwn-topic-pill:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.mwn-topic-pill.mwn-active {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

.mwn-topic-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    position: relative;
    scroll-behavior: auto;
}

.mwn-topic-cat-heading {
    font-size: 0.72rem;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 8px 8px 3px 8px;
}

.mwn-topic-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    font-size: 0.88rem;
    color: #1e293b;
    text-align: left;
    transition: all 0.12s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

.mwn-topic-row:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.mwn-topic-row.mwn-selected {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
    font-weight: 600;
}

.mwn-topic-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mwn-topic-cat-badge {
    font-size: 0.7rem;
    font-weight: 600;
    background: #e2e8f0;
    color: #475569;
    padding: 2px 6px;
    border-radius: 4px;
}

.mwn-topic-lvl-badge {
    font-size: 0.7rem;
    font-weight: 700;
    background: #fef3c7;
    color: #92400e;
    padding: 2px 6px;
    border-radius: 4px;
}

.mwn-topic-empty {
    text-align: center;
    color: #64748b;
    padding: 30px 16px;
    font-size: 0.9rem;
}
