/* ============================================================
   CalorieLab — styles.css  (v2 — post senior-dev review)
   Fixes: mobile overflow, contrast, ARIA layout, ad spacing,
          canvas DPI, focus rings, reduced-motion, print
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────── */
:root {
  --bg:         #F0F4F8;
  --bg-card:    #FFFFFF;
  --bg-card-2:  #F7FAFC;
  --border:     #E2E8F0;
  --text:       #1A202C;
  --text-muted: #4A5568;
  --text-faint: #718096;

  --teal:       #00C49A;   /* slightly darkened for 4.5:1 on white */
  --teal-dim:   #009978;
  --teal-glow:  rgba(0,196,154,0.13);
  --coral:      #E85555;
  --amber:      #D4920A;   /* darkened for contrast on light bg */
  --navy:       #0A0F1E;
  --navy-mid:   #111827;

  --col-agg-loss: #C0392B;
  --col-loss:     #E74C3C;
  --col-mild-loss:#D4920A;
  --col-maintain: #00C49A;
  --col-mild-gain:#16A085;
  --col-bulk:     #2980B9;

  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 40px;
  --sp-2xl: 64px;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 220ms;

  /* header height for scroll-margin offset */
  --header-h: 70px;
}

[data-theme="dark"] {
  --bg:         #0A0F1E;
  --bg-card:    #111827;
  --bg-card-2:  #1A2235;
  --border:     #1F2D45;
  --text:       #E8F4F1;
  --text-muted: #94A3B8;
  --text-faint: #64748B;
  --teal:       #00D4AA;   /* can be brighter on dark bg */
  --teal-glow:  rgba(0,212,170,0.13);
  --amber:      #FFB347;
  --coral:      #FF6B6B;
  --col-agg-loss:#FF4444;
  --col-loss:    #FF6B6B;
  --col-mild-loss:#FFB347;
  --col-maintain:#00D4AA;
  --col-mild-gain:#4ECDC4;
  --col-bulk:    #45B7D1;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  /* offset anchors so sticky header doesn't cover them */
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color var(--duration) var(--ease),
              color var(--duration) var(--ease);
  min-height: 100vh;
}

img, canvas { display: block; max-width: 100%; }

a {
  color: var(--teal);
  text-decoration: none;
  transition: opacity var(--duration) var(--ease);
}
a:hover { opacity: 0.8; }
a:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ── Accessibility ─────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 16px;
  background: var(--teal);
  color: var(--navy);
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 700;
  z-index: 9999;
  transition: top 0.2s;
}
.skip-link:focus { top: 0; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  line-height: 1.2;
  font-weight: 700;
  color: var(--text);
}

h1 { font-size: clamp(1.9rem, 5vw, 3.2rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); margin-bottom: var(--sp-md); }
h3 { font-size: 1.2rem; margin-bottom: var(--sp-md); }
h4 { font-size: 1rem; }

p { color: var(--text-muted); }
p + p { margin-top: var(--sp-sm); }

/* ── Layout ─────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--sp-lg);
}

.main-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--sp-xl);
  padding-top: var(--sp-xl);
  padding-bottom: var(--sp-2xl);
  align-items: start;
}

@media (max-width: 960px) {
  .main-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ── Page wrapper (inner pages) ─────────────────────────── */
.page-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--sp-xl) var(--sp-lg) var(--sp-2xl);
}
.page-wrap h1 { margin-bottom: var(--sp-lg); }
.page-wrap h2 { font-size: 1.2rem; margin-top: var(--sp-xl); margin-bottom: var(--sp-sm); }
.page-wrap p  { margin-bottom: var(--sp-md); }
.page-wrap ul, .page-wrap ol {
  padding-left: var(--sp-xl);
  color: var(--text-muted);
  margin-bottom: var(--sp-md);
}
.page-wrap li { margin-bottom: var(--sp-sm); line-height: 1.7; }
.page-wrap a  { text-decoration: underline; }
.last-updated {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-bottom: var(--sp-xl);
  display: block;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(var(--bg-card), 0.95);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  height: var(--header-h);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-lg);
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text);
  flex-shrink: 0;
}
.logo strong { color: var(--teal); }
.logo-icon { font-size: 1.3rem; }

