/*
 * Brutalist Academic Portfolio
 * Inspired by utrecht.jp - Minimal, purposeful, honest
 */

/* ========== CSS Custom Properties ========== */
:root {
  /* Color Palette - Near monochrome with red accents */
  --color-bg: #fafafa;
  --color-text: #0a0a0a;
  --color-text-secondary: #4a4a4a;
  --color-border: #2e2e2e;
  --color-accent: #da532c; /* Utrecht red */
  --color-accent-light: rgba(218, 83, 44, 0.1);
  --color-link: #0a0a0a;
  --color-link-hover: #da532c;

  /* Typography Scale */
  --font-size-base: 16px;
  --font-size-sm: 14px;
  --font-size-md: 18px;
  --font-size-lg: 22px;
  --font-size-xl: clamp(28px, 4vw, 48px);
  --font-size-xxl: clamp(36px, 6vw, 64px);

  /* Spacing System */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 2rem;
  --space-lg: 3rem;
  --space-xl: 4rem;
  --space-xxl: 6rem;

  /* Layout */
  --max-width: 1200px;
  --content-width: 900px;
  --border-width: 2px;

  /* Typography */
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --line-height-tight: 1.2;
  --line-height-normal: 1.6;
  --line-height-relaxed: 1.8;
}

/* ========== Reset & Base ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: var(--line-height-normal);
  overflow-x: hidden;
}

/* ========== Typography ========== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-sm);
  letter-spacing: -0.02em;
}

h1 {
  font-size: var(--font-size-xxl);
  margin-bottom: var(--space-md);
}

h2 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-md);
  border-left: var(--border-width) solid var(--color-accent);
  padding-left: var(--space-sm);
}

h3 {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-sm);
}

p {
  margin-bottom: var(--space-sm);
  max-width: 70ch;
}

a {
  color: var(--color-link);
  text-decoration: none;
  border-bottom: 1px solid var(--color-border);
  transition: all 0.2s ease;
}

a:hover,
a:focus {
  color: var(--color-link-hover);
  border-bottom-color: var(--color-link-hover);
  outline: none;
}

a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

strong, b {
  font-weight: 700;
}

em, i {
  font-style: italic;
}

/* ========== Layout Structure ========== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-md);
}

.content {
  max-width: var(--content-width);
  margin: 0 auto;
}

/* ========== Navigation ========== */
.nav {
  position: sticky;
  top: 0;
  background-color: var(--color-bg);
  border-bottom: var(--border-width) solid var(--color-border);
  padding: var(--space-sm) 0;
  margin-bottom: var(--space-xl);
  z-index: 100;
  backdrop-filter: blur(8px);
  background-color: rgba(250, 250, 250, 0.95);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  justify-content: flex-start;
  gap: var(--space-lg);
  align-items: center;
}

.nav a {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: none;
  padding: var(--space-xs) 0;
  position: relative;
}

.nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: var(--border-width);
  background-color: var(--color-accent);
  transition: width 0.2s ease;
}

.nav a:hover::after,
.nav a.active::after {
  width: 100%;
}

/* ========== Header Section ========== */
.header-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xl);
  margin-bottom: var(--space-xxl);
  align-items: start;
}

.header-info h1 {
  margin-bottom: var(--space-sm);
}

.contact-info {
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-md);
}

.contact-info p {
  margin-bottom: var(--space-xs);
}

.social-links {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-top: var(--space-sm);
}

