:root {
  --bg: oklch(99% 0.004 80);
  --surface: oklch(96% 0.006 80);
  --ink: oklch(19% 0.01 40);
  --muted: oklch(45% 0.012 40);
  --line: oklch(83% 0.01 40);
  --line-strong: oklch(19% 0.01 40);
  --accent: oklch(48% 0.14 250);
  --accent-soft: oklch(93% 0.03 250);
}

:root[data-theme="dark"] {
  --bg: oklch(16% 0.007 260);
  --surface: oklch(21% 0.009 260);
  --ink: oklch(94% 0.004 80);
  --muted: oklch(66% 0.012 80);
  --line: oklch(33% 0.012 260);
  --line-strong: oklch(80% 0.01 80);
  --accent: oklch(74% 0.11 250);
  --accent-soft: oklch(28% 0.05 250);
}


* { box-sizing: border-box; }

html { color-scheme: light; overflow-x: hidden; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Times New Roman', Times, serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
.fig-body p a, .article p a { color: var(--accent); }
.fig-body p a:hover, .article p a:hover { text-decoration: underline; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line-strong);
}
.nav-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 24px;
}
.brand { font-weight: 600; font-size: 17px; letter-spacing: 0.01em; }
.nav-links { display: flex; gap: 22px; flex-wrap: wrap; font-size: 15px; letter-spacing: 0.01em; }
.nav-links a { color: var(--muted); }
.nav-links a.active { color: var(--ink); border-bottom: 2px solid var(--accent); padding-bottom: 2px; }
.nav-links a:hover { color: var(--ink); }

.theme-toggle {
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink);
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface); }

@media (max-width: 480px) {
  .nav-inner { padding: 10px 12px; gap: 6px; }
  .brand { font-size: 12px; }
  .nav-links { gap: 7px; font-size: 10px; }
  .theme-toggle { width: 24px; height: 24px; }
  .theme-toggle svg { width: 13px; height: 13px; }
}

