/*
 * The admin portal's stylesheet, in the RubyWell design language: deep purple, lilac and coral,
 * Poppins, rounded cards and pills. It is written one cascade layer to a file in this folder and
 * served as one sheet, `/style.css`, joined in the order the static catalog (`../../assets.ts`)
 * lists: this file, which orders the layers, then `fonts.css` and one file per layer, from
 * `tokens.css` to `motion.css`.
 *
 * The pages carry no class, id-for-styling or style attribute, so every rule here selects what the
 * markup already means: an element, an attribute, a state, or where it sits. The conventions:
 *
 *   - Every rule sits in one of the layers the statement below orders: a rule outside them would
 *     beat every one of them, whatever its specificity.
 *   - `:root`, in the `tokens` layer, is the token layer, and the only place a colour or a tuned
 *     value is written: a length, an angle, a fraction, a duration, a curve, a percentage other
 *     than `0` or `100%`. Every other rule spends tokens through `var()`, and writes only keywords,
 *     whole numbers (a grid line, a flex factor, a multiplier), `fr` shares, strings and urls
 *     beside them.
 *   - A `section` is a card, an `article` a card inside one, a `menu` a row of actions, a `dl` a
 *     grid of labelled values, and the `div` around a `table` the frame it scrolls in.
 *   - `role="status"` is a success notice, `role="alert"` a refusal, `role="note"` a warning, and
 *     the paragraph just before an invalid control (or just after an invalid group's summary) its
 *     own error.
 *   - A button says what its form does as `name="action"` and its `value`: `remove` is drawn
 *     as danger, `unlink` as outlined danger, `prefer` as the quieter choice.
 *   - Pagination says which link is which with `rel`: `next` keeps to the end of its row.
 *   - A `span` inside a link is context for screen readers only.
 *   - A rule's states, parts and descendants nest inside it with `&`, and so does its narrow-screen
 *     `@media`, so each look reads in one place. A media query cannot read a token, so the one
 *     breakpoint, `40rem`, is written in each, and every width a query names must be that one.
 *   - Each layer owns its looks: notices (`role` status, alert, note) and invalid fields are styled
 *     only in `feedback` (set moving in `motion`, and marked in `icons`), and `motion` declares
 *     only what moves.
 *   - Every icon lives in the `icons` layer, which draws it on a `::before` or `::after` beside the
 *     words it marks and declares nothing else. The icon follows what the markup says an element
 *     is, so one meaning always has one icon and no page chooses its own.
 *   - Everything that moves lives in the `motion` layer, inside
 *     `prefers-reduced-motion: no-preference`.
 *
 * `caregraph static` enforces these (scripts/checks/styles.ts and scripts/checks/markup.ts).
 */

@layer tokens, base, page, content, controls, feedback, icons, motion;
/* Poppins, the RubyWell typeface, served by the portal itself (see `../fonts/`). */

