/* A1C Calculator: shared stylesheet (mobile-first) */

:root {
  --paper: #ffffff;
  --wash: #f4f6fa;
  --ink: #172036;
  --ink-2: #4a5368;
  --ink-3: #636b7f;
  --line: #dde2ec;
  --line-2: #c6cddb;
  --brand: #2742c4;
  --brand-ink: #1b2f96;
  --brand-wash: #eef1fd;
  --ok: #23885a;
  --ok-wash: #e2f3e9;
  --ok-ink: #17633f;
  --pre: #c98a17;
  --pre-wash: #fbf0d4;
  --pre-ink: #7d5404;
  --high: #c43c55;
  --high-wash: #fbe4e8;
  --high-ink: #992640;
  --radius: 12px;
  --radius-sm: 8px;
  --wrap: 1120px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
}

img, svg { max-width: 100%; height: auto; }

a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-ink); }

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

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; font-weight: 700; margin: 0 0 0.5em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
ul, ol { margin: 0 0 1rem; padding-left: 1.25rem; }
li { margin-bottom: 0.35rem; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }

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

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; color: #fff; }

/* Header (not sticky) */
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); }
.site-header .wrap {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 4px 20px; padding-top: 10px; padding-bottom: 10px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand svg { width: 28px; height: 28px; flex: none; }
.site-nav ul { display: flex; flex-wrap: wrap; gap: 0 18px; list-style: none; margin: 0; padding: 0; }
.site-nav li { margin: 0; }
.site-nav a {
  display: inline-block; padding: 6px 0; font-size: 0.95rem; font-weight: 500;
  color: var(--ink-2); text-decoration: none;
}
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--brand); }

/* Hero */
.hero { background: var(--wash); border-bottom: 1px solid var(--line); padding: 20px 0 28px; }
.hero-grid { display: grid; gap: 20px; }
.hero-intro > :last-child, .hero-extra > :last-child { margin-bottom: 0; }

.breadcrumb ol {
  display: flex; flex-wrap: wrap; gap: 4px; list-style: none;
  margin: 0 0 12px; padding: 0; font-size: 0.875rem; color: var(--ink-3);
}
.breadcrumb li { margin: 0; }
.breadcrumb li + li::before { content: "/"; margin-right: 4px; color: var(--line-2); }
.breadcrumb a { color: var(--ink-2); }

.lede { font-size: 1.05rem; color: var(--ink-2); max-width: 62ch; }

.byline { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 0.9rem; color: var(--ink-3); margin-bottom: 18px; }
.byline a { color: var(--ink); font-weight: 600; }

.key { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.key-title { font-weight: 650; font-size: 0.95rem; margin: 0 0 8px; }
.range-key { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.range-key li { display: flex; align-items: baseline; gap: 10px; margin: 0; font-size: 0.95rem; }
.range-key li::before {
  content: ""; flex: none; width: 10px; height: 10px; border-radius: 3px;
  transform: translateY(1px); background: var(--ok);
}
.range-key .rk-pre::before { background: var(--pre); }
.range-key .rk-high::before { background: var(--high); }
.range-key strong { font-variant-numeric: tabular-nums; }
.range-key span { color: var(--ink-2); }

.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.925rem; color: var(--ink-2); }
.facts li { position: relative; padding-left: 22px; margin: 0; }
.facts li::before {
  content: ""; position: absolute; left: 2px; top: 0.45em; width: 11px; height: 6px;
  border-left: 2px solid var(--brand); border-bottom: 2px solid var(--brand); transform: rotate(-45deg);
}

/* Calculator card */
.calc {
  background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 18px 16px; box-shadow: 0 1px 2px rgba(23, 32, 54, 0.06);
  scroll-margin-top: 16px;
}
.calc h2 { font-size: 1.15rem; margin: 0 0 4px; }
.calc-help { font-size: 0.925rem; color: var(--ink-2); margin-bottom: 14px; }

.field-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 8px; }
.field-label { font-weight: 600; font-size: 0.95rem; }
.unit-switch { border: 0; margin: 0; padding: 0; min-width: 0; }
.unit-options {
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px;
  background: var(--wash); border: 1px solid var(--line-2);
}
.unit-options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.unit-options label {
  padding: 6px 16px; border-radius: 999px; cursor: pointer;
  font-size: 0.9rem; font-weight: 600; color: var(--ink-2); min-height: 34px; display: inline-flex; align-items: center;
}
.unit-options input:checked + label { background: var(--paper); color: var(--brand); box-shadow: 0 0 0 1px var(--line-2); }
.unit-options input:focus-visible + label { outline: 3px solid var(--brand); outline-offset: 1px; }

