::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f8f9fa;
}
.dark ::-webkit-scrollbar-track {
    background: #060608;
}
::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 3px;
}
.dark ::-webkit-scrollbar-thumb {
    background: #1c1c24;
}
::-webkit-scrollbar-thumb:hover {
    background: #B45309;
}
.border-glow:hover {
    box-shadow: 0 0 15px rgba(180, 83, 9, 0.08);
    border-color: rgba(180, 83, 9, 0.3);
}
.katex {
    font-size: 1.1em !important;
}


/* CLS prevention: reserve height for math before KaTeX hydration */
.math-target {
    min-height: 2.5em;
    display: block;
    line-height: 2.2;
}
.math-fallback.math-block {
    min-height: 2.5em;
    display: block;
    line-height: 2.2;
    text-align: center;
}
.math-fallback.math-inline {
    display: inline-block;
    min-height: auto;
    line-height: inherit;
    font-style: italic;
    padding: 0 2px;
}
.katex:not(.katex-display .katex) {
    min-height: 1.2em;
    display: inline-block;
    vertical-align: middle;
}
.katex-display > .katex {
    min-height: auto;
}
.rankbit-double-box-container {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}
/* ── Robust SVG / image display fix ─────────────────────────────── */
.token-media img,
.token-media svg {
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
    /* Never let an inline SVG spill outside its container */
    overflow: hidden !important;
}
.question-image-block {
    margin: 0.9rem auto 1.1rem;
    max-width: min(760px, 96%);
    width: 100%;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: transparent;
    /* Prevent SVG overflow from leaking out */
    overflow: hidden;
}
.question-image-block img {
    width: auto;
    max-width: 100%;
    min-width: 120px;
    max-height: 420px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}
.question-image-block svg {
    max-width: 100% !important;
    max-height: 420px !important;
    width: auto !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
}
.main-question-field .inline-token-media {
    display: inline-block;
    vertical-align: middle;
    max-width: min(240px, 70vw);
    margin: 0 0.35rem;
    overflow: hidden;
}
.main-question-field .inline-token-media img,
.main-question-field .inline-token-media svg {
    max-height: 110px !important;
    width: auto !important;
    max-width: 100% !important;
    border-radius: 8px;
}
.diagram-block {
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 180px;
}
.dark .diagram-block {
    border-color: #1c1c24;
}
.diagram-block img, .diagram-block svg {
    max-width: 240px; /* maintained proper visually appealing size ratio */
    height: auto;
}
@keyframes float-up {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(-100px) rotate(360deg); opacity: 0; }
}
.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: float-up 1s forwards ease-out;
    z-index: 100;
}

/* ── Options Media Adjustments ─────────────────────────────── */
.opt-action-trigger .question-image-block {
    margin: 0.4rem 0 0;
    max-width: 100%;
}
.opt-action-trigger .question-image-block img,
.opt-action-trigger .question-image-block svg {
    max-height: 220px !important;
    width: auto !important;
    margin: 0 !important;
}

/* ── Multi-Media Grid Items ─────────────────────────────── */
.multimedia-grid-item {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    background: transparent !important;
}
.multimedia-grid-item img,
.multimedia-grid-item svg {
    max-height: 160px !important;
    width: auto !important;
    margin: 0 auto !important;
}

/* ── Solution Media Compact Sizing & Spacing ──────────────── */
.rankbit-double-box-container .question-image-block {
    margin: 0.25rem auto 0.4rem !important;
    max-width: min(560px, 96%) !important;
}
.rankbit-double-box-container .question-image-block img,
.rankbit-double-box-container .question-image-block svg {
    max-height: 340px !important;
    width: auto !important;
    margin: 0 auto !important;
}

