/* ============================================================================
 * Trilogy Mind Body Soul — Shared calculator shell
 * Used by the Body Fat, Ideal Weight, Macronutrient and Calorie calculators.
 * Same palette + concept as the BMI/BMR tools (form left, animated artifacts
 * right). Class prefix: .tri-calc__
 * ========================================================================== */

.tri-calc {
    --tri-orange: #ff4500;
    --tri-primary: #1c0e21;
    --tri-text: #5e5e5e;
    --tri-accent: #f5faff;
    --tri-line: rgba(28, 14, 33, 0.1);
    --tri-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --c-blue: #3b9ad6;
    --c-green: #2bb673;
    --c-amber: #f5a623;
    --c-red: #e63946;

    max-width: 980px;
    margin: 40px auto;
    padding: 0 16px;
    box-sizing: border-box;
    color: var(--tri-primary);
    font-family: "Inter", "DM Sans", system-ui, -apple-system, sans-serif;
}
.tri-calc *, .tri-calc *::before, .tri-calc *::after { box-sizing: border-box; }

.tri-calc__card {
    background: #fff;
    border: 1px solid var(--tri-line);
    border-radius: 22px;
    box-shadow: 0 24px 60px -28px rgba(28, 14, 33, 0.28);
    padding: clamp(24px, 4vw, 44px);
}

/* ---- Header ---- */
.tri-calc__eyebrow {
    display: inline-block;
    position: relative;
    color: var(--tri-orange);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    padding-bottom: 11px;
}
.tri-calc__eyebrow::before { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 3px; border-radius: 2px; background: var(--tri-orange); }
.tri-calc__title { margin: 16px 0 8px; font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.tri-calc__intro { margin: 0; color: var(--tri-text); line-height: 1.6; }

/* ---- Layout ---- */
.tri-calc__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 26px; align-items: stretch; margin-top: 26px; }
.tri-calc__field { margin-bottom: 16px; }
.tri-calc__label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.tri-calc__row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---- Segmented control ---- */
.tri-calc__seg {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    padding: 4px;
    background: var(--tri-accent);
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px var(--tri-line);
    -webkit-tap-highlight-color: transparent;
}
.tri-calc__thumb {
    position: absolute;
    top: 4px; bottom: 4px; left: 4px;
    width: calc(50% - 4px);
    border-radius: 999px;
    background: var(--tri-orange);
    box-shadow: 0 6px 16px -5px rgba(255, 69, 0, 0.55);
    transition: transform 0.34s var(--tri-ease);
    z-index: 0;
}
.tri-calc__seg.is-second .tri-calc__thumb { transform: translateX(100%); }
.tri-calc__opt {
    position: relative; z-index: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    cursor: pointer; border-radius: 999px; padding: 9px 8px;
    color: var(--tri-text); transition: color 0.25s ease;
}
.tri-calc__opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tri-calc__opt-name { font-weight: 700; font-size: 14px; line-height: 1.1; }
.tri-calc__opt-hint { font-size: 11px; font-weight: 500; opacity: 0.75; line-height: 1.1; }
.tri-calc__opt-icon { display: inline-flex; }
.tri-calc__opt-icon svg { width: 18px; height: 18px; }
.tri-calc__opt.is-active { color: #fff; }
.tri-calc__opt:not(.is-active):hover { color: var(--tri-primary); }

/* ---- Inputs ---- */
.tri-calc__inputs { display: flex; gap: 10px; }
.tri-calc__input-wrap { position: relative; flex: 1; }
.tri-calc__input-wrap input {
    width: 100%; height: 52px; padding: 0 46px 0 16px; font-size: 16px;
    color: var(--tri-primary); background: #fff; border: 1.5px solid var(--tri-line);
    border-radius: 12px; transition: border-color 0.2s ease, box-shadow 0.2s ease; -moz-appearance: textfield;
}
.tri-calc__input-wrap input::-webkit-outer-spin-button,
.tri-calc__input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tri-calc__input-wrap input:focus { outline: none; border-color: var(--tri-orange); box-shadow: 0 0 0 3px rgba(255, 69, 0, 0.15); }
.tri-calc__suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--tri-text); font-size: 14px; font-weight: 600; pointer-events: none; }

