/* =================================================================
   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: 320px;
    --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: 18px;
    min-width: 0;
    text-decoration: none;
    height: 56px;
    overflow: hidden;
}

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

.math-logo-img {
    width: 168px;
    height: auto;
    object-fit: contain;
    flex-shrink: 0;
}

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

.math-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--math-text);
    white-space: nowrap;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

.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: 1px solid transparent;
    border-radius: var(--math-radius-sm);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--math-transition);
    line-height: 1;
}

.math-menu-toggle i {
    font-size: 17px;
    line-height: 1;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.math-menu-toggle.active i {
    transform: scale(0.92);
}

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

/* ─── Main Layout ──────────────────────────────────────── */
.math-shell {
    display: flex;
    width: 100%;
    min-height: calc(100vh - var(--math-header-height));
    min-height: calc(100dvh - var(--math-header-height));
}

/* ─── 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;
    display: flex;
    justify-content: flex-start;
    padding: 36px 40px 48px;
}

.math-tool-panel {
    display: none;
    width: min(100%, 980px);
    max-width: none;
    margin: 0;
    opacity: 1;
    transform: translateY(0);
    transform-origin: top center;
    will-change: opacity, transform;
}

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

.math-tool-panel.active.is-panel-transition-in {
    animation: math-tool-panel-enter 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.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-field-note {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--math-text-muted);
}

.math-field-note code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: var(--math-text-soft);
}

.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-input-control {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.math-input-control .math-input {
    flex: 1;
    min-width: 0;
}

.math-sign-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    padding: 0;
    border: 1.5px solid var(--math-border);
    border-radius: var(--math-radius-sm);
    background: var(--math-surface-alt);
    color: var(--math-text);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: all var(--math-transition);
}

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

.math-sign-toggle.hidden {
    display: none !important;
}

.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);
}

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

/* ─── 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-meta {
    margin-top: 12px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--math-text-soft);
}

.math-result-meta code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: var(--math-text);
}

.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-steps-scroll-cue {
    position: sticky;
    bottom: 16px;
    z-index: 5;
    display: none;
    justify-content: center;
    margin-top: -2px;
    pointer-events: none;
}

.math-steps-scroll-cue.visible {
    display: flex;
}

.math-steps-scroll-cue-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid rgba(99, 102, 241, 0.18);
    border-radius: var(--math-radius-full);
    background: rgba(255, 255, 255, 0.9);
    color: var(--math-primary);
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(8px);
    animation: math-scroll-cue-bounce 1.6s ease-in-out infinite;
}

.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;
}

.math-expr .math-transform-before {
    color: var(--math-error);
    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;
}

/* ─── 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;
    table-layout: fixed;
}

.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 th,
.math-ascii-table td {
    vertical-align: middle;
}

.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-col-dec,
.math-ascii-col-hex,
.math-ascii-col-oct,
.math-ascii-col-bin,
.math-ascii-col-char {
    text-align: center;
    white-space: nowrap;
}

.math-ascii-col-dec {
    width: 10%;
}

.math-ascii-col-hex {
    width: 10%;
}

.math-ascii-col-oct {
    width: 10%;
}

.math-ascii-col-bin {
    width: 18%;
}

.math-ascii-col-char {
    width: 14%;
}

.math-ascii-col-name {
    text-align: left;
    font-family: 'Manrope', sans-serif;
    font-size: 11px;
    color: var(--math-text-soft);
}

.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);
}

/* ─── Bitwise Table (in steps) ─────────────────────────── */
.math-bitwise-table {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    line-height: 2;
    margin: 8px 0;
    padding: 12px 16px;
    background: var(--math-surface-alt);
    border-radius: var(--math-radius-sm);
    border: 1px solid var(--math-border-light);
}

.math-bitwise-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-bitwise-label {
    width: 36px;
    text-align: right;
    font-weight: 700;
    color: var(--math-text-soft);
    flex-shrink: 0;
}

.math-bitwise-divider {
    height: 2px;
    background: var(--math-primary);
    margin: 4px 0;
    border-radius: 1px;
}

.math-bitwise-result {
    color: var(--math-primary);
    font-weight: 700;
}

/* ─── Step Final Result Card ──────────────────────────── */
.math-step-final {
    border-color: var(--math-primary);
    border-width: 2px;
    background: linear-gradient(135deg, var(--math-surface) 0%, var(--math-primary-soft) 100%);
}

