/* --- BASE.CSS — Design Token System ---
   Fonts are loaded from index.html (<link> after preconnect) — no @import,
   so the font CSS request starts in parallel with the stylesheets. */

:root {

    /* Follow the system by default; JS sets data-theme to pin a choice.
       All semantic colors resolve via light-dark() — declared exactly once. */
    color-scheme: light dark;

    /* --- 1. PRIMITIVE TOKENS --- */

    /* --- FONTS --- */
    --font-primary: 'Solway', serif;
    --font-secondary: 'Alice', serif;
    --font-mono: 'Courier New', Courier, monospace;

    /* --- SPACING SCALE (based on 0.5rem / 8px unit) --- */
    --space-2xs:  0.25rem;  /*  4px */
    --space-xs:   0.5rem;   /*  8px */
    --space-sm:   0.75rem;  /* 12px */
    --space-md:   1rem;     /* 16px */
    --space-lg:   1.5rem;   /* 24px */
    --space-xl:   2rem;     /* 32px */
    --space-2xl:  3rem;     /* 48px */
    --space-3xl:  4rem;     /* 64px */
    --space-4xl:  6rem;     /* 96px */

    /* --- MODULAR TYPE SCALE ---
       ~Major Third (×1.25) from xs through 2xl; the display sizes
       (3xl, 4xl) are tuned by eye. */
    --text-xs:    0.72rem;
    --text-sm:    0.9rem;
    --text-base:  1.125rem;
    --text-lg:    1.4rem;
    --text-xl:    1.75rem;
    --text-2xl:   2.2rem;
    --text-3xl:   3.2rem;
    --text-4xl:   4.2rem;

    /* --- BORDER RADIUS --- */
    --radius-xs:     2px;
    --radius-md:     12px;
    --radius-lg:     20px;
    --radius-full:   50px;
    --radius-circle: 50%;

    /* --- RAW PALETTE --- */

    --light-BG:               #fbf7f3;     /* Warmer vellum paper */
    --light-text-primary:     #5e5045;     /* 7.15:1 on light-BG */
    --light-text-secondary:   #7d6e5f;     /* 4.54:1 on light-BG */
    --light-accent:           #d98324;     /* decorative only */

    --dark-BG:                #1c1a18;     /* Deeper graphite studio dark */
    --dark-text-primary:      #e6e0d4;     /* 12.18:1 on dark-BG */
    --dark-text-secondary:    #b5ada5;     /* 7.23:1 on dark-BG */
    --dark-accent:            #ffb894;     /* Warmer, glowing amber */

    /* --- TEXTURES (baked from procedural SVG to seamless WebP tiles) --- */
    --grain-light:  url('../img/ui/light/paper-light.webp');
    --grain-dark:   url('../img/ui/dark/paper-dark.webp');
    --specks-light: url('../img/ui/light/specks-light.webp');
    --specks-dark:  url('../img/ui/dark/specks-dark.webp');
    --frags-light: url('../img/ui/light/fragments-light.webp');
    --frags-dark:  url('../img/ui/dark/fragments-dark.webp');

    /* Each texture = sparse dust specks (1200px tile) over fine grain (400px tile).
       Both tiles are seamless and tile infinitely; sizes live in --texture-size. */
    --texture-light: var(--frags-light), var(--specks-light), var(--grain-light);
    --texture-dark:  var(--frags-dark),  var(--specks-dark),  var(--grain-dark);
    --texture-size:  1500px 1500px, 600px 600px, 200px 200px;

    /* --- 2. SEMANTIC TOKENS --- */

    --bg-texture:             var(--texture-light);  /* multi-layer; dark set in overrides below */
    --color-background:       light-dark(var(--light-BG), var(--dark-BG));
    --color-text-primary:     light-dark(var(--light-text-primary), var(--dark-text-primary));
    --color-text-secondary:   light-dark(var(--light-text-secondary), var(--dark-text-secondary));
    --color-accent:           light-dark(var(--light-accent), var(--dark-accent));
    --color-opaque-bg:        transparent;

    --color-header-bg:        light-dark(rgba(251, 247, 243, 1), rgba(28, 26, 24, 1));

    /* Vellum overlay: paper-on-paper tint for collapsed header.
       Both modes darken — paper always blocks light from below. */

    --color-border:           light-dark(rgba(94, 80, 69, 0.15), rgba(230, 224, 212, 0.15));

    --light-shadow:           hsla(26, 15%, 32%, 0.7);
    --dark-shadow:            rgba(0, 0, 0, 0.7);
    --color-card-shadow:      light-dark(var(--light-shadow), var(--dark-shadow));

    --light-shadow-subtle:    hsla(26, 15%, 32%, 0.15);
    --dark-shadow-subtle:     rgba(0, 0, 0, 0.3);
    --color-shadow:           light-dark(var(--light-shadow-subtle), var(--dark-shadow-subtle));




    /* --- 3. COMPONENT TOKENS --- */

    --transition-tech:    all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    --transition-theme:   0.4s ease;
}


/* --- MANUAL THEME OVERRIDE ---
   JS sets data-theme on <html>; pinning color-scheme makes every
   light-dark() above resolve to that side. No token re-declarations. */

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* --bg-texture is the one non-color token (light-dark() is colors-only),
   so it switches explicitly. */
:root[data-theme="dark"] { --bg-texture: var(--texture-dark); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --bg-texture: var(--texture-dark); }
}


/* --- 4. TEXTURE GHOST (Seamless Page Transitions) --- */