@font-face {
  font-display: swap;
  font-family: Poppins;
  font-style: normal;
  font-weight: 400;
  src: url("/fonts/poppins-400.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: Poppins;
  font-style: normal;
  font-weight: 500;
  src: url("/fonts/poppins-500.woff2") format("woff2");
}

@font-face {
  font-display: swap;
  font-family: Poppins;
  font-style: normal;
  font-weight: 600;
  src: url("/fonts/poppins-600.woff2") format("woff2");
}
/* The token layer: every colour and tuned value the sheet spends. */

@layer tokens {
  :root {
    /* Palette: the RubyWell design system's own values. */
    --white: #ffffff;
    --black: #000000;
    --purple-900: #280026;
    --purple-800: #380036;
    --purple-600: #5c006d;
    --purple-500: #700083;
    --purple-300: #af56e9;
    --lilac-50: #fcfaff;
    --lilac-200: #f5edff;
    --lilac-300: #f0e2ff;
    --lilac-500: #e6ceff;
    --lilac-700: #d9b5ff;
    --coral-700: #ff4f58;
    --neutral-300: #e7e7e7;
    --neutral-500: #858585;
    --neutral-600: #5a5a5a;
    --neutral-700: #3e3e3e;
    --red-700: #c71b00;
    --red-800: #9e1500;
    /* Each notice's ink contrasts at least 4.5:1 with its background: test/contrast.test.ts. */
    --status-yellow: #ffefc1;
    --status-yellow-ink: #775b0a;
    --status-green: #99f0c0;
    --status-green-ink: #0a3808;
    --status-red: #ffc7c1;
    --status-red-ink: #660d03;

    /* Translucent tints of the palette, for glass, glows and shadows. */
    --veil: rgb(255 255 255 / 12%);
    --veil-strong: rgb(255 255 255 / 40%);
    --sheen: rgb(255 255 255 / 22%);
    --glow-lilac: rgb(230 206 255 / 70%);
    --glow-coral: rgb(255 79 88 / 16%);
    --shade-soft: rgb(56 0 54 / 6%);
    --shade: rgb(56 0 54 / 12%);
    --shade-deep: rgb(56 0 54 / 22%);

    /* Roles: what each colour is for. */
    --surface-page: var(--lilac-50);
    --surface-card: var(--white);
    --surface-inset: var(--lilac-50);
    --surface-head: var(--lilac-50);
    --surface-hover: var(--lilac-200);
    --brand: var(--purple-800);
    --brand-hover: var(--purple-600);
    --brand-ink: var(--white);
    --accent: var(--coral-700);
    --ink: var(--black);
    --ink-soft: var(--neutral-700);
    --ink-muted: var(--neutral-600);
    --link: var(--purple-500);
    --link-hover: var(--purple-800);
    --line: var(--neutral-300);
    --line-strong: var(--neutral-500);
    --line-brand: var(--lilac-500);
    --danger: var(--red-700);
    --danger-hover: var(--red-800);
    --focus: var(--purple-300);

    /* Type. */
    --font-sans: Poppins, ui-sans-serif, system-ui, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-4xl: 2.25rem;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --tracking-tight: -0.43px;
    --tracking-wide: 0.04em;
    --leading: 1.5;
    --leading-tight: 1.1;
    /* What labels, buttons, disclosures, notices and field errors are set in. */
    --type-label: var(--weight-medium) var(--text-sm) / var(--leading) var(--font-sans);
    --underline-offset: 0.25em;

    /* Space and size. */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --hairline: 1px;
    --stroke: 2px;
    --ring: 3px;
    --lift: -2px;
    --press: 1px;
    --rise: 0.75rem;
    --control: 3rem;
    --button: 2.5rem;
    --button-compact: 2rem;
    --checkbox: 1.25rem;
    --mark: 0.8em;
    --mark-gap: 0.35em;
    --glyph-size: 1.15em;
    --glyph-gap: 0.5em;
    --glyph-size-notice: 1lh;
    --progress: 3px;
    --measure-page: 85rem;
    --measure-main: 70rem;
    --measure-card: 34rem;
    --measure-field: 30rem;
    --measure-value: 14rem;
    --measure-text: 75ch;
    --viewport: 100dvh;
    --scroll-clear: 9rem;
    --condense-range: 6rem;

    /* Shape and depth. */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 2px var(--shade-soft), 0 1px 3px var(--shade-soft);
    --shadow-md: 0 4px 12px var(--shade), 0 2px 4px var(--shade-soft);
    --shadow-lg: 0 18px 40px var(--shade-deep), 0 4px 10px var(--shade);
    --shadow-press: inset 0 2px 4px var(--shade-deep);
    --layer-header: 10;
    --layer-progress: 20;
    --layer-skip: 30;
    --clip-all: inset(50%);

    /* Light: the sheen that crosses a button, the bar's progress line and the glow before sign-in. */
    --sheen-gradient: linear-gradient(110deg, transparent 35%, var(--sheen) 50%, transparent 65%);
    --sheen-size: 250% 100%;
    --sheen-rest: 120% 0;
    --sheen-pass: -60% 0;
    --glow:
      radial-gradient(60% 50% at 15% 10%, var(--glow-lilac), transparent),
      radial-gradient(50% 45% at 90% 85%, var(--glow-coral), transparent);
    --glow-size: 140% 140%;

    /* Motion. */
    --duration-fast: 120ms;
    --duration: 220ms;
    --duration-slow: 480ms;
    --duration-ambient: 24s;
    --stagger: 45ms;
    --tucked: -300%;
    --quarter-turn: 90deg;
    --press-scale: 0.98;
    --check-press-scale: 0.88;
    --arrive-scale: 0.98;
    --shake: var(--space-1);
    --shake-settle: calc(var(--space-1) / 2);
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  }
}
/* Elements as the whole portal sets them: type, links, focus and selection. */

@layer base {
  html {
    background: var(--surface-page);
    color: var(--ink);
    color-scheme: light;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading);
    scroll-padding-top: var(--scroll-clear);
    scrollbar-color: var(--lilac-700) transparent;
    text-size-adjust: 100%;
  }

  body {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: var(--viewport);
    margin: 0;
  }

  h1,
  h2,
  h3,
  h4 {
    margin: 0 0 var(--space-4);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-4xl);

    @media (max-width: 40rem) {
      font-size: var(--text-2xl);
    }
  }

  h2 {
    font-size: var(--text-2xl);

    @media (max-width: 40rem) {
      font-size: var(--text-xl);
    }
  }

  h3 {
    font-size: var(--text-xl);
  }

  h4 {
    margin-top: var(--space-6);
    font-size: var(--text-lg);
  }

  p {
    max-width: var(--measure-text);
    margin: 0 0 var(--space-4);
    text-wrap: pretty;
  }

  a {
    font-weight: var(--weight-medium);
    color: var(--link);
    text-decoration-thickness: var(--stroke);
    text-decoration-color: var(--line-brand);
    text-underline-offset: var(--underline-offset);

    &:hover {
      color: var(--link-hover);
      text-decoration-color: var(--accent);
    }
  }

  /* What only a screen reader needs: a link's span says which record "Edit" is for, and a table's
     caption names the table, which the heading above it already names on screen. */
  a > span,
  caption {
    position: absolute;
    width: var(--hairline);
    height: var(--hairline);
    overflow: hidden;
    white-space: nowrap;
    clip-path: var(--clip-all);
  }

  strong {
    font-weight: var(--weight-semibold);
  }

  time {
    font-variant-numeric: tabular-nums;
    color: var(--ink-muted);
  }

  :focus-visible {
    outline: var(--ring) solid var(--focus);
    outline-offset: var(--stroke);
  }

  ::selection {
    color: var(--purple-900);
    background: var(--lilac-500);
  }
}
/* The frame every page shares: the bar, the main column and the skip link. */