.header-nav {
  display: flex;
  gap: var(--sp-lg);
  margin-left: auto;
}
.header-nav a {
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: color var(--duration) var(--ease);
  white-space: nowrap;
}
.header-nav a:hover { color: var(--teal); opacity: 1; }

.header-actions { display: flex; gap: var(--sp-sm); flex-shrink: 0; }

.theme-toggle {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--duration) var(--ease),
              background var(--duration) var(--ease);
}
.theme-toggle:hover {
  border-color: var(--teal);
  background: var(--teal-glow);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

@media (max-width: 640px) {
  .header-nav { display: none; }
  .header-inner { gap: var(--sp-md); }
}

/* ── Ad Slots ──────────────────────────────────────────── */
/* FIX: ads are now siblings to header/main, never inside header */
.ad-slot { width: 100%; }
.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-2);
  border: 1px dashed var(--border);
  color: var(--text-faint);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: var(--font-display);
}
.ad-leaderboard .ad-placeholder { height: 90px; }
.ad-inline .ad-placeholder     { height: 90px; margin: var(--sp-xl) 0; border-radius: var(--radius-sm); }
.ad-sidebar .ad-placeholder    { height: 250px; border-radius: var(--radius-sm); }
.ad-footer .ad-placeholder     { height: 90px; }

/* Buffer above inline ads so they aren't adjacent to calculator output */
.ad-buffer { margin-top: var(--sp-xl); }

/* ── Hero ───────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #0A0F1E 0%, #0D1B2A 60%, #0A1628 100%);
  padding: var(--sp-2xl) 0;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -5%;
  width: 560px;
  height: 560px;
  background: radial-gradient(circle, rgba(0,212,170,0.07) 0%, transparent 70%);
  pointer-events: none;
}

.hero-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2xl);
}

.hero-content { flex: 1; min-width: 0; }

.hero-eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
  margin-bottom: var(--sp-md);
}

h1 em {
  font-style: normal;
  color: #00D4AA; /* always bright teal on dark hero */
}

/* FIX: hero-sub hardcoded rgba was invisible in light mode */
.hero-sub {
  font-size: 1rem;
  color: rgba(232,244,241,0.75);
  max-width: 480px;
  margin: var(--sp-lg) 0 var(--sp-xl);
  line-height: 1.75;
}

.hero-visual {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* FIX: canvas blurriness on HiDPI — set via JS after devicePixelRatio check */
#gaugeCanvas {
  filter: drop-shadow(0 0 20px rgba(0,212,170,0.25));
  width: 260px;
  height: 260px;
}

.gauge-labels {
  text-align: center;
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

.gauge-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 700;
  color: #00D4AA;
  line-height: 1;
}

.gauge-unit {
  display: block;
  font-size: 0.72rem;
  color: rgba(232,244,241,0.5);
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.gauge-label {
  display: block;
  font-size: 0.68rem;
  color: rgba(232,244,241,0.35);
  margin-top: 2px;
}

@media (max-width: 800px) {
  .hero-inner { flex-direction: column; text-align: center; }
  .hero-sub { margin-left: auto; margin-right: auto; }
  #gaugeCanvas { width: 200px; height: 200px; }
  .gauge-labels { bottom: 20px; }
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--duration) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  min-height: 44px; /* WCAG tap target */
}

.btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

.btn-primary {
  background: var(--teal);
  color: var(--navy);
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,196,154,0.28);
}
.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,196,154,0.38);
  opacity: 1;
}
.btn-primary:active { transform: translateY(0); }

.btn-full { width: 100%; padding: 14px 24px; font-size: 1rem; }

.btn-sm {
  background: var(--bg-card-2);
  border-color: var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 0.8rem;
  min-height: 36px;
}
.btn-sm:hover { border-color: var(--teal); color: var(--teal); opacity: 1; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-xl);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--sp-xl);
}

