:root {
    /* Light theme colors */
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-muted: #eef2f7;
    --border: #d8e1ee;
    --text: #0f172a;
    --text-secondary: #475569;
    --muted: #94a3b8;
    --primary: #0ea5a4;
    --primary-hover: #0f766e;
    --accent: #f97316;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.06);
    --shadow: 0 10px 22px rgb(15 23 42 / 0.12);
    --shadow-md: 0 18px 35px rgb(15 23 42 / 0.18);

    --radius: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --ring: rgba(14, 165, 164, 0.25);
    --glow-1: rgba(14, 165, 164, 0.22);
    --glow-2: rgba(249, 115, 22, 0.16);
    --panel-grad-start: rgba(255, 255, 255, 0.92);
    --panel-grad-end: rgba(255, 255, 255, 0.7);
    --preview-grad-start: rgba(255, 255, 255, 0.85);
    --preview-grad-end: rgba(255, 255, 255, 0.5);
}

:root[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #121c2f;
    --surface-muted: #1b2944;
    --border: #24314a;
    --text: #e2e8f0;
    --text-secondary: #cbd5e1;
    --muted: #94a3b8;
    --primary: #2dd4bf;
    --primary-hover: #14b8a6;
    --accent: #fb923c;
    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.5);
    --shadow: 0 10px 24px rgb(0 0 0 / 0.35);
    --shadow-md: 0 18px 40px rgb(0 0 0 / 0.45);
    --ring: rgba(45, 212, 191, 0.35);
    --glow-1: rgba(45, 212, 191, 0.18);
    --glow-2: rgba(251, 146, 60, 0.16);
    --panel-grad-start: rgba(18, 28, 47, 0.92);
    --panel-grad-end: rgba(18, 28, 47, 0.68);
    --preview-grad-start: rgba(18, 28, 47, 0.92);
    --preview-grad-end: rgba(18, 28, 47, 0.62);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Space Grotesk", "Manrope", "Noto Sans", sans-serif;
    background-color: var(--bg);
    background-image:
        radial-gradient(900px 500px at 10% -10%, var(--glow-1), transparent 70%),
        radial-gradient(800px 520px at 90% 0%, var(--glow-2), transparent 70%);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

button,
input,
textarea,
select {
    font-family: inherit;
}

:focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: 2px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.tool-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.tool-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    color: transparent;
    background-clip: text;
    letter-spacing: -0.025em;
    text-transform: none;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
    font-weight: 400;
}

.panel {
    background: linear-gradient(160deg, var(--panel-grad-start), var(--panel-grad-end));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    backdrop-filter: blur(10px);
    animation: panelIn 0.4s ease;
}

.panel:hover {
    box-shadow: var(--shadow-md);
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: stretch;
}

.pane {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
    min-height: 280px;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.pane-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.pane-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.pane-meta .history-btn {
    min-width: 4.5rem;
    justify-content: center;
}

.meta-pill {
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.pane-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 1.25rem;
}

.draft-status {
    font-size: 0.8125rem;
    color: var(--muted);
}

.preview-controls {
    gap: 0.6rem;
}

.preview-controls label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.preview-select {
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8125rem;
}

.preview-pane .preview {
    flex: 1;
}

.preview-pane .preview-hint {
    margin: 0;
}

.preview-footer {
    align-items: flex-start;
    flex-direction: column;
}

.preview-insights {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

.preview-chip {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
}

.preview-chip.is-valid {
    border-color: color-mix(in srgb, var(--success) 55%, var(--border));
    background: color-mix(in srgb, var(--success) 12%, var(--surface));
    color: var(--success);
}

.preview-chip.is-invalid {
    border-color: color-mix(in srgb, var(--error) 55%, var(--border));
    background: color-mix(in srgb, var(--error) 12%, var(--surface));
    color: var(--error);
}

.selection-actions {
    display: none;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.selection-actions.active {
    display: flex;
    animation: selectionIn 0.25s ease;
}

.selection-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text);
}

.selection-count {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.selection-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
    position: sticky;
    top: 1rem;
    z-index: 3;
    backdrop-filter: blur(14px);
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.toolbar-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
    position: relative;
    cursor: pointer;
    user-select: none;
}

.toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
    flex: 0 0 auto;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

.toggle input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3px var(--ring);
}

.toggle-text {
    color: var(--text);
    font-weight: 600;
}

@media (max-width: 900px) {
    .row {
        grid-template-columns: 1fr;
    }
}

