/* =================================================================
   THYNEX ACADEMY — Math Tools
   Design tokens inherited from calendar module
   Mobile-first responsive approach
   ================================================================= */

/* ─── Design Tokens ─────────────────────────────────────── */
:root {
    --math-bg: #f5f7fa;
    --math-surface: #ffffff;
    --math-surface-alt: #f9fafb;
    --math-border: #e5e7eb;
    --math-border-light: #f0f1f3;
    --math-text: #1f2937;
    --math-text-soft: #4b5563;
    --math-text-muted: #9ca3af;
    --math-primary: #6366f1;
    --math-primary-hover: #4f46e5;
    --math-primary-soft: rgba(99, 102, 241, 0.10);
    --math-primary-glow: rgba(99, 102, 241, 0.18);
    --math-success: #10b981;
    --math-error: #ef4444;
    --math-warning: #f59e0b;
    --math-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --math-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --math-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --math-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.10), 0 4px 8px rgba(0, 0, 0, 0.06);
    --math-radius-sm: 8px;
    --math-radius-md: 12px;
    --math-radius-lg: 16px;
    --math-radius-xl: 20px;
    --math-radius-full: 999px;
    --math-header-height: 64px;
    --math-sidebar-width: 280px;
    --math-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --math-bit-on: #6366f1;
    --math-bit-off: #e5e7eb;
    --math-step-highlight: rgba(99, 102, 241, 0.08);
}

/* ─── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--math-bg);
    color: var(--math-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ─── Header ────────────────────────────────────────────── */
.math-header {
    height: var(--math-header-height);
    background: var(--math-surface);
    border-bottom: 1px solid var(--math-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--math-shadow-xs);
}

.math-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    text-decoration: none;
}

.math-logo-link {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.math-logo-img {
    width: 140px;
    height: auto;
}

.math-brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.math-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--math-text);
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.math-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--math-primary-soft);
    color: var(--math-primary);
    border: none;
    border-radius: var(--math-radius-full);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--math-transition);
    white-space: nowrap;
}

.math-header-btn:hover {
    background: var(--math-primary-glow);
}

.math-header-btn i {
    font-size: 14px;
}

/* ─── Mobile menu toggle ───────────────────────────────── */
.math-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--math-primary-soft);
    color: var(--math-primary);
    border: none;
    border-radius: var(--math-radius-sm);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--math-transition);
}

.math-menu-toggle:hover {
    background: var(--math-primary-glow);
}

/* ─── Main Layout ──────────────────────────────────────── */
.math-shell {
    display: flex;
    min-height: calc(100vh - var(--math-header-height));
    min-height: calc(100dvh - var(--math-header-height));
    max-width: 1440px;
    margin: 0 auto;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.math-sidebar {
    width: var(--math-sidebar-width);
    flex-shrink: 0;
    background: var(--math-surface);
    border-right: 1px solid var(--math-border);
    padding: 20px 0;
    overflow-y: auto;
    position: sticky;
    top: var(--math-header-height);
    height: calc(100vh - var(--math-header-height));
    height: calc(100dvh - var(--math-header-height));
}

.math-sidebar-category {
    padding: 0 16px;
    margin-bottom: 8px;
}

.math-sidebar-category-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--math-text-muted);
    padding: 8px 12px 6px;
}

.math-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--math-radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--math-text-soft);
    cursor: pointer;
    transition: all var(--math-transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.math-sidebar-item:hover {
    background: var(--math-surface-alt);
    color: var(--math-text);
}

.math-sidebar-item.active {
    background: var(--math-primary-soft);
    color: var(--math-primary);
    font-weight: 600;
}

.math-sidebar-item i {
    width: 20px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* ─── Sidebar History ──────────────────────────────────── */
.math-sidebar-history {
    border-top: 1px solid var(--math-border);
    margin-top: 16px;
    padding-top: 16px;
}

.math-sidebar-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px 8px;
}

.math-sidebar-history-header span {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--math-text-muted);
}

.math-history-clear {
    font-size: 11px;
    color: var(--math-error);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--math-transition);
}

.math-history-clear:hover {
    background: rgba(239, 68, 68, 0.08);
}

.math-history-list {
    list-style: none;
    padding: 0 16px;
    max-height: 240px;
    overflow-y: auto;
}

.math-history-entry {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    border-radius: var(--math-radius-sm);
    cursor: pointer;
    transition: all var(--math-transition);
    font-size: 12px;
}