.texture-ghost {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -998;
    background-image: var(--bg-texture);
    background-size: var(--texture-size);
    background-repeat: repeat;
    pointer-events: none;
    transition: opacity 0.25s ease-out;
    opacity: 1;
}


/* --- 5. KEYFRAME ANIMATIONS --- */



@keyframes pulsePrompt {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.15; }
}

/* --- 5. GLOBAL RESETS & BASE STYLES --- */

/* --- Custom Text Selection --- */
::selection {
    background-color: var(--color-accent);
    color: var(--color-background);
}

/* Anything wired to section navigation behaves like a link */
[data-section] {
    cursor: pointer;
}

/* Screen-reader-only content (e.g. the home <h1>) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* --- Custom Scrollbar ---
   Standard properties only. Any non-auto scrollbar-width/color makes
   Chromium ignore ::-webkit-scrollbar rules, so mixing both systems
   means the webkit ones silently never apply. */
html {
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    scrollbar-color: var(--color-border) var(--color-background);
    background-color: var(--color-background);
    transition: background-color var(--transition-theme), scrollbar-color var(--transition-theme);
    position: relative;
    min-height: 100vh;
}

body {
    margin: 0;
    font-family: var(--font-primary);
    color: var(--color-text-primary);
    font-weight: 400;
    text-align: center;
    font-size: var(--text-base);
    transition: 
        background-color var(--transition-theme), 
        color var(--transition-theme);
    background: transparent;
}

/* --- Background Texture Cross-fade --- */
html::before, html::after {
    content: '';
    position: absolute;   /* scrolls with the page; textures are baked WebP rasters, so full-height tiling is cheap on Safari */
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -999;
    background-repeat: repeat;
    background-position: top left;
    pointer-events: none;
    transition: opacity var(--transition-theme);
}
html::before { background-image: var(--texture-light); background-size: var(--texture-size); opacity: 1; }
html::after  { background-image: var(--texture-dark);  background-size: var(--texture-size); opacity: 0; }

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"])::before { opacity: 0; }
    html:not([data-theme="light"])::after  { opacity: 1; }
}
html[data-theme="dark"]::before { opacity: 0; }
html[data-theme="dark"]::after  { opacity: 1; }


/* --- 6. TYPOGRAPHY --- */

h1, h2, h3, h4 {
    font-family: var(--font-secondary);
    font-weight: 700;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-md) 0;
    transition: color var(--transition-theme);
}

h1,
.project-detail-title,
#blog-post-content h2 {
    font-size: var(--text-4xl);
    line-height: 1.1;
}

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

/* .section-intro lets a semantic <h2> (e.g. the blog intro) wear this look */
h3, .section-intro {
    font-size: var(--text-xl);
    font-weight: 400;
    font-style: italic;
    color: var(--color-text-secondary);
    letter-spacing: 0.02em;
}

h4 {
    font-size: var(--text-lg);
}

p {
    line-height: 1.7;
    margin-bottom: var(--space-lg);
    transition: color var(--transition-theme);
}

p:last-child { margin-bottom: 0; }

/* Alice at body sizes needs breathing room — tighter than heading sizes,
   the default tracking feels cramped. This targets all elements where
   Alice is explicitly set for running text (not headings). */
.post-paragraphs p,
.project-detail-description p,
.text-block p,
.description-text,
.blog-card p {
    letter-spacing: 0.04em;
    word-spacing: 0.05em;
    line-height: 1.8;
}

/* --- Interactive Hover Prompts --- */
.prompt {
    color: inherit;
    font-family: var(--font-mono);
    font-weight: 700;
    display: inline-block;
    width: 0;
    overflow: hidden;
    opacity: 0;
    white-space: nowrap;
    transition: var(--transition-tech);
    vertical-align: top;
}

.about-block.has-active-cursor .prompt,
.contact-block.has-active-cursor .prompt {
    width: 1em;
    opacity: 1;
    animation: pulsePrompt 1.5s step-end infinite;
}

/* Always show on mobile where there is no hover state */
@media (hover: none) {
    .prompt {
        width: 1em;
        opacity: 1;
    }
}

/* --- 4K & Ultrawide Auto-Scaling ---
   Automatically scales the entire site (typography, spacing, max-widths)
   up proportionately on unscaled 1440p and 4K monitors (e.g. Windows at 100%).
   1vw at 1920px = 19.2px. 16px / 19.2 = 0.8333vw. */
@media (min-width: 1921px) {
    html {
        font-size: clamp(16px, 0.8333vw, 32px);
    }
}

/* --- VIEW TRANSITIONS (Theme Toggle Mask) --- */
::view-transition-old(root),
::view-transition-new(root) {
    mix-blend-mode: normal;
}

@keyframes wipe-in {
    from { clip-path: circle(0px at var(--tx, 50%) var(--ty, 50%)); }
    to { clip-path: circle(var(--tr, 100%) at var(--tx, 50%) var(--ty, 50%)); }
}
@keyframes wipe-out {
    from { clip-path: circle(var(--tr, 100%) at var(--tx, 50%) var(--ty, 50%)); }
    to { clip-path: circle(0px at var(--tx, 50%) var(--ty, 50%)); }
}

/* When transitioning TO dark mode, shrink the old (light) layer away */
.dark-transition::view-transition-old(root) {
    z-index: 2;
    animation: wipe-out 800ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}
.dark-transition::view-transition-new(root) {
    z-index: 1;
    animation: none;
}

/* When transitioning TO light mode, expand the new (light) layer */
.light-transition::view-transition-old(root) {
    z-index: 1;
    animation: none;
}
.light-transition::view-transition-new(root) {
    z-index: 2;
    animation: wipe-in 800ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}