/* ---------- Custom display font ----------
   Only letters A–Z and a–z are taken from FutureFnt (unicode-range below).
   Everything else (? ' ’ digits , . etc.) automatically uses the readable font,
   so nothing looks broken even if the custom font lacks those characters. */
@font-face {
  font-family: "FutureFnt";
  src: url("fonts/FutureFnt-Regular.ttf") format("truetype");
  font-display: swap;
  unicode-range: U+0041-005A, U+0061-007A;
}

:root {
  --bg: #FAFAF7;          /* warm near-white */
  --surface: #FFFFFF;
  --text: #1A1A1A;        /* 16.6:1 on --bg */
  --text-2: #333333;      /* 12.1:1 on --bg, never lighter */
  --brand: #1F4D3A;       /* white text on it: 9.6:1 */
  --brand-dark: #163A2B;
  --brand-tint: #EEF3EF;
  --danger: #8A1C1C;      /* white text on it: 9.3:1 */
  --danger-text: #7A1515;
  --danger-tint: #FDF3F3;
  --line: #2B2B2B;
  --focus: #1F4D3A;

  --font-readable: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-custom: "FutureFnt", var(--font-readable);

  --scale: 1;             /* set by the A / A+ / A++ buttons */
  --tap: max(56px, 3.5rem);
  --radius: 16px;
}

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

html {
  font-size: calc(100% * var(--scale)); /* 16px × scale; text below is in rem */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-readable);
  font-size: 1.25rem;     /* 20px minimum body text */
  line-height: 1.6;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 50rem;
  margin: 0 auto;
  padding: 0 16px;
}

main { flex: 1; }

/* ---------- Accessibility helpers ---------- */
.visually-hidden {
  position: absolute !important;
  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: 16px; top: -100px;
  background: var(--brand); color: #fff;
  padding: 12px 20px; border-radius: 12px;
  z-index: 10; text-decoration: none; font-weight: 700;
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}
.btn--primary:focus-visible, .btn--danger:focus-visible { outline-color: #111; }

[hidden] { display: none !important; }

/* ---------- Top bar: text size ---------- */
.topbar {
  display: flex;
  justify-content: flex-end;
  padding: 16px 0 0;
}
.text-size {
  display: flex;
  align-items: center;
  gap: 8px;
}
.text-size__label {
  font-size: 1.125rem;
  color: var(--text-2);
  margin-right: 4px;
}
.text-size__btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: 700 1.25rem/1 var(--font-readable);
  cursor: pointer;
}
.text-size__btn[data-scale="1.2"] { font-size: 1.4rem; }
.text-size__btn[data-scale="1.4"] { font-size: 1.6rem; }
.text-size__btn[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Heading ---------- */
h1 {
  margin: clamp(24px, 7vh, 72px) 0 28px;
  font-size: clamp(2.5rem, 7vw, 3.75rem);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}
[data-heading-font="custom"] h1 {
  font-family: var(--font-custom);
  font-weight: 400;
  letter-spacing: 0.01em;
  font-size: clamp(2.75rem, 8vw, 4.25rem);
}
h1:focus { outline: none; }

/* ---------- Search bar ---------- */
.ask {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.ask__input {
  flex: 1000 1 18rem;   /* takes the spare room when the buttons sit beside it */
  min-width: 0;
  min-height: max(68px, 4.25rem);
  padding: 0 22px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 1.375rem/1.3 var(--font-readable);
}
.ask__input::placeholder { color: #3D3D3D; opacity: 1; } /* 10.9:1, not light gray */
.ask__input:focus-visible { outline-offset: 2px; }
.ask__buttons {
  display: flex;
  flex: 1 0 auto;       /* fills the row when it wraps under the input */
  gap: 12px;
}
.ask__buttons .btn { flex: 1 0 auto; min-height: max(68px, 4.25rem); }
.ask__help {
  flex-basis: 100%;
  margin: 0;
  min-height: 0;
  font-size: 1.125rem;
  color: var(--text-2);
}
.ask__help:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 10px 24px;
  border: 2px solid transparent;
  border-radius: 14px;
  font: 700 1.25rem/1.2 var(--font-readable);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--secondary { background: var(--surface); color: var(--brand); border-color: var(--brand); }
.btn--secondary:hover, .btn--outline:hover { background: var(--brand-tint); }
.btn--secondary[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--outline { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--big { min-height: max(72px, 4.5rem); flex-direction: column; gap: 2px; font-size: 1.375rem; }
.btn__sub { font-weight: 400; font-size: 1.125rem; }
#ask-btn { min-width: 7.5rem; font-size: 1.375rem; }

/* ---------- Popular question bubbles ---------- */
.popular { margin-top: 32px; }
.bubbles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}
.bubble {
  min-height: var(--tap);
  padding: 12px 26px;
  border: 2px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: 400 1.5rem/1.25 var(--font-readable);  /* 24px minimum */
  text-align: center;
  cursor: pointer;
}
.bubble:hover { background: var(--brand-tint); }
[data-bubble-font="custom"] .bubble {
  font-family: var(--font-custom);
  font-size: 1.75rem;   /* the display font is narrow, so a little bigger */
  letter-spacing: 0.02em;
  line-height: 1.2;
}

/* ---------- Floating chapter boxes ---------- */
.chapters { margin: 64px 0 8px; }
.chapters:focus { outline: none; }
.chapters__heading {
  margin: 0 0 24px;
  font-size: 1.75rem;
  line-height: 1.25;
  text-align: center;
}
.chapter-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 20px;
}
.chapter-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  height: 100%;
  min-height: 9.5rem;
  padding: 22px 22px 24px;
  border: 1px solid #E4E4DC;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  /* soft layered shadow so the boxes look like they float off the page */
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.06), 0 8px 24px rgba(26, 26, 26, 0.08);
}
.chapter-card:hover {
  border-color: var(--brand);
  box-shadow: 0 2px 4px rgba(26, 26, 26, 0.08), 0 16px 36px rgba(26, 26, 26, 0.14);
}
.chapter-card__num {
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.15;
  color: var(--brand);
}
[data-chapter-font="custom"] .chapter-card__num {
  font-family: var(--font-custom);
  font-weight: 400;
  font-size: 2.125rem;
  letter-spacing: 0.02em;
}
.chapter-card__title {
  font-size: 1.25rem;
  line-height: 1.35;
  font-weight: 700;
}
@media (prefers-reduced-motion: no-preference) {
  .chapter-card { transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease; }
  .chapter-card:hover, .chapter-card:focus-visible { transform: translateY(-4px); }
}

/* ---------- Chapter page ---------- */
.chapter-top { padding-top: 8px; }
.back-btn { gap: 10px; }
.is-chapter h1 { margin: 24px 0 8px; }
.is-chapter[data-chapter-font="custom"] h1 {
  font-family: var(--font-custom);
  font-weight: 400;
  letter-spacing: 0.01em;
}
.chapter-intro { text-align: center; margin: 0 auto 28px; max-width: 36rem; }
.chapter-intro p { margin: 0; }
.chapter-intro__title { font-size: 1.75rem; font-weight: 700; line-height: 1.3; }
.chapter-intro__about { margin-top: 12px !important; font-size: 1.25rem; color: var(--text-2); }
.chapter-intro__pages { margin-top: 8px !important; font-size: 1.125rem; color: var(--text-2); }
.popular__label { margin: 0 0 12px; text-align: center; font-weight: 700; }

/* ---------- Result ---------- */
.result { margin-top: 28px; }
.result:focus { outline: none; }
.result__asked {
  margin: 0 0 16px;
  color: var(--text-2);
}
.result__asked-label { font-weight: 700; color: var(--text); }

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 22px;
  border-radius: var(--radius);
  background: var(--brand-tint);
  font-size: 1.375rem;
  font-weight: 700;
}
.spinner {
  width: 28px; height: 28px; flex: none;
  border: 4px solid var(--brand);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-right-color: var(--brand); opacity: 0.6; }
}

