/* ==========================================================================
   Base — reset, document defaults, typography, focus, and a handful of
   single-purpose utilities. No component styles here.
   ========================================================================== */

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

/* The `hidden` attribute must always win. Many components set `display`,
   which would otherwise override the browser's own `[hidden]` rule and leave
   a "hidden" element on screen. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-height) + var(--space-4));
  scrollbar-color: var(--border) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-feature-settings: "cv11", "calt";   /* Inter: single-storey a, contextual alternates */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

h1, h2, h3, h4 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.011em;
  text-wrap: balance;
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { cursor: pointer; }
:disabled { cursor: not-allowed; }
table { border-collapse: collapse; }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}

::selection { background: var(--primary-soft); color: var(--text); }
::placeholder { color: var(--text-placeholder); opacity: 1; }

/* ---- Focus ---------------------------------------------------------------
   One visible ring for keyboard users, on everything focusable. Mouse clicks
   don't trigger it (:focus-visible). */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---- Scrollbars (inside scrolling panels) ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 3px solid transparent;
  border-radius: var(--radius-full);
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--border-strong); }

/* ---- Motion preference ---- */
@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
   ========================================================================== */

.icon { flex: none; }

/* Screen-reader-only text */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* First tab stop on every page: jump past the navigation. */
.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);
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--text-on-primary);
  font-weight: var(--weight-semibold);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

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

.tabular { font-variant-numeric: tabular-nums; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success-text); }

/* Vertical rhythm: children separated by a consistent gap. */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack--lg { gap: var(--space-6); }

/* Items in a row that wrap when they run out of room. */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--primary-text);
  font-weight: var(--weight-medium);
}
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: color var(--duration-fast) var(--ease);
}
.back-link:hover { color: var(--text); }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 0.375rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
}