.math-history-entry:hover {
    background: var(--math-surface-alt);
}

.math-history-entry-tool {
    font-weight: 600;
    color: var(--math-primary);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.math-history-entry-value {
    color: var(--math-text-soft);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.math-history-empty {
    padding: 12px 28px;
    font-size: 12px;
    color: var(--math-text-muted);
    font-style: italic;
}

/* ─── Workspace ────────────────────────────────────────── */
.math-workspace {
    flex: 1;
    min-width: 0;
    padding: 32px;
}

.math-tool-panel {
    display: none;
    max-width: 780px;
    margin: 0 auto;
}

.math-tool-panel.active {
    display: block;
}

.math-tool-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--math-text);
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.math-tool-desc {
    font-size: 14px;
    color: var(--math-text-soft);
    margin-bottom: 28px;
    line-height: 1.6;
}

/* ─── Input Area ───────────────────────────────────────── */
.math-input-group {
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--math-shadow-sm);
}

.math-input-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.math-field {
    flex: 1;
    min-width: 180px;
}

.math-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--math-text-soft);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.math-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--math-border);
    border-radius: var(--math-radius-sm);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 16px;
    color: var(--math-text);
    background: var(--math-surface);
    transition: all var(--math-transition);
    outline: none;
}

.math-input:focus {
    border-color: var(--math-primary);
    box-shadow: 0 0 0 3px var(--math-primary-soft);
}

.math-input.error {
    border-color: var(--math-error);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.math-input::placeholder {
    color: var(--math-text-muted);
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
}

.math-select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--math-border);
    border-radius: var(--math-radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--math-text);
    background: var(--math-surface);
    cursor: pointer;
    transition: all var(--math-transition);
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%239ca3af'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.math-select:focus {
    border-color: var(--math-primary);
    box-shadow: 0 0 0 3px var(--math-primary-soft);
}

/* ─── Action Buttons ───────────────────────────────────── */
.math-actions-row {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.math-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--math-radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--math-transition);
    white-space: nowrap;
}

.math-btn-primary {
    background: var(--math-primary);
    color: #fff;
    box-shadow: var(--math-shadow-sm);
}

.math-btn-primary:hover {
    background: var(--math-primary-hover);
    box-shadow: var(--math-shadow-md);
    transform: translateY(-1px);
}

.math-btn-primary:active {
    transform: translateY(0);
}

.math-btn-secondary {
    background: var(--math-surface);
    color: var(--math-text-soft);
    border: 1.5px solid var(--math-border);
}

.math-btn-secondary:hover {
    background: var(--math-surface-alt);
    color: var(--math-text);
    border-color: var(--math-text-muted);
}

.math-btn-ghost {
    background: none;
    color: var(--math-text-muted);
    padding: 8px 14px;
    font-size: 13px;
}

.math-btn-ghost:hover {
    color: var(--math-text);
    background: var(--math-surface-alt);
}

.math-btn i {
    font-size: 14px;
}

/* ─── Result Display ───────────────────────────────────── */
.math-result-box {
    display: none;
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-lg);
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: var(--math-shadow-sm);
    text-align: center;
    animation: math-fade-in 0.3s ease;
}

.math-result-box.visible {
    display: block;
}

.math-result-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--math-text-muted);
    margin-bottom: 8px;
}

.math-result-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--math-primary);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    letter-spacing: -0.02em;
    word-break: break-all;
    line-height: 1.2;
}

.math-result-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* ─── Steps (Step-by-Step Solution) ────────────────────── */
.math-steps-toggle {
    display: none;
    width: 100%;
    padding: 14px 24px;
    background: var(--math-step-highlight);
    border: 1.5px solid var(--math-primary-soft);
    border-radius: var(--math-radius-md);
    color: var(--math-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--math-transition);
    margin-bottom: 20px;
}

.math-steps-toggle.visible {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.math-steps-toggle:hover {
    background: var(--math-primary-soft);
    border-color: var(--math-primary);
}

.math-steps-toggle i {
    transition: transform var(--math-transition);
}

.math-steps-toggle.expanded i {
    transform: rotate(180deg);
}

.math-steps-container {
    display: none;
    margin-bottom: 24px;
}

.math-steps-container.visible {
    display: block;
}

.math-steps-timeline {
    position: relative;
    padding-left: 36px;
}

.math-steps-timeline::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: linear-gradient(to bottom, var(--math-primary), var(--math-primary-soft));
    border-radius: 1px;
}

