﻿/* =============================================================================
   TDEE Calculator -- Design System (Clean Clinical)
   Single CSS file. No build step. System fonts only. Mobile-first.
   ----------------------------------------------------------------------------
   Sections:
     1. Tokens (custom properties)
     2. Reset
     3. Base typography & elements
     4. Layout primitives
     5. Utilities
     6. Components
        6.1  Skip link
        6.2  Site header + brand
        6.3  Site nav
        6.4  Hero
        6.5  Calculator form
        6.6  Result card
        6.7  Power Mode
        6.8  FAQ
        6.9  Buttons / CTA
        6.10 Site footer
        6.11 Mobile sticky result chip
     7. Responsive
     8. Print
     9. Reduced motion / accessibility
============================================================================= */

/* ====== 1. TOKENS ========================================================= */

:root {
  /* Color -- ink scale */
  --ink-50:  #f8fafc;
  --ink-100: #f1f5f9;
  --ink-200: #e2e8f0;
  --ink-300: #cbd5e1;
  --ink-400: #94a3b8;
  --ink-500: #64748b;
  --ink-600: #475569;
  --ink-700: #334155;
  --ink-800: #1e293b;
  --ink-900: #0f172a;
  --white:   #ffffff;

  /* Color -- teal accent */
  --teal-50:  #f0fdfa;
  --teal-100: #ccfbf1;
  --teal-300: #5eead4;
  --teal-500: #14b8a6;
  --teal-600: #0d9488;   /* primary accent */
  --teal-700: #0f766e;   /* hover */
  --teal-800: #115e59;

  /* Semantic colors */
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    var(--teal-600);

  /* Surfaces */
  --surface-page:    var(--white);
  --surface-raised:  var(--white);
  --surface-sunken:  var(--ink-50);
  --surface-invert:  var(--ink-900);

  /* Text */
  --text-strong:   var(--ink-900);
  --text-default:  var(--ink-800);
  --text-muted:    var(--ink-600);
  --text-subtle:   var(--ink-500);
  --text-faint:    var(--ink-400);
  --text-invert:   var(--white);

  /* Borders */
  --border-subtle:  var(--ink-200);
  --border-default: var(--ink-300);
  --border-strong:  var(--ink-400);

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --fs-11: 0.6875rem;
  --fs-12: 0.75rem;
  --fs-13: 0.8125rem;
  --fs-14: 0.875rem;
  --fs-15: 0.9375rem;
  --fs-16: 1rem;
  --fs-18: 1.125rem;
  --fs-20: 1.25rem;
  --fs-24: 1.5rem;
  --fs-28: 1.75rem;
  --fs-32: 2rem;
  --fs-40: 2.5rem;
  --fs-48: 3rem;
  --fs-56: 3.5rem;

  --lh-tight:  1.15;
  --lh-snug:   1.3;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;

  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;

  --tracking-tight: -0.02em;
  --tracking-snug:  -0.01em;
  --tracking-normal: 0;
  --tracking-wide:  0.02em;
  --tracking-wider: 0.06em;
  --tracking-widest: 0.12em;

  /* Spacing -- 4px base scale */
  --s-1:  0.25rem;   /*  4px */
  --s-2:  0.5rem;    /*  8px */
  --s-3:  0.75rem;   /* 12px */
  --s-4:  1rem;      /* 16px */
  --s-5:  1.25rem;   /* 20px */
  --s-6:  1.5rem;    /* 24px */
  --s-8:  2rem;      /* 32px */
  --s-10: 2.5rem;    /* 40px */
  --s-12: 3rem;      /* 48px */
  --s-16: 4rem;      /* 64px */
  --s-20: 5rem;      /* 80px */
  --s-24: 6rem;      /* 96px */

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
  --shadow-focus: 0 0 0 3px rgba(13, 148, 136, 0.35);

  /* Motion */
  --motion-fast:    120ms cubic-bezier(0.4, 0, 0.2, 1);
  --motion-normal:  200ms cubic-bezier(0.4, 0, 0.2, 1);
  --motion-slow:    320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --container-narrow: 720px;
  --container-default: 1100px;
  --container-wide:   1320px;
  --gutter: var(--s-5);

  /* Z-index */
  --z-skip-link: 100;
  --z-sticky:    50;
  --z-overlay:   200;
  --z-modal:     300;
  --z-toast:     400;
}

/* ====== 2. RESET ========================================================= */

*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: var(--lh-normal);
  color: var(--text-default);
  background: var(--surface-page);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video, canvas, picture { display: block; max-width: 100%; }
img { height: auto; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { background: transparent; border: 0; cursor: pointer; padding: 0; }

a {
  color: var(--teal-700);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--motion-fast);
}
a:hover { color: var(--teal-800); }
a:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--r-sm);
}

ul, ol { padding-left: 0; }
li { list-style: none; }

table { border-collapse: collapse; border-spacing: 0; }

hr { border: 0; border-top: 1px solid var(--border-subtle); margin: var(--s-8) 0; }

/* ====== 3. BASE TYPOGRAPHY =============================================== */

h1, h2, h3, h4, h5, h6 {
  color: var(--text-strong);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}

h1 { font-size: clamp(1.875rem, 2.5vw + 1rem, 2.5rem); }
h2 { font-size: clamp(1.5rem, 1.5vw + 0.875rem, 2rem); letter-spacing: var(--tracking-snug); }
h3 { font-size: var(--fs-20); letter-spacing: var(--tracking-snug); }
h4 { font-size: var(--fs-18); }
h5 { font-size: var(--fs-16); }
h6 { font-size: var(--fs-14); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--text-muted); }

p { line-height: var(--lh-relaxed); }
p + p, p + ul, p + ol, ul + p, ol + p { margin-top: var(--s-4); }

strong, b { font-weight: var(--fw-semibold); }

code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

pre {
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-4);
  overflow-x: auto;
  font-size: var(--fs-13);
  line-height: var(--lh-normal);
}

code:not(pre code) {
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  padding: 0.1em 0.4em;
  border-radius: var(--r-sm);
}

::selection {
  background: var(--teal-100);
  color: var(--teal-800);
}

/* ====== 4. LAYOUT PRIMITIVES ============================================ */

.container {
  width: 100%;
  max-width: var(--container-default);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

.container--narrow { max-width: var(--container-narrow); }
.container--wide   { max-width: var(--container-wide); }

.stack > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.stack-lg > * + * { margin-top: var(--s-6); }

/* ====== 5. UTILITIES ===================================================== */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.text-muted   { color: var(--text-muted); }
.text-subtle  { color: var(--text-subtle); }
.text-strong  { color: var(--text-strong); }
.text-center  { text-align: center; }
.text-balance { text-wrap: balance; }
.tabular      { font-variant-numeric: tabular-nums; }

/* ====== 6.1  SKIP LINK =================================================== */

.skip-link {
  position: absolute;
  left: var(--s-2);
  top: -100px;
  z-index: var(--z-skip-link);
  padding: var(--s-2) var(--s-5);
  background: var(--ink-900);
  color: var(--white);
  text-decoration: none;
  border-radius: var(--r-md);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wide);
  transition: top var(--motion-fast);
  outline: none;
}
.skip-link:focus {
  top: var(--s-2);
  color: var(--white);
  box-shadow: 0 0 0 3px var(--teal-300);
}

/* ====== 6.2  SITE HEADER + BRAND ========================================= */

.site-header {
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-6);
  min-height: 54px;
}

/* Brand lockup */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-strong);
  text-decoration: none;
  font-weight: var(--fw-bold);
  font-size: var(--fs-15);
  transition: opacity var(--motion-fast);
}
.brand:hover { color: var(--text-strong); opacity: 0.82; }
.brand:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--r-sm);
}

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--teal-600);
  color: var(--white);
  font-weight: var(--fw-bold);
  font-size: var(--fs-13);
  letter-spacing: 0;
  /* Hairline inset highlight for depth */
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 1px 3px rgba(13,148,136,0.30);
  flex-shrink: 0;
}

.brand__name {
  letter-spacing: -0.015em;
}


/* -- 6.2 responsive overrides ----------------------------------------- */

/* Safe-area insets: header respects iOS notch */
.site-header {
  padding-top: env(safe-area-inset-top);
}
.site-header__inner {
  padding-left: max(var(--s-4), env(safe-area-inset-left));
  padding-right: max(var(--s-4), env(safe-area-inset-right));
}

/* Compact header on small phones */
@media (max-width: 540px) {
  .site-header__inner {
    min-height: 48px;
    gap: var(--s-3);
  }
}

/* Touch: ensure brand hit area meets 44x44 */
@media (hover: none) and (pointer: coarse) {
  .brand {
    padding-block: 10px;
  }
}
/* ====== 6.3  SITE NAV ==================================================== */

.site-nav__list {
  display: flex;
  gap: var(--s-1);
  align-items: center;
}

.site-nav__link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  position: relative;
  transition: color var(--motion-fast), background var(--motion-fast);
}
.site-nav__link:hover {
  color: var(--text-strong);
  background: var(--ink-100);
}
.site-nav__link:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.site-nav__link.is-current {
  color: var(--teal-700);
  font-weight: var(--fw-semibold);
}
/* Active: small dot under the current link */
.site-nav__link.is-current::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 4px; height: 4px;
  background: var(--teal-600);
  border-radius: var(--r-pill);
  transform: translateX(-50%);
}


/* -- 6.3 responsive overrides ----------------------------------------- */

/* Toggle button + backdrop are desktop-hidden; revealed at mobile widths. */
.site-nav__toggle {
  display: none;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  min-height: 44px;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-strong);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--motion-fast), border-color var(--motion-fast);
}
.site-nav__toggle:hover {
  background: var(--ink-100);
  border-color: var(--ink-300);
}
.site-nav__toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.site-nav__toggle-bars,
.site-nav__toggle-bars::before,
.site-nav__toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform var(--motion-fast), opacity var(--motion-fast);
}
.site-nav__toggle-bars {
  position: relative;
}
.site-nav__toggle-bars::before,
.site-nav__toggle-bars::after {
  content: '';
  position: absolute;
  left: 0;
}
.site-nav__toggle-bars::before { top: -6px; }
.site-nav__toggle-bars::after  { top:  6px; }

.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-bars {
  background: transparent;
}
.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}
.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

.site-nav__backdrop {
  display: none;
}