.calculator-card { margin-bottom: 0; }

.card-header {
  margin-bottom: var(--sp-xl);
  padding-bottom: var(--sp-lg);
  border-bottom: 1px solid var(--border);
}
.card-header p { font-size: 0.88rem; margin-top: var(--sp-sm); }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: var(--sp-lg); }

.form-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: var(--sp-sm);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-bottom: var(--sp-sm);
  line-height: 1.5;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-card-2);
  border: 2px solid var(--border); /* 2px for better visibility */
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px; /* touch target */
}
.form-input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}
.form-input::placeholder { color: var(--text-faint); }

/* FIX: only show invalid state after blur, not while typing */
.form-input.touched:invalid { border-color: var(--coral); }

.form-select {
  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' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

/* Pills */
.toggle-pills { display: flex; gap: var(--sp-sm); flex-wrap: wrap; }

.pill-label { flex: 1; min-width: 110px; cursor: pointer; }
.pill-label input[type="radio"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.pill-label span {
  display: block;
  text-align: center;
  padding: 10px 16px;
  background: var(--bg-card-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--duration) var(--ease);
  user-select: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pill-label input:checked + span {
  background: var(--teal-glow);
  border-color: var(--teal);
  color: var(--teal);
  font-weight: 700;
}
.pill-label:hover span { border-color: var(--teal); }
.pill-label input:focus-visible + span {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

.metric-input, .imperial-input {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}
.metric-input .form-input, .imperial-input .form-input { flex: 1; }
.input-unit { font-size: 0.85rem; font-weight: 600; color: var(--text-faint); white-space: nowrap; min-width: 28px; }
.input-pair { display: flex; align-items: center; gap: var(--sp-sm); flex: 1; }
.input-pair .form-input { flex: 1; min-width: 60px; }

.required { color: var(--coral); }
.optional-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--teal-glow);
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin-left: var(--sp-sm);
  vertical-align: middle;
}

.field-error {
  font-size: 0.8rem;
  color: var(--coral);
  margin-top: 5px;
  min-height: 20px;
  font-weight: 500;
}

/* ── Results ─────────────────────────────────────────────── */
.results-section {
  animation: slideUp 0.35s var(--ease) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* FIX: results-header must wrap on small screens */
.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-lg);
  flex-wrap: wrap;
  gap: var(--sp-md);
}

.results-actions {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Spotlight */
.spotlight-card {
  background: linear-gradient(135deg, rgba(0,196,154,0.1) 0%, rgba(0,196,154,0.02) 100%);
  border: 1px solid rgba(0,196,154,0.3);
  border-radius: var(--radius-xl);
  padding: var(--sp-xl);
  text-align: center;
  margin-bottom: var(--sp-xl);
  position: relative;
  overflow: hidden;
}
.spotlight-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--teal), transparent);
}

.spotlight-badge {
  display: inline-block;
  background: var(--teal);
  color: var(--navy);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 100px;
  margin-bottom: var(--sp-md);
}

.spotlight-method {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--sp-sm);
}

.spotlight-tdee {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-sm);
}

.spotlight-num {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 700;
  color: var(--teal);
  line-height: 1;
}

.spotlight-unit  { font-size: 1rem; color: var(--text-muted); }
.spotlight-label { font-size: 0.82rem; color: var(--text-faint); margin-bottom: var(--sp-sm); }
.spotlight-note  { font-size: 0.8rem; color: var(--teal); opacity: 0.85; }

/* Goals Grid */
/* FIX: 3 cols → 2 cols → 1 col cascade, no overflow at 320px */
.goals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-md);
  margin-bottom: var(--sp-xl);
}

@media (max-width: 600px) { .goals-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 360px) { .goals-grid { grid-template-columns: 1fr; } }

.goal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-md) var(--sp-sm);
  text-align: center;
  transition: transform var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}
