/* ==========================================================================
   Toni Ferrari Juan, portfolio
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #0a0b10;
  --bg-alt: #0e1018;
  --surface: #13151f;
  --surface-2: #1a1d2a;
  --border: rgba(255, 255, 255, .09);
  --text: #e9ebf3;
  --muted: #9aa2b8;
  --accent: #8b7cff;
  --accent-2: #2dd4ff;
  --accent-ink: #0a0b10;
  --grad: linear-gradient(120deg, var(--accent), var(--accent-2));
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, .7);
  --nav-bg: rgba(10, 11, 16, .72);

  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Space Grotesk", var(--font-body);
  --radius: 18px;
  --nav-h: 68px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-alt: #eef0f7;
  --surface: #ffffff;
  --surface-2: #f1f2f9;
  --border: rgba(15, 18, 40, .1);
  --text: #12141f;
  --muted: #566078;
  --accent: #5a41ee;
  --accent-2: #0a8fb0;
  --accent-ink: #ffffff;
  --shadow: 0 20px 40px -22px rgba(30, 30, 80, .35);
  --nav-bg: rgba(246, 247, 251, .78);
  color-scheme: light;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .3s, color .3s;
}

img, video, svg { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.1; margin: 0; letter-spacing: -.02em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }

svg { width: 1.15em; height: 1.15em; flex: none; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; border-radius: 6px; }

.container { width: min(1160px, 100% - 2.5rem); margin-inline: auto; }
.center { justify-content: center; }

.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; border-radius: 10px; font-weight: 600; text-decoration: none;
  transition: top .2s;
}
.skip-link:focus { top: 1rem; }

.progress {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 120;
  background: var(--grad); transform-origin: left; transform: scaleX(0);
}

.grad {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1.05rem; border-radius: 999px;
  border: 1px solid var(--border); background: transparent;
  font-weight: 600; font-size: .95rem; text-decoration: none; line-height: 1.2;
  transition: transform .2s, background-color .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn-lg { padding: .85rem 1.4rem; font-size: 1rem; }
.btn-primary {
  background: var(--grad); color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 10px 30px -12px var(--accent);
}
.btn-primary:hover { box-shadow: 0 14px 34px -10px var(--accent); }
.btn-ghost { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.btn-ghost:hover { border-color: var(--accent); background: var(--surface-2); }

.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  transition: border-color .2s, transform .2s;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Nav ---------- */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 100; height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid transparent;
  transition: border-color .3s, background-color .3s;
}
.nav.scrolled { border-bottom-color: var(--border); }
.nav-inner {
  width: min(1160px, 100% - 2.5rem); height: 100%; margin-inline: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; font-family: var(--font-head); font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px;
  background: var(--grad); color: var(--accent-ink); font-size: .95rem;
}
.brand-name { font-size: 1.05rem; }

.nav-links { display: flex; gap: .25rem; }
.nav-links a {
  position: relative; padding: .5rem .85rem; border-radius: 999px;
  text-decoration: none; color: var(--muted); font-weight: 500; font-size: .95rem;
  transition: color .2s, background-color .2s;
}
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--text); background: var(--surface-2); }
.nav-actions { display: flex; align-items: center; gap: .5rem; }

.i-sun { display: none; }
:root[data-theme="light"] .i-sun { display: block; }
:root[data-theme="light"] .i-moon { display: none; }

.burger { display: none; position: relative; }
.burger span {
  position: absolute; left: 11px; right: 11px; height: 2px; border-radius: 2px;
  background: currentColor; transition: transform .25s, top .25s;
}
.burger span:first-child { top: 16px; }
.burger span:last-child { top: 24px; }
.nav.open .burger span:first-child { top: 20px; transform: rotate(45deg); }
.nav.open .burger span:last-child { top: 20px; transform: rotate(-45deg); }

@media (max-width: 760px) {
  .burger { display: inline-grid; }
  .brand-name { display: none; }
  .nav-links {
    position: fixed; inset: var(--nav-h) 0 auto 0;
    flex-direction: column; gap: .25rem; padding: 1rem 1.25rem 1.5rem;
    background: var(--bg); border-bottom: 1px solid var(--border);
    transform: translateY(-12px); opacity: 0; visibility: hidden;
    transition: transform .25s, opacity .25s, visibility .25s;
  }
  .nav.open .nav-links { transform: none; opacity: 1; visibility: visible; }
  .nav-links a { font-size: 1.1rem; padding: .8rem 1rem; }
}

