/* Define cascade layers for style organization */
@layer reset, base, layout, components, utilities;

/* Reset layer - minimal modern reset */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    hanging-punctuation: first last;
    color-scheme: dark light;
  }

  body {
    min-height: 100dvh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

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

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

  p,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    overflow-wrap: break-word;
    text-wrap: pretty;
  }

  h1,
  h2,
  h3,
  h4 {
    text-wrap: balance;
  }

  a {
    color: inherit;
    text-decoration-skip-ink: auto;
  }

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

/* Base layer - typography and foundational styles */
@layer base {
  :root {
    /* Typography */
    --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace;
    --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --font-size-sm: clamp(0.875rem, 0.8rem + 0.4vw, 1rem);
    --font-size-lg: clamp(1.25rem, 1.1rem + 0.8vw, 1.5rem);
    --font-size-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.5rem);
    --font-size-2xl: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
    --line-height-tight: 1.2;
    --line-height-normal: 1.6;
    --line-height-relaxed: 1.8;

    /* Spacing scale */
    --space-3xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.375rem);
    --space-2xs: clamp(0.5rem, 0.45rem + 0.25vw, 0.625rem);
    --space-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --space-sm: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
    --space-md: clamp(1.5rem, 1.35rem + 0.75vw, 2rem);
    --space-lg: clamp(2rem, 1.8rem + 1vw, 2.75rem);
    --space-xl: clamp(3rem, 2.7rem + 1.5vw, 4rem);
    --space-2xl: clamp(4rem, 3.5rem + 2.5vw, 6rem);

    /* Layout */
    --content-width: 70ch;
    --wide-width: 90ch;
    --gutter: var(--space-md);

    /* Animation */
    --duration-fast: 150ms;
    --duration-normal: 300ms;
    --duration-slow: 500ms;
    --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

    /* Border radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
  }

  body {
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    background-color: var(--color-bg);
    color: var(--color-text);
  }

  h1,
  h2,
  h3,
  h4 {
    font-weight: 600;
    line-height: var(--line-height-tight);
  }

  h1 {
    font-size: var(--font-size-2xl);
  }

  h2 {
    font-size: var(--font-size-xl);
  }

  h3 {
    font-size: var(--font-size-lg);
  }

  a {
    color: var(--color-accent);
    transition: color var(--duration-fast) var(--ease-out);

    &:hover {
      color: var(--color-accent-hover);
    }

    &:focus-visible {
      outline: 2px solid var(--color-accent);
      outline-offset: 2px;
    }
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: var(--color-surface);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-sm);
  }

  pre {
    background-color: var(--color-surface);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    overflow-x: auto;

    & code {
      background: none;
      padding: 0;
    }
  }

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