/* ---------- tokens ----------
   Monochrome. Every text color clears WCAG AA (4.5:1) against the paper. */
:root {
  --paper: #f2e8d0;    /* papyrus */
  --ink: #231c12;      /* 14:1 */
  --muted: #4f4434;    /* 8.5:1 */
  --faint: #6a5c47;    /* 5.3:1 */
  --rule: #d4c5a3;
  --rule-strong: #9a8a6c;
  --tint: rgba(120, 85, 30, 0.07);
  --code-bg: rgba(120, 85, 30, 0.08);
  --select: #e0cc9c;
  --accent: #231c12;

  --serif: "Alegreya", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sc: "Alegreya SC", "Alegreya", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 40rem;
  --side: 10rem;
  --notes: 14rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1d1a15;
    --ink: #ece2cc;      /* 14:1 */
    --muted: #c9bea6;    /* 10:1 */
    --faint: #a39780;    /* 5.9:1 */
    --rule: #3b352b;
    --rule-strong: #6e6452;
    --tint: rgba(255, 235, 190, 0.04);
    --code-bg: rgba(255, 235, 190, 0.05);
    --select: #4a4030;
    --accent: #ece2cc;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-variant-numeric: oldstyle-nums;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--select); }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover, a:focus-visible { text-decoration-color: var(--ink); text-decoration-thickness: 2px; }

p { margin: 0 0 1em; }
b, strong { font-weight: 700; }
h1, h2, h3 { font-weight: 700; line-height: 1.25; }

.label {
  font-family: var(--sc);
  text-transform: lowercase;
  letter-spacing: 0.04em;
  color: var(--faint);
  font-size: 0.95rem;
  font-weight: 500;
}
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.mono { font-family: var(--mono); font-size: 0.75rem; }
time { font-variant-numeric: lining-nums tabular-nums; }

/* ---------- page grid ----------
   phone:   one column, header on top
   ≥ 920:   [sidebar | text]
   ≥ 1340:  [sidebar | text | margin notes]                          */
.page {
  max-width: calc(var(--side) + var(--measure) + var(--notes) + 8rem);
  margin: 0 auto;
  padding: 0 1.25rem;
}
.content { min-width: 0; }

.site-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.9rem;
  padding: 1.1rem 0 0.9rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.25rem;
}
.logo {
  font-size: 1.9rem;
  line-height: 1;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.site-title {
  font-family: var(--sc);
  letter-spacing: 0.03em;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.15;
}
.site-title br { display: none; }
.site-nav { display: flex; flex-wrap: wrap; gap: 0.1rem 1rem; width: 100%; }
.site-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 1rem;
}
.site-nav a:hover { color: var(--ink); text-decoration: underline; }

@media (min-width: 920px) {
  .page {
    display: grid;
    grid-template-columns: var(--side) minmax(0, var(--measure));
    column-gap: 4rem;
    justify-content: center;
  }
  .site-head {
    position: sticky;
    top: 0;
    align-self: start;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 4.5rem 0 2rem;
    margin: 0;
    border: 0;
  }
  .logo { font-size: 3.4rem; margin: 0 0 0.1rem -0.1rem; }
  .site-title { font-size: 1.15rem; }
  .site-title br { display: inline; }
  .site-nav {
    flex-direction: column;
    gap: 0.15rem;
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--rule);
  }
  .content { padding-top: 4.5rem; }
}
@media (min-width: 1340px) {
  .page { grid-template-columns: var(--side) minmax(0, var(--measure)) var(--notes); }
}

/* ---------- page heads ---------- */
.page-head { text-align: center; margin-bottom: 2rem; }
.page-head h1 {
  margin: 0;
  font-family: var(--sc);
  font-size: 2.2rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-wrap: balance;
}
.page-head .subtitle, .page-head .meta {
  text-align: center;
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-style: italic;
}
.meta time { font-style: normal; }
.status { font-style: normal; font-family: var(--sc); text-transform: lowercase; letter-spacing: 0.04em; }

.abstract {
  background: var(--tint);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule-strong);
  padding: 1.1rem 1.35rem 0.2rem;
  margin: 0 0 2.75rem;
}

/* ---------- sections ---------- */
section { margin-bottom: 2.75rem; scroll-margin-top: 1.5rem; }

