/*
 * CalcMentor Premium Styles v3.1
 * ────────────────────────────────
 * v3.1 fixes:
 *   FIX 8  — Long equations now scroll horizontally instead of overflowing
 *   FIX 8b — step-display-math and step-body both overflow-x:auto on mobile
 *   NEW    — #voice-hint styles for the voice-confirm toast
 *   NEW    — #graph-container canvas fully responsive
 *   NEW    — solve-btn loading state text handled gracefully
 */

/* ═══ RESET & BASE ═══════════════════════════════════════════════════ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary:    #0891b2;
    --secondary:  #14b8a6;
    --accent:     #06b6d4;
    --success:    #10b981;
    --warning:    #f59e0b;
    --danger:     #ef4444;
    --dark:       #0f172a;
    --light:      #f8fafc;
    --border:     #e2e8f0;
    --text:       #0f172a;
    --text-light: #64748b;
    --card-bg:    #ffffff;
    --radius:     14px;
    --shadow-sm:  0 2px 8px rgba(0,0,0,.06);
    --shadow:     0 4px 20px rgba(0,0,0,.10);
    --shadow-lg:  0 12px 40px rgba(0,0,0,.14);
}

html { overflow-x: hidden; scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.65;
    color: var(--text);
    background: #f0f9ff;
    min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
}

/* ═══ NAVIGATION ═══════════════════════════════════════════════════ */
nav {
    background: rgba(255,255,255,0.98);
    backdrop-filter: blur(12px);
    box-shadow: 0 2px 16px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 3px solid var(--secondary);
    width: 100%;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 72px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    flex-shrink: 0;
}

.logo-img { width: 46px; height: 46px; border-radius: 10px; }