/* ── Button Responsiveness and Viewport Stabilization ─────── */
button,
.opt-action-trigger,
.num-key,
.verify-btn,
.num-verify-btn,
.sub-reveal-btn {
    touch-action: manipulation !important; /* Disables double-tap zoom delay on mobile viewports */
    -webkit-tap-highlight-color: transparent !important; /* Removes grey block overlay feedback on tap */
    user-select: none !important; /* Prevents text highlighting under rapid interaction clicks */
}

/* Stabilize click latency and active state feedback */
button:active,
.opt-action-trigger:active,
.num-key:active {
    transform: scale(0.985);
    transition: transform 0.05s ease;
}

@media (max-width: 640px) {
    /* Responsive margins and paddings for small mobile viewport buttons */
    .opt-action-trigger {
        padding: 0.75rem 1rem !important;
        font-size: 0.95rem !important;
    }
}

/* ── Premium SEO Pre-render Styles (Vanilla CSS Fallback) ── */
/* Content-first source order: the SSR block is injected as the first child of <body>
   so crawlers read the question/answer/solution before any navigation boilerplate.
   flex `order` keeps it visually after the sticky header for human visitors.
   JS sets display:none on it after hydration, so it never shows on interactive pages. */
#seo-pre-render-container {
    order: 5;
    max-width: 1200px;
    margin: 40px auto;
    padding: 32px;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    color: #1f2937;
    transition: all 0.3s ease;
}

.dark #seo-pre-render-container {
    background-color: #121217;
    border-color: #272733;
    color: #f3f4f6;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.seo-breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #d97706; /* brand amber */
    margin-bottom: 20px;
}

.seo-breadcrumbs a {
    color: #d97706;
    text-decoration: none;
    transition: color 0.2s ease;
}

.seo-breadcrumbs a:hover {
    text-decoration: underline;
}

.seo-breadcrumbs span {
    color: #6b7280;
}

.dark .seo-breadcrumbs span {
    color: #9ca3af;
}

#seo-pre-render-container h1 {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.25;
    margin-top: 0;
    margin-bottom: 12px;
    color: #111827;
}

.dark #seo-pre-render-container h1 {
    color: #ffffff;
}

#seo-pre-render-container p {
    font-size: 15px;
    line-height: 1.6;
    color: #4b5563;
    margin-bottom: 24px;
}

.dark #seo-pre-render-container p {
    color: #9ca3af;
}

#seo-pre-render-container ul {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    list-style: none;
    padding: 0;
    margin: 0;
}

@media (min-width: 768px) {
    #seo-pre-render-container ul {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #seo-pre-render-container ul.space-y-3,
    #seo-pre-render-container ul.question-options {
        grid-template-columns: 1fr;
    }
}

#seo-pre-render-container li {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}

.dark #seo-pre-render-container li {
    background-color: #1c1c24;
    border-color: #272733;
}

#seo-pre-render-container li:hover {
    border-color: #d97706;
    box-shadow: 0 0 12px rgba(217, 119, 6, 0.08);
    background-color: #ffffff;
}

.dark #seo-pre-render-container li:hover {
    background-color: #1e1e27;
}

#seo-pre-render-container li a {
    color: #111827;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
    line-height: 1.4;
}

.dark #seo-pre-render-container li a {
    color: #ffffff;
}

#seo-pre-render-container li a:hover {
    color: #d97706;
    text-decoration: underline;
}

/* Question detail pre-render overrides */
.main-question-field {
    font-size: 18px;
    line-height: 1.7;
    color: #1f2937;
    padding-bottom: 24px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 24px;
}

.dark .main-question-field {
    color: #f3f4f6;
    border-color: #272733;
}

.passage-context {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #4b5563;
}

.dark .passage-context {
    background-color: #1c1c24;
    border-color: #272733;
    color: #9ca3af;
}

.passage-context h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0;
    margin-bottom: 8px;
    color: #111827;
}

.dark .passage-context h3 {
    color: #ffffff;
}

#seo-pre-render-container ul.question-options li {
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dark #seo-pre-render-container ul.question-options li {
    border-color: #272733;
    background-color: #121217;
}