/* Mobile: hamburger drawer (replaces inline list) */
@media (max-width: 640px) {
  .site-nav {
    position: static;
  }
  .site-nav__toggle {
    display: inline-flex;
  }

  .site-nav__list {
    position: fixed;
    top: 54px;
    right: 0;
    left: 0;
    z-index: var(--z-sticky);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--s-3) max(var(--s-4), env(safe-area-inset-right))
             calc(var(--s-4) + env(safe-area-inset-bottom, 0px))
             max(var(--s-4), env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.98);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    max-height: calc(100dvh - 54px);
    overflow-y: auto;
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: transform var(--motion-fast), opacity var(--motion-fast), visibility 0s linear var(--motion-fast);
  }
  /* When the toggle is open, sibling list becomes visible */
  .site-nav__toggle[aria-expanded="true"] ~ .site-nav__list {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    transition: transform var(--motion-fast), opacity var(--motion-fast), visibility 0s linear 0s;
  }

  .site-nav__item {
    border-bottom: 1px solid var(--border-subtle);
  }
  .site-nav__item:last-child {
    border-bottom: 0;
  }

  .site-nav__link {
    display: flex;
    align-items: center;
    padding: var(--s-3) var(--s-2);
    min-height: 48px;
    font-size: var(--fs-15);
    border-radius: 0;
  }
  /* Reposition the "current" dot from below-baseline to inline-left in drawer mode */
  .site-nav__link.is-current::after {
    left: var(--s-1);
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
  }
  .site-nav__link.is-current {
    padding-left: var(--s-4);
  }

  /* Backdrop: dim the page when drawer open. Activated by JS via .is-open. */
  .site-nav__backdrop {
    display: block;
    position: fixed;
    inset: 54px 0 0 0;
    z-index: calc(var(--z-sticky) - 1);
    background: rgba(15, 23, 42, 0.32);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--motion-fast), visibility 0s linear var(--motion-fast);
  }
  .site-nav__backdrop.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--motion-fast), visibility 0s linear 0s;
  }

  /* When drawer is open, lock body scroll via this class (set by JS). */
  :root.nav-open,
  :root.nav-open body {
    overflow: hidden;
  }
}

/* Tighten drawer top offset when compact header kicks in */
@media (max-width: 540px) {
  .site-nav__list {
    top: 48px;
    max-height: calc(100dvh - 48px);
  }
  .site-nav__backdrop {
    inset: 48px 0 0 0;
  }
}

/* Touch: enlarge nav link tap targets (desktop/horizontal nav) */
@media (hover: none) and (pointer: coarse) and (min-width: 641px) {
  .site-nav__link {
    padding: var(--s-2) var(--s-3);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* Reduced-motion: skip the slide-in/fade */
@media (prefers-reduced-motion: reduce) {
  .site-nav__list,
  .site-nav__backdrop,
  .site-nav__toggle-bars,
  .site-nav__toggle-bars::before,
  .site-nav__toggle-bars::after {
    transition: none !important;
  }
}
/* ====== 6.4  HERO ======================================================== */

.hero {
  padding-block: var(--s-10) var(--s-6);
}

/* Eyebrow: pill badge instead of plain uppercase */
.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--teal-700);
  margin-bottom: var(--s-3);
  background: var(--teal-100);
  padding: 3px var(--s-3);
  border-radius: var(--r-pill);
}
/* No leading dot -- the existing mid-dot in the text already separates segments */

.hero__title {
  font-size: clamp(1.875rem, 3.5vw + 0.75rem, 3rem);
  font-weight: var(--fw-bold);
  letter-spacing: -0.025em;
  line-height: 1.12;
  text-wrap: balance;
  color: var(--text-strong);
  margin-bottom: var(--s-3);
  max-width: 22ch;
}

.hero__lead {
  color: var(--text-muted);
  font-size: var(--fs-15);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--s-4);
  max-width: 54ch;
}

.hero__answer {
  color: var(--text-default);
  font-size: var(--fs-14);
  line-height: var(--lh-relaxed);
  max-width: 60ch;
  margin-top: var(--s-5);
  padding: var(--s-4) var(--s-5);
  background: var(--ink-50);
  border: 1px solid var(--ink-200);
  border-radius: var(--r-lg);
}


/* -- 6.4 responsive overrides ----------------------------------------- */

/* Reduce hero padding on small phones */
@media (max-width: 540px) {
  .hero {
    padding-block: var(--s-6) var(--s-4);
  }
}

/* Landscape phone: smaller top padding so calc is visible */
@media (orientation: landscape) and (max-height: 500px) {
  .hero {
    padding-block: var(--s-4) var(--s-3);
  }
  .hero__answer {
    display: none;
  }
}

/* Hero title: tighter clamp minimum at extreme narrow */
@media (max-width: 375px) {
  .hero__title {
    font-size: clamp(1.75rem, 4vw + 0.75rem, 2.5rem);
  }
}

/* Hero lead: full width on mobile (remove max-width constraint) */
@media (max-width: 540px) {
  .hero__lead {
    max-width: none;
  }
  .hero__answer {
    padding: var(--s-3) var(--s-4);
  }
}
/* ====== 6.5  CALCULATOR FORM ============================================= */

.calc {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  padding: var(--s-6) var(--s-6) var(--s-5);
  margin-block: var(--s-6);
  box-shadow: var(--shadow-sm);
}

.calc__form {
  /* CSS counter for numbered step legends */
  counter-reset: calc-step;
  margin: 0;
}

.calc__group {
  border: 0;
  padding: 0;
  margin: 0 0 var(--s-5) 0;
}
.calc__group + .calc__group {
  padding-top: var(--s-5);
  border-top: 1px solid var(--border-subtle);
}

/* Legend: numbered teal circle + uppercase label */
.calc__legend {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--ink-600);
  margin: 0 0 var(--s-4);
  padding: 0;
  width: 100%;
  counter-increment: calc-step;
}
.calc__legend::before {
  content: counter(calc-step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--teal-600);
  color: var(--white);
  font-size: 10px;
  font-weight: var(--fw-bold);
  letter-spacing: 0;
  flex-shrink: 0;
}

.calc__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4);
}

/* Single-column stack */
.calc__grid--stack { grid-template-columns: 1fr; gap: var(--s-3); }

/* Three-column grid for Body group */
.calc__grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 480px) {
  .calc__grid--three { grid-template-columns: 1fr; }
}

/* Full-width segmented control */
.calc__segmented--full {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  max-width: none;
}
.calc__segmented--full label {
  text-align: center;
  padding: var(--s-3) var(--s-4);
}

.calc__field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
}

.calc__field--span-2 { grid-column: 1 / -1; }

.calc__field > label {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
}

.calc__optional {
  font-size: var(--fs-11);
  color: var(--text-faint);
  letter-spacing: 0;
  text-transform: none;
  font-weight: var(--fw-regular);
  font-style: italic;
}

.calc__input-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}

/* Number + text inputs */
.calc__field input[type="number"],
.calc__field input[type="text"] {
  width: 100%;
  padding: var(--s-3) var(--s-3);
  padding-right: 44px;
  border: 1.5px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}

/* Select: custom chevron, removes native OS arrow */
.calc__field select {
  width: 100%;
  padding: var(--s-3) var(--s-3);
  padding-right: var(--s-10);
  border: 1.5px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  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 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  background-size: 12px 8px;
  appearance: none;
  -webkit-appearance: none;
  font-size: var(--fs-15);
  font-weight: var(--fw-medium);
  color: var(--text-strong);
  cursor: pointer;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}

/* Suffix label: teal-tinted for visual distinction */
.calc__suffix {
  position: absolute;
  right: var(--s-3);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-11);
  font-weight: var(--fw-bold);
  color: var(--teal-600);
  pointer-events: none;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}

/* Focus ring: custom teal, not browser default */
.calc__field input[type="number"]:focus,
.calc__field input[type="text"]:focus,
.calc__field select:focus {
  outline: none;
  border-color: var(--teal-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}

/* Placeholder: italic signals example value, not label */
.calc__field input[type="number"]::placeholder,
.calc__field input[type="text"]::placeholder {
  color: var(--ink-300);
  font-weight: var(--fw-regular);
  font-style: italic;
}

/* Remove native spin buttons */
.calc__field input[type="number"]::-webkit-outer-spin-button,
.calc__field input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.calc__field input[type="number"] { -moz-appearance: textfield; }

/* Hint text */
.calc__hint {
  font-size: var(--fs-12);
  color: var(--text-faint);
  margin-top: 3px;
  font-style: italic;
}

/* Actions row */
.calc__actions {
  display: flex;
  gap: var(--s-3);
  margin-top: var(--s-6);
  align-items: center;
}

/*
  Calculate button: single consolidated definition.
  Previous codebase had a duplicate block that silently overrode
  padding, flex, and shadow. Merged and polished here.
*/
.calc__submit {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-6);
  background: var(--teal-600);
  color: var(--white);
  border-radius: var(--r-md);
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.28), 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: background var(--motion-fast), transform var(--motion-fast), box-shadow var(--motion-fast);
}
/* Amber under-bar: slides in from left on hover */
.calc__submit::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--warning);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.calc__submit:hover {
  background: var(--teal-700);
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.34), 0 2px 4px rgba(15, 23, 42, 0.10);
  transform: translateY(-1px);
}
.calc__submit:hover::after {
  transform: scaleX(1);
}
.calc__submit:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.28);
}
.calc__submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.35), 0 4px 14px rgba(13, 148, 136, 0.28);
}

.calc__submit-icon {
  font-size: var(--fs-18);
  line-height: 1;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.calc__submit:hover .calc__submit-icon { transform: translateX(4px); }

/* Reset button */
.calc__reset {
  padding: var(--s-3) var(--s-4);
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border-default);
  border-radius: var(--r-md);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast), border-color var(--motion-fast);
}
.calc__reset:hover {
  background: var(--surface-sunken);
  color: var(--text-strong);
  border-color: var(--border-strong);
}
.calc__reset:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/*
  Segmented control: CSS-only sliding pill indicator via :has().
  Falls back to simple :checked + label fill for unsupporting browsers.
*/
.calc__segmented {
  display: inline-flex;
  border: 1.5px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--ink-50);
  overflow: hidden;
  width: max-content;
  max-width: 100%;
  position: relative;
}
.calc__segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.calc__segmented label {
  position: relative;
  z-index: 1;
  padding: var(--s-2) var(--s-5);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color var(--motion-fast);
  text-transform: capitalize;
}
.calc__segmented label:hover { color: var(--text-strong); }
.calc__segmented input[type="radio"]:checked + label {
  color: var(--white);
  font-weight: var(--fw-semibold);
}
/* Sliding teal pill behind the labels */
.calc__segmented::before {
  content: '';
  position: absolute;
  top: 2px; bottom: 2px;
  width: 50%;
  background: var(--teal-600);
  border-radius: calc(var(--r-md) - 2px);
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1);
  transform: translateX(0);
  box-shadow: 0 1px 4px rgba(13,148,136,0.22);
  pointer-events: none;
}
/* Slide pill to second position */
.calc__segmented--full:has(input:nth-of-type(2):checked)::before,
.calc__segmented:has(input:nth-of-type(2):checked)::before {
  transform: translateX(100%);
}
/* Fallback for browsers without :has() */
@supports not selector(:has(*)) {
  .calc__segmented input[type="radio"]:checked + label {
    background: var(--teal-600);
    color: var(--white);
  }
}
/* Keyboard focus ring inside the segment */
.calc__segmented input[type="radio"]:focus-visible + label {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--teal-300);
  border-radius: calc(var(--r-md) - 2px);
}

/* Quiz trigger link */
.calc__quiz-trigger {
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  color: var(--teal-700);
  text-decoration: none;
  margin-top: var(--s-2);
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  letter-spacing: 0.01em;
  transition: color var(--motion-fast);
}
.calc__quiz-trigger:hover {
  color: var(--teal-800);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.calc__quiz-trigger:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--r-sm);
}

/* No-JS notice */
.calc__nojs {
  margin-top: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  font-size: var(--fs-13);
  color: var(--text-muted);
}


/* -- 6.5 responsive overrides ----------------------------------------- */

/* Calc card: tighter padding on narrow phones */
@media (max-width: 480px) {
  .calc {
    padding: var(--s-4) var(--s-4) var(--s-4);
    border-radius: var(--r-lg);
  }
}