.goal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.goal-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin-bottom: var(--sp-sm); }
.goal-val   { font-family: var(--font-display); font-size: clamp(1.2rem,3vw,1.5rem); font-weight: 700; margin-bottom: 4px; }
.goal-sub   { font-size: 0.65rem; color: var(--text-faint); line-height: 1.4; }

.goal-aggressive-loss .goal-val { color: var(--col-agg-loss); }
.goal-loss .goal-val            { color: var(--col-loss); }
.goal-mild-loss .goal-val       { color: var(--col-mild-loss); }
.goal-maintain {
  border-color: rgba(0,196,154,0.35);
  background: var(--teal-glow);
}
.goal-maintain .goal-val        { color: var(--col-maintain); }
.goal-mild-gain .goal-val       { color: var(--col-mild-gain); }
.goal-bulk .goal-val            { color: var(--col-bulk); }

/* Chart */
.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-xl);
  margin-bottom: var(--sp-xl);
}
.bar-chart-wrap { position: relative; height: 220px; }

/* Methods */
.methods-section { margin-bottom: var(--sp-xl); }
.section-sub { font-size: 0.88rem; color: var(--text-muted); margin-bottom: var(--sp-lg); }

.methods-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-md);
}
@media (max-width: 860px) { .methods-grid { grid-template-columns: 1fr; } }

.method-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}
.method-card.is-recommended {
  border-color: rgba(0,196,154,0.5);
  box-shadow: 0 0 0 1px rgba(0,196,154,0.18), var(--shadow-md);
}

.method-badge {
  display: inline-block;
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 3px 8px;
  border-radius: 100px;
  background: var(--bg-card-2);
  color: var(--text-faint);
  border: 1px solid var(--border);
  margin-bottom: var(--sp-sm);
}
.method-badge-primary { background: rgba(212,146,10,0.12); color: var(--amber); border-color: rgba(212,146,10,0.3); }
.method-badge-green   { background: var(--teal-glow); color: var(--teal); border-color: rgba(0,196,154,0.3); }

.method-name { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; margin-bottom: var(--sp-md); }

.method-bmr, .method-tdee {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--border);
}
.method-bmr-label, .method-tdee-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.method-bmr-val, .method-tdee-val {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--teal);
}

.method-formula { margin: var(--sp-md) 0; }
.formula-label  {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: var(--sp-sm);
}
.formula-code {
  display: block;
  font-family: 'Space Grotesk', monospace;
  font-size: 0.72rem;
  color: var(--teal);
  background: var(--teal-glow);
  border: 1px solid rgba(0,196,154,0.2);
  border-radius: var(--radius-sm);
  padding: var(--sp-sm);
  line-height: 1.6;
  word-break: break-word;
  /* FIX: prevent long strings from overflowing on narrow screens */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.method-desc { font-size: 0.8rem; color: var(--text-faint); line-height: 1.6; }

/* Macros */
.macro-section { margin-bottom: var(--sp-xl); }

/* FIX: macro tabs need a proper tablist wrapper for ARIA */
.macro-tablist {
  display: flex;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
  flex-wrap: wrap;
}
.macro-tab {
  background: var(--bg-card-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 16px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  min-height: 40px;
}
.macro-tab:hover { border-color: var(--teal); color: var(--text); }
.macro-tab[aria-selected="true"] {
  background: var(--teal-glow);
  border-color: var(--teal);
  color: var(--teal);
}
.macro-tab:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

.macro-tabpanel { /* role=tabpanel */ }

.macro-bar-container { margin-bottom: var(--sp-lg); }
.macro-bar {
  display: flex;
  height: 18px;
  border-radius: 100px;
  overflow: hidden;
  background: var(--border);
}
.macro-segment { height: 100%; transition: width 0.4s var(--ease); }
.macro-protein { background: var(--coral); }
.macro-carbs   { background: var(--amber); }
.macro-fat     { background: var(--teal); }

.macro-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-md); }
@media (max-width: 480px) { .macro-cards { grid-template-columns: 1fr; } }

