/* Reset, element defaults, and the handful of utilities worth having.
 *
 * Utilities are deliberately few. This is not a utility framework -- the rule
 * for the rebuild was that layout and spacing belong to named component
 * classes, so that no screen file has to reach for a string of them. What is
 * here covers the cases where a named class would be one-off noise: stacking,
 * a row, truncation, and screen-reader text.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Anchors and focus scrolls land below the sticky bar rather than under it. */
  scroll-padding-top: calc(var(--topbar-height) + var(--space-4));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizelegibility;
}

body.is-overlay-open {
  overflow: hidden;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-base); }

p,
ul,
ol,
dl,
figure {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration-color: color-mix(in oklab, var(--accent) 35%, transparent);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-color: currentcolor;
}

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

img,
svg {
  max-width: 100%;
}

hr {
  height: 1px;
  margin: var(--space-5) 0;
  border: 0;
  background: var(--border);
}

/* One focus treatment for the whole application. Never removed, never
 * replaced per-component: a visible focus ring is the only thing telling a
 * keyboard user where they are. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Fields draw their own ring inside the border, so the generic outline would
 * double up. They still get a visible focus indicator -- see components.css. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}

::selection {
  background: color-mix(in oklab, var(--accent) 25%, transparent);
}

@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;
  }
}

/* ------------------------------------------------------------ utilities -- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--tight { gap: var(--space-2); }
.stack--loose { gap: var(--space-6); }

.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--top { align-items: flex-start; }
.row--gap-3 { gap: var(--space-3); }

.grow { flex: 1; min-width: 0; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); font-size: 0.9em; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.break-anywhere { overflow-wrap: anywhere; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }

/* Visible only to assistive technology. Used for live-region announcements,
 * for the labels on icon-only controls, and for table captions. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The skip link: off-screen until focused, then pinned to the top-left. It is
 * the first thing in the tab order, so a keyboard user can jump the nav. */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: calc(var(--z-toast) + 1);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}
