:root {
  --accent: #7a1f1f;
  --bg: #fbfaf7;
  --sidebar-bg: #f1efe9;
  --border: #ddd9cf;
  --text: #1d1d1b;
  --muted: #6b675e;
  --link: #1a5276;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  color: var(--text); background: var(--bg); line-height: 1.55;
}
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  background: var(--accent); color: #fff;
  padding: .5rem 1rem; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
#topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 600; letter-spacing: .02em; }
#menu-toggle { display: block; background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer; }
#home-link { color: #fff; text-decoration: none; font-size: 1.3rem; line-height: 1; opacity: .9; }
#home-link:hover { opacity: 1; }
#lang-switch { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
#rpane-label { font-size: .85rem; opacity: .85; letter-spacing: .03em; }
#lang-switch button {
  background: transparent; border: 1px solid rgba(255,255,255,.6); color: #fff;
  padding: .15rem .5rem; cursor: pointer; border-radius: 3px; font: inherit;
}
#lang-switch button.active { background: #fff; color: var(--accent); font-weight: 700; }
#layout { display: flex; align-items: stretch; }
#sidebar {
  width: 320px; min-width: 320px; height: calc(100vh - 44px);
  overflow-y: auto; background: var(--sidebar-bg);
  border-right: 1px solid var(--border); padding: .5rem 0; font-size: .9rem;
}
#sidebar .chap { margin: 0; }
#sidebar .chap > a {
  display: block; padding: .35rem .8rem; font-weight: 700; color: var(--text);
  text-decoration: none; border-top: 1px solid var(--border);
}
#sidebar .chap > a .cnum { color: var(--accent); margin-right: .35rem; }
#sidebar .chap > a:hover { background: #e7e4db; }
#sidebar .pages a {
  display: block; padding: .2rem .8rem .2rem 1.8rem; color: var(--link);
  text-decoration: none; font-size: .85rem;
}
#sidebar .pages a:hover { background: #e7e4db; }
#sidebar a.current { background: #e0dccf; font-weight: 700; }
main {
  flex: 1; min-width: 0; height: calc(100vh - 44px); overflow-y: auto; padding: 2rem 3rem 6rem;
}
/* Two columns aligned block-by-block: each top-level block (theorem / proof /
   paragraph / equation) and its translation share an .align-row, so every
   statement lines up vertically. The center rule is drawn down the column gap. */