#latex-input {
    min-height: 220px;
    padding: 1.125rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, 'Cascadia Code', monospace;
    font-size: 1rem;
    line-height: 1.7;
    resize: vertical;
    transition: border-color 0.2s;
    width: 100%;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

#latex-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--ring);
}

#latex-input.valid {
    border-color: var(--success);
}

#latex-input.invalid {
    border-color: var(--error);
}

.preview {
    min-height: 220px;
    padding: 1.5rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--preview-grad-start), var(--preview-grad-end)), var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.preview[data-bg="white"] {
    background: #ffffff;
    color: #0f172a;
}

.preview[data-bg="dark"] {
    background: #0b1220;
    color: #f8fafc;
}

.preview[data-bg="dark"] .katex {
    color: #f8fafc;
}

.preview[data-bg="transparent"] {
    background: linear-gradient(135deg, var(--preview-grad-start), var(--preview-grad-end)), var(--surface);
}

.preview:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

.preview.inline {
    align-items: flex-start;
    justify-content: flex-start;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 1.5rem;
    gap: 0.875rem;
}

.actions label {
    flex: 0 0 auto;
    font-weight: 500;
    color: var(--text-secondary);
}

.actions input[type="range"] {
    flex: 1 1 200px;
    min-width: 160px;
}

.actions .btn {
    flex: 0 0 auto;
}

.actions .btn.btn-ghost {
    border-style: dashed;
}

.font-size-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
}

@media (max-width: 768px) {
    .container {
        padding: 1.5rem 1rem;
    }

    .tool-header h1 {
        font-size: 2rem;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions input[type="range"] {
        width: 100%;
    }

    .selection-actions {
        align-items: flex-start;
    }

    .pane {
        min-height: unset;
        padding: 1rem;
    }

    .toolbar {
        position: static;
        backdrop-filter: none;
    }
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    font-weight: 600;
    font-size: 0.9375rem;
    box-shadow: var(--shadow-sm);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-color: var(--primary);
    color: #fff;
}

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

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-ghost:hover {
    background: var(--surface-muted);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    border-radius: var(--radius);
}

.hint {
    color: var(--muted);
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9375rem;
}

.status-message {
    margin-top: 1rem;
    text-align: left;
    font-size: 0.9375rem;
    color: var(--muted);
}

.status-message[data-state="error"] {
    color: var(--error);
}

.status-message[data-state="info"] {
    color: var(--muted);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.preview-hint {
    text-align: left;
    margin: 1rem 0 0.25rem;
}

.input-flash {
    animation: inputFlash 0.6s ease-out;
}

@keyframes inputFlash {
    0% {
        box-shadow: 0 0 0 0 var(--ring);
    }
    100% {
        box-shadow: 0 0 0 6px rgba(0, 0, 0, 0);
    }
}

@keyframes selectionIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Symbol Panel Styles */
.symbol-panel, .template-panel, .advanced-panel {
    margin-top: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.symbol-toggle-btn, .template-toggle-btn, .advanced-toggle-btn {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: none;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    transition: background 0.2s;
}

.symbol-toggle-btn:hover, .template-toggle-btn:hover, .advanced-toggle-btn:hover {
    background: var(--bg);
}

.symbol-toggle-btn.active, .template-toggle-btn.active, .advanced-toggle-btn.active {
    background: var(--primary);
    color: #fff;
}

.symbol-container, .template-container, .advanced-container {
    border-top: 1px solid var(--border);
}

.symbol-search, .template-search {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.symbol-search-input, .template-search-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9375rem;
}

.symbol-search-input:focus, .template-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.symbol-empty, .template-empty {
    margin: 0.75rem 1.25rem 1.25rem;
}

.symbol-tabs, .template-tabs, .advanced-tabs {
    display: flex;
    flex-wrap: wrap;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0;
    overflow-x: auto;
}

.symbol-tab, .template-tab, .advanced-tab {
    padding: 0.75rem 1.125rem;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.symbol-tab:hover, .template-tab:hover, .advanced-tab:hover {
    color: var(--text);
    background: var(--surface);
}

.symbol-tab.active, .template-tab.active, .advanced-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--surface);
}

.symbol-content, .template-content, .advanced-content {
    max-height: 400px;
    overflow-y: auto;
}

.symbol-grid, .template-grid {
    display: none;
    padding: 1.25rem;
}

.symbol-grid.active, .template-grid.active {
    display: grid;
}

.symbol-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.625rem;
}

.template-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.875rem;
}

