/* Calculator pages: the hub, each calculator page, and the calculator web
   components themselves. The components link this file inside their shadow
   roots, after their own <style>, so one stylesheet restyles all eight.

   Page rules are scoped to body.calc-page. Component rules are scoped with
   :where(.calculator), which adds no specificity: they replace each
   component's base styles (same selector, later in the cascade) but leave its
   modifiers alone (e.g. .result-card.loss keeps its colour).

   After changing this file, bump its ?v= in the <link> of every component
   (components/calculators and its de, es and fr folders) and on the English
   pages that link it, then run scripts/build-i18n.js for the localized pages. */

/* ---------- Page ---------- */

body.calc-page {
    --ink: #1d1d1f;
    --ink-soft: #424245;
    --muted: #6e6e73;
    --surface: #f5f5f7;
    --line: #e5e5ea;
    --lime: #A4FF00;
    --lime-deep: #4f7d00;

    background:
        radial-gradient(70% 520px at 50% 0, rgba(164, 255, 0, 0.2), rgba(164, 255, 0, 0) 72%),
        #fff;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.calc-page .calculator-header,
.calc-page .calculators-page > h1,
.calc-page .calculators-page > .subtitle {
    text-align: center;
}

.calc-page .calculator-header {
    max-width: 780px;
    margin: 0 auto;
    padding: 148px 24px 48px;
}

.calc-page .calculator-header h1,
.calc-page .calculators-page > h1 {
    font-family: 'Roboto', sans-serif;
    font-style: italic;
    font-weight: 900;
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    line-height: 1.02;
    letter-spacing: -0.025em;
    color: var(--ink);
    margin: 0;
    text-wrap: balance;
}

.calc-page .calculator-header p,
.calc-page .calculators-page > .subtitle {
    max-width: 40ch;
    margin: 18px auto 0;
    font-size: clamp(1.125rem, 1.6vw, 1.375rem);
    line-height: 1.45;
    color: var(--muted);
    text-wrap: pretty;
}

/* The calculator component sits in the glow under the header. */
.calc-page .calculator-header + * {
    display: block;
    padding: 0 20px;
}

/* Explanations below the calculator, set as an article. */
.calc-page .calculator-info {
    max-width: 720px;
    margin: 112px auto 0;
    padding: 0 24px 48px;
    background: none;
    border-radius: 0;
}

.calc-page .calculator-info h2 {
    font-family: 'Roboto', sans-serif;
    font-style: italic;
    font-weight: 900;
    font-size: clamp(1.75rem, 3.2vw, 2.375rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 64px 0 18px;
    text-wrap: balance;
}

.calc-page .calculator-info h2:first-child {
    margin-top: 0;
}

.calc-page .calculator-info h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
    margin: 32px 0 8px;
}

.calc-page .calculator-info p,
.calc-page .calculator-info li {
    font-size: 1.0625rem;
    line-height: 1.7;
    color: var(--ink-soft);
}

.calc-page .calculator-info p {
    margin: 0 0 16px;
}

.calc-page .calculator-info ul,
.calc-page .calculator-info ol {
    margin: 0 0 24px 1.25em;
}

.calc-page .calculator-info li {
    margin-bottom: 6px;
}

.calc-page .calculator-info a {
    color: var(--ink);
    text-decoration-color: var(--lime);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.calc-page .calculator-info strong {
    color: var(--ink);
}

/* ---------- Hub ---------- */

.calc-page .calculators-page {
    max-width: 1040px;
    margin: 0 auto;
    padding: 148px 24px 40px;
    text-align: left;
}

.calc-page .calculators-page > .subtitle {
    margin-bottom: 88px;
}

.calc-page .calc-category,
.calc-page .calc-category:first-of-type {
    font-size: 1.1875rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    color: var(--lime-deep);
    margin: 0 0 18px;
}

.calc-page .calc-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 72px;
}

.calc-page .calc-card {
    display: flex;
    flex-direction: column;
    padding: 36px;
    border-radius: 28px;
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.calc-page .calc-card:hover {
    transform: translateY(-4px);
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 28px 56px -28px rgba(30, 50, 0, 0.35);
}

.calc-page .calc-card:focus-visible {
    outline: 3px solid var(--lime-deep);
    outline-offset: 4px;
}

.calc-page .calc-card .calc-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: 28px;
    border-radius: 16px;
    background: linear-gradient(180deg, #c6ff60 0%, #a4ff00 55%, #8fd400 100%);
    box-shadow: 0 8px 20px -8px rgba(79, 125, 0, 0.6);
    color: var(--ink);
}

.calc-page .calc-card .calc-icon .ti {
    font-size: 28px;
}

.calc-page .calc-card h2 {
    font-family: 'Roboto', sans-serif;
    font-style: italic;
    font-weight: 900;
    font-size: 1.625rem;
    line-height: 1.1;
    letter-spacing: -0.015em;
    margin: 0 0 10px;
}

.calc-page .calc-card p {
    margin: 0;
    font-size: 1.0625rem;
    line-height: 1.5;
    color: var(--muted);
}

@media (max-width: 700px) {
    .calc-page .calculator-header,
    .calc-page .calculators-page {
        padding-top: 112px;
    }

    .calc-page .calculators-page > .subtitle {
        margin-bottom: 56px;
    }

    .calc-page .calc-grid {
        grid-template-columns: 1fr;
        margin-bottom: 48px;
    }

    .calc-page .calc-card {
        padding: 28px;
    }

    .calc-page .calculator-info {
        margin-top: 80px;
    }
}

/* ---------- Calculator components (inside their shadow roots) ---------- */

:where(.calculator) {
    --ink: #1d1d1f;
    --muted: #6e6e73;
    --surface: #f5f5f7;
    --line: #e5e5ea;
    --lime: #A4FF00;
    --lime-deep: #4f7d00;
    --error: #d70015;
}

.calculator {
    max-width: 640px;
    margin: 0 auto;
    padding: 44px;
    border-radius: 32px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 48px 96px -48px rgba(30, 50, 0, 0.4);
    color: var(--ink);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
}

:where(.calculator) .calc-title,
:where(.calculator) .calculator-title {
    font-style: italic;
    font-weight: 900;
    font-size: 1.875rem;
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0 0 8px;
}

:where(.calculator) .calc-subtitle,
:where(.calculator) .calculator-subtitle {
    font-size: 1.0625rem;
    line-height: 1.45;
    color: var(--muted);
    margin: 0 0 32px;
}

:where(.calculator) .input-group {
    margin-bottom: 22px;
}

:where(.calculator) label,
:where(.calculator) .input-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
}

:where(.calculator) input[type="number"],
:where(.calculator) .input-field,
:where(.calculator) select {
    width: 100%;
    height: 56px;
    padding: 0 18px;
    border: 2px solid transparent;
    border-radius: 16px;
    background-color: var(--surface);
    color: var(--ink);
    font-family: 'Roboto', sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

:where(.calculator) select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 46px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 18px center;
    background-size: 12px 8px;
    cursor: pointer;
}

:where(.calculator) input::placeholder {
    color: #a1a1a6;
    font-weight: 400;
}

:where(.calculator) input[type="number"]:hover,
:where(.calculator) .input-field:hover,
:where(.calculator) select:hover {
    background-color: #efeff2;
}

:where(.calculator) input[type="number"]:focus,
:where(.calculator) .input-field:focus,
:where(.calculator) select:focus {
    outline: none;
    border-color: #8fd400;
    background-color: #fff;
    box-shadow: 0 0 0 4px rgba(164, 255, 0, 0.35);
}

:where(.calculator) .input-error,
:where(.calculator) input[type="number"].input-error {
    border-color: var(--error);
    background-color: #fff;
}

:where(.calculator) .unit-label-weight {
    right: 18px;
    font-size: 0.9375rem;
    color: var(--muted);
}

/* Segmented control */
:where(.calculator) .toggle-group,
:where(.calculator) .unit-toggle {
    display: inline-flex;
    gap: 2px;
    width: fit-content;
    padding: 4px;
    border: 0;
    border-radius: 999px;
    background: #ececf0;
    overflow: visible;
}

:where(.calculator) .toggle-btn,
:where(.calculator) .unit-btn {
    padding: 9px 22px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-family: 'Roboto', sans-serif;
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

:where(.calculator) .toggle-btn:hover:not(.active),
:where(.calculator) .unit-btn:hover:not(.active) {
    background: transparent;
    color: var(--ink);
}

:where(.calculator) .toggle-btn.active,
:where(.calculator) .unit-btn.active {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 3px 10px rgba(0, 0, 0, 0.06);
}

/* Primary button: the site's lime call to action. */
:where(.calculator) .calc-btn,
:where(.calculator) .calculate-btn {
    width: 100%;
    height: 58px;
    margin-top: 10px;
    border: 0;
    border-radius: 999px;
    background: var(--lime);
    color: var(--ink);
    font-family: 'Roboto', sans-serif;
    font-size: 1.125rem;
    font-style: italic;
    font-weight: 900;
    letter-spacing: -0.005em;
    cursor: pointer;
    box-shadow: 0 14px 30px -16px rgba(79, 125, 0, 0.95);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

:where(.calculator) .calc-btn:hover,
:where(.calculator) .calculate-btn:hover {
    background: #b2ff26;
    transform: translateY(-1px);
    box-shadow: 0 18px 34px -16px rgba(79, 125, 0, 0.95);
}

:where(.calculator) .calc-btn:active,
:where(.calculator) .calculate-btn:active {
    transform: scale(0.99);
}

:where(.calculator) .calc-btn:focus-visible,
:where(.calculator) .calculate-btn:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 3px;
}

:where(.calculator) .error-msg {
    color: var(--error);
    font-size: 0.9375rem;
    font-weight: 500;
    margin-top: 12px;
}

/* Results */
:where(.calculator) .results {
    margin-top: 36px;
}

:where(.calculator) .results-divider {
    height: 1px;
    border: 0;
    background: var(--line);
    margin: 36px 0;
}

:where(.calculator) .results-header,
:where(.calculator) .results-title,
:where(.calculator) .section-title,
:where(.calculator) .pct-title,
:where(.calculator) .meal-table-title,
:where(.calculator) .breakdown-title {
    font-size: 1.1875rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-transform: none;
    color: var(--ink);
}

:where(.calculator) .result-card,
:where(.calculator) .composition-card,
:where(.calculator) .macro-card,
:where(.calculator) .summary-card,
:where(.calculator) .hero-stat,
:where(.calculator) .bmr-display {
    border: 0;
    border-radius: 20px;
    background: var(--surface);
    padding: 20px;
}

:where(.calculator) .result-card .result-label,
:where(.calculator) .result-label,
:where(.calculator) .result-card-label,
:where(.calculator) .composition-card-label,
:where(.calculator) .macro-card-label,
:where(.calculator) .summary-card .s-label,
:where(.calculator) .hero-stat-label,
:where(.calculator) .bmr-label,
:where(.calculator) .bmi-label,
:where(.calculator) .bf-label,
:where(.calculator) .protein-label,
:where(.calculator) .at-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

:where(.calculator) .result-card .result-value,
:where(.calculator) .result-value,
:where(.calculator) .result-card-value,
:where(.calculator) .composition-card-value,
:where(.calculator) .macro-card-grams,
:where(.calculator) .summary-card .s-value,
:where(.calculator) .hero-stat-value,
:where(.calculator) .bmr-value,
:where(.calculator) .goal-value,
:where(.calculator) .at-value {
    font-family: 'Roboto', sans-serif;
    font-style: italic;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--ink);
}

:where(.calculator) .result-card .result-value,
:where(.calculator) .summary-card .s-value,
:where(.calculator) .composition-card-value {
    font-size: 1.75rem;
}

/* The one number that matters most in each calculator. */
:where(.calculator) .bmi-value,
:where(.calculator) .bf-value,
:where(.calculator) .protein-value {
    font-family: 'Roboto', sans-serif;
    font-style: italic;
    font-weight: 900;
    font-size: clamp(3.25rem, 9vw, 4.5rem);
    line-height: 1;
    letter-spacing: -0.035em;
}

/* Dark highlight cards keep their lime number. */
:where(.calculator) .result-card.avg,
:where(.calculator) .hero-stat.primary {
    background: var(--ink);
    color: #fff;
}

:where(.calculator) .result-card.avg .result-value {
    color: var(--lime);
    font-size: clamp(2.25rem, 6vw, 3rem);
}

/* Tables */
:where(.calculator) table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--line);
}