.social-links a {
  border-bottom: none;
  display: inline-block;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.social-links a:hover {
  transform: translateY(-2px);
  opacity: 0.7;
}

.social-links img {
  display: block;
  width: 28px;
  height: 28px;
}

.header-photo {
  position: relative;
}

.header-photo img {
  width: 100%;
  height: auto;
  display: block;
  border: var(--border-width) solid var(--color-border);
}

.header-photo figcaption {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
  font-family: var(--font-mono);
}

/* ========== Section Headers ========== */
.section-header {
  font-family: var(--font-mono);
  font-size: var(--font-size-lg);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: var(--border-width) solid var(--color-border);
  font-weight: 700;
}

/* ========== Bio Section ========== */
.bio-section {
  margin-bottom: var(--space-xxl);
  padding: var(--space-lg);
  border-left: 4px solid var(--color-accent);
  background-color: var(--color-accent-light);
}

.bio-section p {
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
  max-width: 100%;
}

/* ========== News Section ========== */
.news-section {
  margin-bottom: var(--space-xxl);
}

.news-list {
  list-style: none;
}

.news-list li {
  font-size: var(--font-size-md);
  margin-bottom: var(--space-sm);
  padding-left: var(--space-md);
  position: relative;
}

.news-list li::before {
  content: '→';
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
}

/* ========== Papers Section ========== */
.paper-item {
  margin-bottom: var(--space-xxl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid rgba(46, 46, 46, 0.2);
}

.paper-item:last-child {
  border-bottom: none;
}

.paper-title {
  font-size: var(--font-size-xl);
  font-family: var(--font-mono);
  font-weight: 700;
  margin-bottom: var(--space-sm);
  line-height: var(--line-height-tight);
  border-left: none;
  padding-left: 0;
}

.paper-authors {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-md);
  font-style: italic;
}

.paper-media {
  margin: var(--space-md) 0;
  border: var(--border-width) solid var(--color-border);
  overflow: hidden;
  max-width: 70ch; /* Match paragraph width */
}

.paper-media img,
.paper-media video {
  width: 100%;
  height: auto;
  display: block;
}

.paper-abstract {
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-md);
  text-align: justify;
}

.paper-links {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  align-items: center;
}

.paper-links a {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: var(--border-width) solid var(--color-border);
  padding: var(--space-xs) var(--space-sm);
  border-radius: 0;
  transition: all 0.2s ease;
}

.paper-links a:hover {
  background-color: var(--color-accent);
  color: var(--color-bg);
  border-bottom-color: var(--color-accent);
  border-color: var(--color-accent);
}

/* ========== Potpourri Section ========== */
.potpourri-item {
  margin-bottom: var(--space-xxl);
  padding-bottom: var(--space-xl);
}

.potpourri-title {
  font-size: var(--font-size-lg);
  font-family: var(--font-mono);
  margin-bottom: var(--space-md);
}

.potpourri-media {
  margin: var(--space-md) 0;
  border: var(--border-width) solid var(--color-border);
  max-width: 70ch; /* Match paragraph width */
}

.potpourri-media img,
.potpourri-media video {
  width: 100%;
  height: auto;
  display: block;
}

.potpourri-content {
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
}

.potpourri-date {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  margin-top: var(--space-md);
}

.potpourri-separator {
  width: 45%;
  height: 1px;
  background-color: var(--color-border);
  margin: var(--space-xl) auto;
  border: none;
}