.macro-card {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-md);
  text-align: center;
}
.macro-protein-card { border-top: 3px solid var(--coral); }
.macro-carbs-card   { border-top: 3px solid var(--amber); }
.macro-fat-card     { border-top: 3px solid var(--teal); }

.macro-icon  { font-size: 1.4rem; margin-bottom: var(--sp-sm); }
.macro-name  { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); margin-bottom: var(--sp-sm); text-transform: uppercase; letter-spacing: 0.05em; }
.macro-grams { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--text); }
.macro-kcal  { font-size: 0.78rem; color: var(--text-faint); margin-top: 2px; }
.macro-pct   { font-size: 0.73rem; color: var(--text-faint); margin-top: 2px; }

/* Extra Metrics */
.extra-metrics { margin-bottom: var(--sp-xl); }
.extra-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-md); }
@media (max-width: 480px) { .extra-grid { grid-template-columns: 1fr; } }

.extra-item {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-md);
  text-align: center;
}
.extra-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: var(--sp-sm); }
.extra-val   { font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.extra-sub   { font-size: 0.72rem; color: var(--text-faint); }

/* FIX: BMI badge shows shape + color, not just color */
.bmi-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  margin-top: 4px;
}
.bmi-under  { background: rgba(41,128,185,0.15); color: #2980B9; }
.bmi-normal { background: rgba(0,196,154,0.15);  color: var(--teal); }
.bmi-over   { background: rgba(212,146,10,0.15); color: var(--amber); }
.bmi-obese  { background: rgba(231,76,60,0.15);  color: var(--coral); }

.disclaimer {
  background: rgba(212,146,10,0.08);
  border: 1px solid rgba(212,146,10,0.25);
  border-radius: var(--radius-md);
  padding: var(--sp-md) var(--sp-lg);
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-top: var(--sp-xl);
}
.disclaimer strong { color: var(--amber); }

/* ── Learn Section ──────────────────────────────────────── */
.learn-section { margin-bottom: var(--sp-xl); }
.learn-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-lg);
  margin-top: var(--sp-lg);
}
@media (max-width: 640px) { .learn-grid { grid-template-columns: 1fr; } }

.learn-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-xl);
  transition: border-color var(--duration) var(--ease);
}
.learn-card:hover { border-color: var(--teal); }
.learn-icon { font-size: 1.8rem; margin-bottom: var(--sp-md); display: block; }
.learn-card h3 { margin-bottom: var(--sp-md); }
.learn-card p + p { margin-top: var(--sp-sm); }

.learn-list { list-style: none; display: flex; flex-direction: column; gap: var(--sp-sm); }
.learn-list li {
  padding: var(--sp-sm) var(--sp-md);
  background: var(--bg-card-2);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--text-muted);
  border-left: 3px solid var(--teal);
}

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: var(--sp-md);
  /* Horizontal scroll on very narrow screens */
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.activity-table th {
  text-align: left;
  padding: var(--sp-sm) var(--sp-md);
  background: var(--bg-card-2);
  font-family: var(--font-display);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.activity-table td {
  padding: var(--sp-sm) var(--sp-md);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.activity-table td:nth-child(2) {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--teal);
}

/* ── FAQ ────────────────────────────────────────────────── */
.faq-section { margin-bottom: var(--sp-xl); }
.faq-list { margin-top: var(--sp-lg); display: flex; flex-direction: column; gap: var(--sp-sm); }

.faq-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease);
}
.faq-item[open] { border-color: var(--teal); }

.faq-q {
  padding: var(--sp-md) var(--sp-lg);
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.93rem;
  color: var(--text);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: color var(--duration) var(--ease);
  gap: var(--sp-md);
}
.faq-q::-webkit-details-marker { display: none; }
.faq-q::after {
  content: '+';
  font-size: 1.3rem;
  color: var(--teal);
  font-weight: 300;
  flex-shrink: 0;
  transition: transform var(--duration) var(--ease);
}
.faq-item[open] .faq-q::after { transform: rotate(45deg); }
.faq-item[open] .faq-q { color: var(--teal); }

