/* Instrument Sans (SIL Open Font License) — variable font, weights 400–700 */
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/InstrumentSans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/InstrumentSans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #fafaf8;
  --fg: #3a3a37;      /* dark grey text on light (never pure black) */
  --muted: #3a3a37;   /* one uniform text colour: no secondary grey */
  --line: #e4e4de;
  --card: #efefea;
  --accent: #3a3a37;
  --hi: #000;         /* highlight (menu hover / current page): black on the light theme */
  --gutter: clamp(20px, 3.2vw, 120px); /* full-width layout: only side margins, no centered column */
  --font: "Instrument Sans", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #1c1c1b;
  --fg: #b6b6b1;      /* light grey text on dark (never pure white) */
  --muted: #b6b6b1;   /* one uniform text colour: no secondary grey */
  --line: #333330;
  --card: #262624;
  --accent: #b6b6b1;
  --hi: #fff;         /* highlight (menu hover / current page): white on the dark theme */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1b; --fg: #b6b6b1; --muted: #b6b6b1;
    --line: #333330; --card: #262624; --accent: #b6b6b1; --hi: #fff;
  }
}

/* Fluid root size: 15px on most screens, growing gently on very large displays. */
html { font-size: clamp(14px, 0.12vw + 10.5px, 18px); }

/* WebGL background (js/bg.js): fixed, behind everything, never intercepts clicks */
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; display: block; }

/* ---- Type scale (single place to tune the typography) ----------------------
   H1  page titles (Home slogan, category, project): caps, wide tracking, Bold
   H2  statements (About headline, contact e-mail): large, regular-medium
   H3  titles (cards, captions, skills, bar names): body size, medium
   P   body text; P-large for introductions; small for captions/meta
   --------------------------------------------------------------------------- */
:root {
  --fs-h1: clamp(0.8rem, 1.15vw, 2.2rem);
  --fs-h2: clamp(1.2rem, 1.7vw, 2.4rem);
  --fs-h3: 1rem;
  --fs-p: calc(1rem + 2px);
  --fs-p-lg: calc(1.0625rem + 2px);
  --fs-sm: 0.875rem;
}
h1 { font-size: var(--fs-h1); font-weight: 700; line-height: 1.25; text-transform: uppercase; letter-spacing: .32em; }
h2 { font-size: var(--fs-h2); font-weight: 500; line-height: 1.15; letter-spacing: -0.025em; }
h3 { font-size: var(--fs-h3); font-weight: 500; line-height: 1.3; }
p, dd, li { font-size: var(--fs-p); line-height: 1.6; }

* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 400 1rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.site-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 16px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; color: var(--fg); }
/* White-on-transparent logo used as a mask, so it follows the theme colour. */
.logo {
  display: block; height: 2.5rem; aspect-ratio: 1490 / 1301;
  background-color: currentColor;
  -webkit-mask: url("../img/logo.png") center / contain no-repeat;
          mask: url("../img/logo.png") center / contain no-repeat;
}
.nav { display: flex; gap: 28px; margin-left: 20px; color: var(--muted); }
/* Menu items: small caps with wide tracking */
.nav a { font-size: 0.75rem; letter-spacing: 0.16em; text-transform: uppercase; }
/* Menu: hover and current page are highlighted in white (black on the light theme), no underline */
.nav a, .tools button { transition: color .15s; }
.nav a:hover, .nav a[aria-current="page"], .tools button:hover { color: var(--hi); }
.tools { display: flex; gap: 12px; margin-left: auto; color: var(--muted); }
.tools button { padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.8125rem; }

main, .site-footer { padding: 0 var(--gutter); }

.hero { padding: clamp(32px, 7.5vw, 100px) 0; } /* same space above the title and below the text */
.eyebrow { color: var(--muted); font-size: 0.875rem; letter-spacing: .08em; text-transform: uppercase; }
/* Cinematic title: single line, caps, wide tracking, heaviest weight. */
.hero h1 { margin: 0 0 8px; white-space: nowrap; } /* H1 = heaviest weight of the variable font (400–700) */
.hero .lead { font-size: var(--fs-p); max-width: none; } /* same size as body text */
@media (max-width: 700px) {
  .hero h1 { white-space: normal; font-size: 0.9375rem; letter-spacing: .22em; line-height: 1.5; }
}
.lead { max-width: 52ch; color: var(--muted); font-size: var(--fs-p-lg); }