@layer page {
  /* Reading progress: a coral line the page's scroll draws across the top. */
  body::before {
    position: fixed;
    inset: 0 0 auto;
    z-index: var(--layer-progress);
    height: var(--progress);
    content: "";
    background: linear-gradient(to right, var(--accent), var(--purple-300));
    transform: scaleX(0);
    transform-origin: left;
  }

  /* The RubyWell bar: deep purple, rounded below, stuck to the top. */
  header {
    position: sticky;
    top: 0;
    z-index: var(--layer-header);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: auto auto 1fr;
    row-gap: var(--space-3);
    column-gap: var(--space-4);
    align-items: center;
    justify-self: center;
    width: min(100% - var(--space-6), var(--measure-page));
    padding: var(--space-5) var(--space-8);
    color: var(--brand-ink);
    background: var(--brand);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-md);

    @media (max-width: 40rem) {
      grid-template-columns: auto 1fr;
      padding: var(--space-4);
    }

    & > a {
      display: flex;
      border-radius: var(--radius-sm);
    }

    & img {
      display: block;
      height: auto;
    }

    & small {
      padding: var(--space-1) var(--space-3);
      font-size: var(--text-xs);
      font-weight: var(--weight-medium);
      color: var(--lilac-300);
      letter-spacing: var(--tracking-wide);
      background: var(--veil);
      border-radius: var(--radius-pill);

      @media (max-width: 40rem) {
        justify-self: end;
      }
    }

    & > p {
      justify-self: end;
      margin: 0;
      font-size: var(--text-sm);
      color: var(--lilac-300);
      text-align: end;

      @media (max-width: 40rem) {
        grid-column: 1 / -1;
        justify-self: start;
        text-align: start;
      }
    }

    & nav {
      display: flex;
      grid-column: 1 / -1;
      gap: var(--space-4);
      align-items: center;
      justify-content: space-between;
      min-width: 0;
    }

    & ul {
      display: flex;
      gap: var(--space-1);
      padding: var(--space-1);
      margin: 0;
      overflow-x: auto;
      list-style: none;
      scrollbar-width: none;
    }

    & li a {
      display: block;
      padding: var(--space-2) var(--space-4);
      font-size: var(--text-sm);
      color: var(--brand-ink);
      white-space: nowrap;
      text-decoration: none;
      border-radius: var(--radius-pill);

      &:hover {
        background: var(--veil);
      }

      /* The section the page is in: its own page, or one beneath or owned by it. */
      &[aria-current] {
        color: var(--brand);
        background: var(--surface-card);
      }
    }
  }

  main {
    box-sizing: border-box;
    justify-self: center;
    width: min(100%, var(--measure-main));
    padding: var(--space-10) var(--space-6) var(--space-12);

    @media (max-width: 40rem) {
      padding: var(--space-6) var(--space-4) var(--space-10);
    }

    &:focus {
      outline: none;
    }

    /* The RubyWell star before every page title. */
    & > h1::before {
      display: inline-block;
      width: var(--mark);
      height: var(--mark);
      margin-inline-end: var(--mark-gap);
      content: "";
      background: var(--accent);
      mask: url("/mark.svg") center / contain no-repeat;
    }

    & > div {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      gap: var(--space-6);

      & > * {
        margin-block: 0;
      }
    }
  }

  /* The skip link: off screen until the keyboard reaches it. */
  body > a:first-child {
    position: fixed;
    top: var(--space-4);
    left: var(--space-4);
    z-index: var(--layer-skip);
    padding: var(--space-2) var(--space-5);
    background: var(--surface-card);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-lg);
    transform: translateY(var(--tucked));

    &:focus {
      transform: none;
    }
  }

  /* Before sign-in there is no navigation: the page is one card over a lilac and coral glow. */
  body:not(:has(header nav)) {
    background: var(--glow), var(--surface-page);
    background-attachment: fixed;
    background-size: var(--glow-size);

    & main {
      align-self: center;
      width: min(100% - var(--space-6), var(--measure-card));
      padding: var(--space-10);
      margin-block: var(--space-10);
      background: var(--surface-card);
      border: var(--hairline) solid var(--line-brand);
      border-radius: var(--radius-xl);
      box-shadow: var(--shadow-lg);

      @media (max-width: 40rem) {
        padding: var(--space-5) var(--space-4);
      }
    }
  }
}
/* What a page holds: cards, labelled values, lists, tables and disclosures. */

