/**
 * Base Styles
 * Reset, typography, and fundamental elements
 */

/* Box sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Remove default margins */
* {
    margin: 0;
    padding: 0;
}

/* Prevent font size inflation */
html {
    -moz-text-size-adjust: none;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    scroll-behavior: smooth;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Body defaults - Premium Editorial Serif */
body {
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: var(--text-fluid-base);
    font-weight: var(--font-normal);
    line-height: var(--leading-relaxed);
    color: var(--on-surface);
    background-color: var(--surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
 * TYPOGRAPHY - Premium Editorial Headings
 * Crimson Pro serif with fluid scaling
 * ============================================ */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    font-weight: var(--font-light);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    color: var(--on-surface);
    text-wrap: balance;
}

/* Fluid headings - scale smoothly across viewports */
h1 { font-size: var(--text-fluid-3xl); }  /* 34px → 52px */
h2 { font-size: var(--text-fluid-2xl); }  /* 28px → 42px */
h3 { font-size: var(--text-fluid-xl); }   /* 22px → 32px */
h4 { font-size: var(--text-fluid-lg); }   /* 19px → 24px */
h5 { font-size: var(--text-lg); font-weight: var(--font-normal); }
h6 { font-size: var(--text-base); font-weight: var(--font-medium); }

/* Display heading - Hero titles, large statements */
.display-heading {
    font-family: var(--font-serif);
    font-size: var(--text-fluid-display);
    font-weight: var(--font-light);
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--on-surface);
}

/* Body text */
p {
    text-wrap: pretty;
    max-width: 65ch; /* Optimal reading width */
}

/* Lead text - larger intro paragraphs */
.lead {
    font-size: var(--text-fluid-lg);
    line-height: var(--leading-relaxed);
    color: var(--on-surface-variant);
}

/* Small text */
small, .text-sm {
    font-size: var(--text-sm);
}

/* Caption text */
.caption {
    font-size: var(--text-xs);
    color: var(--on-surface-variant);
    letter-spacing: var(--tracking-wide);
}

/* Uppercase label */
.label {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
}

/* Links */
a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Images */
img,
picture,
svg,
video {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Form elements inherit fonts */
input,
button,
textarea,
select {
    font: inherit;
}

/* Remove list styles on ul, ol with role="list" */
ul[role="list"],
ol[role="list"] {
    list-style: none;
}

/* Tables */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: var(--font-medium);
}

/* Visually hidden (accessible) */
.sr-only,
.screen-reader-text {
    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 */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    background: var(--primary);
    color: var(--on-primary);
    padding: var(--space-3) var(--space-6);
    border-radius: var(--shape-md);
    font-weight: var(--font-medium);
    z-index: var(--z-toast);
    text-decoration: none;
}

.skip-link:focus {
    top: var(--space-4);
}

/* Focus visible */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* Selection */
::selection {
    background: #dcdcc8;
    color: var(--on-surface);
}

/* ============================================
 * LAYOUT UTILITIES
 * ============================================ */

/**
 * Container System
 *
 * Single source of truth for page widths.
 * Uses fluid gutter that scales with viewport.
 */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--gutter-fluid);
}

/* Container variants */
.container--narrow {
    max-width: var(--container-narrow);
}

.container--text {
    max-width: var(--container-text);
}

.container--wide {
    max-width: var(--container-wide);
}

.container--full {
    max-width: none;
    padding-inline: 0;
}

/* Full-bleed with wide gutters (editorial hero sections) */
.container--bleed {
    max-width: none;
    padding-inline: var(--gutter-wide);
}

/* No padding variant (for nested containers) */
.container--flush {
    padding-inline: 0;
}


/**
 * Section Spacing - Premium Editorial
 *
 * Generous vertical rhythm (80-100px+) for editorial feel.
 * Uses fluid spacing tokens that scale with viewport.
 */
.section {
    padding-block: var(--space-section);  /* 64-96px fluid */
}

.section--sm {
    padding-block: var(--space-section-sm);  /* 48-64px fluid */
}

.section--lg {
    padding-block: var(--space-section-lg);  /* 80-128px fluid */
}

/**
 * Flow Utility
 *
 * Adds consistent spacing between child elements.
 * Usage: <div class="flow"> or <div class="flow--lg">
 */
.flow > * + * {
    margin-block-start: var(--flow-space, var(--space-4));
}

.flow--sm > * + * {
    --flow-space: var(--space-2);
}

.flow--lg > * + * {
    --flow-space: var(--space-6);
}

/**
 * Stack & Cluster (Flexbox utilities)
 */
.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: center;
}

/**
 * Grid Utility
 */
.grid {
    display: grid;
    gap: var(--space-4);
}

.grid--2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid--3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid--4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Auto-fit grid: columns sized between min and 1fr */
.grid--auto {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}

/* ============================================
 * TEXT UTILITIES
 * ============================================ */

/* Alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Wrapping */
.text-balance { text-wrap: balance; }
.text-pretty { text-wrap: pretty; }
.text-nowrap { white-space: nowrap; }

/* Font Size */
.text-2xs { font-size: var(--text-2xs); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

/* Font Weight */
.font-light { font-weight: var(--font-light); }
.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

/* Font Family */
.font-sans { font-family: var(--font-sans); }
.font-serif { font-family: var(--font-serif); }
.font-body { font-family: var(--font-body); }
.font-mono { font-family: var(--font-mono); }

/* Line Height */
.leading-none { line-height: var(--leading-none); }
.leading-tight { line-height: var(--leading-tight); }
.leading-normal { line-height: var(--leading-normal); }
.leading-relaxed { line-height: var(--leading-relaxed); }

/* Letter Spacing */
.tracking-tight { letter-spacing: var(--tracking-tight); }
.tracking-normal { letter-spacing: var(--tracking-normal); }
.tracking-wide { letter-spacing: var(--tracking-wide); }

/* Text Transform */
.uppercase { text-transform: uppercase; }
.lowercase { text-transform: lowercase; }
.capitalize { text-transform: capitalize; }

/* Text Color */
.text-muted { color: var(--on-surface-variant); }
.text-primary { color: var(--primary); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }

/* ============================================
 * ALPINE.JS UTILITIES
 * ============================================ */

/**
 * x-cloak: Hide elements until Alpine initializes
 * Prevents Flash of Unstyled Content (FOUC)
 */
[x-cloak] {
    display: none !important;
}

/* ============================================
 * LOADING ANIMATIONS
 * ============================================ */

/**
 * Shared spin animation for all spinners
 * Used by: .loading-spinner (PLP), .pdp__spinner (PDP), .cart-loading__spinner (Cart)
 */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