/* Profile grid: stack to 1-col on very narrow (<=360px) */
@media (max-width: 360px) {
  .calc__grid {
    grid-template-columns: 1fr;
  }
}

/* Body group (3-col): raise breakpoint to 560px for comfort */
@media (max-width: 560px) {
  .calc__grid--three {
    grid-template-columns: 1fr;
  }
}

/* Actions row: stack on narrow so reset button stays accessible */
@media (max-width: 400px) {
  .calc__actions {
    flex-wrap: wrap;
  }
  .calc__reset {
    flex: 1;
    text-align: center;
  }
}

/* Touch: enlarge segmented control labels to 44px touch target */
@media (hover: none) and (pointer: coarse) {
  .calc__segmented label {
    padding-block: var(--s-3);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Enlarge number inputs for fat-finger accuracy */
  .calc__field input[type="number"],
  .calc__field input[type="text"] {
    padding-block: var(--s-3);
    min-height: 44px;
  }

  /* Enlarge select on touch */
  .calc__field select {
    min-height: 44px;
    padding-block: var(--s-3);
  }

  /* Enlarge reset button */
  .calc__reset {
    padding: var(--s-3) var(--s-5);
    min-height: 44px;
  }

  /* Quiz trigger: easier tap */
  .calc__quiz-trigger {
    padding-block: var(--s-2);
    display: inline-flex;
  }
}

/* Landscape phone: compact form spacing */
@media (orientation: landscape) and (max-height: 500px) {
  .calc {
    padding: var(--s-4) var(--s-5);
  }
  .calc__group {
    margin-bottom: var(--s-3);
  }
  .calc__group + .calc__group {
    padding-top: var(--s-3);
  }
}

/* Safe-area: prevent form from kissing notch edges */
@media (max-width: 540px) {
  .calc {
    margin-inline: max(0px, env(safe-area-inset-left));
  }
}
/* ====== 6.6  RESULT CARD ================================================= */

.result {
  background: var(--surface-invert);
  color: var(--text-invert);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-block: var(--s-4);
  box-shadow: var(--shadow-md);
  position: relative;
  /* Hidden until user clicks Calculate (or URL state pre-populates) */
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding-block: 0;
  margin-block: 0;
  transition: max-height var(--motion-slow), opacity var(--motion-normal), padding var(--motion-normal), margin var(--motion-normal);
}

.result.is-revealed {
  max-height: 4000px; /* enough room for charts */
  opacity: 1;
  padding-block: var(--s-5);
  margin-block: var(--s-4);
}

/* Count-up animation on the TDEE number */
@keyframes numReveal {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result__value--animating [data-result="tdee"] {
  animation: numReveal 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@media (prefers-reduced-motion: reduce) {
  .result__value--animating [data-result="tdee"] { animation: none; }
}

.result__hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
  align-items: center;
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--ink-700);
  margin-bottom: var(--s-4);
}
@media (min-width: 520px) {
  .result__hero { grid-template-columns: 1fr 180px; }
}

.result__sub {
  font-size: var(--fs-13);
  color: var(--ink-400);
  margin-top: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.result__h3 {
  font-size: var(--fs-12);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--ink-400);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--s-3);
}
.result__metric-unit {
  font-size: var(--fs-11);
  color: var(--ink-400);
  margin-left: 2px;
}

.result__primary { display: flex; flex-direction: column; gap: var(--s-2); }

.result__eyebrow {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--teal-300);
  margin: 0;
}

.result__value {
  font-size: clamp(3rem, 8vw, 4.5rem);
  font-weight: var(--fw-bold);
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  flex-wrap: wrap;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.result__unit {
  font-size: var(--fs-15);
  font-weight: var(--fw-regular);
  color: var(--ink-400);
  letter-spacing: var(--tracking-normal);
}

/* Quick-facts row: BMR, BMI, LBM */
.result__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-3);
  padding-block: var(--s-4);
  border-top: 1px solid var(--ink-700);
  border-bottom: 1px solid var(--ink-700);
  margin: 0;
}
.result__fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  padding-inline: var(--s-3);
  border-left: 1px solid var(--ink-700);
}
.result__fact:first-child { border-left: 0; padding-left: 0; }
.result__fact-label {
  font-size: var(--fs-11);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--ink-400);
  font-weight: var(--fw-semibold);
}
.result__fact-value {
  font-size: var(--fs-24);
  font-weight: var(--fw-bold);
  color: var(--white);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.result__fact-unit {
  font-size: var(--fs-12);
  color: var(--ink-400);
  text-transform: capitalize;
}

/* Section labels inside the result card */
.result__section-label {
  font-size: var(--fs-12);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--ink-400);
  font-weight: var(--fw-semibold);
  margin: 0 0 var(--s-3);
}

.result__goals { margin-top: var(--s-5); }
.result__goal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-2);
}
.goal-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-1);
  padding: var(--s-4) var(--s-4) var(--s-3);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  color: var(--text-invert);
  cursor: pointer;
  text-align: left;
  font: inherit;
  position: relative;
  overflow: hidden;
  transition:
    background var(--motion-fast),
    border-color var(--motion-fast),
    transform var(--motion-fast),
    box-shadow var(--motion-fast);
}
/* Bottom accent bar - hidden until active */
.goal-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  border-radius: 0 0 var(--r-md) var(--r-md);
  transition: background var(--motion-fast);
}
.goal-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--ink-500);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.goal-card:active {
  transform: translateY(0);
  box-shadow: none;
}
.goal-card.is-active {
  background: var(--teal-800);
  border-color: var(--teal-600);
  box-shadow: 0 0 0 2px var(--teal-600), inset 0 1px 0 rgba(255,255,255,0.06);
}
.goal-card.is-active::after {
  background: var(--teal-300);
}
/* Goal-specific active accent colors */
.goal-card--cut.is-active {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3), inset 0 1px 0 rgba(255,255,255,0.04);
}
.goal-card--cut.is-active::after { background: #f59e0b; }
.goal-card--bulk.is-active {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3), inset 0 1px 0 rgba(255,255,255,0.04);
}
.goal-card--bulk.is-active::after { background: var(--success); }

.goal-card__icon {
  font-size: var(--fs-15);
  font-weight: var(--fw-bold);
  color: var(--teal-300);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: rgba(255,255,255,0.05);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.goal-card--cut  .goal-card__icon { color: #fbbf24; background: rgba(251,191,36,0.10); }
.goal-card--bulk .goal-card__icon { color: var(--success); background: rgba(16,185,129,0.10); }
.goal-card.is-active .goal-card__icon {
  color: var(--white);
  background: rgba(255,255,255,0.15);
}
.goal-card__label {
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--ink-400);
  margin-top: var(--s-1);
}
.goal-card.is-active .goal-card__label { color: var(--ink-200); }
.goal-card__value {
  font-size: var(--fs-24);
  font-weight: var(--fw-bold);
  color: var(--white);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.goal-card__pace {
  font-size: var(--fs-11);
  color: var(--ink-500);
  font-weight: var(--fw-regular);
  line-height: var(--lh-snug);
}
.goal-card.is-active .goal-card__pace { color: var(--ink-300); }

/* Macro section */
.result__macros { margin-top: var(--s-6); }
.result__macros-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.result__macros-hint {
  font-size: var(--fs-12);
  color: var(--ink-400);
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.result__macros-bar {
  display: flex;
  width: 100%;
  height: 28px;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--ink-800);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.35);
  gap: 1px;
}
.macro-bar__seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  transition: flex var(--motion-normal);
  position: relative;
  /* Subtle inner highlight - top edge shimmer */
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
}
.macro-bar__seg-pct {
  color: var(--white);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.result__macros-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-3);
  margin: var(--s-3) 0 0;
  padding: 0;
  list-style: none;
}
.macro-card {
  display: grid;
  grid-template-columns: 8px 1fr;
  grid-template-rows: auto auto auto;
  align-items: start;
  column-gap: var(--s-2);
  row-gap: 2px;
  padding: var(--s-3);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  transition: border-color var(--motion-fast), background var(--motion-fast);
}
.macro-card:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--ink-600);
}
.macro-card__dot {
  grid-row: 1; grid-column: 1;
  width: 8px; height: 8px; border-radius: 2px;
  align-self: center;
  margin-top: 2px;
}
.macro-card__label {
  grid-row: 1; grid-column: 2;
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  color: var(--ink-400);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}
.macro-card__grams {
  grid-row: 2; grid-column: 1 / -1;
  font-size: var(--fs-20);
  font-weight: var(--fw-bold);
  color: var(--white);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.macro-card__grams small {
  font-size: var(--fs-13);
  font-weight: var(--fw-regular);
  color: var(--ink-400);
  margin-left: 1px;
}
.macro-card__per {
  grid-row: 3; grid-column: 1 / -1;
  font-size: var(--fs-11);
  color: var(--ink-500);
  font-variant-numeric: tabular-nums;
  line-height: var(--lh-snug);
  padding-top: 2px;
  border-top: 1px solid var(--ink-800);
  margin-top: 4px;
}

/* Action row */
.result__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--ink-700);
}
.result__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--ink-700);
  color: var(--ink-200);
  border-radius: var(--r-md);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--motion-fast),
    border-color var(--motion-fast),
    color var(--motion-fast),
    transform var(--motion-fast),
    box-shadow var(--motion-fast);
  font: inherit;
}
.result__btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--ink-500);
  color: var(--white);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.result__btn:active {
  transform: translateY(0);
  box-shadow: none;
  background: rgba(255,255,255,0.06);
}
.result__btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.result__btn--ghost {
  border-style: dashed;
  color: var(--ink-400);
  background: transparent;
}
.result__btn--ghost:hover {
  color: var(--teal-300);
  border-color: var(--teal-700);
  border-style: solid;
  background: rgba(13, 148, 136, 0.06);
}
.result__btn-icon {
  font-size: var(--fs-14);
  line-height: 1;
  opacity: 0.75;
  transition: opacity var(--motion-fast);
}
.result__btn:hover .result__btn-icon { opacity: 1; }
.result__share-status:not(:empty) {
  color: var(--success);
  font-size: var(--fs-13);
  margin-left: var(--s-2);
}

/* Footnote: inset block with left accent rule */
.result__footnote {
  margin: var(--s-5) 0 0;
  font-size: var(--fs-12);
  color: var(--ink-500);
  line-height: var(--lh-relaxed);
  max-width: 60ch;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  border-left: 2px solid var(--ink-700);
  background: rgba(255,255,255,0.02);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.result__footnote a { color: var(--teal-300); text-underline-offset: 2px; }
.result__footnote a:hover { color: var(--teal-300); }

/* Empty state */
.result.is-empty .result__value { color: var(--ink-500); }

/* Mobile breakpoint: stack goal cards, facts, and macros */
@media (max-width: 640px) {
  .result__facts,
  .result__goal-grid,
  .result__macros-list { grid-template-columns: 1fr; }
  .result__fact { border-left: 0; border-top: 1px solid var(--ink-700); padding: var(--s-3) 0 0; }
  .result__fact:first-child { border-top: 0; padding-top: 0; }
  .result__value { font-size: clamp(2.5rem, 12vw, 3.5rem); }
  /* Macro bar: at 320px a 20% segment is ~50px; 10px font + nowrap fits the label comfortably */
  .macro-bar__seg-pct { font-size: 10px; }
  /* Shrink min-width from 40px to 28px so small segments stay visible at narrow widths */
  .macro-bar__seg { min-width: 28px; }
  /* Goal cards: 60px minimum touch target height */
  .goal-card { min-height: 60px; }
  /* Action buttons: 44px minimum touch target height */
  .result__btn { min-height: 44px; }
}

/* Touch devices: disable hover lift animations -- mouse-only interaction pattern */
@media (hover: none) and (pointer: coarse) {
  .goal-card:hover {
    transform: none;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--ink-700);
  }
  .goal-card.is-active:hover {
    background: var(--teal-800);
    border-color: var(--teal-600);
    box-shadow: 0 0 0 2px var(--teal-600), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  .goal-card--cut.is-active:hover {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.45);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3), inset 0 1px 0 rgba(255,255,255,0.04);
  }
  .goal-card--bulk.is-active:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.45);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3), inset 0 1px 0 rgba(255,255,255,0.04);
  }
  .result__btn:hover {
    transform: none;
    box-shadow: none;
  }
}

