/* ==========================================================================
   BMI Calculator — global stylesheet
   No external fonts, no frameworks. Mobile-first, ~1 network request.
   ========================================================================== */

:root {
  --brand: #0f9d76;
  --brand-dark: #0b7d5d;
  --brand-soft: #e6f6f1;
  --ink: #14201d;
  --body: #4a5a56;
  --muted: #6b7c78;
  --line: #e2e8e6;
  --bg: #ffffff;
  --bg-alt: #f6f9f8;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(16, 40, 34, .06), 0 8px 24px rgba(16, 40, 34, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1120px;
  --c-under: #3b82f6;
  --c-normal: #16a34a;
  --c-over: #eab308;
  --c-ob1: #f97316;
  --c-ob2: #ef4444;
  --c-ob3: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #2fc79b;
    --brand-dark: #24b189;
    --brand-soft: #12312a;
    --ink: #eef4f2;
    --body: #b6c4c0;
    --muted: #8b9b96;
    --line: #26332f;
    --bg: #0e1513;
    --bg-alt: #121b19;
    --card: #141d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .3);
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

/* Keep anchor jumps clear of the sticky header. */
[id] { scroll-margin-top: 84px; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 {
  color: var(--ink);
  line-height: 1.25;
  margin: 0 0 .6em;
  font-weight: 700;
  letter-spacing: -.015em;
}

h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1.1vw, 1.8rem); margin-top: 2.2rem; }
h3 { font-size: 1.15rem; margin-top: 1.6rem; }

p { margin: 0 0 1.05rem; }

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) a { color: var(--brand); }
}

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 760px; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 64px;
}
.logo {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 800; font-size: 1.06rem; color: var(--ink);
  letter-spacing: -.02em; text-decoration: none;
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  display: grid; place-items: center; color: #fff; font-size: .82rem; font-weight: 800;
}

.nav-toggle {
  display: inline-flex; flex-direction: column; justify-content: center; gap: 5px;
  width: 42px; height: 42px; padding: 0 10px;
  background: transparent; border: 1px solid var(--line); border-radius: 9px; cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--ink); border-radius: 2px; transition: transform .2s, opacity .2s; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav {
  display: none;
  position: absolute; left: 0; right: 0; top: 100%;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 8px 20px 16px;
}
.nav.open { display: block; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav li + li { border-top: 1px solid var(--line); }
.nav a {
  display: block; padding: 12px 2px; color: var(--ink); font-weight: 600; font-size: .97rem;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--brand-dark); text-decoration: none; }

@media (min-width: 860px) {
  .nav-toggle { display: none; }
  .nav {
    display: block; position: static; background: none; border: 0; padding: 0;
  }
  .nav ul { display: flex; align-items: center; gap: 4px; }
  .nav li + li { border-top: 0; }
  .nav a { padding: 8px 13px; border-radius: 8px; }
  .nav a:hover { background: var(--bg-alt); }
  .nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-dark); }
}

/* ---------- Hero ---------- */
.hero { padding: 44px 0 8px; text-align: center; }
.hero h1 { margin-bottom: .45em; max-width: 22ch; margin-left: auto; margin-right: auto; text-wrap: balance; }
@media (min-width: 700px) { .hero h1 { max-width: 26ch; } }
.hero .lede { font-size: 1.06rem; max-width: 640px; margin: 0 auto; color: var(--muted); }

/* ---------- Calculator ---------- */
.calc-shell {
  display: grid; gap: 20px; margin: 28px 0 8px;
}
@media (min-width: 900px) {
  .calc-shell { grid-template-columns: 1.05fr .95fr; align-items: start; }
}

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
@media (min-width: 640px) { .card { padding: 28px; } }

.unit-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: 11px; padding: 4px; margin-bottom: 20px;
}
.unit-switch button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 9px 8px; border-radius: 8px; font: inherit; font-size: .93rem; font-weight: 600;
  color: var(--muted); transition: background .15s, color .15s;
}
.unit-switch button[aria-selected="true"] {
  background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(16, 40, 34, .12);
}

.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: .84rem; font-weight: 700; color: var(--ink);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 7px;
}
.input-row { display: flex; gap: 10px; }
.input-row > * { flex: 1; }

