/**
 * _reset.css — Native element baselines and shared control primitives.
 *
 * @layer      reset
 * @requires   _layers.css, _properties.css, _variables.css
 * @uses       appearance: none — select chevron reset
 * @uses       ::details-content — accordion open/close (see accordion.css for :where(ui-accordion, [data-ui~="accordion"]))
 * @uses       container-type — html is the page's inline-size container, the one breakpoint
 *             tiers read when nothing closer is (layout children and any `--container-type` are closer)
 * @uses       view-transition-name via the <main> tag - main-content and [data-transition-layer] —
 *             global (animated in _view-transitions.css)
 * @uses       text-box — vertical trim on headings
 * @tokens     Native-element hooks declared in each element's rule (override them
 *             on the element): --code-* (incl. --code-font-family), --search-cancel-*,
 *             --placeholder-color, --strong-font-weight, --hr-bg,
 *             --optgroup-font-weight, --optgroup-option-pl. Text selection reads
 *             --color-selection / --color-selection-foreground (_variables.css)
 *
 * Checkbox, range, switch, select picker, popover and dialog internals live in
 * their primitive stylesheets.
 */
@layer reset {
  /* ===========================================================================
  UNIVERSAL RESET — box model, margins, padding, borders
  =========================================================================== */

  :where(*, ::before, ::after, ::backdrop, ::file-selector-button) {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0 solid;
  }

  /* ===========================================================================
  BASE ELEMENT RESETS
  =========================================================================== */

  :where(html) {
    font-family: var(--font-family-body, sans-serif);
    font-size: 16px;
    line-height: 1.5;
    tab-size: 4;
    -webkit-text-size-adjust: 100%;
    background-color: var(--color-background);
    -webkit-tap-highlight-color: transparent;

    /* html (the viewport) is the page's scrolling element, as browsers expect */
    scroll-behavior: smooth;

    /* The outermost query container: breakpoint tiers read the nearest
       inline-size container, and this one is it when nothing closer is. */
    container-type: inline-size;
    container-name: html;
  }

  :where(:host) {
    line-height: 1.5;
    tab-size: 4;
    -webkit-text-size-adjust: 100%;
  }

  :where(body) {
    display: flex;
    flex-direction: column;
    position: relative;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    text-wrap: pretty;
    color: var(--color-foreground);
    background-color: var(--color-background);
    /* at least a screen tall, so main (flex: 1) pins the footer on short pages */
    min-block-size: 100svh;
    /* clip, not hidden: no scroll container, so the viewport keeps scrolling */
    overflow-x: clip;

    font-synthesis-weight: none;
    font-size: var(--font-size-md);
    line-height: var(--leading-md);
    letter-spacing: var(--tracking-md);
    font-feature-settings: var(--font-feature-body);
    font-kerning: var(--font-kerning-body);
    font-language-override: var(--font-language-body);
    font-optical-sizing: var(--font-optical-sizing-body, auto);
    font-size-adjust: var(--font-size-adjust-body);
    font-variant-alternates: var(--font-alternates-body);
    font-variant-caps: var(--font-caps-body);
    font-variant-east-asian: var(--font-east-asian-body);
    font-variant-emoji: var(--font-emoji-body);
    font-variant-ligatures: var(--font-ligatures-body);
    font-variant-numeric: var(--font-numeric-body);
    font-variant-position: var(--font-position-body);
    font-variation-settings: var(--font-settings-body);
    font-weight: var(--font-weight-body);
  }

  /* --focus-ring sets the width; a negative one draws the outline inside the box */
  :where(:focus-visible) {
    --_focus-in: max(0, -1 * sign(var(--_focus-ring-w, 1px)));
    outline: abs(var(--_focus-ring-w, var(--outline-width))) var(--outline-style)
      var(--ring-shadow-color);
    outline-offset: calc(
      var(--outline-offset) - var(--_focus-in) *
        (2 * var(--outline-offset) + abs(var(--_focus-ring-w, var(--outline-width))))
    );
  }

  :where(b, strong) {
    --strong-font-weight: var(--font-weight-strong);
    font-weight: var(--strong-font-weight);
  }

  :where(main) {
    --_view-transition-name: main-content;

    /* predictable z-indexing */
    isolation: isolate;
    position: relative;

    /* Fill the flex body so the footer stays pinned to the bottom on short pages.
       Keeps main's box consistent between pages so view-transition snapshots align. */
    flex: 1 0 auto;
    overflow: clip;

    /* isolated so it can animate independently of header/footer */
    view-transition-name: var(--_view-transition-name);
  }

  :where([data-transition-layer="global-header"]) {
    view-transition-name: global-header;
  }

  :where([data-transition-layer="global-footer"]) {
    view-transition-name: global-footer;
  }

  :where(header, footer, section, article) {
    position: relative;
  }

  :where(pre) {
    margin: unset;
  }

  :where(a) {
    color: unset;
    background-color: unset;
    -webkit-text-decoration: inherit;
    text-decoration: inherit;
  }

  /* ===========================================================================
  TYPOGRAPHY & SEMANTIC ELEMENTS
  =========================================================================== */

  /* Headings take their role from _typography.css */

  :where(small) {
    font-size: 80%;
  }

  :where(sub, sup) {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
  }

  :where(sub) {
    bottom: -0.25em;
  }

  :where(sup) {
    top: -0.5em;
  }

  :where(abbr[title]) {
    -webkit-text-decoration: underline dotted;
    text-decoration: underline dotted;
  }

  :where(hr) {
    --hr-bg: var(--color-border);
    block-size: 1px;
    color: var(--hr-bg);
    background-color: var(--hr-bg);
    border: 0;
    flex-shrink: 0;
  }

  :where(hr[data-orientation="vertical"]) {
    inline-size: 1px;
    color: var(--hr-bg);
    background-color: var(--hr-bg);
    border: 0;
  }

  :where(code, samp, pre) {
    --code-font-family: var(--font-family-mono);
    font-family: var(--code-font-family);
    font-size: 1em;
  }

  :where(code) {
    --code-display: inline;
    --code-background: var(--color-muted);
    --code-border-width: 1px;
    --code-border-style: solid;
    --code-border-color: var(--color-muted);
    --code-padding-inline: var(--spacing);
    --code-padding-block: 0.025em;
    --code-radius: var(--radius-xs);
    --code-color: var(--color-foreground);

    display: var(--code-display);
    background-color: var(--code-background);
    padding-inline: var(--code-padding-inline);
    padding-block: var(--code-padding-block);
    border: var(--code-border-width) var(--code-border-style) var(--code-border-color);
    border-radius: var(--code-radius);
    corner-shape: var(--radius-corner-shape);
    color: var(--code-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-inline-size: 100%;
  }

  /* ===========================================================================
  LIST RESETS
  =========================================================================== */

  :where(ol, ul, menu) {
    list-style: none;
  }

  /* ===========================================================================
  TABLE RESETS
  =========================================================================== */

  :where(table) {
    text-indent: 0;
    border-color: inherit;
    border-collapse: collapse;
  }

  /* ===========================================================================
  MEDIA RESETS
  =========================================================================== */

  :where(img, svg, video, canvas, audio, iframe, embed, object) {
    display: block;
  }

  :where(img, svg, video, canvas, audio, iframe, embed, object) {
    vertical-align: middle;
  }

  :where(img, video) {
    max-inline-size: 100%;
    block-size: auto;
  }

  :where(figure) {
    display: flex;
    flex-direction: column;

    > img {
      inline-size: 100%;
    }
  }

  /* Text selection: an opaque --color-selection fill with its own
     --color-selection-foreground text, a role pair like primary, so contrast
     comes from the pair rather than a tint over unknown content.

     On :root only, on purpose (so the tokens only take effect on :root; set on
     a subtree they change nothing): highlight pseudo-elements inherit from the
     parent's highlight pseudo-element (css-pseudo-4 highlight inheritance:
     Chrome 134+, Firefox, WebKit), so one rule reaches every selection. A
     universal `::selection` rule that reads a var() makes Chromium recalculate
     an element's whole subtree whenever any custom property on it changes
     (measured: a container's inline utility change restyled 1,000 styled
     children, 194 ms per frame; 0.4 ms with this form). Engines without
     highlight inheritance fall back to the UA selection color. */
  :root::selection {
    background-color: var(--color-selection);
    color: var(--color-selection-foreground);
  }

  /* ===========================================================================
  FORM ELEMENT RESETS
  =========================================================================== */

  :where(button, input, optgroup, select, textarea),
  ::file-selector-button {
    font: inherit;
    font-feature-settings: inherit;
    font-variation-settings: inherit;
    letter-spacing: inherit;
    color: inherit;
    padding: unset;
  }

  :where(button, input, select, textarea),
  ::file-selector-button {
    border-radius: 0;
    background-color: transparent;
    opacity: 1;
  }

  :where(button, input[type="button"], input[type="reset"], input[type="submit"]),
  ::file-selector-button {
    appearance: button;
  }

  ::file-selector-button {
    margin-inline-end: 4px;
  }

  :where(select:is([multiple], [size])) optgroup {
    --optgroup-font-weight: var(--font-weight-strong);
    font-weight: var(--optgroup-font-weight);
  }

  :where(select:is([multiple], [size])) optgroup option {
    --optgroup-option-pl: var(--space-sm);
    padding-inline-start: var(--optgroup-option-pl);
  }

  :-moz-ui-invalid {
    box-shadow: none;
  }

  ::-webkit-inner-spin-button,
  ::-webkit-outer-spin-button {
    height: auto;
  }

  ::-webkit-search-decoration {
    -webkit-appearance: none;
  }

  ::-webkit-details-marker {
    display: none;
  }

  ::-webkit-search-cancel-button {
    --search-cancel-display: block;
    --search-cancel-color: currentColor;
    --search-cancel-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Cline x1='200' y1='56' x2='56' y2='200' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='200' y1='200' x2='56' y2='56' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E");
    --search-cancel-icon-size: calc(var(--spacing) * 4);
    --search-cancel-size: calc(var(--spacing) * 6);
    --search-cancel-radius: var(--radius-sm);

    -webkit-appearance: none;

    margin: 0;
    padding: 0;
    inline-size: var(--search-cancel-size);
    block-size: var(--search-cancel-size);
    border-radius: var(--search-cancel-radius);
    corner-shape: var(--radius-corner-shape);

    transition:
      opacity var(--default-transition-duration) var(--default-transition-timing-function),
      display var(--default-transition-duration) var(--default-transition-timing-function)
        allow-discrete;

    mask: var(--search-cancel-mask) no-repeat center / var(--search-cancel-icon-size);
    background-size: var(--search-cancel-icon-size);
    background-color: var(--search-cancel-color);
    background-repeat: no-repeat;
    background-position: center;
  }

  ::-webkit-search-cancel-button:is(:hover) {
    opacity: 0.5;
  }

  /* Suppress the browser's built-in password reveal / clear glyphs (Edge/IE) so
     they never double up with the Zazz [data-password-group-slot~="toggle"] button. */
  ::-ms-reveal,
  ::-ms-clear {
    display: none;
  }

  ::-webkit-date-and-time-value {
    min-height: 1lh;
    text-align: inherit;
  }

  ::-webkit-datetime-edit {
    display: inline-flex;
  }

  ::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
  }

  ::-webkit-datetime-edit,
  ::-webkit-datetime-edit-year-field,
  ::-webkit-datetime-edit-month-field,
  ::-webkit-datetime-edit-day-field,
  ::-webkit-datetime-edit-hour-field,
  ::-webkit-datetime-edit-minute-field,
  ::-webkit-datetime-edit-second-field,
  ::-webkit-datetime-edit-millisecond-field,
  ::-webkit-datetime-edit-meridiem-field {
    padding-block: 0;
  }

  ::-webkit-calendar-picker-indicator {
    line-height: 1;
  }

  :where(textarea, input) {
    font-size: unset;
    block-size: unset;
    padding: unset;
    margin-bottom: unset;
    line-height: unset;
    background-color: unset;
    border: unset;
  }

  :where(textarea) {
    resize: vertical;
  }

  ::placeholder {
    --placeholder-color: var(--color-muted-foreground);
    color: var(--placeholder-color);
  }

  :where(select) {
    font-size: unset;
    padding: unset;
    margin: unset;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background-repeat: no-repeat;
    background-position: right center;
  }

  ::picker(select) {
    padding: unset;
    margin: unset;
  }

  :where(button) {
    color: unset;
    padding: unset;
    text-align: inherit;
    background-color: unset;
  }

  /* ===========================================================================
  BROWSER NORMALIZATION
  =========================================================================== */

  /* Strip UA chrome so progress.css / meter.css can redraw track and fill. */
  :where(progress, meter) {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border: none;
    background: none;
    vertical-align: baseline;
  }

  /* WebKit wraps both controls in an inner box that carries its own UA styles */
  :where(progress)::-webkit-progress-inner-element {
    display: block;
    block-size: 100%;
  }

  :where(meter)::-webkit-meter-inner-element {
    display: block;
    block-size: 100%;
  }

  /* ===========================================================================
  MISCELLANEOUS RESETS
  =========================================================================== */

  :where([hidden]:not([hidden="until-found"])) {
    display: none !important;
  }
}