.logo-text {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu { display: flex; gap: 28px; list-style: none; align-items: center; }
.nav-menu a { text-decoration: none; color: var(--text); font-weight: 600; font-size: 14.5px; transition: color .25s; }
.nav-menu a:hover, .nav-menu a.active { color: var(--primary); }

.mobile-toggle { display: none; flex-direction: column; gap: 5px; cursor: pointer; padding: 8px; background: none; border: none; }
.mobile-toggle span { width: 26px; height: 2.5px; background: var(--primary); border-radius: 3px; transition: all .3s; }

/* ═══ LAYOUT ════════════════════════════════════════════════════════ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ═══ BREADCRUMB ════════════════════════════════════════════════════ */
.breadcrumb {
    background: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}
.breadcrumb-list { display: flex; align-items: center; gap: 8px; list-style: none; font-size: 13.5px; white-space: nowrap; }
.breadcrumb-list a { color: var(--primary); text-decoration: none; font-weight: 600; }
.breadcrumb-list li:not(:last-child)::after { content: '›'; color: var(--text-light); margin-left: 8px; }

/* ═══ ARTICLE ═══════════════════════════════════════════════════════ */
.article-container {
    background: white;
    border-radius: 24px;
    padding: 52px 56px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 36px;
    border-top: 5px solid var(--primary);
    overflow: hidden;
}

.article-header {
    text-align: center;
    margin-bottom: 44px;
    padding-bottom: 28px;
    border-bottom: 2px solid var(--border);
}

h1 {
    font-size: 44px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 900;
    line-height: 1.2;
    word-break: break-word;
}

.article-meta { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin-top: 16px; color: var(--text-light); font-size: 13.5px; }
.article-intro { font-size: 19px; line-height: 1.8; color: var(--text-light); margin-top: 22px; text-align: left; }

h2 { font-size: 32px; color: var(--primary); margin: 44px 0 22px; font-weight: 800; border-left: 5px solid var(--secondary); padding-left: 18px; word-break: break-word; }
h3 { font-size: 24px; color: var(--text); margin: 28px 0 16px; font-weight: 700; }

p  { font-size: 16.5px; line-height: 1.8; margin-bottom: 18px; }
ul, ol { margin: 18px 0; padding-left: 28px; }
li { margin: 8px 0; line-height: 1.8; }
strong { color: var(--primary); font-weight: 700; }
code { font-family: 'Menlo', 'Monaco', 'Consolas', monospace; font-size: 13px; background: #f1f5f9; padding: 2px 6px; border-radius: 5px; color: var(--dark); }

/* ═══ INFO BOXES ════════════════════════════════════════════════════ */
.tip-box {
    background: linear-gradient(135deg, rgba(16,185,129,.07), rgba(52,211,153,.07));
    border-left: 5px solid var(--success);
    padding: 18px 22px;
    border-radius: 14px;
    margin: 22px 0;
}
.tip-title { font-size: 17px; font-weight: 800; color: var(--success); margin-bottom: 8px; }

.application-box {
    background: var(--light);
    border: 2px solid var(--border);
    border-radius: 18px;
    padding: 28px;
    margin: 26px 0;
    border-left: 6px solid var(--primary);
}
.application-title { font-size: 22px; font-weight: 800; color: var(--primary); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* ═══ CALCULATOR AREA ═══════════════════════════════════════════════ */
.calc-main-area { max-width: 980px; margin: 0 auto; }

/* Input */
.input-wrapper { position: relative; }

.math-input {
    width: 100%;
    padding: 20px 60px 20px 22px;
    font-size: 18px;
    border: 3px solid var(--border);
    border-radius: 16px;
    outline: none;
    transition: border-color .25s, box-shadow .25s;
    font-family: 'Georgia', 'Cambria Math', 'Times New Roman', serif;
    background: white;
    color: var(--text);
    line-height: 1.5;
    resize: vertical;
    min-height: 62px;
}
.math-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(8,145,178,.12); }
.math-input::placeholder { color: #94a3b8; font-family: -apple-system, sans-serif; font-size: 15px; }
.math-input.shake { animation: shake .45s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

#voice-btn {
    position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; font-size: 22px;
    color: var(--text-light); transition: all .25s; padding: 7px; border-radius: 50%;
}
#voice-btn:hover { color: var(--primary); background: rgba(8,145,178,.08); }
#voice-btn.listening { color: var(--danger); animation: pulse-mic 1s infinite; }
@keyframes pulse-mic { 0%,100% { transform: translateY(-50%) scale(1); } 50% { transform: translateY(-50%) scale(1.2); } }

/* FIX — Voice hint toast (shown after speech recognition result) */
#voice-hint {
    display: none;
    margin-top: 8px;
    padding: 8px 14px;
    background: rgba(8,145,178,.08);
    border: 1px solid rgba(8,145,178,.2);
    border-radius: 10px;
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
}

/* Solve Button */
.solve-btn {
    width: 100%; margin-top: 16px; padding: 18px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; border: none; border-radius: 16px;
    font-size: 18px; font-weight: 800; cursor: pointer;
    transition: all .25s; box-shadow: 0 8px 24px rgba(8,145,178,.28);
    letter-spacing: .3px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.solve-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(8,145,178,.38); }
.solve-btn:disabled { opacity: .65; cursor: not-allowed; transform: none; }
.solve-btn.loading { background: linear-gradient(135deg, #0e7490, #0d9488); }

/* Examples */
.examples-row { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 16px; }
.example-btn {
    padding: 7px 15px; background: white; border: 2px solid var(--border);
    border-radius: 24px; font-size: 12.5px; cursor: pointer; transition: all .2s;
    color: var(--text-light); font-weight: 600; white-space: nowrap;
}
.example-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(8,145,178,.04); transform: translateY(-1px); }

/* ═══ LOADER ═════════════════════════════════════════════════════════ */
#loader-container {
    text-align: center; padding: 40px 24px; margin-top: 28px;
    background: white; border-radius: 20px; border: 2px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.loader-spinner {
    border: 4px solid #e2e8f0; border-top: 4px solid var(--primary);
    border-radius: 50%; width: 44px; height: 44px;
    animation: spin .75s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
#loader-text { color: var(--primary); font-weight: 700; font-size: 17px; margin-bottom: 16px; }
.stage-item { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-light); padding: 5px 0; }
.stage-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex-shrink: 0; transition: background .3s; }
.stage-item.active .stage-dot { background: var(--primary); animation: pulse-dot 1s infinite; }
.stage-item.done  .stage-dot { background: var(--success); }
.stage-item.active { color: var(--primary); font-weight: 600; }
.stage-item.done   { color: var(--success); }
@keyframes pulse-dot { 0%,100% { transform: scale(1); } 50% { transform: scale(1.4); } }
#loader-stages { max-width: 320px; margin: 0 auto; text-align: left; }

/* ═══ RESULT SECTION ═════════════════════════════════════════════════ */
#result-section {
    background: linear-gradient(135deg, #f0f9ff, #f0fdfa);
    border: 2px solid var(--primary); border-radius: 22px;
    padding: 36px; margin-top: 36px; overflow: hidden;
}

#final-answer {
    background: white; padding: 24px 28px; border-radius: 16px;
    margin-bottom: 24px; border: 1px solid var(--border);
    overflow-x: auto; word-break: break-word;
}

/* Confidence badges */
.answer-badge {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 700; padding: 5px 14px;
    border-radius: 20px; margin-bottom: 16px;
}
.conf-high   { background: rgba(16,185,129,.12); color: #065f46; border: 1px solid rgba(16,185,129,.3); }
.conf-medium { background: rgba(245,158,11,.12); color: #92400e; border: 1px solid rgba(245,158,11,.3); }
.conf-low    { background: rgba(239,68,68,.12);  color: #7f1d1d; border: 1px solid rgba(239,68,68,.3);  }

/* Answer display — FIX 8: always scrollable for long equations */
.answer-display {
    font-size: 22px;
    margin: 12px 0 18px;
    overflow-x: auto;         /* FIX 8 — scroll long answers horizontally */
    max-width: 100%;
    padding: 8px 0;
}
.answer-display .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 0;
    max-width: 100%;
}
.answer-display .katex { font-size: 1.4em; }

/* Action buttons */
.answer-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.action-btn {
    padding: 9px 18px; border: 1.5px solid var(--border); border-radius: 10px;
    background: white; font-size: 13.5px; font-weight: 600; cursor: pointer;
    color: var(--text); transition: all .2s;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(8,145,178,.04); transform: translateY(-1px); }

/* Engine cross-check */
.engine-checks {
    margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    overflow-x: auto;           /* FIX 8 — engine tags scroll on mobile */
}
.engine-label { font-size: 12px; color: var(--text-light); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }
.engine-tag {
    font-size: 12px; background: var(--light); border: 1px solid var(--border);
    border-radius: 7px; padding: 3px 10px; color: var(--text-light);
    white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis;
}
.engine-tag strong { color: var(--primary); margin-right: 3px; }
.engine-tag code { background: none; padding: 0; font-size: 11.5px; }

/* Result metadata */
#result-meta {
    display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px;
    font-size: 12.5px; color: var(--text-light);
    padding-top: 12px; border-top: 1px solid var(--border);
}
#result-meta strong { color: var(--text); }

/* Error box */
.error-box {
    padding: 20px; border: 2px solid rgba(239,68,68,.25);
    border-radius: 14px; background: rgba(239,68,68,.04);
}
.error-box strong { color: var(--danger); display: block; font-size: 17px; margin-bottom: 8px; }
.error-box p { color: var(--text-light); margin-bottom: 4px; font-size: 15px; }
.error-hint { font-size: 13px !important; opacity: .75; }

/* ═══ GRAPH CONTAINER ════════════════════════════════════════════════ */
/* FIX 4 (confirm) — graph-container was already in HTML but main.js
   was not resetting display:none before checking. Now fixed in main.js.
   CSS here ensures the canvas is always responsive. */
#graph-container {
    background: white;
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    overflow: hidden;
}
#graph-container h3 {
    margin-top: 0;
    color: var(--primary);
    font-size: 17px;
    margin-bottom: 16px;
}
#math-chart {
    max-height: 320px;
    width: 100% !important;     /* override Chart.js inline width */
    max-width: 100%;
}

