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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg);
  transition: color var(--transition), background-color var(--transition);
  position: relative;
}

html,
body {
  max-width: 100%;
}

/* Space background — dark mode only, rendered by canvas */
.space-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.5s ease;
}

[data-theme="dark"] .space-bg {
  opacity: 1;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .space-bg {
    opacity: 1;
  }
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

/* Let inline SVGs remain inline */
svg:not(.space-bg) {
  display: inline-block;
}

a {
  color: var(--text-primary);
  text-decoration: none;
  overflow-wrap: anywhere;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

ul, ol {
  list-style: none;
}

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

/* Accessibility — skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-sm) var(--space-md);
  background: var(--text-primary);
  color: var(--bg);
  font-size: var(--text-sm);
  border-radius: 4px;
  z-index: 1000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: var(--space-sm);
  text-decoration: none;
}

/* Focus visible — keyboard-only outline */
*:focus-visible {
  outline: 2px solid var(--text-tertiary);
  outline-offset: 2px;
}

button:focus-visible {
  outline: 2px solid var(--text-tertiary);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  body {
    -webkit-text-size-adjust: 100%;
  }
}