.symbol-btn {
    padding: 0.875rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 1rem;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    text-align: center;
    line-height: 1.4;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    white-space: normal;
    word-break: break-word;
}

.symbol-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.template-btn {
    padding: 1rem 1.125rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.15s;
    text-align: left;
}

.template-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.template-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
    color: var(--text);
}

.template-preview {
    font-size: 0.8125rem;
    color: var(--muted);
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Advanced Panel Styles */
.advanced-content-panel {
    display: none;
    padding: 1.25rem;
}

.advanced-content-panel.active {
    display: block;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.history-list, .favorites-list {
    max-height: 220px;
    overflow-y: auto;
}

.history-item, .favorite-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.625rem;
    background: var(--bg);
    transition: all 0.15s;
}

.history-item:hover, .favorite-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.history-preview, .favorite-preview {
    flex: 1;
    font-family: monospace;
    font-size: 0.875rem;
    margin-right: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.history-actions, .favorite-actions {
    display: flex;
    gap: 0.5rem;
}

.shortcuts-list {
    max-height: 280px;
    overflow-y: auto;
}

.shortcut-item {
    display: flex;
    align-items: center;
    padding: 0.875rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
}

.shortcut-item:last-child {
    border-bottom: none;
}

kbd {
    background: var(--border);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-family: monospace;
    margin-right: 0.75rem;
    color: var(--text);
    font-weight: 500;
}

.export-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.875rem;
    margin-bottom: 1.25rem;
}

.export-btn {
    text-align: center;
    padding: 1rem 0.875rem;
}

.export-settings {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.875rem;
    align-items: center;
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.export-settings label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.export-settings select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9375rem;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1.5rem;
    font-style: italic;
    font-size: 0.9375rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .symbol-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.5rem;
    }

    .template-grid {
        grid-template-columns: 1fr;
    }

    .symbol-btn {
        font-size: 0.9375rem;
        min-height: 42px;
        padding: 0.625rem 0.375rem;
    }

    .export-options {
        grid-template-columns: 1fr;
    }

    .export-settings {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.625rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        position: static;
        backdrop-filter: none;
    }

    .toolbar-group {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .symbol-grid {
        grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
    }

    .symbol-btn {
        font-size: 0.875rem;
        min-height: 44px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

/* Theme toggle button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow);
}

/* Toolbar responsive (Task 1) */
@media (max-width: 1200px) {
    .toolbar-group.quick-inserts {
        gap: 0.5rem;
    }
    .toolbar-group.quick-inserts .btn-small {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 900px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .toolbar-group {
        width: 100%;
    }
    .toolbar-group.quick-inserts {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .toolbar-group.quick-inserts .btn-small {
        padding: 0.35rem 0.55rem;
        font-size: 0.75rem;
        flex: 0 0 auto;
    }
    .toolbar-group.quick-inserts .toolbar-label {
        width: 100%;
        font-size: 0.8125rem;
    }
}

/* Preview render transition (Task 6) */
.preview .katex {
    animation: previewFadeIn 0.25s ease;
}

@keyframes previewFadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Active toggle indicator (Task 6) */
.toggle input:checked ~ .toggle-text {
    color: var(--primary);
}

/* Actions visual grouping (Task 6) */
.actions .btn-primary {
    order: -1;
}

/* Symbol/template panel hover effects (Task 6) */
.symbol-btn:active,
.template-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Render error display (Task 3) */
.render-error {
    color: var(--error);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    padding: 1rem;
    text-align: left;
    width: 100%;
}

.render-error .render-error-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.render-error .render-error-detail {
    opacity: 0.85;
    word-break: break-word;
}

/* Keyboard shortcuts modal (Task 5) */
.shortcuts-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.2s ease;
}

.shortcuts-modal-overlay.active {
    display: flex;
}

.shortcuts-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    animation: modalSlideIn 0.25s ease;
}

.shortcuts-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.shortcuts-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.shortcuts-modal-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 32px;
    height: 32px;
    font-size: 1.125rem;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.shortcuts-modal-close:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.shortcuts-modal-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.shortcuts-modal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
    color: var(--text);
}

.shortcuts-modal-item:last-child {
    border-bottom: none;
}

.shortcuts-modal-item kbd {
    margin-right: 0;
    flex-shrink: 0;
}

.shortcuts-modal-hint {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.8125rem;
    color: var(--muted);
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
