/* ===========================================================================
   Base layer. Element defaults only — no components, no utilities.
   Every value comes from tokens.css.

   Written with logical properties throughout (inline-start, block-end) rather
   than left/right/top/bottom. Arabic is on the roadmap and RTL retrofitting a
   stylesheet is far more expensive than writing it this way from the start.
   =========================================================================== */

@layer base {

  *, *::before, *::after { box-sizing: border-box; }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Respects the user's OS setting instead of forcing smooth scroll. */
    scroll-behavior: smooth;
  }

  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
  }

  body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bh-surface-0);
    color: var(--bh-chrome);
    font-family: var(--ff-ui);
    font-size: var(--fs-body);
    line-height: var(--lh-ui);
    font-synthesis-weight: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  /* A perfectly flat digital surface reads synthetic. 2.5% of grain makes the
     product feel like an object. See docs/design/00-design-language.md. */
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: var(--z-base);
    pointer-events: none;
    background-image: url("../brand/grain.svg");
    opacity: 0.025;
  }

  h1, h2, h3, h4 {
    margin-block: 0 var(--sp-3);
    font-weight: 600;
    line-height: var(--lh-heading);
    text-wrap: balance;
  }

  h1 { font-size: var(--fs-h1); letter-spacing: -0.025em; line-height: var(--lh-tight); }
  h2 { font-size: var(--fs-h2); letter-spacing: -0.02em; }
  h3 { font-size: var(--fs-h3); letter-spacing: -0.01em; }

  p {
    margin-block: 0 var(--sp-4);
    text-wrap: pretty;
  }

  a {
    color: var(--bh-ion);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: color var(--dur-instant) var(--ease-human);
  }
  a:hover { color: var(--bh-chrome); }

  /* Focus is never removed, only replaced. :focus-visible so a mouse click does
     not paint a ring but a keyboard user always gets one.
     See docs/rules/11-accessibility.md. */
  :focus-visible {
    outline: 2px solid var(--bh-ember);
    outline-offset: 2px;
    border-radius: var(--r-xs);
  }

  /* Evidence voice. Any provenance datum renders monospaced, always. */
  code, kbd, samp, pre, .bh-evidence {
    font-family: var(--ff-evidence);
    font-variant-ligatures: none;
    letter-spacing: 0;
    overflow-wrap: anywhere;
  }

  img, svg, video { max-width: 100%; height: auto; display: block; }

  hr {
    border: 0;
    border-block-start: 1px solid var(--bh-hairline);
    margin-block: var(--sp-6);
  }

  ul, ol { padding-inline-start: var(--sp-5); }

  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }

  /* Native field auto-sizing where supported, so Spanish labels that run 15-30%
     longer than English do not clip. */
  input, textarea, select { field-sizing: content; }

  [hidden] { display: none !important; }

  .bh-visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* Skip link: visible only once focused. */
  .bh-skip {
    position: absolute;
    inset-block-start: var(--sp-2);
    inset-inline-start: var(--sp-2);
    z-index: var(--z-toast);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-sm);
    background: var(--bh-ember);
    color: var(--bh-on-accent);
    font-weight: 600;
    transform: translateY(-200%);
    transition: transform var(--dur-fast) var(--ease-enter);
  }
  .bh-skip:focus-visible { transform: translateY(0); }

  /* Navigation happens on the Z axis, not the X axis. No animation JavaScript. */
  @view-transition { navigation: auto; }

  ::view-transition-old(root) {
    animation: bh-recede var(--dur-base) var(--ease-exit) both;
  }
  ::view-transition-new(root) {
    animation: bh-advance var(--dur-base) var(--ease-enter) both;
  }

  @keyframes bh-recede {
    to { opacity: 0; transform: scale(0.96); filter: blur(8px); }
  }
  @keyframes bh-advance {
    from { opacity: 0; transform: translateY(8px); }
  }
}