/* ═══ STEPS ══════════════════════════════════════════════════════════ */
.steps-wrapper { margin-top: 8px; }

.step-item {
    background: white;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: box-shadow .25s;
}
.step-item:hover { box-shadow: 0 4px 14px rgba(0,0,0,.07); }

.step-header {
    padding: 15px 20px; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    user-select: none; transition: background .2s;
}
.step-header:hover { background: rgba(8,145,178,.03); }

.step-number-title { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.step-num {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; font-size: 13px; font-weight: 800;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.step-title { font-weight: 700; color: var(--primary); font-size: 15px; word-break: break-word; }
.step-arrow { font-size: 11px; color: var(--text-light); flex-shrink: 0; margin-left: 10px; }

/* FIX 8 — step-body: long equations scroll horizontally, never overflow */
.step-body {
    padding: 18px 22px;
    border-top: 1px solid var(--border);
    line-height: 1.9;
    font-size: 15px;
    color: #374151;
    word-break: break-word;
    overflow-x: auto;           /* FIX 8 — horizontal scroll for long content */
    max-width: 100%;
}
.step-body .katex-display {
    margin: 14px 0;
    overflow-x: auto;           /* FIX 8 — KaTeX display equations scroll */
    overflow-y: hidden;
    background: #f8fafc;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    max-width: 100%;
}
.step-body .katex { font-size: 1.1em; }

/* ═══ HISTORY ════════════════════════════════════════════════════════ */
.history-card {
    background: white; border: 2px solid var(--border);
    border-radius: 20px; padding: 22px; margin-top: 28px;
}
.history-card h3 { margin-top: 0; font-size: 17px; border-bottom: 2px solid var(--border); padding-bottom: 10px; margin-bottom: 14px; }

.history-item {
    padding: 11px 13px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    font-size: 13.5px;
    color: var(--text-light);
    transition: all .2s;
    border-radius: 8px;
    margin-bottom: 3px;
}
.history-item:hover { color: var(--primary); background: #f0f9ff; transform: translateX(4px); }
.history-item:last-child { border-bottom: none; }
.history-query { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-time { font-size: 11px; opacity: .6; margin-top: 2px; }
.history-empty { text-align: center; color: var(--text-light); padding: 18px; font-size: 13.5px; }

#clear-history {
    width: 100%; margin-top: 12px;
    background: none; border: 1px solid var(--border);
    padding: 9px; border-radius: 10px; font-size: 13px;
    cursor: pointer; color: var(--text-light); transition: all .2s; font-weight: 600;
}
#clear-history:hover { border-color: var(--danger); color: var(--danger); }

/* ═══ EXAMPLE CARDS GRID ═════════════════════════════════════════════ */
.examples-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin: 28px 0; }
.example-card {
    background: white; border: 2px solid var(--border); border-radius: 18px;
    padding: 22px; cursor: pointer; transition: all .25s;
    border-top: 4px solid var(--primary);
}
.example-card:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.example-card:hover { border-color: var(--primary); box-shadow: 0 8px 24px rgba(8,145,178,.15); transform: translateY(-3px); }
.example-card-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.example-card-query { font-size: 13px; color: var(--text-light); font-family: 'Georgia', serif; margin-bottom: 10px; }
.example-card-answer { font-size: 13px; color: var(--primary); font-weight: 600; }

/* ═══ CTA SECTION ════════════════════════════════════════════════════ */
.cta-section {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; padding: 48px; border-radius: 22px;
    text-align: center; margin: 48px 0;
    box-shadow: 0 14px 36px rgba(8,145,178,.28);
}
.cta-section h2 { color: white; margin: 0 0 18px; border: none; padding: 0; -webkit-text-fill-color: white; font-size: 30px; }
.cta-section p { color: rgba(255,255,255,.9); margin-bottom: 28px; font-size: 17px; }
.cta-button {
    display: inline-block; background: white; color: var(--primary);
    padding: 16px 38px; border-radius: 14px; text-decoration: none;
    font-weight: 800; font-size: 17px; transition: all .3s;
    box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.cta-button:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.22); }

/* ═══ FOOTER ═════════════════════════════════════════════════════════ */
footer {
    background: linear-gradient(135deg, #0c4a6e, #0f766e);
    color: white; padding: 56px 24px 28px; margin-top: 56px;
}
.footer-container {
    max-width: 1400px; margin: 0 auto;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 36px; margin-bottom: 36px;
}
.footer-section h3 { margin-bottom: 18px; font-size: 18px; font-weight: 800; color: var(--secondary); }
.footer-section p { color: rgba(255,255,255,.7); line-height: 1.8; font-size: 14px; }
.footer-section ul { list-style: none; padding: 0; }
.footer-section ul li { margin-bottom: 10px; }
.footer-section a { color: rgba(255,255,255,.8); text-decoration: none; transition: all .25s; font-size: 14px; }
.footer-section a:hover { color: var(--secondary); padding-left: 4px; }
.footer-bottom { text-align: center; padding-top: 28px; border-top: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.65); font-size: 13.5px; }

/* ═══ KATEX GLOBAL FIXES ═════════════════════════════════════════════ */
/* FIX 8 — all KaTeX display blocks scroll horizontally, never clip */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}
.katex { font-size: 1.05em; }

