/* ============================================
   Base — Reset, Custom Properties, Typography
   ============================================ */

/* Custom Properties */
:root {
    color-scheme: dark light;

    /* Spacing scale */
    --space-2xs: 4px;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 40px;
    --space-3xl: 60px;

    /* Typography scale */
    --text-xs: clamp(0.6875rem, 0.65rem + 0.15vw, 0.75rem);
    --text-sm: clamp(0.8125rem, 0.78rem + 0.15vw, 0.875rem);
    --text-base: clamp(0.875rem, 0.83rem + 0.2vw, 1rem);
    --text-lg: clamp(1rem, 0.93rem + 0.3vw, 1.125rem);
    --text-xl: clamp(1.125rem, 1rem + 0.5vw, 1.25rem);
    --text-2xl: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    --text-3xl: clamp(2rem, 1.5rem + 2vw, 2.5rem);
    --text-hero: clamp(2.25rem, 1.5rem + 3.5vw, 4.5rem);

    /* Font stacks */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;

    /* Layout */
    --sidebar-width: 280px;
    --header-height: 60px;
    --content-max-width: 1200px;

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 300ms;
    --duration-slow: 500ms;

    /* Z-index layers */
    --z-base: 1;
    --z-sticky: 10;
    --z-sidebar: 100;
    --z-overlay: 200;
    --z-modal: 300;
    --z-progress: 1000;
    --z-toast: 1100;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    hanging-punctuation: first last;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Improved media defaults */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Remove built-in form typography styles */
input, button, textarea, select {
    font: inherit;
    color: inherit;
}

/* Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
}

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

p {
    text-wrap: pretty;
}

ul, ol {
    list-style: none;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

/* Focus styles */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Skip to content */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    padding: var(--space-xs) var(--space-md);
    background: var(--accent-primary);
    color: #fff;
    border-radius: var(--radius-sm);
    z-index: var(--z-toast);
    font-weight: 600;
    font-size: var(--text-sm);
    transition: top var(--duration-fast) var(--ease-out);

    &:focus {
        top: var(--space-md);
    }
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============ Scrollbar ============ */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============ Selection ============ */
::selection {
    background: rgba(59, 130, 246, 0.3);
    color: var(--text-primary);
}
