@font-face {
  font-family: 'Space Grotesk';
  src: url('assets/fonts/space-grotesk-400-600.woff2') format('woff2');
  font-style: normal;
  font-weight: 400 600;
  font-display: optional;
}

@font-face {
  font-family: 'DM Serif Display';
  src: url('assets/fonts/dm-serif-display-regular.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: optional;
}

@font-face {
  font-family: 'DM Serif Display';
  src: url('assets/fonts/dm-serif-display-italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 400;
  font-display: optional;
}

/* ═══════════════════════════════════════
   DESIGN TOKENS — LIGHT (Cohere-inspired)
═══════════════════════════════════════ */
[data-theme="light"] {
  --page:         #ffffff;
  --bg:           #fafafa;
  --surface:      #ffffff;
  --surface2:     #f5f5f5;
  --surface3:     #eeeeee;
  --border:       #e5e5e5;
  --border-em:    #d9d9dd;
  --text:         #000000;
  --text2:        #212121;
  --text3:        #61616e;
  --text4:        #636372;
  --interact:     #1863dc;
  --interact-bg:  rgba(24,99,220,0.06);
  --prot:         #1863dc;
  --prot-soft:    #eef3fd;
  --fat:          #b45309;
  --fat-soft:     #fef3c7;
  --carb:         #166534;
  --carb-soft:    #dcfce7;
  --brand-accent: #1f5b24;
  --red:          #b00020;
  --red-soft:     #ffeef0;
  --warn:         #92400e;
  --warn-soft:    #fffbeb;
  --green:        #166534;
  --green-soft:   #dcfce7;
  --shadow-xs:    0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow:       0 2px 6px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.06);
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 22px;
}

/* ═══════════════════════════════════════
   DESIGN TOKENS — DARK
═══════════════════════════════════════ */
[data-theme="dark"] {
  --page:         #0d0d0f;
  --bg:           #111113;
  --surface:      #18181b;
  --surface2:     #1e1e22;
  --surface3:     #26262b;
  --border:       #2e2e34;
  --border-em:    #3d3d44;
  --text:         #fafafa;
  --text2:        #e4e4e7;
  --text3:        #a1a1aa;
  --text4:        #b3b3bc;
  --interact:     #5b9cf6;
  --interact-bg:  rgba(91,156,246,0.08);
  --prot:         #5b9cf6;
  --prot-soft:    rgba(91,156,246,0.10);
  --fat:          #f59e0b;
  --fat-soft:     rgba(245,158,11,0.10);
  --carb:         #4ade80;
  --carb-soft:    rgba(74,222,128,0.10);
  --brand-accent: #9ce6a5;
  --red:          #f87171;
  --red-soft:     rgba(248,113,113,0.10);
  --warn:         #fbbf24;
  --warn-soft:    rgba(251,191,36,0.10);
  --green:        #4ade80;
  --green-soft:   rgba(74,222,128,0.10);
  --shadow-xs:    0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --shadow:       0 2px 6px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.25);
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 22px;
}

/* ═══════════════════════════════════════
   BASE RESET
═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  height: 100%;
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* ═══════════════════════════════════════
   LAYOUT — FIXED VIEWPORT APP
═══════════════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── TOP BAR ── */
.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-name {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.3px;
  line-height: 1;
}
.brand-name em { font-style: italic; color: var(--brand-accent); }
.brand-tag {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Segment control */
.seg {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  padding: 5px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.15s;
  white-space: nowrap;
}

.seg-btn.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* Icon buttons */
.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--border-em); color: var(--text2); }

/* Ghost button (Cohere style) */
.ghost-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.ghost-btn:hover { color: var(--interact); border-color: var(--interact); }

/* ── WORKSPACE GRID ── */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 16px;
  padding: 16px 0;
}

/* ═══════════════════════════════════════
   LEFT PANEL — FORM
═══════════════════════════════════════ */
.form-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 0;
}

/* Internal scroll — thin track */
.form-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-em) transparent;
}
.form-scroll::-webkit-scrollbar { width: 3px; }
.form-scroll::-webkit-scrollbar-thumb { background: var(--border-em); border-radius: 99px; }

/* Section */
.sec {
  margin-bottom: 20px;
}
.sec:last-child { margin-bottom: 0; }

.sec-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

.sec-lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
}

.sec-action {
  font-size: 10px;
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s;
  padding: 0;
}
.sec-action:hover { color: var(--interact); }