main h2 {
  font-family: var(--sc);
  font-size: 1.4rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin: 0 0 1rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--rule-strong);
}
main h3 {
  font-size: 1.05rem;
  margin: 1.8rem 0 0.6rem;
}

@media (min-width: 720px) {
  main p, .abstract p { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
}

/* ---------- dated lists ---------- */
.entries { list-style: none; margin: 0; padding: 0; }
.entries li {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: 0 1rem;
  align-items: baseline;
  padding: 0.4rem 0;
  border-bottom: 1px dotted var(--rule);
}
.entries li:last-child { border-bottom: 0; }
.entries time { color: var(--faint); font-size: 0.9rem; }
.summary, .authors {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-top: 0.1rem;
}
.authors b { color: var(--ink); }
.papers time { font-size: 0.9rem; }

@media (max-width: 540px) {
  .entries li { grid-template-columns: 1fr; }
}

.interests { color: var(--muted); }
.interests .label { margin-right: 0.6rem; }
.more { margin-top: 0.8rem; font-size: 0.95rem; }

.contact { list-style: none; padding: 0; margin: 0; }
.contact li { display: grid; grid-template-columns: 6.2rem 1fr; gap: 1rem; padding: 0.15rem 0; }

/* ---------- articles ---------- */
article h2 { font-size: 1.3rem; margin-top: 2.4rem; }
article h3 { font-size: 1.08rem; font-style: italic; font-weight: 400; }

article blockquote {
  margin: 1.5rem 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}
article ul, article ol { padding-left: 1.4rem; }
article li { margin-bottom: 0.35rem; }
article li::marker { color: var(--faint); }
article hr { border: 0; text-align: center; margin: 2.5rem 0; }
article hr::after { content: "∴"; color: var(--faint); font-size: 1.2rem; }
article img { max-width: 100%; height: auto; display: block; margin: 1.5rem auto; }

code {
  font-family: var(--mono);
  font-size: 0.8em;
  background: var(--code-bg);
  padding: 0.08em 0.3em;
  border-radius: 3px;
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border-radius: 3px;
  line-height: 1.5;
  margin: 1.4rem 0;
}
pre code { background: none; padding: 0; font-size: 0.74rem; }
.math-display { display: block; overflow-x: auto; margin: 1rem 0; text-align: center; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule-strong);
}
.pager a { text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--ink); text-decoration: underline; }
.pager a:last-child { text-align: right; }

/* ---------- sidenotes ---------- */
main { counter-reset: sidenote; }
.sn-ref { counter-increment: sidenote; cursor: pointer; }
.sn-ref::after {
  content: counter(sidenote);
  font-size: 0.7rem;
  font-variant-numeric: lining-nums;
  vertical-align: super;
  line-height: 0;
  margin-left: 0.1rem;
  font-weight: 600;
}
.sn-toggle { display: none; }
.sidenote {
  display: none;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
  text-align: left;
}
.sidenote::before {
  content: counter(sidenote) ". ";
  font-weight: 600;
  color: var(--ink);
}
.sn-toggle:checked + .sidenote {
  display: block;
  margin: 0.6rem 0 0.8rem;
  padding: 0.6rem 0.9rem;
  background: var(--tint);
  border-left: 3px solid var(--rule-strong);
}
@media (min-width: 1340px) {
  .sn-ref { cursor: default; }
  .sidenote, .sn-toggle:checked + .sidenote {
    display: block;
    float: right;
    clear: right;
    width: var(--notes);
    margin: 0.2rem calc(-1 * var(--notes) - 3rem) 0.8rem 0;
    padding: 0 0 0 0.8rem;
    background: none;
    border-left: 1px solid var(--rule);
  }
}

/* ---------- footer + colophon ---------- */
.site-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin: 4rem 0 0;
  padding: 1rem 0 3rem;
  border-top: 1px solid var(--rule);
  color: var(--faint);
  font-size: 0.85rem;
}
.egg-hint { all: unset; cursor: pointer; }
.egg-hint:hover { color: var(--ink); }
.egg-hint:focus-visible { outline: 1px dotted var(--ink); outline-offset: 2px; }
kbd {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0 0.3em;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
}

dialog {
  max-width: min(25rem, calc(100vw - 2rem));
  padding: 1.4rem 1.6rem 1rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.55;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 10, 10, .35); }