.math-step {
    position: relative;
    margin-bottom: 16px;
    opacity: 0;
    transform: translateY(12px);
}

.math-step.animate-in {
    animation: math-step-in 0.4s ease forwards;
}

.math-step-badge {
    position: absolute;
    left: -36px;
    top: 4px;
    width: 28px;
    height: 28px;
    background: var(--math-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    z-index: 1;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.math-step-card {
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-md);
    padding: 16px 20px;
    box-shadow: var(--math-shadow-xs);
}

.math-step-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--math-text);
    margin-bottom: 6px;
}

.math-step-desc {
    font-size: 13px;
    color: var(--math-text-soft);
    line-height: 1.6;
}

.math-step-desc code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    background: var(--math-surface-alt);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--math-primary);
    border: 1px solid var(--math-border-light);
}

/* ─── Bit Visualization ────────────────────────────────── */
.math-bits {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin: 10px 0;
    justify-content: center;
}

.math-bit {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 16px;
    font-weight: 700;
    border-radius: 6px;
    border: 2px solid var(--math-bit-off);
    color: var(--math-text-muted);
    background: var(--math-surface);
    transition: all 0.3s ease;
}

.math-bit.on {
    border-color: var(--math-bit-on);
    color: var(--math-bit-on);
    background: var(--math-primary-soft);
}

.math-bit.highlight {
    border-color: var(--math-primary);
    color: #fff;
    background: var(--math-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
    transform: scale(1.08);
}

.math-bit.sign-bit {
    border-color: var(--math-error);
    color: var(--math-error);
}

.math-bit.sign-bit.highlight {
    background: var(--math-error);
    color: #fff;
    border-color: var(--math-error);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

.math-bit-labels {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 4px;
}

.math-bit-label {
    width: 40px;
    text-align: center;
    font-size: 10px;
    color: var(--math-text-muted);
    font-weight: 600;
}

/* ─── Math Expression ──────────────────────────────────── */
.math-expr {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    background: var(--math-surface-alt);
    padding: 12px 16px;
    border-radius: var(--math-radius-sm);
    border: 1px solid var(--math-border-light);
    margin: 8px 0;
    overflow-x: auto;
    white-space: nowrap;
    line-height: 1.8;
}

.math-expr sup {
    font-size: 10px;
    color: var(--math-primary);
    font-weight: 700;
}

.math-expr .highlight {
    color: var(--math-primary);
    font-weight: 700;
}

.math-expr .muted {
    color: var(--math-text-muted);
}

.math-expr .equals {
    color: var(--math-success);
    font-weight: 700;
}

/* ─── Truth Table ──────────────────────────────────────── */
.math-truth-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    margin: 12px 0;
}

.math-truth-table th {
    background: var(--math-primary);
    color: #fff;
    padding: 10px 16px;
    font-weight: 600;
    text-align: center;
    font-size: 12px;
    letter-spacing: 0.04em;
}

.math-truth-table th:first-child {
    border-radius: var(--math-radius-sm) 0 0 0;
}

.math-truth-table th:last-child {
    border-radius: 0 var(--math-radius-sm) 0 0;
}

.math-truth-table td {
    padding: 8px 16px;
    text-align: center;
    border-bottom: 1px solid var(--math-border-light);
}

.math-truth-table tr:nth-child(even) {
    background: var(--math-surface-alt);
}

.math-truth-table tr:hover {
    background: var(--math-step-highlight);
}

.math-truth-table td.result-col {
    font-weight: 700;
    color: var(--math-primary);
    background: var(--math-primary-soft);
}

/* ─── IEEE 754 Bit Fields ──────────────────────────────── */
.math-ieee-fields {
    display: flex;
    gap: 2px;
    margin: 12px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.math-ieee-sign { background: #ef4444; color: #fff; }
.math-ieee-exponent { background: #f59e0b; color: #fff; }
.math-ieee-mantissa { background: #6366f1; color: #fff; }

.math-ieee-fields .math-bit {
    width: 28px;
    height: 36px;
    font-size: 13px;
    border: none;
    border-radius: 4px;
}

.math-ieee-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: 8px 0 16px;
    flex-wrap: wrap;
}

.math-ieee-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--math-text-soft);
}

.math-ieee-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* ─── Color Picker ─────────────────────────────────────── */
.math-color-preview {
    width: 100%;
    height: 80px;
    border-radius: var(--math-radius-md);
    border: 2px solid var(--math-border);
    margin: 12px 0;
    transition: all var(--math-transition);
}

/* ─── ASCII Table ──────────────────────────────────────── */
.math-ascii-table-wrap {
    max-height: 500px;
    overflow-y: auto;
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-md);
    margin: 12px 0;
}

.math-ascii-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.math-ascii-table th {
    background: var(--math-surface-alt);
    color: var(--math-text-soft);
    padding: 8px 12px;
    font-weight: 600;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 2px solid var(--math-border);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.math-ascii-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--math-border-light);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.math-ascii-table tr:hover {
    background: var(--math-step-highlight);
}

.math-ascii-char {
    font-size: 16px;
    font-weight: 700;
    color: var(--math-primary);
}

/* ─── Error message ────────────────────────────────────── */
.math-error-msg {
    display: none;
    padding: 10px 16px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--math-radius-sm);
    color: var(--math-error);
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
}

