.al-tool-shell--calcium-magnesium {
    --camg-ca: #2f7d62;
    --camg-ca-soft: #c9eadc;
    --camg-mg: #729c8d;
    --camg-ink: #112f28;
}

/* The calculator must remain usable when the optional reveal observer is
   delayed or skipped by a cached/direct route transition. */
.js .al-tools-app.al-tool-shell--calcium-magnesium .al-reveal {
    opacity: 1;
    transform: none;
}

.al-camg-card,
.al-camg-result,
.al-camg-guide,
.al-camg-related {
    min-width: 0;
}

.al-camg-mode-fieldset {
    min-width: 0;
    margin: 0 0 1.5rem;
    padding: 0;
    border: 0;
}

.al-tools-app.al-tool-shell .al-camg-mode {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    margin-top: 0.5rem;
    padding: 0.35rem;
    border: 1px solid var(--al-border, #dbe6e1);
    border-radius: 0.9rem;
    background: #f4f8f6;
}

.al-camg-mode label {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.55rem 0.7rem;
    border-radius: 0.65rem;
    color: #4c625b;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 750;
    line-height: 1.15;
    text-align: center;
}

.al-camg-mode label.is-active {
    color: #fff;
    background: var(--camg-ca);
    box-shadow: 0 0.25rem 0.75rem rgba(22, 75, 58, 0.16);
}

.al-camg-mode input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.al-camg-mode label:focus-within {
    outline: 3px solid rgba(47, 125, 98, 0.25);
    outline-offset: 2px;
}

.al-camg-fields {
    align-items: start;
}

.al-camg-input-unit,
.al-camg-input-suffix {
    display: grid;
    align-items: stretch;
}

.al-camg-input-unit {
    grid-template-columns: minmax(0, 1fr) minmax(8.8rem, auto);
}

.al-camg-input-unit .al-tool-input {
    border-radius: 0.75rem 0 0 0.75rem;
}

.al-camg-unit-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.al-camg-unit {
    min-width: 0;
    border-left: 0;
    border-radius: 0 0.75rem 0.75rem 0;
    font-size: 0.83rem;
    font-weight: 700;
}

.al-camg-input-suffix {
    position: relative;
}

.al-tool-shell--calcium-magnesium .al-camg-input-suffix .al-tool-input {
    padding-right: 4.75rem;
}

.al-tool-shell--calcium-magnesium input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.al-tool-shell--calcium-magnesium input[type="number"]::-webkit-inner-spin-button,
.al-tool-shell--calcium-magnesium input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.al-camg-input-suffix > span {
    position: absolute;
    top: 50%;
    right: 1rem;
    color: #60736d;
    font-size: 0.78rem;
    font-weight: 750;
    transform: translateY(-50%);
    pointer-events: none;
}

.al-camg-help,
.al-camg-report-note {
    margin: 0.55rem 0 0;
    color: #60736d;
    font-size: 0.8rem;
    line-height: 1.45;
}

.al-camg-report-note {
    padding: 0.75rem 0.9rem;
    border-left: 3px solid var(--camg-ca-soft);
    border-radius: 0 0.55rem 0.55rem 0;
    background: #f5faf7;
}

.al-camg-form-error {
    margin-top: 1rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid #d89a95;
    border-radius: 0.65rem;
    color: #7b2822;
    background: #fff4f3;
    font-size: 0.88rem;
    font-weight: 700;
}

.al-camg-result {
    display: grid;
    gap: 1.1rem;
}

.al-camg-result[hidden] {
    display: none;
}

.al-camg-result-head {
    padding: 0.2rem 0.1rem;
}

.al-camg-result-head p:last-child {
    margin: 0.45rem 0 0;
    color: #60736d;
}

.al-camg-primary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.al-camg-primary-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 8.2rem;
    padding: 1rem;
    border: 1px solid #dce7e2;
    border-radius: 0.9rem;
    background: #fff;
}

