@layer tokens, base, layout, components, pages, motion;

/* ---------- Tokens ---------- */
@layer tokens {
  :root {
    color-scheme: light dark;
    --paper: #efece6;        /* niebla del lago */
    --paper-2: #e6e2da;
    --ink: #1c1d1b;          /* zinc negro */
    --muted: #595c56;
    --line: #cfcac0;
    --accent: #9a4a26;       /* tejuela de alerce */
    --focus: #9a4a26;
    --over-photo: #f4f1ea;

    --f-display: "Archivo", system-ui, sans-serif;
    --f-mono: "IBM Plex Mono", ui-monospace, monospace;

    --gutter: clamp(1rem, 3.2vw, 2.75rem);
    --max: 1520px;
    --s-1: .25rem; --s-2: .5rem; --s-3: 1rem; --s-4: 1.5rem; --s-5: 2.5rem; --s-6: 4rem; --s-7: 7rem; --s-8: 11rem;

    --t-xs: .75rem;
    --t-sm: .875rem;
    --t-md: 1.0625rem;
    --t-lg: clamp(1.25rem, 1.05rem + .8vw, 1.75rem);
    --t-xl: clamp(2rem, 1.2rem + 3.4vw, 4.5rem);
    --t-xxl: clamp(2.75rem, .8rem + 8vw, 10.5rem);

    --ease: cubic-bezier(.2, .7, .1, 1);
    --header-h: 4.25rem;
    --z-header: 10; --z-peek: 20; --z-lightbox: 30;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --paper: #141513;
      --paper-2: #1c1d1a;
      --ink: #e9e6df;
      --muted: #a5a69e;
      --line: #33342f;
      --accent: #e0956a;
      --focus: #e0956a;
    }
  }
}

/* ---------- Base ---------- */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 400 var(--t-md)/1.55 var(--f-display);
    font-variation-settings: "wdth" 100;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  img { display: block; max-width: 100%; height: auto; }
  a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
  h1, h2, h3, p { margin: 0; }
  h1, h2, h3 { text-wrap: balance; font-weight: 600; }
  p { text-wrap: pretty; }
  ul, ol { margin: 0; padding: 0; list-style: none; }
  button { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }
  ::selection { background: var(--accent); color: var(--paper); }
  .skip {
    position: absolute; left: var(--gutter); top: -4rem; z-index: 50;
    background: var(--ink); color: var(--paper); padding: .6rem 1rem; text-decoration: none;
  }
  .skip:focus { top: .75rem; }
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- Layout ---------- */
@layer layout {
  .wrap { width: min(100% - 2 * var(--gutter), var(--max)); margin-inline: auto; }
  main { min-height: 70dvh; outline: none; }

  .site-header {
    position: fixed; inset: 0 0 auto; z-index: var(--z-header);
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
    padding-inline: var(--gutter);
    color: var(--ink);
    transition: background-color .3s var(--ease), color .3s var(--ease), border-color .3s;
    border-bottom: 1px solid transparent;
  }
  .site-header.is-solid {
    background: color-mix(in oklab, var(--paper) 86%, transparent);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    border-color: var(--line);
  }
  body:has(.hero-photo) .site-header:not(.is-solid) { color: var(--over-photo); }

  .wordmark {
    font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; text-decoration: none;
    font-variation-settings: "wdth" 118; text-transform: none; white-space: nowrap;
  }
  .wordmark span:last-child { font-weight: 300; }

  .nav { display: flex; gap: clamp(1rem, 2.2vw, 2rem); font-size: var(--t-sm); }
  .nav a { text-decoration: none; position: relative; padding-block: .35rem; }
  .nav a::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
    background: currentColor; transform: scaleX(0); transform-origin: left; transition: transform .35s var(--ease);
  }
  .nav a:hover::after, .nav a[aria-current="page"]::after { transform: scaleX(1); }
  .menu-btn { display: none; }

  @media (max-width: 760px) {
    .menu-btn {
      display: inline-flex; background: none; border: 1px solid currentColor; border-radius: 99px;
      padding: .35rem .9rem; font-size: var(--t-sm); cursor: pointer;
    }
    .nav {
      position: fixed; inset: var(--header-h) 0 auto; flex-direction: column; gap: 0;
      background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--line);
      padding: var(--s-3) var(--gutter) var(--s-5);
      font-size: var(--t-xl); font-weight: 500; font-variation-settings: "wdth" 110; letter-spacing: -.02em;
      transform: translateY(-.5rem); opacity: 0; visibility: hidden;
      transition: opacity .25s var(--ease), transform .25s var(--ease), visibility 0s .25s;
    }
    .nav a { padding-block: .4rem; }
    body .site-header[data-header]:has([aria-expanded="true"]) { background: var(--paper); color: var(--ink); }
    .site-header:has([aria-expanded="true"]) .nav { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
  }

  .site-footer { margin-top: var(--s-8); border-top: 1px solid var(--line); padding: var(--s-6) var(--gutter) var(--s-4); }
  .foot-grid { max-width: var(--max); margin-inline: auto; display: grid; gap: var(--s-5); grid-template-columns: 1fr; }
  .foot-big { font-size: var(--t-xl); line-height: 1; font-weight: 600; letter-spacing: -.03em; font-variation-settings: "wdth" 112; }
  .foot-list { display: grid; gap: .4rem; align-content: end; font-size: var(--t-md); }
  .foot-meta { font: 400 var(--t-xs)/1.5 var(--f-mono); color: var(--muted); grid-column: 1 / -1; }
  @media (min-width: 900px) { .foot-grid { grid-template-columns: 2fr 1fr; } }
}

