/* ==========================================================================
   Category II FHR walkthrough — fhr.brisaloca.com

   Tokens, base type, controls and the topbar are shared in spirit with
   ob.brisaloca.com's stylesheet (the two tools look like siblings) but the
   files are independent: this Worker ships only what this page uses, and
   there is no build step joining them. Keep the token block in sync by hand
   if the palette ever changes.
   ========================================================================== */

/* --------------------------------------------------------------- tokens */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --good-wash: rgba(12, 163, 12, 0.09);
  --warning-wash: rgba(250, 178, 25, 0.14);
  --critical-wash: rgba(208, 59, 59, 0.1);

  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --good-wash: rgba(12, 163, 12, 0.16);
    --warning-wash: rgba(250, 178, 25, 0.16);
    --critical-wash: rgba(208, 59, 59, 0.18);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --good-wash: rgba(12, 163, 12, 0.16);
  --warning-wash: rgba(250, 178, 25, 0.16);
  --critical-wash: rgba(208, 59, 59, 0.18);
}

/* ---------------------------------------------------------------- base */
* {
  box-sizing: border-box;
}

/* Author `display` rules outrank the UA sheet's [hidden], so restate it. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3 {
  margin: 0 0 0.35em;
  line-height: 1.25;
}
h1 {
  font-size: 1.4rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-top: 1.75rem;
}

/* Gestational age is written 28w0d — never upper-cased into 28W0D. */
h3 .ga {
  text-transform: none;
  letter-spacing: 0;
}

p {
  margin: 0 0 0.75em;
}

a {
  color: var(--series-1);
}

.muted {
  color: var(--text-muted);
}
.lede {
  color: var(--text-secondary);
  max-width: 62ch;
}
.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0.5rem;
}
.error {
  color: var(--critical);
  font-size: 0.85rem;
  margin: 0.25rem 0;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* -------------------------------------------------------------- controls */
button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  padding: 0.45rem 0.85rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover {
  background: color-mix(in srgb, var(--text-primary) 6%, transparent);
}

button.primary {
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
button.primary:hover {
  background: color-mix(in srgb, var(--series-1) 85%, #000);
}
button.small,
a.small {
  padding: 0.28rem 0.6rem;
  font-size: 0.85rem;
}
button.danger:hover {
  background: var(--critical-wash);
  border-color: var(--critical);
  color: var(--critical);
}

.ghost {
  background: transparent;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
a.ghost:hover {
  background: color-mix(in srgb, var(--text-primary) 6%, transparent);
}

input[type="text"],
input[type="password"],
input[type="number"],
input:not([type]) {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
}

input:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand-mark {
  font-size: 1.35rem;
}
.brand strong {
  display: block;
  line-height: 1.15;
}
.brand .muted {
  font-size: 0.8rem;
}
.topbar-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}


/* --------------------------------------------------------------- mobile  */
@media (max-width: 720px) {
  /* Four actions is wider than a phone. Wrap them onto a second line rather than
     let them push the whole page into a horizontal scroll. */
  .topbar {
    padding: 0.6rem 0.9rem;
    flex-wrap: wrap;
  }
  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .brand .muted {
    display: none;
  }
  .ghost {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
  }
}

/* ==========================================================================
   The walkthrough itself
   One question per screen, so the type is large and the tap targets are big.

   Phone first: a single column, with Definitions collapsed above the question.
   From 1000px up the same markup becomes two columns and Definitions moves into
   a sticky rail that is open from the start — see the media query at the end.
   ========================================================================== */

.wizard-layout {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

/* ------------------------------------------------------------ breadcrumbs */
.trail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}
.trail:empty {
  display: none;
}
/* "Back" is in the toolbar from the first screen, where there is nowhere to go. */
.topbar-actions button:disabled {
  opacity: 0.4;
  cursor: default;
}
.topbar-actions button:disabled:hover {
  background: transparent;
}

.crumb {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface-1);
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- screens */
.screen h1 {
  font-size: 1.6rem;
  letter-spacing: -0.015em;
  margin-bottom: 0.5rem;
}
.screen-column {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

/* Both criteria of a joined-by-"or" decision box, as the chart prints them. */
.criteria {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  overflow: hidden;
}
.criteria li {
  padding: 0.7rem 0.9rem;
}
.criteria .criteria-or {
  padding: 0.15rem 0.9rem;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: color-mix(in srgb, var(--text-primary) 4%, transparent);
}

.steps {
  margin: 1rem 0;
  padding-left: 1.3rem;
  max-width: 60ch;
}
.steps li {
  margin-bottom: 0.4rem;
}

.emphasis {
  border-left: 3px solid var(--warning);
  background: var(--warning-wash);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  max-width: 60ch;
}


/* ---------------------------------------------------------------- choices */
.choices {
  display: grid;
  gap: 0.6rem;
  margin: 1.25rem 0;
}
.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  text-align: left;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: var(--surface-1);
  font-size: 1rem;
}
.choice:hover {
  border-color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 7%, var(--surface-1));
}
.choice-key {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-primary) 7%, transparent);
}
.choice-body {
  display: block;
}
.choice-label {
  display: block;
  font-weight: 550;
}
.choice-hint {
  display: block;
  font-size: 0.83rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}
.choice-continue,
.choice-followup {
  font-weight: 600;
  justify-content: center;
}