/* ---- Select ---- */
.tri-calc__select-wrap { position: relative; }
.tri-calc__select-wrap::after {
    content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px;
    border-right: 2px solid var(--tri-text); border-bottom: 2px solid var(--tri-text);
    transform: translateY(-65%) rotate(45deg); pointer-events: none;
}
.tri-calc__select {
    width: 100%; height: 52px; padding: 0 40px 0 16px; font-size: 15px;
    color: var(--tri-primary); background: #fff; border: 1.5px solid var(--tri-line);
    border-radius: 12px; appearance: none; -webkit-appearance: none; cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tri-calc__select:focus { outline: none; border-color: var(--tri-orange); box-shadow: 0 0 0 3px rgba(255, 69, 0, 0.15); }

/* ---- Button + error ---- */
.tri-calc__btn {
    margin-top: 8px; width: 100%; border: none; cursor: pointer;
    background: var(--tri-orange); color: #fff; font-size: 16px; font-weight: 700;
    padding: 15px 24px; border-radius: 80px; box-shadow: 0 12px 26px -8px rgba(255, 69, 0, 0.55);
    transition: transform 0.2s var(--tri-ease), box-shadow 0.2s var(--tri-ease);
}
.tri-calc__btn:hover { transform: translateY(-2px); box-shadow: 0 18px 34px -10px rgba(255, 69, 0, 0.65); }
.tri-calc__btn:active { transform: translateY(0); }
.tri-calc__error { margin: 14px 0 0; color: var(--c-red); font-size: 14px; font-weight: 600; }

/* ---- Result panel ---- */
.tri-calc__panel--result {
    background: linear-gradient(160deg, #ffffff 0%, var(--tri-accent) 100%);
    border: 1px solid var(--tri-line); border-radius: 18px; padding: 28px;
    display: flex; flex-direction: column; justify-content: center; min-height: 420px; text-align: center;
}
.tri-calc__empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; height: 100%; }
.tri-calc__empty-eyebrow, .tri-calc__result-label {
    font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--tri-text); opacity: 0.8;
}
.tri-calc__result-sub { margin: 6px 0 14px; font-size: 13.5px; line-height: 1.5; color: var(--tri-text); }
.tri-calc__empty-text { margin: 0; font-size: 14px; line-height: 1.6; color: var(--tri-text); max-width: 320px; }
.tri-calc__empty-text strong { color: var(--tri-primary); }