/* ---------- Components ---------- */
@layer components {
  .label {
    font: 500 var(--t-xs)/1.3 var(--f-mono); letter-spacing: .04em; color: var(--muted);
    text-transform: uppercase;
  }
  .display {
    font-size: var(--t-xxl); line-height: .86; letter-spacing: -.045em; font-weight: 650;
    font-variation-settings: "wdth" 115;
  }
  .h2 { font-size: var(--t-xl); line-height: .95; letter-spacing: -.035em; font-variation-settings: "wdth" 110; }
  .lede { font-size: var(--t-lg); line-height: 1.32; letter-spacing: -.01em; max-width: 34ch; font-weight: 400; }
  .prose { max-width: 62ch; display: grid; gap: 1em; color: var(--ink); }
  .prose p { font-size: var(--t-md); }
  .muted { color: var(--muted); }

  .link-arrow {
    display: inline-flex; align-items: center; gap: .5em; text-decoration: none; font-weight: 500;
    border-bottom: 1px solid currentColor; padding-bottom: .15em;
  }
  .link-arrow::after { content: "→"; transition: transform .3s var(--ease); }
  .link-arrow:hover::after { transform: translateX(4px); }

  .section-head { display: flex; justify-content: space-between; align-items: end; gap: var(--s-4); padding-bottom: var(--s-4); border-bottom: 1px solid var(--line); margin-bottom: var(--s-5); }

  /* Tarjeta de obra */
  .card { display: grid; gap: .7rem; align-content: start; text-decoration: none; }
  .card-media { overflow: hidden; background: var(--paper-2); }
  .card-media img { width: 100%; aspect-ratio: var(--ar, 4 / 3); object-fit: cover; transition: transform 1.1s var(--ease), filter .6s; }
  .card:hover .card-media img { transform: scale(1.035); }
  .card-meta { display: flex; justify-content: space-between; gap: var(--s-3); align-items: baseline; }
  .card-title { font-size: var(--t-lg); font-weight: 600; letter-spacing: -.02em; line-height: 1.1; font-variation-settings: "wdth" 108; }
  .card-sub { font: 400 var(--t-xs)/1.4 var(--f-mono); color: var(--muted); text-align: right; white-space: nowrap; }
  .card, .card-meta > * { min-width: 0; }
  @media (max-width: 600px) { .pair .card-meta { flex-direction: column; } .pair .card-sub { text-align: left; } }

  .chips { display: flex; flex-wrap: wrap; gap: .5rem; }
  .chip {
    border: 1px solid var(--line); background: transparent; border-radius: 99px;
    padding: .45rem .95rem; font-size: var(--t-sm); cursor: pointer;
    transition: background-color .2s, color .2s, border-color .2s, transform .15s;
  }
  .chip:hover { border-color: var(--ink); }
  .chip:active { transform: scale(.97); }
  .chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
  .chip sup { font: 400 .65rem var(--f-mono); margin-left: .25rem; opacity: .7; }

  .toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
  .toggle button { border: 0; background: none; padding: .35rem .8rem; border-radius: 99px; font-size: var(--t-sm); cursor: pointer; }
  .toggle button[aria-pressed="true"] { background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--line); }

  /* Índice */
  .index { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
  .index th { text-align: left; font: 500 var(--t-xs)/1 var(--f-mono); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 0 .9rem; border-bottom: 1px solid var(--line); }
  .index td { padding: 0; border-bottom: 1px solid var(--line); }
  .index tr { transition: background-color .2s; }
  .index tbody tr:hover { background: var(--paper-2); }
  .index a { display: block; padding: .85rem 0; text-decoration: none; }
  .index .n { font: 400 var(--t-xs) var(--f-mono); color: var(--muted); width: 3.5rem; }
  .index .t { font-weight: 600; font-variation-settings: "wdth" 106; letter-spacing: -.01em; }
  .index .y, .index .s, .index .p { color: var(--muted); }
  .index .y { font: 400 var(--t-sm) var(--f-mono); width: 6rem; text-align: right; }
  @media (max-width: 700px) { .index .p, .index .s, .index .n, .index th.hide-sm { display: none; } }

  .peek {
    position: fixed; left: 0; top: 0; z-index: var(--z-peek); pointer-events: none;
    width: 300px; aspect-ratio: 4 / 3; opacity: 0; transform: translate3d(-999px, 0, 0) scale(.92);
    transition: opacity .2s var(--ease), scale .3s var(--ease);
    box-shadow: 0 20px 50px -20px rgb(28 29 27 / .45);
  }
  .peek img { width: 100%; height: 100%; object-fit: cover; }
  .peek.is-on { opacity: 1; }
  @media (hover: none), (pointer: coarse) { .peek { display: none; } }

  /* Lightbox */
  .lightbox {
    width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
    background: rgb(14 15 13 / .96); color: #efece6;
  }
  .lightbox::backdrop { background: transparent; }
  .lightbox figure { margin: 0; height: 100%; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 4rem var(--gutter) 1.25rem; gap: 1rem; }
  .lightbox img { max-width: 100%; max-height: calc(100dvh - 8rem); object-fit: contain; }
  .lightbox figcaption { font: 400 var(--t-xs) var(--f-mono); opacity: .75; }
  .lb-btn { position: absolute; background: none; border: 1px solid rgb(239 236 230 / .35); color: inherit; border-radius: 99px; cursor: pointer; padding: .5rem 1rem; transition: background-color .2s; }
  .lb-btn:hover { background: rgb(239 236 230 / .12); }
  .lb-close { top: 1rem; right: var(--gutter); }
  .lb-prev, .lb-next { top: 50%; translate: 0 -50%; width: 3rem; height: 3rem; padding: 0; }
  .lb-prev { left: var(--gutter); } .lb-next { right: var(--gutter); }
  @media (max-width: 700px) { .lb-prev, .lb-next { top: auto; bottom: 1rem; translate: none; } }
}

