/* base.css: ui-craft starter layer. Load AFTER tokens.css and BEFORE your site.css.
   It gives correct structure and accessibility (focus, tap size, labels, motion, theme)
   and takes every visual value from tokens.css. It sits in cascade layers, so any
   rule in your own unlayered site.css wins without !important or specificity fights. */

@layer reset, base, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, picture, video, canvas { display: block; max-width: 100%; height: auto; }
  svg { max-width: 100%; flex-shrink: 0; }
  input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
  p, h1, h2, h3, h4, h5, h6, li, dd, figcaption, blockquote { overflow-wrap: break-word; }
  button { cursor: pointer; }
  [hidden] { display: none !important; }
}

@layer base {
  html { scroll-padding-top: 5rem; }
  @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
  body {
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-text);
    font-size: var(--step-0);
    line-height: var(--leading-body);
    font-kerning: normal;
  }
  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: var(--weight-display);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-display);
    text-wrap: balance;
    color: var(--ink);
  }
  h1 { font-size: var(--step-5); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-2); line-height: var(--leading-snug); }
  h4 { font-size: var(--step-1); line-height: var(--leading-snug); }
  p, li, dd { text-wrap: pretty; }
  p { max-width: var(--measure); }
  strong, b { font-weight: var(--weight-strong); }
  small { font-size: var(--step--1); }
  a { color: var(--accent-ink); text-decoration-thickness: from-font; text-underline-offset: .18em; }
  a:hover { text-decoration-thickness: 2px; }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  ::selection { background: var(--accent-tint); color: var(--ink); }
  hr { border: 0; border-top: var(--border-w) solid var(--line); }
  table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  th { text-align: start; font-weight: var(--weight-strong); color: var(--ink-2); font-size: var(--step--1); }
  th, td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); vertical-align: top; }
  td.num, th.num { text-align: end; }
  code, kbd, samp, pre { font-family: var(--font-mono); font-size: .92em; }
  pre { overflow-x: auto; padding: var(--space-4); background: var(--surface-2); border-radius: var(--radius-2); }
  blockquote { font-family: var(--font-display); font-size: var(--step-2); line-height: var(--leading-snug); }
  figcaption { color: var(--ink-3); font-size: var(--step--1); margin-top: var(--space-2); }
}

@layer components {
  .container { width: min(100% - 2 * var(--gutter), var(--container)); margin-inline: auto; }
  .section { padding-block: var(--section); }
  .stack > * + * { margin-top: var(--space-4); }
  .tabular { font-variant-numeric: tabular-nums; }
  .muted { color: var(--ink-3); }

  .skip-link {
    position: absolute; left: var(--space-3); top: -200px; z-index: 100;
    padding: var(--space-2) var(--space-4); background: var(--ink); color: var(--paper);
    border-radius: var(--radius-1);
  }
  .skip-link:focus { top: var(--space-3); }
  .visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  /* Buttons: one .btn-primary per screen; everything else secondary or text. */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: var(--tap); padding: var(--space-2) var(--space-5);
    border: var(--border-w) solid transparent; border-radius: var(--radius-1);
    font-family: var(--font-text); font-weight: var(--weight-strong); font-size: var(--step-0); line-height: 1.2;
    text-decoration: none; text-align: center;
    transition: background-color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
                transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
  }
  .btn-primary { background: var(--accent); color: var(--on-accent); }
  .btn-primary:hover { background: color-mix(in oklab, var(--accent), var(--ink) 14%); }
  .btn-secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
  .btn-secondary:hover { background: var(--surface-2); }
  .btn-text { display: inline-flex; align-items: center; min-height: var(--tap); padding-inline: 0; background: none; border: 0; color: var(--accent-ink); font-weight: var(--weight-strong); text-decoration: underline; text-underline-offset: .18em; }
  .btn:active { transform: translateY(1px); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
  .btn svg { width: 1.1em; height: 1.1em; }

  /* Forms: visible label above the field, hint and error below. */
  .field { display: grid; gap: var(--space-2); }
  .field > label, .field > .label { font-weight: var(--weight-strong); }
  .field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
    width: 100%; min-height: var(--tap); padding: var(--space-2) var(--space-3);
    background: var(--surface); color: var(--ink);
    border: var(--border-w) solid var(--line-strong); border-radius: var(--radius-1);
  }
  .field textarea { min-height: 7rem; resize: vertical; }
  .field :is(input, select, textarea):focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
  .field ::placeholder { color: var(--ink-3); opacity: 1; }
  .field .hint { color: var(--ink-3); font-size: var(--step--1); }
  .field .error { color: var(--danger-ink); font-size: var(--step--1); font-weight: var(--weight-strong); }
  .field [aria-invalid="true"] { border-color: var(--danger-ink); }
  .check { display: flex; gap: var(--space-3); align-items: center; min-height: var(--tap); }
  .check input { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }

  /* States */
  .notice { padding: var(--space-4); border-radius: var(--radius-2); background: var(--surface-2); }
  .notice[data-tone="ok"] { background: var(--ok-tint); color: var(--ok-ink); }
  .notice[data-tone="warn"] { background: var(--warn-tint); color: var(--warn-ink); }
  .notice[data-tone="danger"] { background: var(--danger-tint); color: var(--danger-ink); }
  .skeleton { background: var(--surface-2); border-radius: var(--radius-1); min-height: 1em; }

  /* Header + accessible mobile menu (see templates/page.html for the markup and script). */
  .site-header { border-bottom: var(--border-w) solid var(--line); background: var(--paper); }
  .site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: 4rem; }
  .brand { display: inline-flex; align-items: center; min-height: var(--tap); font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--step-1); color: var(--ink); text-decoration: none; }
  .site-nav ul { display: flex; gap: var(--space-2); list-style: none; padding: 0; }
  .site-nav a { display: inline-flex; align-items: center; min-height: var(--tap); padding-inline: var(--space-3); color: var(--ink); text-decoration: none; border-radius: var(--radius-1); }
  .site-nav a:hover { background: var(--surface-2); }
  .site-nav a[aria-current="page"] { color: var(--accent-ink); text-decoration: underline; text-underline-offset: .3em; }
  .nav-toggle { display: none; min-height: var(--tap); min-width: var(--tap); padding-inline: var(--space-3); background: none; border: var(--border-w) solid var(--line-strong); border-radius: var(--radius-1); color: var(--ink); }
  /* Collapsible menu only when the header has a toggle; 2-4 links can stay inline on phones. */
  @media (max-width: 47.99em) {
    .site-header__inner:has(.nav-toggle) { flex-wrap: wrap; }
    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .nav-toggle[aria-expanded="false"] + .site-nav { display: none; }
    .site-header__inner:has(.nav-toggle) .site-nav { flex-basis: 100%; padding-bottom: var(--space-3); }
    .site-header__inner:has(.nav-toggle) .site-nav ul { flex-direction: column; gap: 0; }
    .site-header__inner:has(.nav-toggle) .site-nav a { width: 100%; }
    .site-nav a { padding-inline: var(--space-2); }
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
