/* ==========================================================================
   Nexteryale — base layer (load AFTER tokens.css, BEFORE components).

   QUOI   : light reset, document defaults, focus, scrollbars, selection,
            shared interaction states and reduced-motion handling.
   POURQUOI: every component can then assume a sane box model, inherited
            fonts and one consistent focus ring — no per-component patch.
   COMMENT: element selectors only (+ a few utilities prefixed .nx-), low
            specificity via :where() so any component rule wins without
            !important.
   ========================================================================== */

/* ---- Reset ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

:where(html) {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
  /* Stable gutter: no layout jump when a scrollbar appears mid-stream. */
  scrollbar-gutter: stable;
}

:where(body) {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, pre) { margin: 0; }
:where(h1, h2, h3, h4) { line-height: var(--leading-tight); font-weight: var(--weight-semibold); color: var(--color-text-strong); text-wrap: balance; }
:where(p) { text-wrap: pretty; }
:where(ul[role="list"], ol[role="list"]) { list-style: none; margin: 0; padding: 0; }
:where(img, svg, video, canvas) { display: block; max-width: 100%; }
:where(svg) { flex-shrink: 0; }

/* Form controls inherit the type system instead of the UA's 13px Arial. */
:where(button, input, select, textarea) {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  margin: 0;
}
:where(button) { cursor: pointer; background: none; border: 0; padding: 0; }
:where(button:disabled, [aria-disabled="true"]) { cursor: not-allowed; }
:where(textarea) { resize: none; }
:where(::placeholder) { color: var(--color-text-subtle); opacity: 1; }

:where(a) { color: var(--color-link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
:where(a:hover) { color: var(--color-accent-hover); }

:where(code, kbd, samp, pre) { font-family: var(--font-mono); font-size: 0.92em; }
:where(hr) { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-4) 0; }

::selection { background: var(--color-accent-soft); color: var(--color-accent-soft-text); }

/* ---- Focus ------------------------------------------------------------ */
/* Keyboard focus only (:focus-visible): a mouse click never paints a ring.
   2px ring + 2px offset is ≥ 3:1 on every surface (contrast.py). */
:where(:focus) { outline: none; }
:where(:focus-visible) {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus); /* Sider's soft violet halo around the AA ring */
  border-radius: var(--radius-sm);
}
/* Fields draw the ring inside their own rounded box. */
:where(input, textarea, select):focus-visible { outline-offset: 0; }

/* ---- Scrollbars ------------------------------------------------------- */
/* Thin, theme-aware, invisible until the container is hovered. */
:where(*) {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
:where(*:hover, *:focus-within) { scrollbar-color: var(--color-border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: var(--radius-full);
  border: 3px solid transparent;
  background-clip: padding-box;
}
:hover::-webkit-scrollbar-thumb { background-color: var(--color-border-strong); }

/* ---- Shared states ---------------------------------------------------- */
/* Disabled: dimmed + no pointer events, never meaning by colour alone
   (components also set aria-disabled / disabled). */
:where(:disabled, [aria-disabled="true"]) { opacity: 0.45; }

/* ---- Utilities -------------------------------------------------------- */
.nx-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;
}
.nx-skip-link {
  position: absolute; left: var(--space-2); top: var(--space-2);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-raised);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transform: translateY(-200%);
}
.nx-skip-link:focus-visible { transform: none; }

/* ---- Reduced motion --------------------------------------------------- */
/* Keep state changes, drop travel: durations collapse to ~0 and the
   streaming caret stops blinking (components read --motion-scale too). */
:root { --motion-scale: 1; }
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-scale: 0;
    --duration-fast: 1ms;
    --duration-base: 1ms;
    --duration-slow: 1ms;
  }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
