/* =========================================================
   Leandro Sanz — personal site
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
  --bg: #fafaf7;
  --bg-elevated: #ffffff;
  --text: #171717;
  --text-muted: #5f5f5f;
  --text-subtle: #8a8a87;
  --border: #ebe8e1;
  --border-strong: #d9d5cc;
  --accent: #0f3460;
  --accent-hover: #1e4d8b;
  --accent-muted: rgba(15, 52, 96, 0.08);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Newsreader', 'Charter', 'Iowan Old Style', Georgia, 'Times New Roman', serif;

  --container: 960px;
  --container-narrow: 720px;

  --radius: 6px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(15, 20, 30, 0.04);
  --shadow-md: 0 4px 20px rgba(15, 20, 30, 0.06);

  --transition: 180ms cubic-bezier(0.2, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f0f10;
  --bg-elevated: #17171a;
  --text: #e8e8e6;
  --text-muted: #a0a09d;
  --text-subtle: #6e6e6b;
  --border: #2a2a2c;
  --border-strong: #3a3a3d;
  --accent: #8fb3ff;
  --accent-hover: #b8ceff;
  --accent-muted: rgba(143, 179, 255, 0.14);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

img { max-width: 100%; height: auto; display: block; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 0.5em;
  color: var(--text);
}

h1 { font-size: clamp(2rem, 4vw, 2.8rem); font-weight: 500; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.5rem, 2.5vw, 1.875rem); margin-top: 2em; }
h3 { font-size: 1.2rem; font-weight: 600; font-family: var(--font-sans); letter-spacing: -0.005em; }

p { margin: 0 0 1em; }
p, li { color: var(--text); }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
a:hover { color: var(--accent-hover); border-bottom-color: currentColor; }

strong { font-weight: 600; color: var(--text); }

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }

/* ---------- Layout ---------- */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.container--narrow { max-width: var(--container-narrow); }

main {
  padding: 3rem 0 6rem;
}

section { margin-bottom: 3.5rem; }

/* ---------- Header / Nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition), background var(--transition);
}
.site-header.is-scrolled {
  border-bottom-color: var(--border);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  height: 64px;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  padding: 0;
  margin: 0;
  align-items: center;
}

.nav-links a {
  color: var(--text-muted);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.93rem;
  font-weight: 450;
  border: none;
  transition: color var(--transition), background var(--transition);
}
.nav-links a:hover { color: var(--text); background: var(--accent-muted); border: none; }
.nav-links a.active { color: var(--accent); }

.theme-toggle {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}
.theme-toggle:hover { color: var(--text); background: var(--accent-muted); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Mobile nav */
.nav-toggle { display: none; }
@media (max-width: 640px) {
  .nav-links {
    position: absolute;
    top: 64px;
    right: 1.5rem;
    left: 1.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity var(--transition), transform var(--transition);
  }
  .nav-links.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
  .nav-toggle {
    display: inline-flex;
    width: 36px; height: 36px;
    align-items: center; justify-content: center;
    border-radius: var(--radius);
    color: var(--text-muted);
  }
  .nav-toggle:hover { color: var(--text); background: var(--accent-muted); }
}

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 3rem;
  align-items: center;
  padding: 3rem 0 1rem;
}

.hero-text h1 {
  margin-bottom: 0.4em;
}

.hero-title {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-family: var(--font-sans);
}

.hero-bio p {
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.7;
}

.hero-photo {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--bg-elevated);
}
.hero-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
}

@media (max-width: 780px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; }
  .hero-photo { max-width: 260px; aspect-ratio: 1 / 1; margin: 0 auto; }
}

/* ---------- Contact row ---------- */
.contact {
  display: grid;
  grid-template-columns: max-content max-content;
  justify-content: start;
  column-gap: 2.25rem;
  row-gap: 0.55rem;
  margin-top: 1.5rem;
  font-size: 0.93rem;
}
@media (max-width: 520px) {
  .contact { grid-template-columns: 1fr; column-gap: 0; }
}
.contact-item {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.contact-item .icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-subtle);
  flex-shrink: 0;
}
.contact-item .icon svg { width: 100%; height: 100%; }
.contact-item a {
  color: var(--text);
  border-bottom: 1px solid var(--border-strong);
  line-height: 1.2;
}
.contact-item a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Section headings ---------- */
.section-label {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 1.6rem;
  font-family: var(--font-serif);
  font-weight: 500;
  margin: 0 0 1.75rem;
  letter-spacing: -0.01em;
}

