:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;

    --background: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;

    --text: #172033;
    --muted: #667085;

    --border: #d9dee8;

    --success-bg: #ecfdf3;
    --success-border: #a7f3d0;

    --error: #dc2626;

    --radius: 14px;

    --shadow:
        0 8px 30px rgba(15, 23, 42, 0.07);
}


/* =========================================================
   RESET
   ========================================================= */

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;

    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background: var(--background);
    color: var(--text);

    line-height: 1.5;

    -webkit-text-size-adjust: 100%;
}

button,
input,
select {
    font: inherit;
}


/* =========================================================
   ACCESSIBILITY / FOCUS
   ========================================================= */

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: 2px;
}


/* =========================================================
   LAYOUT
   ========================================================= */

.container {
    width: min(1100px, calc(100% - 32px));
    margin-inline: auto;
}


/* =========================================================
   HEADER
   ========================================================= */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    min-height: 82px;

    display: flex;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;

    gap: 14px;
}

.brand-icon {
    width: 48px;
    height: 48px;

    display: grid;
    place-items: center;

    background: #eff6ff;
    color: var(--primary);

    border-radius: 12px;

    font-size: 25px;

    flex-shrink: 0;
}

.brand h1 {
    margin: 0;

    font-size: 22px;
    line-height: 1.2;
}

.brand p {
    margin: 3px 0 0;

    color: var(--muted);

    font-size: 13px;
}


/* =========================================================
   HERO
   ========================================================= */

.hero {
    padding: 34px 0 20px;
}

.hero h2 {
    margin: 0 0 5px;

    font-size: clamp(24px, 4vw, 32px);

    line-height: 1.2;
}

.hero p {
    margin: 0;

    color: var(--muted);
}


/* =========================================================
   TABS
   ========================================================= */

.calculator-tabs {
    display: flex;

    gap: 8px;

    overflow-x: auto;

    padding: 8px 0 18px;

    scrollbar-width: thin;

    -webkit-overflow-scrolling: touch;
}

.calculator-tabs::-webkit-scrollbar {
    height: 5px;
}

.calculator-tabs::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

.tab {
    flex: 0 0 auto;

    min-height: 44px;

    border: 1px solid var(--border);

    background: var(--surface);

    color: var(--muted);

    padding: 10px 16px;

    border-radius: 10px;

    cursor: pointer;

    font-weight: 650;

    white-space: nowrap;

    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        transform 0.15s ease;
}

.tab:hover {
    border-color: var(--primary);

    color: var(--primary);
}

.tab:active {
    transform: translateY(1px);
}

.tab.active {
    background: var(--primary);

    color: #ffffff;

    border-color: var(--primary);
}

.tab.active:hover {
    background: var(--primary-dark);

    border-color: var(--primary-dark);

    color: #ffffff;
}


/* =========================================================
   CALCULATOR PANEL
   ========================================================= */

.calculator-panel {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    box-shadow: var(--shadow);

    padding: 24px;

    margin-bottom: 24px;
}

.hidden {
    display: none !important;
}


/* =========================================================
   PANEL HEADER
   ========================================================= */

.panel-header {
    display: flex;
    align-items: flex-start;

    gap: 13px;

    margin-bottom: 22px;
}

.panel-icon {
    width: 44px;
    height: 44px;

    display: grid;
    place-items: center;

    background: #eff6ff;

    border-radius: 11px;

    font-size: 21px;

    flex-shrink: 0;
}

.panel-header h2 {
    margin: 0;

    font-size: 20px;

    line-height: 1.3;
}

.panel-header p {
    margin: 3px 0 0;

    color: var(--muted);

    font-size: 14px;
}


/* =========================================================
   CALCULATOR GRID
   ========================================================= */

.calculator-grid {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        minmax(280px, 0.8fr);

    gap: 20px;

    align-items: stretch;
}


/* =========================================================
   INPUT CARD
   ========================================================= */

.input-card {
    background: var(--surface-soft);

    border: 1px solid var(--border);

    border-radius: 12px;

    padding: 20px;

    min-width: 0;
}


/* =========================================================
   FORMS
   ========================================================= */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;

    margin-bottom: 6px;

    font-size: 13px;

    font-weight: 700;

    line-height: 1.35;
}

.form-group input,
.form-group select {
    width: 100%;

    min-height: 46px;

    padding: 10px 12px;

    border: 1px solid var(--border);

    border-radius: 9px;

    background: #ffffff;

    color: var(--text);

    outline: none;

    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        background 0.15s ease;
}

.form-group input:hover,
.form-group select:hover {
    border-color: #b8c1d1;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-group input::placeholder {
    color: #98a2b3;
}


/* =========================================================
   NUMBER INPUT
   ========================================================= */

.form-group input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.form-group input[type="number"]::-webkit-inner-spin-button,
.form-group input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
}


/* =========================================================
   INPUT + UNIT
   Used by Molarity calculator
   ========================================================= */

.input-with-unit {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        100px;

    gap: 8px;

    align-items: stretch;
}

.input-with-unit input,
.input-with-unit select {
    min-width: 0;
}


/* =========================================================
   HIDDEN INPUT GROUPS
   ========================================================= */

.molarity-input-group[hidden] {
    display: none !important;
}


/* =========================================================
   BUTTONS
   ========================================================= */

.button-row {
    display: flex;

    gap: 9px;

    flex-wrap: wrap;

    margin-top: 4px;
}

.btn {
    min-height: 44px;

    border-radius: 9px;

    padding: 10px 17px;

    cursor: pointer;

    font-weight: 700;

    border: 1px solid transparent;

    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        transform 0.15s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--primary);

    color: #ffffff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #ffffff;

    color: var(--text);

    border-color: var(--border);
}

