/* Fabrizio Pregadio — site stylesheet
   Layout: a fixed left column (portrait, seal, navigation, contact) beside a
   single reading column; on phones the two stack and the navigation wraps. */

:root {
  --paper:   #f8f7f3;   /* page ground */
  --leaf:    #efede6;   /* sidebar ground */
  --ink:     #1f2328;   /* body text */
  --ink-2:   #5b6068;   /* secondary text */
  --rule:    #d9d5ca;   /* hairlines */
  --indigo:  #2b4a6f;   /* links */
  --cinnabar:#b23a26;   /* seal, active page */

  --serif:   "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --display: "EB Garamond", Garamond, "Times New Roman", serif;
  --han:     "Noto Serif TC", "Songti TC", "PMingLiU", "Noto Serif SC", serif;

  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:#16181b; --leaf:#1c1f23; --ink:#e6e3dc; --ink-2:#a3a7ad;
    --rule:#33373d; --indigo:#9dbbe0; --cinnabar:#e0705a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper:#16181b; --leaf:#1c1f23; --ink:#e6e3dc; --ink-2:#a3a7ad;
  --rule:#33373d; --indigo:#9dbbe0; --cinnabar:#e0705a; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.65 var(--serif);
  font-optical-sizing: auto;
}
img { max-width: 100%; height: auto; display: block; }
:lang(zh), .han { font-family: var(--han); font-style: normal; }

a { color: var(--indigo); text-decoration: underline; text-decoration-thickness: 1px;
    text-underline-offset: 0.18em; text-decoration-color: color-mix(in srgb, var(--indigo) 40%, transparent); }
a:hover { text-decoration-color: currentColor; }
a:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; border-radius: 2px; }