/* ====== 6.6b  CHARTS ===================================================== */

.result__chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
}

.chart-donut {
  width: 100%;
  max-width: 160px;
  height: auto;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.30));
}
.chart-donut__total {
  font-size: 14px;
  font-weight: 700;
  fill: var(--white);
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
}
.chart-donut__unit {
  font-size: 7px;
  fill: var(--ink-400);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--font-sans);
}
.chart-donut__legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  font-size: var(--fs-12);
  font-variant-numeric: tabular-nums;
}
.chart-donut__legend li {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  align-items: center;
  gap: 6px;
  color: var(--ink-300);
  padding: 3px 0;
}

.chart-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chart-legend-label { color: var(--ink-300); }
.chart-legend-value { color: var(--white); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.chart-legend-pct   { color: var(--ink-400); font-size: var(--fs-11); }

.result__macros {
  padding-top: var(--s-4);
  margin-top: var(--s-4);
  border-top: 1px solid var(--ink-700);
}
.result__macros-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: var(--s-4);
  align-items: center;
}
.chart-pie { width: 100px; height: 100px; display: block; }

.result__macros-legend {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-13);
  font-variant-numeric: tabular-nums;
}
.result__macros-legend li {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: baseline;
  gap: 8px;
  color: var(--ink-300);
}
.result__macros-legend small { font-size: var(--fs-11); color: var(--ink-400); margin-left: 2px; }

/* Power Mode charts -- horizontal bars (formulas) and vertical bars (activity ladder) */
.pm-chart-wrap { margin-top: var(--s-3); }

.chart-bars { display: flex; flex-direction: column; gap: var(--s-2); }
.chart-bars__row {
  display: grid;
  grid-template-columns: 140px 1fr 80px;
  align-items: center;
  gap: var(--s-3);
  font-size: var(--fs-13);
}
.chart-bars__label { color: var(--text-muted); }
.chart-bars__row.is-primary .chart-bars__label { color: var(--text-strong); font-weight: var(--fw-semibold); }
.chart-bars__track {
  position: relative;
  height: 10px;
  background: var(--ink-100);
  border-radius: var(--r-pill);
  /* no overflow:hidden so pill terminals on the fill are visible */
}
.chart-bars__fill {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  min-width: 6px;
  background: var(--teal-300);
  border-radius: var(--r-pill);
  transition: width var(--motion-normal);
}
.chart-bars__row.is-primary .chart-bars__fill {
  background: var(--teal-600);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.18);
}
/* Primary row: left accent stripe */
.chart-bars__row.is-primary .chart-bars__label::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 0.85em;
  background: var(--teal-600);
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.chart-bars__value {
  text-align: right;
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.chart-bars__row.is-primary .chart-bars__value { color: var(--teal-700); }

/* Vertical bar chart */
.chart-bars--vert {
  flex-direction: row;
  align-items: flex-end;
  gap: var(--s-3);
  height: 220px;
  padding: var(--s-2) 0;
}
.chart-bars__col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-1);
  height: 100%;
  min-width: 0;
}
.chart-bars__col-value {
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.chart-bars__col.is-primary .chart-bars__col-value { color: var(--teal-700); }
.chart-bars__col-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background: var(--ink-100);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.chart-bars__col-fill {
  width: 100%;
  background: var(--teal-300);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: height var(--motion-normal);
}
.chart-bars__col.is-primary .chart-bars__col-fill { background: var(--teal-600); }
.chart-bars__col-label {
  font-size: var(--fs-11);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wide);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  white-space: nowrap;
}
.chart-bars__col.is-primary .chart-bars__col-label { color: var(--text-strong); font-weight: var(--fw-semibold); }

/* ====== 6.7  POWER MODE ================================================== */

.power-mode {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  margin-block: var(--s-4);
}

.power-mode__toggle {
  cursor: pointer;
  font-weight: var(--fw-semibold);
  color: var(--teal-700);
  font-size: var(--fs-15);
  padding: var(--s-3) var(--s-4);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  user-select: none;
}
.power-mode__toggle::-webkit-details-marker { display: none; }

@media (hover: hover) {
  .power-mode__toggle:hover { color: var(--teal-800); }
  .power-mode__toggle:hover .power-mode__icon {
    border-color: var(--teal-700);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
  }
}

.power-mode__label {
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
}

.power-mode__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border: 1.5px solid var(--teal-500);
  border-radius: var(--r-sm);
  font-size: var(--fs-14);
  line-height: 1;
  color: var(--teal-600);
  flex-shrink: 0;
  transition: transform var(--motion-normal), background var(--motion-normal),
              color var(--motion-fast), border-color var(--motion-fast),
              box-shadow var(--motion-fast);
}
.power-mode[open] .power-mode__icon {
  background: var(--teal-600);
  border-color: var(--teal-600);
  color: var(--white);
  transform: rotate(45deg) scale(1.05);
}

.power-mode__hint {
  font-weight: var(--fw-regular);
  color: var(--text-subtle);
  font-size: var(--fs-12);
  background: var(--ink-100);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  padding: 2px var(--s-2);
  letter-spacing: var(--tracking-wide);
}

.power-mode__body {
  padding: var(--s-2) var(--s-4) var(--s-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-raised);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

.power-mode__section {
  padding-block: var(--s-3);
}
.power-mode__section + .power-mode__section { border-top: 1px solid var(--border-subtle); }

.power-mode__section h3 {
  font-size: var(--fs-15);
  letter-spacing: var(--tracking-snug);
  margin-bottom: var(--s-1);
}

.power-mode__placeholder {
  color: var(--text-faint);
  font-size: var(--fs-13);
  font-style: italic;
}
/* Hide placeholder text once the JS has rendered real content into the section. */
.power-mode__section:has(.pm-table, .pm-formulas, .pm-macros, .pm-life-stage-result) .power-mode__placeholder {
  display: none;
}

/* ---- Tables: all-metrics, formulas, goal ladder ---- */
.pm-table,
.pm-formulas,
.pm-ladder {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-14);
  font-variant-numeric: tabular-nums;
  margin-top: var(--s-3);
}
.pm-table th,
.pm-table td,
.pm-formulas th,
.pm-formulas td,
.pm-ladder th,
.pm-ladder td {
  text-align: left;
  padding: var(--s-1) var(--s-3);
  border-bottom: 1px solid var(--border-subtle);
}
/* Subtle zebra striping */
.pm-table tbody tr:nth-child(even),
.pm-ladder tbody tr:nth-child(even) {
  background: rgba(241, 245, 249, 0.55);
}
@media (hover: hover) {
  .pm-table tbody tr:hover,
  .pm-formulas tbody tr:hover,
  .pm-ladder tbody tr:hover {
    background: rgba(13, 148, 136, 0.04);
    transition: background var(--motion-fast);
  }
}
.pm-table th[scope="row"],
.pm-formulas th[scope="row"],
.pm-ladder th[scope="row"] {
  font-weight: var(--fw-medium);
  color: var(--text-default);
}
.pm-table thead th,
.pm-formulas thead th,
.pm-ladder thead th {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-default);
  padding-top: 0;
}
.pm-table__v {
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  text-align: right;
  width: 1%;
  white-space: nowrap;
}
.pm-table__h {
  color: var(--text-subtle);
  font-size: var(--fs-12);
  font-style: italic;
  width: 1%;
  white-space: nowrap;
}
/* Citation cell: smaller, academic-reference style */
.pm-table__cite {
  color: var(--text-subtle);
  font-size: var(--fs-11);
  letter-spacing: var(--tracking-wide);
}
/* Primary formula row highlight */
.pm-formulas tbody tr.is-primary th,
.pm-formulas tbody tr.is-primary td {
  color: var(--text-strong);
  font-weight: var(--fw-semibold);
  background: rgba(13, 148, 136, 0.05);
}

/* Goal ladder direction tints */
.pm-ladder tbody tr[data-direction="deficit"] {
  background: rgba(245, 158, 11, 0.06);
}
.pm-ladder tbody tr[data-direction="surplus"] {
  background: rgba(16, 185, 129, 0.06);
}
.pm-ladder tbody tr[data-direction="neutral"] {
  background: var(--surface-raised);
  font-weight: var(--fw-semibold);
}
.pm-ladder tbody tr:nth-child(even)[data-direction="deficit"] {
  background: rgba(245, 158, 11, 0.09);
}
.pm-ladder tbody tr:nth-child(even)[data-direction="surplus"] {
  background: rgba(16, 185, 129, 0.09);
}

/* ---- Macro selector: grouped chips + values ---- */
/* ---- 2D macro matrix: goal x carb level ---- */
.pm-macros {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  margin-top: var(--s-3);
}

.pm-matrix {
  display: grid;
  gap: 6px;
  background: var(--surface-sunken);
  padding: var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border-subtle);
}

.pm-matrix__row {
  display: grid;
  grid-template-columns: 88px repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
}
.pm-matrix__row--head {
  margin-bottom: 2px;
}

.pm-matrix__corner { /* empty top-left cell */ }

.pm-matrix__col-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 4px;
  text-align: center;
}
.pm-matrix__col-label {
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  line-height: 1;
}
.pm-matrix__col-sub {
  font-size: var(--fs-10, 0.625rem);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 2px;
}

.pm-matrix__row-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: var(--s-2) var(--s-2) var(--s-2) 0;
  gap: 2px;
  border-right: 1px solid var(--border-subtle);
}
.pm-matrix__row-label {
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-strong);
  line-height: 1;
}
.pm-matrix__row-sub {
  font-size: var(--fs-11);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.pm-matrix__row-head[data-tone="cut"]      .pm-matrix__row-label { color: var(--warning); }
.pm-matrix__row-head[data-tone="bulk"]     .pm-matrix__row-label { color: var(--success); }
.pm-matrix__row-head[data-tone="maintain"] .pm-matrix__row-label { color: var(--teal-700); }

.pm-matrix__cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--s-3) var(--s-1);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: center;
  transition: background var(--motion-fast), border-color var(--motion-fast),
              color var(--motion-fast), box-shadow var(--motion-fast),
              transform var(--motion-fast);
  user-select: none;
}
.pm-matrix__cell input { position: absolute; opacity: 0; pointer-events: none; }

