/* Minimalist but intriguing visual style */
:root {
  --bg: #0a0b0e;
  --fg: #e9ecf1;
  --muted: #a3aab8;
  --accent: #5ee1ff;
  --accent-2: #b388ff;
  --card: #11131a;
  --border: #1c1f2a;
  /* Header/nav */
  --header-bg: rgba(10,11,14,0.85);
  --header-border: rgba(255,255,255,0.08);
  --nav-hover-bg: rgba(255,255,255,0.06);

  /* Spacing scale */
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 28px;
  --space-6: 40px;

  /* Type scale */
  --fs-0: 14px;
  --fs-1: 16px;
  --fs-2: 18px;
  --fs-3: 22px;
  --fs-4: 28px;
  --fs-5: 36px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html {
  background:
    radial-gradient(1200px 800px at 85% -10%, rgba(94,225,255,0.08), transparent),
    radial-gradient(900px 600px at 10% 110%, rgba(179,136,255,0.06), transparent),
    var(--bg);
  background-attachment: fixed, fixed, fixed;
  background-repeat: no-repeat;
  background-color: var(--bg);
}
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--fg);
  background: transparent;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

/* Global type rhythm */
main { font-size: var(--fs-1); line-height: 1.6; }
p { margin: var(--space-2) 0; }
h1, h2, h3 { line-height: 1.25; margin: var(--space-2) 0 var(--space-2); }
h1 { font-size: var(--fs-5); }
h2 { font-size: var(--fs-4); }
h3 { font-size: var(--fs-3); }

a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--accent); }

.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 22px; backdrop-filter: blur(10px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.5px; }
.brand svg { width: 22px; height: 22px; fill: var(--fg); opacity: 0.95; }
/* Center nav and use gap instead of link margins */
.site-header nav { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: nowrap; }
nav a { display: inline-flex; align-items: center; gap: 8px; margin-left: 0; color: var(--fg); opacity: 0.85; padding: 8px 10px; border-radius: 10px; transition: background 140ms ease, opacity 140ms ease, border-color 140ms ease; border: 1px solid transparent; white-space: nowrap; }
nav a:hover { opacity: 1; background: var(--nav-hover-bg); }
nav a.active { color: var(--accent); opacity: 1; background: rgba(94,225,255,0.10); border-color: rgba(94,225,255,0.25); }
nav a svg { width: 16px; height: 16px; fill: currentColor; opacity: 0.9; }

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

/* Animated link underline */
a { position: relative; }
a::after { content: ""; position: absolute; left: 0; bottom: 0; width: 0; height: 2px; background: currentColor; transition: width 120ms ease; opacity: 0.6; }
a:hover::after { width: 100%; }
nav a::after { display: none; }
/* Do not show underline for full-card anchors (project and writing cards) */
a.card::after { display: none !important; }
/* Clip animated underline within rounded containers */
.card a, .item a, .list a { border-radius: 8px; overflow: hidden; display: inline-block; padding-bottom: 2px; }

.container { max-width: 980px; width: 100%; margin: 0 auto; padding: 32px 20px 80px; }
main.container { flex: 1; }
.section-title { font-size: var(--fs-4); letter-spacing: 0.3px; margin: var(--space-2) 0 var(--space-1); }
.subtle { color: var(--muted); }

/* Section overline */
.overline { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: var(--fs-0); }
.divider { height: 1px; background: linear-gradient(90deg, rgba(255,255,255,0.08), rgba(255,255,255,0)); border: 0; margin: var(--space-3) 0; }

.footer { border-top: 1px solid var(--border); padding: 20px; color: var(--muted); text-align: center; margin-top: auto; }

/* Summary banner */
.summary-banner { 
  background: linear-gradient(90deg, rgba(94,225,255,0.15), rgba(179,136,255,0.15));
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 12px 14px;
  border-radius: 12px;
  margin: 6px 0 16px;
}