@layer content {
  /* The card: a section, a signed-in page's own form, a search form and a table's frame. */
  section,
  header:has(nav) ~ main > div > form[method="post"],
  form[method="get"],
  div:has(> table) {
    background: var(--surface-card);
    border: var(--hairline) solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
  }

  /* A search form lifts while a reader is in it; cards do not move under the pointer. */
  form[method="get"]:focus-within {
    border-color: var(--line-brand);
    box-shadow: var(--shadow-md);
  }

  section,
  header:has(nav) ~ main > div > form[method="post"] {
    min-width: 0;
    padding: var(--space-6);

    @media (max-width: 40rem) {
      padding: var(--space-5) var(--space-4);
    }
  }

  section > :last-child,
  article > :last-child,
  fieldset > :last-child,
  form > :last-child,
  li > :last-child {
    margin-bottom: 0;
  }

  section section {
    margin-top: var(--space-6);
    box-shadow: none;
  }

  article {
    padding: var(--space-5);
    margin-block: var(--space-4);
    background: var(--surface-inset);
    border: var(--hairline) solid var(--line-brand);
    border-radius: var(--radius-lg);
  }

  /* Labelled values, the way a RubyWell profile shows them. */
  dl {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--measure-value), 1fr));
    gap: var(--space-5) var(--space-6);
    margin: 0 0 var(--space-5);
  }

  dt {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
  }

  dd {
    margin: var(--space-1) 0 0;
    font-weight: var(--weight-medium);
    overflow-wrap: anywhere;

    & p {
      margin: var(--space-1) 0 0;
      font-size: var(--text-sm);
      font-weight: var(--weight-regular);
      color: var(--ink-muted);
    }
  }

  /* Lists of records: one row each, divided by a hairline. */
  main ul {
    padding: 0;
    margin: 0 0 var(--space-4);
    list-style: none;

    & > li {
      padding-block: var(--space-3);
      border-top: var(--hairline) solid var(--line);

      &:first-child {
        border-top-color: transparent;
      }
    }

    /* A list inside a row is its history: a timeline down a lilac rule. */
    & ul {
      padding-inline-start: var(--space-4);
      margin: var(--space-2) 0;
      font-size: var(--text-sm);
      color: var(--ink-soft);
      border-inline-start: var(--stroke) solid var(--line-brand);

      & > li {
        padding-block: var(--space-1);
        border-top: 0;
      }
    }
  }

  /* A table's frame scrolls sideways on a narrow screen, and holds what is positioned inside it,
     such as a link's words for screen readers, so nothing in it widens the page. */
  div:has(> table) {
    position: relative;
    margin-bottom: var(--space-6);
    overflow-x: auto;
  }

  table {
    width: 100%;
    border-collapse: collapse;
  }

  th,
  td {
    padding: var(--space-4) var(--space-6);
    vertical-align: middle;
    text-align: start;

    @media (max-width: 40rem) {
      padding: var(--space-3) var(--space-4);
    }
  }

  /* The column names: small and quiet on a faint band, set off from the rows by a heavier rule
     rather than a strong fill, so they are not mistaken for a highlighted row. */
  th {
    padding-block: var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--ink-soft);
    white-space: nowrap;
    background: var(--surface-head);
    border-bottom: var(--stroke) solid var(--line-brand);
  }

  td {
    overflow-wrap: break-word;
    border-top: var(--hairline) solid var(--line);

    & div {
      font-size: var(--text-sm);
      font-weight: var(--weight-regular);
      color: var(--ink-muted);
    }
  }

  /* Each row's first cell names its record, so it is the one that stands out. */
  tbody > tr > td:first-child {
    font-weight: var(--weight-medium);
  }

  /* A disclosure: closed it is a quiet row, open it frames what it holds. */
  summary {
    padding: var(--space-3) var(--space-4);
    font: var(--type-label);
    color: var(--link);
    cursor: pointer;
    list-style: none;
    border-radius: var(--radius-md);

    &:hover {
      background: var(--surface-hover);
    }
  }

  details {
    margin-block: var(--space-3);
    border: var(--hairline) solid var(--line);
    border-radius: var(--radius-md);

    &[open] > summary {
      color: var(--link-hover);
      border-end-start-radius: 0;
      border-end-end-radius: 0;
    }

    &[open] > summary::before {
      transform: rotate(var(--quarter-turn));
    }

    & > :not(summary) {
      margin-inline: var(--space-4);
    }

    /* What it holds starts clear of the summary's hover colour. */
    & > summary + * {
      margin-top: var(--space-3);
    }

    & > :last-child:not(summary) {
      margin-bottom: var(--space-4);
    }

    /* The inset stays inside the box that unfolds, so clipping it leaves a field's ring whole. */
    &::details-content {
      display: flow-root;
    }
  }
}
/* What a reader acts with: fields, buttons, menus, search forms and pagination. */

