/* ==========================================================================
   SJMaths — Class 11 Chemistry Common Design System & UI/UX Engine
   Theme: Quantum Orbital & Chemistry Lab Palette (Indigo, Cyan, Emerald, Amber)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;500;600;700&display=swap');

:root {
    /* Quantum Orbital & Chemistry Lab Palette */
    --chem-p: #4f46e5;            /* Electric Indigo (Primary) */
    --chem-p-hover: #4338ca;      /* Deep Indigo hover */
    --chem-p-light: #eef2ff;      /* Indigo mist tint */
    --chem-cyan: #0891b2;         /* Cyan solution accent */
    --chem-cyan-light: #ecfeff;   /* Cyan mist tint */
    --chem-emerald: #059669;      /* Synthesis emerald */
    --chem-emerald-light: #ecfdf5;/* Emerald mist */
    --chem-amber: #d97706;        /* Bunsen flame amber */
    --chem-amber-light: #fffbeb;  /* Amber mist */
    --chem-rose: #e11d48;         /* Litmus crimson */
    --chem-rose-light: #fff1f2;   /* Rose mist */
    --chem-violet: #7c3aed;       /* Potassium flame violet */
    --chem-violet-light: #f5f3ff; /* Violet mist */
    --chem-dark: #0f172a;         /* Deep slate heading */
    --chem-ink: #1e293b;          /* Body text color */
    --chem-muted: #64748b;        /* Secondary muted text */
    --chem-border: #e2e8f0;       /* Card border */
    --chem-border-subtle: #f1f5f9;/* Light inner border */
    --chem-bg: #f8fafc;           /* Clean laboratory background */
    --chem-card: #ffffff;         /* Crisp white card */
    --chem-formula-bg: #0b0f19;   /* High-contrast dark equation canvas */
    
    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;

    /* Geometry & Depth */
    --chem-radius-sm: 8px;
    --chem-radius-md: 14px;
    --chem-radius-lg: 20px;
    --chem-radius-xl: 28px;
    --chem-shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
    --chem-shadow-md: 0 10px 25px -4px rgba(79, 70, 229, 0.07), 0 4px 10px rgba(15, 23, 42, 0.03);
    --chem-shadow-lg: 0 20px 40px -8px rgba(79, 70, 229, 0.12), 0 8px 16px rgba(15, 23, 42, 0.04);

    /* Interoperability variables for Class 9/10 parity */
    --sj-p: var(--chem-p);
    --sj-pd: var(--chem-p-hover);
    --sj-bg: var(--chem-bg);
    --sj-s: var(--chem-dark);
    --sj-border: var(--chem-border);
    --sj-card-bg: var(--chem-card);
}

/* ===== Base Resets & Global Typography ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-body);
    background-color: var(--chem-bg);
    color: var(--chem-ink);
    line-height: 1.75;
    font-size: 1rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--chem-dark);
    font-weight: 700;
    line-height: 1.3;
}

p {
    margin-bottom: 1.25rem;
    color: #334155;
    font-size: 0.98rem;
}

strong, b {
    color: var(--chem-dark);
    font-weight: 700;
}

ul, ol {
    margin-bottom: 1.35rem;
    padding-left: 1.6rem;
}

li {
    margin-bottom: 0.5rem;
    line-height: 1.7;
    color: #334155;
}

li::marker {
    color: var(--chem-p);
    font-weight: 800;
}

code, var, kbd, samp {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 6px;
    color: #312e81;
    border: 1px solid #e2e8f0;
}

/* Highlight tags */
.chem-highlight {
    background: linear-gradient(120deg, rgba(79, 70, 229, 0.12) 0%, rgba(6, 182, 212, 0.12) 100%);
    color: var(--chem-p);
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* ===== Layout Container ===== */
.chem-container, .sj-container {
    width: 100%;
    max-width: 1160px;
    margin: 0 auto;
    padding: 16px 20px 40px;
}

/* ===== Top Bar / Breadcrumb Navigation ===== */
.chem-tbar, .sj-tbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-radius: var(--chem-radius-md);
    margin-bottom: 14px;
    box-shadow: var(--chem-shadow-sm);
}

.chem-bcrumb, .sj-bcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--chem-muted);
    flex-wrap: wrap;
}

.chem-bcrumb a, .sj-bcrumb a {
    color: var(--chem-p);
    text-decoration: none;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chem-bcrumb a:hover, .sj-bcrumb a:hover {
    color: var(--chem-p-hover);
    text-decoration: underline;
}

.chem-bcrumb i, .sj-bcrumb i {
    font-size: 0.75rem;
    color: #cbd5e1;
}

.chem-btn, .sj-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--chem-p-light);
    color: var(--chem-p);
    font-family: var(--font-heading);
    font-size: 0.84rem;
    font-weight: 700;
    text-decoration: none;
    border: 1px solid rgba(79, 70, 229, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chem-btn:hover, .sj-btn:hover {
    background: var(--chem-p);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
    transform: translateY(-1px);
}

/* ===== Chemistry Hero Header Banner ===== */
.chem-hero, .science-hero {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: center !important;
    text-align: left !important;
    height: auto !important;
    min-height: 160px !important;
    padding: 32px 28px !important;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4338ca 75%, #0891b2 100%) !important;
    border-radius: var(--chem-radius-xl) !important;
    color: #ffffff !important;
    margin-bottom: 16px !important;
    overflow: hidden !important;
    box-shadow: var(--chem-shadow-lg) !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
}

.chem-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 85% 20%, rgba(6, 182, 212, 0.28) 0%, transparent 45%),
                radial-gradient(circle at 15% 85%, rgba(124, 58, 237, 0.35) 0%, transparent 50%);
    pointer-events: none;
}

.chem-hero .chapter-badge {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 6px 14px !important;
    border-radius: 999px !important;
    background: rgba(255, 255, 255, 0.16) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    font-family: var(--font-heading) !important;
    font-size: 0.76rem !important;
    font-weight: 800 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    color: #e0e7ff !important;
    margin-bottom: 14px !important;
    width: fit-content !important;
    max-width: 100% !important;
    white-space: normal !important;
    line-height: 1.3 !important;
}