dialog .label { display: block; margin: 0 0 0.6rem; }
dialog .small { margin: 1.1rem 0 0; }
dialog[open] { animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- vault ---------- */
dialog.vault { width: min(30rem, calc(100vw - 2rem)); max-width: none; }
.vault-intro { color: var(--muted); font-style: italic; }
.vault input {
  width: 100%;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--ink);
  outline: none;
}
.vault input:focus { border-color: var(--accent); }
.vault-status { min-height: 1.2em; color: var(--accent); margin: 0.6rem 0 0; }
.vault .entries { max-height: 55vh; overflow-y: auto; margin-bottom: 1rem; }
.vault .entries a.busy { color: var(--faint); cursor: progress; }
.vault-lock { all: unset; cursor: pointer; font-family: var(--mono); font-size: 0.62rem; text-decoration: underline; text-decoration-color: var(--rule); }
.vault-lock:hover { color: var(--accent); }
/* reader mode: a file open inside the vault */
dialog.vault.reading {
  width: min(56rem, calc(100vw - 1.5rem));
  height: min(92vh, 100dvh - 1.5rem);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.v-bar {
  margin: 0 !important;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
}
.v-bar .v-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.v-bar a { text-decoration: none; color: var(--muted); }
.v-bar a:hover { color: var(--accent); }
.v-stage { flex: 1; min-height: 0; overflow: auto; padding: 1.4rem 1.6rem 2rem; }
.v-stage:has(> .v-frame) { padding: 0; overflow: hidden; }
.v-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.v-pdf { max-width: 48rem; margin: 0 auto; }
.v-page { aspect-ratio: var(--ratio, 8.5 / 11); background: #fff; margin: 0 auto 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.v-page canvas { width: 100%; height: 100%; display: block; }
.v-pages { text-align: center; }
.v-media { display: grid; place-items: center; min-height: 100%; }
.v-media img, .v-media video { max-width: 100%; max-height: 78vh; border-radius: 3px; }
.v-media audio { width: min(100%, 28rem); }

.v-prose { max-width: var(--measure); margin: 0 auto; font-size: 1rem; }
.v-prose h1, .v-prose h2, .v-prose h3 { font-weight: 500; line-height: 1.25; margin: 1.8rem 0 0.6rem; }
.v-prose h1 { font-size: 1.5rem; font-weight: 400; }
.v-prose img { max-width: 100%; }
.v-prose table, .v-table table { border-collapse: collapse; font-size: 0.8rem; }
.v-prose td, .v-prose th { border: 1px solid var(--rule); padding: 0.25rem 0.5rem; }

.v-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.7rem; background: none; padding: 0; }
.v-table { overflow: auto; }
.v-table table { font-family: var(--mono); font-size: 0.66rem; white-space: nowrap; }
.v-table th { position: sticky; top: -1.4rem; background: var(--paper); text-align: left; font-weight: 500; }
.v-table th, .v-table td { border-bottom: 1px solid var(--rule); padding: 0.3rem 0.9rem 0.3rem 0; }
.v-table section + section { margin-top: 2rem; }

.v-notebook { max-width: 46rem; margin: 0 auto; }
.v-notebook img { max-width: 100%; display: block; margin: 0.5rem 0 1rem; background: #fff; }
.v-cell { position: relative; }
.v-prompt { position: absolute; right: calc(100% + 0.5rem); top: 0.95rem; font-size: 0.58rem; color: var(--faint); }
.v-code { margin: 0.8rem 0 0.4rem; }
.v-out { margin: 0 0 1rem; background: none; border-left: 2px solid var(--rule); border-radius: 0; padding: 0.2rem 0 0.2rem 0.9rem; font-size: 0.66rem; }
.v-err { color: var(--accent); }
.v-out-html { overflow-x: auto; font-size: 0.8rem; margin-bottom: 1rem; }
.v-empty { text-align: center; padding-top: 18vh; color: var(--muted); }
@media (max-width: 900px) { .v-prompt { position: static; display: block; margin-top: 0.8rem; } }

.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  dialog[open], .shake { animation: none; }
}

@media print {
  .site-head, .site-foot, .pager { display: none; }
  .page { display: block; }
  .sidenote { display: inline; font-size: .85em; }
  .sidenote::before { content: " [" counter(sidenote) ": "; }
  .sidenote::after { content: "]"; }
}