.error {
  padding: 20px 22px;
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-tint);
}
.error p { margin: 0 0 16px; font-size: 1.375rem; }

.answer-card {
  padding: clamp(20px, 4vw, 32px);
  border: 2px solid #D9D9D2;
  border-radius: 20px;
  background: var(--surface);
}
.answer-card.is-emergency { border-color: var(--danger); background: var(--danger-tint); }
.answer {
  font-size: 1.5rem;     /* large, plain answer text */
  line-height: 1.6;
}
.answer p { margin: 0 0 0.8em; }
.answer p:last-child { margin-bottom: 0; }
.answer ul { margin: 0 0 0.8em; padding-left: 1.3em; }
.answer li { margin-bottom: 0.3em; }
.is-emergency .answer { color: var(--danger-text); font-weight: 700; }
.answer__lead { margin: 0; }
.row--emergency { margin: 16px 0 24px; }

.source {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 2px solid #E6E6E0;
  font-size: 1.25rem;
}
.source strong { display: block; }
.source__title { display: block; color: var(--text-2); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}
.clinic {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}
.next { margin-top: 24px; }
.next .btn { flex: 1 1 14rem; }

/* ---------- Footer ---------- */
.footer {
  padding: 24px 0 20px;
  text-align: center;
}
.footer p {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-2);
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  .topbar { justify-content: center; }
  .ask__input { flex-basis: 100%; }
  .ask__buttons { flex: 1 1 100%; }
  .ask__buttons .btn { flex: 1; }
  .bubbles { flex-direction: column; align-items: stretch; }
  .clinic { grid-template-columns: 1fr; }
  .row .btn { flex: 1 1 100%; }
  .chapters { margin-top: 48px; }
  .chapter-card { min-height: 0; }
}

/* ---------- Embedded in another website (?embed=1) ---------- */
.is-embed .page { min-height: 0; }
.is-embed h1 { margin-top: 16px; }