.chem-hero h1 {
    display: block !important;
    width: 100% !important;
    font-size: clamp(1.6rem, 4vw, 2.5rem) !important;
    font-weight: 850 !important;
    color: #ffffff !important;
    letter-spacing: -0.02em !important;
    margin-bottom: 12px !important;
    line-height: 1.25 !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

.chem-hero p {
    display: block !important;
    width: 100% !important;
    font-size: 0.98rem !important;
    color: #cbd5e1 !important;
    max-width: 820px !important;
    margin-bottom: 0 !important;
    line-height: 1.65 !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

/* ===== Sticky Glassmorphism Tabs Navigation ===== */
.chem-tabs, .science-tabs, .tabs {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    gap: 8px !important;
    padding: 6px !important;
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid var(--chem-border) !important;
    border-radius: 50px !important;
    margin-bottom: 10px !important;
    position: sticky !important;
    top: 12px !important;
    z-index: 99 !important;
    box-shadow: var(--chem-shadow-md) !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.chem-tabs::-webkit-scrollbar, .science-tabs::-webkit-scrollbar, .tabs::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.chem-tab, .science-tab, .tab {
    flex: 0 0 auto !important;
    min-width: max-content !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 10px 18px !important;
    border: 1px solid transparent !important;
    border-radius: 50px !important;
    background: transparent !important;
    color: var(--chem-muted) !important;
    font-family: var(--font-heading) !important;
    font-size: 0.88rem !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    min-height: 40px !important;
}

.chem-tab:hover, .science-tab:hover, .tab:hover {
    color: var(--chem-p) !important;
    background: var(--chem-p-light) !important;
}

.chem-tab.active, .science-tab.active, .tab.active {
    background: var(--chem-p) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

/* Tab Label Responsive Visibility: Desktop shows full, mobile shows short */
.chem-tab .short,
.science-tab .short,
.tab .short {
    display: none !important;
}

.chem-tab .full,
.science-tab .full,
.tab .full {
    display: inline !important;
}

/* Tab pane visibility */
.tab-pane, .pane {
    display: none;
}

.tab-pane.active, .pane.active {
    display: block;
    animation: chemFadeIn 0.25s ease-out forwards;
}

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

/* Crawler & Print Optimization: Ensure full content indexing and print fidelity */
@media print {
    .chem-tabs, .chem-nav, .theme-toggle, #darkToggle, .sol-toggle-btn, .toggle-sol-btn, .mobile-bottom-nav, .chem-tbar .chem-nav {
        display: none !important;
    }

    .tab-pane, .pane {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        margin-bottom: 30px !important;
    }

    .solution-box {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* ===== Bento Grid & Topic Overview Cards ===== */
.chem-grid, .science-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 26px;
}

.topic-card {
    background: var(--chem-card);
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    padding: 22px;
    box-shadow: var(--chem-shadow-sm);
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.topic-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--chem-p), var(--chem-cyan));
    opacity: 0;
    transition: opacity 0.2s;
}

.topic-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--chem-shadow-md);
    border-color: rgba(79, 70, 229, 0.3);
}

.topic-card:hover::before {
    opacity: 1;
}

.topic-number {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--chem-p-light);
    color: var(--chem-p);
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 900;
    margin-bottom: 12px;
}

.topic-card h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--chem-dark);
}

.topic-card p {
    font-size: 0.92rem;
    color: var(--chem-muted);
    margin-bottom: 0;
    line-height: 1.6;
}

/* ===== Standard Premium Content Cards ===== */
.chem-card, .science-card, .concept-card {
    background: var(--chem-card);
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    padding: 14px 20px;
    margin-bottom: 10px;
    box-shadow: var(--chem-shadow-sm);
}

.chem-card h2, .science-card h2, .concept-card h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0px;
    color: var(--chem-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chem-card h3, .science-card h3, .concept-card h3 {
    font-size: 1.2rem;
    font-weight: 750;
    margin: 20px 0 10px;
    color: var(--chem-dark);
}

/* ===== Chemical Equation Canvas & Formula Blocks ===== */
.chem-eq, .formula {
    margin: 18px 0;
    padding: 16px 20px;
    border-radius: var(--chem-radius-md);
    background: var(--chem-formula-bg);
    color: #ffffff;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 500;
    box-shadow: var(--chem-shadow-md);
    border: 1px solid #1e293b;
    max-width: 100% !important;
    box-sizing: border-box !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(79, 70, 229, 0.4) transparent;
}

.chem-eq::-webkit-scrollbar, .formula::-webkit-scrollbar {
    height: 4px;
}

.chem-eq::-webkit-scrollbar-thumb, .formula::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.4);
    border-radius: 4px;
}

.chem-eq small, .formula small {
    display: block;
    margin-top: 6px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: #94a3b8;
}

.formula-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin: 12px 0 18px;
    padding: 12px 16px;
    background: var(--chem-border-subtle);
    border-radius: var(--chem-radius-sm);
    font-size: 0.88rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #475569;
}

.legend-item strong {
    font-family: var(--font-mono);
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 0.85rem;
}