input[type="number"], input[type="text"], input[type="email"], select, textarea {
  width: 100%; font: inherit; font-size: 1rem;
  padding: 11px 13px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

.suffix { position: relative; }
.suffix input { padding-right: 48px; }
.suffix span {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  font-size: .85rem; color: var(--muted); pointer-events: none; font-weight: 600;
}

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  text-transform: none; letter-spacing: 0; font-size: .95rem; margin: 0;
  text-align: center; padding: 11px 8px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--body); font-weight: 600;
  transition: border-color .15s, background .15s, color .15s;
}
.seg input:checked + label {
  border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark);
}
.seg input:focus-visible + label { outline: 3px solid var(--brand); outline-offset: 2px; }

.btn {
  display: inline-block; width: 100%; cursor: pointer;
  font: inherit; font-size: 1.02rem; font-weight: 700;
  padding: 13px 20px; border: 0; border-radius: var(--radius-sm);
  background: var(--brand); color: #fff; text-align: center;
  transition: background .15s, transform .06s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  font-size: .92rem; padding: 10px; margin-top: 10px;
}
.btn-ghost:hover { background: var(--bg-alt); color: var(--ink); }

.error {
  color: var(--c-obese); font-size: .9rem; font-weight: 600;
  margin: -6px 0 12px; display: none;
}
.error.show { display: block; }

/* ---------- Result ---------- */
.result { display: none; }
.result.show { display: block; }

.result-empty { color: var(--muted); font-size: .95rem; text-align: center; padding: 18px 0; }