@media (hover: hover) {
  .pm-matrix__cell:hover {
    border-color: var(--teal-500);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
  }
}
.pm-matrix__cell.is-active {
  background: var(--teal-600);
  border-color: var(--teal-600);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.30), inset 0 0 0 1px rgba(255,255,255,0.10);
}

.pm-matrix__ratio {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-size: var(--fs-18);
  font-weight: var(--fw-bold);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: var(--tracking-tight);
}
.pm-matrix__cell.is-active .pm-matrix__ratio { color: var(--white); }
.pm-matrix__ratio-p { color: var(--teal-700); }
.pm-matrix__ratio-c { color: var(--text-strong); }
.pm-matrix__ratio-f { color: var(--warning); }
.pm-matrix__ratio-sep {
  color: var(--text-faint);
  font-weight: var(--fw-regular);
  margin-inline: 1px;
}
.pm-matrix__cell.is-active .pm-matrix__ratio-p,
.pm-matrix__cell.is-active .pm-matrix__ratio-c,
.pm-matrix__cell.is-active .pm-matrix__ratio-f,
.pm-matrix__cell.is-active .pm-matrix__ratio-sep { color: var(--white); }

.pm-matrix__ratio-axis {
  font-size: var(--fs-10, 0.625rem);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: var(--fw-semibold);
}
.pm-matrix__cell.is-active .pm-matrix__ratio-axis { color: rgba(255, 255, 255, 0.75); }

/* ---- Macro tiles below the matrix ---- */
.pm-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-2);
}

.pm-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-3) var(--s-3) var(--s-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--border-default);
  text-align: left;
}
.pm-tile--protein { border-top-color: var(--teal-600); }
.pm-tile--carbs   { border-top-color: var(--teal-300); }
.pm-tile--fat     { border-top-color: var(--warning); }
.pm-tile--total   { border-top-color: var(--ink-700); background: var(--ink-900); }
.pm-tile--total .pm-tile__label,
.pm-tile--total .pm-tile__pct,
.pm-tile--total .pm-tile__per { color: var(--ink-300); }
.pm-tile--total .pm-tile__value,
.pm-tile--total .pm-tile__unit { color: var(--white); }

.pm-tile__label {
  font-size: var(--fs-11);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
}
.pm-tile__value {
  font-size: var(--fs-28);
  font-weight: var(--fw-bold);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
  line-height: 1.05;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.pm-tile__unit {
  font-size: var(--fs-13);
  font-weight: var(--fw-regular);
  color: var(--text-muted);
  letter-spacing: 0;
}
.pm-tile__pct {
  font-size: var(--fs-12);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.pm-tile__per {
  font-size: var(--fs-11);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* Mobile: stack tiles 2x2, stack matrix into single column */
@media (max-width: 640px) {
  .pm-matrix__row {
    grid-template-columns: 64px repeat(3, minmax(0, 1fr));
  }
  .pm-matrix__cell { padding: var(--s-2) 2px; }
  .pm-matrix__ratio { font-size: var(--fs-15); }
  .pm-matrix__row-label { font-size: var(--fs-12); }
  .pm-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- Formula reveal: monospace code callout with teal left-rail ---- */
.pm-reveal {
  margin-top: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-sunken);
  border-radius: var(--r-md);
  border-left: 3px solid var(--teal-600);
}
.pm-reveal__caption {
  font-size: var(--fs-11);
  color: var(--teal-700);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--s-2);
}
.pm-reveal__formula {
  background: transparent;
  border: 0;
  padding: 2px 0;
  margin: 0 0 var(--s-1);
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  color: var(--text-strong);
  line-height: var(--lh-snug);
  white-space: pre-wrap;
  word-break: break-all;
}
.pm-reveal__formula code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
.pm-reveal__cite {
  font-size: var(--fs-12);
  color: var(--text-subtle);
  margin-top: var(--s-2);
  font-style: italic;
  padding-top: var(--s-2);
  border-top: 1px solid var(--border-subtle);
}

/* ---- Life-stage result callout ---- */
.pm-life-stage-result {
  margin-top: var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--fs-14);
}
.pm-life-stage-result__empty {
  padding: var(--s-3) var(--s-4);
  background: var(--surface-sunken);
  border-radius: var(--r-md);
  color: var(--text-faint);
  font-size: var(--fs-13);
  font-style: italic;
}
.pm-life-stage-result--active {
  padding: var(--s-3) var(--s-4);
  background: var(--surface-sunken);
  border-left: 3px solid var(--info);
}
.pm-life-stage-result__body {
  color: var(--text-default);
  line-height: var(--lh-snug);
}
.pm-life-stage-result__badge {
  display: inline-block;
  background: rgba(13, 148, 136, 0.10);
  color: var(--teal-700);
  border: 1px solid rgba(13, 148, 136, 0.25);
  border-radius: var(--r-pill);
  padding: 1px var(--s-2);
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  text-transform: capitalize;
  margin-right: var(--s-1);
  letter-spacing: var(--tracking-wide);
}
.pm-life-stage-result__cite {
  font-size: var(--fs-12);
  color: var(--text-subtle);
  font-style: italic;
  margin-top: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--border-subtle);
}

/* ---- pm-reveal: horizontal scroll for formula pre blocks ---- */
.pm-reveal__formula {
  white-space: pre;
  overflow-x: auto;
  word-break: normal;
  -webkit-overflow-scrolling: touch;
}
.pm-reveal__formula::-webkit-scrollbar { height: 4px; }
.pm-reveal__formula::-webkit-scrollbar-track { background: transparent; }
.pm-reveal__formula::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--r-pill);
}

/* ---- Table overflow wrappers (JS renders .pm-table-wrap around each table) ---- */
.pm-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: var(--s-3);
}
.pm-table-wrap .pm-table,
.pm-table-wrap .pm-formulas,
.pm-table-wrap .pm-ladder {
  margin-top: 0;
}

/* ---- chart-bars horizontal: tighten label and value columns on narrow ---- */
@media (max-width: 480px) {
  .chart-bars__row {
    grid-template-columns: 90px 1fr 58px;
    font-size: var(--fs-12);
  }
}
@media (max-width: 360px) {
  .chart-bars__row {
    grid-template-columns: 72px 1fr 48px;
    font-size: var(--fs-11);
  }
}

/* ---- pm-formulas table: citation column scrolls with pm-table-wrap below 480px ---- */
/* (No hide: the overflow-x wrapper on .pm-table-wrap handles narrow viewports) */

/* ---- Activity ladder vertical bars: narrow viewports ---- */
@media (max-width: 480px) {
  .chart-bars--vert {
    height: 180px;
    gap: var(--s-2);
  }
  .chart-bars__col {
    min-width: 32px;
  }
  .chart-bars__col-value {
    font-size: var(--fs-11);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    height: 3.2em;
    overflow: hidden;
  }
}
@media (max-width: 360px) {
  .chart-bars--vert {
    height: 160px;
  }
  .chart-bars__col-label {
    font-size: var(--fs-10, 0.625rem);
  }
}

/* ---- 2D Macro Matrix: vertical stack layout at very narrow viewports ---- */
@media (max-width: 379px) {
  .pm-matrix__row--head .pm-matrix__corner {
    display: none;
  }
  .pm-matrix__row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: auto auto;
    gap: 4px;
  }
  .pm-matrix__row-head {
    grid-column: 1 / -1;
    grid-row: 1;
    flex-direction: row;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-1) 0;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .pm-matrix__cell {
    grid-row: 2;
  }
}

/* ---- Touch targets ---- */
@media (hover: none) and (pointer: coarse) {
  .pm-matrix__cell {
    min-height: 44px;
    padding: var(--s-2) var(--s-1);
  }
  .power-mode__toggle {
    min-height: 44px;
  }
}

/* ---- Power Mode toggle: narrow viewport hint pill wrapping ---- */
@media (max-width: 400px) {
  .power-mode__hint {
    /* flex-wrap on the parent already puts the pill on its own line;
       width:100% causes overflow when combined with margin, so let it size naturally */
    max-width: calc(100% - var(--s-3));
  }
}

/* ---- pm-tiles: scale down value at 320px ---- */
@media (max-width: 380px) {
  .pm-tile__value {
    font-size: var(--fs-22, 1.375rem);
  }
  .pm-tile__label {
    font-size: var(--fs-10, 0.625rem);
  }
}

/* ---- Power Mode body: tighter padding on small screens ---- */
@media (max-width: 480px) {
  .power-mode__body {
    padding: var(--s-2) var(--s-2) var(--s-3);
  }
  .power-mode__section {
    padding-block: var(--s-2);
  }
}

/* ---- Life-stage note: graceful wrap on mobile ---- */
.pm-life-stage-result--active {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* prefers-reduced-motion: disable new power-mode transitions */
@media (prefers-reduced-motion: reduce) {
  .power-mode__icon,
  .pm-chip,
  .pm-table tbody tr,
  .pm-formulas tbody tr,
  .pm-ladder tbody tr,
  .pm-matrix__cell,
  .chart-bars__fill,
  .chart-bars__col-fill {
    transition: none;
  }
}

/* ====== 6.12  ACTIVITY QUIZ MODAL ======================================== */

.quiz {
  width: min(640px, calc(100vw - 2 * var(--s-4)));
  /* Use 100dvh (dynamic viewport height) so iOS browser chrome doesn't clip the modal */
  max-height: calc(100dvh - 2 * var(--s-4));
  /* Fallback for browsers that don't support dvh */
  max-height: calc(100vh - 2 * var(--s-4));
  /* dvh override (placed after fallback for cascade ordering) */
  max-height: min(760px, calc(100dvh - 2 * var(--s-4)));
  padding: 0;
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  background: var(--surface-raised);
  color: var(--text-default);
  overflow: hidden;
}
.quiz::backdrop {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.quiz[open] {
  display: flex;
  flex-direction: column;
  animation: quizIn var(--motion-normal) cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes quizIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Progress bar across top of the header */
.quiz__header {
  position: relative;
  padding: var(--s-5) var(--s-6) var(--s-3);
  border-bottom: 1px solid var(--border-subtle);
}
.quiz__progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border-subtle);
  overflow: hidden;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
}
.quiz__progress-bar {
  height: 100%;
  background: linear-gradient(to right, var(--teal-600), var(--teal-300));
  border-radius: var(--r-pill);
  transition: width var(--motion-slow);
  width: 0%;
}
.quiz__title {
  font-size: var(--fs-20);
  letter-spacing: var(--tracking-snug);
  margin-bottom: var(--s-1);
  padding-top: var(--s-1); /* clear progress bar */
}
.quiz__intro {
  font-size: var(--fs-14);
  color: var(--text-muted);
  line-height: var(--lh-relaxed);
  max-width: 56ch;
}
.quiz__close {
  position: absolute;
  top: var(--s-3); right: var(--s-3);
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-24);
  line-height: 1;
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}
.quiz__close:hover { background: var(--surface-sunken); color: var(--text-strong); }
.quiz__close:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.quiz__form {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-4) var(--s-6);
  /* Smooth scrollbar on Webkit */
  scrollbar-width: thin;
  scrollbar-color: var(--ink-300) transparent;
}
.quiz__form::-webkit-scrollbar { width: 4px; }
.quiz__form::-webkit-scrollbar-track { background: transparent; }
.quiz__form::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: var(--r-pill); }

.quiz__q {
  border: 0;
  padding: 0;
  margin-bottom: var(--s-5);
}
.quiz__q + .quiz__q {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--s-5);
}