.btn-secondary:hover {
    border-color: var(--primary);

    color: var(--primary);
}


/* =========================================================
   RESULT CARD
   ========================================================= */

.result-card {
    min-height: 100%;

    display: flex;

    flex-direction: column;

    justify-content: center;

    background: var(--success-bg);

    border: 1px solid var(--success-border);

    border-radius: 12px;

    padding: 24px;

    min-width: 0;
}

.result-label {
    color: var(--muted);

    font-size: 13px;

    font-weight: 700;

    text-transform: uppercase;

    letter-spacing: 0.04em;
}

.result-value {
    margin-top: 7px;

    font-size: clamp(26px, 5vw, 38px);

    line-height: 1.2;

    font-weight: 800;

    overflow-wrap: anywhere;

    word-break: break-word;
}

.result-note {
    margin: 12px 0 0;

    color: var(--muted);

    font-size: 13px;

    line-height: 1.55;

    overflow-wrap: anywhere;
}


/* =========================================================
   ERROR
   ========================================================= */

.error-message {
    min-height: 20px;

    margin: 10px 0 0;

    color: var(--error);

    font-size: 13px;

    font-weight: 600;

    line-height: 1.45;

    overflow-wrap: anywhere;
}


/* =========================================================
   MOLECULAR FORMULA EXAMPLES
   ========================================================= */

.formula-examples {
    display: flex;

    align-items: center;

    flex-wrap: wrap;

    gap: 7px;

    margin-top: -6px;

    margin-bottom: 18px;

    color: var(--muted);

    font-size: 13px;
}

.formula-examples > span {
    flex: 0 0 auto;
}

.formula-example {
    min-height: 32px;

    border: 1px solid var(--border);

    background: #ffffff;

    color: var(--text);

    border-radius: 7px;

    padding: 5px 9px;

    cursor: pointer;

    font-size: 13px;

    transition:
        border-color 0.15s ease,
        color 0.15s ease,
        background 0.15s ease;
}

.formula-example:hover {
    border-color: var(--primary);

    color: var(--primary);

    background: #f8fbff;
}


/* =========================================================
   MOLECULAR COMPOSITION
   ========================================================= */

.composition {
    width: 100%;

    margin-top: 18px;

    border-top: 1px solid var(--border);

    padding-top: 14px;

    font-size: 14px;
}

.composition-row {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        minmax(80px, 1fr);

    gap: 10px;

    padding: 7px 0;

    border-bottom: 1px solid #edf0f4;
}

.composition-row:last-child {
    border-bottom: 0;
}

.composition-element {
    font-weight: 700;
}

.composition-count {
    color: var(--muted);

    text-align: right;

    overflow-wrap: anywhere;
}


/* =========================================================
   FOOTER
   ========================================================= */

.site-footer {
    padding: 28px 0 40px;

    color: var(--muted);

    font-size: 13px;

    text-align: center;
}


/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 800px) {

    .calculator-grid {
        grid-template-columns: 1fr;
    }

    .result-card {
        min-height: 180px;
    }
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 600px) {

    .container {
        width: min(
            100% - 20px,
            1100px
        );
    }


    /* Header */

    .header-inner {
        min-height: 70px;
    }

    .brand {
        gap: 11px;
    }

    .brand-icon {
        width: 42px;
        height: 42px;

        font-size: 22px;
    }

    .brand h1 {
        font-size: 19px;
    }

    .brand p {
        font-size: 12px;
    }


    /* Hero */

    .hero {
        padding-top: 24px;
    }

    .hero h2 {
        font-size: 25px;
    }


    /* Tabs */

    .calculator-tabs {
        padding-bottom: 14px;
    }

    .tab {
        padding: 9px 13px;

        font-size: 13px;
    }


    /* Panel */

    .calculator-panel {
        padding: 16px;

        margin-bottom: 18px;
    }

    .panel-header {
        gap: 10px;

        margin-bottom: 18px;
    }

    .panel-icon {
        width: 40px;
        height: 40px;

        font-size: 19px;
    }

    .panel-header h2 {
        font-size: 18px;
    }

    .panel-header p {
        font-size: 13px;
    }


    /* Cards */

    .input-card,
    .result-card {
        padding: 17px;
    }


    /* Input + Unit */

    .input-with-unit {
        grid-template-columns:
            minmax(0, 1fr)
            90px;

        gap: 7px;
    }


    /* Buttons */

    .button-row {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }


    /* Result */

    .result-card {
        min-height: 160px;
    }

    .result-value {
        font-size: 30px;
    }


    /* Formula examples */

    .formula-examples {
        gap: 6px;
    }

    .formula-example {
        padding: 5px 8px;
    }


    /* Composition */

    .composition-row {
        grid-template-columns:
            1fr
            auto;
    }
}


/* =========================================================
   VERY SMALL MOBILE
   ========================================================= */

@media (max-width: 380px) {

    .container {
        width: calc(100% - 16px);
    }

    .calculator-panel {
        padding: 13px;
    }

    .input-card,
    .result-card {
        padding: 14px;
    }

    .input-with-unit {
        grid-template-columns:
            minmax(0, 1fr)
            78px;
    }

    .form-group input,
    .form-group select {
        min-height: 44px;

        padding-inline: 10px;
    }

    .result-value {
        font-size: 27px;
    }
}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* =========================================
   Normality Calculator
   ========================================= */

.normality-input-group[hidden] {
    display: none !important;
}