/* ---------- page frame ---------- */
.page {
  display: grid;
  grid-template-columns: minmax(15rem, 19rem) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- sidebar ---------- */
.side {
  background: var(--leaf);
  border-right: 1px solid var(--rule);
  padding: 3rem 2rem 2.5rem;
  display: flex; flex-direction: column; gap: 2rem;
}
.side__inner { position: sticky; top: 2.5rem; display: flex; flex-direction: column; gap: 2rem; }

.side__head  { display: flex; flex-direction: column; gap: 1.5rem; }
.side__extra { display: flex; flex-direction: column; gap: 1.75rem; }

.portrait { width: 100%; max-width: 13rem; aspect-ratio: 4 / 5; object-fit: cover;
            border: 1px solid var(--rule); filter: grayscale(15%); }

.name { display: flex; align-items: flex-start; gap: 0.9rem; }
.name h1, .name .site-name {
  margin: 0; font: 500 1.9rem/1.1 var(--display); letter-spacing: 0.01em;
  text-wrap: balance;
}
.name p { margin: 0.35rem 0 0; color: var(--ink-2); font-size: 0.9rem; line-height: 1.4; }

/* the seal: style name 玄英 in a square vermilion stamp */
.seal {
  flex: none; width: 2.6rem; height: 2.6rem; margin-top: 0.2rem;
  display: grid; place-items: center;
  border: 2px solid var(--cinnabar); border-radius: 3px;
  color: var(--cinnabar); font: 600 0.95rem/1 var(--han);
  writing-mode: vertical-rl; letter-spacing: 0.05em;
}

.nav { border-top: 1px solid var(--rule); padding-top: 1.25rem; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.nav a { color: var(--ink); text-decoration: none; font: 1.12rem/1.3 var(--display); }
.nav a:hover { color: var(--indigo); }
.nav a[aria-current="page"] { color: var(--cinnabar); }
.nav a[aria-current="page"]::before { content: "▪ "; font-size: 0.8em; }

.side h2 {
  margin: 0 0 0.5rem; font: 600 0.72rem/1.2 var(--serif);
  text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2);
}
.side ul.plain { list-style: none; margin: 0; padding: 0; font-size: 0.95rem; display: flex; flex-direction: column; gap: 0.3rem; }
.side .muted { color: var(--ink-2); font-size: 0.85rem; }

/* ---------- main column ---------- */
.main { padding: 4.5rem clamp(1.25rem, 5vw, 4.5rem) 3rem; min-width: 0; }
.main > * { max-width: 40rem; }

.lede {
  margin: 0 0 3rem; font: italic 400 1.35rem/1.5 var(--display); color: var(--ink);
  text-wrap: pretty;
}

.section { margin-bottom: 2.75rem; }
.section > h2 {
  margin: 0 0 1rem; font: 500 1.5rem/1.2 var(--display);
  display: flex; align-items: baseline; gap: 0.75rem;
}
.section > h2::after { content: ""; flex: 1; border-bottom: 1px solid var(--rule); transform: translateY(-0.3em); }
.section p { margin: 0 0 1.05rem; hyphens: auto; }

.interests { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.45rem; }
.interests li { padding-left: 1.2rem; position: relative; }
.interests li::before { content: ""; position: absolute; left: 0; top: 0.68em; width: 0.4rem; height: 0.4rem; background: var(--cinnabar); }

/* small note for gloss of Chinese terms */
.gloss { color: var(--ink-2); }

.foot {
  margin-top: 3.5rem; padding-top: 1.25rem; border-top: 1px solid var(--rule);
  font-size: 0.82rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem;
}

/* ---------- inner pages ---------- */
.name .site-name { display: block; color: var(--ink); text-decoration: none; }
.name .site-name:hover { color: var(--indigo); }

.page-head { margin: 0 0 2.75rem; }
.page-head h1 {
  margin: 0; font: 500 2.6rem/1.1 var(--display); letter-spacing: 0.005em; text-wrap: balance;
}
.page-head .han-title { display: block; margin-top: 0.35rem; font: 400 1.25rem/1.3 var(--han); color: var(--ink-2); letter-spacing: 0.15em; }

.note {
  display: inline-block; margin: 1rem 0 0; padding: 0.15rem 0.6rem;
  border: 1px solid var(--rule); border-radius: 2px;
  font: italic 0.95rem/1.5 var(--display); color: var(--ink-2);
}

/* a list of links to texts, indexes, resources — same red square as the home page */
.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.entries > li { padding-left: 1.2rem; position: relative; min-width: 0; }
.entries > li::before { content: ""; position: absolute; left: 0; top: 0.68em; width: 0.4rem; height: 0.4rem; background: var(--cinnabar); }
.entries .muted-item { color: var(--ink-2); font-style: italic; }
.entries .han { color: var(--ink-2); font-size: 0.95em; letter-spacing: 0.05em; }
.entries .kind { color: var(--ink-2); font-size: 0.9rem; }

/* ---------- publications page ---------- */
.intro { margin: 1rem 0 0; color: var(--ink-2); }
.toc { margin-top: 1.25rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem;
       font: 1.1rem/1.3 var(--display); }
.toc a { text-decoration: none; }
.toc a::before { content: "↓ "; color: var(--ink-2); font-size: 0.85em; }
.section > h2 .han, .section h3 .han { font-size: 0.8em; color: var(--ink-2); letter-spacing: 0.05em; }
.h-gloss { font-size: 0.75em; color: var(--ink-2); font-style: italic; }
.section h3 {
  margin: 2rem 0 0.9rem; font: 600 0.78rem/1.3 var(--serif);
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-2);
}
.section h3 i { text-transform: none; font-size: 1.15em; letter-spacing: 0.02em; }
.section h3 .han { font-size: 1.1em; }
.section, .section h3 { scroll-margin-top: 1.5rem; }
.biblio { gap: 1.1rem; }
.biblio > li { line-height: 1.55; }
.biblio .aside { color: var(--ink-2); font-size: 0.93em; }
.biblio .access { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.6rem;
                  margin-top: 0.35rem; font-size: 0.85rem; color: var(--ink-2); }
.biblio .access a {
  font-weight: 600; font-size: 0.78rem; letter-spacing: 0.04em; text-decoration: none;
  padding: 0.05rem 0.45rem; border: 1px solid color-mix(in srgb, var(--indigo) 35%, transparent); border-radius: 2px;
}
.biblio .access a:hover { background: color-mix(in srgb, var(--indigo) 10%, transparent); }

