/* ===== Shared theme tokens ===== */
:root {
  /* Light by default */
  --bg: #f6f8fc;
  --bg-accent: radial-gradient(1200px 600px at 20% -10%, rgba(54,92,255,0.12) 0%, rgba(54,92,255,0.06) 40%, transparent 70%);
  --surface: #ffffff;
  --surface-translucent: rgba(255,255,255,0.92);
  --text: #101218;
  --muted: #465064;
  --border: #e6e8ef;
  --shadow: 0 10px 30px rgba(16,18,24,0.08);
  --link: #1b4cff;
  --accent: #365cff;

  --container: min(90vw, 980px);
  --radius: 14px;

  /* Background image slots (pages override) */
  --hero-bg-image: none;
  --interstitial-bg-image: none;
}

/* Dark override */
[data-theme="dark"] {
  --bg: #0a0b0e;
  --bg-accent: radial-gradient(1200px 600px at 20% -10%, rgba(54,92,255,0.22) 0%, rgba(54,92,255,0.10) 40%, transparent 70%);
  --surface: #12141a;
  --surface-translucent: rgba(18,20,26,0.92);
  --text: #e7eaf3;
  --muted: #a4adbd;
  --border: #2a2f3a;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --link: #8fb1ff;
  --accent: #88a7ff;
}

/* Respect system pref on first load */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b0e;
    --bg-accent: radial-gradient(1200px 600px at 20% -10%, rgba(54,92,255,0.22) 0%, rgba(54,92,255,0.10) 40%, transparent 70%);
    --surface: #12141a;
    --surface-translucent: rgba(18,20,26,0.92);
    --text: #e7eaf3;
    --muted: #a4adbd;
    --border: #2a2f3a;
    --shadow: 0 10px 30px rgba(0,0,0,0.35);
    --link: #8fb1ff;
    --accent: #88a7ff;
  }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg-accent), var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; }

.skip-link { position: absolute; left: -9999px; top: auto; }
.skip-link:focus { left: 16px; top: 16px; background: #fff; padding: 8px 12px; border-radius: 8px; z-index: 2; }

/* ===== Header variants ===== */
header.site-header {
  position: relative;
  isolation: isolate;
  color: #fff;
  background:
    linear-gradient(to bottom, rgba(10,11,14,0.6), rgba(10,11,14,0.4)),
    var(--hero-bg-image) center/cover no-repeat;
}
header.site-header--angled {
  background:
    linear-gradient(to bottom right, rgba(2,6,23,0.85), rgba(2,6,23,0.55)),
    var(--hero-bg-image) center/cover no-repeat;
  clip-path: polygon(0 0, 100% 0, 100% 88%, 0 100%);
}
header.site-header::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(800px 400px at 70% -20%, rgba(255,255,255,0.18), transparent 40%),
              linear-gradient(to bottom, rgba(0,0,0,0.45), rgba(0,0,0,0.65));
  z-index: -1;
}
header.site-header--angled::before {
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px;
  mask-image: radial-gradient(1000px 500px at 70% 10%, black, transparent 70%);
  pointer-events: none;
}
.hero-inner { max-width: var(--container); margin: 0 auto; padding: 6rem 0 3.5rem; }
.identity { display: grid; gap: 0.2rem; margin-bottom: 1.2rem; }
.identity h1 { margin: 0; font-size: clamp(1.9rem, 2.8vw + 1rem, 3rem); line-height: 1.2; letter-spacing: 0.2px; }
.identity p { margin: 0; color: #d7dbe6; font-size: 1.05rem; }

/* ===== Top nav ===== */
.topnav {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}
.topnav a, .btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  background: #ffffff;
  color: #111;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(16,18,24,0.06);
}
.btn.secondary {
  background: rgba(255,255,255,0.14);
  color: #fff;
  border-color: transparent;
  backdrop-filter: blur(6px);
}
.btn.toggle { cursor: pointer; user-select: none; }

/* ===== Main & panes ===== */
main { position: relative; z-index: 1; padding: 2.2rem 0 4rem; }
.stack { max-width: var(--container); margin: 0 auto; padding: 0 0.5rem; }