/* ========== Responsive Design ========== */
@media (max-width: 768px) {
  :root {
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
    --space-xxl: 4rem;
  }

  .container {
    padding: var(--space-sm);
  }

  .nav-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .header-section {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .header-photo {
    order: -1;
  }

  .bio-section {
    padding: var(--space-md);
  }

  .paper-abstract {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .nav a {
    font-size: 12px;
  }

  .contact-info {
    font-size: var(--font-size-base);
  }
}

/* ========== Accessibility ========== */
/* Note: Animations section below has comprehensive reduced-motion support */

/* ========== Print Styles ========== */
@media print {
  .nav {
    position: static;
    border-bottom: 1px solid var(--color-border);
  }

  a {
    text-decoration: underline;
    border-bottom: none;
  }

  .paper-media,
  .potpourri-media {
    border: 1px solid var(--color-border);
  }
}

/* ========== Utilities ========== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.text-center {
  text-align: center;
}

.text-secondary {
  color: var(--color-text-secondary);
}

.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

/* ========== Retro-Futuristic Animations ========== */
/* Nature + Computation: Organic growth meets digital precision */

/* 1. Fibonacci Spiral Fade-in (Nature's mathematical pattern) */
@keyframes spiralFadeIn {
  0% {
    opacity: 0;
    transform: scale(0.95) rotate(-1deg);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.98) rotate(0deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* 2. Binary Pulse (Computation heartbeat) */
@keyframes binaryPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* 3. Cellular Automata Border Growth */
@keyframes borderGrowth {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

/* 4. Quantum Flicker (Probabilistic states) */
@keyframes quantumFlicker {
  0%, 100% {
    box-shadow: 0 0 0 rgba(218, 83, 44, 0);
  }
  50% {
    box-shadow: 0 0 20px rgba(218, 83, 44, 0.1);
  }
}

/* 5. Fractal Zoom (Self-similarity across scales) */
@keyframes fractalZoom {
  0% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.03) rotate(0.3deg);
  }
  50% {
    transform: scale(1.05) rotate(0deg);
  }
  75% {
    transform: scale(1.03) rotate(-0.3deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

/* 6. Neural Activation Wave */
@keyframes neuralWave {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* 7. Pixel Glitch (Retro computing artifacts) */
@keyframes pixelGlitch {
  0%, 90%, 100% {
    transform: translate(0);
  }
  92% {
    transform: translate(2px, 0);
  }
  94% {
    transform: translate(-2px, 0);
  }
  96% {
    transform: translate(1px, 0);
  }
  98% {
    transform: translate(-1px, 0);
  }
}

/* Apply animations to elements */

/* Papers fade in with spiral pattern - DISABLED (too tacky) */
.paper-item {
  /* animation: spiralFadeIn 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; */
  /* animation-delay: calc(var(--item-index, 0) * 0.1s); */
}

/* Section headers get binary pulse */
.section-header {
  animation: binaryPulse 3s ease-in-out infinite;
}

/* Nav underlines grow like cellular automata */
.nav a.active::after {
  animation: borderGrowth 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
  width: 100%;
}

/* Make hover more visible too */
.nav a:hover::after {
  animation: borderGrowth 0.4s ease-out forwards;
}

/* Paper media gets subtle quantum flicker on hover */
.paper-media:hover {
  animation: quantumFlicker 2s ease-in-out infinite;
}

/* Bio section - animation disabled (too disorienting) */
.bio-section {
  /* animation: fractalZoom 6s ease-in-out infinite; */
  /* transform-origin: center center; */
}

/* Links get neural activation on hover */
a:hover {
  animation: neuralWave 1.5s ease infinite;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(218, 83, 44, 0.05) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
}

/* Occasional pixel glitch on h1 (very subtle, retro) */
h1:hover {
  animation: pixelGlitch 0.3s ease-in-out;
}

/* Photo gets organic reveal - DISABLED (too tacky) */
.header-photo img {
  /* animation: spiralFadeIn 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; */
}

/* News items cascade in - DISABLED (too tacky) */
.news-list li {
  /* animation: spiralFadeIn 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; */
  /* animation-delay: calc(var(--item-index, 0) * 0.15s); */
}

/* Paper links shimmer subtly */
.paper-links a {
  position: relative;
  overflow: hidden;
}

.paper-links a::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(218, 83, 44, 0.2),
    transparent
  );
  transition: left 0.5s ease;
}

.paper-links a:hover::before {
  left: 100%;
}

/* ========== Floating Background Particles ========== */
/* Minimalist geometric shapes drifting like generative samples exploring latent space */

.floating-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

/* Cellular Automata Grid Background */
.floating-background::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 49px,
      rgba(218, 83, 44, 0.05) 49px,
      rgba(218, 83, 44, 0.05) 50px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 49px,
      rgba(218, 83, 44, 0.05) 49px,
      rgba(218, 83, 44, 0.05) 50px
    );
  animation: gridFadeIn 2s ease-in forwards, gridShift 20s linear infinite 2s;
}

/* Grid slowly shifts to create cellular automata effect */
@keyframes gridShift {
  0% {
    background-position: 0 0, 0 0;
  }
  100% {
    background-position: 50px 50px, 50px 50px;
  }
}

/* Grid fades in gradually */
@keyframes gridFadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.float-particle {
  position: absolute;
  opacity: 0.15;
  border: 2px solid var(--color-accent);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Collision effect - particles pulse when they cross */
.float-particle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(218, 83, 44, 0.3) 0%, transparent 70%);
  transform: translate(-50%, -50%);
  animation: collisionPulse 8s ease-in-out infinite;
  pointer-events: none;
}

/* Different collision timings for each particle */
.particle-1::after { animation-delay: 0s; }
.particle-2::after { animation-delay: 2.5s; }
.particle-3::after { animation-delay: 5s; }
.particle-4::after { animation-delay: 7.5s; }
.particle-5::after { animation-delay: 1.5s; }
.particle-6::after { animation-delay: 4s; }

/* Collision pulse animation */
@keyframes collisionPulse {
  0%, 95%, 100% {
    width: 0;
    height: 0;
    opacity: 0;
  }
  96% {
    width: 150px;
    height: 150px;
    opacity: 1;
  }
  99% {
    width: 200px;
    height: 200px;
    opacity: 0;
  }
}

/* Particle 1: Large square - like a pixel in computational space */
.particle-1 {
  width: 120px;
  height: 120px;
  top: 10%;
  left: -120px;
  animation: floatRight 40s linear infinite;
  animation-delay: 0s;
}

/* Particle 2: Small circle - quantum state */
.particle-2 {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  top: 25%;
  right: -60px;
  animation: floatLeft 30s linear infinite;
  animation-delay: 3s;
}

/* Particle 3: Tall rectangle - data column */
.particle-3 {
  width: 40px;
  height: 140px;
  top: 50%;
  left: -40px;
  animation: floatDiagonal 45s linear infinite;
  animation-delay: 6s;
}

/* Particle 4: Medium square rotated - network node */
.particle-4 {
  width: 80px;
  height: 80px;
  top: 70%;
  right: -80px;
  transform: rotate(45deg);
  animation: floatLeftRotate 35s linear infinite;
  animation-delay: 9s;
}

/* Particle 5: Small horizontal line - gradient vector */
.particle-5 {
  width: 100px;
  height: 2px;
  background-color: var(--color-accent);
  border: none;
  top: 40%;
  left: -100px;
  animation: floatRight 32s linear infinite;
  animation-delay: 12s;
  opacity: 0.25;
}

/* Particle 6: Medium circle - probability distribution */
.particle-6 {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  top: 80%;
  left: -90px;
  animation: floatDiagonal 42s linear infinite;
  animation-delay: 15s;
}

/* Animation: Float from left to right */
@keyframes floatRight {
  0% {
    transform: translateX(0) translateY(0);
  }
  100% {
    transform: translateX(calc(100vw + 200px)) translateY(-30px);
  }
}

/* Animation: Float from right to left */
@keyframes floatLeft {
  0% {
    transform: translateX(0) translateY(0);
  }
  100% {
    transform: translateX(calc(-100vw - 200px)) translateY(40px);
  }
}

/* Animation: Float diagonally */
@keyframes floatDiagonal {
  0% {
    transform: translateX(0) translateY(0) rotate(0deg);
  }
  50% {
    transform: translateX(50vw) translateY(-100px) rotate(180deg);
  }
  100% {
    transform: translateX(calc(100vw + 200px)) translateY(50px) rotate(360deg);
  }
}

/* Animation: Float left with rotation */
@keyframes floatLeftRotate {
  0% {
    transform: translateX(0) translateY(0) rotate(45deg);
  }
  100% {
    transform: translateX(calc(-100vw - 200px)) translateY(-60px) rotate(405deg);
  }
}

/* Respect user preferences - disable all animations if requested */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .floating-background,
  .floating-background::before {
    display: none;
  }
}