.input-row { display: flex; gap: 8px; }
.input-unit { position: relative; flex: 1; min-width: 0; }
.input-unit input {
  width: 100%; min-height: 54px; padding: 10px 96px 10px 14px;
  font: inherit; font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
}
.input-unit input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(39, 66, 196, 0.2); }
.input-unit input[aria-invalid="true"] { border-color: var(--high); }
.input-unit .suffix {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-weight: 600; color: var(--ink-3); pointer-events: none;
}
.field-error { min-height: 1.4em; margin: 6px 0 0; font-size: 0.875rem; color: var(--high-ink); }

.btn {
  appearance: none; flex: none; min-height: 54px; margin: 0; padding: 0 18px;
  border: 0; border-radius: var(--radius-sm); background: var(--brand); color: #fff;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn:hover { background: var(--brand-ink); }

/* Result, styled like a lab result slip */
.result { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line-2); }
.result.is-stale { opacity: 0.45; }
.result-label { margin: 0; font-size: 0.9rem; color: var(--ink-2); }
.result-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.result-value { font-size: 2.6rem; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.result-unit { font-weight: 600; color: var(--ink-2); }
.result-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0 0 12px; }
.result-rows.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.result-rows > div { display: flex; flex-direction: column; justify-content: space-between; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--wash); }
.result-rows dt { font-size: 0.8rem; color: var(--ink-2); line-height: 1.35; }
.result-rows dd { margin: 2px 0 0; font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums; }

/* Range meter: the A1C scale from 4% to 10%+ */
.meter { position: relative; padding-top: 14px; }
.meter-track { display: flex; gap: 2px; height: 10px; }
.meter-track span { display: block; height: 100%; }
.seg-ok { flex: 1.7; background: var(--ok); border-radius: 5px 0 0 5px; }
.seg-pre { flex: 0.8; background: var(--pre); }
.seg-high { flex: 3.5; background: var(--high); border-radius: 0 5px 5px 0; }
.meter-pin {
  position: absolute; top: 0; width: 0; height: 0; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 10px solid var(--ink);
  transition: left 0.25s ease;
}
.meter-ticks { position: relative; height: 20px; margin-top: 4px; font-size: 0.75rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.meter-ticks span { position: absolute; top: 0; transform: translateX(-50%); }
.meter-ticks .t-min { left: 0; transform: none; }
.meter-ticks .t-pre { left: 28.33%; }
.meter-ticks .t-high { left: 41.67%; }
.meter-ticks .t-max { right: 0; left: auto; transform: none; }

.range-badge {
  display: flex; align-items: center; gap: 8px; margin: 8px 0 0; padding: 8px 12px;
  border-radius: var(--radius-sm); font-size: 0.95rem; font-weight: 650;
  background: var(--ok-wash); color: var(--ok-ink);
}
.range-badge::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--ok); }
.range-badge[data-range="pre"] { background: var(--pre-wash); color: var(--pre-ink); }
.range-badge[data-range="pre"]::before { background: var(--pre); }
.range-badge[data-range="high"] { background: var(--high-wash); color: var(--high-ink); }
.range-badge[data-range="high"]::before { background: var(--high); }
.range-badge .range-note { font-weight: 500; }
.result-note { margin: 10px 0 0; font-size: 0.85rem; color: var(--ink-3); }

/* Content layout */
.layout { display: grid; gap: 8px; padding-top: 24px; padding-bottom: 40px; }
.content { min-width: 0; }
.content > section { padding-top: 12px; scroll-margin-top: 16px; }
.content > section + section { margin-top: 22px; }
.content p, .content li { max-width: 72ch; }

.toc { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.toc summary {
  cursor: pointer; padding: 12px 16px; font-weight: 650; list-style-position: inside;
}
.toc ol { margin: 0; padding: 0 16px 14px 36px; font-size: 0.925rem; }
.toc li { margin-bottom: 4px; }
.toc a { color: var(--ink-2); text-decoration: none; }
.toc a:hover { color: var(--brand); text-decoration: underline; }

/* Calculator list */
.calc-list { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--line); }
.calc-list li { margin: 0; border-bottom: 1px solid var(--line); max-width: none; }
.calc-list a { display: block; padding: 12px 2px; text-decoration: none; }
.calc-list strong { display: block; color: var(--brand); font-size: 1rem; }
.calc-list span { display: block; color: var(--ink-2); font-size: 0.925rem; }
.calc-list a:hover strong { text-decoration: underline; }