/* CV */
.cv-meta { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 10px 0 24px; }
.cv-meta .name { font-size: 22px; font-weight: 400; }
.cv-meta a { color: var(--accent); }
.cv-meta.has-avatar { grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; }
.avatar-wrap { width: 96px; height: 96px; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); position: relative; transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease; cursor: pointer; }
.avatar-wrap:hover { transform: scale(1.03); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 35%, transparent); border-color: rgba(94,225,255,0.45); }
.avatar { width: 100%; height: 100%; object-fit: cover; display: block; }
.cv-meta .subtle { font-size: 15px; }
.cv-actions { font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; margin-top: 2px; }
.cv-actions .sep { opacity: 0.6; }
.cv-actions a { color: var(--muted); border: 1px solid var(--border); padding: 4px 8px; border-radius: 8px; background: rgba(255,255,255,0.03); transition: color 120ms ease, border-color 120ms ease, background 120ms ease; }
.cv-actions a::after { display: none; }
.cv-actions a:hover { color: var(--accent); border-color: rgba(94,225,255,0.35); background: rgba(255,255,255,0.06); }
.cv-section { margin: 26px 0; }
.timeline { display: grid; gap: 14px; }
.item { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 12px; padding: 14px; transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.item:hover { transform: translateY(-2px); border-color: rgba(94,225,255,0.35); }
.item .role { font-weight: 600; }
.item .where { color: var(--muted); }
.item .when { color: var(--muted); font-variant-numeric: tabular-nums; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 8px 0; border-bottom: 1px dashed rgba(255,255,255,0.06); transition: transform 120ms ease, border-color 120ms ease; }
.list li:hover { transform: translateX(2px); border-color: rgba(94,225,255,0.25); }
.tags { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
.tags li { background: rgba(94,225,255,0.12); border: 1px solid rgba(94,225,255,0.3); color: var(--accent); padding: 6px 10px; border-radius: 999px; }

/* Generic button-style link */
.button { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); color: var(--fg); text-decoration: none; font-weight: 500; transition: background 140ms ease, color 140ms ease, border-color 140ms ease; }
.button:hover { background: var(--nav-hover-bg); color: var(--accent); border-color: rgba(94,225,255,0.35); }
/* Disable animated underline for button-like anchors */
a.button::after { display: none; }

/* Carded lists (Publications/Presentations) */
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.cards .card { padding: 14px 16px; }
.cards .card .title { font-weight: 600; margin: 0 0 6px; }
.cards .card .meta { color: var(--muted); font-size: 14px; }
/* Keep titles looking like text, not underlined on hover */
.cards .card .title a {
  color: var(--fg);
  text-decoration: none;
  display: inline-block;
  border-radius: 8px;
  overflow: hidden;
  padding-bottom: 2px;
  /* Background underline animation aligned with text start */
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 0% 2px;
  background-position: 0 100%;
  transition: color 160ms ease, background-size 160ms ease;
}
.cards .card .title a:hover { color: var(--accent); background-size: 100% 2px; }
.cards .card .title a::after { display: none !important; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 14px; padding: 16px; transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.card:hover { transform: translateY(-2px); border-color: rgba(94,225,255,0.35); }
.card .title { font-weight: 600; margin: 0 0 6px; }
.card .meta { color: var(--muted); font-size: 14px; }
.card .desc { color: var(--fg); opacity: 0.9; }
.cards { display: grid; gap: 12px; }

/* Pills/tags */
.pill { display: inline-block; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.card .tags { margin-top: 8px; }
.card .tags .pill { margin-right: 6px; margin-bottom: 6px; }

code { background: rgba(255,255,255,0.06); color: var(--fg); padding: 2px 6px; border-radius: 6px; }

@media (min-width: 700px) {
  .cv-meta { grid-template-columns: 1fr auto; align-items: center; }
}

/* Ensure CV meta stacks on small screens even when an avatar is present */
@media (max-width: 650px) {
  .cv-meta.has-avatar {
    grid-template-columns: 1fr;
    align-items: start;
    justify-items: start;
    text-align: left;
    gap: 12px;
  }
  /* Make avatar not shrink too small and align nicely */
  .cv-meta.has-avatar .avatar-wrap { margin: 0; }
}

@media (max-width: 520px) {
  .cv-meta .name { font-size: 24px; }
  .avatar-wrap { width: 72px; height: 72px; }
}

/* Skip link */
.skip-link { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip-link:focus { position: fixed; left: 16px; top: 16px; width: auto; height: auto; padding: 8px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; z-index: 999; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Theme toggle */
:root[data-theme='light'] {
  --bg: #f7f8fb;
  --fg: #0e1014;
  --muted: #4b5566;
  --card: #ffffff;
  --border: #e2e8f0;
  --header-bg: rgba(255,255,255,0.8);
  --header-border: #e2e8f0;
  --nav-hover-bg: rgba(0,0,0,0.05);
  /* Stronger, more legible accent in light mode */
  --accent: #0b63ce;
}

/* Responsive adjustments
 *
 * These rules ensure the site remains usable on smaller screens like phones and tablets
 * without altering the desktop experience. They only apply below certain widths.
 */
@media (max-width: 700px) {
  /* Wrap navigation items so they don't overflow horizontally on narrow viewports */
  .site-header nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }
  /* Reset left margin and allow items to flex so they distribute evenly */
  .site-header nav a,
  .site-header nav button {
    margin-left: 0;
    flex: 0 0 auto; /* do not stretch; keep centered sizing */
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
  }
  /* Allow header container itself to wrap if needed */
  .site-header {
    flex-wrap: wrap;
  }
  /* Reduce overall horizontal padding on small screens */
  .container {
    padding: 24px 16px 60px;
  }
  /* Decrease the minimum width of cards in grids so they fit smaller screens */
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

@media (max-width: 450px) {
  /* On very narrow screens, stack cards into a single column */
  .grid,
  .gallery-grid {
    grid-template-columns: 1fr;
  }
}

/* Projects: force a single column on small screens for consistency and accessibility */
@media (max-width: 700px) {
  #projects-grid {
    grid-template-columns: 1fr;
  }
  /* Gallery: match one-column behavior on small screens */
  #gallery-grid {
    grid-template-columns: 1fr;
  }
}

.theme-toggle { margin-left: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--fg); cursor: pointer; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; transition: background 140ms ease, opacity 140ms ease, border-color 140ms ease; }
.theme-toggle:hover { background: var(--nav-hover-bg); }
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; opacity: 0.9; }

/* Cursor orb (behind content) */
body::before {
  content: "";
  position: fixed;
  left: var(--cursor-x, -100px);
  top: var(--cursor-y, -100px);
  width: 320px;
  height: 320px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--accent) 25%, transparent) 0%, transparent 70%);
  filter: blur(24px);
  opacity: 0.45;
}
/* Ensure content sits above the orb */
header, main, footer { position: relative; z-index: 1; }

