/* What a bare element looks like, so a page written as plain ERB (a heading, a form, a table)
   is already presentable. Selectors here are kept weak; components.css builds on them. */
@layer tokens, base, layout, components, screens;

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

  [hidden] {
    display: none !important;
  }

  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 1rem/1.5 var(--font);
  }

  /* No element brings a margin of its own; the rhythm below sets them. Both are written with
     :where(), which weighs nothing, so that the later rule wins and any class wins over both. */
  :where(h1, h2, h3, p, ul, ol, dl, dd, table, fieldset, figure, form) {
    margin: 0;
  }

  h1, h2, h3 {
    line-height: 1.2;
    text-wrap: balance;
  }

  h1 { font-size: 1.625rem; letter-spacing: -0.01em; }
  h2 { font-size: 1.1875rem; }
  h3 { font-size: 1rem; }

  /* Vertical rhythm: inside these, each thing stands a step below the one before it, and a
     section heading a little further. The hidden fields Rails opens a form with do not count. */
  :where(main, section, article, form, fieldset, details, .stack) > :not(input[type="hidden"]) + * {
    margin-block-start: var(--space-4);
  }

  :where(main, .stack) > * + :where(h2, section) {
    margin-block-start: var(--space-6);
  }

  a {
    color: var(--accent);
    text-underline-offset: 0.15em;
  }

  a:hover {
    color: var(--accent-strong);
  }

  :focus-visible {
    outline: 0.1875rem solid var(--focus);
    outline-offset: 0.125rem;
  }

  small {
    color: var(--ink-soft);
    font-size: var(--text-sm);
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    overflow-wrap: anywhere;
  }

  ul, ol {
    padding-inline-start: 1.25rem;
  }

  /* Fields. */
  label {
    display: block;
    font-weight: 600;
  }

  input:not([type="radio"], [type="checkbox"], [type="submit"], [type="hidden"]),
  select,
  textarea {
    display: block;
    width: 100%;
    max-width: 28rem;
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    font: inherit;
  }

  textarea {
    max-width: none;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    overflow-wrap: anywhere;
  }

  input[type="radio"],
  input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0;
    accent-color: var(--accent);
  }

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

  legend {
    padding: 0;
    font-weight: 600;
  }

  summary {
    width: fit-content;
    color: var(--accent);
    cursor: pointer;
  }

  /* Buttons. One that is not marked otherwise is a quiet outline; a page gives its main action
     button--primary (components.css). A link may dress as one with class "button". */
  button,
  input[type="submit"],
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
  }

  :is(button, input[type="submit"], .button):hover {
    border-color: var(--ink);
    color: var(--ink);
  }

  /* Tables and lists of facts. A wide table goes in a .table-scroll (components.css). */
  table {
    width: 100%;
    border-collapse: collapse;
  }

  th,
  td {
    padding: var(--space-3);
    border-block-end: 1px solid var(--line);
    text-align: start;
    vertical-align: middle;
  }

  th {
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  dl {
    display: grid;
    grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
    gap: var(--space-2) var(--space-5);
  }

  dt {
    color: var(--ink-soft);
  }

  dd {
    overflow-wrap: anywhere;
  }

  @media (max-width: 30rem) {
    dl {
      grid-template-columns: minmax(0, 1fr);
      gap: 0;
    }

    dd + dt {
      margin-block-start: var(--space-3);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    :is(a, button, input[type="submit"], .button) {
      transition: background-color 120ms, border-color 120ms, color 120ms;
    }
  }
}