.quiz__qnum {
  font-size: var(--fs-11);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--teal-700);
  font-weight: var(--fw-semibold);
  padding: 0;
  margin-bottom: var(--s-1);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
/* Tiny dot separator */
.quiz__qnum::after {
  content: '';
  display: inline-block;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--teal-300);
  flex-shrink: 0;
}
.quiz__qtext {
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  margin-bottom: var(--s-3);
}

.quiz__choices {
  display: grid;
  gap: var(--s-2);
}
.quiz__choice {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  cursor: pointer;
  font-size: var(--fs-14);
  transition: background var(--motion-fast), border-color var(--motion-fast), box-shadow var(--motion-fast);
}
.quiz__choice:hover {
  background: var(--teal-50);
  border-color: var(--teal-300);
}
.quiz__choice input[type="radio"] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--teal-600);
}
.quiz__choice:has(input:checked) {
  background: var(--teal-50);
  border-color: var(--teal-600);
  box-shadow: 0 0 0 1px var(--teal-600);
}

.quiz__result {
  padding: var(--s-3) var(--s-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
}
.quiz__hint {
  font-size: var(--fs-13);
  color: var(--text-muted);
  margin: 0;
}

.quiz__result-card {
  display: grid;
  gap: var(--s-2);
}
.quiz__multiplier {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.quiz__multiplier-label {
  font-size: var(--fs-11);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
}
.quiz__multiplier-value {
  font-size: var(--fs-32);
  font-weight: var(--fw-bold);
  color: var(--teal-700);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}
.quiz__multiplier-cat {
  font-size: var(--fs-14);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.quiz__costnote {
  font-size: var(--fs-13);
  color: var(--text-default);
  line-height: var(--lh-relaxed);
  margin: 0;
}
.quiz__costnote strong { color: var(--danger); font-weight: var(--fw-semibold); }

.quiz__actions {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-raised);
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .quiz {
    width: 100vw;
    /* dvh: accounts for iOS browser chrome expanding/collapsing */
    height: 100dvh;
    max-height: 100dvh;
    /* Fallback */
    height: 100vh;
    max-height: 100vh;
    /* dvh override after fallback */
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  .quiz__form { padding-inline: var(--s-4); }
  .quiz__header, .quiz__result, .quiz__actions { padding-inline: var(--s-4); }
}

/* Landscape phone: prevent modal from exceeding the short viewport */
@media (max-width: 896px) and (max-height: 500px) {
  .quiz {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  .quiz__header { padding-block: var(--s-3); }
  .quiz__title { font-size: var(--fs-16); margin-bottom: 0; }
  .quiz__intro { display: none; }
}

/* ====== 6.13  PWA INSTALL BANNER ========================================= */

.pwa-banner {
  position: fixed;
  /* Inset from left+right with fallback for safe-area env() */
  left: var(--s-3); right: var(--s-3);
  /* Respect iOS home indicator using env(safe-area-inset-bottom) */
  bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  /* On desktop: centered, max 480px wide */
  max-width: 480px;
  margin-inline: auto;
  animation: pwaIn var(--motion-slow) cubic-bezier(0.22, 1, 0.36, 1);
}

/* At >=768px pin to bottom-right corner instead of center */
@media (min-width: 768px) {
  .pwa-banner {
    left: auto;
    right: var(--s-5);
    margin-inline: 0;
  }
}
@keyframes pwaIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* .is-dismissing: add via JS before removing the banner */
.pwa-banner.is-dismissing {
  animation: pwaOut var(--motion-normal) cubic-bezier(0.4, 0, 1, 1) forwards;
  pointer-events: none;
}
@keyframes pwaOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(16px); }
}

.pwa-banner__icon {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  background: var(--teal-600);
  color: var(--white);
  font-weight: var(--fw-bold);
  font-size: var(--fs-14);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.30);
}

.pwa-banner__text { flex: 1; min-width: 0; overflow: hidden; }
.pwa-banner__title {
  font-size: var(--fs-14);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  margin: 0;
  /* Prevent truncation on narrow viewports */
  white-space: normal;
  overflow-wrap: break-word;
}
.pwa-banner__sub {
  font-size: var(--fs-12);
  color: var(--text-muted);
  margin: 0;
  margin-top: 1px;
  white-space: normal;
  overflow-wrap: break-word;
}

/* At very narrow widths, hide the subtitle so icon+title+CTA+dismiss all fit */
@media (max-width: 380px) {
  .pwa-banner__sub { display: none; }
  .pwa-banner { gap: var(--s-2); padding: var(--s-2) var(--s-3); }
  .pwa-banner__icon { width: 32px; height: 32px; font-size: var(--fs-12); }
  .pwa-banner__cta { padding: var(--s-2) var(--s-3); font-size: var(--fs-12); }
}

.pwa-banner__cta {
  padding: var(--s-2) var(--s-4);
  background: var(--teal-600);
  color: var(--white);
  border-radius: var(--r-md);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition: background var(--motion-fast), box-shadow var(--motion-fast);
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.22);
  cursor: pointer;
}
.pwa-banner__cta:hover {
  background: var(--teal-700);
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.32);
}
.pwa-banner__cta:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.pwa-banner__dismiss {
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-18);
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--motion-fast), color var(--motion-fast);
}
.pwa-banner__dismiss:hover { background: var(--surface-sunken); color: var(--text-strong); }
.pwa-banner__dismiss:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ====== 6.14  PROSE BLOCKS (article content) ============================ */

.prose {
  font-size: var(--fs-16);
  line-height: var(--lh-relaxed);
  color: var(--text-default);
  margin-block: var(--s-8);
  max-width: 65ch;
}
.prose > * + * { margin-top: var(--s-4); }
.prose h2 { font-size: var(--fs-24); letter-spacing: var(--tracking-snug); margin-top: var(--s-8); }
.prose h3 { font-size: var(--fs-18); margin-top: var(--s-6); }
.prose ul, .prose ol { padding-left: var(--s-6); }
.prose li { list-style: disc; padding-block: 4px; }
.prose ol li { list-style: decimal; }
.prose blockquote {
  padding: var(--s-3) var(--s-4);
  border-left: 3px solid var(--teal-600);
  background: var(--surface-sunken);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-style: italic;
  color: var(--text-muted);
}
.prose code { font-size: 0.92em; }

/* Figure with optional caption -- used for the TDEE components chart and similar */
.tdee-figure {
  margin: var(--s-6) 0;
  padding: 0;
  text-align: center;
}
.tdee-figure img {
  max-width: min(100%, 480px);
  width: auto;       /* never upscale beyond intrinsic size */
  height: auto;      /* preserve aspect ratio */
  display: block;
  margin: 0 auto var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-raised);
}
.tdee-figure figcaption {
  font-size: var(--fs-13);
  color: var(--text-muted);
  font-style: italic;
  max-width: 50ch;
  margin: 0 auto;
  line-height: var(--lh-relaxed);
}

/* Scrollable code blocks -- formulas must not wrap on narrow screens */
.prose pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Touch tap targets on prose links */
.prose a {
  padding-block: 2px;
}

/* Defensive table wrapper -- future prose tables scroll rather than overflow */
.prose table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Narrow viewport: smaller monospace font keeps code blocks from triggering page scroll */
@media (max-width: 640px) {
  .prose pre {
    font-size: var(--fs-12);
  }
}

/* Touch-specific: reinforce tap area on prose links */
@media (hover: none) and (pointer: coarse) {
  .prose a {
    padding-block: 2px;
  }
}

/* ====== 6.15  RELATED-TOOL CALLOUT ======================================= */

.related-tool {
  position: relative;
  margin-block: var(--s-8);
  padding: var(--s-6);
  background:
    radial-gradient(ellipse at top right, rgba(13, 148, 136, 0.05), transparent 55%),
    linear-gradient(180deg, var(--white) 0%, var(--ink-50) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.03),
    0 12px 28px -12px rgba(15, 23, 42, 0.08);
}
@media (min-width: 641px) {
  .related-tool {
    padding: var(--s-8);
  }
}

/* Scoped overrides: when the callout sits inside .prose, its h2/p/a
   would inherit .prose typography. Selectors below carry .related-tool
   prefix to win specificity over .prose h2 / .prose a. */
.related-tool .related-tool__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 var(--s-4);
  padding: 5px var(--s-3);
  background: rgba(13, 148, 136, 0.10);
  color: var(--teal-700);
  font-size: var(--fs-11);
  font-weight: var(--fw-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--r-pill);
  line-height: 1;
}
/* Tiny spark dot in the eyebrow chip */
.related-tool .related-tool__eyebrow::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--teal-600);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.18);
}

.related-tool .related-tool__title {
  margin: 0 0 var(--s-3);
  font-size: var(--fs-20);
  font-weight: var(--fw-bold);
  color: var(--text-strong);
  line-height: 1.25;
  letter-spacing: -0.015em;
  /* Override .prose h2 inheritance */
  margin-top: 0;
}
@media (min-width: 641px) {
  .related-tool .related-tool__title {
    font-size: var(--fs-24);
    line-height: 1.2;
  }
}

.related-tool .related-tool__body {
  margin: 0 0 var(--s-6);
  color: var(--text-muted);
  font-size: var(--fs-15);
  line-height: 1.6;
  max-width: 62ch;
}

.related-tool .related-tool__cta {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px var(--s-5);
  background: var(--teal-600);
  color: var(--white);
  text-decoration: none;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-14);
  letter-spacing: -0.005em;
  border-radius: var(--r-sm);
  min-height: 44px;
  /* Override .prose a padding-block */
  padding-block: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 2px 6px rgba(13, 148, 136, 0.25);
  transition: background var(--motion-fast), transform var(--motion-fast), box-shadow var(--motion-fast);
}
.related-tool .related-tool__cta:hover {
  background: var(--teal-700);
  color: var(--white);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 6px 14px rgba(13, 148, 136, 0.32);
}
.related-tool .related-tool__cta:active {
  transform: translateY(0);
}
.related-tool .related-tool__cta:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus), 0 2px 6px rgba(13, 148, 136, 0.25);
}
.related-tool .related-tool__cta::after {
  content: '\2197';
  font-size: 1.05em;
  line-height: 1;
  font-weight: var(--fw-bold);
  transition: transform var(--motion-fast);
}
.related-tool .related-tool__cta:hover::after {
  transform: translate(2px, -2px);
}

@media (prefers-reduced-motion: reduce) {
  .related-tool__cta,
  .related-tool__cta:hover,
  .related-tool__cta:hover::after {
    transform: none !important;
    transition: none !important;
  }
}

@media (max-width: 480px) {
  .related-tool {
    margin-block: var(--s-6);
    padding: var(--s-5);
    border-radius: var(--r-md);
  }
  .related-tool .related-tool__title {
    font-size: var(--fs-18);
  }
  .related-tool .related-tool__body {
    font-size: var(--fs-14);
    margin-bottom: var(--s-5);
  }
  .related-tool .related-tool__cta {
    width: 100%;
    justify-content: center;
    padding: 12px var(--s-4);
  }
}

/* ====== 6.8  FAQ ========================================================= */

.faq { margin-block: var(--s-12); }

.faq__heading {
  font-size: var(--fs-24);
  margin-bottom: var(--s-4);
  letter-spacing: var(--tracking-snug);
}

