:root {
  --bg: #0a0f14;
  --bg-2: #0f1620;
  --card: #121b26;
  --card-2: #16212e;
  --line: #22303f;
  --text: #e7eef5;
  --muted: #93a4b6;
  --accent: #34d399;
  --accent-2: #22d3ee;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --protein: #4ade80;
  --carb: #60a5fa;
  --fat: #fbbf24;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 12% -8%, #10312b 0%, transparent 60%),
    radial-gradient(900px 520px at 92% 4%, #10263a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1180px, 92vw); margin: 0 auto; }

/* ---------- hero ---------- */
.hero { padding: 26px 0 6px; }
.brand { display: flex; gap: 16px; align-items: center; }
.logo {
  font-size: 34px; line-height: 1; color: var(--accent);
  filter: drop-shadow(0 0 14px rgba(52, 211, 153, .45));
}
.hero h1 {
  margin: 0; font-size: 30px; letter-spacing: -.5px;
  background: linear-gradient(90deg, #fff, var(--accent) 70%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { margin: 2px 0 0; color: var(--muted); font-size: 14.5px; }

/* ---------- layout: inputs on top, plan below ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 18px 0 40px;
}
#results { scroll-margin-top: 12px; }

.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 40px -28px rgba(0, 0, 0, .9);
}
.card + .card { margin-top: 18px; }
.card h2 {
  margin: 0 0 14px; font-size: 17px; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h2 { margin-bottom: 14px; }

.form-card { padding-bottom: 16px; min-width: 0; }

/* The four input groups sit side by side on wide screens so the whole form —
 * and the Calculate button — stays above the fold. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(310px, 100%), 1fr));
  gap: 14px;
  align-items: start;
}
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* Number inputs have an intrinsic minimum width and grid/flex children default
 * to min-width:auto, which used to push the whole page sideways on tablets and
 * phones. Let everything shrink to its cell. */
.form-grid > *,
.grid-2 > *,
.grid-3 > *,
.card-head > * { min-width: 0; }
input, select, label, output { min-width: 0; }

/* ---------- form ---------- */
fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d151e;
  margin: 0;
  padding: 12px 14px 14px;
  min-width: 0;
}
/* A normal in-flow heading inside the panel. (A floated legend makes the
 * following grid collapse to 0 width — do not reintroduce that.) */
legend {
  display: block;
  width: 100%;
  font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--accent); font-weight: 700; padding: 0 0 8px;
}
legend small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 460px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 380px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.unit { color: #64778b; font-weight: 400; }
output { color: var(--accent); font-weight: 700; }

input[type="number"], select {
  width: 100%; margin-top: 5px; padding: 9px 11px;
  background: #0c141d; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14.5px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input[type="number"]:focus, select:focus {
  outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, .16);
}
input[type="range"] { width: 100%; margin-top: 12px; accent-color: var(--accent); }
input[type="number"]::placeholder { color: #4c5d70; }

.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.hint b { color: #cfe0ee; }

.errors {
  border: 1px solid rgba(251, 113, 133, .45);
  background: rgba(251, 113, 133, .1);
  color: #ffd7dd; border-radius: 10px; padding: 10px 12px;
  font-size: 13px; margin: 14px 0 0;
}
.errors div + div { margin-top: 4px; }

.actions {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.btn {
  border: 1px solid var(--line); background: #16212e; color: var(--text);
  padding: 11px 16px; border-radius: 10px; font: 600 14px/1 inherit;
  cursor: pointer; transition: transform .12s, filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #05221b; border-color: transparent;
  flex: 0 0 auto; min-width: 230px; padding: 13px 20px; font-size: 15px;
  box-shadow: 0 10px 26px -14px rgba(52, 211, 153, .8);
}
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: 12.5px; }
@media (max-width: 520px) {
  .actions .btn.primary { flex: 1 1 100%; min-width: 0; }
}

/* Phones: the form is long, so keep the Calculate button floating at the bottom
 * of the viewport while the form is on screen. */
@media screen and (max-width: 700px) {
  .form-card { padding-bottom: 10px; }
  .actions {
    position: sticky; bottom: 0; z-index: 5;
    margin: 14px -20px 0; padding: 12px 20px;
    background: #0f1620;
    box-shadow: 0 -14px 22px -14px rgba(0, 0, 0, .95);
    border-radius: 0 0 var(--radius) var(--radius);
  }
}

/* ---------- stats ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
@media (max-width: 760px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .stats-grid { grid-template-columns: 1fr; } }

.stat {
  background: #0d151e; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; display: flex; flex-direction: column; gap: 2px;
  border-left: 3px solid var(--line);
}
.stat.tone-good { border-left-color: var(--good); }
.stat.tone-warn { border-left-color: var(--warn); }
.stat.tone-bad { border-left-color: var(--bad); }
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -.6px; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.stat-sub { font-size: 12px; color: var(--muted); }

.callout {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  background: #0d151e; border: 1px solid var(--line);
  font-size: 13.5px; color: #c6d5e3;
}
.callout strong { color: #eaf3fb; }
.warn-callout { border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .08); color: #ffe9b8; }

.micro-quick {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px;
}
.micro-quick span {
  background: #0d151e; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; color: var(--muted);
}
.micro-quick b { color: var(--accent); }

/* ---------- macros ---------- */
.macro-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .macro-cards { grid-template-columns: repeat(2, 1fr); } }
.macro-card {
  background: #0d151e; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column;
}
.macro-card span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.macro-card b { font-size: 22px; letter-spacing: -.5px; }
.macro-card em { font-style: normal; font-size: 12px; color: var(--muted); }
.macro-card.p b { color: var(--protein); }
.macro-card.c b { color: var(--carb); }
.macro-card.f b { color: var(--fat); }

.macro-rows { margin-top: 16px; display: grid; gap: 12px; }
.macro-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.macro-head b { color: var(--text); }
.macro-head em { font-style: normal; color: var(--muted); }
.bar { height: 9px; border-radius: 999px; background: #0a1119; border: 1px solid var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 999px; }

/* ---------- tables / micros ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.micro-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }

/* Phones: stack each nutrient as a small card so no column is cut off and the
 * table never needs sideways scrolling. */
@media screen and (max-width: 620px) {
  .micro-table { min-width: 0; }
  .micro-table thead { display: none; }
  .micro-table, .micro-table tbody, .micro-table tr, .micro-table td { display: block; width: 100%; }
  .micro-table tr { border-bottom: 1px solid #1a2632; padding: 9px 2px; }
  .micro-table tr:last-child { border-bottom: 0; }
  .micro-table td { border: 0; padding: 1px 12px; }
  .micro-table td.num { text-align: left; }
  .micro-table td.num::before { content: 'Target: '; color: var(--muted); font-weight: 400; }
  .micro-table td.src { font-size: 12px; }
}
.micro-table th {
  text-align: left; padding: 10px 12px; background: #0d151e;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.micro-table td { padding: 9px 12px; border-bottom: 1px solid #1a2632; vertical-align: top; }
.micro-table tr:last-child td { border-bottom: 0; }
.micro-table .num { text-align: right; white-space: nowrap; }
.micro-table .num b { color: var(--accent); }
.micro-table .src { color: var(--muted); font-size: 12.5px; }
.micro-note { font-size: 11.5px; color: var(--warn); margin-top: 3px; }

.flags { margin-top: 16px; }
.flags h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.flag {
  display: flex; gap: 10px; padding: 9px 12px; border-radius: 10px;
  background: #0d151e; border: 1px solid var(--line); font-size: 13px; margin-bottom: 8px;
}
.flag b { color: var(--accent); white-space: nowrap; }
.flag span { color: #c6d5e3; }

/* ---------- meal plan ---------- */
.day {
  border: 1px solid var(--line); border-radius: 12px; background: #0d151e;
  margin-bottom: 10px; overflow: hidden;
}
.day summary {
  cursor: pointer; padding: 12px 14px; display: flex; flex-wrap: wrap;
  gap: 6px 14px; align-items: baseline; list-style: none;
}
.day summary::-webkit-details-marker { display: none; }
.day summary::before { content: '▸'; color: var(--accent); margin-right: 6px; }
.day[open] summary::before { content: '▾'; }
.day-name { font-weight: 800; }
.day-macros { font-size: 12.5px; color: var(--muted); }
.day summary:hover { background: #101a24; }

.meals { padding: 4px 14px 14px; }
.meal { border-top: 1px dashed #22303f; padding: 12px 0; }
.meal-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.meal-head h5 { margin: 0; font-size: 14px; }
.meal-head h5 small { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.meal-kcal { font-size: 12px; color: var(--accent); white-space: nowrap; }
.items { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
@media (max-width: 560px) { .items { grid-template-columns: 1fr; } }
.items li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: #c6d5e3; border-bottom: 1px dotted #1e2a37; padding: 2px 0; }
.items b { color: var(--text); font-variant-numeric: tabular-nums; }
.topup {
  font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); border: 1px solid rgba(52, 211, 153, .4);
  border-radius: 999px; padding: 0 6px; margin-left: 5px; white-space: nowrap;
}

/* ---------- workouts ---------- */
.wday {
  border: 1px solid var(--line); border-radius: 12px; background: #0d151e;
  padding: 14px; margin-bottom: 12px;
}
.wday-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.wday-head h5 { margin: 0; font-size: 14.5px; }
.whint { font-size: 12px; color: var(--muted); }
.wbadge {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; font-weight: 800;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line);
}
.wbadge.strength { color: #05221b; background: var(--accent); border-color: transparent; }
.wbadge.cardio { color: #06202b; background: var(--accent-2); border-color: transparent; }
.wbadge.recovery { color: #2a1c02; background: var(--warn); border-color: transparent; }

.block { margin-top: 10px; }
.block-name { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: 4px; }
.block ul { margin: 0; padding-left: 18px; }
.block li { font-size: 13.5px; color: #c6d5e3; margin-bottom: 2px; }
.block-list { margin: 0; padding-left: 18px; }
.block-list li { font-size: 13.5px; color: #c6d5e3; margin-bottom: 8px; }
.block-list b { color: var(--accent); }

/* ---------- footer ---------- */
footer { padding: 0 0 46px; }
footer p { color: #6f8296; font-size: 12px; max-width: 820px; }
footer b { color: var(--muted); }

/* ---------- misc ---------- */
[hidden] { display: none !important; }

/* ---------- print ---------- */
@media print {
  body { background: #fff; color: #111; }
  .hero, .form-card, footer, .btn { display: none !important; }
  .layout { display: block; width: 100%; padding: 0; }
  #results, .card { break-inside: avoid; }
  .card { background: #fff; border: 1px solid #ccc; box-shadow: none; margin-bottom: 12px; }
  .stat, .macro-card, .day, .wday, .callout, .micro-quick span, .flag { background: #fff; border-color: #ccc; }
  .stat-value, .card h2, .macro-head b, .items b, .block li, .items li { color: #111; }
  .micro-table th { background: #f2f2f2; }
}
