:root {
  --bg: #ffffff;
  --paper: #f6f6f5;
  --ink: #212121;
  --muted: #5e5e5e;
  --line: #e6e6e6;
  --accent: #1f4e3d;
  --accent-soft: #e7f2ec;
  --serif: "Newsreader", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --frame: 48.5rem;
  --pad: 1.15rem;
  color-scheme: light;
}

[data-accent="forest"] { --accent: #1f4e3d; --accent-soft: #e7f2ec; }
[data-accent="ink"] { --accent: #1e3a5f; --accent-soft: #e8eef5; }
[data-accent="wine"] { --accent: #7a3142; --accent-soft: #f8ebee; }
[data-accent="clay"] { --accent: #8a4b2f; --accent-soft: #f8f0ea; }

[data-mode="dark"] {
  --bg: #161513;
  --paper: #221f1c;
  --ink: #f3efe8;
  --muted: #c4bbb0;
  --line: #3a342e;
  color-scheme: dark;
}

[data-mode="dark"][data-accent="forest"] { --accent: #9dcebb; --accent-soft: #1c332c; }
[data-mode="dark"][data-accent="ink"] { --accent: #a9c4e4; --accent-soft: #1c2836; }
[data-mode="dark"][data-accent="wine"] { --accent: #e7b3be; --accent-soft: #3a2429; }
[data-mode="dark"][data-accent="clay"] { --accent: #e2c0ab; --accent-soft: #3a2c24; }

[data-density="compact"] { --pad: 0.8rem; }
[data-density="airy"] { --pad: 1.65rem; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--bg);
  padding: 0.4rem 0.7rem;
  z-index: 50;
}
.skip:focus { top: 0.6rem; }

.frame,
.page,
.studio-shell {
  width: min(var(--frame), calc(100% - 2.5rem));
  margin-inline: auto;
}
body[data-page="studio"] { --frame: 76rem; }
.page { padding: 2.15rem 0 4.2rem; }
.studio-shell { padding: 1.15rem 0 2.4rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  min-height: 3.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.2rem;
  letter-spacing: -0.015em;
  color: inherit;
  text-decoration: none;
}
.nav-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.95rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-list a,
.lang-btn {
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.nav-list a:hover,
.lang-btn:hover,
.nav-list a[aria-current="page"] { color: var(--accent); }
.menu-btn {
  display: none;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  background: transparent;
  padding: 0;
  place-items: center;
  gap: 5px;
  cursor: pointer;
}
.menu-btn span {
  display: block;
  width: 1.15rem;
  height: 1.5px;
  background: var(--ink);
}

.identity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.25rem 2rem;
  align-items: center;
  margin-bottom: 1.6rem;
}
.identity h1 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: clamp(2.05rem, 4.6vw, 2.75rem);
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0 0 0.35rem;
}
.role { margin: 0; color: var(--muted); }
.portrait {
  width: 9.25rem;
  height: 9.25rem;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 18%;
  background: var(--accent-soft);
}
.portrait.fallback {
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 1.8rem;
  color: var(--accent);
}
.social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.95rem;
}
.social-sq {
  height: 2.55rem;
  min-width: 3.15rem;
  padding: 0 0.7rem;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
}
.social-sq svg { width: 1.4rem; height: 1.4rem; display: block; }
.social-mark {
  font-size: 0.84rem;
  font-weight: 680;
  letter-spacing: 0.06em;
  line-height: 1;
}
.social-sq:hover,
.social-sq:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.subhead {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  margin: 2rem 0 0.55rem;
}
.subhead-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.subhead-row .subhead { margin-bottom: 0.35rem; }
.subhead-row a { color: var(--accent); text-decoration: none; }
.subhead-row a:hover { text-decoration: underline; }

.reading { font-size: 1.08rem; line-height: 1.7; }
.reading p { margin: 0.55rem 0; }
.reading a { color: var(--accent); }
.reading ul,
.reading ol { margin: 0.45rem 0; padding-left: 1.2rem; }
.reading li + li { margin-top: 0.4rem; }
.about .subhead:first-child { margin-top: 0.2rem; }

.news { list-style: none; margin: 0; padding: 0; }
.news li {
  display: grid;
  grid-template-columns: 7.2rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}
.news-k { color: var(--accent); }
.news a { color: inherit; }
.news-meta { display: block; color: var(--muted); }

.interests { list-style: none; margin: 0; padding: 0; }
.interests li {
  padding: 0.28rem 0 0.28rem 0.85rem;
  border-left: 2px solid var(--accent-soft);
}
.interests li + li { margin-top: 0.35rem; }

.contact p { margin: 0.35rem 0; }
.contact a { color: var(--accent); }
.label { color: var(--muted); }

.page-head { margin: 0.2rem 0 1.1rem; }
.page-head h1 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: clamp(2rem, 4vw, 2.6rem);
  letter-spacing: -0.03em;
  line-height: 1.12;
  margin: 0;
}
.back {
  display: inline-block;
  margin: 0 0 1rem;
  color: var(--muted);
  text-decoration: none;
}
.back:hover { color: var(--accent); }
.lede {
  font-size: 1.12rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0.55rem 0 0;
}

.filters { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; margin-bottom: 0.3rem; }
.filter {
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.15rem 0;
  cursor: pointer;
}
.filter.is-on { color: var(--ink); border-bottom-color: var(--accent); }

.year-block {
  display: grid;
  grid-template-columns: 4.8rem minmax(0, 1fr);
  gap: 0.3rem 1.2rem;
  padding: var(--pad) 0;
  border-top: 1px solid var(--line);
}
.year-block.named { grid-template-columns: 1fr; }
.year-label {
  margin: 0.1rem 0 0;
  font-size: 1.02rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.named .year-label {
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 560;
  margin-bottom: 0.35rem;
}
.entry + .entry { margin-top: 1.15rem; }
.year-block .entry {
  display: block;
  font-size: 1rem;
  padding: 0.75rem 0 0;
}
.bib-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 2.6rem;
  align-items: start;
}
.bib-group { margin-bottom: 1.8rem; }
.bib-group:last-child { margin-bottom: 0; }
.bib-cat {
  margin: 0 0 0.15rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 560;
}
.bib-list .entry {
  display: block;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
}
.bib-list .entry:last-child { border-bottom: 0; }
.bib-list .entry + .entry { margin-top: 0; }
.entry-title {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.12rem;
  line-height: 1.35;
  letter-spacing: -0.015em;
  margin: 0 0 0.15rem;
}
.title-index {
  flex: none;
  color: var(--accent);
  font-weight: 650;
}
.title-sep {
  flex: none;
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.92rem;
}
.title-text { flex: 1; min-width: 0; }
.entry-title a { color: inherit; text-decoration: none; }
.entry-title a:hover { color: var(--accent); }
.entry-meta { margin: 0; color: var(--muted); }
.entry-meta em { font-style: italic; }
.entry-meta strong { color: var(--ink); font-weight: 600; }
.kind {
  margin: 0 0 0.15rem;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.45rem; }
.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 0.02rem 0.38rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
}
.chip:hover,
.chip[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.fold { margin-top: 0.65rem; }
.fold pre {
  margin: 0.55rem 0 0;
  padding: 0.75rem 0.85rem;
  background: var(--paper);
  border-radius: 8px;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.theme,
.project-row,
.course { border-top: 1px solid var(--line); }
.theme { padding: 0.9rem 0; }
.theme h3,
.course h3,
.project-title,
.block h2,
.paper-title {
  font-family: var(--serif);
  font-weight: 560;
  letter-spacing: -0.02em;
}
.theme h3 { font-size: 1.28rem; margin: 0 0 0.28rem; }
.theme p { margin: 0; }
.project-row {
  display: grid;
  grid-template-columns: 2.3rem minmax(0, 1fr);
  gap: 0.7rem;
  padding: 0.95rem 0;
  color: inherit;
  text-decoration: none;
}
.project-title { display: block; font-size: 1.28rem; line-height: 1.3; }
.project-row:hover .project-title { color: var(--accent); }
.project-summary { display: block; color: var(--muted); margin-top: 0.22rem; }
.idx { color: var(--accent); font-variant-numeric: tabular-nums; padding-top: 0.22rem; }

.inst { margin-top: 1.4rem; }
.inst-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem;
}
.inst-head h2 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.45rem;
  margin: 0;
}
.inst-head p { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.semester { margin: 1rem 0 0; color: var(--muted); font-weight: 600; }
.course { padding: 0.75rem 0; }
.course h3 { font-size: 1.18rem; margin: 0 0 0.2rem; }
.course p { margin: 0.08rem 0; color: var(--muted); }
.course p span { color: var(--ink); }

.block h2 { font-size: 1.4rem; margin: 1.7rem 0 0.45rem; }
.math-display { overflow-x: auto; margin: 0.85rem 0; text-align: center; }
.figure { margin: 1rem 0; }
.size-small { max-width: 16rem; }
.size-medium { max-width: 36rem; }
.size-large,
.size-full { max-width: 100%; }
figcaption { color: var(--muted); font-size: 0.92rem; margin-top: 0.4rem; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  align-items: start;
}
.fig-fallback {
  min-height: 5.5rem;
  display: grid;
  place-items: center;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  background: var(--paper);
  border-radius: 8px;
}
.video { position: relative; padding-top: 56.25%; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-file { width: 100%; }

.font-serif { font-family: var(--serif); }
.font-sans { font-family: var(--sans); }
.font-mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.math-sans .katex,
.math-sans .katex * { font-family: var(--sans) !important; }
.size-s { font-size: 0.98rem; }
.size-m { font-size: 1.06rem; }
.size-l { font-size: 1.16rem; }
.size-xl { font-size: 1.28rem; }

.colophon { border-top: 1px solid var(--line); padding: 1.1rem 0 1.6rem; color: var(--muted); font-size: 0.95rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.colophon p { margin: 0; }
.colophon a { color: var(--muted); }
.fine { display: flex; gap: 0.8rem; flex-wrap: wrap; }

.studio {
  display: grid;
  grid-template-columns: minmax(22rem, 32rem) minmax(0, 1fr);
  gap: 1.15rem;
  align-items: start;
}
.studio-form {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1rem 1.3rem;
}
.studio-form h1 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}
.studio-lead,
.hint { color: var(--muted); font-size: 0.95rem; margin: 0.2rem 0 0.7rem; }
.studio-status { min-height: 1.3em; margin: 0.2rem 0 0.4rem; color: var(--accent); font-size: 0.92rem; }
.studio-actions,
.preview-switch { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.btn,
.file-btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.32rem 0.8rem;
  cursor: pointer;
  text-decoration: none;
}
[data-mode="dark"] .btn,
[data-mode="dark"] .file-btn { color: #1a1814; }
.btn.ghost,
.file-btn.ghost {
  background: transparent;
  color: var(--accent);
}
fieldset {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.85rem 0 0;
  padding: 0.7rem 0 0;
}
legend {
  padding: 0;
  font-size: 0.74rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}
.check,
.order-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.22rem 0;
}
.order-item .check { flex: 1; padding: 0; }
.order-item span { flex: 1; }
.mini {
  width: 1.55rem;
  height: 1.55rem;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 5px;
  cursor: pointer;
}
.choice { display: flex; flex-wrap: wrap; gap: 0.45rem 0.8rem; margin: 0.3rem 0 0.5rem; }
.choice label { display: inline-flex; gap: 0.3rem; align-items: center; }
select,
textarea,
input[type="text"],
input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.28rem 0.45rem;
  width: 100%;
}
textarea { min-height: 6.2rem; resize: vertical; }
.studio-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.2rem 0 0.8rem; }
.studio-tabs button.is-on { background: var(--accent); color: #fff; }
[data-mode="dark"] .studio-tabs button.is-on { color: #1a1814; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.entry {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.28rem 0;
  font-size: 0.92rem;
}
.mini-text {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}
.color {
  width: 2.7rem;
  height: 1.9rem;
  padding: 0.12rem;
  margin: 0 0 0.55rem;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 7px;
}
.local-note { max-width: 36rem; }
.studio-form [hidden] { display: none !important; }
.field { display: grid; gap: 0.2rem; margin: 0.45rem 0; }
.swatches { display: flex; gap: 0.55rem; margin: 0.35rem 0 0.2rem; }
.swatch {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.swatch input { position: absolute; opacity: 0; }
.swatch:has(input:checked) { outline: 2px solid var(--ink); outline-offset: 2px; }
details { margin-top: 0.35rem; }
summary { cursor: pointer; }
.item-note { color: var(--muted); font-size: 0.85rem; }
.preview-col { position: sticky; top: 4.5rem; }
.preview-switch { margin-bottom: 0.45rem; }
.preview-switch button.is-on { background: var(--accent); color: #fff; }
[data-mode="dark"] .preview-switch button.is-on { color: #1a1814; }
.preview-frame {
  height: calc(100vh - 8.2rem);
  min-height: 28rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.preview-frame iframe { width: 100%; height: 100%; border: 0; background: #fff; }

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

@media (max-width: 820px) {
  .menu-btn { display: inline-grid; }
  .topbar-inner { position: relative; }
  .nav-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.55rem;
    padding: 0.4rem 0 0.9rem;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }
  .nav-list.open { display: flex; }
  .identity { grid-template-columns: 1fr; }
  .portrait { order: -1; width: 7.2rem; height: 7.2rem; }
  .news li,
  .year-block,
  .bib-layout { grid-template-columns: 1fr; gap: 0.2rem; }
  .footer-inner { flex-direction: column; }
}

@media (max-width: 980px) {
  .studio { grid-template-columns: 1fr; }
  .preview-col { position: static; }
  .preview-frame { height: 70vh; }
}

@media print {
  .topbar, .colophon, .chips, .filters, .menu-btn { display: none !important; }
  .page { width: auto; }
  body { background: #fff; color: #000; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