#seo-pre-render-container ul.question-options li.bg-emerald-50\/5 {
    border-color: rgba(16, 185, 129, 0.3) !important;
    background-color: rgba(16, 185, 129, 0.05) !important;
    color: #047857 !important;
}

.dark #seo-pre-render-container ul.question-options li.bg-emerald-50\/5 {
    color: #34d399 !important;
}

.question-solution {
    background-color: rgba(217, 119, 6, 0.05);
    border: 1px solid rgba(217, 119, 6, 0.2);
    border-radius: 12px;
    padding: 24px;
    margin-top: 24px;
}

.question-solution h2 {
    color: #d97706;
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 18px;
    font-weight: 700;
}

.seo-study-references {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    font-size: 13px;
    margin-top: 24px;
}

.dark .seo-study-references {
    background-color: #1c1c24;
    border-color: #272733;
}

.seo-study-references h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-top: 0;
    margin-bottom: 8px;
}

.dark .seo-study-references h3 {
    color: #9ca3af;
}

.seo-study-references a {
    color: #d97706;
    text-decoration: none;
    margin-right: 16px;
    font-weight: 600;
}

.seo-study-references a:hover {
    text-decoration: underline;
}

.seo-image-block {
    display: block;
    margin: 16px 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background-color: #f3f4f6;
    padding: 8px;
    max-width: 100%;
}

.dark .seo-image-block {
    border-color: #272733;
    background-color: #1c1c24;
}

.seo-image-block img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

/* ── Premium Pre-render Component Styles ── */
.seo-chapter-card {
    background-color: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    padding: 24px !important;
    margin-bottom: 20px !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02) !important;
    color: #111827 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
}
.dark .seo-chapter-card {
    background-color: #0b0b0e !important;
    border-color: #1c1c24 !important;
    color: #f3f4f6 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
}
.seo-chapter-card:hover {
    border-color: #d97706 !important;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.08) !important;
}
.seo-sample-box {
    background-color: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 8px !important;
    padding: 16px !important;
    color: #4b5563 !important;
}
.dark .seo-sample-box {
    background-color: #121217 !important;
    border-color: #1c1c24 !important;
    color: #9ca3af !important;
}
.seo-gradient-banner {
    border-radius: 16px !important;
    padding: 24px !important;
    margin-bottom: 28px !important;
    color: #ffffff !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 24px !important;
    border: 1px solid transparent !important;
}
.seo-yield-box {
    padding: 10px 16px !important;
    border-radius: 8px !important;
    text-align: center !important;
    min-width: 70px !important;
}
.seo-progress-bar {
    height: 8px !important;
    border-radius: 4px !important;
    overflow: hidden !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    display: flex !important;
}
.seo-progress-bar-bg {
    background-color: rgba(0, 0, 0, 0.05) !important;
    height: 6px !important;
    border-radius: 3px !important;
    overflow: hidden !important;
    width: 100% !important;
}
.seo-btn-amber {
    background-color: #B45309 !important;
    color: #ffffff !important;
    padding: 8px 16px !important;
    border-radius: 6px !important;
    font-weight: 700 !important;
    text-decoration: none !important;
    display: inline-block !important;
    text-align: center !important;
    font-size: 12px !important;
    transition: background-color 0.2s ease !important;
}
.seo-btn-amber:hover {
    background-color: #d97706 !important;
}





/* ============================================================
   KATEX MOBILE: SCROLL-FIRST + LEFT-ALIGNED (v3)

   Rules:
   • Scroll overflowing math — never hide the scrollbar, show branded amber
   • Left-align from the outermost wrapper so x=0 is always the first char
   • NEVER set white-space:normal on .base or .katex-html — that causes
     KaTeX to split subscripts (CH_3CHO → "CH" / "3CHO") and collapses
     inline-block elements to 1-character-wide vertical columns
   • Pure \text{} blocks get word-wrap enabled by a JS MutationObserver
     (see index.html script) — CSS cannot safely distinguish them
   ============================================================ */