/* ---------- Hero ---------- */
.hero {
  position: relative; min-height: min(100vh, 980px); min-height: min(100svh, 980px);
  display: flex; align-items: center; padding: calc(var(--nav-h) + 2rem) 0 5rem;
  overflow: hidden; isolation: isolate;
}
#bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.hero-glow {
  position: absolute; z-index: -2; width: 60vmax; height: 60vmax; left: -15vmax; top: -20vmax;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 28%, transparent), transparent);
  filter: blur(20px);
}
.hero::after {
  content: ""; position: absolute; z-index: -1; inset: auto 0 0 0; height: 160px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
}

.hero-grid { display: grid; gap: 3rem; align-items: center; grid-template-columns: 1fr; }
@media (min-width: 960px) { .hero-grid { grid-template-columns: 1.15fr .85fr; } }

.eyebrow {
  display: inline-flex; align-items: center; gap: .55rem;
  font-size: .8rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent-2); margin-bottom: 1.1rem;
}
:root[data-theme="light"] .eyebrow { color: var(--accent); }
.hero .eyebrow {
  padding: .4rem .85rem; border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  letter-spacing: .08em; text-transform: none; font-size: .85rem; color: var(--muted);
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #3ddc97; box-shadow: 0 0 0 0 rgba(61, 220, 151, .6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(61, 220, 151, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 151, 0); } }

.hero h1 { font-size: clamp(2.6rem, 8vw, 5.4rem); font-weight: 700; line-height: 1.02; }
.hero h1 span { display: block; }
.hero-hi { color: var(--muted); font-weight: 500; font-size: .45em; margin-bottom: .35em; letter-spacing: 0; }

.hero-role {
  margin-top: 1.4rem; font-family: var(--font-head); font-weight: 500;
  font-size: clamp(1.25rem, 3.2vw, 1.8rem); min-height: 1.4em;
}
.caret { display: inline-block; width: 3px; height: 1.1em; margin-left: 4px; vertical-align: -.15em; background: var(--accent-2); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.hero-lead { margin-top: 1.2rem; max-width: 34em; color: var(--muted); font-size: 1.15rem; }
.hero-cta { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 2rem; }

.socials { display: flex; gap: .6rem; margin-top: 2rem; }
.socials.center { justify-content: center; }
.socials a {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  transition: color .2s, border-color .2s, transform .2s;
}
.socials a:hover { color: var(--text); border-color: var(--accent); transform: translateY(-3px); }
.socials svg { width: 20px; height: 20px; }

.scroll-hint {
  position: absolute; bottom: 1.6rem; left: 50%; translate: -50% 0; z-index: 2;
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface);
  animation: bob 2.2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(6px); } }