/* ═══ ANSWER INTRO ═══════════════════════════════════════════════════ */
.answer-intro {
    font-size: 16px;
    line-height: 1.7;
    color: #1e3a5f;
    background: linear-gradient(135deg, rgba(8,145,178,.06), rgba(20,184,166,.04));
    border-left: 4px solid var(--primary);
    border-radius: 0 10px 10px 0;
    padding: 14px 18px;
    margin: 16px 0 20px;
    font-style: italic;
}

/* ═══ STEP BODY STRUCTURED ELEMENTS ══════════════════════════════════ */
.step-section-title {
    display: block; font-weight: 700; font-size: 14px; color: var(--primary);
    margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .5px;
}

.steps-empty {
    text-align: center; padding: 28px 20px;
    color: var(--text-light); font-style: italic; font-size: 15px;
}

.step-list { margin: 8px 0; padding-left: 22px; }
.step-list li { margin-bottom: 5px; line-height: 1.65; color: var(--text); }

.step-numbered-item { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; line-height: 1.65; }
.step-num-inline { flex-shrink: 0; font-weight: 700; color: var(--primary); min-width: 22px; }

.step-conclusion {
    margin: 12px 0 6px; padding: 10px 16px;
    background: rgba(16,185,129,.07); border-left: 3px solid var(--success);
    border-radius: 0 8px 8px 0; font-weight: 600; color: #065f46;
}

