/* ==========================================================================
   Site theme (replaces minima's stylesheet)
   ========================================================================== */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --text: #15171c;
  --muted: #5d6472;
  --border: #e4e6ea;
  --accent: #2f5fd0;
  --accent-soft: rgba(47, 95, 208, 0.1);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 2px 4px rgba(16, 24, 40, 0.06), 0 18px 40px rgba(16, 24, 40, 0.12);
  --header-bg: rgba(250, 250, 249, 0.8);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 3px;
  --radius-sm: 2px;
  --content: 720px;
  --wide: 1120px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13;
    --surface: #15181e;
    --surface-2: #1b1f27;
    --text: #e8eaef;
    --muted: #9aa2b1;
    --border: #262a33;
    --accent: #7ea2ff;
    --accent-soft: rgba(126, 162, 255, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.35), 0 18px 40px rgba(0, 0, 0, 0.4);
    --header-bg: rgba(13, 15, 19, 0.78);
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f13;
  --surface: #15181e;
  --surface-2: #1b1f27;
  --text: #e8eaef;
  --muted: #9aa2b1;
  --border: #262a33;
  --accent: #7ea2ff;
  --accent-soft: rgba(126, 162, 255, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.35), 0 18px 40px rgba(0, 0, 0, 0.4);
  --header-bg: rgba(13, 15, 19, 0.78);
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; }

img, video, iframe { max-width: 100%; }
img, video { height: auto; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3, h4 {
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 650;
  margin: 2.2em 0 0.6em;
}
h1 { font-size: clamp(2rem, 4.5vw, 2.75rem); letter-spacing: -0.03em; font-weight: 700; margin-top: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }

hr { border: 0; border-top: 1px solid var(--border); margin: 3rem 0; }

::selection { background: var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

.container {
  width: 100%;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 64px;
}

.site-title {
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.site-title:hover { text-decoration: none; color: var(--accent); }

.site-nav { display: flex; align-items: center; gap: 0.25rem; }

.site-nav a {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

@media (max-width: 600px) {
  .site-header__inner { height: auto; padding-top: 0.6rem; padding-bottom: 0.5rem; flex-wrap: wrap; row-gap: 0.25rem; }
  .site-nav { width: 100%; justify-content: space-between; margin: 0 -0.75rem; width: calc(100% + 1.5rem); }
  .site-nav a { padding: 0.35rem 0.6rem; font-size: 0.9rem; }
  .site-title { flex: 1; }
  .theme-toggle { position: absolute; top: 0.55rem; right: var(--gutter); }
  .site-header__inner { position: relative; }
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 5rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.site-footer__inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-top: 1.75rem;
  padding-bottom: 2rem;
}
.site-footer__links { display: flex; gap: 1.25rem; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }

/* ---------- Pages ---------- */

.page { padding-top: 3.5rem; }

.page-header { max-width: var(--content); margin: 0 auto 2.5rem; }
.page-header h1 { margin-bottom: 0.4em; }

.lede { font-size: 1.15rem; color: var(--muted); margin: 0; line-height: 1.6; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.75rem;
}

.back-link {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.prose { max-width: var(--content); margin: 0 auto; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.25em; }
.prose li { margin-bottom: 0.35em; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 600; }
.prose h2 { padding-top: 0.5rem; }
.prose img, .prose video { border-radius: var(--radius-sm); }
.prose iframe { border: 0; border-radius: var(--radius-sm); }
.prose figure { margin: 2rem 0; }
.prose figcaption, .caption { font-size: 0.88rem; color: var(--muted); margin-top: 0.6rem; text-align: center; }
.prose code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 0.15em 0.4em; border-radius: var(--radius-sm); }
.prose blockquote { margin: 1.5rem 0; padding-left: 1.25rem; border-left: 3px solid var(--border); color: var(--muted); }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 1.5rem 0; }
.prose th, .prose td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); }
.prose br + br { display: none; }

/* Wider-than-text elements inside .prose */
.breakout,
.prose .breakout {
  width: min(var(--wide), 100vw - 2 * var(--gutter));
  margin-left: 50%;
  margin-right: 0;
  transform: translateX(-50%);
}

/* Responsive 16:9 embed */
.embed { position: relative; aspect-ratio: 16 / 9; margin: 2rem 0; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #000; }
.embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; }
.embed--portrait { aspect-ratio: 9 / 16; max-width: 340px; margin-left: auto; margin-right: auto; }
.embed--4x3 { aspect-ratio: 4 / 3; }

/* ---------- Buttons ---------- */

.button-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.5rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 550;
  line-height: 1.2;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.btn:hover { text-decoration: none; border-color: var(--muted); transform: translateY(-1px); }
.btn--primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn--primary:hover { border-color: var(--text); opacity: 0.9; }
.btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------- Home ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 3.5rem;
  align-items: center;
  padding: 4.5rem 0 3.5rem;
}
.hero h1 { font-size: clamp(2.4rem, 6vw, 3.6rem); margin-bottom: 0.3em; }
.hero__lede { font-size: 1.12rem; color: var(--muted); margin: 0 0 1em; }
.hero__lede strong { color: var(--text); font-weight: 600; }
.hero__photo {
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  aspect-ratio: 4 / 5;
  background: var(--surface-2);
}
.hero__photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; padding-top: 2.5rem; }
  .hero__photo { order: -1; aspect-ratio: 16 / 10; max-width: 520px; }
}

