/* ==========================================================================
   Base — reset, typography, layout primitives, a11y, utilities
   ========================================================================== */

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

    html {
        scroll-behavior: smooth;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        -webkit-tap-highlight-color: transparent;
    }

    img {
        max-width: 100%;
        height: auto;
        display: block;
    }

    a {
        color: inherit;
        text-decoration: none;
        transition: color var(--transition);
    }

    button {
        font-family: inherit;
        cursor: pointer;
        border: none;
        background: none;
        color: inherit;
    }

    input, select, textarea {
        font-family: inherit;
        font-size: inherit;
        color: inherit;
    }

    ul, ol {
        list-style: none;
    }

    @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;
        }
    }
}

@layer base {
    body {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        color: var(--text);
        background:
            radial-gradient(circle at 15% 0%, rgba(255, 107, 53, 0.10), transparent 30%),
            linear-gradient(180deg, var(--cream-bg) 0%, var(--cream-mid) 48%, #FFFFFF 100%);
        background-attachment: fixed;
        line-height: 1.6;
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
    }

    /* App-shell: leave room for the bottom tab bar on phones */
    @media (max-width: 767px) {
        body {
            padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
        }
    }

    main {
        flex: 1 0 auto;
        width: 100%;
    }

    h1, h2, h3, h4, h5, h6 {
        font-weight: 800;
        line-height: 1.15;
        letter-spacing: -0.02em;
        color: var(--text);
        text-wrap: balance;
    }

    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
    h4 { font-size: var(--text-md); }

    p {
        color: var(--text-secondary);
    }

    .container {
        width: min(100%, var(--content-width));
        margin-inline: auto;
        padding-inline: var(--space-8);
    }

    @media (max-width: 767px) {
        .container {
            padding-inline: var(--space-4);
        }
    }

    /* ── A11y ──────────────────────────────────────────────────────── */
    .skip-link {
        position: absolute;
        top: -100%;
        left: 50%;
        transform: translateX(-50%);
        padding: 0.75rem 1.5rem;
        background: var(--brand);
        color: #fff;
        font-weight: 700;
        border-radius: 0 0 var(--radius) var(--radius);
        z-index: 9999;
        transition: top 0.2s ease;
    }

    .skip-link:focus {
        top: 0;
    }

    :focus-visible {
        outline: 2px solid var(--brand);
        outline-offset: 2px;
    }

    input:focus-visible,
    textarea:focus-visible,
    select:focus-visible {
        outline: none;
        border-color: var(--brand);
        box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
    }

    /* ── Shared motion / loading primitives ────────────────────────── */
    @keyframes spin {
        to { transform: rotate(360deg); }
    }

    @keyframes fadeInUp {
        from { opacity: 0; transform: translateY(12px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .spinner {
        width: 36px;
        height: 36px;
        border: 3px solid var(--border);
        border-top-color: var(--brand);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
        margin-inline: auto;
    }

    .loading-block {
        text-align: center;
        padding: var(--space-12) var(--space-8);
        color: var(--text-muted);
        font-size: var(--text-base);
    }

    .loading-block .spinner {
        margin-bottom: var(--space-4);
    }

    .htmx-indicator {
        opacity: 0;
        transition: opacity 200ms;
    }

    .htmx-request .htmx-indicator,
    .htmx-request.htmx-indicator {
        opacity: 1;
    }

    /* Lazy images fade in once loaded (app.js adds .loaded) */
    img[loading="lazy"] {
        opacity: 0;
        transition: opacity 0.35s ease;
    }

    img[loading="lazy"].loaded {
        opacity: 1;
    }
}

@layer utilities {
    .text-center { text-align: center; }
    .text-brand  { color: var(--brand); }
    .mt-1 { margin-top: 0.5rem; }
    .mt-2 { margin-top: 1rem; }
    .mt-3 { margin-top: 1.5rem; }
    .mt-4 { margin-top: 2rem; }
    .mb-1 { margin-bottom: 0.5rem; }
    .mb-2 { margin-bottom: 1rem; }
    .mb-3 { margin-bottom: 1.5rem; }
    .mb-4 { margin-bottom: 2rem; }
    .hidden { display: none !important; }

    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        border: 0;
    }

    /* Visibility helpers keyed to the 768px shell switch */
    @media (max-width: 767px) {
        .desktop-only { display: none !important; }
    }
    @media (min-width: 768px) {
        .mobile-only { display: none !important; }
    }
}