.al-camg-primary-card.is-calculated {
    border-color: #8dc9b3;
    background: linear-gradient(145deg, #f2fbf7, #fff);
    box-shadow: inset 0 3px 0 var(--camg-ca);
}

.al-camg-primary-card > span {
    color: #536a62;
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.02em;
}

.al-camg-primary-card strong {
    display: block;
    margin-top: auto;
    color: var(--camg-ink);
    font-size: clamp(1.65rem, 3vw, 2.3rem);
    line-height: 1;
    white-space: nowrap;
}

.al-camg-primary-card strong small {
    font-size: 0.72rem;
    font-weight: 750;
}

.al-camg-primary-card em {
    margin-top: 0.4rem;
    color: #60736d;
    font-size: 0.75rem;
    font-style: normal;
}

.al-camg-secondary-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
    gap: 0.85rem;
}

.al-camg-ratio-card,
.al-camg-breakdown {
    min-width: 0;
    padding: 1.1rem;
    border: 1px solid #dce7e2;
    border-radius: 0.9rem;
    background: #f9fbfa;
}

.al-camg-ratio-value {
    display: block;
    margin: 0.25rem 0 0.65rem;
    color: var(--camg-ink);
    font-size: clamp(1.65rem, 3vw, 2.2rem);
    line-height: 1.1;
}

.al-camg-ratio-card > p:not(.al-tool-eyebrow) {
    color: #50665f;
    font-size: 0.84rem;
    line-height: 1.5;
}

.al-camg-ratio-scale {
    margin-top: 1rem;
}

.al-camg-ratio-track {
    position: relative;
    height: 0.42rem;
    border-radius: 99px;
    background: linear-gradient(90deg, #a9c8bd, #d7e6e0 50%, #8caf9f);
}

.al-camg-ratio-track span {
    position: absolute;
    top: 50%;
    width: 0.9rem;
    height: 0.9rem;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--camg-ink);
    box-shadow: 0 1px 5px rgba(14, 44, 36, 0.28);
    transform: translate(-50%, -50%);
}

.al-camg-ratio-labels {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.45rem;
    color: #667a73;
    font-size: 0.66rem;
    line-height: 1.25;
}

.al-camg-ratio-labels span:last-child {
    text-align: right;
}

.al-camg-ratio-warning {
    margin-top: 0.8rem;
    padding: 0.7rem;
    border-radius: 0.55rem;
    background: #f1f5f3;
    font-weight: 700;
}

.al-camg-breakdown-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
}

.al-camg-breakdown-head h3 {
    margin: 0.2rem 0 0;
    color: var(--camg-ink);
    font-size: 1.05rem;
}

.al-camg-breakdown-head > span {
    max-width: 10rem;
    color: #647871;
    font-size: 0.67rem;
    line-height: 1.3;
    text-align: right;
}

.al-camg-stacked {
    display: flex;
    width: 100%;
    height: 1rem;
    margin: 1.1rem 0 0.85rem;
    overflow: hidden;
    border-radius: 99px;
    background: #e8efec;
}

.al-camg-stacked span {
    display: block;
    min-width: 0;
    transition: width 220ms ease;
}

.al-camg-stacked__ca {
    background: var(--camg-ca);
}

.al-camg-stacked__mg {
    background: var(--camg-mg);
}

.al-camg-contributions {
    display: grid;
    gap: 0.5rem;
    margin: 0;
}

.al-camg-contributions > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.al-camg-contributions dt,
.al-camg-contributions dd {
    margin: 0;
    font-size: 0.8rem;
}

.al-camg-contributions dt {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
}

.al-camg-contributions dd {
    white-space: nowrap;
}

.al-camg-contributions dd span {
    color: #647871;
}

.al-camg-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
}

.al-camg-dot--ca {
    background: var(--camg-ca);
}

.al-camg-dot--mg {
    background: var(--camg-mg);
}

.al-camg-calculation-intro {
    margin: 0 0 0.55rem;
    color: #4b625a;
    font-size: 0.84rem;
    line-height: 1.5;
}

.al-camg-calculation-steps {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.al-camg-calculation-steps li {
    display: grid;
    grid-template-columns: 1.65rem minmax(0, 1fr);
    gap: 0.65rem;
    align-items: start;
    padding: 0.72rem 0;
    border-bottom: 1px solid #e3ebe7;
}

.al-camg-calculation-steps li:last-child {
    border-bottom: 0;
}

.al-camg-calculation-step__number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.55rem;
    height: 1.55rem;
    border-radius: 50%;
    color: var(--camg-ca);
    background: #e9f5ef;
    font-size: 0.72rem;
    font-weight: 800;
}