.interests { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1.5rem 0 0; padding: 0; list-style: none; }
.interests li {
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

.section { padding: 3rem 0; border-top: 1px solid var(--border); }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; }
.section__head h2 { margin: 0; }
.section__head a { font-size: 0.92rem; font-weight: 500; white-space: nowrap; }
.section .prose { margin: 0; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 3rem; align-items: start; }
.split .embed { margin: 0; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; gap: 1.5rem; } }

/* ---------- Cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: transparent; }

.card__media {
  aspect-ratio: 3 / 2;
  background: var(--surface-2);
  overflow: hidden;
}
.card__media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.4s ease; }
.card__media--contain img { object-fit: contain; padding: 1rem; }
.card:hover .card__media img { transform: scale(1.03); }

.card__body { padding: 1.1rem 1.25rem 1.3rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.card__meta { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.card__title { font-size: 1.05rem; font-weight: 650; line-height: 1.3; margin: 0; }
.card__title a { color: var(--text); }
.card__title a::after { content: ""; position: absolute; inset: 0; } /* whole card is clickable */
.card__title a:hover { text-decoration: none; }
.card:hover .card__title a { color: var(--accent); }
.card__desc { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.55; }

.card--featured { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.card--featured .card__media { aspect-ratio: auto; min-height: 300px; }
.card--featured .card__body { justify-content: center; padding: 2rem; gap: 0.6rem; }
.card--featured .card__title { font-size: 1.5rem; letter-spacing: -0.02em; }
.card--featured .card__desc { font-size: 1rem; }
@media (max-width: 760px) {
  .card--featured { grid-template-columns: 1fr; }
  .card--featured .card__media { min-height: 0; aspect-ratio: 3 / 2; }
  .card--featured .card__body { padding: 1.25rem; }
}

/* ---------- Project pages ---------- */

.project-hero {
  max-width: 960px;
  margin: 0 auto 3rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.project-hero img { display: block; width: 100%; max-height: 560px; object-fit: cover; }
.project-hero--contain img { object-fit: contain; padding: 2rem; max-height: 480px; }

/* ---------- CV ---------- */

.cv-embed {
  width: 100%;
  height: min(1100px, 85vh);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #fff;
}

/* ---------- STL viewer ---------- */

.stl-viewer { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); max-width: 100%; }

/* ---------- Semantic map viewer ---------- */

.semantic-map { margin-top: 2.5rem; margin-bottom: 3rem; }

.semantic-map__stage {
  position: relative;
  height: min(72vh, 680px);
  min-height: 380px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b0d12;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  color: #e8eaef;
}
.semantic-map__stage canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.semantic-map__stage canvas:active { cursor: grabbing; }

.semantic-map__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0 !important;
  opacity: 0.55;
  transition: opacity 0.5s;
}
.semantic-map.is-ready .semantic-map__poster { opacity: 0; pointer-events: none; }

.semantic-map__hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  pointer-events: none;
  background: linear-gradient(rgba(11, 13, 18, 0.7), rgba(11, 13, 18, 0));
}
.semantic-map__info { pointer-events: auto; }
.semantic-map__stats { font-family: var(--mono); font-size: 0.72rem; color: #9aa2b1; margin-top: 0.5rem; }

/* Buttons that sit flush together as one segmented control */
.semantic-map__group { display: inline-flex; }
.semantic-map__group > .semantic-map__btn { border-radius: 0; }
.semantic-map__group > .semantic-map__btn + .semantic-map__btn { margin-left: -1px; }
.semantic-map__group > .semantic-map__btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.semantic-map__group > .semantic-map__btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.semantic-map__envs .semantic-map__btn { font-size: 0.85rem; font-weight: 600; padding: 0.4rem 0.85rem; }

.semantic-map__toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem; pointer-events: auto; }
.semantic-map__btn {
  font: 500 0.78rem var(--font);
  color: #e8eaef;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s;
}
.semantic-map__btn:hover { background: rgba(255, 255, 255, 0.16); }
.semantic-map__btn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.92); color: #0b0d12; border-color: transparent; }

.semantic-map__status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  color: #c9ced8;
  pointer-events: none;
}
.semantic-map__status:empty { display: none; }

.semantic-map__robots {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  opacity: 0;
  transition: opacity 0.4s;
}
.semantic-map.is-ready .semantic-map__robots { opacity: 1; }
.semantic-map__robot { display: inline-flex; align-items: center; gap: 0.4rem; }
.semantic-map__dot { width: 8px; height: 8px; border-radius: 1px; flex: none; }

.semantic-map__legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.9rem; }
.semantic-map__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font: 500 0.8rem var(--font);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.28rem 0.7rem 0.28rem 0.5rem;
  cursor: pointer;
  text-transform: capitalize;
  transition: opacity 0.15s, border-color 0.15s;
}
.semantic-map__chip:hover { border-color: var(--muted); }
.semantic-map__chip[aria-pressed="false"] { opacity: 0.4; }
.semantic-map__chip:disabled { opacity: 0.25; cursor: default; }
.semantic-map__chip[hidden] { display: none; }
.semantic-map__swatch { width: 10px; height: 10px; border-radius: 1px; flex: none; }
.semantic-map figcaption { text-align: left; margin-top: 0.75rem; }

@media (max-width: 600px) {
  .semantic-map__stage { height: 62vh; }
  .semantic-map__hud { flex-direction: column; }
  .semantic-map__toolbar { justify-content: flex-start; }
}

/* ---------- Motion ---------- */

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