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

:root {
    --bg: #f9f7f7;
    --bg-secondary: #dbe2ef;
    --bg-card: #ffffff;
    --text: #112d4e;
    --text-secondary: #3f72af;
    --text-muted: #7b9dc7;
    --border: #c4d4e8;
    --border-focus: #3f72af;
    --primary: #3f72af;
    --primary-hover: #2e5d94;
    --primary-light: #dbe2ef;
    --success: #10b981;
    --success-light: #ecfdf5;
    --error: #ef4444;
    --error-light: #fef2f2;
    --shadow-sm: 0 1px 2px rgba(17, 45, 78, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(17, 45, 78, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(17, 45, 78, 0.08);
    --shadow-xl: 0 20px 25px -5px rgba(17, 45, 78, 0.08);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: 200ms ease;
}

[data-theme="dark"] {
    --bg: #0d1b2a;
    --bg-secondary: #1b2d45;
    --bg-card: #152238;
    --text: #f9f7f7;
    --text-secondary: #dbe2ef;
    --text-muted: #7b9dc7;
    --border: #2a4568;
    --border-focus: #5b8fc0;
    --primary-light: #1b2d45;
    --success-light: #064e3b;
    --error-light: #450a0a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition:
        background var(--transition),
        color var(--transition);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

[data-theme="dark"] a {
    color: var(--border-focus);
}

[data-theme="dark"] a:hover {
    color: var(--primary);
}

/* ===== Navbar ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition:
        background var(--transition),
        border-color var(--transition);
}

.nav-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.5px;
}

.logo-icon {
    width: 26px;
    height: 26px;
    color: var(--primary);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

.moon-icon {
    display: none;
}

/* ===== Main ===== */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===== Hero ===== */
.hero {
    text-align: left;
    padding: 48px 0 32px;
}

.hero-title {
    font-size: clamp(1.8rem, 4.5vw, 3rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -1px;
    color: var(--primary);
}

.hero-title-block {
    display: block;
}

.hero-subtitle {
    margin-top: 12px;
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 620px;
    line-height: 1.7;
}

/* ===== Balancer Card ===== */
.balancer-section {
    margin-bottom: 48px;
}

.balancer-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-xl);
    transition:
        background var(--transition),
        border-color var(--transition),
        box-shadow var(--transition);
}

.input-group {
    margin-bottom: 20px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
}

.equation-input {
    flex: 1;
    padding: 14px 18px;
    font-size: 1.05rem;
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", monospace;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
    transition: all var(--transition);
}

.equation-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(63, 114, 175, 0.2);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(63, 114, 175, 0.35);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 14px rgba(63, 114, 175, 0.4);
    transform: translateY(-1px);
}

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

.btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.input-hints {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.input-hints code {
    font-size: 0.8rem;
    padding: 1px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* ===== Loading Spinner ===== */
.spinner-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 20px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== Error ===== */
.error-area {
    margin-top: 16px;
    padding: 14px 18px;
    background: var(--error-light);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.9rem;
    font-weight: 500;
}

/* ===== Dual Solutions ===== */
.dual-solutions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.dual-solutions.single-col {
    grid-template-columns: 1fr;
}

.solution-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.solution-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.solution-panel-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.solution-panel-body {
    padding: 16px;
}

.solution-panel .placeholder-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.solution-panel .balanced-equation {
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    word-break: break-all;
    line-height: 1.7;
    padding: 6px 0;
}

.solution-panel .solution-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.88rem;
    margin-bottom: 6px;
    transition: all var(--transition);
}

.solution-panel .solution-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.solution-panel .solution-index {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 24px;
    flex-shrink: 0;
    padding-top: 2px;
}

.panel-error {
    padding: 12px 16px;
    color: var(--error);
    font-size: 0.85rem;
    font-weight: 500;
}

.panel-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.panel-copy-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.panel-copy-btn svg {
    width: 14px;
    height: 14px;
}

/* ===== Equation Highlighting ===== */
.balanced-equation .hl-element {
    color: #112d4e;
    font-weight: 700;
}

.balanced-equation .hl-number {
    color: #3f72af;
    font-weight: 800;
}

.balanced-equation .hl-separator {
    color: #7b9dc7;
    font-weight: 400;
}

.balanced-equation .hl-charge {
    color: #112d4e;
    font-weight: 600;
}

[data-theme="dark"] .balanced-equation .hl-element {
    color: #f9f7f7;
}

[data-theme="dark"] .balanced-equation .hl-number {
    color: #5b8fc0;
}

[data-theme="dark"] .balanced-equation .hl-separator {
    color: #7b9dc7;
}

[data-theme="dark"] .balanced-equation .hl-charge {
    color: #f9f7f7;
}

.solution-item .hl-element {
    color: #112d4e;
    font-weight: 600;
}

.solution-item .hl-number {
    color: #3f72af;
    font-weight: 700;
}

.solution-item .hl-separator {
    color: #7b9dc7;
}

[data-theme="dark"] .solution-item .hl-element {
    color: #f9f7f7;
}

[data-theme="dark"] .solution-item .hl-number {
    color: #5b8fc0;
}

[data-theme="dark"] .solution-item .hl-separator {
    color: #7b9dc7;
}

/* ===== Examples ===== */
.examples-section {
    margin-bottom: 48px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    margin-top: 32px;
}

.examples-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.example-chip {
    display: inline-block;
    padding: 9px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.85rem;
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.example-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ===== About ===== */
.about-section {
    margin-bottom: 64px;
    max-width: 700px;
}

.about-section h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.about-section p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.75;
    margin-bottom: 12px;
}

.tech-note {
    margin-top: 20px;
    padding: 14px 18px;
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--primary) !important;
}

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

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 18px;
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .nav-inner {
        padding: 0 16px;
    }

    .main {
        padding: 0 16px;
    }

    .hero {
        padding: 32px 0 24px;
    }

    .hero-title {
        font-size: 1.5rem;
    }

    .balancer-card {
        padding: 18px;
        border-radius: var(--radius-lg);
    }

    .input-wrapper {
        flex-direction: column;
    }

    .equation-input {
        font-size: 0.95rem;
        padding: 12px 14px;
    }

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

    .solution-panel .balanced-equation {
        font-size: 1rem;
    }

    .examples-grid {
        gap: 8px;
    }

    .example-chip {
        font-size: 0.78rem;
        padding: 7px 12px;
    }
}