/* ---------- layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.section { padding: 40px 0; }
.section-tight { margin: 0 24px 40px; max-width: 1052px; margin-left: auto; margin-right: auto; }
.section-label {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 18px;
}

.grid-2 { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 24px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
@media (max-width: 680px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- schematic figure blocks ---------- */
.fig {
  position: relative;
  border: 1px solid var(--line-strong);
  background: var(--bg);
}
.tick { position: absolute; width: 9px; height: 9px; border-color: var(--accent); border-style: solid; border-width: 0; pointer-events: none; }
.tl { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.tr { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.bl { bottom: -1px; left: -1px; border-bottom-width: 2px; border-left-width: 2px; }
.br { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }

.portrait { padding: 14px; }
.portrait img { display: block; width: 100%; height: auto; aspect-ratio: 1/1; object-fit: cover; }

/* ---------- grayscale-to-color image treatment ---------- */
.project-row .thumb {
  filter: grayscale(100%);
  transition: filter 0.35s ease;
}
.project-row:hover .thumb {
  filter: grayscale(0%);
}
@media (prefers-reduced-motion: reduce) {
  .project-row .thumb { transition: none; }
}

.fig-body { padding: 24px 26px 22px; }
.fig-body h1 { margin: 0 0 6px; font-size: clamp(26px, 3.4vw, 32px); font-weight: 600; }
.fig-body .role { font-size: 13.5px; color: var(--muted); margin-bottom: 16px; }
.fig-body p { font-size: 14px; line-height: 1.65; margin: 0 0 16px; }
.fig-body .stub, .article .stub { color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 7px; font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; }
.tags span { border: 1px solid var(--line-strong); padding: 4px 9px; }

/* ---------- contact bar ---------- */
.contact-bar { display: flex; flex-wrap: wrap; font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.contact-item { flex: 1 1 220px; padding: 13px 20px; border-right: 1px solid var(--line-strong); }
.contact-item:last-child { border-right: none; }
.lbl { color: var(--muted); }
.contact-item a:hover { color: var(--accent); }

/* ---------- project list ---------- */
.project-list { display: flex; flex-direction: column; gap: 20px; }
.project-row { display: flex; transition: border-color 0.15s ease; }
.project-row:hover { border-color: var(--accent); }
.project-row .thumb { display: block; align-self: flex-start; width: 200px; height: auto; flex-shrink: 0; aspect-ratio: 1/1; object-fit: cover; border-right: 1px solid var(--line-strong); }
.project-row .fig-body { flex: 1; padding: 20px 26px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.project-row h3 { font-size: 17px; line-height: 1.35; margin: 8px 0 8px; }
.project-row p { font-size: 14px; line-height: 1.6; color: var(--muted); margin: 0; }
@media (max-width: 560px) {
  .project-row { flex-direction: column; }
  .project-row .thumb { width: 100%; border-right: none; border-bottom: 1px solid var(--line-strong); }
}

.mono-tag {
  display: inline-block; font-family: 'IBM Plex Mono', monospace; font-size: 10px;
  letter-spacing: 0.06em; color: var(--accent); border: 1px solid var(--accent-soft);
  background: var(--accent-soft); padding: 3px 8px;
}
.mono-tag-muted { color: var(--muted); border-color: var(--line); background: transparent; margin-right: 8px; }

.blog-stub-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; font-size: 14px; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line);
  padding: 22px 24px 40px;
  max-width: 1100px; margin: 0 auto;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted);
  display: flex; gap: 10px;
}
.dot { color: var(--line-strong); }

/* ---------- mascot ---------- */
.mascot {
  position: fixed; bottom: 14px; left: -80px;
  display: flex; flex-direction: column; align-items: center;
  color: var(--ink);
  z-index: 40;
  transition: left 1.8s cubic-bezier(.65, .05, .36, 1),
              bottom 2.2s cubic-bezier(.65, .05, .36, 1),
              transform 2.2s ease;
  pointer-events: none;
}
.mascot-figure { display: block; }
.mascot .leg { transform-origin: 30px 58px; }
.mascot.walking .mascot-figure { animation: mascotBob 0.5s ease-in-out infinite; }
.mascot.walking .leg-left { animation: legSwingL 0.5s ease-in-out infinite; }
.mascot.walking .leg-right { animation: legSwingR 0.5s ease-in-out infinite; }
.mascot.idle .mascot-figure { animation: mascotBreathe 2.4s ease-in-out infinite; }

@keyframes legSwingL { 0%, 100% { transform: rotate(16deg); } 50% { transform: rotate(-16deg); } }
@keyframes legSwingR { 0%, 100% { transform: rotate(-16deg); } 50% { transform: rotate(16deg); } }
@keyframes mascotBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes mascotBreathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.5px); } }

.mascot-bubble {
  pointer-events: auto;
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  margin-bottom: 10px;
  width: max-content; max-width: 220px;
  border: 1px solid var(--line-strong); background: var(--bg);
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; line-height: 1.5;
  padding: 9px 11px;
}
.mascot-bubble a { color: var(--accent); }
.mascot-bubble::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--line-strong);
}

.rocket {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  opacity: 0; z-index: -1; color: var(--ink); pointer-events: none;
  transition: opacity 0.4s ease;
}
.mascot.launching .rocket { opacity: 1; }
.mascot.launching { transform: rotate(-8deg); }
.mascot.launching .mascot-figure { opacity: 0; }
.mascot.launching .rocket .flame { animation: flicker 0.15s steps(2) infinite; }

@keyframes flicker { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }

