:root {
  --color-brand: #0e7c84;
  --color-brand-soft: #d3ecee;
  --color-brand-dark: #0a4d52;
  --color-bg: #faf7f2;
  --color-card: #ffffff;
  --color-text: #14171a;
  --color-muted: #4a4f55;
  --color-border: #e2dcd1;
  --color-danger: #b91c1c;
  --color-placeholder: #6b7076;
  --color-surface-2: #f3f1ec;
  --color-disabled-bg: #dbe3e4;
  --color-disabled-text: #4f5b5e;

  /* Tinted surfaces for call-outs: background, hairline border. */
  --color-info-bg: #f1f8f9;
  --color-info-border: #c5dfe2;
  --color-notice-bg: #fff8e8;
  --color-notice-border: #e4b96b;
  --color-notice-ink: #7a3a00;
  --color-warn-bg: #fff4e5;
  --color-warn-border: #f2c998;
  --color-danger-bg: #fdecec;
  --color-danger-border: #f1b5b5;
  --color-ok-bg: #e7f6ef;
  --color-ok-border: #a9dcc3;

  /* Tier colours carry icons and bands (3:1 against white). The -strong
     pair is for small white text on a tier fill or tier-coloured text on
     white (4.5:1). */
  --tier-green: #059669;
  --tier-green-strong: #047857;
  --tier-yellow: #f59e0b;
  --tier-orange: #ea580c;
  --tier-orange-strong: #c2410c;
  --tier-red: #dc2626;
  --tier-gray: #6b7280;

  color-scheme: light;
  accent-color: var(--color-brand);
  caret-color: var(--color-brand);

  /* One design pixel of text. Every font-size is a multiple of this, so the
     whole type scale follows the reader's text-size setting. 1px at the
     default setting; bounded so layouts hold at the extremes. */
  --px: clamp(0.88px, calc(1rem / 16), 1.6px);
}

/* On iPhone and iPad the root font follows the Larger Text setting (17px at
   the default size, so the divisor differs). The touch-callout test keeps
   this off the Mac, where the same keyword means a 13px desktop font. */
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  :root {
    font: -apple-system-body;
    --px: clamp(0.88px, calc(1rem / 17), 1.6px);
  }
}

* { box-sizing: border-box; }

/* The `hidden` HTML attribute must win over any author display rule
   (.modal-backdrop and .emergency-overlay both set display:flex). */
[hidden] { display: none !important; }

::selection { background: var(--color-brand-soft); color: var(--color-brand-dark); }
::placeholder { color: var(--color-placeholder); opacity: 1; }

/* Present for screen readers, absent from the layout. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, ui-sans-serif, system-ui, sans-serif;
  font-size: calc(16 * var(--px));
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);
}

/* Keyboard focus must be visible everywhere. */
:focus-visible {
  outline: 3px solid var(--color-brand);
  outline-offset: 2px;
}

/* TOP BAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: calc(17 * var(--px)); color: var(--color-brand); }
.link-button {
  text-decoration: none;
  background: none; border: none;
  color: var(--color-brand);
  font-size: calc(14 * var(--px));
  cursor: pointer;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 6px 4px;
  min-height: 44px;
  font-family: inherit;
}
.link-button:active { opacity: 0.6; }
.link-button.danger-link { color: var(--color-danger); }
.caret { font-size: calc(18 * var(--px)); line-height: 1; }
.caret-back { font-size: calc(22 * var(--px)); line-height: 1; margin-right: 2px; }

/* VIEWS */
.view { flex: 1; padding: 18px 16px 24px; }
.view h1 {
  font-size: calc(24 * var(--px));
  margin: 4px 0 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.view h2 {
  font-size: calc(14 * var(--px));
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin: 24px 0 8px;
}
.view h3 { font-size: calc(16 * var(--px)); margin: 16px 0 6px; }
/* Section heading inside a card: an h2 in the outline, sized like body-level headings. */
.view .card-heading {
  font-size: calc(16 * var(--px));
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--color-text);
  margin: 16px 0 6px;
}
.card > .card-heading:first-child, .lab-result-header .card-heading { margin-top: 0; }
.lab-result-header .card-heading { margin-bottom: 0; }
.muted { color: var(--color-muted); }
.small { font-size: calc(13 * var(--px)); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: calc(12 * var(--px)); }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