@layer controls {
  /* A field: its label, its control, its error. */
  div:has(> label) {
    margin-bottom: var(--space-4);
  }

  label {
    display: block;
    margin-bottom: var(--space-2);
    font: var(--type-label);

    /* A checkbox sits beside the words of its own label. */
    &:has(> input[type="checkbox"]) {
      display: flex;
      gap: var(--space-3);
      align-items: center;
      margin-block: var(--space-4);
      cursor: pointer;
    }
  }

  input,
  select {
    font: inherit;
  }

  input:not([type="checkbox"]),
  select {
    box-sizing: border-box;
    display: block;
    width: min(100%, var(--measure-field));
    height: var(--control);
    padding: 0 var(--space-4);
    font-size: var(--text-sm);
    color: var(--ink);
    background: var(--surface-card);
    border: var(--hairline) solid var(--line-strong);
    border-radius: var(--radius-md);
  }

  input:not([type="checkbox"]):hover,
  select:hover {
    border-color: var(--purple-300);
  }

  input:not([type="checkbox"]):focus-visible,
  select:focus-visible {
    /* The ring is a shadow, which forced colours remove: the outline they draw instead stays. */
    outline: var(--ring) solid transparent;
    border-color: var(--brand-hover);
    box-shadow: 0 0 0 var(--ring) var(--lilac-500);
  }

  input[type="checkbox"] {
    width: var(--checkbox);
    height: var(--checkbox);
    margin: 0;
    accent-color: var(--brand);
    cursor: pointer;
  }

  /* Buttons, and a menu's links, which are the page's own actions. */
  button,
  menu a {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--button);
    /* Less the edge below, so a button is as large as before it had one. */
    padding: calc(var(--space-2) - var(--hairline)) calc(var(--space-5) - var(--hairline));
    font: var(--type-label);
    color: var(--brand-ink);
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    background-color: var(--brand);
    background-image: var(--sheen-gradient);
    background-repeat: no-repeat;
    background-position: var(--sheen-rest);
    background-size: var(--sheen-size);
    /* Unseen here, but the edge forced colours draw, so a button still looks like one there. */
    border: var(--hairline) solid transparent;
    border-radius: var(--radius-md);

    &:hover {
      background-color: var(--brand-hover);
      background-position: var(--sheen-pass);
      box-shadow: var(--shadow-md);
      transform: translateY(var(--lift));
    }

    &:active {
      box-shadow: var(--shadow-press);
      transform: translateY(var(--press)) scale(var(--press-scale));
    }
  }

  /* The quieter of several choices: make preferred. */
  button[name="action"][value="prefer"] {
    color: var(--brand);
    background-color: var(--surface-card);
    border: var(--hairline) solid var(--line-strong);

    &:hover {
      background-color: var(--surface-hover);
    }
  }

  /* Removing: a button that removes, and the disclosure that holds one. */
  button[name="action"][value="remove"] {
    background-color: var(--danger);

    &:hover {
      background-color: var(--danger-hover);
    }
  }

  /* Unlinking ends a connection and keeps both records, so it is red but outlined, quieter than
     removing. */
  button[name="action"][value="unlink"] {
    color: var(--danger);
    background-color: var(--surface-card);
    border: var(--hairline) solid var(--danger);

    &:hover {
      color: var(--danger-hover);
      border-color: var(--danger-hover);
    }
  }

  details:has(> form button[name="action"][value="remove"]) > summary {
    color: var(--danger);
  }

  menu {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: 0;
    margin: 0;
    list-style: none;
  }

  fieldset menu {
    margin-top: var(--space-5);
  }

  fieldset {
    min-width: 0;
    padding: 0;
    margin: 0;
    border: 0;
  }

  li > div {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: start;
    margin-top: var(--space-3);

    & > details {
      flex: 1 1 100%;
      margin-block: 0;
    }
  }

  /* A search form: its fields in a row, its button at their baseline. */
  form[method="get"] {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: end;
    padding: var(--space-5) var(--space-6);

    & > div {
      flex: 1 1 var(--measure-value);
      margin-bottom: 0;
    }

    & button {
      min-height: var(--control);
    }
  }

  /* A button in a table cell or a list row is compact. */
  td button,
  li > form:not(:has(label)) button,
  li > div button {
    min-height: var(--button-compact);
    padding: var(--space-1) var(--space-4);
    font-size: var(--text-xs);
  }

  /* Pagination: previous at the start, next at the end. */
  main nav {
    display: flex;
    gap: var(--space-4);
    justify-content: space-between;

    & a {
      padding: var(--space-2) var(--space-5);
      text-decoration: none;
      background: var(--surface-card);
      border: var(--hairline) solid var(--line-brand);
      border-radius: var(--radius-pill);

      &:hover {
        background: var(--surface-hover);
      }

      /* The next page keeps to the end, even with no previous page before it. */
      &[rel="next"] {
        margin-inline-start: auto;
      }
    }
  }

  /* The bar's sign out: an outline on the purple, not a second block of it. It narrows the
     buttons above, so it comes last and specificity only ever rises down the file. */
  header button {
    white-space: nowrap;
    background-color: transparent;
    border: var(--hairline) solid var(--veil-strong);

    &:hover {
      background-color: var(--veil);
      box-shadow: none;
    }
  }
}
/* What the portal says back: notices, field errors and invalid fields. */