.planet {
  position: fixed; top: 185px; right: 8.7%;
  color: var(--ink);
  opacity: 0;
  transition: opacity 1.6s ease;
  z-index: 5;
  pointer-events: none;
}
.planet.visible { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .mascot { transition: none; }
  .mascot.walking .mascot-figure,
  .mascot.walking .leg-left,
  .mascot.walking .leg-right,
  .mascot.idle .mascot-figure { animation: none; }
  .mascot.launching { transform: none; }
  .mascot.launching .mascot-figure,
  .mascot.launching .rocket .flame { animation: none; }
  .rocket { display: none; }
  .planet { transition: none; }
}

@media (max-width: 560px) {
  .mascot-figure { width: 38px; height: 64px; }
  .mascot-bubble { max-width: 160px; font-size: 10.5px; }
}

/* ---------- back link ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
  margin: 28px 0 0;
}
.back-link:hover { color: var(--accent); }

/* ---------- article (project / blog detail) ---------- */
.article-head { padding: 36px 0 28px; border-bottom: 1px solid var(--line); margin-bottom: 32px; }
.article-head .mono-tag { margin-bottom: 14px; }
.article-head h1 { font-size: clamp(26px, 4vw, 36px); margin: 0 0 10px; }
.article-head .dek { font-size: 14.5px; color: var(--muted); margin: 0; }

.article { padding-bottom: 60px; }
.article h2 { font-size: 19px; margin: 40px 0 12px; }
.article p { font-size: 14.5px; line-height: 1.7; margin: 0 0 16px; }
.article ul { font-size: 14.5px; line-height: 1.7; padding-left: 20px; margin: 0 0 16px; }
.article li { margin-bottom: 4px; }

.article-fig { margin: 28px 0; }
.article-fig img, .article-fig video { display: block; width: 100%; max-width: 620px; height: auto; margin: 0 auto; }
.article-fig figcaption { max-width: 620px; margin: 10px auto 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); text-align: center; }
.article-fig.wide img, .article-fig.wide video { max-width: 100%; }
.article-fig.wide figcaption { max-width: 100%; }

.video-embed { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--surface); }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }

.resource-list { list-style: none; padding: 0; margin: 24px 0 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.resource-list a { color: var(--accent); }
.resource-list a:hover { text-decoration: underline; }

/* ---------- listing pages (projects / blog index) ---------- */
.page-head { padding: 40px 0 8px; }
.page-head h1 { font-size: clamp(26px, 4vw, 34px); margin: 0 0 8px; }
.page-head p { font-size: 14.5px; color: var(--muted); margin: 0; }

/* ---------- cv ---------- */
.cv-block { display: grid; grid-template-columns: 180px 1fr; gap: 24px; padding: 28px 0; border-bottom: 1px solid var(--line); }
.cv-block:last-child { border-bottom: none; }
.cv-block h2 { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-family: 'IBM Plex Mono', monospace; margin: 0; font-weight: 500; }
.cv-block p { font-size: 14.5px; line-height: 1.7; margin: 0; }

.cv-cta {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  padding: 18px 24px; margin-top: 24px; margin-bottom: 8px;
}
.cv-cta > a { font-size: 16px; font-weight: 600; color: var(--accent); }
.cv-cta > a:hover { text-decoration: underline; }
.cv-cta-note { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); letter-spacing: 0.03em; }
@media (max-width: 620px) { .cv-block { grid-template-columns: 1fr; gap: 8px; } }

/* ---------- long-form report pages (SURF) ---------- */
.report-affil {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 20px 0; margin-bottom: 8px; border-bottom: 1px solid var(--line);
}
.report-affil img { height: 40px; width: auto; }
.report-affil .sep { color: var(--line-strong); }
.report-affil .meta { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.report-affil .meta strong { color: var(--ink); font-weight: 600; }

.article h3 { font-size: 16px; margin: 28px 0 10px; }
.article h4 { font-size: 14.5px; margin: 22px 0 8px; font-style: italic; font-weight: 600; }

.abstract-block {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 20px;
  margin: 24px 0 36px;
}
.abstract-block p { font-size: 14.5px; line-height: 1.7; margin: 0 0 14px; }
.abstract-block p:last-child { margin-bottom: 0; }

.fig-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 28px 0; }
.fig-pair figure { margin: 0; }
.fig-pair img, .fig-pair video { display: block; width: 100%; height: auto; }
.fig-pair figcaption { margin-top: 8px; font-size: 12px; line-height: 1.5; color: var(--muted); }
@media (max-width: 600px) { .fig-pair { grid-template-columns: 1fr; } }