/* big score + badge */
.tri-calc__score { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 8px 0 4px; }
.tri-calc__score-value { font-size: clamp(2.4rem, 7vw, 3.4rem); font-weight: 800; line-height: 1; letter-spacing: -0.02em; color: var(--tri-primary); }
.tri-calc__score-unit { font-size: 15px; font-weight: 600; color: var(--tri-text); }
.tri-calc__empty-num { font-size: clamp(2.2rem, 6vw, 3rem); font-weight: 800; line-height: 1; letter-spacing: -0.02em; color: rgba(28, 14, 33, 0.18); animation: triCalcPulse 1.8s ease-in-out infinite; }
@keyframes triCalcPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.tri-calc__badge { display: inline-block; margin: 4px auto 0; padding: 7px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; color: #fff; background: var(--tri-text); }
.tri-calc__badge[data-tone="blue"] { background: var(--c-blue); }
.tri-calc__badge[data-tone="green"] { background: var(--c-green); }
.tri-calc__badge[data-tone="amber"] { background: var(--c-amber); }
.tri-calc__badge[data-tone="red"] { background: var(--c-red); }

/* ---- Circular gauge ---- */
.tri-calc__gauge { position: relative; width: 188px; max-width: 72%; aspect-ratio: 1 / 1; margin: 12px auto 8px; }
.tri-calc__ring { width: 100%; height: 100%; display: block; }
.tri-calc__ring-track { fill: none; stroke: rgba(28, 14, 33, 0.09); stroke-width: 13; }
.tri-calc__ring-arc {
    fill: none; stroke: var(--tri-orange); stroke-width: 13; stroke-linecap: round;
    stroke-dasharray: 540.354; stroke-dashoffset: 540.354;
    transform: rotate(-90deg); transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.9s var(--tri-ease);
}
.tri-calc__gauge--ghost .tri-calc__ring-track { stroke-dasharray: 4 9; opacity: 0.7; }
.tri-calc__gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tri-calc__gauge .tri-calc__score-value, .tri-calc__gauge .tri-calc__empty-num { font-size: clamp(1.9rem, 5.5vw, 2.4rem); }
.tri-calc__gauge .tri-calc__score-unit { font-size: 12px; }
.tri-calc__sexicon { display: inline-flex; margin-bottom: 4px; }
.tri-calc__sexicon svg { width: 24px; height: 24px; color: var(--tri-orange); }
.tri-calc__sexicon .i-female { display: none; }
[data-sex="female"] .i-male { display: none; }
[data-sex="female"] .i-female { display: inline; }

/* ---- Level/scenario bars ---- */
.tri-calc__levels { display: flex; flex-direction: column; gap: 10px; width: 100%; text-align: left; }
.tri-calc__levels--preview { opacity: 0.7; }
.tri-calc__level { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 12px; }
.tri-calc__level-name { font-size: 13px; font-weight: 600; color: var(--tri-primary); }
.tri-calc__level-track { height: 8px; border-radius: 999px; background: rgba(28, 14, 33, 0.08); overflow: hidden; }
.tri-calc__level-fill { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #ff8a4c, var(--tri-orange)); transition: width 0.7s var(--tri-ease); }
.tri-calc__levels--preview .tri-calc__level-fill { background: rgba(28, 14, 33, 0.16); transition: none; }
.tri-calc__level-val { font-size: 13px; font-weight: 700; color: var(--tri-text); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.tri-calc__level.is-selected .tri-calc__level-name,
.tri-calc__level.is-selected .tri-calc__level-val { color: var(--tri-orange); }
.tri-calc__level.is-selected .tri-calc__level-track { box-shadow: 0 0 0 2px rgba(255, 69, 0, 0.25); }

/* ---- Macro donut ---- */
.tri-calc__donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.tri-calc__donut {
    position: relative; width: 178px; height: 178px; border-radius: 50%;
    background: conic-gradient(var(--c-green) 0 0); /* JS overrides */
    transition: background 0.7s var(--tri-ease);
}
.tri-calc__donut::after {
    content: ""; position: absolute; inset: 26px; border-radius: 50%; background: #fff;
    box-shadow: inset 0 1px 6px rgba(28, 14, 33, 0.08);
}
.tri-calc__donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1; }
.tri-calc__donut-center .num { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.tri-calc__donut-center .lbl { font-size: 11px; font-weight: 600; color: var(--tri-text); letter-spacing: 0.06em; text-transform: uppercase; }
.tri-calc__macros { display: flex; flex-direction: column; gap: 10px; width: 100%; text-align: left; }
.tri-calc__macro { display: grid; grid-template-columns: 14px 1fr auto auto; align-items: center; gap: 10px; }
.tri-calc__macro-dot { width: 12px; height: 12px; border-radius: 50%; }
.tri-calc__macro-name { font-size: 13px; font-weight: 600; }
.tri-calc__macro-pct { font-size: 12px; color: var(--tri-text); }
.tri-calc__macro-g { font-size: 14px; font-weight: 700; min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Semicircle gauge (Body Fat) ---- */
.tri-calc__semi { position: relative; width: 240px; max-width: 88%; margin: 8px auto 4px; }
.tri-calc__semi svg { width: 100%; display: block; }
.tri-calc__semi-track { fill: none; stroke: rgba(28, 14, 33, 0.09); stroke-width: 16; stroke-linecap: round; }
.tri-calc__semi-arc {
    fill: none; stroke: var(--tri-orange); stroke-width: 16; stroke-linecap: round;
    stroke-dasharray: 270.18; stroke-dashoffset: 270.18;
    transition: stroke-dashoffset 0.9s var(--tri-ease);
}
.tri-calc__semi-center { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; }
.tri-calc__semi-center .tri-calc__sexicon { margin-bottom: 0; }
.tri-calc__semi-center .num { font-size: clamp(2rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.tri-calc__semi-center .num.is-ghost { color: rgba(28, 14, 33, 0.18); animation: triCalcPulse 1.8s ease-in-out infinite; }
.tri-calc__semi-center .unit { font-size: 12px; font-weight: 600; color: var(--tri-text); }

/* ---- Stacked composition bar (TDEE) ---- */
.tri-calc__stack { display: flex; width: 100%; height: 26px; border-radius: 999px; overflow: hidden; background: rgba(28, 14, 33, 0.07); margin: 6px 0 14px; }
.tri-calc__stack-seg { height: 100%; width: 0; transition: width 0.8s var(--tri-ease); }
.tri-calc__stack-seg.s-bmr { background: linear-gradient(90deg, #ffb088, var(--tri-orange)); }
.tri-calc__stack-seg.s-act { background: var(--c-blue); }
.tri-calc__stack-key { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.tri-calc__stack-key span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--tri-text); font-weight: 600; }
.tri-calc__stack-key i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---- Vertical columns (Protein, per meal) ---- */
.tri-calc__cols { display: flex; align-items: flex-end; justify-content: center; gap: 14px; height: 168px; margin: 14px 0 6px; }
.tri-calc__col { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; max-width: 64px; height: 100%; justify-content: flex-end; }
.tri-calc__col-val { font-size: 13px; font-weight: 700; color: var(--tri-primary); }
.tri-calc__col-bar { width: 100%; border-radius: 10px 10px 4px 4px; background: linear-gradient(180deg, var(--tri-orange), #ff8a4c); height: 0; transition: height 0.8s var(--tri-ease); min-height: 4px; }
.tri-calc__col--ghost .tri-calc__col-bar { background: rgba(28, 14, 33, 0.14); transition: none; }
.tri-calc__col-lbl { font-size: 11px; color: var(--tri-text); font-weight: 600; }

/* ---- Range band (Ideal Weight) ---- */
.tri-calc__band-wrap { margin: 18px 0 8px; }
.tri-calc__band { position: relative; height: 14px; border-radius: 999px; background: rgba(28, 14, 33, 0.08); }
.tri-calc__band-fill { position: absolute; top: 0; bottom: 0; left: 30%; width: 40%; border-radius: 999px; background: linear-gradient(90deg, #ff8a4c, var(--tri-orange)); transition: left 0.8s var(--tri-ease), width 0.8s var(--tri-ease); }
.tri-calc__band-scale { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--tri-text); }

/* ---- Split bar (Daily Carb: % of calories) ---- */
.tri-calc__split { position: relative; width: 100%; height: 34px; border-radius: 12px; overflow: hidden; background: rgba(28, 14, 33, 0.07); margin: 10px 0 6px; display: flex; }
.tri-calc__split-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ff8a4c, var(--tri-orange)); display: flex; align-items: center; justify-content: flex-end; padding-right: 10px; color: #fff; font-weight: 700; font-size: 12px; transition: width 0.8s var(--tri-ease); white-space: nowrap; }
.tri-calc__split-rest { flex: 1; display: flex; align-items: center; padding-left: 10px; color: var(--tri-text); font-size: 12px; font-weight: 600; }
.tri-calc__chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.tri-calc__chip { padding: 8px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--tri-line); font-size: 13px; font-weight: 600; color: var(--tri-text); }
.tri-calc__chip.is-selected { background: rgba(255, 69, 0, 0.1); border-color: rgba(255, 69, 0, 0.4); color: var(--tri-orange); }
.tri-calc__chip strong { color: var(--tri-primary); }
.tri-calc__chip.is-selected strong { color: var(--tri-orange); }

/* result fade-in */
.tri-calc__result { animation: triCalcFade 0.45s var(--tri-ease) both; }
@keyframes triCalcFade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.tri-calc__disclaimer { margin: 26px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--tri-text); }

/* ---- Responsive ---- */
@media (max-width: 760px) {
    .tri-calc__grid { grid-template-columns: 1fr; }
    .tri-calc__panel--result { min-height: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .tri-calc__btn, .tri-calc__thumb, .tri-calc__empty-num, .tri-calc__level-fill,
    .tri-calc__ring-arc, .tri-calc__donut, .tri-calc__result,
    .tri-calc__semi-arc, .tri-calc__stack-seg, .tri-calc__col-bar,
    .tri-calc__band-fill, .tri-calc__split-fill {
        transition: none !important; animation: none !important;
    }
}
