/* 風雅千載 — paper, ink and one vermilion. No web fonts: the page must load
   quickly on a school network, so it uses the reader's own Song/Ming face. */
:root {
  --paper: #f5f0e6;
  --panel: #fbf8f1;
  --ink: #1d1b18;
  --muted: #6a6358;
  --line: #d8cfbd;
  --accent: #a3301c;
  --accent-soft: #a3301c1f;
  --ping: #2c4f6e;
  --ze: #a3301c;
  --c-shi: #37566f;
  --c-ci: #a3301c;
  --c-qu: #b08a2e;
  --c-sao: #56705a;
  --k-sky: #3f6f8f;
  --k-land: #56705a;
  --k-plant: #6f8f3f;
  --k-fauna: #a8672a;
  --k-thing: #8a5a6a;
  --k-mood: #a3301c;
  --k-time: #b08a2e;
  --k-color: #6d4a8c;
  --k-place: #4a5a8c;
  --f1: #2c4f6e;
  --f2: #5f86a8;
  --f3: #8a2a1a;
  --f4: #c96a52;
  --f5: #b08a2e;
  --f6: #56705a;
  --f7: #93aa8a;
  --f8: #b9b0a0;
  --serif: "Songti TC", "Songti SC", "Noto Serif CJK TC", "Noto Serif TC", "Source Han Serif TC", "Source Han Serif SC", "PMingLiU", "SimSun", "STSong", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --wrap: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161513;
    --panel: #1e1c19;
    --ink: #ebe5d8;
    --muted: #a39b8c;
    --line: #3a362f;
    --accent: #e0694f;
    --accent-soft: #e0694f26;
    --ping: #8db4d6;
    --ze: #e0694f;
    --c-shi: #7da2c2;
    --c-ci: #e0694f;
    --c-qu: #d6b04f;
    --c-sao: #8fb096;
    --k-sky: #7fb0d0;
    --k-land: #8fb096;
    --k-plant: #a8c56a;
    --k-fauna: #d99a55;
    --k-thing: #c48fa2;
    --k-mood: #e0694f;
    --k-time: #d6b04f;
    --k-color: #a98ac9;
    --k-place: #8a9ad0;
    --f1: #6f9cc2;
    --f2: #a9c6de;
    --f3: #d0563f;
    --f4: #eda08c;
    --f5: #d6b04f;
    --f6: #7fa086;
    --f7: #b5c9ad;
    --f8: #6b655b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 0.22em; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-weight: 600; line-height: 1.3; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.7rem); letter-spacing: 0.06em; }
h2 { font-size: 1.3rem; letter-spacing: 0.04em; }
h3 { font-size: 1.08rem; }
p { margin: 0.5em 0; }
small { color: var(--muted); font-size: 0.82em; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 1.2rem 0; }
.error { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 0.6rem; background: var(--panel); padding: 0.3rem 0.8rem; z-index: 10; }
.scroll-x { overflow-x: auto; }

/* ---- shell ---- */
.top {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  max-width: var(--wrap); margin: 0 auto; padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; }
.seal {
  display: grid; place-items: center; width: 2.3rem; height: 2.3rem; background: var(--accent); color: var(--paper);
  font-size: 0.86rem; line-height: 1.05; letter-spacing: 0; writing-mode: vertical-rl; border-radius: 3px; font-weight: 700;
}
.brand-name { font-size: 1.15rem; letter-spacing: 0.2em; font-weight: 600; }
#nav { display: flex; gap: 0.2rem 1.1rem; flex-wrap: wrap; margin-left: auto; }
#nav a { text-decoration: none; padding: 0.15rem 0; border-bottom: 2px solid transparent; letter-spacing: 0.1em; }
#nav a[aria-current] { border-color: var(--accent); color: var(--accent); }
main { max-width: var(--wrap); margin: 0 auto; padding: 0 1.2rem 3rem; min-height: 70vh; outline: none; }
.bottom { max-width: var(--wrap); margin: 0 auto; padding: 1.4rem 1.2rem 5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.88rem; }

/* ---- page furniture ---- */
.hero { padding: 3.2rem 0 1.6rem; text-align: center; }
.hero h1 { font-size: clamp(2.6rem, 8vw, 4.4rem); letter-spacing: 0.3em; margin-right: -0.3em; }
.eyebrow { color: var(--accent); letter-spacing: 0.3em; font-size: 0.9rem; margin: 0 0 0.6rem; }
.sub { color: var(--muted); max-width: 40em; margin: 0.7rem auto 0; text-wrap: pretty; }
.hero .sub { margin-bottom: 1.6rem; }
.pagehead { padding: 2.2rem 0 1rem; }
.pagehead .sub { margin-left: 0; }
.block { margin: 2.4rem 0; }
.block > h2 { padding-left: 0.7rem; border-left: 4px solid var(--accent); }
.lead { color: var(--muted); max-width: 44em; margin: 0.5rem 0 1rem; text-wrap: pretty; }
.note { color: var(--muted); font-size: 0.86rem; max-width: 52em; margin-top: 0.9rem; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 0 2.4rem; align-items: start; }
.count { color: var(--muted); font-size: 0.92rem; }

.searchbox { display: flex; gap: 0.5rem; max-width: 36rem; margin: 0 auto; }
.pagehead .searchbox, .searchbox.small { margin: 0.8rem 0 0; }
.searchbox.small { max-width: 22rem; }
.searchbox input {
  flex: 1; min-width: 0; padding: 0.6rem 0.9rem; background: var(--panel); border: 1px solid var(--line); border-radius: 3px;
}
.searchbox input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
button { cursor: pointer; }
.searchbox button, .ghost {
  padding: 0.55rem 1.2rem; background: var(--accent); color: var(--paper); border: 1px solid var(--accent); border-radius: 3px; letter-spacing: 0.2em;
}
.ghost { background: none; color: var(--accent); letter-spacing: 0.08em; padding: 0.3rem 0.9rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem 0.7rem; align-items: center; margin: 0.8rem 0; }
select { padding: 0.35rem 0.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; }
.chip {
  display: inline-block; margin: 0.15rem 0.3rem 0.15rem 0; padding: 0.05rem 0.7rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); text-decoration: none; font-size: 0.93rem;
}
.chip:hover { border-color: var(--accent); }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0.5rem 0 1rem; }
.tab { padding: 0.12rem 0.75rem; background: none; border: 1px solid var(--line); border-radius: 999px; font-size: 0.93rem; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.8rem; margin: 1rem 0 0; }
.tiles > div { padding: 0.9rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.tiles dt { color: var(--muted); font-size: 0.86rem; letter-spacing: 0.2em; }
.tiles dd { margin: 0; font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.tiles dd small { margin-left: 0.25em; font-size: 0.5em; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0.8rem; }
.card { display: block; padding: 1rem 1.1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; text-decoration: none; }
.card:hover { border-color: var(--accent); color: inherit; }
.card h3 { color: var(--accent); letter-spacing: 0.2em; }
.card p { color: var(--muted); font-size: 0.93rem; margin-bottom: 0; }

/* ---- poems ---- */
.featured { padding: 1.2rem 1.4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.featured h3 { font-size: 1.3rem; }
.byline { color: var(--muted); font-size: 0.93rem; margin: 0.2rem 0 0.6rem; }
.verse p { margin: 0.15em 0; font-size: 1.12rem; letter-spacing: 0.04em; }
.results { padding-left: 2.2rem; }
.results li { padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.results li::marker { color: var(--muted); font-size: 0.85rem; }
.hitline { font-size: 1.08rem; margin: 0; }
mark { background: var(--accent-soft); color: inherit; border-bottom: 2px solid var(--accent); padding: 0 0.05em; }
.pager { display: flex; justify-content: space-between; margin: 1.2rem 0; }
.linelist, .works { padding-left: 1.3rem; margin: 0.4rem 0; }
.linelist li, .works li { padding: 0.12rem 0; }
.works { columns: 2 18rem; column-gap: 2.4rem; padding-left: 2.4rem; }
.works li { break-inside: avoid; }
.works li::marker { color: var(--muted); font-size: 0.8rem; }

.poem { margin: 2rem 0; }
.poem header h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
.toggles { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0; }
.toggle { padding: 0.15rem 0.9rem; background: none; border: 1px solid var(--line); border-radius: 999px; font-size: 0.93rem; }
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.poem-body { padding: 1.4rem 1.6rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; font-size: 1.32rem; letter-spacing: 0.08em; line-height: 2; }
.poem-body p { margin: 0; }
.poem-body.with-tones { line-height: 2.7; }
.poem-body.vertical { writing-mode: vertical-rl; max-height: 32rem; overflow-x: auto; width: 100%; line-height: 2.1; }
.poem-body.vertical.with-tones { line-height: 2.9; }
.poem-body.vertical p { margin: 0 0 0 0.5em; }
.punct { color: var(--muted); }
ruby.ch { ruby-position: under; ruby-align: center; }
.vertical ruby.ch { ruby-position: over; }
ruby.ch rt { font-size: 0.4em; letter-spacing: 0; color: var(--muted); font-family: var(--mono); }
.with-tones ruby.ping rt, .checked ruby.ping rt { color: var(--ping); }
.with-tones ruby.ze rt, .checked ruby.ze rt { color: var(--ze); }
ruby.rhyme { background: var(--accent-soft); border-radius: 2px; }
ruby.miss { outline: 1.5px solid var(--accent); outline-offset: 0; border-radius: 2px; }
ruby.img { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 0.3em; }
ruby.cat-sky { text-decoration-color: var(--k-sky); } ruby.cat-land { text-decoration-color: var(--k-land); }
ruby.cat-plant { text-decoration-color: var(--k-plant); } ruby.cat-fauna { text-decoration-color: var(--k-fauna); }
ruby.cat-thing { text-decoration-color: var(--k-thing); } ruby.cat-mood { text-decoration-color: var(--k-mood); }
ruby.cat-time { text-decoration-color: var(--k-time); } ruby.cat-color { text-decoration-color: var(--k-color); }
ruby.cat-place { text-decoration-color: var(--k-place); }
.keyline { display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem; color: var(--muted); font-size: 0.86rem; margin: 0.7rem 0; }
.k-rhyme { background: var(--accent-soft); padding: 0 0.4em; border-radius: 2px; }
.k-miss { outline: 1.5px solid var(--accent); padding: 0 0.4em; border-radius: 2px; }
.diagnosis { margin: 1rem 0; padding: 0.9rem 1.2rem; border-left: 4px solid var(--accent); background: var(--panel); }
.diagnosis ul { margin: 0.4rem 0; padding-left: 1.3rem; font-size: 0.95rem; }
.poem-foot { color: var(--muted); font-size: 0.88rem; margin-top: 0.8rem; display: flex; flex-wrap: wrap; gap: 0 1.6rem; }
.termlist { margin: 0.8rem 0; }
.bio { max-width: 46em; text-wrap: pretty; }

/* ---- charts ---- */
.bars { list-style: none; margin: 0; padding: 0; }
.bar { display: grid; grid-template-columns: 2rem minmax(5.5rem, 12rem) 1fr auto; gap: 0.6rem; align-items: center; padding: 0.16rem 0; }
.bar-rank { color: var(--muted); font-size: 0.8rem; text-align: right; font-variant-numeric: tabular-nums; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label small { margin-left: 0.5em; }
.bar-track { height: 0.62rem; background: color-mix(in srgb, var(--line) 55%, transparent); border-radius: 2px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.bar-value { font-size: 0.88rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pickable { cursor: pointer; }

.columns { display: flex; align-items: stretch; gap: 0.5rem; padding-top: 1.4rem; }
.col-link { flex: 1; min-width: 0; text-decoration: none; }
.columns > .col { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; height: 100%; text-align: center; }
.col-total { font-size: 0.72rem; color: var(--muted); height: 1.3rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-stack { flex: 1; display: flex; flex-direction: column-reverse; justify-content: flex-start; border-bottom: 1px solid var(--ink); }
.col-seg { display: block; min-height: 1px; }
.col-stack .col-seg:last-child { border-radius: 2px 2px 0 0; }
.col-label { font-size: 0.86rem; padding-top: 0.3rem; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; list-style: none; padding: 0; margin: 0.8rem 0 0; font-size: 0.86rem; color: var(--muted); }
.legend i { display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.4em; border-radius: 2px; vertical-align: -0.05em; border: 1px solid var(--line); }

.heat { border-collapse: collapse; width: 100%; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.heat th { font-weight: 400; padding: 0.2rem 0.5rem; white-space: nowrap; }
.heat thead th { color: var(--muted); font-size: 0.82rem; }
.heat tbody th { text-align: left; font-size: 1rem; }
.heat td { text-align: center; padding: 0.22rem 0.3rem; min-width: 2.9rem; background: color-mix(in srgb, var(--accent) calc(var(--a, 0) * 82%), transparent); border: 1px solid var(--paper); }
.heat td.strong { color: var(--paper); }
.heat tr.pickable:hover th, .heat tr.picked th { color: var(--accent); }
.heat tr.picked th::before { content: "▸ "; }

.linechart { width: 100%; height: auto; }
.linechart .grid { stroke: var(--line); stroke-width: 1; }
.linechart .axis { fill: var(--muted); font-size: 12px; font-family: var(--serif); }
.network { width: 100%; min-width: 640px; height: auto; }
.network .edges line { stroke: var(--muted); stroke-opacity: 0.32; }
.network .nodes g { cursor: default; outline: none; }
.network .nodes g.linked { cursor: pointer; }
.network .nodes circle { stroke: var(--paper); stroke-width: 1.5; }
.network .nodes text { fill: var(--ink); font-size: 13px; font-family: var(--serif); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
.network.focused .nodes g:not(.on) { opacity: 0.18; }
.network.focused .edges line:not(.on) { stroke-opacity: 0.05; }
.network.focused .edges line.on { stroke: var(--accent); stroke-opacity: 0.85; }
.pairs { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.1rem 1rem; list-style: none; padding: 0; font-size: 0.93rem; }

.facet { margin: 1.2rem 0; padding: 1rem 1.2rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.facet h2 { font-size: 1.1rem; }
.facet-row { display: flex; gap: 0.3rem; overflow-x: auto; }
.facet-col { flex: 1; min-width: 3.1rem; display: flex; flex-direction: column; align-items: center; text-decoration: none; font-size: 0.82rem; padding: 0.2rem 0; border-radius: 3px; }
.facet-col[aria-current] { background: var(--accent-soft); }
.facet-num { font-variant-numeric: tabular-nums; }
.facet-bar { height: 4.5rem; width: 62%; display: flex; align-items: flex-end; border-bottom: 1px solid var(--ink); }
.facet-bar i { display: block; width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; }
.facet-label { padding-top: 0.2rem; font-size: 0.9rem; white-space: nowrap; }
.facet-count { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }

/* ---- prosody ---- */
.patterns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0.8rem; }
.patterns figure, .pu-fig { margin: 0; padding: 0.8rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.pu-fig { margin-top: 0.8rem; }
figcaption { color: var(--accent); letter-spacing: 0.1em; margin-bottom: 0.4rem; font-size: 0.95rem; }
.pattern p { margin: 0; letter-spacing: 0.22em; font-size: 1.08rem; white-space: nowrap; }
.pattern.pu p { white-space: normal; letter-spacing: 0.12em; margin-bottom: 0.3rem; }
.t-p { color: var(--ping); } .t-z { color: var(--ze); } .t-x { color: var(--muted); }
.rhyme-mark { font-size: 0.6em; color: var(--paper); background: var(--accent); border-radius: 2px; padding: 0 0.25em; letter-spacing: 0; margin: 0 0.2em 0 -0.1em; vertical-align: 0.25em; }
.checker textarea { width: 100%; padding: 0.8rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; font-size: 1.1rem; line-height: 1.8; resize: vertical; }
.checked { margin: 1rem 0; font-size: 1.3rem; letter-spacing: 0.1em; line-height: 2.7; }
.checked p { margin: 0; }
.expect { margin-left: 1.2em; font-size: 0.62em; color: var(--muted); letter-spacing: 0.2em; white-space: nowrap; }
.cloud { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.7rem; line-height: 1.25; padding: 0.6rem 0; }
.cloud a { text-decoration: none; }

.plain { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.plain th, .plain td { padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.plain thead th { color: var(--muted); font-weight: 400; font-size: 0.84rem; white-space: nowrap; }
.plain tbody th { white-space: nowrap; font-weight: 600; }
.plain td.num { text-align: right; }
.editions { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1.4rem; }
.editions dt { color: var(--accent); white-space: nowrap; }
.editions dd { margin: 0; }
.prose { padding-left: 1.2rem; max-width: 50em; }
.prose li { margin: 0.5rem 0; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .top { padding: 0.7rem 0.9rem; gap: 0.5rem; }
  #nav { margin-left: 0; gap: 0.1rem 0.9rem; font-size: 0.95rem; }
  main { padding: 0 0.9rem 2.5rem; }
  .hero { padding-top: 2rem; }
  .bar { grid-template-columns: 1.5rem minmax(4.5rem, 7.5rem) 1fr auto; gap: 0.4rem; }
  .poem-body { padding: 1rem; font-size: 1.16rem; letter-spacing: 0.04em; }
  .editions { grid-template-columns: 1fr; gap: 0.1rem; }
  .editions dd { margin-bottom: 0.7rem; }
  .columns { gap: 0.2rem; }
  .col-label { font-size: 0.7rem; }
  .col-total { font-size: 0.6rem; }
  .checked { font-size: 1.1rem; }
  .expect { display: block; margin-left: 0; line-height: 1.2; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar-fill, .col-seg { transition: width 0.3s, height 0.3s; }
}