/* CHIPS */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: calc(15 * var(--px));
  cursor: pointer;
  user-select: none;
  transition: transform 0.04s ease;
  min-height: 44px;
  font-family: inherit;
}
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"] {
  border-color: var(--color-brand);
  background: var(--color-brand-soft);
  color: var(--color-brand-dark);
  font-weight: 600;
}

/* BUTTONS */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.primary-button {
  width: 100%;
  background: var(--color-brand);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: calc(16 * var(--px));
  font-weight: 600;
  cursor: pointer;
  min-height: 52px;
  font-family: inherit;
  text-align: center;
  display: inline-block;
  text-decoration: none;
}
.primary-button:active:not(:disabled) { background: var(--color-brand-dark); }
.primary-button:disabled {
  background: var(--color-disabled-bg);
  color: var(--color-disabled-text);
  cursor: not-allowed;
}
.secondary-button {
  background: var(--color-card);
  color: var(--color-brand);
  border: 1.5px solid var(--color-brand);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: calc(15 * var(--px));
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  font-family: inherit;
  width: 100%;
}
.secondary-button:active { background: var(--color-brand-soft); }
.text-input {
  width: 100%;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: max(16px, calc(16 * var(--px))); /* below 16px, iOS Safari zooms the page on focus */
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-card);
}
.text-input:focus { border-color: var(--color-brand); }
/* iOS gives date and time fields an intrinsic width that ignores width: 100%
   and pushes them past the card edge; an empty one also collapses in height. */
input[type="date"].text-input,
input[type="datetime-local"].text-input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  min-height: 46px;
}
input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--color-brand); }
.check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}
.form-error { color: var(--color-danger); font-size: calc(14 * var(--px)); margin: 8px 0 0; }