/* ---------- phones and narrow windows ---------- */
@media (max-width: 52rem) {
  .page { grid-template-columns: minmax(0, 1fr); }
  .side { border-right: 0; border-bottom: 1px solid var(--rule); padding: 1.75rem 1.25rem 1.5rem; }
  .side__inner { position: static; gap: 1.5rem; }
  .side__head { display: flex; gap: 1.1rem; align-items: center; }
  .portrait { width: 5.5rem; flex: none; aspect-ratio: 1; border-radius: 50%; }
  .name h1, .name .site-name { font-size: 1.6rem; }
  .nav { padding-top: 1rem; }
  .nav ul { flex-direction: row; flex-wrap: wrap; gap: 0.4rem 1.25rem; }
  .side__extra { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1.25rem; }
  .main { padding: 2.25rem 1.25rem 2rem; }
  .lede { font-size: 1.2rem; margin-bottom: 2.25rem; }
  .page-head { margin-bottom: 2rem; }
  .page-head h1 { font-size: 2rem; }
  body { font-size: 1rem; }
}

@media print {
  .page { display: block; }
  .side { background: none; border: 0; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- index pages (collections of texts) ----------
   Wide screens: a real five-column table with a sticky header, lodge headings
   as full-width bands. Phones: each row becomes a compact entry card-less block. */
.main.wide > * { max-width: none; }
.main.wide > .page-head, .main.wide > .prose { max-width: 44rem; }

.prose p { margin: 0 0 1rem; }

.abbr { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.95rem; }
.abbr dt { font: 600 0.85rem/1.6 var(--serif); letter-spacing: 0.06em; color: var(--cinnabar); }
.abbr dd { margin: 0; color: var(--ink-2); }

.lodge-nav { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0 0 2rem; }
.lodge-nav a {
  display: grid; place-items: center; min-width: 2.4rem; padding: 0.25rem 0.35rem;
  border: 1px solid var(--rule); border-radius: 2px; text-decoration: none;
  color: var(--ink); line-height: 1.1; font-size: 0.7rem; font-variant-numeric: tabular-nums;
}
.lodge-nav a span { font: 1rem/1.2 var(--han); }
.lodge-nav a:hover { border-color: var(--cinnabar); color: var(--cinnabar); }

.table-wrap { overflow-x: auto; }
.ix { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.ix th, .ix td { text-align: left; vertical-align: baseline; padding: 0.42rem 0.75rem 0.42rem 0; }
.ix thead th {
  position: sticky; top: 0; z-index: 1; background: var(--paper);
  font: 600 0.72rem/1.2 var(--serif); text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-2);
  border-bottom: 1px solid var(--ink-2); padding-top: 0.7rem;
}
.ix tbody tr:not(.lodge) td { border-bottom: 1px solid var(--rule); }
.ix tbody tr:not(.lodge):hover td { background: color-mix(in srgb, var(--cinnabar) 5%, transparent); }
.ix .no { width: 4rem; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.ix tr.sub .no { padding-left: 0.9rem; font-size: 0.88em; }
.ix .ti { font: 1.08rem/1.5 var(--han); color: var(--ink); }
.ix .at { font-family: var(--han); color: var(--ink); white-space: nowrap; }
.ix .at .anon { font-family: var(--serif); font-style: italic; color: var(--ink-2); }
.ix .ft { font-family: var(--han); color: var(--ink-2); }
.ix .re { font-size: 0.82rem; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ix .nref { margin-left: 0.3rem; font: 600 0.68rem/1 var(--serif); color: var(--cinnabar); text-decoration: none; vertical-align: super; }

.ix tr.lodge td { padding: 2rem 0 0.6rem; border-bottom: 1px solid var(--ink-2); }
.ix tr.lodge h2 { margin: 0; font: 500 1.4rem/1.2 var(--display); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.75rem; }
.ix tr.lodge h2 .han { font: 1.1rem/1 var(--han); color: var(--cinnabar); }
.ix tr.lodge p { margin: 0.3rem 0 0; font-size: 0.95rem; color: var(--ink-2); max-width: 44rem; }
.ix tr.lodge, .ix tr[id] { scroll-margin-top: 3rem; }

.notes { margin-top: 3rem; }
.notes ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; font-size: 0.95rem; }
.notes li { display: grid; grid-template-columns: 3.5rem 1fr; gap: 0.75rem; scroll-margin-top: 2rem; }
.notes li > a:first-child { font-variant-numeric: tabular-nums; color: var(--cinnabar); text-decoration: none; }
.notes li:target { background: color-mix(in srgb, var(--cinnabar) 8%, transparent); }

@media (max-width: 52rem) {
  .ix, .ix tbody { display: block; }
  .ix thead { display: none; }
  .ix tr { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); column-gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid var(--rule); }
  .ix tbody tr:not(.lodge) td { border: 0; padding: 0; }
  .ix .no { grid-row: 1 / span 3; width: auto; padding: 0.2rem 0 0; }
  .ix tr.sub .no { padding-left: 0.5rem; }
  .ix .ti, .ix .at, .ix .ft, .ix .re { grid-column: 2; white-space: normal; }
  .ix .at { font-size: 0.9rem; }
  .ix .ft { font-size: 0.88rem; }
  .ix .ft:empty { display: none; }
  .ix .ft::before { content: "Full title: "; font: italic 0.8rem var(--serif); }
  .ix .re { margin-top: 0.15rem; }
  .ix tr.lodge { display: block; border-bottom: 1px solid var(--ink-2); padding: 1.75rem 0 0.5rem; }
  .ix tr.lodge td { display: block; padding: 0; border: 0; }
  .notes li { grid-template-columns: 2.8rem 1fr; }
}
.crumb { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--ink-2); }
h2.mini { margin: 2rem 0 0.75rem; font: 600 0.72rem/1.2 var(--serif); text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); }
.placeholder { color: var(--ink-2); font-style: italic; }
.after-list { margin-top: 1.5rem; }
.ix tr.extra .no { color: var(--ink-2); }
.view-tip {
  margin: 0 0 1rem; padding: 0.45rem 0.8rem; max-width: 44rem;
  border-left: 3px solid var(--cinnabar); background: var(--leaf);
  font: italic 0.95rem/1.45 var(--display); color: var(--cinnabar);
}
@media (max-width: 52rem) { .view-tip { display: none; } }  /* phones get the stacked layout instead */
.ix .lacuna { font-size: 1.1em; line-height: 1; }
.ix tr.sub2 .no { padding-left: 1.8rem; }
@media (max-width: 52rem) { .ix tr.sub2 .no { padding-left: 1rem; } }

