@layer reset {
  html {
    box-sizing: border-box;
    accent-color: var(--color-accent);
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
  }

  :where(body, header, nav, main, section, article, aside, footer, div, form, fieldset, dialog, input, select, textarea, button, canvas) {
    box-sizing: border-box;
  }

  body, h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote, pre {
    margin: 0;
  }

  h1, h2, h3, h4, button, input, select, textarea {
    font: inherit;
    color: inherit;
  }

  button {
    background: none;
    border: none;
    padding: 0;
  }

  ul, ol {
    padding: 0;
    list-style: none;
  }

  img, svg, canvas {
    display: block;
    max-inline-size: 100%;
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    background-color: var(--bg-canvas);
    color: var(--ink-primary);
    line-height: 1.55;
    min-block-size: 100dvb;
    display: flex;
    flex-direction: column;
    overflow-x: clip;
  }

  code, pre, kbd, .mono {
    font-family: var(--font-mono);
  }

  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
  }

  /* Enforce native hidden attribute over component display rules (except until-found) */
  [hidden]:not([hidden="until-found"]) {
    display: none !important;
  }

  /* Accessible visually-hidden utility */
  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .skip-link {
    position: fixed;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-3);
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    background-color: var(--color-accent);
    color: var(--color-accent-contrast);
    font-weight: 700;
    text-decoration: none;
  }

  /* Standard scrollbars with WebKit fallback */
  .scroller {
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
  }

  @supports not (scrollbar-color: auto) {
    html,
    .scroller {
      scrollbar-width: auto;
    }

    html::-webkit-scrollbar,
    .scroller::-webkit-scrollbar {
      width: 10px;
      height: 10px;
    }

    html::-webkit-scrollbar-thumb,
    .scroller::-webkit-scrollbar-thumb {
      background: var(--scrollbar-thumb);
      border-radius: var(--radius-pill);
    }

    html::-webkit-scrollbar-track,
    .scroller::-webkit-scrollbar-track {
      background: var(--scrollbar-track);
    }
  }

  /* Fallback for range & checkbox where accent-color is unsupported */
  @supports not (accent-color: auto) {
    input[type="range"] {
      -webkit-appearance: none;
      appearance: none;
      background: transparent;
      cursor: pointer;
    }

    input[type="range"]::-webkit-slider-runnable-track {
      height: 6px;
      border-radius: var(--radius-pill);
      background: linear-gradient(
        to right,
        var(--color-accent) var(--progress, 50%),
        var(--border-subtle) var(--progress, 50%)
      );
    }

    input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: var(--color-accent);
      margin-top: -5px;
    }
  }

  /* Respect reduced motion for View Transitions */
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
      animation: none !important;
    }
  }

  /* Branch theme toggle icon/label visibility in CSS without JS class dependence */
  .theme-toggle .theme-label-to-light,
  .theme-toggle .theme-icon-sun {
    display: none;
  }

  :root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-toggle {
    & .theme-label-to-light,
    & .theme-icon-sun {
      display: inline-flex;
    }

    & .theme-label-to-dark,
    & .theme-icon-moon {
      display: none;
    }
  }

  @media (prefers-color-scheme: dark) {
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-toggle {
      & .theme-label-to-light,
      & .theme-icon-sun {
        display: inline-flex;
      }

      & .theme-label-to-dark,
      & .theme-icon-moon {
        display: none;
      }
    }
  }
}
