/* ============================================================
   JUANSE GIRALDO — Portfolio
   CSS layers: cascade control without !important
   ============================================================ */
@layer reset, tokens, base, layout, components, utilities, animations;

/* Fonts loaded via <link> in HTML <head> for non-render-blocking delivery */

/* View Transitions — MPA (Chrome 126+, Safari 18.2+) */
@view-transition { navigation: auto; }

@keyframes pg-fade-in  { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
@keyframes pg-fade-out { from { opacity:1; } to { opacity:0; } }

::view-transition-old(root) { animation: 180ms ease-in  both pg-fade-out; }
::view-transition-new(root) { animation: 360ms ease-out 120ms both pg-fade-in; }

@layer tokens {
  :root {
    color-scheme: light dark;
    --bg:             #F8F7F3;
    --bg-surface:     #EFEDE7;
    --text-primary:   #111110;
    --text-secondary: #000000;
    --accent:         #4CAF50;
    --accent-light:   #D4E8D4;
    --border:         #A8A49C;
    --bg-scrim:       rgba(248, 247, 243, 0.85);

    --header-bg:      rgba(248, 247, 243, 0.85);
    --header-border:  rgba(168, 164, 156, 0.6);

    --font-display: 'Syne', sans-serif;
    --font-serif:   'Syne', sans-serif;
    --font-body:    'Switzer', sans-serif;
    --font-mono:    'JetBrains Mono', monospace;

    --text-xs:   0.75rem;
    --text-sm:   0.875rem;
    --text-base: 1rem;
    --text-lg:   1.125rem;
    --text-xl:   1.25rem;
    --text-2xl:  1.5rem;
    --text-3xl:  2rem;
    --text-4xl:  2.75rem;
    --text-hero: clamp(3.5rem, 8vw, 7rem);

    --space-1:  0.25rem;  --space-2:  0.5rem;   --space-3:  0.75rem;
    --space-4:  1rem;     --space-6:  1.5rem;   --space-8:  2rem;
    --space-12: 3rem;     --space-16: 4rem;     --space-24: 6rem;
    --space-32: 8rem;

    --max-width:   1280px;
    --page-margin: clamp(1.5rem, 7vw, 7.5rem);
    --content-w:   720px;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in:  cubic-bezier(0.4, 0, 1, 1);
    --dur-fast: 150ms;
    --dur-base: 300ms;
    --dur-slow: 600ms;
  }

  [data-theme="dark"] {
    --bg:             #111110;
    --bg-surface:     #1A1A18;
    --text-primary:   #F0EFE9;
    --text-secondary: #FFFFFF;
    --accent:         #B388FF;
    --accent-light:   #1E3A1F;
    --border:         #2E2E2B;
    --bg-scrim:       rgba(17, 17, 16, 0.8);

    --header-bg:      rgba(17, 17, 16, 0.85);
    --header-border:  rgba(46, 46, 43, 0.6);
  }

  @media (max-width: 640px) {
    :root { --space-32: 5rem; --space-24: 4rem; --space-16: 3rem; }
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
  body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.65;
    color: var(--text-primary);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
  img, video { max-width: 100%; display: block; background-color: var(--bg-surface); }
  a          { color: inherit; text-decoration: none; }
  button     { font: inherit; cursor: pointer; border: none; background: none; }
  ul, ol     { list-style: none; }
}

@layer base {
  .t-display    { font-family: var(--font-display); font-weight: 800; line-height: 0.95; letter-spacing: -0.03em; }
  .t-heading    { font-family: var(--font-display); font-weight: 700; line-height: 1.1;  letter-spacing: -0.02em; }
  .t-editorial  { font-family: var(--font-serif); line-height: 1.4; }
  .t-body       { font-family: var(--font-body); font-weight: 400; line-height: 1.7; }
  .t-body-light { font-family: var(--font-body); font-weight: 300; line-height: 1.65; }
  .t-label      { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); }
  .t-mono       { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-secondary); }
}

