.calc-page {
  width: min(1200px, calc(100% - 32px));
  margin: clamp(2rem, 6vw, 5rem) auto 4rem;
}

.calc-page h1 {
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  line-height: 1.05;
  margin-bottom: .75rem;
}

.calc-page h2 {
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  margin-block: 1.75rem 1rem;
}

.calc-page h3, .calc-page legend { font-weight: 650; }
.calc-muted, .calc-macro small { color: var(--muted); }
.calc-page [hidden] { display: none !important; }

.calc-card {
  min-width: 0;
  padding: clamp(.9rem, 3vw, 1.4rem);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.calc-quick { margin-top: 1.6rem; }
.calc-quick summary { cursor: pointer; font-weight: 650; }
.calc-quick form { margin-top: 1rem; }
.calc-page form { display: grid; gap: 1rem; }
.calc-page legend { padding-inline: .3rem; }
.calc-page label { display: grid; gap: .3rem; min-width: 0; }
.calc-page input, .calc-page select { accent-color: var(--accent); }
.calc-page :is(input[type="number"], select) {
  width: 100%;
  min-height: 44px;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
}

.calc-page :is(input, select, summary, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.calc-fields, .calc-segments { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.calc-fields { margin-top: .75rem; }
.calc-row { display: grid; gap: 1rem; }
.calc-row > * { min-width: 0; }
.calc-body-fields { margin-top: .75rem; }
.calc-body-slider { width: 100%; min-height: 32px; }
.calc-imperial-height { margin-top: 0; }
@media (min-width: 800px) {
  .calc-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.calc-segments label { position: relative; cursor: pointer; }
.calc-segments input { position: absolute; opacity: 0; }
.calc-segments span { padding: .65rem; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.calc-segments input:checked + span { border-color: var(--accent); color: var(--accent); }
.calc-segments input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.calc-range { display: grid; grid-template-columns: minmax(0, 1fr) 6rem; align-items: center; gap: .5rem; }
.calc-range input[type="range"] { grid-column: 1 / -1; width: 100%; }
.calc-page .calc-toggle { display: flex; align-items: center; gap: .6rem; margin-top: .75rem; }
.calc-toggle input { width: 1.2rem; height: 1.2rem; flex: none; }

.calc-page .calc-macro { display: grid; grid-template-columns: 1fr auto; align-items: center; margin-block: .7rem; }
.calc-protein { --macro: var(--accent); }
.calc-carbs { --macro: #51c99b; }
.calc-fat { --macro: #e49760; }
[data-theme="emerald"] .calc-carbs { --macro: #167054; }
[data-theme="emerald"] .calc-fat { --macro: #9b4e1f; }
.calc-macro output { color: var(--macro); font-weight: 700; }
.calc-macro input {
  appearance: none;
  grid-column: 1 / -1;
  width: 100%;
  height: 30px;
  background: transparent;
  cursor: pointer;
}
.calc-macro input::-webkit-slider-runnable-track {
  height: .65rem;
  border-radius: 99px;
  background: linear-gradient(to right, var(--macro) var(--fill), color-mix(in srgb, var(--macro) 25%, var(--surface)) var(--fill));
}
.calc-macro input::-webkit-slider-thumb {
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: -.3rem;
  border-radius: 50%;
  background: var(--macro);
}
.calc-macro input::-moz-range-track { height: .65rem; border-radius: 99px; background: color-mix(in srgb, var(--macro) 25%, var(--surface)); }
.calc-macro input::-moz-range-progress { height: .65rem; border-radius: 99px; background: var(--macro); }
.calc-macro input::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: 0; border-radius: 50%; background: var(--macro); }
.calc-macro small { grid-column: 2; }
.calc-macro small:empty { display: none; }
.calc-sum { text-align: center; }
.calc-error, .calc-sum.is-invalid { color: #ff9b9b; }
[data-theme="emerald"] :is(.calc-error, .calc-sum.is-invalid) { color: #a52323; }
.calc-error:empty { display: none; }

.calc-button, .calc-target {
  padding: .75rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: #10223a;
  font-weight: 700;
  text-align: center;
}
.calc-button { width: 100%; min-height: 44px; }
.calc-button[type="submit"] { width: auto; justify-self: center; }
.calc-button:hover { filter: brightness(.94); }
[data-theme="emerald"] :is(.calc-button, .calc-target) { color: white; }
.calc-target { font-size: clamp(1.25rem, 5vw, 1.75rem); }
#calc-result { display: grid; gap: .85rem; width: min(100%, 500px); margin-inline: auto; scroll-margin-top: 1rem; }
.calc-result-rows > div { display: flex; justify-content: space-between; gap: .75rem; padding-block: .35rem; }
.calc-result-rows dd { text-align: right; font-variant-numeric: tabular-nums; }
.calc-result-emphasis { border-top: 1px solid var(--line); font-weight: 700; }

@page { size: A4; margin: 0; background: #fff; }
@media print {
  html[data-theme] { color-scheme: light !important; background: #fff !important; }
  body.clean-preview { min-height: 0 !important; color: #142238 !important; background: #fff !important; }
  body > :not(main), .calc-page > :not(#calc-result):not(h1), #calc-print,
  body.clean-preview #site-footer.zf-unified-footer { display: none !important; }
  body.clean-preview { margin: 0 !important; }
  /* Physical padding survives the browser's "no margins" print preference. */
  main.calc-page { box-sizing: border-box; width: 210mm !important; max-width: 100%; margin: 0 !important; padding: 30mm !important; }
  .calc-page h1 { font-size: 28pt; line-height: 1.35; margin: 0 0 6mm; }
  .calc-page h2 { font-size: 15pt; line-height: 1.2; margin: 0 0 4mm; }
  .calc-page { font-size: 10.5pt; line-height: 1.45; }
  #calc-result .calc-card { padding: 4mm; border-radius: 3mm; }
  #calc-result .calc-target { padding: 4mm; font-size: 16pt; }
  #calc-result .calc-result-rows > div { padding-block: 1.2mm; }
  #calc-result { display: block; width: 100%; outline: none; }
  #calc-result > * { margin-block: .7rem; }
  #calc-result .calc-card { background: white; border-color: #d9e2ed; break-inside: avoid; }
  #calc-result .calc-target { background: white; color: #18549e; border: 1px solid #d9e2ed; }
  #calc-result .calc-muted { color: #475b73; }
}