/* ---------- Pages ---------- */
@layer pages {
  .page-top { padding-top: calc(var(--header-h) + var(--s-6)); }

  /* Inicio */
  .hero-photo { position: relative; height: 100dvh; min-height: 560px; overflow: hidden; background: #1c1d1b; color: var(--over-photo); }
  .hero-photo .slide { position: absolute; inset: 0; opacity: 0; transition: opacity 1.6s ease; }
  .hero-photo .slide.is-on { opacity: 1; }
  .hero-photo img { width: 100%; height: 100%; object-fit: cover; }
  .hero-photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgb(20 21 19 / .45) 0%, transparent 22%, transparent 48%, rgb(20 21 19 / .72) 100%); pointer-events: none; }
  .hero-copy { position: absolute; inset: auto 0 0; z-index: 2; padding: 0 var(--gutter) clamp(1.25rem, 3vw, 2.5rem); display: grid; gap: var(--s-4); }
  .hero-copy .display { max-width: 12ch; color: var(--over-photo); }
  .hero-foot { display: flex; justify-content: space-between; align-items: end; gap: var(--s-4); flex-wrap: wrap; }
  .hero-caption { font: 400 var(--t-xs)/1.4 var(--f-mono); letter-spacing: .03em; color: var(--over-photo); text-decoration: none; display: inline-flex; gap: .75rem; align-items: center; }
  .hero-caption .bar { width: 3rem; height: 1px; background: currentColor; position: relative; overflow: hidden; opacity: .6; }
  .hero-dots { display: flex; gap: .4rem; }
  .hero-dots button { width: 2.25rem; height: 1.5rem; border: 0; background: none; cursor: pointer; position: relative; }
  .hero-dots button::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: rgb(244 241 234 / .4); }
  .hero-dots button[aria-current="true"]::before { background: var(--over-photo); }

  .statement { padding-block: var(--s-7) var(--s-6); display: grid; gap: var(--s-5); grid-template-columns: 1fr; }
  .statement .lede { font-size: clamp(1.5rem, 1rem + 2.1vw, 2.9rem); line-height: 1.12; letter-spacing: -.025em; max-width: 26ch; font-weight: 450; }
  .statement .lede em { font-style: normal; color: var(--accent); }
  .stats { display: grid; grid-template-columns: repeat(3, auto); gap: var(--s-5); justify-content: start; align-self: end; }
  .stats b { display: block; font-size: var(--t-xl); font-weight: 600; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; font-variation-settings: "wdth" 112; }
  @media (min-width: 1000px) { .statement { grid-template-columns: 1.6fr 1fr; align-items: end; } .stats { justify-content: end; } }

  .featured { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s-6) var(--gutter); align-items: start; }
  .featured .card { grid-column: 1 / -1; }
  @media (min-width: 820px) {
    .featured .card:nth-child(6n+1) { grid-column: 1 / span 7; }
    .featured .card:nth-child(6n+2) { grid-column: 9 / span 4; margin-top: 30%; }
    .featured .card:nth-child(6n+3) { grid-column: 2 / span 4; }
    .featured .card:nth-child(6n+4) { grid-column: 7 / span 6; margin-top: 6%; }
    .featured .card:nth-child(6n+5) { grid-column: 1 / span 5; }
    .featured .card:nth-child(6n+6) { grid-column: 7 / span 5; margin-top: 18%; }
  }

  .band { margin-top: var(--s-8); background: var(--paper-2); padding-block: var(--s-7); }
  .band-grid { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1fr); }
  .band-grid .pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gutter); }
  .band-grid .pair .card:last-child { margin-top: var(--s-6); }
  @media (min-width: 960px) { .band-grid { grid-template-columns: 1fr 1.4fr; align-items: center; } }

  .press-strip { display: grid; grid-auto-flow: column; grid-auto-columns: clamp(220px, 22vw, 300px); gap: var(--gutter); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: var(--s-3); }
  .press-strip > * { scroll-snap-align: start; }
  .press-strip .card-media img { aspect-ratio: 3 / 4; width: 100%; }
  .press-strip .card-meta { flex-direction: column; gap: .3rem; }
  .press-strip .card-sub { text-align: left; white-space: normal; }

  /* Obras */
  .works-head { display: grid; gap: var(--s-5); margin-bottom: var(--s-6); }
  .works-tools { display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; align-items: center; }
  .grid-works { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--s-6) var(--gutter); }
  .grid-works .card:nth-child(7n+1) { grid-column: span 2; }
  @media (max-width: 760px) { .grid-works .card:nth-child(7n+1) { grid-column: auto; } }
  .empty { padding: var(--s-6) 0; color: var(--muted); }

  /* Ficha de obra */
  .project-head { display: grid; gap: var(--s-5); padding-bottom: var(--s-6); }
  .project-head .display { font-size: clamp(2.6rem, 1rem + 7vw, 9rem); }
  .facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s-4); border-top: 1px solid var(--line); padding-top: var(--s-4); }
  .facts dt { margin-bottom: .35rem; }
  .facts dd { margin: 0; font-weight: 500; }
  .project-cover { width: 100%; max-height: 92dvh; object-fit: cover; }
  .project-body { display: grid; gap: var(--s-5); padding-block: var(--s-7); }
  @media (min-width: 1000px) { .project-body { grid-template-columns: 1fr 2fr; } }
  .gallery { columns: 2 320px; column-gap: var(--gutter); }
  .gallery button { display: block; width: 100%; padding: 0; border: 0; background: var(--paper-2); margin-bottom: var(--gutter); cursor: zoom-in; break-inside: avoid; overflow: hidden; }
  .gallery button img { width: 100%; transition: transform .9s var(--ease), opacity .3s; }
  .gallery button:hover img { transform: scale(1.02); }
  .pager { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gutter); border-top: 1px solid var(--line); padding-top: var(--s-4); margin-top: var(--s-6); }
  .pager a { text-decoration: none; display: grid; gap: .3rem; }
  .pager a:last-child { text-align: right; }
  .pager .card-title { transition: color .2s; }
  .pager a:hover .card-title { color: var(--accent); }
  .note { border-left: 2px solid var(--accent); padding: .3rem 0 .3rem 1rem; color: var(--muted); font-size: var(--t-sm); max-width: 60ch; }

  /* Estudio */
  .studio-grid { display: grid; gap: var(--s-6); }
  @media (min-width: 1000px) { .studio-grid { grid-template-columns: 1fr 1fr; align-items: start; } .studio-grid figure { position: sticky; top: calc(var(--header-h) + 1rem); } }
  .studio-grid figure { margin: 0; display: grid; gap: .6rem; }
  .timeline { display: grid; gap: var(--s-6); }
  .timeline h3 { font-size: var(--t-lg); letter-spacing: -.02em; margin-bottom: var(--s-3); }
  .timeline ol li { display: grid; grid-template-columns: 6.5rem 1fr; gap: var(--s-3); padding: .6rem 0; border-top: 1px solid var(--line); }
  .timeline ol li span:first-child { font: 400 var(--t-sm) var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; }

  /* Diseño */
  .objects { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: var(--s-6) var(--gutter); }
  .objects .card { background: none; border: 0; padding: 0; text-align: left; cursor: zoom-in; }
  .objects .card-media img { aspect-ratio: 1; }

  /* Prensa */
  .press-list li { border-top: 1px solid var(--line); }
  .press-list a { display: grid; grid-template-columns: 7rem 1fr auto; gap: var(--gutter); align-items: center; padding: var(--s-4) 0; text-decoration: none; }
  .press-list img { width: 7rem; aspect-ratio: 3 / 4; object-fit: cover; }
  .press-list .t { font-size: var(--t-lg); font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
  .press-list a:hover .t { color: var(--accent); }
  @media (max-width: 600px) { .press-list a { grid-template-columns: 5rem 1fr; } .press-list .label:last-child { display: none; } .press-list img { width: 5rem; } }

  /* Contacto */
  .contact-grid { display: grid; gap: var(--s-6); }
  @media (min-width: 960px) { .contact-grid { grid-template-columns: 1fr 1fr; } }
  .contact-data { display: grid; gap: var(--s-4); align-content: start; }
  .contact-data a { font-size: var(--t-lg); }
  form { display: grid; gap: var(--s-4); }
  .field { display: grid; gap: .4rem; }
  .field label { font: 500 var(--t-xs) var(--f-mono); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .field input, .field textarea, .field select {
    font: inherit; color: inherit; background: transparent; border: 0; border-bottom: 1px solid var(--line);
    padding: .6rem 0; border-radius: 0; transition: border-color .2s;
  }
  .field textarea { min-height: 8rem; resize: vertical; }
  .field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--ink); }
  .field:has(:user-invalid) input, .field:has(:user-invalid) textarea { border-color: #b3261e; }
  .field .err { display: none; font-size: var(--t-xs); color: #b3261e; }
  .field:has(:user-invalid) .err { display: block; }
  @media (prefers-color-scheme: dark) { .field:has(:user-invalid) input, .field:has(:user-invalid) textarea { border-color: #f2867d; } .field .err { color: #f2867d; } }
  .btn {
    justify-self: start; background: var(--ink); color: var(--paper); border: 0; border-radius: 99px;
    padding: .9rem 1.6rem; font-weight: 500; cursor: pointer; transition: transform .15s, background-color .2s;
  }
  .btn:hover { background: var(--accent); }
  .btn:active { transform: translateY(1px) scale(.99); }
  .form-ok { padding: var(--s-4); background: var(--paper-2); }
}

/* ---------- Motion ---------- */
@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    .reveal { opacity: 0; transform: translateY(24px); transition: opacity .9s var(--ease), transform .9s var(--ease); }
    .reveal.is-in { opacity: 1; transform: none; }
    ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .35s; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
  }
}