/* ---------- Cantong qi: commentaries and editions ----------
   Each commentary is an entry: a reproduced page on the left, notes on the right;
   on phones the picture sits above the text at a modest size. */
.h-sub { font-size: 0.6em; color: var(--ink-2); font-style: normal; }
.page-head .part { margin: 0.9rem 0 0; font: 600 0.78rem/1.3 var(--serif); text-transform: uppercase; letter-spacing: 0.14em; color: var(--cinnabar); }

.ed-toc { display: flex; flex-wrap: wrap; gap: 0.3rem 1.4rem; margin: 0 0 2.5rem; font: 1.05rem/1.3 var(--display); }
.ed-toc a { text-decoration: none; }

.ed {
  display: grid; grid-template-columns: 11rem minmax(0, 1fr); column-gap: 2rem;
  padding: 2.25rem 0 0.5rem; border-top: 1px solid var(--rule); scroll-margin-top: 1.5rem;
}
.main > .ed { max-width: 48rem; }
.ed h2 { grid-column: 1 / -1; margin: 0 0 1.25rem; font: 500 1.5rem/1.25 var(--display); text-wrap: balance; }
.ed h2 [lang="zh"] { font-size: 0.8em; }
.ed-no { color: var(--cinnabar); font-variant-numeric: tabular-nums; margin-right: 0.15rem; }
.ed-attr { color: var(--ink-2); font-size: 0.8em; }

.ed-fig { margin: 0; align-self: start; }
.ed-fig img { width: 100%; max-width: 225px; height: auto; border: 1px solid var(--rule); background: #fff; }
.ed-fig figcaption { margin-top: 0.45rem; font-size: 0.82rem; line-height: 1.4; color: var(--ink-2); }

.ed-body { min-width: 0; }
.ed-body p { margin: 0 0 1rem; hyphens: auto; }
.ed-body .ed-title { margin: 0; font: 500 1.12rem/1.4 var(--display); }
.ed-body .ed-eng { margin: 0.1rem 0 1.1rem; color: var(--ink-2); }
.ed-body .ed-ref {
  margin-top: 1.25rem; padding-top: 0.6rem; border-top: 1px dotted var(--rule);
  font-size: 0.88rem; color: var(--ink-2);
}
.ed-body .ed-ref::before { content: "See "; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); font: 1.1rem/1.3 var(--display); max-width: 48rem; }
.pager a { text-decoration: none; }

@media (max-width: 40rem) {
  .ed { grid-template-columns: minmax(0, 1fr); }
  .ed-fig { margin-bottom: 1.25rem; }
  .ed-fig img { max-width: 11rem; }
}
