/* ========= THEME (auto + manual override) ========= */
:root{
  color-scheme: light dark;
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --card: #f8fafc;
  --border: #e5e7eb;
  --accent: #0ea5e9;
  --shadow: 0 10px 25px rgba(0,0,0,0.06);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg: #0b0f13;
    --text: #e5e7eb;
    --muted: #9aa3af;
    --card: #121821;
    --border: #1f2937;
    --accent: #38bdf8;
    --shadow: 0 10px 25px rgba(0,0,0,0.30);
  }
}
:root[data-theme="light"]{
  --bg:#ffffff; --text:#1a1a1a; --muted:#6b7280; --card:#f8fafc; --border:#e5e7eb; --accent:#0ea5e9; --shadow:0 10px 25px rgba(0,0,0,0.06);
}
:root[data-theme="dark"]{
  --bg:#0b0f13; --text:#e5e7eb; --muted:#9aa3af; --card:#121821; --border:#1f2937; --accent:#38bdf8; --shadow:0 10px 25px rgba(0,0,0,0.30);
}

html{ scrollbar-gutter: stable both-edges; }
*{ box-sizing: border-box; }
html, body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial;
  color:var(--text); background:var(--bg); line-height:1.6;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background-color .25s, color .25s;
}

.container{ width:min(1280px, 92%); margin-inline:auto; }
.visually-hidden{ position:absolute !important; inline-size:1px; block-size:1px; overflow:hidden; clip:rect(1px,1px,1px,1px); }


/* ========= HEADER / NAV ========= */
.site-header{
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in oklab, var(--bg), transparent 15%);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.nav-bar{ display:flex; align-items:center; justify-content:space-between; padding:.8rem 0; }
.logo{ font-weight:700; letter-spacing:.2px; color:var(--text); text-decoration:none; }
.nav-links{ display:flex; gap:1rem; list-style:none; margin:0; padding:0; align-items:center; }
.nav-links a{ color:var(--text); text-decoration:none; padding:.4rem .6rem; border-radius:8px; }
.nav-links a[aria-current="page"], .nav-links a:hover{ background:var(--card); }
.theme-toggle{ border:1px solid var(--border); background:var(--card); color:var(--text); padding:.35rem .55rem; border-radius:10px; cursor:pointer; }
.theme-toggle:hover{ filter:brightness(1.05); }

/* ========= INTRO ========= */
.intro{ margin:1.2rem 0 .4rem; color:var(--muted); }

/* ========= MASONRY (CSS columns — stable spacing) ========= */
.gallery-grid{
  column-count: 3;
  column-gap: 16px;

  --masonry-gap: 16px;
  --footer-space: 48px;

  padding: 1rem 0 var(--footer-space);
  margin-bottom: calc(-1 * var(--masonry-gap)); /* cancel final card margin */
  display: flow-root; /* prevents margin-collapsing with footer */
}
@media (max-width: 900px){ .gallery-grid{ column-count: 2; } }
@media (max-width: 600px){ .gallery-grid{ column-count: 1; } }

/* Cards — no breaks, no hover jitter */
/* Gallery Cards — Flicker-free */
.card {
  display: block;
  break-inside: avoid;
  margin-bottom: var(--masonry-gap, 16px);
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;

  /* Prevent Chrome repaint flicker */
  isolation: isolate;        /* creates new stacking context */
  contain: paint;            /* isolate paints */
  transform: translateZ(0);  /* force GPU layer */
  will-change: opacity;      /* hint to browser */
  backface-visibility: hidden;
}

.card img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  border-radius: inherit;

  /* Keep rendering stable */
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: opacity;
  contain: layout paint style;

  /* Smooth fade-in hover */
  transition: opacity 0.25s ease-in-out;
}

/* Overlay hover (no scaling → no layout shift) */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.card:hover::after {
  opacity: 1;
}

/* Placeholder tile */
.placeholder{ background:var(--card); border:2px dashed var(--border); border-radius:16px; display:grid; place-items:center; color:var(--muted); min-height:220px; }
.card.placeholder{ pointer-events:none; }

/* ========= LIGHTBOX ========= */
.lightbox[hidden]{ display:none; }
.lightbox{
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.85);
}
.lb-figure{ max-width: 92vw; max-height: 86vh; margin: 0; display: grid; gap: 10px; }
#lb-image{ max-width: 92vw; max-height: 80vh; width: auto; height: auto; object-fit: contain; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.45); }