/* Formula and steps */
.formula {
  margin: 0 0 1rem; padding: 12px 14px; overflow-x: auto;
  background: var(--brand-wash); border-left: 3px solid var(--brand); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1.02rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.formula var { font-style: normal; }
.steps { padding-left: 1.4rem; }
.steps li { padding-left: 4px; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 0 1.25rem; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
caption { caption-side: top; text-align: left; padding: 10px 12px; font-weight: 650; font-size: 0.9rem; color: var(--ink-2); border-bottom: 1px solid var(--line); }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { background: var(--wash); font-size: 0.85rem; font-weight: 650; color: var(--ink-2); }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 650; }
tbody th .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; background: var(--ok); }
tr[data-range="pre"] .dot { background: var(--pre); }
tr[data-range="high"] .dot { background: var(--high); }

/* Charts */
.chart { position: relative; margin: 0 0 1.25rem; padding: 12px 10px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.chart svg { display: block; width: 100%; touch-action: pan-y; }
.chart figcaption { margin: 6px 4px 0; font-size: 0.875rem; color: var(--ink-3); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; list-style: none; margin: 0 4px 8px; padding: 0; font-size: 0.85rem; color: var(--ink-2); }
.chart-legend li { display: flex; align-items: center; gap: 6px; margin: 0; }
.chart-legend li::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--ok-wash); box-shadow: inset 0 0 0 1px var(--ok); }
.chart-legend .lg-pre::before { background: var(--pre-wash); box-shadow: inset 0 0 0 1px var(--pre); }
.chart-legend .lg-high::before { background: var(--high-wash); box-shadow: inset 0 0 0 1px var(--high); }

.c-band-ok { fill: var(--ok-wash); }
.c-band-pre { fill: var(--pre-wash); }
.c-band-high { fill: var(--high-wash); }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-axis { stroke: var(--line-2); stroke-width: 1; }
.c-tick { fill: var(--ink-3); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.c-title { fill: var(--ink-2); font-size: 12px; font-weight: 600; font-family: var(--font); }
.c-line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--brand); stroke: var(--paper); stroke-width: 2; }
.c-dot.is-active { fill: var(--brand-ink); }
.c-note { fill: var(--ink); font-size: 12px; font-weight: 650; font-family: var(--font); }
.c-cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; visibility: hidden; }
.c-cross.is-visible { visibility: visible; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; opacity: 0;
  padding: 6px 9px; border-radius: 6px; background: var(--ink); color: #fff;
  font-size: 0.8rem; line-height: 1.35; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px));
  transition: opacity 0.12s;
}
.chart-tip.is-visible { opacity: 1; }

/* FAQ */
.faq { border-top: 1px solid var(--line); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 2px; cursor: pointer; list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary h3 { margin: 0; font-size: 1rem; }
.faq summary::after {
  content: ""; flex: none; width: 9px; height: 9px; margin-right: 4px;
  border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(45deg); transition: transform 0.15s;
}
.faq details[open] summary::after { transform: rotate(-135deg); }
.faq details > p { margin: 0 2px 14px; color: var(--ink-2); }

.sources { font-size: 0.925rem; color: var(--ink-2); padding-left: 1.4rem; }
.sources li { margin-bottom: 6px; }

.note {
  margin-top: 28px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--wash); border: 1px solid var(--line); font-size: 0.9rem; color: var(--ink-2);
}
.note p { margin: 0; }