.al-camg-calculation-step__copy,
.al-camg-calculation-step__copy strong,
.al-camg-calculation-step__copy code {
    display: block;
    min-width: 0;
}

.al-camg-calculation-step__copy strong {
    color: var(--camg-ink);
    font-size: 0.82rem;
    line-height: 1.25;
}

.al-camg-calculation-step__copy code,
.al-camg-guide code {
    color: var(--camg-ink);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.78rem;
    white-space: normal;
}

.al-camg-calculation-step__copy code {
    margin-top: 0.25rem;
    color: #687b74;
    font-size: 0.73rem;
    line-height: 1.35;
}

.al-camg-calculation-note {
    margin: 0.6rem 0 0;
    padding-top: 0.7rem;
    border-top: 1px solid #dfe8e4;
    color: #61756e;
    font-size: 0.74rem;
    line-height: 1.45;
}

.al-camg-guide,
.al-camg-related {
    margin-top: 1.5rem;
    padding: clamp(1.2rem, 3vw, 2rem);
    border: 1px solid #dce7e2;
    border-radius: 1rem;
    background: #fff;
}

.al-camg-guide {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.5rem;
}

.al-camg-guide > .al-tool-eyebrow,
.al-camg-guide > .al-tool-section__title {
    grid-column: 1 / -1;
}

.al-camg-guide article {
    min-width: 0;
    padding-top: 1rem;
    border-top: 1px solid #e4ece9;
}

.al-camg-guide article h3 {
    margin: 0 0 0.55rem;
    color: var(--camg-ink);
    font-size: 1.02rem;
    line-height: 1.3;
}

.al-camg-guide article p {
    margin: 0.4rem 0 0;
    color: #4c625b;
    font-size: 0.9rem;
    line-height: 1.65;
}

.al-camg-example {
    margin-top: 0.75rem;
    padding: 0.85rem;
    border-radius: 0.7rem;
    background: #f3f8f6;
}

.al-camg-related-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.al-camg-related-card {
    display: flex;
    flex-direction: column;
    min-height: 8rem;
    padding: 1rem;
    border: 1px solid #dce7e2;
    border-radius: 0.85rem;
    color: var(--camg-ink);
    background: #f8fbfa;
    text-decoration: none;
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.al-camg-related-card:hover,
.al-camg-related-card:focus-visible {
    border-color: #8fc4b1;
    box-shadow: 0 0.55rem 1.3rem rgba(28, 70, 57, 0.1);
    transform: translateY(-2px);
}

.al-camg-related-card span {
    color: #60736d;
    font-size: 0.75rem;
}

.al-camg-related-card strong {
    margin-top: 0.35rem;
}

.al-camg-related-card em {
    margin-top: auto;
    color: var(--camg-ca);
    font-size: 0.8rem;
    font-style: normal;
    font-weight: 750;
}

@media (max-width: 900px) {
    .al-camg-primary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .al-camg-primary-card:last-child {
        grid-column: 1 / -1;
    }

    .al-camg-secondary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .al-tools-app.al-tool-shell .al-camg-mode {
        gap: 0.2rem;
        padding: 0.25rem;
    }

    .al-camg-mode label {
        min-height: 3rem;
        padding: 0.45rem 0.3rem;
        font-size: 0.74rem;
    }

    .al-camg-input-unit {
        grid-template-columns: minmax(0, 1fr) minmax(7.3rem, 42%);
    }

    .al-camg-unit {
        padding-right: 1.65rem;
        font-size: 0.72rem;
    }

    .al-camg-primary-grid,
    .al-camg-guide,
    .al-camg-related-grid {
        grid-template-columns: 1fr;
    }

    .al-camg-primary-card:last-child,
    .al-camg-guide > .al-tool-eyebrow,
    .al-camg-guide > .al-tool-section__title {
        grid-column: auto;
    }

    .al-camg-primary-card {
        min-height: 6.8rem;
    }

    .al-camg-breakdown-head {
        display: block;
    }

    .al-camg-breakdown-head > span {
        display: block;
        max-width: none;
        margin-top: 0.4rem;
        text-align: left;
    }

    .al-camg-contributions > div {
        align-items: start;
    }

    .al-camg-contributions dd {
        text-align: right;
        white-space: normal;
    }
}

@media (prefers-reduced-motion: reduce) {
    .al-camg-stacked span,
    .al-camg-related-card {
        transition: none;
    }
}
