/* Vertical kanbun typesetting. Copyright 2026 Hanpu Li; site code.
 * Set as in a Japanese 漢文 textbook: each .kanbun-column is one 句 from
 * the top; each .unit is one cell:
 *
 *   left side    character   right side
 *   saidoku      字          furigana
 *   kaeriten     punctuation okurigana
 *
 * The three tracks never share horizontal space, so readings cannot be
 * drawn over a character. A cell is as tall as its own readings, plus a
 * gap below them, so a reading never runs on beside the next character
 * and every reading stays with its own. */
.kanbun .kanbun-column {
  display:flex; flex-direction:column; align-items:center; flex:none;
  width:2.03em; writing-mode:horizontal-tb;
}
.kanbun .unit {
  display:grid; flex:none;
  grid-template-columns:.48em 1em .55em;
  grid-template-rows:.5em .5em minmax(.3em,auto);
  line-height:1;
}
/* 低二格: two empty body cells above a preface column. */
.kanbun .kanbun-indent { display:block; flex:none; width:1em; height:2.6em; }
/* A preface is smaller, and its cells are proportionally shorter. */
.kanbun .kanbun-preface .unit { font-size:.74em; }
.kanbun .kanji {
  grid-column:2; grid-row:1 / 3;
  width:1em; height:1em; text-align:center;
}
.kanbun .punctuation {
  grid-column:2; grid-row:3; align-self:start;
  writing-mode:vertical-rl; font-size:.72em; height:.6em; width:1em;
  margin-left:.39em; overflow:visible;
}
/* 句読点 sit at the character's lower right; a middle dot is centred. */
.kanbun .punctuation.dot { margin-left:.19em; }
.kanbun .side {
  display:flex; flex-direction:column;
  font-size:.5em; line-height:1;
  /* Space below a cell's readings before the next cell's begin. */
  margin-bottom:.4em;
}
.kanbun .side > * { flex:none; }
.kanbun .side-right { grid-column:3; grid-row:1 / -1; padding-left:.08em; }
.kanbun .side-right.side-sunk { grid-row:2 / -1; }
.kanbun .side-left { grid-column:1; grid-row:2 / -1; align-items:flex-end; padding-right:.08em; }
.kanbun .side-left.side-gap { grid-row:3 / -1; }
.kanbun .furigana,
.kanbun .okurigana,
.kanbun .saidoku,
.kanbun .kaeriten {
  writing-mode:vertical-rl; text-orientation:upright;
  width:1em; white-space:nowrap;
}
.kanbun .kaeriten { font-size:.86em; color:var(--kanbun-vermilion, #8a2f1d); }
/* 合符: a short rule in the gap joining a two-character word. */
.kanbun .unit.gofu::after {
  content:""; grid-column:2; grid-row:3;
  justify-self:center; width:0; border-left:1px solid currentColor;
  margin-top:-.04em; margin-bottom:-.04em;
}
