/* ============================================================
   BASE.CSS — CSS variables, reset, global layout
   ============================================================ */

html { font-size: calc(16px * var(--ui-scale, 1)); }

/* Design tokens (colors, typography, spacing, radii, motion) live in
   tokens.css, which is loaded before this file. Themes are switched by
   setting data-theme="light" | "dark" on <html>. */

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--dur-base) var(--ease-out),
              color var(--dur-base) var(--ease-out);
}

/* Ambient background (theme-aware via --ambient-* tokens) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 20% 20%, var(--ambient-1) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 80%, var(--ambient-2) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 50% 50%, var(--ambient-3) 0%, transparent 60%),
    url('../assets/math_bg.png');
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-blend-mode: normal, normal, normal, overlay;
  opacity: var(--ambient-photo-opacity);
  z-index: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}

/* Upgrade the background to WebP where supported (keeps the PNG fallback above) */
@supports (background-image: image-set(url("x.png") type("image/png"))) {
  body::before {
    background-image:
      radial-gradient(ellipse 60% 40% at 20% 20%, var(--ambient-1) 0%, transparent 60%),
      radial-gradient(ellipse 50% 40% at 80% 80%, var(--ambient-2) 0%, transparent 60%),
      radial-gradient(ellipse 40% 30% at 50% 50%, var(--ambient-3) 0%, transparent 60%),
      image-set(
        url('../assets/math_bg.webp') type('image/webp'),
        url('../assets/math_bg.png') type('image/png')
      );
  }
}

.grid-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: 0;
  pointer-events: none;
}

/* Shared screen wrapper */
.screen {
  display: none;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.screen.active { display: flex; flex-direction: column; }

.screen-inner {
  max-width: 38.75rem;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.screen-inner.center-col {
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Particles overlay */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}
.particle {
  position: absolute;
  border-radius: 50%;
  animation: particle-fly 1.2s ease-out forwards;
}

/* Scale the whole rem-based UI up on large displays and projectors.
   The --ui-scale multiplier is adjustable at runtime (A− / A+ control). */
@media (min-width: 1441px) {
  html { font-size: calc(18px * var(--ui-scale, 1)); }
}
@media (min-width: 1920px) {
  html { font-size: calc(22px * var(--ui-scale, 1)); }
}
@media (min-width: 2560px) {
  html { font-size: calc(28px * var(--ui-scale, 1)); }
}
@media (min-width: 3840px) {
  html { font-size: calc(36px * var(--ui-scale, 1)); }
}

/* ============================================================
   ACCESSIBILITY (a11y)
   ============================================================ */

/* Visually 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;
}

/* Skip link — visible only when focused */
.skip-link {
  position: absolute;
  top: -6rem;
  left: 1rem;
  z-index: 1000;
  background: var(--primary);
  color: var(--text-on-accent);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 900;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus-visible {
  top: 1rem;
}

/* Visible keyboard focus indicator */
:focus-visible {
  outline: 3px solid var(--focus-color);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Card-like elements converted to native <button> keep their look */
button.cat-bubble,
button.diff-card,
button.mode-card {
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

/* Respect reduced motion preferences */
@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;
  }
}