/* FIX 8 — display math inside steps scrolls horizontally */
.step-display-math {
    margin: 10px auto;
    text-align: center;
    overflow-x: auto;           /* FIX 8 */
    max-width: 100%;
    padding: 4px 0;
}

.step-spacer { height: 8px; }

/* ═══ PRINT STYLES ═══════════════════════════════════════════════════ */
/* FIX 6 — Print is now handled by _printSolution() which opens a new
   clean window. This @media print block applies to any accidental
   direct browser print (Ctrl+P) to hide chrome and show only content. */
@media print {
    nav, .solve-btn, .example-btn, .examples-row, .history-card,
    .cta-section, footer, .answer-actions, #loader-container,
    .breadcrumb, #graph-container, .tip-box { display: none !important; }
    body { background: white; }
    .article-container { box-shadow: none; padding: 20px; }
    .step-body { display: block !important; overflow-x: auto; }
    .katex-display { overflow-x: auto; }
}

/* ═══ RESPONSIVE ═════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .article-container { padding: 36px 28px; }
}

@media (max-width: 768px) {
    .nav-menu {
        position: fixed; left: -100%; top: 72px;
        flex-direction: column; background: white;
        width: 100%; padding: 20px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
        transition: left .3s; gap: 16px; z-index: 999;
    }
    .nav-menu.active { left: 0; }
    .mobile-toggle { display: flex; }

    h1 { font-size: 30px; }
    h2 { font-size: 26px; }
    h3 { font-size: 20px; }
    .container { padding: 16px; }
    .article-container { padding: 22px 16px; }
    .article-intro { font-size: 16px; }

    .math-input { font-size: 15px; padding: 16px 50px 16px 16px; }
    .solve-btn { font-size: 16px; padding: 16px; }
    #result-section { padding: 22px 16px; }
    #final-answer { padding: 16px; }
    .answer-display .katex { font-size: 1.2em; }

    .examples-row { gap: 7px; }
    .example-btn { font-size: 12px; padding: 6px 11px; }

    .cta-section { padding: 28px 18px; }
    .cta-section h2 { font-size: 24px; }

    .step-header { padding: 13px 15px; }
    .step-body { padding: 14px 16px; font-size: 14.5px; }

    .engine-checks { flex-direction: column; align-items: flex-start; }
    #result-meta { gap: 10px; }
}

@media (max-width: 480px) {
    h1 { font-size: 26px; }
    .logo-text { font-size: 16px; }
    .answer-display .katex { font-size: 1.1em; }
    .answer-actions { flex-direction: column; }
    .action-btn { width: 100%; text-align: center; }

    /* FIX 8 — on very small screens, step body font slightly smaller for long equations */
    .step-body { font-size: 14px; }
    .step-body .katex { font-size: 1em; }
}

/* ═══ MATH KEYBOARD ══════════════════════════════════════════════════ */
.math-keyboard {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.key-btn {
    flex: 1 1 calc(10% - 6px);
    min-width: 44px;
    height: 36px;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--primary);
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.key-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(8,145,178,0.25);
}
.key-btn:active {
    transform: translateY(0);
}

/* ═══ IMAGE SOLVER ZONE ══════════════════════════════════════════════ */
.image-solver-zone {
    margin-top: 14px;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    background: #faf8fc;
    transition: all 0.25s;
    padding: 16px;
    text-align: center;
}
.image-solver-zone.dragover {
    border-color: var(--primary);
    background: rgba(8,145,178,0.04);
}
.image-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 13.5px;
    font-weight: 600;
    transition: color 0.2s;
}
.image-upload-label:hover {
    color: var(--primary);
}
.upload-icon {
    font-size: 24px;
}
#image-preview-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin-top: 4px;
}
#image-preview {
    max-height: 120px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
#remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    transition: transform 0.15s;
}
#remove-image-btn:hover {
    transform: scale(1.15);
}

/* ═══ FOLLOW-UP QUESTIONS ════════════════════════════════════════════ */
.followup-container {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1.5px solid var(--border);
}
.followup-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-light);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.followup-pills {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.followup-btn {
    text-align: left;
    width: 100%;
    padding: 12px 16px;
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    color: var(--primary);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.followup-btn:hover {
    background: rgba(8,145,178,0.04);
    border-color: var(--primary);
    transform: translateX(4px);
}
.followup-btn::after {
    content: "→";
    font-size: 16px;
    opacity: 0.7;
    transition: transform 0.2s;
}
.followup-btn:hover::after {
    transform: translateX(2px);
}

@media (max-width: 600px) {
    .key-btn {
        flex: 1 1 calc(20% - 6px);
        font-size: 12.5px;
        height: 32px;
    }
}

/* ═══ MODAL OVERLAY (Welcome + Image Confirmation) ═══════════════════ */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15,23,42,.65); backdrop-filter: blur(4px);
    z-index: 10000; display: flex; align-items: center; justify-content: center;
    padding: 20px; animation: fadeIn .3s;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-box {
    background: white; border-radius: 24px; max-width: 540px; width: 100%;
    box-shadow: 0 24px 64px rgba(0,0,0,.3); overflow: hidden;
    animation: slideUp .35s ease-out; max-height: 90vh; overflow-y: auto;
}
@keyframes slideUp { from { transform:translateY(30px); opacity:0; } to { transform:translateY(0); opacity:1; } }

.modal-header {
    padding: 24px 28px 16px; text-align: center;
    border-bottom: 1px solid var(--border);
}
.modal-icon { font-size: 36px; display: block; margin-bottom: 8px; }
.modal-header h2 { margin:0; font-size:22px; border:none; padding:0; color:var(--dark); }

.modal-body { padding: 20px 28px; }
.modal-intro { font-size:15px; color:var(--text-light); margin-bottom:16px; text-align:center; }
.modal-footnote { font-size:13px; color:#94a3b8; text-align:center; margin:16px 0 0; }

.welcome-tips { display:flex; flex-direction:column; gap:12px; }
.tip-card {
    display:flex; align-items:flex-start; gap:14px;
    background:var(--light); border:1px solid var(--border);
    border-radius:14px; padding:14px 16px; transition:all .2s;
}
.tip-card:hover { border-color:var(--primary); }
.tip-num {
    width:28px; height:28px; border-radius:50%;
    background:linear-gradient(135deg,var(--primary),var(--secondary));
    color:white; font-size:14px; font-weight:800;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.tip-card strong { display:block; font-size:14px; margin-bottom:3px; }
.tip-card span { font-size:13px; color:var(--text-light); line-height:1.5; }

.modal-footer { padding:16px 28px 24px; }
.modal-btn {
    width:100%; padding:14px; border:none; border-radius:14px;
    background:linear-gradient(135deg,var(--primary),var(--secondary));
    color:white; font-size:16px; font-weight:800; cursor:pointer;
    transition:all .25s; box-shadow:0 4px 16px rgba(8,145,178,.28);
}
.modal-btn:hover { transform:translateY(-1px); box-shadow:0 6px 20px rgba(8,145,178,.38); }
.modal-btn-secondary {
    background:white; color:var(--text); box-shadow:none;
    border:1.5px solid var(--border); flex:0 1 auto;
}
.modal-btn-secondary:hover { border-color:var(--primary); color:var(--primary); transform:none; box-shadow:none; }

/* Extracted text area */
.extracted-textarea {
    width:100%; padding:14px; font-size:17px; font-family:'Georgia','Cambria Math',serif;
    border:2px solid var(--border); border-radius:12px; outline:none;
    resize:vertical; min-height:80px; color:var(--text); line-height:1.6;
}
.extracted-textarea:focus { border-color:var(--primary); box-shadow:0 0 0 3px rgba(8,145,178,.1); }

@media (max-width: 480px) {
    .modal-box { max-width:100%; border-radius:18px; }
    .modal-header { padding:20px 20px 12px; }
    .modal-body { padding:16px 20px; }
    .modal-footer { padding:12px 20px 20px; }
    .modal-header h2 { font-size:19px; }
}