:where(.calculator) table th,
:where(.calculator) .pct-table th {
    padding: 13px 16px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

:where(.calculator) table td,
:where(.calculator) .pct-table tr:nth-child(even) td,
:where(.calculator) .pct-table tr:nth-child(odd) td {
    padding: 13px 16px;
    background: #fff;
    color: var(--ink);
    font-size: 0.9875rem;
    border-bottom: 1px solid #f0f0f3;
}

:where(.calculator) table tr:last-child td {
    border-bottom: 0;
}

:where(.calculator) .pct-table tr:first-child td {
    background: rgba(164, 255, 0, 0.2);
    font-weight: 700;
}

@media (max-width: 768px) {
    .calculator {
        padding: 32px;
        border-radius: 28px;
    }
}

@media (max-width: 480px) {
    .calculator {
        padding: 24px 20px;
        border-radius: 24px;
    }

    :where(.calculator) .calc-title,
    :where(.calculator) .calculator-title {
        font-size: 1.5rem;
    }

    :where(.calculator) .toggle-btn,
    :where(.calculator) .unit-btn {
        padding: 8px 16px;
    }

    /* Plate totals stay side by side instead of stacking three tall cards. */
    :where(.calculator) .summary-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    :where(.calculator) .summary-card {
        padding: 14px 6px;
    }

    :where(.calculator) .summary-card .s-value {
        font-size: 1.25rem;
    }

    :where(.calculator) table th,
    :where(.calculator) table td,
    :where(.calculator) .pct-table tr:nth-child(even) td,
    :where(.calculator) .pct-table tr:nth-child(odd) td {
        padding: 11px 12px;
        font-size: 0.875rem;
    }
}
