/* Shared finishing touches: selection, scrollbars and text composition. */
:root {
  --font-ui:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    Helvetica,
    Arial,
    sans-serif,
    'Apple Color Emoji',
    'Segoe UI Emoji';
  --page-accent: var(--a, #f29e1e);
  --selection-ink: #0b0b0f;
  --scrollbar-track: #17171d;
}

html {
  font-family: var(--font-ui);
}

body {
  font-family: inherit;
}

button,
input,
textarea,
select {
  font: inherit;
}

/* Page-specific accents, sourced from the existing portfolio palette. */
html[data-visual-theme='home'] {
  --page-accent: var(--b, #9b59b6);
  --selection-ink: #ffffff;
}

html[data-visual-theme='graphic'] {
  --page-accent: var(--a, #f29e1e);
}

html[data-visual-theme='video'] {
  --page-accent: var(--b, #9b59b6);
  --selection-ink: #ffffff;
}

html[data-visual-theme='about'] {
  --page-accent: #ffffff;
}

html[data-visual-theme='testimonials'] {
  --page-accent: #ffd700;
}

html[data-visual-theme='1991studio'] {
  --page-accent: #00ff88;
}

html[data-visual-theme='dariozotano'] {
  --page-accent: #9b59b6;
  --selection-ink: #ffffff;
}

html[data-visual-theme='dumplingxi'] {
  --page-accent: #be2821;
  --selection-ink: #ffffff;
}

html[data-visual-theme='josepmoratal'] {
  --page-accent: #ffd700;
}

html[data-visual-theme='oriolnunez'] {
  --page-accent: #c00000;
  --selection-ink: #ffffff;
}

html[data-visual-theme='legal'] {
  --page-accent: #f29e1e;
}

html[data-visual-theme='purple'] {
  --page-accent: #9b59b6;
  --selection-ink: #ffffff;
}

/* Firefox and browsers implementing the CSS Scrollbars standard. */
html {
  scrollbar-color: var(--page-accent) var(--scrollbar-track);
  scrollbar-width: thin;
}

/* Chromium, Safari and older WebKit implementations. */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  min-height: 42px;
  border: 2px solid var(--scrollbar-track);
  border-radius: 999px;
  background-color: var(--page-accent);
}

::-webkit-scrollbar-thumb:hover {
  filter: brightness(1.12);
}

::selection {
  color: var(--selection-ink);
  background: var(--page-accent);
  text-shadow: none;
}

/* Native, dependency-free text morph used only by the About hero label. */
.text-morph-label {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  white-space: nowrap;
}

.text-morph-prefix {
  flex: 0 0 auto;
}

.text-morph-words {
  position: relative;
  display: inline-grid;
  align-items: center;
  justify-items: start;
  filter: url('#text-morph-threshold');
}

.text-morph-anchor,
.text-morph-word {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.text-morph-anchor {
  visibility: hidden;
}

.text-morph-word {
  opacity: 0;
  transform-origin: left center;
  animation: text-morph-cycle 9s var(--text-morph-delay) infinite ease-in-out;
  will-change: opacity, filter, transform;
}

.text-morph-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

html.text-morph-paused .text-morph-word {
  animation-play-state: paused;
}

@keyframes text-morph-cycle {
  0% {
    opacity: 0;
    filter: blur(7px);
    transform: scale(0.9);
  }

  11.111% {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }

  27.778% {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }

  38.889%,
  100% {
    opacity: 0;
    filter: blur(7px);
    transform: scale(1.1);
  }
}

@media (max-width: 768px), (prefers-reduced-motion: reduce) {
  .text-morph-words {
    filter: none;
  }

  .text-morph-word {
    display: none;
    animation: none;
    will-change: auto;
  }

  .text-morph-word[data-text-morph-index='0'] {
    display: block;
    opacity: 1;
    filter: none;
    transform: none;
  }
}

/* Safe baseline for engines without the newer text-wrap values. */
p,
li,
blockquote,
figcaption,
.description,
.lead,
.subtitle {
  overflow-wrap: break-word;
}

/* Progressive enhancement: browsers that understand pretty wrapping use it. */
@supports (text-wrap: pretty) {
  p,
  li,
  blockquote,
  figcaption,
  .description,
  .lead,
  .subtitle {
    text-wrap: pretty;
  }
}

@supports (text-wrap: balance) {
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  .title,
  .heading {
    text-wrap: balance;
  }
}

/* Cursor-proximity weight for the large titles on internal hero panels. */
.immersive-hero-title[data-dynamic-weight] {
  cursor: default;
}

.dynamic-weight-word,
.dynamic-weight-letter {
  display: inline-block;
}

.dynamic-weight-word {
  white-space: nowrap;
}

.dynamic-weight-letter {
  font-variation-settings: 'wght' 640;
  font-weight: 640;
  will-change: font-variation-settings, font-weight;
}

/* Canvas overlay used by the desktop-only pixel-to-sharp image reveal. */
.pixel-reveal-media {
  position: relative;
  display: block;
  width: 100%;
  line-height: 0;
  overflow: hidden;
  border-radius: 14px;
}

.pixel-reveal-media.is-square {
  border-radius: 0;
}

.pixel-reveal-media > img {
  display: block;
}

.pixel-reveal-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  image-rendering: pixelated;
  pointer-events: none;
  opacity: 1;
  transition: opacity 100ms linear;
  will-change: opacity;
}

/* Spring-based magnetic interaction for primary contact buttons. */
.btn-contact[data-magnetic-button] {
  --magnetic-x: 0px;
  --magnetic-y: 0px;
  --magnetic-scale: 1;
  --magnetic-radius: var(--radius, 18px);
  border-radius: var(--magnetic-radius) !important;
  transform: translate3d(var(--magnetic-x), var(--magnetic-y), 0)
    scale(var(--magnetic-scale)) !important;
  transform-origin: center;
  transition:
    border-radius 440ms cubic-bezier(0.22, 1, 0.36, 1),
    background 200ms ease,
    border-color 200ms ease,
    filter 200ms ease,
    box-shadow 200ms ease !important;
  will-change: transform !important;
}

.btn-contact[data-magnetic-button]:hover {
  --magnetic-radius: 999px;
  transition-duration: 260ms, 200ms, 200ms, 200ms, 200ms !important;
  background: linear-gradient(
    135deg,
    rgba(242, 158, 30, 0.25),
    rgba(155, 89, 182, 0.16)
  ) !important;
}

.btn-contact[data-magnetic-button]::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  content: '';
  background: rgba(255, 255, 255, 0.035);
  opacity: var(--magnetic-glow, 0);
  transition: opacity 250ms ease;
  pointer-events: none;
}

.magnetic-button__label {
  position: relative;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translate3d(var(--magnetic-label-x, 0px), var(--magnetic-label-y, 0px), 0);
  will-change: transform;
}

@media (max-width: 768px), (hover: none), (pointer: coarse), (prefers-reduced-motion: reduce) {
  .dynamic-weight-letter {
    font-variation-settings: normal;
    font-weight: inherit;
    will-change: auto;
  }

  .pixel-reveal-canvas {
    display: none;
  }

  .btn-contact[data-magnetic-button] {
    transform: none !important;
    will-change: auto !important;
  }

  .magnetic-button__label {
    transform: none;
    will-change: auto;
  }
}