.faq-a { padding: 0 var(--sp-lg) var(--sp-lg); border-top: 1px solid var(--border); }
.faq-a p { padding-top: var(--sp-md); font-size: 0.88rem; line-height: 1.75; }

/* ── References ─────────────────────────────────────────── */
.references-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-xl);
  margin-bottom: var(--sp-xl);
}
.references-list {
  margin-top: var(--sp-md);
  padding-left: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}
.references-list li { font-size: 0.8rem; color: var(--text-muted); line-height: 1.65; }
.references-list em { font-style: italic; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar { display: flex; flex-direction: column; gap: var(--sp-lg); }
.sticky-ad { position: sticky; top: calc(var(--header-h) + 16px); }

.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
}
.sidebar-card h3 { font-size: 0.92rem; margin-bottom: var(--sp-md); }

.tips-list { list-style: none; display: flex; flex-direction: column; gap: var(--sp-sm); }
.tips-list li {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-left: var(--sp-md);
  position: relative;
  line-height: 1.5;
}
.tips-list li::before { content: '→'; position: absolute; left: 0; color: var(--teal); }

.density-list { display: flex; flex-direction: column; gap: var(--sp-sm); }
.density-item { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--text-muted); }
.density-low, .density-med, .density-high {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 100px;
}
.density-low  { background: rgba(0,196,154,0.12); color: var(--teal); }
.density-med  { background: rgba(212,146,10,0.12); color: var(--amber); }
.density-high { background: rgba(231,76,60,0.12); color: var(--coral); }

/* ── Trust Bar (inner pages) ────────────────────────────── */
.trust-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-md);
  padding: var(--sp-lg) 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-xl);
}
.trust-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.trust-item span:first-child { font-size: 1.1rem; }

/* ── Contact Form ───────────────────────────────────────── */
.contact-form { display: flex; flex-direction: column; gap: var(--sp-lg); margin-top: var(--sp-lg); }
.contact-form textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  padding: 12px 14px;
  background: var(--bg-card-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  transition: border-color var(--duration) var(--ease);
}
.contact-form textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

/* ── Team Cards (About) ─────────────────────────────────── */
.team-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-lg); margin: var(--sp-lg) 0; }
.team-card {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-lg);
  text-align: center;
}
.team-avatar { font-size: 2.5rem; margin-bottom: var(--sp-sm); }
.team-name   { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; }
.team-role   { font-size: 0.78rem; color: var(--teal); font-weight: 600; }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer { background: var(--bg-card); border-top: 1px solid var(--border); }

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--sp-xl);
  padding: var(--sp-xl) 0;
}

.footer-brand { flex: 1; min-width: 180px; }
.footer-brand .logo-text { font-family: var(--font-display); font-size: 1rem; }
.footer-brand p { font-size: 0.8rem; margin-top: var(--sp-sm); }

.footer-col { flex: 1; min-width: 130px; }
.footer-col h4 { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin-bottom: var(--sp-md); }
.footer-col ul { list-style: none; display: flex; flex-direction: column; gap: var(--sp-sm); }
.footer-col li a { font-size: 0.85rem; color: var(--text-muted); transition: color var(--duration) var(--ease); }
.footer-col li a:hover { color: var(--teal); opacity: 1; }

.footer-copy {
  width: 100%;
  font-size: 0.76rem;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-md);
  margin-top: var(--sp-sm);
  line-height: 1.7;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b;
  color: #f1f5f9;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  white-space: nowrap;
  border: 1px solid rgba(0,196,154,0.3);
  max-width: calc(100vw - 48px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Cookie Banner ──────────────────────────────────────── */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navy-mid, #111827);
  color: #e2e8f0;
  padding: var(--sp-md) var(--sp-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-md);
  z-index: 200;
  border-top: 1px solid rgba(0,196,154,0.3);
  font-size: 0.82rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}
.cookie-banner a { color: var(--teal); text-decoration: underline; }
.cookie-banner .btn-sm { background: var(--teal); color: var(--navy); border-color: var(--teal); font-weight: 700; }
.cookie-banner.hidden { display: none; }

