/* ---- Colors, fonts and sizes ---- */
:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --border: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --button: oklch(0.205 0 0);
  --button-text: oklch(0.985 0 0);
  --blue: oklch(0.488 0.243 264.376);
  --blue-dark: oklch(0.424 0.199 265.638);

  /* System font stacks only: no web-font download means no font swap,
     so text never reflows after first paint. */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;

  --content-width: 42.5rem;
  --gutter: 1.25rem;
  color-scheme: light;
}

@media (max-width: 30rem) {
  :root {
    --gutter: 1rem;
  }
}

/* ---- Reset: no default margins, padding or borders; form controls and
   headings take their font from the page ---- */
*,
::before,
::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid var(--border);
  outline-color: oklch(0.708 0 0 / 50%);
}

h1,
h2 {
  font-size: inherit;
  font-weight: inherit;
}

a {
  color: inherit;
  text-decoration: inherit;
  text-underline-offset: 4px;
}

ul {
  list-style: none;
}

svg {
  display: block;
  vertical-align: middle;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  background-color: transparent;
  border-radius: 0;
}

[hidden]:not([hidden="until-found"]) {
  display: none !important;
}

/* ---- Page ---- */
html {
  /* Reserve the scrollbar's space on every page, so moving between a short
     page and a long one never shifts the header sideways. */
  scrollbar-gutter: stable;
  /* Page changes should jump to the top, not animate. */
  scroll-behavior: auto;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  tab-size: 4;
}

body {
  /* At least the window's height, with <main> taking any spare space, so
     the footer sits at the bottom of the window on short pages. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  line-height: 1.6;
  color: var(--foreground);
  background-color: var(--background);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Hidden, but still read by screen readers. */
.sr-only,
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 50;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background-color: var(--background);
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 10%), 0 1px 2px -1px rgb(0 0 0 / 10%);
}

/* ---- Header (never swapped) ---- */
.site-header {
  border-bottom: 2px solid var(--foreground);
}

.site-header__inner {
  /* How far the chestpiece is raised onto the underline.
     Read by stethoscope.ts; the bottom padding shrinks to match. */
  --chestpiece-lift: 5px;
  --heartbeat: oklch(0.577 0.245 27.325);
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 1.25rem;
  /* Room under each row for the stethoscope's chestpiece. */
  row-gap: 1.5rem;
  max-width: calc(var(--content-width) + 2 * var(--gutter));
  margin-inline: auto;
  padding: 0.5rem var(--gutter) calc(1.375rem - var(--chestpiece-lift));
  font-family: var(--font-serif);
}

.brand {
  font-size: 1.375rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

/* ---- Stethoscope (see public/_partials/header.html and src/client/stethoscope.ts) ---- */
.stetho {
  overflow: visible;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stetho-outline {
  stroke: var(--foreground);
  stroke-width: 3.6;
}

.stetho-fill {
  stroke: var(--background);
  stroke-width: 1.4;
}

.heartbeat {
  fill: none;
  stroke: var(--heartbeat);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stetho-part {
  fill: var(--background);
  stroke: var(--foreground);
  stroke-width: 1.2;
}

.stetho-head {
  flex: none;
  /* Sit the stem's end on the text baseline. */
  align-self: baseline;
}

.stetho-tube {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  visibility: hidden;
}

/* Once stethoscope.ts has redrawn the headset in the overlay, the in-flow
   one just holds its place. */
.has-stethoscope .stetho-head {
  visibility: hidden;
}

/* While a reduced-motion page change fades the overlay out and back in, the
   in-flow headset stands in so the headset itself never disappears. */
.has-stethoscope.stetho-fading .stetho-head {
  visibility: visible;
}

.has-stethoscope .stetho-tube {
  visibility: visible;
  transition: opacity 150ms ease;
}

/* Reduced-motion page changes fade the chestpiece instead of sliding it. */
.stetho-tube.is-faded {
  opacity: 0;
}

.site-header nav ul {
  display: flex;
  flex-wrap: wrap;
  font-size: 1.125rem;
}

.site-header nav li + li::before {
  content: "|";
  padding-inline: 0.4em;
  color: var(--muted-foreground);
}

/* Header underlines are a 1px background line along the bottom of the link
   box, not text-decoration, so stethoscope.ts knows exactly where they are
   (the heartbeat blip scrolls along them). Being a background, they paint
   behind the text and the stethoscope overlay. */
.site-header nav a {
  line-height: 1.2;
  text-decoration: none;
}

.brand,
.site-header nav a {
  background: linear-gradient(currentColor, currentColor) left bottom / 0 1px no-repeat;
}

.site-header nav a:hover,
.site-header a[aria-current="page"] {
  background-size: 100% 1px;
}

/* Phones: keep brand, stethoscope and nav on one row so the tube never has
   to cross a line of text. */
@media (max-width: 30rem) {
  .site-header__inner {
    column-gap: 0.5rem;
  }

  .brand {
    font-size: 1rem;
  }

  .site-header nav ul {
    font-size: 0.875rem;
  }

  .site-header nav li + li::before {
    padding-inline: 0.3em;
  }

  .stetho-head {
    width: 20px;
    height: 28px;
  }

  /* Keep strokes as thick as the (unscaled) tube's. */
  .stetho-head * {
    vector-effect: non-scaling-stroke;
  }
}

@media (max-width: 22rem) {
  .site-header__inner {
    column-gap: 0.375rem;
  }

  .brand {
    font-size: 0.9375rem;
  }

  .site-header nav ul {
    font-size: 0.8125rem;
  }

  .site-header nav li + li::before {
    padding-inline: 0.25em;
  }

  .stetho-head {
    width: 18px;
    height: 26px;
  }
}

/* ---- Footer (never swapped) ---- */
.site-footer {
  border-top: 2px solid var(--foreground);
}

.site-footer p {
  max-width: calc(var(--content-width) + 2 * var(--gutter));
  margin-inline: auto;
  padding: 1.5rem var(--gutter);
  font-family: var(--font-serif);
  text-align: center;
}

/* ---- Main (the only part htmx swaps) ---- */
#main {
  display: block;
  flex-grow: 1;
  /* (A flex item with auto side margins shrinks to fit its content
     unless it's given a width.) */
  width: 100%;
  max-width: calc(var(--content-width) + 2 * var(--gutter));
  margin-inline: auto;
  padding: 2.5rem var(--gutter) 4rem;
  font-size: 1.125rem;
}

#main:focus {
  outline: none;
}

/* ---- Page content: everything htmx swaps into <main> ----
   The reset above strips default typography, so it's restored here for plain
   HTML content. Low-specificity :where() keeps components (the contact form,
   alerts) free to set their own spacing. */
main :where(article, section) > * + * {
  margin-top: 1em;
}

main :where(article > section) {
  margin-top: 3rem;
}

main :where(h2) {
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.3;
}

main :where(ul) {
  padding-left: 1.25em;
  list-style: disc;
}

/* Lists of <details> (the references page): the toggle triangles already
   mark each item, so no bullets or indent. */
main :where(ul:has(> li > details)) {
  list-style: none;
  padding-left: 0;
}

/* A <details> description, indented under its summary. */
main :where(details > :not(summary)) {
  margin-top: 0.25em;
  padding-left: 2em;
}

main :where(li + li) {
  margin-top: 0.5em;
}

main :where(a) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

main :where(a:hover) {
  text-decoration-thickness: 2px;
}

.page > h1:not(.sr-only) {
  max-width: 30rem;
  margin: 0 auto 3.5rem;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.875rem);
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
}