/* 1. Scroll container — left-aligned, branded amber scrollbar */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    text-align: left !important;
    scrollbar-width: thin;
    scrollbar-color: #B45309 transparent;
}
.katex-display::-webkit-scrollbar {
    height: 3px;
}
.katex-display::-webkit-scrollbar-track {
    background: transparent;
}
.katex-display::-webkit-scrollbar-thumb {
    background: #B45309;
    border-radius: 2px;
}

/* 2. Inner content: block-level + left-aligned (overrides KaTeX's default center) */
.katex-display > .katex {
    text-align: left !important;
    display: block !important;
}
.katex-display > .katex > .katex-html {
    text-align: left !important;
    display: block !important;
}

/* 3. Mobile: left-align table cells so the first column never starts at x<0 */
@media (max-width: 768px) {
    .katex-display .mtable {
        margin-left: 0 !important;
        text-align: left !important;
    }
    .katex-display .mtd {
        text-align: left !important;
    }
}

/* 4. Formula Tracker sidebar: always-visible branded scrollbar */
#formula-tracker-sidebar {
    scrollbar-width: thin;
    scrollbar-color: #B45309 transparent;
}
#formula-tracker-sidebar::-webkit-scrollbar {
    width: 3px;
}
#formula-tracker-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
#formula-tracker-sidebar::-webkit-scrollbar-thumb {
    background: #B45309;
    border-radius: 2px;
}

/* ── katex-text-mode ────────────────────────────────────────────────────────
   Applied by the MutationObserver in index.html to every .katex-display that
   contains NO layout-sensitive math (.mfrac / .msupsub / .mtable / .mop /
   .vlist-t2).  By using a CSS class + !important we sidestep every inline-
   style specificity race against KaTeX's own stylesheet.

   KaTeX defaults that we must beat:
     .katex-display > .katex  { white-space: nowrap; }
     .katex .base             { display: inline-block; width: min-content;
                                white-space: nowrap; }

   Result: text wraps naturally; no horizontal scrollbar; math is unchanged.
   ─────────────────────────────────────────────────────────────────────── */
.katex-text-mode {
    overflow-x: visible !important;
}
.katex-text-mode .katex {
    display: inline !important;
    white-space: normal !important;
    overflow: visible !important;
}
.katex-text-mode .katex-html {
    display: inline !important;
    overflow: visible !important;
}
.katex-text-mode .base {
    display: inline !important;
    white-space: normal !important;
    width: auto !important;
    overflow-wrap: break-word !important;
}

/* Global smooth color transitions active ONLY during a theme toggle */
.theme-transitioning, .theme-transitioning *, .theme-transitioning *::before, .theme-transitioning *::after {
    transition-property: background-color, border-color, color, fill, stroke !important;
    transition-duration: 300ms !important;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* --- Premium Tables --- */
.rankbit-table-container {
    overflow-x: auto;
    margin: 1.5rem 0;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
}
.dark .rankbit-table-container {
    border-color: #374151;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    background: #1f2937;
}

.rankbit-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 15px;
    background-color: #ffffff;
}
.dark .rankbit-table {
    background-color: #1f2937;
    color: #e5e7eb;
}

.rankbit-table th {
    background-color: #f9fafb;
    color: #374151;
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
}
.dark .rankbit-table th {
    background-color: #111827;
    color: #9ca3af;
    border-bottom-color: #374151;
}

.rankbit-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}
.dark .rankbit-table td {
    border-bottom-color: #374151;
}

.rankbit-table tbody tr {
    transition: background-color 0.2s ease;
}
.rankbit-table tbody tr:hover {
    background-color: #f3f4f6;
}
.dark .rankbit-table tbody tr:hover {
    background-color: #374151;
}
.rankbit-table tbody tr:last-child td {
    border-bottom: none;
}
