/*
 * Underskin — Base layer
 * Reset, typography, and root element styling.
 */

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

html {
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    background-color: var(--bg);
}

body {
    margin: 0;
    /* Gradient rimosso momentaneamente — bg piatto var(--bg). */
    background-color: var(--bg);
    background-image: none;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--font-size-md);
    line-height: var(--line-height-body);
    min-height: 100vh;
    overflow-x: hidden;
    /* Crea stacking context sul body così i pseudo z-index -1 (grain
       texture, radial wash) restano SOPRA il bg-color del body e SOTTO
       il contenuto in-flow. Senza isolate finirebbero dietro al canvas
       e diventerebbero invisibili. */
    isolation: isolate;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse 60% 40% at 20% 10%, rgba(255, 240, 200, 0.2), transparent 60%),
        radial-gradient(ellipse 50% 40% at 85% 85%, rgba(196, 90, 62, 0.06), transparent 65%);
}

/* Paper grain texture layer — inline SVG turbulence.
   Attivo quando body ha classe us-texture-paper-grain (settata da PHP in
   base al campo texture della palette attiva). z-index: -1 = layer sotto
   tutti i contenuti, sopra solo il body background color. Fixed = si muove
   sotto lo scroll come carta stampata dietro il contenuto.
   NOTE: mix-blend-mode rimosso — su un layer negativo blendrebbe solo col
   bg body (già visibile via opacity). Un color-matrix più opaco + opacity
   più bassa dà lo stesso feel senza overhead di composizione. */
body.us-texture-paper-grain::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.55;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='3' stitchTiles='stitch' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.06  0 0 0 0 0.05  0 0 0 0 0.03  0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 260px 260px;
    background-repeat: repeat;
}

/* Grain heavy: opacity più alta + turbulence più fine. */
body.us-texture-grain-heavy::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.22;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    background-repeat: repeat;
}

/* Grain light: appena percettibile. */
body.us-texture-grain-light::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.08;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 250px 250px;
    background-repeat: repeat;
}

/* Header grain replicato localmente.
   Il site-header ha bg = --bg opaco + z-index positive, quindi crea stacking
   context e copre il grain body::after. Un pseudo dentro l'header con la
   stessa texture riporta l'effetto sopra l'header bg ma sotto i figli. */
body.us-texture-paper-grain .site-header,
body.us-texture-grain-heavy .site-header,
body.us-texture-grain-light .site-header {
    position: sticky;
    isolation: isolate;
}
body.us-texture-paper-grain .site-header::before,
body.us-texture-grain-heavy .site-header::before,
body.us-texture-grain-light .site-header::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-repeat: repeat;
}
body.us-texture-paper-grain .site-header > *,
body.us-texture-grain-heavy .site-header > *,
body.us-texture-grain-light .site-header > * {
    position: relative;
    z-index: 1;
}
body.us-texture-paper-grain .site-header::before {
    opacity: 0.55;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='3' stitchTiles='stitch' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.06  0 0 0 0 0.05  0 0 0 0 0.03  0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 260px 260px;
}
body.us-texture-grain-heavy .site-header::before {
    opacity: 0.22;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}
body.us-texture-grain-light .site-header::before {
    opacity: 0.08;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 250px 250px;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-sm);
    font-family: var(--font-body);
    font-weight: 700;
    line-height: var(--line-height-heading);
    letter-spacing: var(--letter-spacing-caps);
    text-transform: uppercase;
}

h1 { font-size: var(--font-size-hero); }
h2 { font-size: var(--font-size-xxl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-md); }
h6 { font-size: var(--font-size-sm); }

p {
    margin: 0 0 var(--space-sm);
}

a {
    color: var(--ink);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-default);
}

a:hover, a:focus-visible {
    color: var(--accent);
}

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

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

.u-signature {
    font-family: var(--font-signature);
    text-transform: uppercase;
    letter-spacing: 0;
}

.u-caps {
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-caps);
}

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

/* FOUC prevention — hide body until fonts load, up to 400ms */
html:not(.fonts-loaded) body {
    opacity: 0;
}

html.fonts-loaded body {
    opacity: 1;
    transition: opacity var(--duration-fast) var(--ease-default);
}

@media (prefers-reduced-motion: reduce) {
    html.fonts-loaded body {
        transition: none;
    }
}
