:root {
  --ink: #17211f;
  --ink-2: #4a5754;
  --ink-3: #75817e;
  --line: #dfe5e3;
  --bg: #f6f7f5;
  --card: #ffffff;
  --brand: #165f52;
  --brand-2: #0f4a40;
  --brand-tint: #e7f1ee;
  --accent: #c2621b;
  --accent-tint: #fbefe5;
  --err: #b3261e;
  --err-tint: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 33, 31, .05), 0 6px 24px rgba(23, 33, 31, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--ink); background: var(--bg); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--ink-3); font-weight: 400; }
sup { font-size: .7em; line-height: 0; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 18px; height: 18px; border-radius: 5px; background: var(--brand); box-shadow: inset 0 -6px 0 rgba(255,255,255,.18); }
.top-link { color: var(--ink-2); text-decoration: none; font-size: 14px; }
.top-link:hover { color: var(--brand); }

/* intro */
.intro { padding: 22px 0 14px; }
h1 { font-size: 28px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 4px; }
.lede { margin: 0; color: var(--ink-2); max-width: 62ch; }

/* layout */
.tool { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form { padding: 20px; }
.results { padding: 22px; position: sticky; top: 16px; }

/* fields */
.field { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.field > label, legend, .label-row label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; padding: 0; }
.label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.label-row label { margin: 0; }
input[type=number], select {
  width: 100%; height: 46px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid #cfd8d5; border-radius: 10px; appearance: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
select:disabled { color: var(--ink-3); background-color: #f1f3f2; }
input[type=number]:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22, 95, 82, .16); }
input[aria-invalid=true] { border-color: var(--err); box-shadow: 0 0 0 3px rgba(179, 38, 30, .12); }
input[type=number]::-webkit-inner-spin-button { opacity: .4; }
.input-unit { position: relative; }
.input-unit input { padding-right: 44px; font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; }
.suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--ink-3); }
.err { margin: 6px 0 0; font-size: 13px; color: var(--err); background: var(--err-tint); padding: 6px 10px; border-radius: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* segmented controls */
.seg { display: flex; background: #eef1f0; border-radius: 10px; padding: 3px; gap: 3px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label, .seg button {
  flex: 1; text-align: center; padding: 0 10px; height: 40px; line-height: 40px; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 15px; font-weight: 500; color: var(--ink-2); border: 0; background: transparent; margin: 0; white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg input:checked + label, .seg button[aria-pressed=true] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(23,33,31,.12); }
.seg input:focus-visible + label, .seg button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.seg input:disabled + label { color: var(--ink-3); cursor: not-allowed; }
.seg-sm { width: 96px; }
.seg-sm button { height: 28px; line-height: 28px; font-size: 13px; padding: 0 6px; }
.rate { margin-top: 10px; }
.rate label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }

/* BCS picker */
.bcs { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.bcs input { position: absolute; opacity: 0; pointer-events: none; }
.bcs label {
  height: 42px; display: flex; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; margin: 0;
  font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); border: 1px solid transparent;
  transition: background .15s, color .15s, transform .1s;
}
.bcs label:nth-of-type(-n+3) { background: #eef0f6; }
.bcs label:nth-of-type(n+4):nth-of-type(-n+5) { background: var(--brand-tint); }
.bcs label:nth-of-type(n+6) { background: var(--accent-tint); }
/* :nth-of-type(n) lifts specificity above the 4–5 band rule so the selected score is always dark */
.bcs input:checked + label:nth-of-type(n) { background: var(--ink); color: #fff; }
.bcs input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.bcs label:active { transform: scale(.96); }
.bcs-scale { display: grid; grid-template-columns: 3fr 2fr 4fr; font-size: 11px; color: var(--ink-3); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }
.bcs-scale span:nth-child(2) { text-align: center; }
.bcs-scale span:nth-child(3) { text-align: right; }
.bcs-info { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: #f7f8f7; border: 1px solid var(--line); }
.bcs-name { margin: 0; font-weight: 700; font-size: 14px; }
.bcs-name[data-band=ideal] { color: var(--brand); }
.bcs-name[data-band=over] { color: var(--accent); }
.bcs-name[data-band=under] { color: #3d4f8a; }
.bcs-desc { margin: 2px 0 0; font-size: 14px; color: var(--ink-2); min-height: 2.9em; }

.food-row { display: grid; grid-template-columns: 1fr 150px; gap: 8px; }

.go {
  width: 100%; height: 52px; border: 0; border-radius: 12px; background: var(--brand); color: #fff;
  font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; letter-spacing: .01em;
  transition: background .15s, transform .1s;
}
.go:hover { background: var(--brand-2); }
.go:active { transform: scale(.985); }
.go:focus-visible { outline: 3px solid rgba(22,95,82,.35); outline-offset: 2px; }

/* results */
.results.pop { animation: pop .22s ease-out; }
.results.stale > :not(.stale-note) { opacity: .45; }
.stale-note { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--err-tint); color: var(--err); font-size: 14px; font-weight: 600; }
.ghost:disabled { opacity: .5; cursor: not-allowed; }
@keyframes pop { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.hero-num { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.big { margin: 0; font-size: 56px; line-height: 1; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: var(--ink); }
.big-label { margin: 6px 0 0; font-weight: 600; color: var(--ink-2); }
.basis { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); }
.portion { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--brand-tint); font-size: 15px; }
.portion strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.hint-box { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-tint); font-size: 14px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 4px 0 0; }
.stats > div { padding: 14px 0; border-bottom: 1px solid var(--line); }
.stats > div:nth-child(odd) { padding-right: 12px; }
.stats > div:nth-child(even) { padding-left: 12px; border-left: 1px solid var(--line); }
.stats dt { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.stats dd { margin: 2px 0 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dd.sub { font-size: 12px; font-weight: 400; color: var(--ink-3); }
.caveat { font-size: 13px; color: var(--ink-3); margin: 12px 0 0; }

.schedule { margin-top: 20px; padding-top: 18px; border-top: 2px solid var(--accent); }
.s-title { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.s-summary { margin: 4px 0 10px; color: var(--ink-2); }
.s-summary strong { color: var(--accent); font-size: 20px; }
.chart { height: 120px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .area { fill: var(--accent-tint); opacity: .8; }
.chart .path { fill: none; stroke: var(--accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart .goal-line { stroke: var(--brand); stroke-width: 1.5; stroke-dasharray: 5 5; vector-effect: non-scaling-stroke; }
.chart .dot { fill: #fff; stroke: var(--accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart .dot.end { stroke: var(--brand); fill: var(--brand); }
.goal-key { color: var(--brand); font-weight: 600; }
.goal-key::before { content: ""; display: inline-block; width: 14px; border-top: 2px dashed var(--brand); vertical-align: middle; margin-right: 6px; }
.chart-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin: 6px 0 12px; font-variant-numeric: tabular-nums; }
.table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: #f7f8f7; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.goal-row td { font-weight: 700; color: var(--brand); background: var(--brand-tint); }

.copy-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.ghost { height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid #cfd8d5; background: #fff; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s; }
.ghost:hover { border-color: var(--brand); }
.ghost.ok { border-color: var(--brand); background: var(--brand-tint); }
.ghost:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.copy-status { font-size: 13px; color: var(--brand); font-weight: 600; }

/* article */
.prose { max-width: 70ch; padding: 40px 0 20px; }
.prose h2 { font-size: 22px; letter-spacing: -.01em; margin: 32px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 17px; margin: 20px 0 4px; }
.prose p { margin: 0 0 12px; color: #2c3735; }
.formula { font-size: 20px; font-weight: 700; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand); padding: 12px 16px; border-radius: 8px; }
.factors { background: var(--card); }
.prose .table-wrap { max-height: none; margin-bottom: 12px; }
.source { font-size: 14px; color: var(--ink-2); }
.disclaimer { font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 20px; }
.foot { border-top: 1px solid var(--line); padding: 18px 0 28px; font-size: 13px; color: var(--ink-3); }

/* mobile */
@media (max-width: 860px) {
  .tool { grid-template-columns: 1fr; }
  .results { position: static; }
}
@media (max-width: 480px) {
  .wrap { padding: 0 14px; }
  h1 { font-size: 24px; }
  .lede { font-size: 15px; }
  .form, .results { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .bcs { gap: 3px; }
  .bcs label { height: 44px; }
  .big { font-size: 48px; }
  .stats dd { font-size: 18px; }
  th, td { padding: 8px 10px; }
  .table-wrap { max-height: none; }
  .food-row { grid-template-columns: 1fr 124px; }
  .food-row select { padding: 0 26px 0 10px; background-position: calc(100% - 14px) 20px, calc(100% - 9px) 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