/* ─── Bit Animation States ─────────────────────────────── */
.math-bit-anim {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.math-bit-anim.bit-visible {
    opacity: 1;
    transform: scale(1);
}

.math-bit-anim.bit-flipping {
    transform: scale(1.15) rotateY(90deg);
    transition: transform 0.2s ease-in;
}

.math-bit-anim.bit-flipped {
    animation: math-bit-land 0.3s ease-out;
}

.math-bit-anim.bit-carry-pulse {
    animation: math-carry-glow 0.4s ease;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
}

.math-bit-anim.bit-carried {
    animation: math-bit-land 0.3s ease-out;
}

.math-bit-anim.bit-pulse-once {
    animation: math-bit-pulse 0.4s ease;
}

/* ─── Expression Animation ─────────────────────────────── */
.math-expr-anim {
    opacity: 0;
    transform: translateY(6px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.math-expr-anim.expr-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ─── IEEE 754 Bit Animation ──────────────────────────── */
.math-ieee-bit-anim {
    opacity: 0;
    transform: scale(0.7);
    animation: math-ieee-bit-pop 0.3s ease forwards;
}

/* ─── Truth Table Row Animation ───────────────────────── */
.math-truth-row-anim {
    opacity: 0;
    animation: math-row-fade 0.2s ease forwards;
}

/* ─── 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(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes math-bit-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.18); box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4); }
    100% { transform: scale(1); }
}

@keyframes math-bit-land {
    0% { transform: scale(1.15) rotateY(-90deg); }
    60% { transform: scale(1.05) rotateY(0); }
    100% { transform: scale(1) rotateY(0); }
}

@keyframes math-carry-glow {
    0% { box-shadow: 0 0 0 rgba(99, 102, 241, 0); transform: scale(1); }
    50% { box-shadow: 0 0 16px rgba(99, 102, 241, 0.6); transform: scale(1.15); }
    100% { box-shadow: 0 0 4px rgba(99, 102, 241, 0.2); transform: scale(1); }
}

@keyframes math-ieee-bit-pop {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes math-scroll-cue-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

@keyframes math-row-fade {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

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

    .math-workspace {
        padding: 24px;
    }

    .math-tool-panel {
        width: 100%;
    }
}

/* ─── Responsive: Mobile ───────────────────────────────── */
@media (max-width: 768px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .math-header-right {
        gap: 8px;
    }

    .math-header {
        padding: 0 16px;
    }

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

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

    .math-back-to-landing span {
        display: none;
    }

    .math-back-to-landing,
    .math-menu-toggle {
        display: flex;
        width: 44px;
        min-width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        align-items: center;
        border: 1px solid rgba(99, 102, 241, 0.20);
        border-radius: 14px;
        color: var(--math-primary);
        background:
            linear-gradient(180deg, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0) 55%),
            linear-gradient(180deg, rgba(99, 102, 241, 0.16) 0%, rgba(99, 102, 241, 0.08) 100%);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.9),
            inset 0 0 0 1px rgba(99, 102, 241, 0.06),
            0 10px 22px -8px rgba(99, 102, 241, 0.32),
            0 2px 6px rgba(99, 102, 241, 0.10);
        transition:
            transform 0.18s cubic-bezier(0.22, 1, 0.36, 1),
            box-shadow 0.22s ease,
            background 0.22s ease,
            border-color 0.22s ease;
    }

    .math-back-to-landing i,
    .math-menu-toggle i {
        font-size: 17px;
        line-height: 1;
    }

    .math-back-to-landing:hover,
    .math-menu-toggle:hover {
        transform: translateY(-1px);
        border-color: rgba(99, 102, 241, 0.28);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.95),
            inset 0 0 0 1px rgba(99, 102, 241, 0.10),
            0 14px 28px -10px rgba(99, 102, 241, 0.38),
            0 4px 10px rgba(99, 102, 241, 0.14);
    }

    .math-back-to-landing:active,
    .math-menu-toggle:active,
    .math-menu-toggle.active {
        transform: translateY(0) scale(0.96);
        border-color: rgba(99, 102, 241, 0.32);
        background:
            linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 55%),
            linear-gradient(180deg, rgba(99, 102, 241, 0.26) 0%, rgba(99, 102, 241, 0.14) 100%);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.55),
            inset 0 0 0 1px rgba(99, 102, 241, 0.18),
            0 4px 12px -4px rgba(99, 102, 241, 0.28);
    }

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

    .math-sidebar {
        width: 100%;
        max-height: min(70vh, calc(100dvh - var(--math-header-height) - 12px));
        overflow-y: auto;
        overscroll-behavior: contain;
        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);
        padding: 8px 0 16px;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(-14px) scale(0.985);
        transform-origin: top center;
        will-change: transform, opacity;
        transition:
            opacity 0.22s ease,
            transform 0.34s cubic-bezier(0.22, 1, 0.36, 1),
            visibility 0s linear 0.34s;
    }

    .math-sidebar.open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translateY(0) scale(1);
        transition:
            opacity 0.24s ease,
            transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
            visibility 0s linear 0s;
    }

    .math-sidebar-category:first-child .math-sidebar-category-title {
        padding-top: 0;
    }

    .math-workspace {
        display: block;
        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-sign-toggle {
        display: inline-flex;
    }

    .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-steps-scroll-cue {
        bottom: 10px;
    }

    .math-steps-scroll-cue-pill {
        font-size: 11px;
        padding: 9px 12px;
    }

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

@media (pointer: coarse) {
    .math-sign-toggle {
        display: inline-flex;
    }
}

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

    .math-header {
        height: var(--math-header-height);
        padding: 0 12px;
    }

    .math-header-right {
        gap: 6px;
    }

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

    .math-back-to-landing,
    .math-menu-toggle {
        width: 42px;
        min-width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .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 {
    position: fixed;
    inset: 0;
    top: var(--math-header-height);
    background: rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 80;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 0.28s;
}

.math-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 0s;
}

body.view-transitioning .math-landing,
body.view-transitioning .math-shell {
    pointer-events: none;
}

@keyframes math-view-enter {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.992);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes math-tool-panel-enter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =================================================================
   LANDING PAGE / MENU
   ================================================================= */
.math-landing {
    display: none;
    min-height: calc(100vh - var(--math-header-height));
    background: linear-gradient(180deg, #f8faff 0%, #f5f7fa 100%);
    padding: 48px 24px 64px;
    opacity: 1;
    transform: translateY(0) scale(1);
    transform-origin: top center;
    will-change: opacity, transform;
    transition:
        opacity 0.2s ease,
        transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.math-landing.visible {
    display: block;
}

.math-landing.is-transition-out {
    opacity: 0;
    transform: translateY(18px) scale(0.992);
}

.math-landing.is-transition-in {
    animation: math-view-enter 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

body.landing-visible .math-shell {
    display: none;
}

body.landing-visible .math-back-to-landing {
    color: var(--math-text-soft);
    border-color: rgba(148, 163, 184, 0.26);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(248, 250, 252, 0.92) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        0 1px 2px rgba(15, 23, 42, 0.04);
    pointer-events: none;
    cursor: default;
}

body.landing-visible .math-menu-toggle {
    color: var(--math-text-soft);
    border-color: rgba(148, 163, 184, 0.26);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(248, 250, 252, 0.92) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        0 1px 2px rgba(15, 23, 42, 0.04);
    pointer-events: none;
    cursor: default;
}

.math-landing-hero {
    max-width: 900px;
    margin: 0 auto 48px;
    text-align: center;
    padding: 24px 16px;
}

.math-landing-logo-link {
    display: inline-block;
    margin-bottom: 24px;
    transition: transform var(--math-transition);
}

.math-landing-logo-link:hover {
    transform: scale(1.03);
}

.math-landing-logo {
    max-width: 180px;
    height: auto;
}

.math-landing-title {
    font-size: clamp(32px, 5vw, 48px);
    font-weight: 800;
    color: var(--math-text);
    margin-bottom: 18px;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--math-primary) 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.math-landing-subtitle {
    font-size: clamp(15px, 2vw, 18px);
    color: var(--math-text-soft);
    line-height: 1.65;
    max-width: 720px;
    margin: 0 auto 24px;
}

.math-landing-subtitle strong {
    color: var(--math-text);
    font-weight: 700;
}

.math-landing-hero-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

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

.math-landing-section-title {
    max-width: 1200px;
    margin: 0 auto 28px;
    text-align: center;
}

.math-landing-section-title h2 {
    font-size: 26px;
    font-weight: 700;
    color: var(--math-text);
    margin-bottom: 6px;
}

.math-landing-section-title p {
    font-size: 14px;
    color: var(--math-text-muted);
}

.math-landing-grid {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.math-landing-card {
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-lg);
    padding: 24px 22px;
    cursor: pointer;
    transition: transform var(--math-transition), box-shadow var(--math-transition), border-color var(--math-transition);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--math-shadow-xs);
    text-align: left;
    transform-origin: center center;
    color: inherit;
    text-decoration: none;
}

.math-landing-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--math-shadow-lg);
    border-color: var(--math-primary);
}

.math-landing-card.is-activating {
    transform: translateY(-8px) scale(1.015);
    box-shadow: 0 18px 42px rgba(99, 102, 241, 0.18), var(--math-shadow-lg);
    border-color: var(--math-primary);
}

.math-shell {
    opacity: 1;
    transform-origin: top center;
    transition:
        opacity 0.2s ease,
        transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.math-shell.is-transition-out {
    opacity: 0;
    transform: translateY(18px) scale(0.992);
}

.math-shell.is-transition-in {
    animation: math-view-enter 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.math-landing-card-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--math-radius-md);
    background: var(--math-primary-soft);
    color: var(--math-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: background var(--math-transition), transform var(--math-transition);
}

.math-landing-card:hover .math-landing-card-icon {
    background: var(--math-primary);
    color: #fff;
    transform: scale(1.08) rotate(-4deg);
}

.math-landing-card h3 {
    font-size: 17px;
    font-weight: 700;
    color: var(--math-text);
    margin: 0;
    line-height: 1.35;
}

.math-landing-card p {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--math-text-soft);
    margin: 0;
    flex: 1;
}

.math-landing-card p code {
    background: var(--math-primary-soft);
    color: var(--math-primary-hover);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.math-landing-card-tag {
    display: inline-block;
    font-size: 11px;
    color: var(--math-text-muted);
    border-top: 1px solid var(--math-border-light);
    padding-top: 10px;
    margin-top: 4px;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.math-landing-footer {
    max-width: 900px;
    margin: 64px auto 0;
    padding: 36px 24px;
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-lg);
    text-align: center;
    box-shadow: var(--math-shadow-sm);
}

.math-landing-footer p {
    font-size: 15px;
    color: var(--math-text-soft);
    line-height: 1.6;
    margin-bottom: 20px;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
}

.math-landing-footer p strong {
    color: var(--math-text);
}

.math-landing-footer .math-btn {
    font-size: 14px;
    padding: 12px 22px;
}

/* Back-to-landing button in header */
.math-back-to-landing {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--math-primary);
    border: 1px solid rgba(99, 102, 241, 0.16);
    border-radius: var(--math-radius-md);
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 55%),
        linear-gradient(180deg, rgba(99, 102, 241, 0.14) 0%, rgba(99, 102, 241, 0.07) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        0 6px 16px -6px rgba(99, 102, 241, 0.25),
        0 1px 2px rgba(99, 102, 241, 0.08);
    transition:
        transform 0.18s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.22s ease,
        background 0.22s ease,
        color 0.22s ease,
        border-color 0.22s ease;
    text-decoration: none;
}

.math-back-to-landing:hover {
    transform: translateY(-1px);
    color: #fff;
    border-color: var(--math-primary);
    background: linear-gradient(180deg, var(--math-primary) 0%, var(--math-primary-hover) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.25),
        0 14px 28px -10px rgba(99, 102, 241, 0.45),
        0 4px 10px rgba(99, 102, 241, 0.18);
}

body.landing-visible .math-back-to-landing:hover,
body.landing-visible .math-back-to-landing:active,
body.landing-visible .math-menu-toggle:hover,
body.landing-visible .math-menu-toggle:active,
body.landing-visible .math-menu-toggle.active {
    transform: none;
    color: var(--math-text-soft);
    border-color: rgba(148, 163, 184, 0.26);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(248, 250, 252, 0.92) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        0 1px 2px rgba(15, 23, 42, 0.04);
}

.math-back-to-landing:active {
    transform: translateY(0) scale(0.98);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 4px 12px -4px rgba(99, 102, 241, 0.3);
}

.math-back-to-landing i {
    font-size: 15px;
    line-height: 1;
}

/* Mobile landing layout */
@media (max-width: 720px) {
    .math-landing {
        padding: 24px 14px 48px;
    }
    .math-landing-hero {
        margin-bottom: 28px;
    }
    .math-landing-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .math-landing-card {
        padding: 20px 18px;
    }
    .math-landing-footer {
        margin-top: 40px;
        padding: 28px 20px;
    }
}

/* =================================================================
   STEP HINT (beginner-friendly tooltip-style callout)
   ================================================================= */
.math-step-hint {
    background: rgba(99, 102, 241, 0.06);
    border-left: 3px solid var(--math-primary);
    padding: 10px 14px;
    border-radius: 0 var(--math-radius-sm) var(--math-radius-sm) 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--math-text-soft);
    margin-top: 10px;
}

