/*
 * Responsible for: the page's ground rules: the reset, the type scale, links, the focus ring, and the one set of buttons
 * every screen uses (`.ia-btn`, made by screens/kit/button.ts or written on a link that looks like one).
 *
 * Must never: hold a colour, size or speed of its own (they come from tokens.css), hide the focus ring, animate anything
 * but transform and opacity, or give a hover effect to something that cannot be pressed.
 */

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

  html {
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* A wild swipe past the end of the page stays a swipe; it cannot drag the page into a stretched, broken state. */
    overscroll-behavior: none;
  }

  body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font: 400 var(--t-md) / 1.5 var(--sans);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
  }

  :where(h1, h2, h3, h4, p, ul, ol, figure, blockquote, dl, dd) {
    margin: 0;
  }

  :where(ul, ol) {
    padding: 0;
  }

  :where(h1, h2, h3) {
    font-weight: 500;
    text-wrap: balance;
  }

  h1 {
    font: 500 clamp(var(--t-xl), 7.4vw, var(--t-3xl)) / 1.12 var(--serif);
    letter-spacing: -0.01em;
  }

  h2 {
    font: 500 clamp(var(--t-xl), 6vw, var(--t-2xl)) / 1.2 var(--serif);
    letter-spacing: -0.005em;
  }

  h3 {
    font: 600 var(--t-lg) / 1.3 var(--sans);
  }

  :where(p) {
    text-wrap: pretty;
  }

  :where(img, svg) {
    display: block;
    max-width: 100%;
  }

  a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
  }

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

  /* No double-tap-to-zoom delay on anything that can be pressed. */
  :where(a, button, summary, label, input, select, textarea) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  [hidden] {
    display: none !important;
  }

  .ia-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* A box that scrolls inside itself and hands the swipe back to itself, never to the page behind it. */
  .ia-scroll {
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Buttons. A wash laid over the button lightens it under the pointer and darkens it while pressed; only the wash's
     opacity and the button's lift move, so nothing repaints a layout and nothing jumps. */
  .ia-btn {
    --ia-wash-hover: var(--ink);
    --ia-wash-hover-amount: 0.05;
    --ia-wash-press-amount: 0.08;
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: var(--tap);
    padding: 0 var(--s-5);
    border: 1px solid var(--rule);
    border-radius: var(--r-md);
    background: var(--panel);
    color: var(--ink);
    font: 600 var(--t-md) / 1.2 var(--sans);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: transform var(--fast) var(--ease);
  }

  .ia-btn::before,
  .ia-btn::after {
    content: "";
    position: absolute;
    inset: -1px;
    z-index: -1;
    border-radius: inherit;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--fast) var(--ease);
  }

  .ia-btn::before {
    background: var(--ia-wash-hover);
  }

  .ia-btn::after {
    background: var(--ink);
  }

  @media (hover: hover) {
    .ia-btn:hover {
      transform: translateY(-1px);
    }

    .ia-btn:hover::before {
      opacity: var(--ia-wash-hover-amount);
    }
  }

  .ia-btn:active {
    transform: translateY(0);
  }

  .ia-btn:active::after {
    opacity: var(--ia-wash-press-amount);
  }

  .ia-btn:disabled {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
  }

  /* A button at rest (aria-disabled) keeps the keyboard focus and its look: it rests for half a second, and a faded button
     would look broken to a person who simply pressed it twice. While the mailbox works, the pointer says so. */
  .ia-btn[aria-busy="true"] {
    cursor: progress;
  }

  .ia-btn--primary {
    --ia-wash-hover: var(--pop);
    --ia-wash-hover-amount: 0.16;
    --ia-wash-press-amount: 0.2;
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow-1);
  }

  /* A main button that leads into the example: the same blue as "Demo" in the banner. */
  .ia-btn--demo {
    border-color: var(--demo);
    background: var(--demo);
  }

  .ia-btn--quiet {
    padding: 0 var(--s-4);
    border-color: transparent;
    background: transparent;
    color: var(--accent);
  }

  /* The one main action of a screen. */
  .ia-btn--big {
    min-height: calc(var(--tap) + var(--s-2));
    padding: 0 var(--s-6);
    font-size: var(--t-lg);
  }
}