.math-error-msg.visible {
    display: block;
}

/* ─── Toast notifications ──────────────────────────────── */
.math-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--math-text);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--math-radius-full);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--math-shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.math-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Animations ───────────────────────────────────────── */
@keyframes math-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes math-step-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes math-bit-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

/* ─── Responsive: Tablet ───────────────────────────────── */
@media (max-width: 1100px) {
    .math-sidebar {
        width: 240px;
    }

    .math-workspace {
        padding: 24px;
    }
}

/* ─── Responsive: Mobile ───────────────────────────────── */
@media (max-width: 768px) {
    .math-header {
        padding: 0 16px;
    }

    .math-logo-img {
        width: 120px;
    }

    .math-brand-copy {
        display: none;
    }

    .math-menu-toggle {
        display: flex;
    }

    .math-shell {
        flex-direction: column;
    }

    .math-sidebar {
        width: 100%;
        height: auto;
        max-height: 0;
        overflow: hidden;
        position: fixed;
        top: var(--math-header-height);
        left: 0;
        right: 0;
        z-index: 90;
        border-right: none;
        border-bottom: 1px solid var(--math-border);
        box-shadow: var(--math-shadow-lg);
        transition: max-height 0.3s ease;
        padding: 0;
    }

    .math-sidebar.open {
        max-height: 70vh;
        overflow-y: auto;
        padding: 16px 0;
    }

    .math-workspace {
        padding: 20px 16px;
    }

    .math-tool-title {
        font-size: 20px;
    }

    .math-input-group {
        padding: 16px;
    }

    .math-input-row {
        flex-direction: column;
    }

    .math-field {
        min-width: 100%;
    }

    .math-actions-row {
        flex-direction: column;
    }

    .math-btn {
        width: 100%;
        justify-content: center;
    }

    .math-result-value {
        font-size: 28px;
    }

    .math-result-box {
        padding: 20px;
    }

    .math-bit {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .math-bit-label {
        width: 34px;
        font-size: 9px;
    }

    .math-steps-timeline {
        padding-left: 30px;
    }

    .math-steps-timeline::before {
        left: 11px;
    }

    .math-step-badge {
        left: -30px;
        width: 24px;
        height: 24px;
        font-size: 11px;
    }

    .math-step-card {
        padding: 12px 14px;
    }

    .math-ieee-fields .math-bit {
        width: 22px;
        height: 30px;
        font-size: 11px;
    }
}

/* ─── Responsive: Small phone ──────────────────────────── */
@media (max-width: 480px) {
    .math-header {
        height: 56px;
        padding: 0 12px;
    }

    .math-logo-img {
        width: 110px;
    }

    .math-workspace {
        padding: 16px 12px;
    }

    .math-tool-title {
        font-size: 18px;
    }

    .math-tool-desc {
        font-size: 13px;
    }

    .math-input {
        font-size: 14px;
        padding: 10px 12px;
    }

    .math-result-value {
        font-size: 24px;
    }

    .math-bit {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .math-bit-label {
        width: 30px;
    }

    .math-expr {
        font-size: 12px;
        padding: 8px 12px;
    }

    .math-ieee-fields .math-bit {
        width: 18px;
        height: 26px;
        font-size: 10px;
    }
}

/* ─── Overlay for mobile sidebar ───────────────────────── */
.math-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--math-header-height);
    background: rgba(0, 0, 0, 0.3);
    z-index: 80;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.math-overlay.active {
    display: block;
    opacity: 1;
}