.math-step-hint::before {
    content: "💡 ";
    font-size: 13px;
    margin-right: 2px;
}

.math-step-hint strong {
    color: var(--math-text);
    font-weight: 600;
}

.math-step-hint code {
    background: #fff;
    border: 1px solid var(--math-border);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 12px;
}

/* =================================================================
   TRUTH TABLE — legend, color coding, summary
   ================================================================= */
.math-truth-description {
    background: var(--math-surface-alt);
    border: 1px solid var(--math-border-light);
    border-radius: var(--math-radius-sm);
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--math-text-soft);
    margin-bottom: 14px;
}

.math-truth-description strong {
    color: var(--math-text);
}

.math-truth-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--math-text-soft);
    align-items: center;
}

.math-truth-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--math-surface-alt);
    border: 1px solid var(--math-border-light);
    padding: 6px 12px;
    border-radius: var(--math-radius-full);
}

.math-truth-legend-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    font-weight: 700;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.math-truth-legend-cell.zero {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.math-truth-legend-cell.one {
    background: rgba(16, 185, 129, 0.15);
    color: #047857;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.math-truth-table td.math-truth-zero {
    background: rgba(239, 68, 68, 0.07);
    color: #b91c1c;
}

.math-truth-table td.math-truth-one {
    background: rgba(16, 185, 129, 0.10);
    color: #047857;
}

.math-truth-table td.result-col.math-truth-zero {
    background: rgba(239, 68, 68, 0.14);
    font-weight: 700;
}

.math-truth-table td.result-col.math-truth-one {
    background: rgba(16, 185, 129, 0.18);
    font-weight: 700;
}

.math-truth-col-label {
    display: block;
    font-size: 10px;
    color: var(--math-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

.math-truth-summary {
    margin-top: 14px;
    padding: 12px 16px;
    background: var(--math-surface-alt);
    border-radius: var(--math-radius-sm);
    border: 1px solid var(--math-border-light);
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    font-size: 13px;
    color: var(--math-text-soft);
}

.math-truth-summary-item strong {
    color: var(--math-text);
    font-weight: 700;
}

/* =================================================================
   BOOLEAN SIMPLIFIER — quick example buttons
   ================================================================= */
.math-bool-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--math-surface-alt);
    border: 1px dashed var(--math-border);
    border-radius: var(--math-radius-sm);
}

.math-bool-examples-label {
    font-size: 12px;
    color: var(--math-text-muted);
    font-weight: 600;
    margin-right: 4px;
}

.math-bool-example-btn {
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: var(--math-radius-sm);
    padding: 6px 12px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    color: var(--math-text-soft);
    cursor: pointer;
    transition: all var(--math-transition);
}

.math-bool-example-btn:hover {
    background: var(--math-primary);
    color: #fff;
    border-color: var(--math-primary);
    transform: translateY(-1px);
}

/* Rule name styling in boolean simplifier steps */
.math-rule-name {
    display: inline-block;
    background: var(--math-primary-soft);
    color: var(--math-primary-hover);
    padding: 2px 10px;
    border-radius: var(--math-radius-full);
    font-size: 12px;
    font-weight: 600;
    margin-right: 6px;
}

.math-rule-name-en {
    color: var(--math-text-muted);
    font-size: 11px;
    font-weight: 500;
    font-style: italic;
}

/* =================================================================
   NEW TOOL UTILITIES
   ================================================================= */

/* ─── Byte boxes (Endianness) ─────────────────────────── */
.math-byte-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.math-byte-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    height: 44px;
    padding: 0 10px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    opacity: 0;
    transform: scale(0.8);
    animation: math-byte-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes math-byte-pop {
    from { opacity: 0; transform: scale(0.8) translateY(6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ─── Binary Add/Sub visual grid ──────────────────────── */
.math-add-grid {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 15px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
    overflow-x: auto;
}

.math-add-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.math-add-label {
    width: 28px;
    text-align: center;
    font-weight: 700;
    color: var(--math-text-soft);
    flex-shrink: 0;
}

.math-add-cell {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: 600;
    background: var(--math-surface-alt);
    border: 1px solid var(--math-border-light);
    color: var(--math-text);
}

.math-add-carry {
    font-size: 11px;
    width: 32px;
    height: 22px;
    color: var(--math-text-muted);
    background: transparent;
    border: 1px dashed var(--math-border);
}

.math-add-carry.active {
    color: var(--math-warning);
    border-color: var(--math-warning);
    background: rgba(245, 158, 11, 0.08);
    font-weight: 700;
}

.math-add-divider {
    height: 2px;
    background: var(--math-primary);
    margin: 2px 0 2px 30px;
    border-radius: 1px;
}

.math-add-result {
    background: var(--math-primary-soft);
    border-color: var(--math-primary);
    color: var(--math-primary);
    font-weight: 700;
}

.math-add-carry-row {
    opacity: 0.7;
}

/* ─── Bit Mask Grid ───────────────────────────────────── */
.math-bit-mask-grid {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.math-bit-mask-cell {
    width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0 8px;
    border: 2px solid var(--math-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    background: var(--math-surface);
}

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

.math-bit-mask-cell.active {
    border-color: var(--math-primary);
    background: var(--math-primary);
    color: #fff;
}

.math-bit-mask-cell.active .math-bit-mask-label {
    color: rgba(255, 255, 255, 0.7);
}

.math-bit-mask-cell.active .math-bit-mask-val {
    color: #fff;
}

.math-bit-mask-label {
    font-size: 9px;
    font-weight: 600;
    color: var(--math-text-muted);
    font-family: 'SF Mono', monospace;
}

.math-bit-mask-val {
    font-size: 16px;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: var(--math-text);
}

/* ─── Logic Gate toggle buttons ───────────────────────── */
.math-gate-toggle {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--math-border);
    border-radius: var(--math-radius-sm);
    background: var(--math-surface);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.math-gate-toggle .math-gate-toggle-val {
    font-size: 24px;
    font-weight: 800;
    color: var(--math-error);
    transition: all 0.2s ease;
}

.math-gate-toggle.active {
    border-color: var(--math-success);
    background: rgba(16, 185, 129, 0.1);
}

.math-gate-toggle.active .math-gate-toggle-val {
    color: var(--math-success);
}

.math-gate-toggle:hover {
    border-color: var(--math-primary);
    transform: scale(1.02);
}

/* ─── IPv4 Subnet result rows ─────────────────────────── */
.math-subnet-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--math-border-light);
    font-size: 14px;
}

.math-subnet-row:last-child {
    border-bottom: none;
}

.math-subnet-row strong {
    color: var(--math-text-soft);
    font-size: 12px;
    min-width: 110px;
    flex-shrink: 0;
}

.math-subnet-val {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-weight: 700;
    color: var(--math-primary);
    font-size: 15px;
}

/* ─── Responsive tweaks for new tools ─────────────────── */
@media (max-width: 768px) {
    .math-byte-box {
        min-width: 40px;
        height: 38px;
        font-size: 14px;
    }

    .math-add-cell {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .math-add-carry {
        width: 26px;
        height: 18px;
        font-size: 10px;
    }

    .math-add-label {
        width: 22px;
        font-size: 12px;
    }

    .math-bit-mask-cell {
        width: 34px;
    }

    .math-bit-mask-val {
        font-size: 14px;
    }

    .math-subnet-row {
        flex-direction: column;
        gap: 2px;
    }

    .math-subnet-row strong {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .math-add-cell {
        width: 22px;
        height: 22px;
        font-size: 11px;
    }

    .math-add-carry {
        width: 22px;
        height: 16px;
        font-size: 9px;
    }

    .math-add-label {
        width: 18px;
        font-size: 11px;
    }

    .math-bit-mask-cell {
        width: 28px;
        padding: 4px 0 6px;
    }

    .math-bit-mask-label {
        font-size: 8px;
    }

    .math-bit-mask-val {
        font-size: 12px;
    }
}