.f-indigo { background: #e0e7ff; color: #3730a3; }
.f-cyan { background: #cffafe; color: #0e7490; }
.f-emerald { background: #d1fae5; color: #065f46; }
.f-amber { background: #fef3c7; color: #92400e; }
.f-rose { background: #ffe4e6; color: #9f1239; }
.f-violet { background: #ede9fe; color: #5b21b6; }

/* ===== Tricks, Mnemonics & Key Takeaway Callout Boxes ===== */
.trick-box, .mnemonic-card {
    position: relative;
    padding: 18px 22px;
    border-radius: var(--chem-radius-md);
    background: linear-gradient(135deg, #fdf4ff 0%, #fae8ff 100%);
    border: 1.5px solid #f0abfc;
    border-left: 5px solid #c026d3;
    margin: 18px 0;
    box-shadow: var(--chem-shadow-sm);
}

.trick-box .trick-title, .mnemonic-card .mnemonic-title {
    font-family: var(--font-heading);
    font-size: 0.98rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #86198f;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.trick-box p, .mnemonic-card p {
    color: #4a044e;
    font-size: 0.94rem;
    margin-bottom: 0;
    line-height: 1.6;
}

.trick-box code, .mnemonic-card code {
    background: #ffffff;
    color: #a21caf;
    border-color: #f5d0fe;
    font-weight: 700;
}

.key-takeaway, .quick-check {
    padding: 16px 20px;
    border-radius: var(--chem-radius-md);
    background: var(--chem-emerald-light);
    border: 1px solid #a7f3d0;
    border-left: 4px solid var(--chem-emerald);
    color: #064e3b;
    margin: 16px 0;
    font-size: 0.94rem;
}

.key-takeaway strong, .quick-check strong {
    color: #047857;
}

.exam-warning {
    padding: 16px 20px;
    border-radius: var(--chem-radius-md);
    background: var(--chem-rose-light);
    border: 1px solid #fecdd3;
    border-left: 4px solid var(--chem-rose);
    color: #881337;
    margin: 16px 0;
    font-size: 0.94rem;
}

.exam-tip {
    padding: 16px 20px;
    border-radius: var(--chem-radius-md);
    background: var(--chem-amber-light);
    border: 1px solid #fde68a;
    border-left: 4px solid var(--chem-amber);
    color: #78350f;
    margin: 16px 0;
    font-size: 0.94rem;
}

/* ===== Comparison Tables & Periodic Grids ===== */
.chem-table-wrap {
    margin: 18px 0;
    overflow-x: auto;
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-md);
    background: var(--chem-card);
    box-shadow: var(--chem-shadow-sm);
}

.chem-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    text-align: left;
}

.chem-table th {
    background: var(--chem-p-light);
    color: var(--chem-p-hover);
    font-family: var(--font-heading);
    font-weight: 800;
    padding: 12px 16px;
    border-bottom: 1.5px solid #c7d2fe;
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chem-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--chem-border-subtle);
    color: #334155;
    vertical-align: top;
}

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

.chem-table tr:hover td {
    background: #fafafa;
}

/* 2-Col Compare Grid */
.chem-compare {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
    gap: 16px !important;
    margin: 16px 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.compare-box {
    padding: 20px !important;
    border: 1px solid var(--chem-border) !important;
    border-radius: var(--chem-radius-md) !important;
    background: var(--chem-card) !important;
    box-shadow: var(--chem-shadow-sm) !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

.compare-box h4 {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 10px;
    color: var(--chem-p);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Vector Diagrams & Educational Flowcharts ===== */
.chem-diagram, .diagram {
    margin: 20px 0;
    padding: 18px 16px 14px;
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    background: #ffffff;
    box-shadow: var(--chem-shadow-sm);
    overflow-x: auto;
}

.diagram-title {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--chem-muted);
    margin-bottom: 10px;
    text-align: center;
}

.chem-diagram svg, .diagram svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

/* SVG Fill defaults ensuring no black boxes */
.chem-diagram svg rect:not([fill]), .diagram svg rect:not([fill]) {
    fill: #ffffff;
    stroke: var(--chem-border);
    stroke-width: 1.5px;
}

.chem-diagram svg circle:not([fill]):not([class]), .diagram svg circle:not([fill]):not([class]) {
    fill: #ffffff;
    stroke: var(--chem-border);
    stroke-width: 1.5px;
}

.svg-label { font-family: var(--font-heading); font-size: 13px; font-weight: 700; fill: var(--chem-dark); }
.svg-small { font-family: var(--font-body); font-size: 10px; font-weight: 600; fill: var(--chem-muted); }
.svg-arrow { stroke: #64748b; stroke-width: 2; fill: none; }
/* ===== Interactive Three.js 3D Chemistry Viewers ===== */
.three-chem-container {
    position: relative;
    width: 100%;
    margin: 18px 0;
    padding: 16px 14px;
    background: #ffffff;
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    box-shadow: var(--chem-shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

body.dark-mode .three-chem-container,
html.dark-mode .three-chem-container {
    background: #111827 !important;
    border-color: #24324a !important;
}

.three-chem-container canvas {
    border-radius: var(--chem-radius-md);
    max-width: 100%;
    display: block;
    outline: none;
}

.chem-3d-btn {
    padding: 6px 12px;
    border-radius: 9999px;
    border: 1.5px solid var(--chem-border);
    background: var(--chem-card, #ffffff);
    color: var(--chem-dark, #1e293b);
    font-family: var(--font-heading);
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chem-3d-btn:hover {
    border-color: var(--chem-p, #4f46e5);
    background: rgba(79, 70, 229, 0.08);
    color: var(--chem-p, #4f46e5);
    transform: translateY(-1px);
}

.chem-3d-btn.active {
    background: var(--chem-p, #4f46e5) !important;
    color: #ffffff !important;
    border-color: var(--chem-p, #4f46e5) !important;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

body.dark-mode .chem-3d-btn {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

body.dark-mode .chem-3d-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: #818cf8;
    color: #818cf8;
}

/* ===== NCERT Solved Exercise System ===== */
.exercise-group {
    margin-bottom: 28px;
}

.exercise-group-title {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--chem-dark);
    margin: 24px 0 14px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--chem-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.q-card {
    background: var(--chem-card);
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--chem-shadow-sm);
    transition: border-color 0.2s;
}

.q-card:hover {
    border-color: rgba(79, 70, 229, 0.4);
}

.q-header {
    padding: 16px 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: #ffffff;
    border-bottom: 1px solid var(--chem-border-subtle);
}

.q-num {
    flex: 0 0 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--chem-p-light);
    color: var(--chem-p);
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 900;
}

.q-text {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: var(--chem-dark);
    line-height: 1.55;
    margin-bottom: 0;
}

.q-body {
    padding: 18px 22px;
    background: #fafafa;
}

.toggle-sol-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    background: #ffffff;
    border: 1.5px solid var(--chem-border);
    color: var(--chem-p);
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 750;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-sol-btn:hover {
    background: var(--chem-p-light);
    border-color: var(--chem-p);
}

.solution-box {
    display: none;
    margin-top: 14px;
    padding: 18px 20px;
    background: #ffffff;
    border: 1px solid var(--chem-border);
    border-left: 4px solid var(--chem-p);
    border-radius: var(--chem-radius-md);
    font-size: 0.95rem;
    line-height: 1.7;
    animation: chemFadeIn 0.25s ease;
}

.step-label {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--chem-p-light);
    color: var(--chem-p);
    margin-bottom: 6px;
}

.final-ans {
    margin-top: 10px;
    padding: 10px 14px;
    background: var(--chem-emerald-light);
    border: 1px solid #a7f3d0;
    border-radius: var(--chem-radius-sm);
    color: #064e3b;
    font-weight: 750;
}

/* ===== Interactive Self-Assessment Quiz Engine ===== */
.quiz-card {
    background: var(--chem-card);
    border: 1px solid var(--chem-border);
    border-radius: var(--chem-radius-lg);
    padding: 16px 20px;
    margin-bottom: 10px;
    box-shadow: var(--chem-shadow-sm);
}

.quiz-q {
    font-family: var(--font-heading);
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--chem-dark);
    margin-bottom: 10px;
    display: flex;
    gap: 10px;
}

.quiz-options {
    display: grid;
    gap: 8px;
}

.quiz-opt {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border: 1.5px solid var(--chem-border);
    border-radius: var(--chem-radius-md);
    background: #ffffff;
    cursor: pointer;
    font-size: 0.94rem;
    transition: all 0.15s;
    text-align: left;
    width: 100%;
}

.quiz-opt:hover {
    background: var(--chem-p-light);
    border-color: rgba(79, 70, 229, 0.4);
}

.opt-letter {
    flex: 0 0 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--chem-border-subtle);
    border: 1px solid var(--chem-border);
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 900;
    color: var(--chem-muted);
}

.quiz-opt.selected {
    border-color: var(--chem-p);
    background: var(--chem-p-light);
}

.quiz-opt.correct {
    border-color: var(--chem-emerald) !important;
    background: var(--chem-emerald-light) !important;
    color: #065f46 !important;
    font-weight: 700;
}

.quiz-opt.correct .opt-letter {
    background: var(--chem-emerald) !important;
    color: #ffffff !important;
    border-color: var(--chem-emerald) !important;
}

.quiz-opt.wrong {
    border-color: var(--chem-rose) !important;
    background: var(--chem-rose-light) !important;
    color: #9f1239 !important;
}

.quiz-opt.wrong .opt-letter {
    background: var(--chem-rose) !important;
    color: #ffffff !important;
    border-color: var(--chem-rose) !important;
}

.quiz-card[data-answered="true"] .quiz-opt {
    cursor: default;
}

/* Inline Per-Option Feedback Styling */
.quiz-opt-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.opt-explain {
    display: none;
    margin: 6px 0 8px 36px;
    padding: 10px 14px;
    border-radius: var(--chem-radius-sm);
    font-size: 0.88rem;
    line-height: 1.55;
    animation: chemFadeIn 0.25s ease-out;
}

@media (max-width: 600px) {
    .opt-explain {
        margin-left: 6px;
        padding: 8px 12px;
        font-size: 0.84rem;
    }
}

.opt-explain.show {
    display: block;
}

.opt-explain.is-correct {
    background: #ecfdf5 !important;
    border-left: 3.5px solid var(--chem-emerald) !important;
    color: #065f46 !important;
}

.opt-explain.is-wrong {
    background: #fff1f2 !important;
    border-left: 3.5px solid var(--chem-rose) !important;
    color: #9f1239 !important;
}

.quiz-submit-btn {
    width: 100%;
    padding: 14px;
    margin-top: 20px;
    border: none;
    border-radius: var(--chem-radius-md);
    background: linear-gradient(135deg, var(--chem-p), #0891b2);
    color: #ffffff;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
    transition: transform 0.15s, opacity 0.15s;
}

.quiz-submit-btn:hover {
    transform: translateY(-1px);
    opacity: 0.95;
}

.quiz-result {
    display: none;
    padding: 24px;
    margin-top: 20px;
    border-radius: var(--chem-radius-lg);
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    color: #ffffff;
    text-align: center;
}

.quiz-score-num {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    font-weight: 900;
    color: #38bdf8;
    margin: 8px 0;
}

.quiz-exp {
    display: none;
    margin-top: 12px;
    padding: 12px 14px;
    background: #f0fdf4;
    border-left: 3px solid var(--chem-emerald);
    border-radius: var(--chem-radius-sm);
    font-size: 0.88rem;
    color: #14532d;
    line-height: 1.6;
}

/* 3-Level Test Switcher */
.test-level-tabs {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.test-level-tab {
    flex: 1 1 auto;
    min-width: 140px;
    padding: 12px 16px;
    border-radius: var(--chem-radius-md);
    border: 1.5px solid var(--chem-border);
    background: #ffffff;
    color: var(--chem-muted);
    font-family: var(--font-heading);
    font-size: 0.92rem;
    font-weight: 750;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.test-level-tab:hover {
    background: var(--chem-p-light);
    border-color: var(--chem-p);
    color: var(--chem-p);
}

.test-level-tab.active {
    background: var(--chem-p);
    border-color: var(--chem-p);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
}

.test-level-pane {
    display: none;
}

.test-level-pane.active {
    display: block;
    animation: chemFadeIn 0.25s ease-out;
}

/* ===== Bottom Nav Buttons ===== */
.section-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--chem-border);
}

.nav-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border-radius: 999px;
    background: #ffffff;
    border: 1.5px solid var(--chem-border);
    color: var(--chem-p);
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 750;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.nav-pill:hover {
    background: var(--chem-p);
    color: #ffffff;
    border-color: var(--chem-p);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

/* ===== Global MathJax & Equation Overflow Containment ===== */
mjx-container {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    vertical-align: middle !important;
    scrollbar-width: thin !important;
    scrollbar-color: rgba(79, 70, 229, 0.3) transparent !important;
}

mjx-container::-webkit-scrollbar {
    height: 3px !important;
}

mjx-container::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.3) !important;
    border-radius: 3px !important;
}

mjx-container[display="true"] {
    display: block !important;
    margin: 0.75em auto !important;
    text-align: center !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 4px 2px !important;
}

.solution-box {
    display: none;
    margin-top: 14px !important;
    padding: 18px 16px !important;
    background: #f8fafc !important;
    border: 1px solid var(--chem-border) !important;
    border-left: 4px solid var(--chem-p) !important;
    border-radius: var(--chem-radius-sm) !important;
    font-size: 0.95rem !important;
    line-height: 1.75 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

/* ===== Responsive Breakpoints ===== */
@media (max-width: 768px) {
    html, body {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    .chem-container, .sj-container {
        padding: 12px 10px 80px !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Breadcrumb Top Bar Mobile Fix */
    div.chem-tbar, nav.chem-tbar, .sj-tbar {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        display: flex !important;
        width: 100% !important;
        padding: 10px 14px !important;
        margin-bottom: 16px !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        box-sizing: border-box !important;
    }

    .chem-bcrumb {
        font-size: 0.78rem !important;
        line-height: 1.4 !important;
        max-width: 100% !important;
    }

    .chem-nav {
        display: none !important; /* Hide ALL UNITS button on mobile to prevent breadcrumb collision */
    }

    .chem-hero, .science-hero {
        padding: 24px 18px !important;
        border-radius: var(--chem-radius-lg) !important;
        margin-bottom: 20px !important;
        min-height: auto !important;
        position: relative !important;
        clear: both !important;
    }

    .chem-hero h1 {
        font-size: 1.55rem !important;
        line-height: 1.25 !important;
    }

    .chem-hero p {
        font-size: 0.88rem !important;
        line-height: 1.55 !important;
    }

    /* Fixed App-Style Bottom Navigation Bar (All 5 tabs fit seamlessly on mobile) */
    .chem-tabs, .science-tabs, .tabs {
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        border: none !important;
        border-top: 1px solid rgba(226, 232, 240, 0.95) !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.12) !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
        gap: 2px !important;
        overflow-x: hidden !important;
    }

    .chem-tab, .science-tab, .tab {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        padding: 5px 2px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        border-radius: 10px !important;
        background: transparent !important;
        border: none !important;
        color: #64748b !important;
        min-height: 48px !important;
        box-shadow: none !important;
    }

    .chem-tab i, .science-tab i, .tab i {
        font-size: 1.15rem !important;
        margin: 0 !important;
        color: inherit !important;
    }

    .chem-tab .short {
        display: block !important;
        font-size: 0.68rem !important;
        font-weight: 700 !important;
        letter-spacing: -0.2px !important;
        line-height: 1 !important;
    }

    .chem-tab .full {
        display: none !important;
    }

    .chem-tab.active, .science-tab.active, .tab.active {
        background: var(--chem-p-light) !important;
        color: var(--chem-p) !important;
        box-shadow: none !important;
    }

    .chem-container, .sj-container {
        padding: 12px 10px 90px !important;
    }

    .chem-card, .science-card, .concept-card {
        padding: 18px 14px !important;
        border-radius: var(--chem-radius-md) !important;
        margin-bottom: 18px !important;
    }

    .chem-card h2, .concept-card h2 {
        font-size: 1.22rem !important;
    }

    .chem-grid, .science-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .chem-compare {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .compare-box {
        padding: 16px 14px !important;
    }

    .chem-eq, .formula {
        padding: 12px 14px !important;
        font-size: 0.95rem !important;
        margin: 12px 0 !important;
    }

    .trick-box {
        padding: 14px 14px !important;
        margin: 14px 0 !important;
    }

    .q-card {
        margin-bottom: 14px !important;
    }

    .q-header {
        padding: 12px 14px !important;
        gap: 10px !important;
    }

    .q-num {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.8rem !important;
        flex-shrink: 0 !important;
    }

    .q-text {
        font-size: 0.92rem !important;
        line-height: 1.55 !important;
    }

    .q-body {
        padding: 12px 14px 14px !important;
    }

    .chem-table-wrap {
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .chem-table th, .chem-table td {
        padding: 10px 10px !important;
        font-size: 0.84rem !important;
    }

    .quiz-card {
        padding: 16px 14px !important;
    }

    .quiz-opt {
        padding: 10px 12px !important;
        font-size: 0.88rem !important;
    }

    .section-nav {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .nav-pill {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
    }
}

/* ===== Tighten Space Before Global Footer to Absolute Minimum ===== */
main.chem-container, .chem-container {
    margin-bottom: 0 !important;
    padding-bottom: 8px !important;
}

#footer-container, #footer-container footer, footer, .sf {
    margin-top: 0 !important;
    padding-top: 1.2rem !important;
}

/* ==========================================================================
   CLASS 11 CHEMISTRY DARK MODE DESIGN SYSTEM
   Seamless, high-contrast, beautiful dark mode for all chemistry pages
   ========================================================================== */

body.dark-mode, html.dark-mode {
    --chem-bg: #0b0f19 !important;
    --chem-card: #151d2e !important;
    --chem-dark: #f8fafc !important;
    --chem-ink: #e2e8f0 !important;
    --chem-muted: #94a3b8 !important;
    --chem-border: #22314a !important;
    --chem-border-subtle: #1e293b !important;
    --chem-formula-bg: #070b13 !important;
    --chem-p-light: rgba(99, 102, 241, 0.15) !important;
    --chem-cyan-light: rgba(8, 145, 178, 0.15) !important;
    --chem-emerald-light: rgba(5, 150, 105, 0.15) !important;
    --chem-amber-light: rgba(217, 119, 6, 0.15) !important;
    --chem-rose-light: rgba(225, 29, 72, 0.15) !important;
    --chem-violet-light: rgba(124, 58, 237, 0.15) !important;
    background-color: #0b0f19 !important;
    color: #e2e8f0 !important;
}

/* Typography contrast in dark mode */
body.dark-mode p,
body.dark-mode li {
    color: #cbd5e1 !important;
}

body.dark-mode strong,
body.dark-mode b,
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
    color: #f8fafc !important;
}

/* Top breadcrumbs */
body.dark-mode .chem-bcrumb {
    color: #94a3b8 !important;
}
body.dark-mode .chem-bcrumb a {
    color: #818cf8 !important;
}
body.dark-mode .chem-bcrumb span {
    color: #f8fafc !important;
}

/* Tab Bar in Dark Mode */
body.dark-mode .chem-tabs,
body.dark-mode .science-tabs,
body.dark-mode .tabs {
    background: rgba(21, 29, 46, 0.95) !important;
    border-color: #22314a !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
}

body.dark-mode .chem-tab,
body.dark-mode .science-tab,
body.dark-mode .tab {
    color: #94a3b8 !important;
}

body.dark-mode .chem-tab:hover,
body.dark-mode .science-tab:hover,
body.dark-mode .tab:hover {
    background: rgba(99, 102, 241, 0.15) !important;
    color: #f8fafc !important;
}

body.dark-mode .chem-tab.active,
body.dark-mode .science-tab.active,
body.dark-mode .tab.active {
    background: linear-gradient(135deg, #4f46e5, #7c3aed) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4) !important;
}

/* Content cards */
body.dark-mode .chem-card,
body.dark-mode .science-card,
body.dark-mode .concept-card,
body.dark-mode .topic-card,
body.dark-mode .learning-objectives-card,
body.dark-mode .info-box,
body.dark-mode .compare-box,
body.dark-mode .q-card,
body.dark-mode .chem-diagram,
body.dark-mode .diagram {
    background: #151d2e !important;
    border-color: #22314a !important;
    color: #e2e8f0 !important;
}

/* Learning Objectives Card Specifics */
body.dark-mode .learning-objectives-card {
    background: #151d2e !important;
    border: 1px solid #22314a !important;
    border-left: 5px solid #4f46e5 !important;
}

body.dark-mode .learning-objectives-card h3 {
    color: #818cf8 !important;
}

body.dark-mode .learning-objectives-card ul li,
body.dark-mode .objectives-list li {
    color: #cbd5e1 !important;
}

/* Information boxes & Callouts */
body.dark-mode .info-box {
    background: #111827 !important;
    border-color: #24324a !important;
}

body.dark-mode .info-box h4 {
    color: #38bdf8 !important;
}

body.dark-mode .trick-box,
body.dark-mode .mnemonic-card {
    background: linear-gradient(135deg, rgba(192, 38, 211, 0.12) 0%, rgba(147, 51, 234, 0.12) 100%) !important;
    border-color: rgba(216, 70, 239, 0.3) !important;
    border-left-color: #d946ef !important;
    color: #f5d0fe !important;
}

body.dark-mode .trick-box .trick-title,
body.dark-mode .mnemonic-card .mnemonic-title {
    color: #f0abfc !important;
}

body.dark-mode .trick-box p,
body.dark-mode .mnemonic-card p,
body.dark-mode .trick-box li,
body.dark-mode .mnemonic-card li {
    color: #fae8ff !important;
}

body.dark-mode .key-takeaway,
body.dark-mode .quick-check {
    background: rgba(5, 150, 105, 0.12) !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
    border-left-color: #10b981 !important;
    color: #a7f3d0 !important;
}

body.dark-mode .key-takeaway strong,
body.dark-mode .quick-check strong {
    color: #34d399 !important;
}

body.dark-mode .exam-warning {
    background: rgba(225, 29, 72, 0.12) !important;
    border-color: rgba(244, 63, 94, 0.3) !important;
    border-left-color: #f43f5e !important;
    color: #fecdd3 !important;
}

body.dark-mode .exam-tip {
    background: rgba(217, 119, 6, 0.12) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
    border-left-color: #f59e0b !important;
    color: #fde68a !important;
}

/* Tables */
body.dark-mode .chem-table-wrap {
    background: #151d2e !important;
    border-color: #22314a !important;
}

body.dark-mode .chem-table th {
    background: #1e293b !important;
    color: #a5b4fc !important;
    border-bottom-color: #334155 !important;
}

body.dark-mode .chem-table td {
    color: #cbd5e1 !important;
    border-bottom-color: #1e293b !important;
}

body.dark-mode .chem-table tr:hover td {
    background: rgba(255, 255, 255, 0.03) !important;
}

/* Questions and Solved Examples */
body.dark-mode .q-header {
    background: #151d2e !important;
    border-bottom-color: #22314a !important;
}

body.dark-mode .q-text,
body.dark-mode .q-text strong {
    color: #f8fafc !important;
}

body.dark-mode .solution-box {
    background: #0f172a !important;
    border-color: #22314a !important;
    color: #cbd5e1 !important;
}

body.dark-mode .solution-title {
    color: #34d399 !important;
}

body.dark-mode .sol-btn {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #818cf8 !important;
}

body.dark-mode .sol-btn:hover {
    background: #312e81 !important;
    color: #ffffff !important;
}

/* Chem Tabs Dark Mode */
body.dark-mode .chem-tabs,
html.dark-mode .chem-tabs {
    background: rgba(15, 23, 42, 0.92) !important;
    border-color: #334155 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4) !important;
}

body.dark-mode .chem-tab,
html.dark-mode .chem-tab {
    color: #94a3b8 !important;
}

body.dark-mode .chem-tab:hover,
html.dark-mode .chem-tab:hover {
    color: #818cf8 !important;
    background: rgba(79, 70, 229, 0.18) !important;
}

body.dark-mode .chem-tab.active,
html.dark-mode .chem-tab.active {
    background: #6366f1 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4) !important;
}

/* Code & inline vars */
body.dark-mode code,
body.dark-mode var,
body.dark-mode kbd,
body.dark-mode samp {
    background: #1e293b !important;
    color: #a5b4fc !important;
    border-color: #334155 !important;
}

/* Chemical formulas */
body.dark-mode .chem-eq,
body.dark-mode .formula {
    background: #070b13 !important;
    border: 1px solid #1e293b !important;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4) !important;
}

/* Formula legend */
body.dark-mode .formula-legend {
    background: #111827 !important;
    border: 1px solid #1e293b !important;
}

body.dark-mode .legend-item {
    color: #cbd5e1 !important;
}

/* MathJax Formulas High Contrast in Dark Mode */
body.dark-mode .MathJax,
body.dark-mode mjx-container,
body.dark-mode mjx-math,
body.dark-mode .katex,
body.dark-mode .katex-display {
    color: #f8fafc !important;
}

body.dark-mode mjx-c,
body.dark-mode mjx-mo,
body.dark-mode mjx-mi,
body.dark-mode mjx-mn,
body.dark-mode mjx-stretchy-h,
body.dark-mode mjx-stretchy-v {
    color: inherit !important;
    fill: currentColor !important;
}

/* SVG Vector Diagrams Seamless Adaptation */
.svg-diagram-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 24px 0;
    padding: 18px;
    background: var(--chem-card, #ffffff);
    border-radius: var(--chem-radius-md, 14px);
    border: 1px solid var(--chem-border, #e2e8f0);
    box-shadow: var(--chem-shadow-sm);
    overflow-x: auto;
}

body.dark-mode .svg-diagram-wrapper,
html.dark-mode .svg-diagram-wrapper {
    background: #151d2e !important;
    border-color: #22314a !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4) !important;
}

body.dark-mode .svg-diagram-wrapper svg rect[fill="#f8fafc"],
html.dark-mode .svg-diagram-wrapper svg rect[fill="#f8fafc"] {
    fill: #0b0f19 !important;
    stroke: #22314a !important;
}

body.dark-mode .svg-diagram-wrapper svg rect[fill="#ffffff"],
html.dark-mode .svg-diagram-wrapper svg rect[fill="#ffffff"] {
    fill: #151d2e !important;
    stroke: #22314a !important;
}

body.dark-mode .svg-diagram-wrapper svg text[fill="#0f172a"],
body.dark-mode .svg-diagram-wrapper svg text[fill="#1e293b"],
html.dark-mode .svg-diagram-wrapper svg text[fill="#0f172a"],
html.dark-mode .svg-diagram-wrapper svg text[fill="#1e293b"] {
    fill: #f8fafc !important;
}

body.dark-mode .svg-diagram-wrapper svg text[fill="#475569"],
body.dark-mode .svg-diagram-wrapper svg text[fill="#334155"],
html.dark-mode .svg-diagram-wrapper svg text[fill="#475569"],
html.dark-mode .svg-diagram-wrapper svg text[fill="#334155"] {
    fill: #94a3b8 !important;
}

body.dark-mode .svg-diagram-wrapper svg polygon[fill="#f1f5f9"],
html.dark-mode .svg-diagram-wrapper svg polygon[fill="#f1f5f9"] {
    fill: #1e293b !important;
    stroke: #334155 !important;
}

/* ==========================================================================
   MathJax 3 Chemical Reaction & Formula Rendering Engine Fix
   Prevents extensible arrows (\xrightarrow) from overlapping or distorting
   ========================================================================== */

mjx-container {
    max-width: 100% !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

mjx-container,
mjx-container * {
    box-sizing: content-box !important;
}

mjx-container svg {
    display: inline-block !important;
    vertical-align: middle !important;
}

body.dark-mode mjx-container,
html.dark-mode mjx-container,
body.dark-mode .MathJax,
html.dark-mode .MathJax {
    color: #f8fafc !important;
}

body.dark-mode mjx-container svg,
html.dark-mode mjx-container svg {
    fill: currentColor !important;
}

mjx-container::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

mjx-container[display="true"],
mjx-container[jax="SVG"][display="true"],
mjx-container[jax="CHTML"][display="true"] {
    display: block !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 8px 0 !important;
    margin: 12px 0 !important;
    text-align: center !important;
}

mjx-container:not([display="true"]) {
    display: inline-grid !important;
    vertical-align: middle !important;
}

/* Ensure horizontal and vertical stretchy arrows and extenders are properly clipped */
mjx-stretchy-h,
mjx-stretchy-h > *,
mjx-stretchy-v,
mjx-stretchy-v > *,
mjx-ext,
mjx-ext *,
mjx-arrow,
mjx-line,
mjx-box,
mjx-box * {
    overflow: hidden !important;
}

mjx-under {
    padding-bottom: 0.15em !important;
}

mjx-over {
    padding-top: 0.15em !important;
}

/* Clean list items and cards from any unwanted pseudo-element underlines */
.chem-card ul li::after,
.chem-card ul li::before,
.concept-card ul li::after,
.concept-card ul li::before,
.rxn-card ul li::after,
.rxn-card ul li::before,
.tab-pane ul li::after,
.tab-pane ul li::before,
.info-box ul li::after,
.info-box ul li::before,
.solved-example-box ul li::after,
.solved-example-box ul li::before,
.exercise-item-card ul li::after,
.exercise-item-card ul li::before {
    display: none !important;
    content: none !important;
    border: none !important;
}

.rxn-card ul, .rxn-card ol {
    list-style: disc;
    padding-left: 22px;
    margin-bottom: 0;
}

.rxn-card li {
    margin-bottom: 12px;
    line-height: 1.8;
}

.rxn-card li:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Mobile Optimization: Maximum Width & Flattened Inner Content Cards
   Eliminates heavy box-in-a-box padding and margins on mobile devices
   ========================================================================== */

@media (max-width: 768px) {
    .chem-container, .sj-container {
        padding: 8px 6px 70px !important;
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .chem-tbar, .sj-tbar {
        padding: 8px 10px !important;
        border-radius: 10px !important;
        margin-bottom: 10px !important;
    }

    .chem-hero, .science-hero {
        padding: 18px 14px !important;
        border-radius: 14px !important;
        margin-bottom: 12px !important;
        min-height: auto !important;
    }

    .chem-hero h1 {
        font-size: 1.5rem !important;
        margin-bottom: 8px !important;
    }

    .chem-hero p {
        font-size: 0.88rem !important;
    }

    .chem-tabs, .science-tabs, .tabs {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        padding: 5px 4px !important;
        gap: 4px !important;
        border-radius: 14px !important;
        margin-bottom: 12px !important;
        position: sticky !important;
        top: 8px !important;
        z-index: 99 !important;
        width: 100% !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(16px) !important;
        -webkit-backdrop-filter: blur(16px) !important;
        box-shadow: var(--chem-shadow-md) !important;
    }

    .chem-tab, .science-tab, .tab {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        padding: 6px 2px !important;
        font-size: 0.72rem !important;
        font-weight: 700 !important;
        border-radius: 10px !important;
        min-height: 46px !important;
    }

    .chem-tab i, .science-tab i, .tab i {
        font-size: 0.95rem !important;
        margin: 0 !important;
    }

    .chem-tab .short,
    .science-tab .short,
    .tab .short {
        display: inline !important;
        font-size: 0.7rem !important;
        line-height: 1.1 !important;
    }

    .chem-tab .full,
    .science-tab .full,
    .tab .full {
        display: none !important;
    }

    /* Full-width primary cards without redundant outer margin */
    .concept-card,
    .chem-card,
    .science-card,
    .topic-card {
        padding: 14px 10px !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Flatten inside boxes on mobile so they take 100% width with no side cramps */
    .info-box,
    .rxn-card,
    .mechanism-box,
    .compare-box,
    .trick-box,
    .mnemonic-card,
    .note-box,
    .key-takeaway,
    .exam-tip,
    .exam-warning,
    .chem-diagram,
    .diagram,
    .svg-diagram-wrapper,
    .learning-objectives-card,
    .exercise-item-card,
    .solved-example-box {
        padding: 12px 10px !important;
        margin: 10px 0 !important;
        border-radius: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .chem-compare {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        margin: 10px 0 !important;
        width: 100% !important;
    }

    .chem-compare .compare-box {
        margin: 0 !important;
        width: 100% !important;
    }

    /* Q-Cards (NCERT In-Text Problems & Exercises) */
    .q-card {
        margin-bottom: 12px !important;
        border-radius: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .q-header {
        padding: 12px 10px !important;
        gap: 10px !important;
    }

    .q-num {
        flex: 0 0 32px !important;
        height: 32px !important;
        font-size: 0.8rem !important;
        border-radius: 8px !important;
    }

    .q-text {
        font-size: 0.92rem !important;
    }

    .q-body {
        padding: 12px 10px !important;
    }

    .toggle-sol-btn {
        width: 100% !important;
        justify-content: center !important;
        padding: 9px 14px !important;
        font-size: 0.85rem !important;
    }

    .solution-box {
        padding: 12px 10px !important;
        margin-top: 10px !important;
        border-radius: 8px !important;
        font-size: 0.9rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* MathJax display scaling on mobile */
    mjx-container[display="true"],
    mjx-container[jax="SVG"][display="true"],
    mjx-container[jax="CHTML"][display="true"] {
        padding: 6px 0 !important;
        margin: 8px 0 !important;
        font-size: 92% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
    }

    .rxn-card ul, .rxn-card ol {
        padding-left: 16px !important;
    }

    .rxn-card li {
        margin-bottom: 10px !important;
        line-height: 1.65 !important;
        font-size: 0.92rem !important;
    }
}

/* ==========================================================================
   Chapter Cross-Linking Navigation (Next / Previous Chapter SEO)
   ========================================================================== */
.chapter-cross-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin: 36px 0 20px 0;
    padding: 20px;
    background: #ffffff;
    border: 1px solid var(--chem-border, #e2e8f0);
    border-radius: var(--chem-radius-lg, 18px);
    box-shadow: var(--chem-shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
}

.cross-nav-card {
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    border-radius: 12px;
    text-decoration: none;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.cross-nav-card:hover {
    background: #ffffff;
    border-color: var(--chem-p, #4f46e5);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.12);
    transform: translateY(-2px);
}

.cross-nav-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--chem-muted, #64748b);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.cross-nav-title {
    font-family: var(--font-heading, 'Outfit', sans-serif);
    font-size: 1.05rem;
    font-weight: 750;
    color: var(--chem-dark, #0f172a);
    line-height: 1.35;
}

.cross-nav-card.next {
    text-align: right;
    align-items: flex-end;
}

.cross-nav-card.prev {
    text-align: left;
    align-items: flex-start;
}

.cross-nav-card.hub {
    text-align: center;
    align-items: center;
    justify-content: center;
}

body.dark-mode .chapter-cross-nav,
html.dark-mode .chapter-cross-nav {
    background: #1e293b !important;
    border-color: #334155 !important;
}

body.dark-mode .cross-nav-card,
html.dark-mode .cross-nav-card {
    background: #0f172a !important;
    border-color: #334155 !important;
}

body.dark-mode .cross-nav-card:hover,
html.dark-mode .cross-nav-card:hover {
    border-color: #818cf8 !important;
}

body.dark-mode .cross-nav-title,
html.dark-mode .cross-nav-title {
    color: #f1f5f9 !important;
}

body.dark-mode .cross-nav-label,
html.dark-mode .cross-nav-label {
    color: #94a3b8 !important;
}