@layer layout {
  .container         { width: 100%; max-width: var(--max-width); margin-inline: auto; padding-inline: var(--page-margin); }
  .container--narrow { max-width: var(--content-w); margin-inline: auto; padding-inline: var(--page-margin); }
}

@layer components {
  .divider { width: 100%; height: 1px; background-color: var(--border); }

  .tag {
    display: inline-flex; align-items: center;
    font-family: var(--font-mono); font-size: var(--text-xs);
    letter-spacing: 0.04em; color: var(--text-secondary);
    border: 1px solid var(--border); padding: 0.25rem 0.6rem; border-radius: 2px;
  }

  .link-underline { position: relative; transition: color var(--dur-fast) var(--ease-out); }
  .link-underline::after {
    content: ''; position: absolute; bottom: -1px; left: 0;
    width: 100%; height: 1px; background: var(--accent);
    transform: scaleX(0); transform-origin: right;
    transition: transform var(--dur-base) var(--ease-out);
  }
  .link-underline:hover { color: var(--accent); }
  .link-underline:hover::after { transform: scaleX(1); transform-origin: left; }

  .theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: none; border: 1px solid var(--border); border-radius: 50%;
    color: var(--text-secondary); cursor: pointer;
    transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }
  .theme-toggle:hover { color: var(--text-primary); border-color: var(--text-primary); }
  .theme-toggle__icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

  [data-theme="dark"]  .theme-toggle__icon--sun  { display: block; }
  [data-theme="dark"]  .theme-toggle__icon--moon { display: none; }
  [data-theme="light"] .theme-toggle__icon--sun  { display: none; }
  [data-theme="light"] .theme-toggle__icon--moon { display: block; }
}

@layer utilities {
  .skip-nav {
    position: fixed; top: var(--space-4); left: var(--space-4); z-index: 9999;
    padding: 0.6rem 1.2rem; background: var(--text-primary); color: var(--bg);
    font-family: var(--font-mono); font-size: var(--text-sm); letter-spacing: 0.04em;
    border-radius: 2px;
    transform: translateY(calc(-100% - var(--space-8))); transition: transform 200ms ease;
  }
  .skip-nav:focus { transform: translateY(0); }
  :focus-visible  { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
  :focus:not(:focus-visible) { outline: none; }
}

@layer animations {
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    html { scroll-behavior: auto; }
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  }
}

@layer components {
  /* Custom cursor (JS-driven; only with a precise pointer) */
  .cursor { display: block; position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 10050; pointer-events: none; }
  .cursor__dot, .cursor__ring { pointer-events: none; }
  .cursor__dot { position: fixed; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%; background-color: var(--accent); }
  .cursor__ring {
    position: fixed; left: -19px; top: -19px; width: 38px; height: 38px;
    border: 1.5px solid var(--accent); border-radius: 50%;
    background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
    opacity: 0.35;
  }
  @media (hover: hover) and (pointer: fine) {
    html.cursor-enabled, html.cursor-enabled * { cursor: none !important; }
  }

  /* Brand intro overlay */
  .intro-overlay {
    position: fixed; inset: 0; z-index: 10040;
    display: flex; align-items: center; justify-content: center;
    background-color: var(--bg); overflow: hidden;
  }
  .intro-overlay__inner { display: flex; flex-direction: column; }
  .intro-overlay__row { overflow: hidden; }
  .intro-overlay__word {
    display: block; font-family: var(--font-display); font-weight: 800;
    font-size: clamp(2.5rem, 9vw, 5.5rem); letter-spacing: -0.03em; line-height: 0.95;
    color: var(--text-primary);
  }
  .intro-overlay__word--accent { color: var(--accent); }
  .intro-overlay__bar {
    position: absolute; left: 0; bottom: 0; width: 100%; height: 4px;
    transform-origin: left; background-color: var(--accent);
  }
}
