/*
 * IRSC base: element defaults built only from irsc-tokens.css.
 *
 * Element rules sit inside :where() so they carry zero specificity; any rule
 * an app writes, even a bare element selector, wins without !important.
 * The utility classes and the print rules at the end use plain selectors on
 * purpose so an app's element rules cannot undo them.
 */

/* Box model */
:where(*),
::before,
::after {
  box-sizing: border-box;
}

:where(html) {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Page */
:where(body) {
  margin: 0;
  background: var(--irsc-bg);
  color: var(--irsc-text);
  font-family: var(--irsc-font-body);
  font-size: 1rem;
  line-height: var(--irsc-leading);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings: Metronic Slab Pro semibold where installed, brand fallbacks elsewhere */
:where(h1, h2, h3, h4) {
  margin: 0 0 var(--irsc-space-3);
  color: var(--irsc-heading);
  font-family: var(--irsc-font-display);
  font-weight: var(--irsc-weight-semibold);
  line-height: var(--irsc-leading-tight);
  text-wrap: balance;
}

:where(h1) {
  font-size: var(--irsc-text-3xl);
}

:where(h2) {
  font-size: var(--irsc-text-2xl);
}

:where(h3) {
  font-size: var(--irsc-text-xl);
}

:where(h4) {
  font-size: var(--irsc-text-lg);
}

/* Give a heading room when it follows running content */
:where(p, ul, ol, dl, blockquote, pre, table, figure) + :where(h2, h3, h4) {
  margin-top: var(--irsc-space-6);
}

:where(small) {
  font-size: var(--irsc-text-sm);
}

/* Links */
:where(a) {
  color: var(--irsc-link);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

:where(a:hover) {
  color: var(--irsc-link-hover);
  text-decoration-thickness: 2px;
}

/* Focus: a ring in the focus color with a halo on both sides, so it reads
   on light, dark and brand-colored backgrounds alike. */
:where(:focus-visible) {
  outline: var(--irsc-focus-width) solid var(--irsc-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 calc(var(--irsc-focus-width) + 4px) var(--irsc-focus-halo);
}

/* The header and toasts sit on the header color, where River Blue vanishes (1.6:1) */
:where(.irsc-header :focus-visible, .irsc-toast :focus-visible) {
  outline-color: var(--irsc-header-focus);
  box-shadow: 0 0 0 calc(var(--irsc-focus-width) + 4px) var(--irsc-header-bg);
}

::selection {
  background: var(--irsc-highlight);
  color: var(--irsc-on-highlight);
}

/* Media */
:where(img, svg, video, canvas, picture) {
  max-width: 100%;
}

:where(img, video) {
  height: auto;
}

/* Tables */
:where(table) {
  border-collapse: collapse;
  border-spacing: 0;
}

:where(th) {
  background: var(--irsc-surface-sunken);
  color: var(--irsc-text);
  font-weight: var(--irsc-weight-semibold);
  text-align: start;
}

/* Form controls take the page font instead of the browser's. Color is left to
   the browser (or a component) so an unstyled control never inherits light
   text from a dark header, toast or app onto its light default background. */
:where(button, input, select, textarea) {
  font: inherit;
}

:where(button, [role="button"], label[for], select, summary) {
  cursor: pointer;
}

:where(input[type="checkbox"], input[type="radio"]) {
  accent-color: var(--irsc-accent);
}

/* Code */
:where(code, kbd, samp, pre) {
  font-family: var(--irsc-font-mono);
  font-size: 0.9em;
}

:where(pre) {
  overflow-x: auto;
  padding: var(--irsc-space-4);
  border-radius: var(--irsc-radius-md);
  background: var(--irsc-surface-sunken);
  color: var(--irsc-text);
}

:where(hr) {
  height: 0;
  margin: var(--irsc-space-6) 0;
  border: 0;
  border-top: 1px solid var(--irsc-border);
}

/* Utilities */

/* Skip link: off screen until a keyboard user tabs to it */
.irsc-skip-link {
  position: absolute;
  top: var(--irsc-space-3);
  left: var(--irsc-space-3);
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  min-height: var(--irsc-control-height);
  padding: var(--irsc-space-2) var(--irsc-space-4);
  border-radius: var(--irsc-radius-sm);
  background: var(--irsc-highlight);
  color: var(--irsc-on-highlight);
  font-weight: var(--irsc-weight-semibold);
  text-decoration: underline;
  transform: translateY(calc(-100% - var(--irsc-space-4)));
}

.irsc-skip-link:focus {
  transform: none;
}

/* Visually hidden, still read by screen readers */
.irsc-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

/* Motion: honor the visitor's reduced-motion setting everywhere */
@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Windows high contrast and other forced-color modes drop box shadows and
   backgrounds, so focus and control edges must come from outlines and borders. */
@media (forced-colors: active) {
  :where(:focus-visible),
  :where(.irsc-header :focus-visible, .irsc-toast :focus-visible) {
    outline: var(--irsc-focus-width) solid Highlight;
    box-shadow: none;
  }

  :where(hr) {
    border-top-color: CanvasText;
  }

  /* Its yellow fill is dropped, so give the skip link a visible edge */
  .irsc-skip-link {
    border: 2px solid CanvasText;
  }
}

/* Print: the dark tokens are screen-only, so pages print with the light theme
   and River Blue links. Browsers drop fills on paper by default, so the header
   prints dark on white, buttons and marks keep the fill their label needs (a
   highlight badge would otherwise print as a yellow hairline), and screen-only
   controls are left out. */
@media print {
  :root {
    --irsc-header-bg: var(--irsc-surface);
    --irsc-header-text: var(--irsc-text);
    --irsc-header-muted: var(--irsc-text-muted);
    --irsc-header-accent: var(--irsc-text);
  }

  .irsc-btn,
  .irsc-badge--highlight,
  .irsc-pagination [aria-current="page"],
  .irsc-notice::before {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* A primary button in the header is filled with the header accent, black here */
  .irsc-header .irsc-btn {
    --irsc-on-accent: var(--irsc-surface);
  }

  .irsc-skip-link,
  .irsc-theme-switch,
  .irsc-toast-region {
    display: none !important;
  }
}
