/* ─── Reset + base ────────────────────────────────────────────────────────
   Minimal, opinionated reset. Sets typography, focus, scroll behavior,
   and the global background/text colors keyed to theme tokens.
   ────────────────────────────────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Hide horizontal scroll on accidental overflow on mobile */
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  min-height: 100dvh;
  min-height: 100vh; /* fallback for browsers without dvh */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Smooth theme transitions */
  transition: background-color var(--motion-base) var(--ease-out),
              color var(--motion-base) var(--ease-out);
}

/* Headings use Space Grotesk bold */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
}

p {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}

a {
  color: var(--accent-expressive);
  text-decoration: none;
  transition: color var(--motion-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-expressive-hover);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Buttons reset */
button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Form controls inherit fonts */
input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Lists */
ul, ol {
  list-style: none;
}

/* Images responsive by default */
img, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

/* Code/data */
code, .data-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Numbers — tabular figures so columns align */
.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* Focus — always visible, expressive cyan */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Selection */
::selection {
  background-color: var(--accent-expressive);
  color: var(--text-on-accent);
}

/* Scrollbars — themed but unobtrusive */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: var(--radius-full);
}

/* Hidden but available to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Visually hidden until focused (skip links) */
.sr-only-focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* App shell — top-level layout container */
.app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100dvh;
  min-height: 100vh;
}

.main {
  width: 100%;
  max-width: var(--max-content-width);
  margin-inline: auto;
  padding: var(--space-4);
  /* Mobile: compact but breathable. Desktop expands below. */
}

@media (min-width: 768px) {
  .main {
    padding: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .main {
    padding: var(--space-8);
  }
}

/* Section spacing */
.stack > * + * {
  margin-top: var(--space-4);
}

@media (min-width: 768px) {
  .stack > * + * {
    margin-top: var(--space-6);
  }
}

.stack-tight > * + * {
  margin-top: var(--space-2);
}

.stack-loose > * + * {
  margin-top: var(--space-8);
}

/* Grid helpers — mobile first, single column by default */
.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .grid {
    gap: var(--space-6);
  }
  .grid-md-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
  .grid-lg-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-lg-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-lg-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Cluster — inline group of items, wraps on overflow */
.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.cluster-tight { gap: var(--space-1); }
.cluster-loose { gap: var(--space-4); }

/* Spacer */
.spacer { flex: 1 1 auto; }