.pane {
  position: relative;
  background: var(--surface-translucent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2.8vw, 2rem);
  margin: 1.2rem 0 1.6rem;
  backdrop-filter: blur(6px);
}
.pane header.pane-head { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.6rem; }
.pane .kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.78rem; color: var(--muted); }

.pane h2 { margin: 0.2rem 0 0.2rem; font-size: clamp(1.35rem, 1.2rem + 1vw, 1.8rem); line-height: 1.25; }
.pane h3 { margin: 1.2rem 0 0.4rem; font-size: clamp(1.1rem, 1rem + 0.7vw, 1.3rem); color: var(--muted); }
p { margin: 0.9rem 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Numbered variant */
.pane.numbered { padding-left: clamp(1rem, 1rem + 1.6vw, 2.4rem); }
.pane.numbered::before {
  content: attr(data-step);
  position: absolute;
  left: 0.6rem; top: 0.8rem;
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1220;
  font-weight: 700;
  font-size: 0.9rem;
  border: 2px solid rgba(255,255,255,0.8);
}
.pane.numbered::after {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 6px; border-radius: 6px 0 0 6px;
  background: linear-gradient(to bottom, var(--accent), transparent 80%);
  opacity: 0.6;
}

/* Figures */
figure { margin: 1rem 0 1.2rem; background: rgba(0,0,0,0.03); border-radius: 12px; overflow: hidden; }
[data-theme="dark"] figure { background: rgba(255,255,255,0.06); }
figure img { display: block; width: 100%; }
figure figcaption { font-size: 0.92rem; color: var(--muted); padding: 0.6rem 0.9rem 0.9rem; }
@media (min-width: 900px) {
  .float-right { float: right; width: min(42%, 360px); margin: 0.2rem 0 1rem 1.2rem; }
  .float-left  { float: left;  width: min(42%, 360px); margin: 0.2rem 1.2rem 1rem 0; }
}

/* Interstitial */
.interstitial {
  margin: 2rem 0 2rem; border-radius: var(--radius); overflow: hidden;
  background:
    linear-gradient(to bottom, rgba(10,11,14,0.55), rgba(10,11,14,0.7)),
    var(--interstitial-bg-image) center/cover no-repeat;
  color: #fff;
}
.interstitial .inner { padding: 1rem 1.2rem; }
.interstitial p { margin: 0.3rem 0; color: #e6e9f2; }

/* Publications list */
.pubs { margin: 0.6rem 0 0.2rem; padding-left: 1.2rem; }
.pubs li { margin: 0.35rem 0; }
.pubs small { color: var(--muted); }

/* Footer */
footer { max-width: var(--container); margin: 2rem auto 4rem; color: var(--muted); padding: 0 0.5rem; font-size: 0.95rem; }

/* Print */
@media print {
  header.site-header, .interstitial { display: none; }
  body { background: #fff; }
  .pane { box-shadow: none; background: #fff; }
  a { color: #000; text-decoration: underline; }
}

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

# Shared JS (script.js)
script_js = r"""
// Year
(function setYear(){
  var y = document.getElementById('y');
  if (y) y.textContent = new Date().getFullYear();
})();

// Lazy-load images
document.addEventListener('DOMContentLoaded', function(){
  document.querySelectorAll('img').forEach(function(img){ img.loading = 'lazy'; });
});

// Theme (persist + system default)
(function initTheme() {
  var root = document.documentElement;
  var stored = localStorage.getItem('theme');
  var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
  var initial = stored || (prefersDark ? 'dark' : 'light');
  root.setAttribute('data-theme', initial);
})();

document.addEventListener('click', function(e){
  var t = e.target;
  if (t && t.id === 'theme-toggle') {
    var root = document.documentElement;
    var now = root.getAttribute('data-theme') || 'light';
    var next = now === 'dark' ? 'light' : 'dark';
    root.setAttribute('data-theme', next);
    localStorage.setItem('theme', next);
  }
});