/* ── Reduced Motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .results-section { animation: none; }
  html { scroll-behavior: auto; }
}

/* ── Print ──────────────────────────────────────────────── */
@media print {
  .site-header, .hero, .ad-slot, .sidebar, .faq-section,
  .references-section, .learn-section, .site-footer,
  .results-actions, .btn, .cookie-banner { display: none !important; }
  body { background: white; color: black; font-size: 12pt; }
  .card, .method-card, .goal-card { border: 1pt solid #ccc; box-shadow: none; }
  a[href]::after { content: ' (' attr(href) ')'; font-size: 10pt; color: #666; }
}

/* ============================================================
   DYNAMIC UPGRADE — scroll reveals, micro-interactions, idle motion
   Additive only. Reuses --ease / --duration tokens from :root above.
   Respects the prefers-reduced-motion block already defined above,
   since that rule zeroes all animation/transition durations globally.
   ============================================================ */

/* Scroll-reveal: elements fade + rise into place as they enter view */
.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
  will-change: opacity, transform;
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}
/* Stagger children of a revealed group for a cascading feel */
.reveal-group.is-visible .reveal-item:nth-child(1) { transition-delay: 0ms; }
.reveal-group.is-visible .reveal-item:nth-child(2) { transition-delay: 60ms; }
.reveal-group.is-visible .reveal-item:nth-child(3) { transition-delay: 120ms; }
.reveal-group.is-visible .reveal-item:nth-child(4) { transition-delay: 180ms; }
.reveal-group.is-visible .reveal-item:nth-child(5) { transition-delay: 240ms; }
.reveal-group.is-visible .reveal-item:nth-child(6) { transition-delay: 300ms; }

/* Sticky header gains depth once the page scrolls */
.site-header { transition: box-shadow var(--duration) var(--ease), border-color var(--duration) var(--ease); }
.site-header.is-scrolled {
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
  border-bottom-color: var(--teal);
}

/* Hero: gentle idle motion so the gauge doesn't sit dead-still pre-calculation */
.hero-visual { animation: heroFloat 6s ease-in-out infinite; position: relative; }
.hero-visual::before {
  content: "";
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--teal-glow) 0%, transparent 70%);
  animation: heroPulse 4s ease-in-out infinite;
  z-index: -1;
}
@keyframes heroFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
@keyframes heroPulse {
  0%, 100% { opacity: 0.5; transform: scale(0.96); }
  50%      { opacity: 0.9; transform: scale(1.04); }
}

/* Hero eyebrow rotation crossfade */
.hero-eyebrow { transition: opacity 0.4s var(--ease); }
.hero-eyebrow.is-swapping { opacity: 0; }

/* Tool/quick-link cards: shine sweep + consistent lift on hover, replacing inline JS handlers */
.tool-card {
  position: relative;
  overflow: hidden;
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.tool-card::after {
  content: "";
  position: absolute;
  top: 0; left: -60%;
  width: 40%; height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,0.10), transparent);
  transform: skewX(-20deg);
  transition: left 0.6s var(--ease);
  pointer-events: none;
}
.tool-card:hover::after { left: 130%; }
.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md, 0 12px 28px rgba(0,0,0,0.22));
}
.tool-card:active { transform: translateY(-1px) scale(0.99); }

/* Count-up number states — subtle pop when a value lands */
.count-target { display: inline-block; transition: transform 0.18s var(--ease); }
.count-target.is-landing { transform: scale(1.08); }

/* Button ripple */
.btn { position: relative; overflow: hidden; }
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transform: scale(0);
  animation: rippleOut 0.6s ease-out;
  pointer-events: none;
}
@keyframes rippleOut {
  to { transform: scale(2.6); opacity: 0; }
}

/* Goal cards: pop in with a slight cascade when results first render */
.goal-card { transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease); }
.goal-card:hover { transform: translateY(-3px); }

@media (prefers-reduced-motion: reduce) {
  .hero-visual, .hero-visual::before { animation: none; }
}
