/* ========================================================================
   Excel Formula Explainer — Styles
   Premium dark-first glassmorphism design
   ======================================================================== */

:root {
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --primary: #3B82F6;
    --primary-hover: #4B92FF;
    --accent: #10B981;
    --bg: #0F172A;
    --bg-secondary: #1E293B;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.04);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(59, 130, 246, 0.5);
    --text: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.3);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --gradient: linear-gradient(135deg, #3B82F6, #10B981);
    --func-color: #3B82F6;
    --string-color: #F59E0B;
    --number-color: #10B981;
    --ref-color: #A78BFA;
    --op-color: #F472B6;
    --paren-color: #94A3B8;
}

[data-theme="light"] {
    --bg: #F8FAFC;
    --bg-secondary: #FFFFFF;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.6);
    --bg-glass-hover: rgba(0, 0, 0, 0.04);
    --bg-input: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.08);
    --text: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.08);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -40%;
    left: -20%;
    width: 70%;
    height: 70%;
    background: radial-gradient(ellipse, rgba(59, 130, 246, 0.07) 0%, transparent 70%);
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    bottom: -30%;
    right: -15%;
    width: 50%;
    height: 50%;
    background: radial-gradient(ellipse, rgba(16, 185, 129, 0.05) 0%, transparent 70%);
    pointer-events: none;
}

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-title {
    font-size: 1.125rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 0.375rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: all var(--transition);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--gradient);
    color: #fff;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(59, 130, 246, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem;
    border: 1px solid transparent;
}

.btn-ghost:hover {
    background: var(--bg-glass-hover);
    color: var(--text);
    border-color: var(--border);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-icon {
    padding: 0.5rem;
}

/* Main */
.main {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

/* Input Section */
.input-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    animation: fadeInUp 0.5s ease-out;
}

.section-header {
    text-align: center;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.formula-input-wrapper {
    width: 100%;
}

.formula-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.formula-bar:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.fx-label {
    font-family: 'Georgia', serif;
    font-weight: 700;
    font-style: italic;
    color: var(--primary);
    font-size: 1rem;
    padding: 0 0.25rem;
    flex-shrink: 0;
}

.formula-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.9375rem;
    outline: none;
    padding: 0.5rem 0;
}

.formula-input::placeholder {
    color: var(--text-muted);
}

.quick-examples {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    padding: 0 0.25rem;
}

.examples-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.example-chip {
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.example-chip:hover {
    background: var(--bg-glass-hover);
    color: var(--text);
    border-color: var(--primary);
}

/* Results Section */
.results-section {
    animation: fadeInUp 0.5s ease-out;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.results-actions {
    display: flex;
    gap: 0.375rem;
}

/* Formula Display */
.formula-display {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 1rem;
    line-height: 1.8;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.token-func {
    color: var(--func-color);
    font-weight: 600;
}

.token-string {
    color: var(--string-color);
}

.token-number {
    color: var(--number-color);
}

.token-ref {
    color: var(--ref-color);
}

.token-op {
    color: var(--op-color);
    font-weight: 600;
}

.token-paren {
    color: var(--paren-color);
}

.token-comma {
    color: var(--text-muted);
}

/* Summary Card */
.summary-card {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.summary-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.summary-text {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.7;
}

.summary-text strong {
    color: var(--text);
}

.summary-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.75rem;
}

.tag {
    padding: 0.1875rem 0.625rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tag-func {
    background: rgba(59, 130, 246, 0.12);
    color: var(--func-color);
}

.tag-complexity-low {
    background: rgba(16, 185, 129, 0.12);
    color: var(--accent);
}

.tag-complexity-med {
    background: rgba(245, 158, 11, 0.12);
    color: var(--string-color);
}

.tag-complexity-high {
    background: rgba(244, 114, 182, 0.12);
    color: var(--op-color);
}

/* Steps */
.steps-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.step-card {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
    animation: fadeInUp 0.4s ease-out backwards;
}

.step-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-title {
    font-weight: 600;
    font-size: 0.9375rem;
}

.step-code {
    font-family: 'SF Mono', monospace;
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    margin: 0.5rem 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.step-explanation {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* Reference Card */
.reference-card {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.ref-title {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ref-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
}

.ref-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.ref-func-name {
    font-family: 'SF Mono', monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--func-color);
}

.ref-func-syntax {
    font-family: 'SF Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ref-func-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal-card {
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    animation: scaleIn 0.25s ease-out;
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
}

.modal-footer {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.history-item {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.history-item:hover {
    background: var(--bg-glass-hover);
}

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

.history-formula {
    font-family: 'SF Mono', monospace;
    font-size: 0.8125rem;
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.empty-history {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.step-card:nth-child(1) {
    animation-delay: 0s;
}

.step-card:nth-child(2) {
    animation-delay: 0.06s;
}

.step-card:nth-child(3) {
    animation-delay: 0.12s;
}

.step-card:nth-child(4) {
    animation-delay: 0.18s;
}

.step-card:nth-child(5) {
    animation-delay: 0.24s;
}

.step-card:nth-child(6) {
    animation-delay: 0.3s;
}

@media (max-width: 640px) {
    .header-content {
        padding: 0.625rem 1rem;
    }

    .main {
        padding: 1.5rem 1rem;
    }

    .section-title {
        font-size: 1.25rem;
    }

    .formula-bar {
        flex-wrap: wrap;
    }

    .formula-input {
        min-width: 0;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .logo-subtitle {
        display: none;
    }
}