/* -------------------------------------------------------- recommendation */
.recommendation {
  border: 1px solid var(--border);
  border-left: 5px solid var(--tone-color, var(--axis));
  border-radius: var(--radius);
  background: var(--surface-1);
  padding: 1.25rem 1.35rem;
}
.recommendation[data-tone="observe"] {
  --tone-color: var(--good);
  background: linear-gradient(var(--good-wash), var(--good-wash)), var(--surface-1);
}
.recommendation[data-tone="caution"] {
  --tone-color: var(--warning);
  background: linear-gradient(var(--warning-wash), var(--warning-wash)), var(--surface-1);
}
.recommendation[data-tone="deliver"] {
  --tone-color: var(--critical);
  background: linear-gradient(var(--critical-wash), var(--critical-wash)), var(--surface-1);
}
.recommendation-kicker {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tone-color);
  font-weight: 650;
  margin-bottom: 0.3rem;
}
.recommendation h1 {
  font-size: 1.75rem;
}
.recommendation p:last-child {
  margin-bottom: 0;
}

.recap-head {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-top: 1.75rem;
}
.recap {
  margin: 0 0 1.25rem;
  padding-left: 1.3rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 64ch;
}
.recap li {
  margin-bottom: 0.25rem;
}
.recap-actions {
  margin-bottom: 1.5rem;
}

/* -------------------------------------------------------------- reference */
/* The in-page way into the drawer, on every screen. The toolbar button does the
   same thing, but it is easy to miss and off-screen once a screen gets long. */
.reference-link {
  margin: 1.5rem 0 0;
}
[data-role="reference-toggle"][aria-expanded="true"] {
  border-color: var(--series-1);
  color: var(--series-1);
}

.reference-drawer {
  margin-bottom: 1.5rem;
  padding: 1rem 1.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
}
.drawer-head {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 0;
}
/* Inside the drawer the panels are the menu, so they read as rows, not cards. */
.reference-drawer .ref {
  background: transparent;
  border-color: transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  margin-top: 0;
  padding: 0.7rem 0.15rem;
}
.reference-drawer .ref summary {
  color: var(--text-primary);
}

.ref {
  margin-top: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  padding: 0.6rem 0.9rem;
}
.ref summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  /* `display: flex` already drops the disclosure triangle in Chrome and Safari;
     say so explicitly for Firefox, since a +/- box replaces it below. */
  list-style: none;
}
.ref summary::-webkit-details-marker {
  display: none;
}

/* ! The +/- box is the only thing that says these rows open.
   Without it they are bold text in a list and read as a heading, not a control —
   which is exactly how it looked before, and nobody tried clicking them. Flips to
   a minus when open so the state is visible without having to read the panel. */
.ref summary::after {
  content: "+";
  margin-left: auto;
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.ref[open] summary::after {
  content: "−";
}
.ref summary:hover {
  color: var(--series-1);
}
.ref summary:hover::after {
  border-color: var(--series-1);
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 10%, var(--page));
}

.ref[open] summary {
  margin-bottom: 0.5rem;
}
.ref-marker {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--page);
  font-size: 0.72rem;
}
.ref-list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.86rem;
  color: var(--text-secondary);
}
.ref-list li {
  margin-bottom: 0.2rem;
}
.ref-list .ref-list {
  margin-top: 0.2rem;
  font-size: 1em;
}

/* ------------------------------------------------------------ attribution */
.source-note {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  max-width: 68ch;
}
.source-note p {
  margin-bottom: 0.5rem;
}

/* ------------------------------------------------------------------- phone */
@media (max-width: 720px) {
  .wizard-layout {
    padding: 1.25rem 1rem 3rem;
  }
  .screen h1 {
    font-size: 1.35rem;
  }
  .recommendation h1 {
    font-size: 1.5rem;
  }
  .crumb {
    max-width: 18ch;
  }
  /* Thumb-sized targets, and the number badge is useless without a keyboard. */
  .choice {
    padding: 1rem;
  }
  .choice-key {
    display: none;
  }
  .reference-link {
    width: 100%;
    justify-content: center;
  }
}

/* ----------------------------------------------------------------- desktop */
/* Two columns: the walkthrough on the left, Definitions parked in a sticky rail
   on the right so the ABCD measures stay readable while answering. The rail's
   column is sized `auto`, so when Definitions is closed it collapses to nothing
   and the walkthrough takes the full width rather than leaving a hole. */
@media (min-width: 1000px) {
  .wizard-layout {
    max-width: 84rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "main rail"
      "foot rail";
    column-gap: 2.5rem;
    align-items: start;
    padding: 2.25rem 2rem 4rem;
  }
  .wizard {
    grid-area: main;
    max-width: 54rem;
  }
  .source-note {
    grid-area: foot;
    max-width: 54rem;
  }
  .reference-drawer {
    grid-area: rail;
    width: 23rem;
    margin-bottom: 0;
    position: sticky;
    top: calc(57px + 2.25rem);
    max-height: calc(100dvh - 57px - 4.5rem);
    overflow-y: auto;
  }

  .screen h1 {
    font-size: 1.85rem;
  }
  .recommendation h1 {
    font-size: 2rem;
  }
  /* ! Answers stay in ONE column at every width.
     A two-across grid was tried and reverted: with three options it reads 1, 2
     across and then drops 3 alone on the next row, so the eye zigzags and the
     odd one out looks like a different kind of thing. A single stack is scanned
     top to bottom in the order the chart lists them, which is the whole point. */
  .choices {
    max-width: 42rem;
  }
  .choices:has(.choice-continue),
  .choices:has(.choice-followup) {
    grid-template-columns: minmax(0, 22rem);
  }
}