.article table {
  width: 100%; border-collapse: collapse; margin: 22px 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.article table caption {
  caption-side: bottom; text-align: left; margin-top: 8px;
  font-size: 12.5px; color: var(--muted); font-family: 'IBM Plex Sans', sans-serif;
}
.article th, .article td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.article th { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line-strong); }
.article .table-scroll { overflow-x: auto; margin: 22px 0; }
.article .table-scroll table { margin: 0; }

.katex-display { margin: 18px 0 !important; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }

.toc-block { border: 1px solid var(--line); padding: 16px 20px; margin: 20px 0 32px; }
.toc-block .cap { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.toc-block ol { margin: 0; padding-left: 20px; font-size: 13.5px; line-height: 1.9; }
.toc-block a:hover { color: var(--accent); }

.cite { font-size: 0.8em; color: var(--accent); }
.cite:hover { text-decoration: underline; }

.ref-list { list-style: none; counter-reset: refnum; padding: 0; margin: 0; font-size: 13.5px; line-height: 1.7; }
.ref-list li { counter-increment: refnum; padding-left: 34px; position: relative; margin-bottom: 12px; scroll-margin-top: 90px; }
.ref-list li::before { content: "[" counter(refnum) "]"; position: absolute; left: 0; color: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.ref-list a { color: var(--accent); }
.ref-list a:hover { text-decoration: underline; }
.ref-list li:target { background: var(--accent-soft); }

/* ---------- project-row peeking mascot ---------- */
.mascot-peek {
  position: absolute; top: 50%; transform: translateY(-50%);
  pointer-events: none;
  z-index: 20;
  color: var(--ink);
}
.mascot-peek.peek-right { right: -44px; }
.mascot-peek.peek-left { left: -28px; }

.mascot-peek-figure-wrap {
  display: block;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.6s cubic-bezier(.34, 1.56, .64, 1);
}
.mascot-peek.peek-right .mascot-peek-figure-wrap { transform: translateX(-42px) translateY(10px); }
.mascot-peek.peek-left .mascot-peek-figure-wrap { transform: translateX(42px) translateY(10px); }
.project-row:hover .mascot-peek-figure-wrap { opacity: 1; transform: translateX(0) translateY(0); }

.mascot-peek-figure { display: block; }
.mascot-peek.peek-left .mascot-peek-figure { transform: scaleX(-1); }

.mascot-peek-bubble {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: max-content; max-width: 190px;
  border: 1px solid var(--line-strong); background: var(--bg);
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; line-height: 1.5;
  padding: 8px 10px;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.project-row:hover .mascot-peek-bubble { opacity: 1; transition-delay: 0.2s; }
.mascot-peek.peek-right .mascot-peek-bubble { left: 100%; margin-left: 10px; }
.mascot-peek.peek-left .mascot-peek-bubble { right: 100%; margin-right: 10px; }
.mascot-peek-bubble::after {
  content: ""; position: absolute; top: 50%; margin-top: -6px;
  border: 6px solid transparent;
}
.mascot-peek.peek-right .mascot-peek-bubble::after { right: 100%; border-right-color: var(--line-strong); }
.mascot-peek.peek-left .mascot-peek-bubble::after { left: 100%; border-left-color: var(--line-strong); }

@media (prefers-reduced-motion: reduce) {
  .mascot-peek-figure-wrap, .mascot-peek-bubble { transition: none; }
}
@media (max-width: 620px) {
  .mascot-peek { display: none; }
}
