/* ==========================================================================
   Base layer — reset, document defaults, typography, accessibility, scrollbars
   ========================================================================== */

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

[hidden] { display: none !important; }

html,
body {
  margin: 0;
  height: 100%;
  background: var(--app-bg);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

/* Theme switches fade instead of snapping, but never during the first paint. */
body.theme-ready,
body.theme-ready * {
  transition: background-color var(--dur-3) var(--ease-std),
              border-color var(--dur-3) var(--ease-std),
              color var(--dur-3) var(--ease-std);
}

h1, h2, h3, h4, p, figure { margin: 0; }

h1, h2, h3, h4 {
  color: var(--text-1);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

button:disabled,
input:disabled,
select:disabled { cursor: not-allowed; }

/* Default icon paint. An SVG with no fill of its own falls back to black, which is invisible on
   dark surfaces; `currentColor` makes every icon follow the text colour of whatever contains it.
   Symbols that are pure strokes keep their own `stroke` and need no change. Icons never shrink,
   because a squeezed glyph is worse than a slightly wide toolbar. */
svg { flex: none; fill: currentColor; }
svg[data-icon],
.icon { width: 18px; height: 18px; }

ul, ol { margin: 0; padding: 0; list-style: none; }

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

::selection {
  background: var(--selection-bg);
  color: var(--text-1);
}

/* ---------- focus: visible for keyboards, quiet for pointers ---------- */

:focus { outline: none; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ---------- scrollbars ---------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-pill);
}
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: content-box; }
*::-webkit-scrollbar-corner { background: transparent; }

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

.spacer { flex: 1 1 auto; min-width: 0; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

.mono { font-family: var(--font-mono); }

.up { color: var(--up); }
.down { color: var(--down); }

.eyebrow {
  color: var(--text-3);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
}

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  line-height: 16px;
  text-align: center;
}

/* ---------- motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- optional noise texture for gradient surfaces ---------- */

.noise::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
