@layer reset, tokens, base, components, utilities;

@layer tokens {
  :root {
    color-scheme: light;
    --archive-cream: #e9e3d7;
    --forbidden-black: #181817;
    --paper-white: #f5f1e8;
    --aged-paper: #c8bfae;
    --antique-gold: #a0834d;
    --blood-red: #7a2626;
    --ink-muted: #625d54;
    --ink-faint: #898173;
    --line-dark: rgba(24, 24, 23, 0.2);
    --line-light: rgba(233, 227, 215, 0.2);
    --surface-dark-soft: #211f1c;
    --surface-paper-deep: #ded6c7;

    --font-display: "Instrument Serif", "Cormorant Garamond", Georgia, serif;
    --font-interface: Inter, Geist, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --text-xs: clamp(0.68rem, 0.66rem + 0.08vw, 0.74rem);
    --text-sm: clamp(0.82rem, 0.79rem + 0.12vw, 0.9rem);
    --text-base: clamp(0.98rem, 0.94rem + 0.17vw, 1.08rem);
    --text-lg: clamp(1.15rem, 1.06rem + 0.35vw, 1.35rem);
    --text-xl: clamp(1.45rem, 1.25rem + 0.8vw, 2rem);
    --text-2xl: clamp(2rem, 1.5rem + 2vw, 3.4rem);
    --text-3xl: clamp(3.2rem, 1.8rem + 5vw, 7.4rem);
    --leading-tight: 0.94;
    --leading-display: 1.02;
    --leading-body: 1.68;
    --tracking-label: 0.18em;
    --tracking-wide: 0.1em;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4.5rem;
    --space-9: 7rem;
    --space-section: clamp(5rem, 10vw, 9rem);
    --container: 78rem;
    --container-narrow: 52rem;

    --radius-none: 0;
    --radius-sm: 0.16rem;
    --radius-md: 0.35rem;
    --radius-pill: 999px;
    --border-hairline: 1px solid var(--line-dark);
    --shadow-paper: 0 1.5rem 4rem -3rem rgba(24, 24, 23, 0.45);
    --ease-archive: cubic-bezier(0.2, 0.65, 0.3, 1);
    --transition-fast: 160ms var(--ease-archive);
    --transition-medium: 320ms var(--ease-archive);
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, h4, p, figure, blockquote, ul, ol { margin: 0; }
  ul, ol { padding: 0; }
  img, svg { display: block; max-width: 100%; }
  button, input, select, textarea { color: inherit; font: inherit; }
  button, a { -webkit-tap-highlight-color: transparent; }
}

@layer base {
  body {
    min-width: 20rem;
    min-height: 100vh;
    background: var(--paper-white);
    color: var(--forbidden-black);
    font-family: var(--font-interface);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  a { color: inherit; }
  button { cursor: pointer; }
  h1, h2, h3, h4, .display-type {
    font-family: var(--font-display);
    font-weight: 400;
    text-wrap: balance;
  }
  ::selection { background: var(--blood-red); color: var(--paper-white); }
  :focus-visible { outline: 2px solid var(--blood-red); outline-offset: 4px; }
  [hidden] { display: none !important; }
}

@layer components {
  .page-grain { position: relative; isolation: isolate; }
  .page-grain::before {
    position: fixed;
    z-index: 20;
    inset: 0;
    pointer-events: none;
    content: "";
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.65'/%3E%3C/svg%3E");
    mix-blend-mode: multiply;
  }

  .container { width: min(calc(100% - 2rem), var(--container)); margin-inline: auto; }
  .container--narrow { width: min(calc(100% - 2rem), var(--container-narrow)); margin-inline: auto; }
  .section { padding-block: var(--space-section); }

  .archive-label, .file-label {
    display: inline-grid;
    grid-template-columns: auto auto;
    gap: 0.3rem 0.8rem;
    min-width: 8.8rem;
    padding: 0.62rem 0.8rem 0.58rem;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: var(--tracking-label);
    line-height: 1;
    text-transform: uppercase;
  }
  .archive-label::before { content: "Archive Nº"; }
  .file-label::before { content: "File Nº"; }
  .archive-label span, .file-label span { letter-spacing: 0.25em; }

  .archive-stamp {
    display: inline-grid;
    width: 6.4rem;
    aspect-ratio: 1;
    place-items: center;
    padding: 1rem;
    border: 2px solid currentColor;
    border-radius: 50%;
    color: var(--blood-red);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    line-height: 1.35;
    text-align: center;
    text-transform: uppercase;
    transform: rotate(-7deg);
  }

  .ornamental-divider {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    align-items: center;
    color: var(--antique-gold);
  }
  .ornamental-divider::before, .ornamental-divider::after { height: 1px; content: ""; background: currentColor; opacity: 0.65; }
  .ornamental-divider span { font-size: 1.05rem; line-height: 1; }

  .eyebrow {
    color: var(--blood-red);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-label);
    line-height: 1.4;
    text-transform: uppercase;
  }
  .eyebrow--gold { color: var(--antique-gold); }

  .button {
    display: inline-flex;
    min-height: 3.15rem;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 0.85rem 1.35rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-label);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
  }
  .button:hover { transform: translateY(-2px); }
  .button--primary { background: var(--forbidden-black); color: var(--paper-white); }
  .button--primary:hover { background: var(--blood-red); }
  .button--paper { background: var(--archive-cream); color: var(--forbidden-black); }
  .button--paper:hover { background: var(--paper-white); }
  .button--outline { border-color: currentColor; background: transparent; }
  .button--outline:hover { border-color: var(--antique-gold); color: var(--antique-gold); }
  .button--text { min-height: auto; padding: 0.35rem 0; border-bottom-color: currentColor; }
  .button--text:hover { color: var(--blood-red); transform: none; }

  .brand-mark--light { filter: invert(94%) sepia(12%) saturate(233%) hue-rotate(356deg) brightness(98%) contrast(92%); }

  .site-header {
    position: relative;
    z-index: 30;
    border-bottom: 1px solid var(--line-dark);
    background: color-mix(in srgb, var(--archive-cream) 94%, transparent);
  }
  .site-header__inner {
    display: grid;
    grid-template-columns: minmax(11rem, 18rem) 1fr auto;
    gap: 2rem;
    min-height: 5rem;
    align-items: center;
  }
  .site-header__wordmark { width: min(100%, 18rem); }
  .site-nav { display: flex; align-items: center; justify-content: center; gap: clamp(1rem, 2.6vw, 2.5rem); }
  .site-nav a {
    position: relative;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-decoration: none;
  }
  .site-nav a::after { position: absolute; right: 0; bottom: -0.5rem; left: 0; height: 1px; content: ""; background: currentColor; transform: scaleX(0); transform-origin: right; transition: transform var(--transition-medium); }
  .site-nav a:hover::after, .site-nav a[aria-current="page"]::after { transform: scaleX(1); transform-origin: left; }
  .menu-toggle { display: none; width: 2.8rem; height: 2.8rem; border: 1px solid currentColor; background: transparent; }
  .menu-toggle span, .menu-toggle::before, .menu-toggle::after { display: block; width: 1.1rem; height: 1px; margin: 0.25rem auto; content: ""; background: currentColor; }

  .site-footer { padding-block: var(--space-8) var(--space-6); background: var(--forbidden-black); color: var(--archive-cream); }
  .site-footer__grid { display: grid; grid-template-columns: minmax(12rem, 22rem) 1fr; gap: clamp(3rem, 9vw, 9rem); align-items: start; }
  .site-footer__seal { width: 9rem; padding: 0.45rem; background: var(--archive-cream); }
  .site-footer__copy { margin-top: 1.25rem; max-width: 28rem; color: var(--aged-paper); }
  .site-footer__links { display: grid; grid-template-columns: repeat(2, minmax(8rem, 1fr)); gap: 1rem 2rem; }
  .site-footer__links a { width: fit-content; font-size: var(--text-sm); text-decoration: none; }
  .site-footer__links a:hover { color: var(--antique-gold); }
  .site-footer__meta { display: flex; justify-content: space-between; gap: 1rem; margin-top: var(--space-7); padding-top: var(--space-5); border-top: 1px solid var(--line-light); color: var(--aged-paper); font-size: var(--text-xs); letter-spacing: 0.08em; text-transform: uppercase; }

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

@layer utilities {
  .text-red { color: var(--blood-red); }
  .text-gold { color: var(--antique-gold); }
  .text-muted { color: var(--ink-muted); }
  .bg-paper { background: var(--paper-white); }
  .bg-cream { background: var(--archive-cream); }
  .bg-black { background: var(--forbidden-black); color: var(--archive-cream); }
  .no-scroll { overflow: hidden; }
}

@media (max-width: 800px) {
  .site-header__inner { grid-template-columns: minmax(0, 1fr) auto; min-height: 4.5rem; }
  .site-header__wordmark { width: 13.5rem; }
  .site-header .button { display: none; }
  .menu-toggle { display: block; }
  .site-nav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: grid;
    gap: 0;
    padding: 0 1rem;
    border-bottom: 1px solid var(--line-dark);
    background: var(--archive-cream);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-0.5rem);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
  }
  .site-nav.is-open { opacity: 1; pointer-events: auto; transform: translateY(0); }
  .site-nav a { padding: 1rem 0; border-bottom: 1px solid var(--line-dark); }
  .site-footer__grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .container, .container--narrow { width: min(calc(100% - 1.25rem), var(--container)); }
  .site-header__wordmark { width: 11.8rem; }
  .site-footer__meta { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