@layer feedback {
  /* A notice: green when something worked, red when it was refused, yellow as a warning. */
  [role="status"],
  [role="alert"],
  [role="note"] {
    padding: var(--space-3) var(--space-4);
    /* Room for the icon that hangs before the words (the icons layer). */
    padding-inline-start: calc(var(--space-4) + var(--glyph-size-notice) + var(--glyph-gap));
    font: var(--type-label);
    border-inline-start: var(--ring) solid currentcolor;
    border-radius: var(--radius-md);
  }

  [role="status"] {
    color: var(--status-green-ink);
    background: var(--status-green);
  }

  [role="alert"] {
    color: var(--status-red-ink);
    background: var(--status-red);
  }

  [role="note"] {
    color: var(--status-yellow-ink);
    background: var(--status-yellow);
  }

  /* The passkey script fills these; until it does they take no room but stay announced. */
  [role="status"]:empty,
  [role="alert"]:empty {
    padding: 0;
    margin: 0;
    border: 0;
  }

  section[role="alert"] {
    padding: var(--space-5);
    border-radius: var(--radius-lg);

    & a {
      color: inherit;
    }
  }

  /* A field's own error, between its label and its control, or a group's after its summary. */
  p:has(+ [aria-invalid="true"]),
  details[aria-invalid="true"] > summary + p {
    padding: 0;
    margin: 0 0 var(--space-2);
    font: var(--type-label);
    color: var(--danger);
    background: none;
    border: 0;
  }

  /* An invalid control or group keeps its red edge when hovered or focused; focused, its ring turns
     red, as wide as any other. Later than controls, so it wins whatever their specificity. */
  [aria-invalid="true"] {
    border-color: var(--danger);
    box-shadow: 0 0 0 var(--hairline) var(--danger);

    &:focus-visible {
      box-shadow: 0 0 0 var(--ring) var(--danger);
    }
  }
}
/*
 * Every icon, and the one rule that draws them. An icon marks words the markup already says
 * something about: it is drawn on a `::before` or `::after` beside them, in their colour, so it
 * keeps their contrast; where the reader's colours are forced it takes the colour forced on its
 * words, rather than losing its fill to the forced background. Screen readers read the words; the
 * icon adds nothing to announce. The shapes are Lucide's (`../icons/`).
 */

