:root {
    /* Light theme colors */
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-secondary: #64748b;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --border: #334155;
        --text: #f1f5f9;
        --text-secondary: #cbd5e1;
        --muted: #94a3b8;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --success: #34d399;
        --warning: #fbbf24;
        --error: #f87171;

        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
        --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
        --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.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;
    color: var(--text);
    letter-spacing: -0.025em;
}

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

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    transition: all 0.2s;
}

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

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

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

#latex-input {
    min-height: 250px;
    padding: 1.125rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    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%;
}

#latex-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

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

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

.preview {
    min-height: 250px;
    padding: 1.5rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

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

@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%;
    }
}

.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: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

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

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

/* 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-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 {
        grid-template-columns: 1fr 1fr;
        gap: 0.625rem;
    }
}

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

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

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