/* Category links: plain text, no pill outline. */
.filters { display: flex; flex-wrap: wrap; gap: 6px 24px; margin-bottom: 28px; }
.chip { padding: 2px 0; color: var(--muted); font-size: var(--fs-p); transition: color .15s; }
.chip:hover { color: var(--fg); }
.chip.is-active { color: var(--fg); text-decoration: underline; text-underline-offset: 7px; text-decoration-thickness: 1px; }

.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(320px, 20vw, 640px)), 1fr)); }
.card { display: block; }
.card .thumb {
  aspect-ratio: 4 / 3; border-radius: 6px; background: var(--card);
  display: grid; place-items: center; color: var(--muted); font-size: 0.8125rem;
  overflow: hidden; transition: transform .25s ease;
}
.card .thumb.wide { aspect-ratio: 16 / 9; } /* video covers: full 16:9 frame, nothing cropped */
.card:hover .thumb { transform: translateY(-3px); }
.card img { width: 100%; height: 100%; object-fit: cover; }
/* Cards without a cover image: show the category in large type. */
.card .thumb.text { align-content: end; justify-items: start; padding: 20px; }
.card .thumb.text span { font-size: clamp(1.25rem, 2vw, 1.75rem); letter-spacing: -0.02em; line-height: 1.1; color: var(--muted); }
.card .meta { display: flex; justify-content: space-between; gap: 12px; padding-top: 10px; }
.card h3 { font-size: var(--fs-h3); }
.card .tag { color: var(--muted); font-size: var(--fs-sm); }
.card[hidden] { display: none; }

.about, .contact { padding: clamp(64px, 10vw, 128px) 0 0; border-top: 0; }
/* Two columns, always: titles on the left, text on the right (only stacks on narrow screens). */
/* Text column is centred on the page (text itself stays left-aligned); a thin vertical line divides it from the titles. */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 46rem) minmax(0, 1fr); gap: 2rem 0; align-items: stretch; }
/* Home: the vertical line is drawn once for About + Contact (not once per section). It sits on the left edge of
   the centred text column: 50% - half of the 46rem column, starting where the About text starts. */
.vline { position: relative; }
.vline::before {
  content: ""; position: absolute; z-index: 1; width: 1px; bottom: 0;
  top: clamp(64px, 10vw, 128px); /* = the padding above the About section */
  left: calc(50% - 23rem);
  background: color-mix(in srgb, var(--fg) 30%, transparent);
}
.vline .split-body { border-left: 0; }
.split-head { grid-column: 1; padding-right: clamp(16px, 3vw, 64px); }
.split-body {
  grid-column: 2; border-left: 1px solid color-mix(in srgb, var(--fg) 30%, transparent); padding-left: clamp(20px, 3vw, 56px);
  /* trim the empty line-height space so the vertical line starts at the top of the first line's capitals and ends at the last baseline */
  text-box: trim-both cap alphabetic;
}
.split-body > * + * { margin-top: 1.25rem; }
.split-body > :first-child { margin-top: 0; } /* so the vertical line starts exactly at the first line of text */
/* On page heads, line up the text with the title (below the "back" link). */
.p-head .split-body { margin-top: calc(0.875rem * 1.6 + 20px); }
@media (max-width: 700px) {
  /* still two columns on phones, just tighter; long caps titles use less tracking */
  .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 1.25rem 0; }
  .vline::before { left: 40%; } /* two columns on phones: 1fr / 1.5fr */
  .split-head { padding-right: 0.75rem; overflow-wrap: anywhere; }
  .facts dd { font-size: var(--fs-sm); }
  .split-body { padding-left: 0.75rem; }
  .p-head h1 { letter-spacing: .14em; overflow-wrap: anywhere; }
  .split-body .lead { font-size: var(--fs-p); }
}