#panes { position: relative; max-width: 1700px; margin: 0 auto; }
#panes::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 1px; background: var(--border); transform: translateX(-50%);
}
.align-row { display: grid; grid-template-columns: 1fr 1fr; column-gap: 3rem; align-items: start; }
.cell { min-width: 0; }                 /* let wide equations scroll, not stretch the row */
.cell-right { color: var(--text); }
/* keep the first block (title) from doubling its top margin inside a row cell */
.cell > :first-child { margin-top: 0; }
#panes h1 { font-size: 1.7rem; color: var(--accent); border-bottom: 2px solid var(--border); padding-bottom: .3rem; }
#panes h2 { font-size: 1.3rem; margin-top: 2rem; color: #333; }
#panes h3 { font-size: 1.08rem; margin-top: 1.4rem; }
#panes p { margin: .6rem 0; text-align: justify; }
a { color: var(--link); }
a.ref, a.eqref { text-decoration: none; color: var(--accent); font-weight: 600; }
a.ref:hover, a.eqref:hover { text-decoration: underline; }
.cite a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* theorem-like blocks */
.thm { margin: 1.1rem 0; padding: .1rem 0; }
.thm-head { font-variant: small-caps; }
.thm-name { font-weight: 700; }
.thm-num { font-weight: 700; }
.thm-title { font-weight: 400; font-style: italic; }
.thm-plain .thm-body { font-style: italic; }
.thm-plain { border-left: 3px solid var(--accent); padding-left: .9rem; }
.thm-remark { border-left: 3px solid #b9b3a3; padding-left: .9rem; }
.thm-body { margin-top: .15rem; }
.thm-body p:first-child { display: inline; }

/* proofs */
.proof { margin: .9rem 0; }
.proof-head { cursor: pointer; color: var(--muted); font-style: italic; user-select: none; }
.proof-name { font-style: italic; }
.proof-toggle { font-size: .7rem; margin-left: .3rem; }
.proof-body { margin: .3rem 0 .3rem .5rem; padding-left: .7rem; border-left: 1px dotted #c9c4b6; }
.proof.collapsed .proof-body { display: none; }
.qed { float: right; font-style: normal; font-variant: small-caps; color: var(--muted); }

/* equations */
.equation, .displaymath { overflow-x: auto; overflow-y: hidden; margin: .3rem 0; }
.equation { }

/* lists */
ol.enumerate, ol.enumerate-i, ol.enumerate-a, ul.itemize { margin: .5rem 0 .5rem 1.2rem; }
.item-label { font-weight: 600; margin-right: .3rem; }

/* footnotes (right pane ids are namespaced to #r-footnotes, so match by suffix) */
.footnote-ref sup { color: var(--accent); }
[id$="footnotes"] { margin-top: 3rem; border-top: 1px solid var(--border); padding-top: .6rem; font-size: .85rem; color: #333; }
[id$="footnotes"] ol { margin: 0; padding-left: 1.4rem; }
[id$="footnotes"] li { margin: .25rem 0; }
[id$="footnotes"] .backref { margin-left: .3rem; text-decoration: none; }

/* bibliography */
dl.bibliography { font-size: .92rem; }
dl.bibliography dt { float: left; clear: left; font-weight: 700; color: var(--accent); margin-right: .6rem; }
dl.bibliography dd { margin: 0 0 .5rem 2.4rem; }

/* tables (indexes) */
table.tabular { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.tabular td { padding: .15rem .5rem; vertical-align: top; }

/* misc inline */
.upshape { font-style: normal; }
.smallcaps { font-variant: small-caps; }
.small { font-size: .85em; }
.large { font-size: 1.2em; }
.center { text-align: center; }
.flushright { text-align: right; }
.anchor { display: block; height: 0; }
.target-flash { background: #fff6c2; transition: background 1.2s; }

/* CJK fallback for the Chinese right pane (set el.lang='cn' in viewer.js) */
[lang="cn"] { font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; }

/* ============================================================= comments ===
   In-viewer error comments (comments.js): a topbar toggle, a floating
   "Comment" button on text selection, create/thread popovers, per-block
   badges, and a slide-over panel. Reuses the palette vars above. */

/* The `hidden` attribute must win over these elements' own `display` rules
   (an ID selector setting `display` otherwise outranks the UA `[hidden]` rule,
   leaving the panel/count/float stuck visible). */
#cmt-panel[hidden], #cmt-count[hidden], #cmt-float[hidden] { display: none; }

/* topbar toggle + open-count badge */
#cmt-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  background: transparent; border: 1px solid rgba(255,255,255,.6); color: #fff;
  padding: .15rem .5rem; cursor: pointer; border-radius: 3px; font: inherit; white-space: nowrap;
}
#cmt-toggle:hover { background: rgba(255,255,255,.12); }
#cmt-count {
  display: inline-block; min-width: 1.1em; padding: 0 .3em; line-height: 1.4;
  background: #fff; color: var(--accent); border-radius: 999px;
  font-size: .72rem; font-weight: 700; text-align: center;
}

/* floating "Comment" button shown over a selection */
#cmt-float {
  position: fixed; z-index: 45; cursor: pointer;
  background: var(--accent); color: #fff; border: none; border-radius: 4px;
  padding: .25rem .6rem; font: inherit; font-size: .82rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* per-block marker: a 💬 badge in the block's top corner + a faint tint */
.has-comment { position: relative; background: rgba(122,31,31,.05); border-radius: 4px; }
.cmt-badge {
  position: absolute; top: .1rem; right: .1rem; z-index: 5;
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  padding: 0 .35rem; line-height: 1.5; font-size: .75rem; cursor: pointer;
  color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.cmt-badge:hover { border-color: var(--accent); }

/* create + thread popovers */
.cmt-popover {
  position: fixed; z-index: 40; width: 300px; max-width: 92vw;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,.22); padding: .6rem; font-size: .85rem;
}
.cmt-pop-head { font-weight: 700; margin-bottom: .35rem; }
.cmt-pop-quote, .cmt-item-quote, .cmt-row-quote {
  font-style: italic; color: var(--muted); border-left: 2px solid var(--border);
  padding-left: .5rem; margin-bottom: .35rem; overflow-wrap: anywhere;
}
.cmt-pop-meta { color: var(--muted); font-size: .76rem; margin-bottom: .35rem; }
.cmt-pop-text, .cmt-edit-text {
  width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: .85rem;
  border: 1px solid var(--border); border-radius: 4px; padding: .35rem;
}
.cmt-pop-actions { display: flex; gap: .4rem; justify-content: flex-end; margin-top: .45rem; }
.cmt-btn {
  background: #f4f2ec; border: 1px solid var(--border); border-radius: 4px;
  padding: .2rem .6rem; cursor: pointer; font: inherit; font-size: .8rem; color: var(--text);
}
.cmt-btn:hover { background: #e9e6dd; }
.cmt-btn.cmt-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.cmt-btn.cmt-primary:hover { background: #621818; }
.cmt-btn.cmt-danger { color: var(--accent); }

/* thread items */
.cmt-thread { max-height: 46vh; overflow-y: auto; }
.cmt-item { border-top: 1px solid var(--border); padding: .4rem 0; }
.cmt-item:first-child { border-top: none; }
.cmt-item-text { overflow-wrap: anywhere; }
.cmt-item-foot, .cmt-row-foot { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin-top: .25rem; }
.cmt-tag { color: var(--muted); font-size: .74rem; }
.cmt-actions { display: flex; gap: .25rem; flex-shrink: 0; }
.cmt-actions button {
  background: none; border: none; color: var(--link); cursor: pointer;
  font: inherit; font-size: .74rem; padding: 0 .15rem; text-decoration: underline;
}
.cmt-actions button:hover { color: var(--accent); }

/* slide-over panel listing every comment */
#cmt-panel {
  position: fixed; top: 44px; right: 0; z-index: 30;
  width: 360px; max-width: 92vw; height: calc(100vh - 44px);
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: -3px 0 14px rgba(0,0,0,.12); display: flex; flex-direction: column;
}
.cmt-panel-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
.cmt-x { background: none; border: none; font-size: 1rem; cursor: pointer; color: var(--muted); }
.cmt-panel-tools { display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem .8rem; border-bottom: 1px solid var(--border); }
.cmt-panel-list { flex: 1; overflow-y: auto; padding: .4rem .8rem 2rem; }
.cmt-empty { color: var(--muted); font-size: .85rem; }
.cmt-grp { margin-bottom: .8rem; }
.cmt-grp-head { font-weight: 700; font-size: .8rem; color: var(--accent); margin: .4rem 0 .2rem; }
.cmt-row { border: 1px solid var(--border); border-radius: 5px; padding: .4rem .5rem; margin-bottom: .4rem; background: #fff; font-size: .85rem; }
.cmt-row-text { overflow-wrap: anywhere; }

@media (max-width: 800px) {
  #cmt-panel { width: 100%; }
  .cmt-popover { width: 92vw; }
}

/* desktop: collapsible TOC sidebar (toggled via body.sidebar-collapsed, persisted) */
@media (min-width: 801px) {
  body.sidebar-collapsed #sidebar { display: none; }
}

@media (max-width: 800px) {
  #sidebar { position: fixed; left: 0; top: 44px; z-index: 9; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: translateX(0); }
  main { padding: 1rem 1.1rem 5rem; }
  /* stack each block over its translation (French block, then its rendering);
     no center rule, and the translation cell gets an accent margin to set it off */
  #panes::before { display: none; }
  .align-row { grid-template-columns: 1fr; row-gap: .2rem; }
  .cell-right {
    border-left: 2px solid var(--border); padding-left: .7rem;
    margin: 0 0 .4rem .1rem;
  }
}
