/* ==========================================================================
   Site layout & components. Colours/fonts come from themes.css tokens.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s, color .25s;
}
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }

/* ---------- Backdrop ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100lvh;
  z-index: -1;
  pointer-events: none;
  -webkit-mask-image: var(--contour-mask);
  mask-image: var(--contour-mask);
}
body { position: relative; isolation: isolate; }

/* ---------- Type ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2rem 0 0.75rem;
  text-wrap: balance;
}
h1 { font-size: clamp(2rem, 1.4rem + 2.6vw, 3rem); margin-top: 0; }
h2 { font-size: clamp(1.4rem, 1.15rem + 1vw, 1.85rem); }
h3 { font-size: 1.2rem; }
p, ul, ol { margin: 0 0 1rem; }
p { text-wrap: pretty; }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 3px; }
code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }
code { background: var(--bg-sunk); padding: 0.1em 0.35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }
.muted { color: var(--text-muted); }
.lede { font-size: 1.2rem; color: var(--text-muted); max-width: var(--measure); }
.prose { max-width: var(--measure); }
.eyebrow {
  font-family: var(--font-sans);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 0.5rem;
}
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: var(--page-width); margin-inline: auto; padding-inline: var(--gutter); }
main { flex: 1; padding-block: clamp(2rem, 6vw, 4.5rem); }
.skip-link { position: absolute; left: -999px; top: 0.5rem; background: var(--bg-elev); padding: 0.5rem 1rem; z-index: 10; }
.skip-link:focus { left: 0.5rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.site-header .wrap { display: flex; align-items: center; gap: 1rem; min-height: 3.75rem; flex-wrap: wrap; }
.site-title {
  font-family: var(--font-heading); font-weight: 600; font-size: 1.15rem;
  color: var(--text); text-decoration: none; margin-right: auto;
  display: inline-flex; align-items: center; gap: 0.55rem;
}
.site-title:hover { color: var(--text); text-decoration: none; }
.site-title svg { width: 1.5rem; height: 1.5rem; color: var(--accent); }
.site-nav ul { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.site-nav a {
  display: block; padding: 0.4rem 0.7rem; border-radius: var(--radius-sm);
  color: var(--text-muted); text-decoration: none; font-family: var(--font-sans); font-size: 0.95rem;
}
.site-nav a:hover { color: var(--text); background: var(--bg-sunk); }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }
.theme-select {
  font: inherit; font-family: var(--font-sans); font-size: 0.85rem;
  color: var(--text); background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem; cursor: pointer;
}
@media (max-width: 640px) {
  .site-header .wrap { padding-block: 0.5rem; }
  .site-nav { order: 3; width: 100%; }
  .site-nav ul { gap: 0; }
  .site-nav a { padding: 0.35rem 0.55rem; }
}

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.9rem; background: color-mix(in srgb, var(--bg) 85%, transparent); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding-block: 1.5rem; }
.site-footer a { color: inherit; }

/* ---------- Components ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}
.button {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font: inherit; font-family: var(--font-sans); font-size: 0.95rem; font-weight: 500;
  padding: 0.6rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-contrast);
  border: 1px solid var(--accent); text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--accent-hover); color: var(--accent-contrast); text-decoration: none; }
.button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.button.ghost:hover { background: var(--bg-sunk); }
.button svg { width: 1.1em; height: 1.1em; }
.button-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.5rem; }
.tag {
  display: inline-block; font-family: var(--font-sans); font-size: 0.78rem;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); border: 1px solid transparent;
}

/* ---------- About (home) ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: clamp(1.5rem, 5vw, 4rem); align-items: center; }
.portrait {
  width: clamp(9rem, 22vw, 15rem); aspect-ratio: 1; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--border); background: var(--bg-sunk);
  box-shadow: var(--shadow);
}
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero .portrait { order: -1; width: 8rem; }
}
.grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); }
.grid-3 .card h3 { margin-top: 0; }
.grid-3 .card p:last-child { margin-bottom: 0; }

/* ---------- Gallery ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.5rem 0 2rem; }
.filters button {
  font: inherit; font-family: var(--font-sans); font-size: 0.85rem;
  padding: 0.3rem 0.85rem; border-radius: 999px; cursor: pointer;
  background: var(--bg-elev); color: var(--text-muted); border: 1px solid var(--border);
}
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.gallery { columns: 3 18rem; column-gap: 1rem; }
.gallery figure { break-inside: avoid; margin: 0 0 1rem; }
.gallery button.thumb {
  display: block; width: 100%; padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: zoom-in; background: var(--bg-sunk);
}
.gallery .thumb img, .gallery .thumb canvas { width: 100%; height: auto; transition: transform .4s ease; }
.gallery .thumb:hover img, .gallery .thumb:hover canvas { transform: scale(1.025); }
.gallery figcaption { font-size: 0.9rem; color: var(--text-muted); padding: 0.45rem 0.15rem 0; }
.gallery figcaption strong { color: var(--text); font-weight: 600; }

.lightbox {
  border: 0; padding: 0; max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh;
  background: color-mix(in srgb, var(--bg) 94%, transparent); color: var(--text);
}
.lightbox::backdrop { background: rgb(0 0 0 / 0.5); }
.lightbox[open] { display: grid; grid-template-rows: 1fr auto; }
.lightbox .stage { display: grid; place-items: center; padding: 3.5rem 4rem 1rem; min-height: 0; }
.lightbox .stage > * { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.lightbox .meta { text-align: center; padding: 0 1.5rem 1.5rem; }
.lightbox .meta h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.lightbox .meta p { margin: 0 auto; color: var(--text-muted); max-width: var(--measure); }
.lightbox .lb-btn {
  position: absolute; background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  width: 2.75rem; height: 2.75rem; border-radius: 50%; cursor: pointer; font-size: 1.3rem; line-height: 1;
  display: grid; place-items: center;
}
.lightbox .lb-close { top: 1rem; right: 1rem; }
.lightbox .lb-prev { left: 1rem; top: 50%; translate: 0 -50%; }
.lightbox .lb-next { right: 1rem; top: 50%; translate: 0 -50%; }
@media (max-width: 640px) {
  .lightbox .stage { padding: 4rem 0.75rem 1rem; }
  .lightbox .lb-prev, .lightbox .lb-next { top: auto; bottom: 1rem; translate: none; }
}

/* ---------- Presentations ---------- */
.course { margin-top: 2.5rem; }
.course-head { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.course-head h2 { margin: 0; }
.course-code { font-family: var(--font-mono); font-size: 0.9rem; color: var(--accent); }
.decks { list-style: none; padding: 0; margin: 1rem 0 0; border-top: 1px solid var(--border); }
.decks li { border-bottom: 1px solid var(--border); }
.decks a {
  display: grid; grid-template-columns: 2.5rem 1fr auto; gap: 0.25rem 1rem; align-items: baseline;
  padding: 0.9rem 0.5rem; text-decoration: none; color: var(--text); border-radius: var(--radius-sm);
}
.decks a:hover { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.decks .num { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.9rem; }
.decks .title { font-weight: 600; }
.decks .date { color: var(--text-muted); font-size: 0.85rem; font-family: var(--font-sans); white-space: nowrap; }
.decks .summary { grid-column: 2 / -1; color: var(--text-muted); font-size: 0.95rem; }
@media (max-width: 560px) {
  .decks a { grid-template-columns: 2rem 1fr; }
  .decks .date { grid-column: 2; }
}

/* ---------- Link tree ---------- */
.tree-page main { padding-block: clamp(2.5rem, 8vh, 5rem); }
.tree { max-width: 34rem; margin-inline: auto; text-align: center; }
.tree .portrait { width: 6.5rem; margin: 0 auto 1rem; }
.tree h1 { font-size: 1.75rem; margin-bottom: 0.25rem; }
.tree .bio { color: var(--text-muted); margin-bottom: 2rem; }
.tree h2 {
  font-family: var(--font-sans); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-muted); margin: 2rem 0 0.75rem;
}
.tree ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.65rem; }
.tree-link {
  display: grid; grid-template-columns: 1.5rem 1fr 1.5rem; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1rem; text-decoration: none; color: var(--text);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); font-weight: 500;
  transition: transform .15s ease, border-color .15s ease;
}
.tree-link:hover { color: var(--text); text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.tree-link svg { width: 1.25rem; height: 1.25rem; color: var(--accent); }
.tree-link small { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.tree-foot { margin-top: 2.5rem; display: flex; justify-content: center; align-items: center; gap: 1rem; font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