/* ── Formula selector ── */
.formula-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Cohere-style ghost card — text always visible */
.f-card {
  position: relative;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s, background 0.18s;
  overflow: hidden;
}

.f-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.18s;
}

.f-card:hover {
  border-color: var(--border-em);
  background: var(--surface2);
}

.f-card.on {
  border-color: var(--interact);
  background: var(--interact-bg);
}

.f-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);           /* ALWAYS reads against bg */
  display: block;
  margin-bottom: 3px;
  line-height: 1.2;
}

.f-card.on .f-name {
  color: var(--interact);       /* blue accent when selected */
}

.f-desc {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text3);
  line-height: 1.4;
  display: block;
}

.f-card.on .f-desc {
  color: var(--text2);
}

/* Check dot */
.f-check {
  position: absolute;
  top: 10px; right: 10px;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-em);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s;
}

.f-check::after {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--interact);
  opacity: 0;
  transition: opacity 0.18s;
}

.f-card.on .f-check {
  border-color: var(--interact);
  background: var(--interact);
}

.f-card.on .f-check::after {
  background: #fff;
  opacity: 1;
}

/* ── Fields ── */
.fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.f-lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
}

.f-inp {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface2);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  width: 100%;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.f-inp:focus {
  border-color: var(--interact);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--interact-bg);
}

.f-inp.err {
  border-color: var(--red);
  background: var(--red-soft);
}

.f-inp::placeholder { color: var(--text4); }

.f-hint {
  font-size: 10px;
  color: var(--text3);
  font-style: italic;
}

.f-err {
  font-size: 10px;
  color: var(--red);
  font-weight: 500;
  display: none;
}

.f-err.show { display: block; }

/* Select */
.sel-wrap { position: relative; }
.sel-wrap select {
  padding: 9px 30px 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface2);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  width: 100%;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sel-wrap select:focus {
  border-color: var(--interact);
  box-shadow: 0 0 0 3px var(--interact-bg);
}
.sel-wrap::after {
  content: '';
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text3);
  pointer-events: none;
}

/* Height imperial */
.imp-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.imp-unit-wrap { display: flex; align-items: center; gap: 5px; }
.imp-unit-wrap input { flex: 1; }
.imp-u { font-size: 11px; color: var(--text3); font-weight: 500; }
.h-preview { font-size: 10px; color: var(--interact); font-weight: 500; min-height: 14px; }

/* LBM badge */
.lbm-strip {
  display: none;
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--prot-soft);
  border: 1px solid var(--prot);
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.lbm-strip.show { display: flex; }
.lbm-info { display: flex; flex-direction: column; gap: 2px; }
.lbm-lbl { font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--prot); }
.lbm-method { font-size: 10px; color: var(--text3); }
.lbm-val { font-family: 'DM Serif Display', serif; font-size: 22px; color: var(--prot); letter-spacing: -0.5px; }
.lbm-unit { font-size: 10px; color: var(--text3); }