/* Call-outs. Used inside printable cards and in the live UI. */
.disclaimer-box {
  background: var(--color-notice-bg);
  border: 1px solid var(--color-notice-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: calc(12 * var(--px));
  margin-bottom: 14px;
}
.warning-box {
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  padding: 10px 12px;
  font-size: calc(13 * var(--px));
  margin: 6px 0;
  border-radius: 8px;
}
.info-box {
  background: var(--color-info-bg);
  border: 1px solid var(--color-info-border);
  padding: 10px 12px;
  font-size: calc(13 * var(--px));
  margin: 6px 0;
  border-radius: 8px;
}
.notice-banner {
  background: var(--color-notice-bg);
  border: 1px solid var(--color-notice-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: calc(13 * var(--px));
  margin: 8px 0 12px;
}

/* PRIVACY POLICY SHEET */
.policy-body h1 { font-size: calc(20 * var(--px)); margin: 0 0 4px; }
.policy-body h2 { font-size: calc(16 * var(--px)); margin: 18px 0 6px; }
.policy-body p, .policy-body li { font-size: calc(14 * var(--px)); line-height: 1.55; }
.policy-body ul { padding-left: 18px; }
.policy-body table { width: 100%; border-collapse: collapse; font-size: calc(13 * var(--px)); margin: 8px 0; }
.policy-body th, .policy-body td {
  text-align: left; vertical-align: top; padding: 6px;
  border-bottom: 1px solid var(--color-border);
}
.policy-body .draft {
  background: var(--color-notice-bg); border: 1px solid var(--color-notice-border); border-radius: 10px;
  padding: 8px 10px; font-size: calc(13 * var(--px));
}

/* FIRST-RUN CONSENT */
.consent-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.consent-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}
.consent-item input { flex: 0 0 auto; margin-top: 2px; }
.consent-item strong { display: block; margin-bottom: 2px; }
.consent-body { display: block; font-size: calc(14 * var(--px)); color: var(--color-muted); }
.consent-points { padding-left: 18px; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }

/* SHEETS (dialog.js) */
.sheet-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sheet-choice { text-align: left; display: flex; flex-direction: column; gap: 2px; }
.sheet-choice .field-hint { font-weight: 400; color: var(--color-muted); font-size: calc(12 * var(--px)); }

/* SCAN */
.viewport-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 16px;
}
#cameraVideo { display: block; width: 100%; height: 100%; object-fit: cover; background: #000; }
.viewport-overlay { position: absolute; inset: 0; pointer-events: none; }
.bracket { position: absolute; width: 36px; height: 36px; border: 3px solid white; }
.bracket.tl { top: 16px; left: 16px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.bracket.tr { top: 16px; right: 16px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.bracket.bl { bottom: 16px; left: 16px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.bracket.br { bottom: 16px; right: 16px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }
/* Its own dark plate, so the line stays readable over any camera image. */
.scan-status {
  position: absolute;
  left: 56px; right: 56px; bottom: 16px;
  text-align: center;
  color: white;
  background: rgba(20, 23, 26, 0.72);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: calc(14 * var(--px));
  font-weight: 600;
}
.scan-controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* CARDS */
.card {
  background: var(--color-card);
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  padding: 18px;
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
}
.card-link {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  transition: transform 0.06s ease;
}
.card-link:active { transform: scale(0.99); background: var(--color-surface-2); }
.card-title { font-size: calc(18 * var(--px)); font-weight: 700; margin-bottom: 4px; }

/* RESULT CARD */
.result-card {
  --tier-tint: var(--color-surface-2);
  background: var(--color-card);
  border-radius: 16px;
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  overflow: hidden;
}
.result-card.tier-red    { --tier-tint: var(--color-danger-bg); }
.result-card.tier-orange { --tier-tint: var(--color-warn-bg); }
.result-card.tier-yellow { --tier-tint: var(--color-notice-bg); }
.result-card.tier-green  { --tier-tint: var(--color-ok-bg); }
.result-header {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 18px;
  background: var(--tier-tint);
}
.result-icon {
  font-size: calc(26 * var(--px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 52px;
  background: var(--tier-gray);
  color: #fff;
  font-weight: 700;
}
.tier-red .result-icon    { background: var(--tier-red); }
.tier-orange .result-icon { background: var(--tier-orange); }
.tier-yellow .result-icon { background: var(--tier-yellow); color: #4a2e00; }
.tier-green .result-icon  { background: var(--tier-green); }
.result-icon svg {
  width: 55%;
  height: 55%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.result-tier { font-size: calc(20 * var(--px)); font-weight: 700; line-height: 1.2; }
.result-subhead { font-size: calc(14 * var(--px)); color: var(--color-muted); margin-top: 2px; }
.result-section { padding: 12px 18px; border-top: 1px solid var(--color-border); }
.result-header + .result-section { border-top: none; }
.result-label {
  font-size: calc(12 * var(--px));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-bottom: 4px;
}
.result-value { font-size: calc(16 * var(--px)); font-weight: 600; }
.result-why { list-style: none; padding: 0; margin: 0; }
.result-why li {
  padding: 6px 0;
  border-bottom: 1px dashed var(--color-border);
  font-size: calc(14 * var(--px));
}
.result-why li:last-child { border-bottom: none; }
.result-why .match {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--color-warn-bg);
  color: var(--color-notice-ink);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: calc(12 * var(--px));
}
.result-ingredients {
  font-size: calc(13 * var(--px));
  color: var(--color-muted);
  max-height: 120px;
  overflow-y: auto;
}
.result-cofactor-text {
  font-size: calc(14 * var(--px));
  background: var(--color-warn-bg);
  border: 1px solid var(--color-warn-border);
  padding: 8px 10px;
  border-radius: 8px;
  margin: 0;
}
.result-cross { background: var(--color-notice-bg); }
.result-watch { background: var(--color-notice-bg); }
.cross-pill {
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
  font-size: calc(11 * var(--px));
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-brand);
  color: white;
  font-weight: 700;
}
.result-cross em {
  font-style: normal;
  font-weight: 600;
  color: var(--color-brand);
}
.explain-output {
  margin-top: 10px;
  padding: 12px;
  background: var(--color-info-bg);
  border-radius: 10px;
  font-size: calc(14 * var(--px));
  line-height: 1.55;
  white-space: pre-wrap;
}
.explain-output.loading { color: var(--color-muted); font-style: italic; }
.result-footer {
  padding: 10px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* LAB LENS */
.lab-result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.lab-allergen {
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
  margin-top: 12px;
}
.lab-allergen:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.lab-allergen-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.lab-allergen-name { font-weight: 700; font-size: calc(17 * var(--px)); }
.lab-interp-badge {
  font-size: calc(11 * var(--px));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  color: white;
}
.lab-interp-badge.t-red    { background: var(--tier-red); }
.lab-interp-badge.t-orange { background: var(--tier-orange-strong); }
.lab-interp-badge.t-yellow { background: var(--tier-yellow); color: #4a2e00; }
.lab-interp-badge.t-green  { background: var(--tier-green-strong); }
.lab-interp-badge.t-gray   { background: var(--tier-gray); }
.lab-components {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.lab-component {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(12 * var(--px));
  background: var(--color-surface-2);
  border-radius: 6px;
  padding: 3px 8px;
}
.lab-component.high { background: var(--color-danger-bg); color: #7f1d1d; font-weight: 600; }
.lab-component.normal { background: var(--color-ok-bg); color: #166534; }
.lab-component.uncertain { outline: 1.5px dashed var(--tier-orange); }
button.lab-component {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  border: none;
  cursor: pointer;
  min-height: 32px;
  padding: 6px 10px;
}
.lab-component-link {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.article-modal {
  max-width: 540px;
  max-height: 88dvh;
}
.article-body {
  font-size: calc(14 * var(--px));
  line-height: 1.6;
  margin-top: 6px;
}
.article-body p { margin: 0 0 10px; }
.lab-explainer { font-size: calc(14 * var(--px)); line-height: 1.55; }
.lab-question {
  font-size: calc(13 * var(--px));
  font-style: italic;
  color: var(--color-muted);
  margin-top: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--color-border);
}

/* CHAT */
.chat-scroll {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 12px;
  min-height: 200px;
  max-height: calc(100dvh - 360px);
  overflow-y: auto;
}
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: calc(14 * var(--px));
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-bubble.user {
  background: var(--color-brand);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  background: var(--color-card);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--color-border);
}
.chat-bubble.system {
  align-self: center;
  background: transparent;
  color: var(--color-muted);
  font-style: italic;
  font-size: calc(13 * var(--px));
}
.chat-form { display: flex; gap: 8px; align-items: stretch; }
.chat-input {
  flex: 1;
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: max(16px, calc(16 * var(--px)));
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-card);
  resize: none;
}
.chat-input:focus { border-color: var(--color-brand); }
.chat-form .primary-button { width: auto; min-width: 80px; padding: 12px 16px; }

/* PROFILE / CLINICAL FIELDS */
.clinical-field {
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.clinical-field label, .clinical-field .field-label {
  font-weight: 600;
  font-size: calc(14 * var(--px));
}
.clinical-field .field-hint {
  font-size: calc(12 * var(--px));
  color: var(--color-muted);
}

/* TAB BAR */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  padding: 4px 0 calc(env(safe-area-inset-bottom, 4px) + 4px);
  z-index: 10;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  color: var(--color-muted);
  font-family: inherit;
  min-height: 48px;
}
.tab:active { color: var(--color-brand-dark); }
.tab-icon { display: block; width: 24px; height: 24px; }
.tab-icon svg, .mic-button svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab[aria-current="page"] .tab-icon svg { stroke-width: 2.1; }
.tab-label { font-size: calc(11 * var(--px)); letter-spacing: 0.02em; }
.tab[aria-current="page"] { color: var(--color-brand); font-weight: 700; }

/* COFACTOR MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 23, 26, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.modal {
  background: var(--color-card);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
}
.modal h2 { margin: 0 0 10px; font-size: calc(18 * var(--px)); }
.tier-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: 1px;
}
.cofactor-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cofactor-list label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: calc(14 * var(--px));
  line-height: 1.4;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.cofactor-list input[type="checkbox"] { margin-top: 1px; }

/* EMERGENCY OVERLAY */
.emergency-overlay {
  position: fixed;
  inset: 0;
  background: rgba(120, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.emergency-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  border: 2px solid var(--tier-red);
}
.emergency-card h1 { color: var(--tier-red); margin: 0 0 12px; font-size: calc(22 * var(--px)); }
.emergency-card ol { padding-left: 20px; margin: 12px 0; }
.emergency-card a.primary-button { background: var(--tier-red); }

/* SPINNER */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 12px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* PRINTABLE CARDS */
.printable {
  background: white;
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  font-size: calc(13 * var(--px));
}
.printable h1 { font-size: calc(22 * var(--px)); margin: 0 0 4px; }
.printable h2 {
  font-size: calc(14 * var(--px));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 6px;
  border-bottom: 1px solid #ccc;
  padding-bottom: 2px;
  color: var(--color-brand-dark);
}
.printable dl {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 4px 12px;
  margin: 0;
}
.printable dt { font-weight: 600; color: var(--color-muted); }
.printable dd { margin: 0; }
.printable ul { padding-left: 20px; margin: 6px 0; }
.printable .footer-row {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  font-size: calc(11 * var(--px));
  color: var(--color-muted);
}

/* PROFILE SWITCHER (top bar) */
.profile-switcher {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: calc(13 * var(--px));
  color: var(--color-text);
}
.profile-switcher:active { background: var(--color-surface-2); }
.profile-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-brand);
  color: white;
  font-weight: 700;
  font-size: calc(12 * var(--px));
}

.profile-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.profile-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  min-height: 52px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  cursor: pointer;
}
.profile-list li.current { border-color: var(--color-brand); background: var(--color-brand-soft); }
.profile-list .profile-avatar { width: 32px; height: 32px; font-size: calc(13 * var(--px)); }
.profile-list .profile-meta { flex: 1; }
.profile-list .profile-meta .name { font-weight: 600; }
.profile-list .profile-meta .role { font-size: calc(12 * var(--px)); color: var(--color-muted); }

/* TODAY BANNER (aggregated daily tasks) */
.today-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.today-row {
  --today-dot: var(--tier-gray);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.today-body { flex: 1; font-size: calc(14 * var(--px)); line-height: 1.4; }
.today-action {
  width: auto;
  padding: 6px 14px;
  min-height: 44px;
  font-size: calc(13 * var(--px));
  flex-shrink: 0;
}
.today-row::before {
  content: "";
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--today-dot);
}
.today-red    { --today-dot: var(--tier-red); background: var(--color-danger-bg); border-color: var(--color-danger-border); }
.today-orange { --today-dot: var(--tier-orange); }
.today-yellow { --today-dot: var(--tier-yellow); }
.today-gray   { --today-dot: var(--tier-gray); }

/* POLLEN BANNER */
.pollen-banner {
  background: var(--color-notice-bg);
  border: 1px solid var(--color-notice-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: calc(13 * var(--px));
  line-height: 1.45;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.pollen-banner-text { flex: 1; }
.pollen-banner-text strong { color: var(--color-notice-ink); }

/* JOURNAL */
.journal-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.journal-entry {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px;
}
.journal-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.journal-entry-when {
  font-size: calc(13 * var(--px));
  color: var(--color-muted);
}
.journal-entry-severity {
  font-size: calc(11 * var(--px));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  color: white;
}
.journal-entry-severity.s-mild { background: var(--tier-green-strong); }
.journal-entry-severity.s-moderate { background: var(--tier-yellow); color: #4a2e00; }
.journal-entry-severity.s-severe { background: var(--tier-orange-strong); }
.journal-entry-severity.s-anaphylaxis { background: var(--tier-red); }
.journal-entry-trigger { font-weight: 600; margin-top: 4px; }
.journal-entry-meta { font-size: calc(13 * var(--px)); color: var(--color-muted); margin-top: 4px; }
.journal-entry-symptoms {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.journal-entry-symptoms .chip-small {
  font-size: calc(11 * var(--px));
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-surface-2);
}
.journal-entry-actions { display: flex; gap: 8px; margin-top: 8px; }
.journal-symptoms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.journal-symptoms label {
  font-size: calc(13 * var(--px));
  padding: 6px 12px;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.journal-symptoms label:has(input:checked) {
  border-color: var(--color-brand);
  background: var(--color-brand-soft);
  color: var(--color-brand-dark);
}
/* Journal insight cards: the source shows as a small label, not a stripe. */
.insight-card { box-shadow: none; }
.insight-source {
  display: inline-block;
  font-size: calc(11 * var(--px));
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tier-orange-strong);
  margin-bottom: 2px;
}
.insight-source.llm { color: var(--color-brand); }
.journal-symptoms label input { margin: 0; }
.journal-form-modal h2 { margin-top: 0; }

/* MIC */
.mic-button {
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  cursor: pointer;
  flex-shrink: 0;
  align-self: stretch;
  font-family: inherit;
}
.mic-button.recording {
  background: var(--tier-red);
  border-color: var(--tier-red);
  color: white;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* LAB HISTORY STRIP */
.lab-history-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 8px 0 14px;
  padding-bottom: 6px;
}
.lab-history-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  min-height: 44px;
  border-radius: 999px;
  background: var(--color-surface-2);
  font-size: calc(12 * var(--px));
  border: 1.5px solid transparent;
  cursor: pointer;
  font-family: inherit;
}
.lab-history-pill.current {
  background: var(--color-brand-soft);
  border-color: var(--color-brand);
  color: var(--color-brand-dark);
  font-weight: 600;
}

/* TREND CALLOUT */
.trend-callout {
  background: var(--color-ok-bg);
  border: 1px solid var(--color-ok-border);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: calc(14 * var(--px));
}
.trend-callout.rising {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
}
.trend-callout strong { color: var(--color-brand-dark); }
.trend-callout.rising strong { color: var(--color-danger); }

.trend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: calc(12 * var(--px));
}
.trend-bar-wrap {
  position: relative;
  height: 6px;
  flex: 1;
  background: var(--color-surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.trend-bar {
  position: absolute;
  height: 100%;
  border-radius: 999px;
  background: var(--color-brand);
}
.trend-direction { font-size: calc(14 * var(--px)); }
.trend-direction.down { color: var(--tier-green-strong); }
.trend-direction.up { color: var(--color-danger); }

/* PRINT */
@media print {
  :root { --px: 1px; }
  body { background: white; }
  .topbar, .tabbar, .detail-header, .modal-backdrop, .emergency-overlay { display: none !important; }
  /* min-height: 100dvh on screen would push a blank second page when printing */
  #app { max-width: 100%; padding-bottom: 0; min-height: 0; display: block; }
  .view { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  .primary-button, .secondary-button, .link-button, .mic-button, .profile-switcher { display: none; }
  .printable { border: none; padding: 0; }
}

/* A11y */
@media (prefers-reduced-motion: reduce) {
  .chip, .card-link { transition: none; }
  .chip:active, .card-link:active { transform: none; }
  /* Recording still reads from the red fill; loading still reads from a slow turn. */
  .mic-button.recording { animation: none; }
  .spinner { animation-duration: 2.4s; }
}