/* ---------- Research cards ---------- */
.paper-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

.paper { max-width: 760px; }

.paper-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  margin: 0 0 0.3rem;
  letter-spacing: -0.005em;
}
.paper-title a {
  color: var(--text);
  border-bottom: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.paper-title a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.paper-meta {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}
.paper-meta .coauthors { font-style: italic; }
.paper-meta .journal { color: var(--text); }

.paper-note {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
  margin: 0 0 0.9rem;
}

.paper-abstract {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-muted);
  margin: 0;
}
.paper-abstract strong { color: var(--text); font-weight: 600; }

.paper-abstract-wrap {
  overflow: hidden;
  margin-top: 0.9rem;
  padding: 0.9rem 1rem;
  border-left: 2px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg-elevated) 60%, transparent);
  border-radius: 0 var(--radius) var(--radius) 0;
  animation: fadeSlide 220ms ease;
}
.paper-abstract-wrap[hidden] { display: none; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.paper-abstract-toggle {
  cursor: pointer;
  font-family: inherit;
}
.paper-abstract-toggle .chev {
  width: 10px;
  height: 10px;
  transition: transform var(--transition);
}
.paper-abstract-toggle[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-muted);
}
.paper-abstract-toggle[aria-expanded="true"] .chev {
  transform: rotate(180deg);
}

.paper-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}
.paper-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: transparent;
  font-weight: 500;
}
.paper-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-muted);
}
.paper-link svg { width: 12px; height: 12px; }

.paper-media {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}
.paper-media strong { color: var(--text); font-weight: 600; margin-right: 0.25rem; }

/* Figures below the card — small thumbnails, single row */
.paper-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.paper-figures figure {
  flex: 0 0 auto;
  width: 130px;
  margin: 0;
}
.paper-figures img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.25rem;
}
[data-theme="dark"] .paper-figures img {
  background: #f7f7f4;
  filter: brightness(0.97);
}
.paper-figures figcaption {
  font-size: 0.7rem;
  color: var(--text-subtle);
  margin-top: 0.3rem;
  text-align: center;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
  line-height: 1.25;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0 3rem;
  margin-top: 4rem;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-subtle);
}
.footer-inner a { color: var(--text-muted); border: none; }
.footer-inner a:hover { color: var(--accent); }

/* ---------- Prose (for static content pages) ---------- */
.prose {
  font-size: 1.02rem;
  line-height: 1.75;
}
.prose p { color: var(--text); }
.prose h2 { margin-top: 2.5rem; }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li { margin-bottom: 0.3rem; }

/* ---------- Utility ---------- */
.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 3rem 0;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Mobile polish ---------- */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .container { padding: 0 1.25rem; }
  main { padding: 2rem 0 4rem; }
  section { margin-bottom: 2.5rem; }

  h1 { font-size: 1.85rem; }
  h2 { font-size: 1.35rem; }
  .section-title { font-size: 1.4rem; margin-bottom: 1.25rem; }

  /* Long URLs / titles should never overflow */
  .paper-title, .paper-meta, .paper-note, .paper-abstract { overflow-wrap: anywhere; }

  /* Larger tap targets for pill buttons */
  .paper-link {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
  }
  .paper-links { gap: 0.5rem; }

  /* Figures: 2 per row on phones */
  .paper-figures {
    gap: 0.4rem;
  }
  .paper-figures figure {
    width: calc(50% - 0.2rem);
    min-width: 0;
  }

  /* Tighter abstract block */
  .paper-abstract-wrap { padding: 0.75rem 0.85rem; }

  /* Footer */
  .site-footer { padding: 1.5rem 0 2.5rem; margin-top: 3rem; }
  .footer-inner { gap: 0.4rem; }

  /* Ensure no horizontal scroll from full-width images */
  img, video, iframe { max-width: 100%; }
}

/* Disable zoom-prevention on iOS form fields not needed here, but keep meta viewport */
html, body { overflow-x: hidden; }

/* Selection */
::selection { background: var(--accent-muted); color: var(--text); }

/* Focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