/* code window */
.hero-visual { display: none; perspective: 900px; }
@media (min-width: 960px) { .hero-visual { display: block; } }
.code-window {
  border-radius: var(--radius); border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); box-shadow: var(--shadow);
  transition: transform .15s ease-out; will-change: transform;
  animation: floaty 7s ease-in-out infinite;
}
@keyframes floaty { 50% { translate: 0 -10px; } }
.code-bar { display: flex; align-items: center; gap: 7px; padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
.code-bar i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.code-bar i:nth-child(2) { background: #febc2e; }
.code-bar i:nth-child(3) { background: #28c840; }
.code-bar span { margin-left: .6rem; font-size: .8rem; color: var(--muted); font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; }
.code-window pre { margin: 0; padding: 1.2rem 1.4rem 1.5rem; overflow: hidden; }
.code-window code { font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace; font-size: .92rem; line-height: 1.75; color: var(--text); }
.code-window .c { color: #6b7490; font-style: italic; }
.code-window .k { color: #c084fc; }
.code-window .f { color: #60a5fa; }
.code-window .t { color: #2dd4bf; }
.code-window .n { color: #fbbf24; }
:root[data-theme="light"] .code-window .k { color: #8b3fd6; }
:root[data-theme="light"] .code-window .f { color: #1d63c9; }
:root[data-theme="light"] .code-window .t { color: #0b8a7d; }
:root[data-theme="light"] .code-window .n { color: #b57400; }

/* ---------- Sections ---------- */
.section { padding: clamp(4.5rem, 10vw, 8rem) 0; position: relative; }
.section.alt { background: var(--bg-alt); }
.section-head { max-width: 46rem; margin-bottom: 2.6rem; }
.section h2 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; }
.section-sub { margin-top: 1rem; color: var(--muted); font-size: 1.1rem; }
.section-head .eyebrow, .about-copy .eyebrow { margin-bottom: .8rem; }

/* ---------- About ---------- */
.about-grid { display: grid; gap: 3rem; align-items: center; grid-template-columns: 1fr; }
@media (min-width: 880px) { .about-grid { grid-template-columns: .8fr 1.2fr; gap: 5rem; } }

.about-photo { max-width: 380px; margin-inline: auto; width: 100%; perspective: 900px; }
.photo-frame {
  position: relative; border-radius: 28px; padding: 6px; background: var(--grad);
  box-shadow: var(--shadow); transition: transform .15s ease-out; will-change: transform;
}
.photo-frame::before {
  content: ""; position: absolute; inset: 18px -18px -18px 18px; z-index: -1;
  border-radius: 28px; border: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
}
.photo-frame img { border-radius: 23px; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; }

.lead { margin-top: 1.2rem; font-size: 1.2rem; color: var(--muted); max-width: 36em; }

.edu { margin-top: 2.2rem; display: grid; gap: 1rem; position: relative; padding-left: 1.7rem; }
.edu::before { content: ""; position: absolute; left: 6px; top: 12px; bottom: 12px; width: 2px; background: linear-gradient(var(--accent), var(--accent-2)); opacity: .5; }
.edu-item { position: relative; padding: 1.1rem 1.25rem; }
.edu-dot { position: absolute; left: -1.7rem; top: 1.45rem; width: 14px; height: 14px; border-radius: 50%; background: var(--grad); box-shadow: 0 0 0 4px var(--bg); }
.edu-item h3 { font-size: 1.1rem; margin-bottom: .3rem; }
.edu-item p { color: var(--muted); font-size: .98rem; }
.edu-item a { text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent); text-underline-offset: 3px; }
.edu-item a:hover { color: var(--accent-2); }

/* spotlight surface (cursor-follow glow) */
.spot {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
.spot::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%);
}
.spot:hover::before { opacity: 1; }
.edu-item.spot { overflow: visible; }

/* ---------- Skills ---------- */
.skills-grid { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .skills-grid { grid-template-columns: repeat(3, 1fr); } }
.skill-card { padding: 1.8rem; display: flex; flex-direction: column; gap: 1rem; }
.skill-icon {
  display: grid; place-items: center; width: 50px; height: 50px; border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-2);
}
:root[data-theme="light"] .skill-icon { color: var(--accent); }
.skill-icon svg { width: 24px; height: 24px; }
.skill-card h3 { font-size: 1.3rem; }
.skill-card p { color: var(--muted); font-size: .98rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chips li {
  padding: .32rem .8rem; border-radius: 999px; font-size: .86rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border);
  transition: transform .2s, border-color .2s;
}
.chips li:hover { transform: translateY(-2px); border-color: var(--accent); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; margin-bottom: 2rem; }
.chip-btn {
  padding: .5rem 1.05rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 500; font-size: .92rem; color: var(--muted);
  transition: all .2s;
}
.chip-btn:hover { color: var(--text); border-color: var(--accent); }
.chip-btn.is-active { background: var(--grad); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.filter-count { margin-left: auto; color: var(--muted); font-size: .9rem; }

/* ---------- Project cards ---------- */
.cards { display: grid; gap: 1.4rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.card { display: flex; flex-direction: column; transition: transform .3s, border-color .3s, box-shadow .3s; }
.card:hover { transform: translateY(-6px); border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: var(--shadow); }
.card[hidden] { display: none; }
.card.pop { animation: pop .45s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } }

.card-media { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; }
.card-media img, .card-media video { width: 100%; height: 100%; object-fit: cover; transition: transform .6s; }
.card:hover .card-media img, .card:hover .card-media video { transform: scale(1.05); }
.card-media::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top, color-mix(in srgb, var(--surface) 55%, transparent), transparent 40%);
}

.card-body { position: relative; display: flex; flex-direction: column; gap: .8rem; padding: 1.35rem 1.4rem 1.5rem; flex: 1; }
.card h3 { font-size: 1.35rem; }
.tags { display: flex; flex-wrap: wrap; gap: .4rem; }
.tags li {
  font-size: .75rem; font-weight: 600; letter-spacing: .02em; padding: .2rem .6rem; border-radius: 6px;
  color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 12%, transparent);
}
:root[data-theme="light"] .tags li { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.desc { color: var(--muted); font-size: .98rem; }
.card .desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .contrib { display: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: auto; padding-top: .6rem; }

/* ---------- Modal ---------- */
.modal {
  width: min(760px, calc(100% - 1.5rem)); max-height: calc(100dvh - 2rem);
  padding: 0; border: 1px solid var(--border); border-radius: 22px; overflow: auto;
  background: var(--surface); color: var(--text); box-shadow: 0 40px 90px -20px rgba(0, 0, 0, .7);
}
.modal[open] { animation: modal-in .3s cubic-bezier(.2, .8, .2, 1); }
.modal::backdrop { background: rgba(4, 5, 10, .7); backdrop-filter: blur(6px); animation: fade .3s; }
@keyframes modal-in { from { opacity: 0; transform: translateY(20px) scale(.97); } }
@keyframes fade { from { opacity: 0; } }
.modal-close { position: absolute; top: .8rem; right: .8rem; z-index: 3; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px); }
.modal-media { aspect-ratio: 16 / 9; background: var(--surface-2); }
.modal-media img, .modal-media video { width: 100%; height: 100%; object-fit: cover; }
.modal-body { padding: 1.6rem 1.8rem 1.9rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-body h3 { font-size: 1.8rem; }
.modal-body .desc { font-size: 1.05rem; }
.modal-body h4 { font-size: 1rem; margin-bottom: .6rem; }
.modal-body .contrib ul { display: grid; gap: .4rem; }
.modal-body .contrib li { position: relative; padding-left: 1.4rem; color: var(--muted); }
.modal-body .contrib li::before {
  content: ""; position: absolute; left: 0; top: .6em; width: 8px; height: 8px; border-radius: 3px; background: var(--grad);
}
.modal-body .card-actions { padding-top: .4rem; }

/* ---------- Contact ---------- */
.contact { padding-top: 2rem; }
.contact-card {
  position: relative; text-align: center; padding: clamp(2.5rem, 7vw, 5rem) 1.5rem;
  border-radius: 32px; border: 1px solid var(--border); overflow: hidden; isolation: isolate;
  background:
    radial-gradient(60% 90% at 15% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent),
    radial-gradient(60% 90% at 90% 100%, color-mix(in srgb, var(--accent-2) 18%, transparent), transparent),
    var(--surface);
}
.contact-card .section-sub { margin-inline: auto; max-width: 30em; }
.contact-card .hero-cta { justify-content: center; }
.contact-card .socials { justify-content: center; }

.footer { border-top: 1px solid var(--border); padding: 1.6rem 0; color: var(--muted); font-size: .92rem; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.footer a { display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; }
.footer a:hover { color: var(--text); }

.toast {
  position: fixed; left: 50%; bottom: 1.6rem; z-index: 300; translate: -50% 140%;
  padding: .7rem 1.2rem; border-radius: 999px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: .92rem; transition: translate .3s;
}
.toast.show { translate: -50% 0; }

/* ---------- Scroll reveal ---------- */
.js .reveal { opacity: 0; translate: 0 28px; transition: opacity .7s ease, translate .7s cubic-bezier(.2, .8, .2, 1); }
.js .reveal.in { opacity: 1; translate: 0 0; }
/* cards: staggered reveal, but hover effects stay instant */
.js .cards .card.reveal {
  transition: opacity .7s ease, translate .7s cubic-bezier(.2, .8, .2, 1), transform .3s, border-color .3s, box-shadow .3s;
  transition-delay: calc(var(--i, 0) * 70ms), calc(var(--i, 0) * 70ms), 0s, 0s, 0s;
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
  .js .reveal { opacity: 1; translate: none; }
  .caret { animation: none; }
}