/* details/summary accordion */
.faq__item {
  border-top: 1px solid var(--border-subtle);
  /* Ensure opening an item doesn't hide behind sticky header */
  scroll-margin-top: 80px;
}
.faq__item:last-child { border-bottom: 1px solid var(--border-subtle); }

/* Remove native disclosure triangle */
.faq__item > summary { list-style: none; }
.faq__item > summary::-webkit-details-marker { display: none; }

.faq__question {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  /* Mobile: minimum 48px tap area per WCAG 2.5.5 */
  min-height: 48px;
  padding-block: var(--s-3);
  cursor: pointer;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-16);
  color: var(--text-strong);
  user-select: none;
  transition: color var(--motion-fast);
  /* Long question text must wrap cleanly */
  word-break: break-word;
  overflow-wrap: anywhere;
}
.faq__question:hover { color: var(--teal-700); }
.faq__question:focus-visible {
  outline: none;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-focus);
}

.faq__question-text {
  flex: 1;
  /* Prevent text from collapsing chevron -- gives text room to wrap */
  min-width: 0;
}

/* Chevron built in pure CSS -- two pseudo lines forming a V */
.faq__chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--motion-fast), border-color var(--motion-fast);
  position: relative;
}
.faq__chevron::before,
.faq__chevron::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 1.5px;
  background: var(--text-muted);
  border-radius: 1px;
  transition: transform var(--motion-normal), background var(--motion-fast);
}
.faq__chevron::before { transform: translateX(-2px) rotate(45deg); }
.faq__chevron::after  { transform: translateX(2px) rotate(-45deg); }

.faq__item[open] .faq__chevron {
  background: var(--teal-50);
  border-color: var(--teal-300);
}
.faq__item[open] .faq__chevron::before { transform: translateX(-2px) rotate(-45deg); background: var(--teal-600); }
.faq__item[open] .faq__chevron::after  { transform: translateX(2px) rotate(45deg);  background: var(--teal-600); }
.faq__item[open] .faq__question { color: var(--teal-700); }

.faq__answer {
  padding-bottom: var(--s-5);
  /* align text under question, leaving room for chevron width + gap */
  padding-right: calc(20px + var(--s-4));
  color: var(--text-muted);
  line-height: var(--lh-relaxed);
  font-size: var(--fs-15);
}

/* On narrow screens the right-padding would squeeze text too much */
@media (max-width: 480px) {
  .faq__answer { padding-right: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .faq__item[open] .faq__answer {
    animation: faqReveal 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }
}
@keyframes faqReveal {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ====== 6.9  BUTTONS / CTA =============================================== */

.cta,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  background: var(--teal-600);
  color: var(--white);
  text-decoration: none;
  border-radius: var(--r-md);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-15);
  border: 0;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.22);
  transition: background var(--motion-fast), transform var(--motion-fast), box-shadow var(--motion-fast);
  white-space: nowrap;
}
.cta:hover,
.button:hover {
  background: var(--teal-700);
  color: var(--white);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.32);
  transform: translateY(-1px);
}
.cta:active,
.button:active { transform: translateY(1px); box-shadow: none; }
.cta:focus-visible,
.button:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.button--ghost {
  background: transparent;
  color: var(--teal-700);
  border: 1px solid var(--border-default);
  box-shadow: none;
}
.button--ghost:hover {
  background: var(--surface-sunken);
  color: var(--teal-800);
  box-shadow: none;
  transform: translateY(-1px);
}

.button--block { width: 100%; }

/* ====== 6.10  SITE FOOTER ================================================ */

.site-footer {
  /* Thin teal-to-transparent accent line replaces the plain border */
  border-top: 0;
  background-image: linear-gradient(to right, var(--teal-600), var(--teal-300) 40%, transparent);
  background-size: 100% 2px;
  background-repeat: no-repeat;
  background-position: top;
  padding-top: calc(var(--s-12) + 2px); /* offset for accent line */
  padding-bottom: var(--s-12);
  margin-top: var(--s-20);
  background-color: var(--surface-sunken);
}

.site-footer__inner {
  display: grid;
  /* Mobile-first: single column */
  grid-template-columns: 1fr;
  gap: var(--s-6);
}

/* 2-column layout: Calculators + Learn side by side, About below, meta full-width */
@media (min-width: 380px) {
  .site-footer__inner {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--s-6) var(--s-8);
  }
  /* About col spans both columns at this size */
  .site-footer__col:nth-child(3) { grid-column: 1 / -1; }
  .site-footer__col--meta { grid-column: 1 / -1; }
}

/* 4-column layout on wide screens */
@media (min-width: 768px) {
  .site-footer__inner {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--s-8);
  }
  /* Reset overrides from the 380px block */
  .site-footer__col:nth-child(3) { grid-column: auto; }
  .site-footer__col--meta { grid-column: 1 / -1; }
}

@media (min-width: 900px) {
  .site-footer__col--meta { grid-column: span 2; }
}

/* Section labels in teal instead of muted gray */
.site-footer__heading {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--teal-700);
  margin-bottom: var(--s-3);
}

.site-footer__col ul li {
  /* Ensure at least 32px tap area on touch devices */
  padding-block: 4px;
  min-height: 32px;
  display: flex;
  align-items: center;
}

/* Links with underline-slide hover */
.site-footer__col a {
  color: var(--text-default);
  text-decoration: none;
  font-size: var(--fs-14);
  transition: color var(--motion-fast);
  position: relative;
  display: inline-block;
}
.site-footer__col a::after {
  content: '';
  position: absolute;
  left: 0; right: 100%; bottom: -1px;
  height: 1px;
  background: var(--teal-600);
  transition: right var(--motion-normal);
}
.site-footer__col a:hover { color: var(--teal-700); }
.site-footer__col a:hover::after { right: 0; }

.site-footer__editorial {
  font-size: var(--fs-13);
  color: var(--text-muted);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--s-2);
  max-width: 60ch;
  /* Prevent last-reviewed date from breaking awkwardly */
  word-break: normal;
  overflow-wrap: break-word;
}

.site-footer__editorial time {
  white-space: nowrap;
}

.site-footer__legal {
  font-size: var(--fs-12);
  color: var(--text-faint);
  margin-top: var(--s-4);
}

/* ====== 6.11  MOBILE STICKY RESULT CHIP ================================== */
/* Pinned to bottom of viewport on mobile while user scrolls form. */
/* Hydrated by calc.js -- hidden until result exists. */

.result-chip {
  position: fixed;
  left: 50%;
  /* Respect iOS home indicator: env(safe-area-inset-bottom) with 16px minimum gap */
  bottom: calc(var(--s-4) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-sticky);
  display: none;
  padding: var(--s-2) var(--s-5);
  background: var(--ink-800);
  color: var(--white);
  border-radius: var(--r-pill);
  font-size: var(--fs-14);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 20px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
  pointer-events: none;
  border: 1px solid var(--ink-700);
  animation: chipIn 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
  white-space: nowrap;
}

.result-chip.is-visible { display: inline-flex; align-items: center; gap: var(--s-2); }
.result-chip.is-hidden  { display: none !important; }

/* Reserve space at page bottom so sticky chip does not occlude content */
body:has(.result-chip.is-visible) {
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}

/* Calorie icon dot - teal accent before value */
.result-chip::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--teal-300);
  flex-shrink: 0;
}