/* Caption + buttons STACKED (buttons underneath) */
#lb-caption{
  display: flex;
  flex-direction: column;  /* put actions underneath */
  align-items: center;
  text-align: center;
  color: #f3f4f6;
  font-size: 1.1rem;
  gap: .6rem;
}
.lb-actions{
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-link{
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: .5rem .9rem;
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
}
.btn-link:hover{ filter: brightness(1.05); }

/* LB controls */
.lb-btn{ position:absolute; background: rgba(255,255,255,.15); color:#fff; border:1px solid rgba(255,255,255,.25); backdrop-filter: blur(6px); padding:.4rem .6rem; border-radius:10px; cursor:pointer; user-select:none; }
.lb-btn:hover{ background: rgba(255,255,255,.25); }
.lb-close{ top:16px; right:16px; font-size:1.4rem; line-height:1; }
.lb-prev{ left:16px; top:50%; transform: translateY(-50%); font-size:1.6rem; padding-inline:.6rem; }
.lb-next{ right:16px; top:50%; transform: translateY(-50%); font-size:1.6rem; padding-inline:.6rem; }

/* Counter centered at top */
.lb-counter{
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  color: #e5e7eb; font-size: .95rem; font-weight: 500;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.15);
  padding: 4px 10px; border-radius: 10px; user-select: none;
}

/* ========= DETAILS POPUP ========= */
.meta[hidden]{ display:none; }
.meta{ position:fixed; inset:0; z-index:1100; background: rgba(0,0,0,.6); display:grid; place-items:center; }
.meta-card{
  width:min(720px, 92vw);
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 1rem 1.2rem 1.2rem;
}
.meta-title{ margin: 0 0 .6rem; font-size: 1.2rem; }
.meta-close{ float:right; border:1px solid var(--border); background:var(--card); color:var(--text); border-radius:10px; padding:.2rem .6rem; cursor:pointer; }
.meta-close:hover{ filter:brightness(1.05); }
.meta-grid{ display:grid; grid-template-columns:1fr 2fr; gap:8px 14px; margin:0; padding:.4rem 0 0; }
.meta-grid dt{ color:var(--muted); } .meta-grid dd{ margin:0; }

/* ========= FOOTER (stable) ========= */
.site-footer{
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flow-root;  /* isolates from gallery margins */
  margin-top: 0;
}
.footer-inner{
  display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between;
  gap:.8rem; padding-block:1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom,0px));
  color: var(--muted);
}
.footer-inner > *{ margin: 0; }
.site-footer a{ color: inherit; text-decoration: none; outline: none; }
.site-footer a:hover, .site-footer a:focus-visible{ text-decoration: underline; text-underline-offset: 2px; }

/* ========= REDUCE MOTION ========= */
@media (prefers-reduced-motion: reduce){
  .card::after, .btn-link, .lb-btn { transition: none; }
}

/* ========= ABOUT PAGE ========= */

.about {
  margin-top: 2rem;
  margin-bottom: 3rem;
}

.about h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  color: var(--text);
  text-align: center;
}

.about-content {
  display: grid;
  grid-template-columns: 280px 1fr;
  align-items: start;
  gap: 2rem;
}

.about-portrait {
  width: 100%;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: var(--card);
  transition: transform 0.3s ease, filter 0.3s ease;
}

.about-portrait:hover {
  transform: scale(1.015);
  filter: brightness(1.05);
}

/* Text sections */
.about-content p {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--text);
}

.about-content h2 {
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
  margin-bottom: 0.5rem;
}

/* Lists */
.about-content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.about-content li {
  margin-bottom: 0.4rem;
  color: var(--muted);
}

/* Contact links */
.about-content a {
  color: var(--accent);
  text-decoration: none;
}

.about-content a:hover {
  text-decoration: underline;
}

/* === Affiliations Section === */
.affiliations {
  margin-top: 2.5rem;
}

.affiliations h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
  margin-bottom: 1rem;
}

/* Grid of cards */
.affiliation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1.5rem;
  align-items: center;
  justify-items: center;
}

/* Each logo + caption */
.affiliation-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  transition: transform 0.2s ease, filter 0.2s ease;
  box-shadow: var(--shadow);
}

.affiliation-card:hover {
  transform: translateY(-3px);
  filter: brightness(1.05);
}

.affiliation-card img {
  max-height: 60px;
  max-width: 120px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--bg);
}

.affiliation-card span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
}

/* On narrow phones, show the whole image inside the card */
@media (max-width: 520px) {
  .card { background: var(--card); }
  .card img {
    object-fit: contain;       /* was cover */
    background: var(--card);   /* subtle letterbox, no stretch */
  }
}

@media (max-width: 600px) {
  .affiliation-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
  .affiliation-card img {
    max-height: 50px;
  }
}

/* Back-to-top (mobile-friendly, theme-aware) */
.back-to-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 900; /* below lightbox (which is 1000+) */
  display: grid;
  place-items: center;

  width: 44px;  
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;

  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease, filter .18s ease;
}
.back-to-top:hover { filter: brightness(1.06); }

/* visible state toggled by JS */
.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Don’t show when the lightbox is open */
.lightbox:not([hidden]) ~ .back-to-top {
  opacity: 0 !important;
  pointer-events: none;
}

@media (max-width: 520px) {
  .back-to-top { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}


/* Responsive layout */
@media (max-width: 768px) {
  .about-content {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .about-portrait {
  width: 100%;
  height: auto;            /* important on mobile */
  object-fit: cover;       /* or 'contain' if you want zero crop */
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  }

  .about-content section {
    margin-top: 1.5rem;
  }
}