/* During theme toggle, suppress lingering transitions for a snappier switch */
.theme-switching *,
[data-theme].theme-switching * { transition: none !important; }

/* Gallery */
.gallery-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.gallery-card .title { margin-top: 8px; }
.gallery-thumb-wrap { aspect-ratio: 4/3; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: rgba(255,255,255,0.02); }
.gallery-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-detail-card { max-width: 820px; margin: 0 auto; }
.gallery-detail-img { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); display: block; }
.toggle-line { display: inline-flex; align-items: center; gap: 8px; }

/* Avatar lightbox (CV) */
.avatar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 50; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 180ms ease; }
.avatar-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }
.avatar-overlay.closing { opacity: 0; pointer-events: none; }
.avatar-modal { outline: none; }
.avatar-modal-img { max-width: min(92vw, 820px); max-height: 92vh; border-radius: 14px; border: 1px solid var(--border); box-shadow: 0 12px 36px rgba(0,0,0,0.45), 0 0 0 6px color-mix(in oklab, var(--accent) 25%, transparent); display: block; cursor: pointer; transform: scale(0.94); transition: transform 200ms ease, box-shadow 200ms ease; }
.avatar-overlay.open .avatar-modal-img { transform: scale(1); }
.avatar-overlay.closing .avatar-modal-img { transform: scale(0.94); }
.avatar-overlay .backdrop { position: absolute; inset: 0; }

/* Reusable overlay controls (close and arrows) */
.overlay-close, .overlay-arrow {
  position: absolute;
  background: rgba(0,0,0,0.55);
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.25);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  border-radius: 999px;
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: background 140ms ease, transform 140ms ease, border-color 140ms ease;
}
.overlay-close:hover, .overlay-arrow:hover { background: rgba(0,0,0,0.7); transform: scale(1.05); border-color: rgba(255,255,255,0.4); }
.overlay-close svg, .overlay-arrow svg { width: 18px; height: 18px; fill: currentColor; }

/* Positioning for controls relative to viewport */
.overlay-close { top: 24px; right: 24px; }
.overlay-arrow.left { left: 24px; top: 50%; transform: translateY(-50%); }
.overlay-arrow.right { right: 24px; top: 50%; transform: translateY(-50%); }

/* Gallery lightbox image style mirrors avatar modal */
.lightbox-modal-img { max-width: min(92vw, 1080px); max-height: 92vh; border-radius: 14px; border: 1px solid var(--border); box-shadow: 0 12px 36px rgba(0,0,0,0.45), 0 0 0 6px color-mix(in oklab, var(--accent) 25%, transparent); display: block; cursor: default; transform: scale(0.94); transition: transform 200ms ease, box-shadow 200ms ease; }
.avatar-overlay.open .lightbox-modal-img, .lightbox-overlay.open .lightbox-modal-img { transform: scale(1); }
.lightbox-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 50; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 180ms ease; }
.lightbox-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }
.lightbox-overlay.closing { opacity: 0; pointer-events: none; }
.lightbox-overlay .backdrop { position: absolute; inset: 0; }
