/* ==========================================================================
   rutabrado.com
   Tipografia: Safiro (Atipo Foundry), autoallotjada.
   ========================================================================== */

@font-face {
  font-family: "Safiro";
  src: url("../fonts/safiro-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Safiro";
  src: url("../fonts/safiro-medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Safiro";
  src: url("../fonts/safiro-semibold.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Safiro";
  src: url("../fonts/safiro-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* --- Paleta ------------------------------------------------------------- */

:root {
  --black: #000000;
  --white: #f6f6f6;
  --stone: #d6d5d0;
  --grey: #5c5c5a;
  --olive: #a29c6b;
  --pink: #f7b7a4;
  --coral: #fb744f;
  --lime: #f5fecc;

  /* Colors per funció: la versió amb fons blanc (.is-light) els redefineix */
  --bg: var(--black);
  --fg: var(--white);
  --dim: var(--grey);
  --soft: var(--stone);
  --muted: var(--olive);
  --word: var(--lime);
  --word-hover: var(--coral);
  --link-hover: var(--pink);
  --line: #1c1c1b;
  --glow: 1;
  --grain: 0;

  --gutter: clamp(1rem, 3.5vw, 3rem);
  --font: "Safiro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.7, 0, 0.2, 1);

  color-scheme: dark;
}

.is-light {
  --bg: var(--white);
  --fg: var(--black);
  --dim: var(--stone);
  --soft: var(--grey);
  --muted: var(--grey);
  --word: var(--coral);
  --word-hover: var(--black);
  --link-hover: var(--coral);
  --line: var(--stone);
  --glow: 0.5;
  --grain: 0.32;

  color-scheme: light;
}

/* --- Base --------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: clamp(1rem, 0.94rem + 0.3vw, 1.1875rem);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

h1,
h2,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 4px;
  border-radius: 2px;
}

::selection {
  background: var(--coral);
  color: var(--bg);
}

.skip-link {
  position: fixed;
  left: var(--gutter);
  top: -4rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--fg);
  color: var(--bg);
}

.skip-link:focus {
  top: 1rem;
}

.label {
  font-size: 1rem;
  font-weight: 400;
  color: var(--muted);
}

/* --- Barra superior ----------------------------------------------------- */

.bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1.25rem var(--gutter);
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--white);
  mix-blend-mode: difference;
}

.bar__role {
  white-space: nowrap;
}

/* Menú d'idioma: l'idioma actual ple, els altres apagats */
.lang ul {
  display: flex;
  gap: 1.25rem;
}

.lang a {
  position: relative;
  opacity: 0.45;
  transition: opacity 0.3s;
}

.lang a[aria-current],
.lang a:hover,
.lang a:focus-visible {
  opacity: 1;
}

.lang a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.35em;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.45s var(--ease);
}

@media (max-width: 30rem) {
  .bar {
    font-size: 0.8125rem;
  }

  .lang ul {
    gap: 0.75rem;
  }
}

.lang a:not([aria-current]):hover::after,
.lang a:not([aria-current]):focus-visible::after {
  transform: scaleX(1);
  transform-origin: left;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Entrada: text de presentació i Colaboratori ------------------------ */

.intro {
  position: relative;
  padding-block: clamp(7rem, 16vh, 11rem) clamp(4rem, 12vw, 10rem);
  overflow: hidden;
}

.intro__glow {
  position: absolute;
  inset: -10% -20% auto;
  height: 120vh;
  background:
    radial-gradient(38% 34% at 72% 30%, rgb(251 116 79 / 0.26), transparent 70%),
    radial-gradient(32% 30% at 20% 62%, rgb(247 183 164 / 0.12), transparent 70%);
  filter: blur(30px);
  opacity: var(--glow);
  pointer-events: none;
  -webkit-mask-image: linear-gradient(#000 40%, transparent 85%);
  mask-image: linear-gradient(#000 40%, transparent 85%);
}

.intro__text {
  position: relative;
  max-width: 84rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
  font-size: clamp(1.75rem, 0.8rem + 3.6vw, 4.25rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: pretty;
}

/* Amb animació, el text i la barra esperen l'entrada.
   Si el JS no arrenca en 3 s, el <head> treu la classe .js i tot es mostra. */
@media (prefers-reduced-motion: no-preference) {
  .js .intro__text,
  .js .intro__glow,
  .js [data-intro] {
    visibility: hidden;
  }
}

/* --- 404 ---------------------------------------------------------------- */

.e404 {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2.5rem;
  min-height: 100vh;
  min-height: 100svh;
  padding: 5rem var(--gutter);
  text-align: center;
}

.e404 h1 {
  font-size: 30vw;
  font-weight: 700;
  line-height: 0.8;
  letter-spacing: -0.05em;
}

.e404 p:first-of-type {
  font-size: clamp(2rem, 1rem + 4vw, 5rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
}

.e404 em {
  font-style: normal;
  color: var(--coral);
}

/* --- Colaboratori ------------------------------------------------------- */

.colab__body {
  max-width: 84rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Foto en una capa sota la paraula, alineada a l'esquerra amb el paràgraf.
   La paraula puja per sobre la foto (alçada de la paraula ≈ 23vw × 0.82). */
.colab__stage {
  position: relative;
}

.colab__figure {
  position: relative;
  z-index: 0;
  width: clamp(11rem, 26vw, 26rem);
  margin: 0 0 0 calc(max(0px, (100% - 84rem) / 2) + var(--gutter));
}

.colab__photo {
  width: 100%;
  height: auto;
}

/* Etiqueta sobre la vora superior de la foto */
.colab__tag {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.55em 1.3em;
  border-radius: 999px;
  background: var(--coral);
  color: var(--black);
  font-size: 0.9375rem; /* com el menú superior */
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 30rem) {
  .colab__tag {
    font-size: 0.8125rem;
  }
}

.colab__stage .colab__word {
  margin-top: -18.86vw;
}

.colab__word {
  position: relative;
  z-index: 1;
  margin-block: clamp(1.5rem, 4vw, 3rem);
  padding-left: var(--gutter);
  font-size: 23vw;
  font-weight: 100;
  line-height: 0.82;
  letter-spacing: -0.042em; /* ≈ -14px a 1440px d’amplada; s’escala amb la mida */
  white-space: nowrap;
  color: var(--word);
}

.colab__word a {
  display: inline-block;
  transition: color 0.5s var(--ease);
}

.colab__word a:hover,
.colab__word a:focus-visible {
  color: var(--word-hover);
}

.colab__body {
  display: grid;
  gap: 2rem;
  justify-items: start;
}

.colab__text p:first-child {
  max-width: 34rem;
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem);
  line-height: 1.5;
  color: var(--soft);
}

@media (min-width: 56rem) {
  .colab__body {
    grid-template-columns: minmax(0, 34rem) 1fr;
    align-items: center;
  }
}

.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 1em 1.7em;
  border: 1px solid var(--fg);
  border-radius: 999px;
  overflow: hidden;
  isolation: isolate;
  font-weight: 500;
  transition: color 0.5s var(--ease), border-color 0.5s var(--ease);
}

.pill::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--coral);
  transform: translateY(101%);
  transition: transform 0.5s var(--ease);
}

.pill:hover,
.pill:focus-visible {
  color: var(--bg);
  border-color: var(--coral);
}

.pill:hover::before,
.pill:focus-visible::before {
  transform: translateY(0);
}

/* --- Contacte ----------------------------------------------------------- */

.contact {
  display: grid;
  gap: 0.75rem;
  max-width: 84rem;
  margin-inline: auto;
  padding: clamp(6rem, 16vw, 12rem) var(--gutter) clamp(5rem, 12vw, 9rem);
}

.contact__mail {
  font-size: clamp(1.5rem, 0.6rem + 4.2vw, 5.5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.contact__mail a {
  transition: color 0.4s var(--ease);
}

.contact__mail a:hover,
.contact__mail a:focus-visible {
  color: var(--link-hover);
}

/* --- Peu ---------------------------------------------------------------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem 2rem;
  padding: 1.5rem var(--gutter) 2rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  color: var(--muted);
}

.foot__host {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.foot__host img {
  width: 96px;
  opacity: 0.85;
  transition: opacity 0.3s;
}

.foot__host a:hover img,
.foot__host a:focus-visible img {
  opacity: 1;
}

/* --- Gra de fons ------------------------------------------------------- */

/* Soroll tipus Photoshop (SVG feTurbulence) que vibra a 10 fotogrames per segon */
body::after {
  content: "";
  position: fixed;
  inset: -50%;
  z-index: 80;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: var(--grain);
  mix-blend-mode: multiply;
  pointer-events: none;
  animation: grain 0.8s steps(1) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  12% { transform: translate(-3%, 2%); }
  25% { transform: translate(4%, -3%); }
  37% { transform: translate(-2%, -4%); }
  50% { transform: translate(3%, 4%); }
  62% { transform: translate(-4%, 1%); }
  75% { transform: translate(2%, -2%); }
  87% { transform: translate(-1%, 3%); }
}

/* --- Cursor ------------------------------------------------------------- */

.cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--white);
  mix-blend-mode: difference;
  pointer-events: none;
  opacity: 0;
}

@media (hover: none), (pointer: coarse) {
  .cursor {
    display: none;
  }
}

/* --- Moviment reduït ---------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cursor {
    display: none;
  }

  body::after {
    animation: none;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* --- Molècules: al costat del paràgraf -------------------------------- */

.colab__text {
  display: grid;
  gap: 2rem;
  justify-items: start;
}

.colab__text .pill {
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem); /* igual que el paràgraf */
}

.molecules {
  position: relative;
  justify-self: center;
  align-self: center;
  width: min(100%, clamp(18rem, 30vw, 26rem));
  aspect-ratio: 1;
}

.molecules__base {
  width: 100%;
  pointer-events: none;
}

.molecules .canvas-container,
.molecules canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