@layer icons {
  /* What draws an icon: a square of the text's colour, cut to the icon's shape. It weighs nothing
     (`:where`), so the rules below that size or place one meaning's icon always win. */
  :where(
    p[role="status"]:not(:empty),
    p[role="alert"]:not(:empty),
    p[role="note"],
    section[role="alert"] > h2,
    p:has(+ [aria-invalid="true"]),
    details[aria-invalid="true"] > summary + p,
    button[name="action"][value="remove"],
    button[name="action"][value="unlink"],
    main nav a[rel="prev"],
    summary
  )::before,
  :where(main nav a[rel="next"])::after {
    display: inline-block;
    inline-size: var(--glyph-size);
    aspect-ratio: 1;
    margin-inline-end: var(--glyph-gap);
    vertical-align: middle;
    forced-color-adjust: preserve-parent-color;
    content: "";
    background-color: currentcolor;
    mask: var(--glyph) center / contain no-repeat;
  }

  /* A notice's icon is larger, a line tall, so it says at a glance what kind of notice it is
     without making its line taller; it hangs in the notice's padding, so wrapped lines start
     under the words, not under the icon. */
  p[role="status"]::before,
  p[role="alert"]::before,
  p[role="note"]::before {
    inline-size: var(--glyph-size-notice);
    margin-inline-start: calc(-1 * (var(--glyph-size-notice) + var(--glyph-gap)));
    vertical-align: top;
  }

  /* An icon after its words keeps its gap on their side. */
  main nav a[rel="next"]::after {
    margin-inline-start: var(--glyph-gap);
    margin-inline-end: 0;
  }

  /* Which meaning has which icon. */
  p[role="status"]::before {
    --glyph: url("/icons/circle-check.svg");
  }

  p[role="alert"]::before,
  section[role="alert"] > h2::before {
    --glyph: url("/icons/circle-x.svg");
  }

  p[role="note"]::before {
    --glyph: url("/icons/triangle-alert.svg");
  }

  /* A field's own error says what to fix, not that the request was refused, and is drawn at the
     text's size even when it is announced as an alert. */
  p:has(+ [aria-invalid="true"])::before,
  details[aria-invalid="true"] > summary + p::before {
    --glyph: url("/icons/circle-alert.svg");
    inline-size: var(--glyph-size);
    margin-inline-start: 0;
    vertical-align: middle;
  }

  button[name="action"][value="remove"]::before {
    --glyph: url("/icons/trash-2.svg");
  }

  button[name="action"][value="unlink"]::before {
    --glyph: url("/icons/unlink.svg");
  }

  main nav a[rel="prev"]::before {
    --glyph: url("/icons/chevron-left.svg");
  }

  main nav a[rel="next"]::after,
  summary::before {
    --glyph: url("/icons/chevron-right.svg");
  }
}
/* Everything that moves, and only for readers who have not asked for less motion. */