/* ── Activity cards ── */
.act-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.act-card {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.act-card:hover {
  border-color: var(--border-em);
  background: var(--surface2);
}

.act-card.on {
  border-color: var(--interact);
  background: var(--interact-bg);
}

.act-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

.act-card.on .act-name { color: var(--interact); }

.act-det {
  font-size: 10px;
  color: var(--text3);
  display: block;
  line-height: 1.35;
}

.act-chip {
  display: inline-flex;
  align-items: center;
  margin-top: 7px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  font-family: 'Space Grotesk', monospace;
  color: var(--text3);
  background: var(--surface3);
  letter-spacing: 0.04em;
  transition: all 0.15s;
}

.act-card.on .act-chip {
  color: var(--interact);
  background: var(--interact-bg);
}

/* ── Goal cards ── */
.goal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.goal-card {
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.goal-card:hover {
  border-color: var(--border-em);
  background: var(--surface2);
}

.g-icon { font-size: 16px; line-height: 1; }
.g-name { font-size: 11px; font-weight: 600; color: var(--text); }
.g-sub  { font-size: 10px; color: var(--text3); }

.goal-card[data-g="maintain"].on { border-color: var(--interact); background: var(--interact-bg); }
.goal-card[data-g="maintain"].on .g-name { color: var(--interact); }

.goal-card[data-g="surplus"].on  { border-color: var(--green); background: var(--green-soft); }
.goal-card[data-g="surplus"].on  .g-name { color: var(--green); }

.goal-card[data-g="deficit"].on  { border-color: var(--fat); background: var(--fat-soft); }
.goal-card[data-g="deficit"].on  .g-name { color: var(--fat); }

/* Goal sub-panel */
.goal-sub {
  display: none;
  margin-top: 8px;
  padding: 13px 15px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.goal-sub.open { display: block; }
.gs-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.gs-lbl { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text3); }
.gs-num {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ── Sliders ── */
.slider-stack { display: flex; flex-direction: column; gap: 14px; }
.sl-item { display: flex; flex-direction: column; }
.sl-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sl-lbl { font-size: 12px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.sl-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sl-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.sl-num.auto-num {
  font-size: 10.5px;
  color: var(--text3);
}
.sl-num.pulse { animation: numPulse 0.4s ease; }
@keyframes numPulse { 0%,100%{transform:scale(1)} 40%{transform:scale(1.18)} }

input[type=range].rng {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 3px; border-radius: 99px;
  outline: none; border: none; cursor: pointer;
  background: linear-gradient(to right,
    var(--rc,#888) 0%,
    var(--rc,#888) var(--rv,0%),
    var(--border-em) var(--rv,0%),
    var(--border-em) 100%
  );
}

input[type=range].rng::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--rc,#888);
  box-shadow: var(--shadow-xs);
  cursor: grab;
  transition: transform 0.12s, box-shadow 0.15s;
}

input[type=range].rng:active::-webkit-slider-thumb {
  cursor: grabbing;
  transform: scale(1.2);
  box-shadow: 0 0 0 6px var(--interact-bg);
}

input[type=range].rng::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--rc,#888); cursor: grab;
}

input[type=range].rng::-moz-range-progress {
  background: var(--rc,#888); height: 3px; border-radius: 99px;
}

.rng-ends { display: flex; justify-content: space-between; margin-top: 4px; }
.rng-end { font-size: 10px; color: var(--text3); font-style: normal; }

.sl-item.dim { pointer-events: none; }
.sl-item.dim .sl-lbl,
.sl-item.dim .sl-num,
.sl-item.dim .rng-end { color: var(--text3); }
.carb-line { height: 3px; border-radius: 99px; background: var(--carb); margin: 8px 0 4px; opacity: 0.8; }

/* ═══════════════════════════════════════
   RIGHT PANEL — RESULTS
═══════════════════════════════════════ */
.results-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 0;
}

/* Empty state */
.r-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 32px;
  text-align: center;
  transition: opacity 0.2s;
}

.results-panel.live .r-empty { display: none; }

.r-empty-icon {
  width: 56px; height: 56px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}

.r-empty-title {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  color: var(--text);
  letter-spacing: -0.3px;
}

.r-empty-sub {
  font-size: 13px;
  color: var(--text3);
  line-height: 1.65;
  max-width: 280px;
}

/* Results content */
.r-live {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.results-panel.live .r-live { display: flex; }

/* Results header */
.r-hdr {
  flex-shrink: 0;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.r-title {
  font-family: 'DM Serif Display', serif;
  font-size: 22px;
  color: var(--text);
  letter-spacing: -0.4px;
  line-height: 1;
}

.r-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
  font-style: italic;
}

.r-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text3);
  white-space: nowrap;
}
.pill-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--interact); }

/* Copy button — Cohere ghost style */
.copy-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.copy-btn:hover { color: var(--interact); border-color: var(--interact); }
.copy-btn.ok { color: var(--green); border-color: var(--green); background: var(--green-soft); }

/* Carb warning */
.r-warn {
  flex-shrink: 0;
  display: none;
  margin: 12px 22px 0;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 11.5px;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid transparent;
  line-height: 1.5;
}
.r-warn.show { display: flex; }
.r-warn.ww { color: var(--warn); background: var(--warn-soft); border-color: rgba(146,64,14,0.15); }
.r-warn.wr { color: var(--red);  background: var(--red-soft);  border-color: rgba(176,0,32,0.15); }

/* Stats row */
.r-stats {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3,1fr);
  border-bottom: 1px solid var(--border);
}

.r-stat { padding: 14px 18px; border-right: 1px solid var(--border); }
.r-stat:last-child { border-right: none; }
.r-stat-lbl {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin-bottom: 7px;
}
.r-stat-val {
  font-family: 'DM Serif Display', serif;
  font-size: 30px;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
  transition: color 0.2s;
}
.r-stat-val.blink { animation: blink 0.35s ease; }
@keyframes blink { 0%,100%{opacity:1} 40%{opacity:0.4} }
.r-stat-unit { font-size: 10px; color: var(--text3); margin-top: 3px; }
.r-stat-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
}
.bg-maintain { background: var(--prot-soft);  color: var(--prot); }
.bg-surplus  { background: var(--green-soft); color: var(--green); }
.bg-deficit  { background: var(--fat-soft);   color: var(--fat); }