/* Footer */
.site-footer { background: var(--wash); border-top: 1px solid var(--line); font-size: 0.925rem; color: var(--ink-2); }
.footer-top { display: grid; grid-template-columns: 1fr 1fr; gap: 28px 24px; padding-top: 36px; padding-bottom: 30px; }
.footer-brand { grid-column: 1 / -1; }
.footer-brand > p { margin: 12px 0 0; max-width: 44ch; }
.footer-review {
  display: inline-flex; align-items: center; gap: 12px; margin: 16px 0 0; padding: 10px 16px 10px 12px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); line-height: 1.35;
}
.footer-review::before {
  content: ""; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.footer-review-label { display: block; font-size: 0.8rem; color: var(--ink-3); }
.footer-review a { display: block; color: var(--ink); font-weight: 650; text-decoration: none; }
.footer-review a:hover { color: var(--brand); text-decoration: underline; }
.footer-title { margin: 0 0 12px; font-size: 0.95rem; font-weight: 700; color: var(--ink); }
.footer-col ul { display: grid; gap: 9px; list-style: none; margin: 0; padding: 0; }
.footer-col li { margin: 0; }
.footer-col a { color: var(--ink-2); text-decoration: none; }
.footer-col a:hover { color: var(--brand); text-decoration: underline; }
.footer-note { padding-top: 16px; padding-bottom: 16px; border-top: 1px solid var(--line); font-size: 0.85rem; color: var(--ink-3); }
.footer-note p { margin: 0; max-width: 90ch; }
.footer-bottom {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px;
  padding-top: 14px; padding-bottom: 22px; border-top: 1px solid var(--line); font-size: 0.875rem;
}
.footer-bottom p { margin: 0; }
.footer-bottom a { color: var(--ink); font-weight: 600; }

/* Content pages (About, policies) */
.hero-plain { padding: 20px 0 26px; }
.hero-plain h1 { margin-bottom: 0.4em; }
.hero-plain .lede { margin-bottom: 0; }
.page-body { padding-top: 28px; padding-bottom: 44px; }
.prose { max-width: 74ch; }
.prose > section + section { margin-top: 26px; }
.prose h2 { margin-top: 0; }
.prose h3 { margin-top: 1.2em; }
.prose .updated { color: var(--ink-3); font-size: 0.9rem; }
.reviewer {
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start;
  margin: 8px 0 18px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
  scroll-margin-top: 16px;
}
.reviewer-avatar {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand-wash); color: var(--brand); font-weight: 700; font-size: 1.1rem;
}
.reviewer h3 { margin: 0 0 2px; font-size: 1.1rem; }
.reviewer-role { margin: 0 0 10px; color: var(--ink-2); }
.reviewer dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 10px; font-size: 0.95rem; }
.reviewer dt { color: var(--ink-3); }
.reviewer dd { margin: 0; }
.reviewer p:last-child { margin-bottom: 0; }
.contact-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--wash); margin-bottom: 18px; }
.contact-card p { margin: 0 0 6px; }
.contact-card a { font-weight: 700; font-size: 1.1rem; }
@media (max-width: 559px) {
  .reviewer { grid-template-columns: 1fr; gap: 12px; }
  .reviewer dl { grid-template-columns: 1fr; gap: 0; }
  .reviewer dd + dt { margin-top: 8px; }
}

/* Larger screens */
@media (min-width: 720px) {
  .wrap { padding-left: 24px; padding-right: 24px; }
  .calc-list { grid-template-columns: 1fr 1fr; column-gap: 28px; }
  .calc { padding: 22px; }
  .footer-top { grid-template-columns: 1.5fr 1.3fr 1fr 1fr; gap: 28px 40px; }
  .footer-brand { grid-column: auto; }
}

@media (min-width: 900px) {
  h1 { font-size: 2.1rem; }
  h2 { font-size: 1.35rem; }
  .hero { padding: 30px 0 40px; }
  .hero-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 440px); grid-template-rows: auto 1fr; gap: 0 44px; align-items: start; }
  .hero-intro { grid-column: 1; grid-row: 1; padding-bottom: 20px; }
  .calc { grid-column: 2; grid-row: 1 / span 2; }
  .hero-extra { grid-column: 1; grid-row: 2; }
}

@media (min-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr) 260px; gap: 48px; padding-top: 32px; }
  .toc { grid-column: 2; grid-row: 1; position: sticky; top: 20px; align-self: start; }
  .content { grid-column: 1; grid-row: 1; }
}

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

@media print {
  .site-header, .site-nav, .toc, .btn, .site-footer { display: none; }
  .hero { background: none; }
}

/* Small screens: the chart scales down, so its text and marks scale up */
@media (max-width: 600px) {
  .c-tick, .c-title, .c-note { font-size: 21px; }
  .c-line { stroke-width: 3.5; }
  .c-dot { r: 7px; stroke-width: 3; }
}