/* Section labels ("Sobre", "Contacto"): small caps eyebrow, not a visual H2 */
.about h2, .contact h2 { font-size: var(--fs-sm); color: var(--muted); font-weight: 500; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 16px; }
.about-lead { max-width: 30ch; font-size: var(--fs-h2); line-height: 1.15; letter-spacing: -0.025em; font-weight: 500; }
.about-edu { margin-top: 16px; color: var(--muted); font-size: var(--fs-sm); letter-spacing: .06em; text-transform: uppercase; }
.about-body { display: grid; gap: 20px; margin-top: 40px; max-width: 64ch; }
.about-body p { font-size: var(--fs-p); line-height: 1.6; }
.skills-title { margin: 64px 0 8px; font-size: var(--fs-sm); font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.skills { margin: 0; }
.skills > div { display: grid; grid-template-columns: 7rem 1fr; gap: 8px 24px; padding: 10px 0; }
.skills dt { font-size: var(--fs-h3); font-weight: 700; }
.skills dd { margin: 0; color: var(--muted); max-width: 70ch; font-weight: 400; }
@media (max-width: 640px) { .skills > div { grid-template-columns: 1fr; gap: 4px; } }
.mail { font-size: var(--fs-h2); letter-spacing: -0.02em; border-bottom: 1px solid var(--line); }
.mail:hover { border-color: var(--fg); }

.site-footer {
  display: flex; justify-content: space-between; margin-top: clamp(64px, 10vw, 128px);
  padding-top: 24px; padding-bottom: 32px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.875rem;
}

/* ---- Home: category bars ---- */
.cats { display: flex; gap: 8px; height: clamp(320px, 54vh, 800px); }
.cat {
  display: flex; flex-direction: column; flex: 1 1 0; min-width: 0;
  transition: flex-grow .7s cubic-bezier(.2, .7, .2, 1);
}
.cat:hover, .cat:focus-visible { flex-grow: 1.3; } /* gentle widening on hover */
.frame { position: relative; flex: 1; min-height: 0; overflow: hidden; isolation: isolate; border-radius: 6px; background: var(--card); }
.slides { position: absolute; inset: 0; transition: filter .4s; }
.cats:hover .cat:not(:hover) .slides { filter: brightness(.8); }
.slides img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transform: scale(1.02);
  transition: opacity 1.4s ease, transform 7s ease-out;
}
.slides img.on { opacity: 1; transform: scale(1); }
/* Caption under each bar: category name as plain text. */
/* Category name inside the image, over a subtle black-to-transparent gradient at the bottom (keeps it readable). */
.cat .frame::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.22) 20%, rgba(0, 0, 0, 0) 42%);
}
.cat-label { position: absolute; left: 1rem; right: 1rem; bottom: 0.9rem; z-index: 2; }
.cat-name { font-size: var(--fs-h3); font-weight: 500; color: #e9e9e5; transition: color .2s; }
.cat:hover .cat-name, .cat:focus-visible .cat-name { color: #fff; }
.cat-count { font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
a.chip { display: inline-block; }
.p-head ~ .grid { margin-top: 8px; }
.p-head .filters { margin-top: 32px; margin-bottom: 0; }
@media (max-width: 640px) {
  .cats { flex-direction: column; height: auto; }
  .cat { flex: none; }
  .frame { flex: none; height: 26vh; min-height: 150px; }
  .cat:hover, .cat:focus-visible { flex-grow: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .cat, .slides img { transition: none; }
}

.cat-intro { max-width: 70ch; margin: 0 0 28px; color: var(--muted); font-size: 1.0625rem; }
.cat-intro[hidden] { display: none; }
.empty { color: var(--muted); }

/* ---- Project page ---- */
.p-head .lead { margin-top: 12px; }
.subtitle { color: var(--muted); font-size: var(--fs-p-lg); margin-bottom: 8px; }
.items { margin: 20px 0 0; padding-left: 1.1em; color: var(--muted); max-width: 70ch; }
.items li { margin: 2px 0; }
.items li:first-child { margin-top: 0; }
.links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn { padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.875rem; }
.btn:hover { border-color: var(--fg); }
.media figcaption strong { display: block; font-weight: 500; color: var(--fg); }
.p-head { padding: clamp(40px, 8vw, 96px) 0 clamp(32px, 5vw, 56px); }
.back { color: var(--muted); font-size: 0.875rem; }
.back:hover { color: var(--fg); }
.p-head h1 { margin: 28px 0 16px; line-height: 1.35; } /* same H1 style as the Home slogan; may wrap */
.facts {
  display: grid; gap: 20px 32px; margin-top: 40px; padding-top: 20px;
  border-top: 1px solid var(--line);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.facts dt { color: var(--muted); font-size: 0.8125rem; letter-spacing: .06em; text-transform: uppercase; }
.facts dd { margin: 4px 0 0; }

/* Gallery: 3 balanced columns, images keep their own proportions (nothing is cropped). Click opens them larger. */
.p-media { column-count: 3; column-gap: 20px; }
.media { break-inside: avoid; margin: 0 0 20px; }
.media.video { column-span: all; max-width: 62rem; }
.media img[data-full] { cursor: zoom-in; }
@media (max-width: 900px) { .p-media { column-count: 2; } }
.media img, .media .frame { display: block; width: 100%; height: auto; border-radius: 6px; }
.media .placeholder { aspect-ratio: 16 / 10; background: var(--card); }
.media .ratio-video { aspect-ratio: 16 / 9; overflow: hidden; }
.media iframe { width: 100%; height: 100%; border: 0; }
.media audio { width: 100%; }
.media figcaption { padding-top: 8px; color: var(--muted); font-size: 0.875rem; }

/* ---- Lightbox (gallery image shown large) ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 95%, transparent); backdrop-filter: blur(6px);
}
.lightbox[hidden] { display: none; }
body.lb-open { overflow: hidden; }
.lb-fig { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 92vw; }
.lb-fig img { max-width: 92vw; max-height: 80vh; width: auto; height: auto; border-radius: 4px; display: block; }
.lb-fig figcaption { font-size: var(--fs-sm); text-align: center; max-width: 70ch; }
.lb-fig figcaption strong { display: block; font-weight: 500; }
.lb-btn { position: absolute; width: 3.5rem; height: 3.5rem; font-size: 2.2rem; line-height: 1; color: var(--fg); transition: color .15s; }
.lb-btn:hover { color: var(--hi); }
.lb-btn[hidden] { display: none; }
.lb-close { top: 1rem; right: 1rem; }
.lb-prev { left: 0.75rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 0.75rem; top: 50%; transform: translateY(-50%); }
.lb-count { position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%); font-size: var(--fs-sm); letter-spacing: .1em; }

.p-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  margin-top: clamp(48px, 8vw, 96px); padding-top: 24px; border-top: 1px solid var(--line);
}
.p-nav a { display: flex; flex-direction: column; gap: 4px; }
.p-nav a:last-child { text-align: right; }
.p-nav span { color: var(--muted); font-size: 0.875rem; }
.p-nav strong { font-size: var(--fs-h3); font-weight: 500; }
.p-nav a:hover strong { text-decoration: underline; text-underline-offset: 4px; }

/* Hamburger button (mobile only) */
.menu-toggle { display: none; position: relative; width: 34px; height: 30px; padding: 0; }
.menu-toggle span, .menu-toggle span::before, .menu-toggle span::after {
  position: absolute; left: 50%; width: 14px; height: 1.5px; background: currentColor;
  transform: translateX(-50%); transition: transform .2s, top .2s, opacity .2s;
}
.menu-toggle span { top: 50%; display: block; }
.menu-toggle span::before, .menu-toggle span::after { content: ""; left: 50%; }
.menu-toggle span::before { top: -5px; }
.menu-toggle span::after { top: 5px; }
.site-header.open .menu-toggle span { background: transparent; }
.site-header.open .menu-toggle span::before { top: 0; transform: translateX(-50%) rotate(45deg); }
.site-header.open .menu-toggle span::after { top: 0; transform: translateX(-50%) rotate(-45deg); }

/* The menu has all categories + About + Contact: switch to the hamburger below this width. */
@media (max-width: 960px) {
  .menu-toggle { display: block; }
  .nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0; margin: 0;
    padding: 8px var(--gutter) 16px;
    max-height: calc(100vh - 4.5rem); overflow-y: auto;
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .site-header.open .nav { display: flex; }
  .nav a { padding: 11px 0; font-size: 0.875rem; color: var(--fg); }
  .tools { margin-left: auto; }
}

@media (max-width: 640px) {
  .p-media { column-gap: 10px; }
  .media { margin-bottom: 10px; }
}