.result-chip__value {
  font-weight: var(--fw-bold);
  font-size: var(--fs-15);
  color: var(--white);
}
/* Pulse when value updates */
@keyframes chipValuePulse {
  0%   { opacity: 1; }
  30%  { opacity: 0.4; transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}
.result-chip__value.is-updating {
  animation: chipValuePulse 200ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@media (prefers-reduced-motion: reduce) {
  .result-chip__value.is-updating { animation: none; }
}
.result-chip__label { color: var(--ink-400); font-size: var(--fs-12); font-weight: var(--fw-regular); }

@keyframes chipIn {
  from { opacity: 0; transform: translate(-50%, 10px) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .result-chip { animation: none; }
}

/* ====== 7. RESPONSIVE ==================================================== */

/* Phones -- stack calc fields */
@media (max-width: 640px) {
  :root { --gutter: var(--s-4); }

  .site-header__inner { gap: var(--s-3); }
  .site-nav__list { gap: var(--s-3); }
  .site-nav__link { font-size: var(--fs-13); }

  .hero { padding-block: var(--s-8) var(--s-4); }

  .calc { padding: var(--s-4); }
  .calc__row { grid-template-columns: 1fr; gap: var(--s-3); }

  .result__metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet -- show chip only on small screens where form scrolls past result */
@media (min-width: 768px) {
  .result-chip { display: none !important; }
}

/* ---- Embed iframe responsive -------------------------------------------- */
/*
  The iframe is served at variable widths by third-party publishers.
  Rules target the document inside iframe.php.
  Narrowest practical embed: 300px. Widest common: 1200px.
*/

/* Narrow embed (<=480px): full-width submit button, tighter padding */
@media (max-width: 480px) {
  .embed-wrap { padding: var(--s-3); }
  .embed-wrap .calc__submit,
  .embed-wrap .cta { width: 100%; }
}

/* Wide embed: cap the calculator at container--narrow width */
@media (min-width: 720px) {
  .embed-wrap .calc { max-width: 720px; margin-inline: auto; }
}

/* Embed landing page: code blocks scroll horizontally on narrow viewports */
.embed-code-block__pre {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Embed landing page iframe preview: fluid min-height */
.embed-preview-iframe {
  min-height: clamp(500px, 120vw, 780px);
}

/* ====== 8. PRINT ========================================================= */

@media print {
  body { background: white; color: black; }
  .site-header, .site-footer, .site-nav, .calc, .power-mode, .cta, .button { display: none !important; }
  .result {
    background: white !important;
    color: black !important;
    border: 1px solid #000;
  }
  .result__label, .result__metric-label, .result__unit, .result__share-status { color: #333 !important; }
  a { text-decoration: underline; color: #000; }
  a::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #555; }
}

/* ====== 9. ACCESSIBILITY ================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Disable quiz open animation */
  .quiz[open] { animation: none; }
  /* Disable FAQ reveal animation */
  .faq__item[open] .faq__answer { animation: none; }
  /* Disable PWA banner slide-in */
  .pwa-banner { animation: none; }
}

@media (prefers-contrast: more) {
  :root {
    --border-subtle:  var(--ink-400);
    --border-default: var(--ink-600);
    --border-strong:  var(--ink-700);
    --text-muted:     var(--ink-700);
    --text-subtle:    var(--ink-600);
    --text-faint:     var(--ink-500);
    --shadow-focus:   0 0 0 3px rgba(13, 148, 136, 0.65);
  }
  /* Stronger chevron and quiz choice borders */
  .faq__chevron { border-width: 2px; }
  .quiz__choice { border-width: 2px; }
  .pwa-banner   { border-width: 2px; }
}

/* Forced colors (Windows High Contrast) */
@media (forced-colors: active) {
  .result, .calc, .power-mode, .site-header, .site-footer {
    border: 1px solid CanvasText;
  }
  /* Buttons: explicit ButtonText / ButtonFace so they remain visible */
  .cta, .button {
    forced-color-adjust: none;
    background: ButtonFace;
    color: ButtonText;
    border: 2px solid ButtonText;
  }
  .cta:hover, .button:hover {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }
  .brand__mark, .calc__segmented input:checked + label {
    forced-color-adjust: none;
  }
  /* PWA install CTA button */
  .pwa-banner__cta {
    forced-color-adjust: none;
    background: ButtonFace;
    color: ButtonText;
    border: 2px solid ButtonText;
  }
  .pwa-banner__cta:hover {
    background: Highlight;
    color: HighlightText;
  }
  /* Quiz: ensure dialog border and checked-choice highlight survive */
  .quiz {
    border: 2px solid CanvasText;
  }
  .quiz__choice:has(input:checked) {
    outline: 2px solid Highlight;
    border-color: Highlight;
  }
  /* PWA banner */
  .pwa-banner { border: 1px solid CanvasText; }
  .pwa-banner__icon { forced-color-adjust: none; }
  /* FAQ chevron stays visible */
  .faq__chevron { forced-color-adjust: none; border-color: CanvasText; }
  /* Skip link preserves ink-on-white */
  .skip-link { forced-color-adjust: none; }
  /* Embed powered-by link */
  .embed-footer a { color: LinkText; }
}

/* Focus rings: catch-all for any interactive element that doesn't already
   declare :focus-visible. Uses --shadow-focus so the ring matches the teal
   design system. Border-radius set to a small value so it wraps inline text. */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--r-sm);
}

/* Inputs / selects / textareas use an outline instead of box-shadow so the
   ring isn't clipped by overflow:hidden parents. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: none;
  outline: 2px solid var(--teal-600);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ====== Life-stage page accents ====== */
/*
  Scope: applies only inside .lifestage--* wrappers in $intro_html.
  Never overrides global tokens; new tokens are private to this section.
  Mobile-first. No border-left/right side-stripes (BAN 1).
*/

:root {
  /* Accent tokens per life stage */
  --accent-pregnancy:          #e8845a;   /* warm coral, amber family */
  --accent-pregnancy-subtle:   #fdf0e8;   /* very light tint */
  --accent-pregnancy-text:     #8a3d18;   /* dark enough for text on subtle bg */
  --accent-pregnancy-hover:    #ab6142;   /* darkened accent: 4.65:1 on white, AA pass */

  --accent-breastfeeding:      #c97d3a;   /* golden peach, amber family */
  --accent-breastfeeding-subtle: #fef5e7;
  --accent-breastfeeding-text: #7a470f;
  --accent-breastfeeding-hover: #a4662f;  /* darkened accent: 4.65:1 on white, AA pass */

  --accent-perimenopause:      #0f766e;   /* deep teal-700 */
  --accent-perimenopause-subtle: #f0fdfa;
  --accent-perimenopause-text: #0d4d48;

  --accent-luteal:             #b8724a;   /* dusty amber-rose */
  --accent-luteal-subtle:      #fdf3ec;
  --accent-luteal-text:        #703e20;
  --accent-luteal-hover:       #a56642;   /* darkened accent: 4.59:1 on white, AA pass */

  --accent-pcos:               #b56020;   /* deep amber, warm clay */
  --accent-pcos-subtle:        #fdf2e5;
  --accent-pcos-text:          #6b3510;
}

/* ---- Base lifestage wrapper -------------------------------------------- */

.lifestage {
  margin-top: var(--s-8);
}

/* ---- Callout block: full border + tinted bg, no side-stripe ------------- */

.ls-callout {
  padding: var(--s-5) var(--s-6);
  border-radius: var(--r-lg);
  border: 1.5px solid currentColor;
  margin-bottom: var(--s-8);
}

.ls-callout__kicker {
  display: block;
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  margin-bottom: var(--s-3);
  opacity: 0.75;
}

.ls-callout__text {
  font-size: var(--fs-16);
  line-height: var(--lh-relaxed);
  font-weight: var(--fw-medium);
  max-width: 58ch;
}

/* Pregnancy callout */
.lifestage--pregnancy .ls-callout {
  background: var(--accent-pregnancy-subtle);
  color: var(--accent-pregnancy-text);
}

/* Breastfeeding callout */
.lifestage--breastfeeding .ls-callout {
  background: var(--accent-breastfeeding-subtle);
  color: var(--accent-breastfeeding-text);
}

/* Perimenopause callout */
.lifestage--perimenopause .ls-callout {
  background: var(--accent-perimenopause-subtle);
  color: var(--accent-perimenopause-text);
}

/* Luteal callout */
.lifestage--luteal .ls-callout {
  background: var(--accent-luteal-subtle);
  color: var(--accent-luteal-text);
}

/* PCOS callout */
.lifestage--pcos .ls-callout {
  background: var(--accent-pcos-subtle);
  color: var(--accent-pcos-text);
}

/* ---- Numbered next-steps list: accent-colored counters, no stripe ------- */

.ls-steps {
  counter-reset: ls-step;
  list-style: none;
  padding: 0;
  margin: var(--s-4) 0 var(--s-8);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.ls-steps li {
  counter-increment: ls-step;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: var(--s-3);
  align-items: baseline;
  font-size: var(--fs-15);
  line-height: var(--lh-relaxed);
}

.ls-steps li::before {
  content: counter(ls-step);
  font-size: var(--fs-18);
  font-weight: var(--fw-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.lifestage--pregnancy    .ls-steps li::before { color: var(--accent-pregnancy); }
.lifestage--breastfeeding .ls-steps li::before { color: var(--accent-breastfeeding); }
.lifestage--perimenopause .ls-steps li::before { color: var(--accent-perimenopause); }
.lifestage--luteal       .ls-steps li::before { color: var(--accent-luteal); }
.lifestage--pcos         .ls-steps li::before { color: var(--accent-pcos); }

/* ---- Sources / citations block: academic small-caps style --------------- */

.ls-sources {
  margin-top: var(--s-8);
  padding-top: var(--s-6);
  border-top: 1px solid var(--border-subtle);
}

.ls-sources__heading {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: var(--s-4);
}

.ls-sources__list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.ls-sources__list li {
  font-size: var(--fs-13);
  line-height: 1.6;
  color: var(--text-muted);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-sunken);
  border-radius: var(--r-md);
}

.ls-sources__list li cite {
  font-style: italic;
}

.ls-sources__list li .ls-source-journal {
  font-weight: var(--fw-semibold);
  font-variant: small-caps;
  letter-spacing: 0.03em;
}

/* Accent-tinted source blocks per stage */
.lifestage--pregnancy    .ls-sources__list li { background: var(--accent-pregnancy-subtle); }
.lifestage--breastfeeding .ls-sources__list li { background: var(--accent-breastfeeding-subtle); }
.lifestage--perimenopause .ls-sources__list li { background: var(--accent-perimenopause-subtle); }
.lifestage--luteal       .ls-sources__list li { background: var(--accent-luteal-subtle); }
.lifestage--pcos         .ls-sources__list li { background: var(--accent-pcos-subtle); }

/* ---- Cross-link cluster: pill row, not cards ---------------------------- */

.ls-crosslinks {
  margin-top: var(--s-8);
  padding-top: var(--s-6);
  border-top: 1px solid var(--border-subtle);
}

.ls-crosslinks__heading {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: var(--s-4);
}

.ls-crosslinks__list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.ls-crosslinks__list a {
  display: inline-block;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
}

/* Pill colors per stage */
.lifestage--pregnancy .ls-crosslinks__list a {
  background: var(--accent-pregnancy-subtle);
  color: var(--accent-pregnancy-text);
  border-color: var(--accent-pregnancy);
}
.lifestage--pregnancy .ls-crosslinks__list a:hover {
  background: var(--accent-pregnancy-hover);
  color: var(--white);
}

.lifestage--breastfeeding .ls-crosslinks__list a {
  background: var(--accent-breastfeeding-subtle);
  color: var(--accent-breastfeeding-text);
  border-color: var(--accent-breastfeeding);
}
.lifestage--breastfeeding .ls-crosslinks__list a:hover {
  background: var(--accent-breastfeeding-hover);
  color: var(--white);
}

.lifestage--perimenopause .ls-crosslinks__list a {
  background: var(--accent-perimenopause-subtle);
  color: var(--accent-perimenopause-text);
  border-color: var(--accent-perimenopause);
}
.lifestage--perimenopause .ls-crosslinks__list a:hover {
  background: var(--accent-perimenopause);
  color: var(--white);
}

.lifestage--luteal .ls-crosslinks__list a {
  background: var(--accent-luteal-subtle);
  color: var(--accent-luteal-text);
  border-color: var(--accent-luteal);
}
.lifestage--luteal .ls-crosslinks__list a:hover {
  background: var(--accent-luteal-hover);
  color: var(--white);
}

.lifestage--pcos .ls-crosslinks__list a {
  background: var(--accent-pcos-subtle);
  color: var(--accent-pcos-text);
  border-color: var(--accent-pcos);
}
.lifestage--pcos .ls-crosslinks__list a:hover {
  background: var(--accent-pcos);
  color: var(--white);
}

/* ---- Eyebrow glyph via CSS ::before on .hero__eyebrow ------------------- */
/* Pages inject body data-lifestage via a <script> in $intro_html -- */
/* Instead we use the .lifestage wrapper; glyphs are in the eyebrow text   */

/* ---- Sources: prevent long DOI/PMID strings from causing overflow ------- */
/* Unconditional -- overflow-wrap: anywhere is harmless at all viewports    */

.ls-sources__list li {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---- Prose adjustments inside .lifestage -------------------------------- */

.lifestage .prose h2 {
  margin-top: var(--s-10);
  margin-bottom: var(--s-3);
}

.lifestage .prose ul,
.lifestage .prose ol {
  padding-left: var(--s-5);
}

.lifestage .prose li {
  list-style: disc;
  margin-bottom: var(--s-2);
  line-height: var(--lh-relaxed);
  font-size: var(--fs-15);
}

.lifestage .prose ol li {
  list-style: decimal;
}

/* ---- Responsive adaptations -------------------------------------------- */
/*
  Tested viewports: 320, 375, 414, 600, 768, 1024, 1280.
  Global section 7 already sets --gutter: var(--s-4) at max-width 640px
  and handles .calc, .hero. Rules here are scoped to .lifestage--* only.
*/

/* Touch devices: ensure crosslink pills meet 44px minimum touch target */
@media (hover: none) and (pointer: coarse) {
  .ls-crosslinks__list a {
    padding-block: var(--s-3);   /* 12px top + 12px bottom + ~20px line-height = ~44px */
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* Narrow phones (<=480px): tighten callout padding, reduce step counter size */
@media (max-width: 480px) {
  .ls-callout {
    padding: var(--s-4) var(--s-4);   /* 16px all sides instead of 20px/24px */
  }

  .ls-callout__text {
    font-size: var(--fs-15);          /* step down one size on narrow viewports */
  }

  .ls-steps li::before {
    font-size: var(--fs-15);          /* match body text; stays in 2rem column cleanly */
  }

  /* Pills: full-width stack on very narrow screens */
  .ls-crosslinks__list {
    flex-direction: column;
  }

  .ls-crosslinks__list a {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
}

/* Between 480px and 640px: 2-column pill grid (wider narrow phones / small tablets) */
@media (min-width: 481px) and (max-width: 640px) {
  .ls-crosslinks__list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .ls-crosslinks__list a {
    text-align: center;
    justify-content: center;
    display: flex;
    align-items: center;
  }
}

/* ====== End Life-stage page accents ====== */