.score { text-align: center; padding-bottom: 4px; }
.score .num {
  font-size: clamp(2.8rem, 2rem + 4vw, 4rem); font-weight: 800;
  color: var(--ink); line-height: 1; letter-spacing: -.03em;
}
.score .cat {
  display: inline-block; margin-top: 12px; padding: 6px 16px;
  border-radius: 999px; font-weight: 700; font-size: .95rem;
  background: var(--brand-soft); color: var(--brand-dark);
}
.score .cat[data-cat="under"] { background: #e0edff; color: #1d4ed8; }
.score .cat[data-cat="normal"] { background: #dcf5e4; color: #15803d; }
.score .cat[data-cat="over"] { background: #fdf3d0; color: #a16207; }
.score .cat[data-cat="ob1"] { background: #ffe8d4; color: #c2410c; }
.score .cat[data-cat="ob2"] { background: #fde3e3; color: #b91c1c; }
.score .cat[data-cat="ob3"] { background: #fbd5d5; color: #991b1b; }

.gauge { margin: 22px 0 6px; }
.gauge-bar {
  position: relative; height: 12px; border-radius: 999px; overflow: visible;
  background: linear-gradient(90deg,
    var(--c-under) 0 14%, var(--c-normal) 14% 32%,
    var(--c-over) 32% 50%, var(--c-ob1) 50% 70%,
    var(--c-ob2) 70% 90%, var(--c-ob3) 90% 100%);
}
.gauge-pin {
  position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--ink);
  transform: translate(-50%, -50%); left: 0;
  transition: left .45s cubic-bezier(.4, 0, .2, 1);
}
.gauge-scale {
  position: relative; height: 1.2em;
  font-size: .68rem; color: var(--muted); margin-top: 9px; font-weight: 600;
}
@media (min-width: 420px) { .gauge-scale { font-size: .74rem; } }
.gauge-legend {
  font-size: .74rem; color: var(--muted); margin-top: 4px; text-align: center;
}
.gauge-scale span {
  position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap;
}
.gauge-scale span:first-child { transform: none; }
.gauge-scale span:last-child { transform: translateX(-100%); }

.facts { list-style: none; margin: 22px 0 0; padding: 0; border-top: 1px solid var(--line); }
.facts li {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid var(--line); font-size: .95rem;
}
.facts .k { color: var(--muted); }
.facts .v { color: var(--ink); font-weight: 700; text-align: right; white-space: nowrap; }

.note {
  font-size: .86rem; color: var(--muted); margin-top: 16px;
  background: var(--bg-alt); border-radius: var(--radius-sm); padding: 12px 14px;
}

/* ---------- Content ---------- */
.section { padding: 12px 0 4px; }
.section-alt { background: var(--bg-alt); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-top: 48px; padding: 8px 0 36px; }

.prose ul, .prose ol { margin: 0 0 1.1rem; padding-left: 1.25rem; }
.prose li { margin-bottom: .45rem; }
.prose strong { color: var(--ink); }

.formula {
  background: var(--bg-alt); border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm); padding: 16px 18px; margin: 0 0 1.2rem;
  font-size: 1rem; color: var(--ink);
}
.formula code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95em; }

.notice {
  background: var(--bg-alt); border: 1px solid var(--line);
  border-left: 4px solid var(--c-over); border-radius: var(--radius-sm);
  padding: 14px 18px; margin: 0 0 1.3rem; font-size: .93rem;
}
.notice p:last-child { margin-bottom: 0; }

.cta {
  background: var(--brand-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 24px; margin: 2rem 0 0; text-align: center;
}
.cta h2 { margin-top: 0; }
.cta .btn { width: auto; padding-left: 32px; padding-right: 32px; }

.table-scroll { overflow-x: auto; margin: 0 0 1.4rem; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 460px; font-size: .95rem; }
caption { text-align: left; font-size: .85rem; color: var(--muted); padding-bottom: 8px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: var(--bg-alt); color: var(--ink); font-weight: 700; font-size: .84rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--bg-alt); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }

.grid-3 { display: grid; gap: 16px; margin: 0 0 1.4rem; }
@media (min-width: 700px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.mini {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px;
}
.mini h3 { margin-top: 0; font-size: 1.02rem; }
.mini p { margin: 0; font-size: .93rem; }

/* ---------- FAQ ---------- */
.faq { border-top: 1px solid var(--line); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary {
  cursor: pointer; list-style: none; padding: 16px 34px 16px 0; position: relative;
  font-weight: 700; color: var(--ink); font-size: 1rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+"; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font-size: 1.4rem; font-weight: 400; color: var(--brand); line-height: 1;
}
.faq details[open] summary::after { content: "\2013"; }
.faq details > div { padding: 0 0 16px; font-size: .96rem; }
.faq details > div p:last-child { margin-bottom: 0; }

/* ---------- Contact form ---------- */
.req { color: var(--c-ob2); font-weight: 700; }

.hp {
  position: absolute !important; left: -9999px !important;
  width: 1px; height: 1px; overflow: hidden;
}

.field-hint {
  display: block; font-size: .82rem; color: var(--muted);
  font-weight: 500; text-transform: none; letter-spacing: 0; margin-top: 6px;
}

.field-error {
  display: none; font-size: .85rem; color: var(--c-ob2);
  font-weight: 600; margin-top: 6px;
}
.field.invalid .field-error { display: block; }
.field.invalid input, .field.invalid textarea { border-color: var(--c-ob2); }

textarea { resize: vertical; min-height: 130px; line-height: 1.6; }

.btn[aria-busy="true"] { opacity: .7; cursor: progress; }

.form-status {
  display: none; margin-top: 16px; padding: 13px 16px;
  border-radius: var(--radius-sm); font-size: .94rem; font-weight: 600;
  border: 1px solid transparent;
}
.form-status.show { display: block; }
.form-status[data-state="ok"] {
  background: #dcf5e4; color: #15803d; border-color: #b6e6c6;
}
.form-status[data-state="err"] {
  background: #fde3e3; color: #b91c1c; border-color: #f6c4c4;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .form-status[data-state="ok"] {
    background: #102d1e; color: #6ee7a8; border-color: #1d4a33;
  }
  :root:not([data-theme="light"]) .form-status[data-state="err"] {
    background: #3a1416; color: #fca5a5; border-color: #5d2226;
  }
}

.checklist { list-style: none; padding-left: 0; }
.checklist li { position: relative; padding-left: 26px; }
.checklist li::before {
  content: ""; position: absolute; left: 4px; top: .62em;
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 56px; border-top: 1px solid var(--line);
  background: var(--bg-alt); padding: 36px 0 24px; font-size: .92rem;
}
.footer-grid { display: grid; gap: 26px; }
@media (min-width: 760px) { .footer-grid { grid-template-columns: 1.6fr 1fr 1fr; } }
.site-footer h4 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: .9em;
}
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: .5rem; }
.site-footer a { color: var(--body); }
.site-footer a:hover { color: var(--brand-dark); }
.footer-bottom {
  margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: .86rem;
  display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: space-between;
}

/* ---------- Page header for inner pages ---------- */
.page-head { padding: 40px 0 4px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.page-head p { color: var(--muted); margin-bottom: 1.4rem; }
.crumbs { font-size: .84rem; color: var(--muted); margin-bottom: 12px; }
.crumbs a { color: var(--muted); }

.placeholder {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 18px 20px; background: var(--bg-alt); color: var(--muted); font-size: .93rem;
}
.placeholder strong { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