.page--narrow {
  max-width: 30rem;
  margin-inline: auto;
}

/* ---- Call to action: a link that looks like a button ---- */
.cta {
  display: block;
  width: fit-content;
  margin-inline: auto;
  padding: 0.625rem 1.5rem;
  border-radius: 0.5rem;
  background-color: var(--blue);
  color: white;
  font-weight: 600;
  text-decoration: none;
}

.cta:hover {
  background-color: var(--blue-dark);
}

.cta:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---- Contact form ---- */
.alert {
  display: grid;
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  border-width: 1px;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(0.577 0.245 27.325 / 90%);
  text-wrap: balance;
}

@media (min-width: 48rem) {
  .alert {
    text-wrap: pretty;
  }
}

.contact-form {
  display: grid;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.contact-form__row {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 30rem) {
  .contact-form__row {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field > label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: fit-content;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  user-select: none;
}

.optional {
  margin-left: 0.25em;
  font-weight: 400;
  color: var(--muted-foreground);
}

.field > :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
  border-width: 1px;
  border-color: var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 5%);
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
  transition: color 150ms, box-shadow 150ms;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.field > input {
  height: 2.25rem;
  padding: 0.25rem 0.625rem;
}

.field > textarea {
  min-height: 7rem;
  padding: 0.5rem 0.625rem;
  resize: vertical;
  field-sizing: content;
}

.field > select {
  height: 2.25rem;
  padding: 0.25rem 2rem 0.25rem 0.625rem;
  appearance: none;
  /* A chevron, since appearance: none removes the browser's own arrow. */
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="oklch(0.556 0 0 / 0.5)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>') right 0.625rem center / 1rem no-repeat;
  font-size: 0.875rem;
  line-height: 1.25rem;
  user-select: none;
}

@media (min-width: 48rem) {
  .field > :is(input, textarea) {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }
}

.field > :is(input, select, textarea):focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(0.708 0 0 / 50%), 0 1px 2px 0 rgb(0 0 0 / 5%);
}

.field > :is(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--destructive);
  box-shadow: 0 0 0 3px oklch(0.577 0.245 27.325 / 20%), 0 1px 2px 0 rgb(0 0 0 / 5%);
}

.field-error {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--destructive);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  height: 2.25rem;
  padding-inline: 0.625rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background-color: var(--button);
  background-clip: padding-box;
  color: var(--button-text);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
  white-space: nowrap;
  user-select: none;
  outline: none;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

@media (hover: hover) {
  .btn:hover {
    background-color: oklch(0.205 0 0 / 80%);
  }
}

.btn:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(0.708 0 0 / 50%);
}

.btn:active {
  translate: 0 1px;
}

/* htmx disables the button while the form is sending (hx-disable). */
.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Honeypot: hidden from people, visible to naive bots. */
.hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