@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    html {
      interpolate-size: allow-keywords;
    }

    /* A disclosure's arrow turns, and what it holds unfolds. */
    summary::before {
      transition: transform var(--duration) var(--ease-spring);
    }

    details::details-content {
      block-size: 0;
      overflow: clip;
      transition:
        block-size var(--duration) var(--ease-out),
        content-visibility var(--duration) allow-discrete;
    }

    details[open]::details-content {
      block-size: auto;
    }

    /* A page arrives: its title, then each part of its body, rises into place. */
    main > h1 {
      animation: rise var(--duration-slow) var(--ease-out) both;

      &::before {
        animation: twinkle var(--duration-slow) var(--ease-spring) both;
      }
    }

    main > div > * {
      animation: rise var(--duration-slow) var(--ease-out) both;
      animation-delay: var(--stagger);

      &:nth-child(2) {
        animation-delay: calc(var(--stagger) * 2);
      }

      &:nth-child(3) {
        animation-delay: calc(var(--stagger) * 3);
      }

      &:nth-child(4) {
        animation-delay: calc(var(--stagger) * 4);
      }

      &:nth-child(n + 5) {
        animation-delay: calc(var(--stagger) * 5);
      }
    }

    body:not(:has(header nav)) {
      animation: drift var(--duration-ambient) ease-in-out infinite alternate;
    }

    body > a:first-child {
      transition: transform var(--duration) var(--ease-spring);
    }

    a,
    summary {
      transition:
        background-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out),
        text-decoration-color var(--duration-fast) var(--ease-out);
    }

    /* Things that can be pressed lift under the pointer and sink under the finger. */
    button,
    menu a {
      transition:
        background-color var(--duration) var(--ease-out),
        background-position var(--duration-slow) var(--ease-out),
        box-shadow var(--duration) var(--ease-out),
        transform var(--duration-fast) var(--ease-spring);
    }

    form[method="get"] {
      transition:
        border-color var(--duration) var(--ease-out),
        box-shadow var(--duration) var(--ease-out);
    }

    input,
    select {
      transition:
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration) var(--ease-out);
    }

    input[type="checkbox"]:active {
      transform: scale(var(--check-press-scale));
    }

    /* Notices arrive: they drop in and settle. */
    [role="status"]:not(:empty),
    [role="alert"]:not(:empty) {
      animation: arrive var(--duration-slow) var(--ease-spring) both;
    }

    [aria-invalid="true"] {
      animation: shake var(--duration-slow) var(--ease-out);
    }

    /* Only what draws the focus outline draws it in: a field's ring is its box shadow, and its
       own animation (an invalid field's shake) must not be replaced. */
    :focus-visible:not(input:not([type="checkbox"]), select) {
      animation: focus-in var(--duration) var(--ease-out);
    }

    /* Scrolling draws the progress line and tucks the bar up. */
    @supports (animation-timeline: scroll()) {
      body::before {
        animation: progress linear both;
        animation-timeline: scroll(root);
      }

      header {
        animation: condense linear both;
        animation-range: 0 var(--condense-range);
        animation-timeline: scroll(root);
      }
    }
  }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(var(--rise));
    }
  }

  @keyframes twinkle {
    from {
      opacity: 0;
      transform: rotate(calc(var(--quarter-turn) * -1)) scale(0);
    }
  }

  @keyframes arrive {
    from {
      opacity: 0;
      transform: translateY(calc(var(--rise) * -1)) scale(var(--arrive-scale));
    }
  }

  @keyframes shake {
    20% {
      transform: translateX(calc(var(--shake) * -1));
    }

    40% {
      transform: translateX(var(--shake));
    }

    60% {
      transform: translateX(calc(var(--shake-settle) * -1));
    }
  }

  @keyframes focus-in {
    from {
      outline-offset: var(--space-2);
      outline-color: transparent;
    }
  }

  @keyframes drift {
    to {
      background-position: 100% 100%;
    }
  }

  @keyframes progress {
    to {
      transform: scaleX(1);
    }
  }

  @keyframes condense {
    to {
      box-shadow: var(--shadow-lg);
      padding-block: var(--space-3);
      row-gap: var(--space-1);
    }
  }
}