/* Donut + macros flex row */
.r-macro-row {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 18px 22px;
  overflow: hidden;
}

/* SVG Donut */
.donut-outer {
  position: relative;
  flex-shrink: 0;
  width: 140px;
  height: 140px;
}

.donut-outer svg {
  transform: rotate(-90deg);
}

.donut-center-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-kcal {
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.donut-unit {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin-top: 3px;
}

/* Macro rows */
.macro-rows {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.m-row {
  display: grid;
  grid-template-columns: 12px 90px 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.m-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.m-name { font-size: 11.5px; font-weight: 500; color: var(--text2); white-space: nowrap; }
.m-bar-bg { height: 4px; background: var(--surface3); border-radius: 99px; overflow: hidden; }
.m-bar { height: 100%; border-radius: 99px; transition: width 0.5s cubic-bezier(0.34,1.56,0.64,1); }
.m-g {
  font-family: 'DM Serif Display', serif;
  font-size: 19px;
  color: var(--text);
  letter-spacing: -0.3px;
  text-align: right;
  white-space: nowrap;
}
.m-g span { font-size: 11px; font-family: 'Space Grotesk', sans-serif; color: var(--text3); font-weight: 400; margin-left: 1px; }
.m-k { font-size: 10px; color: var(--text3); white-space: nowrap; text-align: right; min-width: 56px; }

/* Tips footer */
.r-tips {
  flex-shrink: 0;
  padding: 10px 22px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.r-tips-ico { font-size: 12px; flex-shrink: 0; margin-top: 1px; }
.r-tips-txt { font-size: 11px; color: var(--text3); line-height: 1.6; }
.r-tips-txt strong { color: var(--text2); font-weight: 600; }

/* ── FOOTER ── */
.footer {
  flex-shrink: 0;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 10px;
  color: var(--text4);
}

/* ═══════════════════════════════════════
   RESPONSIVE — MOBILE STACK
═══════════════════════════════════════ */
@media (max-width: 860px) {
  html, body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    padding: 0 14px 16px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 0 10px;
  }

  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .seg {
    flex: 1 1 220px;
    min-width: 0;
  }

  .seg-btn {
    flex: 1;
    text-align: center;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 10px 0 12px;
    min-height: auto;
  }

  .form-panel,
  .results-panel {
    min-height: auto;
  }

  .form-scroll {
    overflow: visible;
    padding: 16px;
  }

  .r-hdr,
  .r-macro-row,
  .r-tips {
    padding-left: 16px;
    padding-right: 16px;
  }

  .r-warn {
    margin-left: 16px;
    margin-right: 16px;
  }

  .r-macro-row {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    overflow: visible;
  }

  .donut-outer { margin: 0 auto; }

  .r-stats { grid-template-columns: 1fr; }
  .r-stat { border-right: none; border-bottom: 1px solid var(--border); }
  .r-stat:last-child { border-bottom: none; }

  .footer {
    line-height: 1.45;
    padding: 10px 6px 2px;
  }
}

@media (max-width: 480px) {
  .app { padding: 0 10px 14px; }

  .fields-row,
  .formula-grid,
  .act-grid,
  .goal-grid {
    grid-template-columns: 1fr;
  }

  .goal-card {
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
    gap: 8px;
    padding: 10px 12px;
  }

  .g-sub { margin-left: auto; }

  .r-hdr {
    flex-wrap: wrap;
    gap: 10px;
  }

  .copy-btn {
    width: 100%;
    justify-content: center;
  }

  .r-title { font-size: 20px; }
  .r-stat-val { font-size: 27px; }

  .m-row {
    grid-template-columns: 10px minmax(74px, 1fr) auto;
    grid-template-areas:
      'dot name grams'
      'bar bar kcal';
    gap: 6px 8px;
  }

  .m-dot { grid-area: dot; }
  .m-name { grid-area: name; }
  .m-bar-bg { grid-area: bar; }
  .m-g { grid-area: grams; font-size: 17px; }
  .m-k { grid-area: kcal; text-align: left; }

  .seg-btn { padding: 7px 8px; font-size: 10px; }
}

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
