:root {
  color-scheme: light;
  --paper: #f4efe4;
  --paper-light: #faf6ed;
  --sidebar: #e8decc;
  --ink: #28251f;
  --muted: #7a7265;
  --faint: #a39a8a;
  --line: rgba(64, 52, 35, .14);
  --cinnabar: #a33b31;
  --cinnabar-soft: rgba(163, 59, 49, .12);
  --font-size: 21px;
  --sidebar-width: 292px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1d1c18;
  --paper-light: #25231e;
  --sidebar: #22201b;
  --ink: #dfd6c5;
  --muted: #aaa091;
  --faint: #766f63;
  --line: rgba(230, 218, 197, .12);
  --cinnabar: #d07162;
  --cinnabar-soft: rgba(208, 113, 98, .14);
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", STSong, SimSun, serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.catalog { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: grid; grid-template-rows: auto auto 1fr auto; background: var(--sidebar); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 18px; border-bottom: 1px solid var(--line); }
.seal { width: 42px; height: 42px; display: grid; place-items: center; color: #f8eee1; background: var(--cinnabar); border-radius: 3px; font-size: 23px; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .16em; }
.brand small { margin-top: 4px; color: var(--muted); font: 10px system-ui, sans-serif; letter-spacing: .1em; }
.brand button { display: none; margin-left: auto; border: 0; background: transparent; font-size: 22px; }
.catalog-tools { display: grid; gap: 12px; padding: 17px 15px; border-bottom: 1px solid var(--line); }
.catalog-tools label span { display: block; margin: 0 0 6px 2px; color: var(--faint); font: 10px system-ui, sans-serif; letter-spacing: .12em; }
.catalog-tools select, .catalog-tools input { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 6px; outline: none; background: rgba(255,255,255,.25); font: 13px system-ui, sans-serif; }
.chapter-list { overflow: auto; padding: 10px 9px 25px; }
.section-name { margin: 16px 10px 6px; color: var(--faint); font: 10px system-ui, sans-serif; letter-spacing: .14em; }
.chapter-button { width: 100%; display: flex; gap: 9px; padding: 9px 10px; border: 0; border-radius: 5px; background: transparent; text-align: left; }
.chapter-button:hover { background: rgba(255,255,255,.25); }
.chapter-button.active { color: var(--cinnabar); background: var(--cinnabar-soft); }
.chapter-button i { color: var(--faint); font: normal 9px system-ui, sans-serif; }
.chapter-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.catalog footer { display: flex; justify-content: space-between; padding: 13px 16px; color: var(--faint); border-top: 1px solid var(--line); font: 9px system-ui, sans-serif; }

main { margin-left: var(--sidebar-width); min-height: 100vh; }
.toolbar { position: sticky; top: 0; z-index: 20; min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 8px 25px; background: color-mix(in srgb, var(--paper) 90%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.toolbar-path, .toolbar-actions { display: flex; align-items: center; gap: 4px; }
.toolbar-path { min-width: 0; color: var(--muted); font-size: 12px; }
#crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar button { padding: 7px 9px; color: var(--muted); border: 0; border-radius: 5px; background: transparent; font: 11px system-ui, sans-serif; }
.toolbar button:hover { color: var(--cinnabar); background: var(--cinnabar-soft); }
#open-catalog { display: none; font-size: 17px; }

.reader { width: min(860px, calc(100% - 60px)); margin: 0 auto; }
.chapter-header { padding: 72px 20px 48px; text-align: center; border-bottom: 1px solid var(--line); }
.chapter-header > p:first-child { margin: 0 0 14px; color: var(--cinnabar); font: 11px system-ui, sans-serif; font-weight: 650; letter-spacing: .18em; }
.chapter-header h1 { margin: 0; font-size: clamp(31px, 4vw, 46px); font-weight: 600; letter-spacing: .07em; }
#chapter-help { margin: 17px 0 0; color: var(--faint); font: 11px system-ui, sans-serif; }
.paper { padding: 48px 4px 60px; }
.text-paragraph { margin: 0 0 1.55em; font-size: var(--font-size); line-height: 2.15; text-align: justify; text-justify: inter-ideograph; letter-spacing: .035em; }
.sentence { border-radius: 2px; }
.section-heading { display: block; margin: 1.8em 0 .6em; color: var(--ink); font-size: .82em; font-weight: 600; letter-spacing: .12em; }
.sentence::selection, .sentence *::selection { color: var(--ink); background: rgba(163, 59, 49, .2); }
.sentence.translated-source, .sentence.selected-source { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--cinnabar) 60%, transparent); text-decoration-thickness: 1px; text-underline-offset: .22em; }
.annotation { margin: 0 .3em; color: color-mix(in srgb, var(--cinnabar) 72%, var(--muted)); font-family: "Kaiti SC", KaiTi, STKaiti, serif; font-size: .7em; line-height: 1.55; letter-spacing: .025em; cursor: pointer; animation: ink-in .18s ease-out; }
.annotation::before { content: "〔"; }
.annotation::after { content: "〕"; }
.annotation-core { padding: .05em .14em; color: var(--cinnabar); background: var(--cinnabar-soft); border-radius: 2px; font-weight: 600; }
.annotation-join { margin: 0 .15em; color: var(--faint); }
.annotation-pending { color: var(--muted); font-style: normal; }
.annotation.pending::before, .annotation.pending::after { color: var(--muted); }
.annotation.low-confidence { text-decoration: underline dotted color-mix(in srgb, var(--cinnabar) 50%, transparent); text-underline-offset: 3px; }
.text-paragraph { position: relative; }
.user-note { color: color-mix(in srgb, var(--ink) 72%, var(--cinnabar)); font-family: "Kaiti SC", KaiTi, STKaiti, serif; }
.user-note i { display: inline-grid; place-items: center; min-width: 1.65em; height: 1.65em; margin-right: .45em; color: var(--cinnabar); border: 1px solid color-mix(in srgb, var(--cinnabar) 55%, transparent); border-radius: 50%; font: normal .55em system-ui, sans-serif; vertical-align: .16em; }
.user-note small { margin-left: .5em; color: var(--faint); font: .68em system-ui, sans-serif; }
.note-interlinear { margin: 0 .3em; padding: .08em .3em; color: #744d42; background: color-mix(in srgb, var(--paper-light) 78%, var(--cinnabar-soft)); border-bottom: 1px dotted color-mix(in srgb, var(--cinnabar) 35%, transparent); font-size: .72em; line-height: 1.55; }
.note-interlinear::before { content: "〈"; color: var(--faint); }
.note-interlinear::after { content: "〉"; color: var(--faint); }
.note-side { position: absolute; left: calc(100% + 22px); top: 0; width: 124px; padding-left: 11px; border-left: 1px solid var(--cinnabar); font-size: 13px; line-height: 1.6; text-align: left; }
.note-side::before { content: ""; position: absolute; left: -18px; top: .78em; width: 17px; border-top: 1px solid color-mix(in srgb, var(--cinnabar) 55%, transparent); }
.note-header, .note-footer { display: block; max-width: 80%; color: color-mix(in srgb, var(--cinnabar) 62%, var(--ink)); font-size: 14px; line-height: 1.65; letter-spacing: .04em; }
.note-header { margin: 2.2em auto .7em 0; padding: 0 0 .5em 1em; border-left: 2px solid var(--cinnabar); border-bottom: 1px solid var(--line); }
.note-header::before { content: "眉批"; margin-right: .7em; color: var(--cinnabar); font: 9px system-ui, sans-serif; letter-spacing: .12em; }
.note-footer { margin: -.75em 0 2em auto; padding: .55em 1em 0 0; border-top: 1px solid var(--line); border-right: 2px solid var(--cinnabar); text-align: right; }
.note-footer::before { content: "尾批"; margin-right: .7em; color: var(--cinnabar); font: 9px system-ui, sans-serif; letter-spacing: .12em; }
.note-private { opacity: .88; }
mark.circle-mark, .sentence.circle-mark { color: inherit; background: transparent; text-decoration: underline wavy color-mix(in srgb, var(--cinnabar) 68%, transparent); text-decoration-thickness: 1px; text-underline-offset: .28em; }
mark.circle-mark::after { content: "·"; color: var(--cinnabar); }
@keyframes ink-in { from { opacity: 0; filter: blur(2px); } }
.empty-state { padding: 100px 20px; color: var(--muted); text-align: center; }
.empty-state span { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 18px; color: var(--cinnabar); border: 1px solid var(--cinnabar); border-radius: 50%; font-size: 24px; }
.empty-state p { line-height: 2; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 80px; }
.pager button { min-height: 82px; padding: 13px 17px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper-light); text-align: left; }
.pager button:last-child { text-align: right; }
.pager button:disabled { opacity: .35; cursor: default; }
.pager small { display: block; margin-bottom: 7px; color: var(--cinnabar); font: 10px system-ui, sans-serif; }
.pager strong { font-size: 13px; font-weight: 500; }

.selection-menu { position: fixed; z-index: 60; display: none; align-items: center; padding: 5px; color: #f7efe3; background: #2b2924; border-radius: 7px; box-shadow: 0 10px 35px rgba(0,0,0,.22); transform: translate(-50%, calc(-100% - 10px)); }
.selection-menu.visible { display: flex; }
.selection-menu::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px; background: #2b2924; transform: translateX(-50%) rotate(45deg); }
.selection-menu button { position: relative; z-index: 1; padding: 7px 10px; color: inherit; border: 0; border-radius: 4px; background: transparent; font: 12px system-ui, sans-serif; }
.selection-menu button:hover { background: rgba(255,255,255,.12); }
.selection-menu button + button { border-left: 1px solid rgba(255,255,255,.14); border-radius: 0; }
.selection-menu button span { color: #e48878; }
.toast { position: fixed; z-index: 70; left: 50%; bottom: 28px; padding: 9px 14px; color: #f7efe3; background: #2b2924; border-radius: 99px; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; font: 11px system-ui, sans-serif; transition: .2s; }
.toast.visible { opacity: .92; transform: translate(-50%, 0); }
.scrim { display: none; }

.ink-dialog { width: min(510px, calc(100vw - 28px)); padding: 0; color: var(--ink); background: transparent; border: 0; }
.ink-dialog::backdrop { background: rgba(24, 20, 16, .55); backdrop-filter: blur(3px); }
.dialog-card { position: relative; display: grid; gap: 15px; padding: 32px; background: var(--paper-light); border: 1px solid color-mix(in srgb, var(--cinnabar) 24%, var(--line)); border-radius: 8px; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.dialog-card h2 { margin: 0; text-align: center; font-weight: 550; letter-spacing: .12em; }
.dialog-card > p { margin: -5px 0 2px; color: var(--muted); font: 12px/1.7 system-ui, sans-serif; text-align: center; }
.dialog-card label { display: grid; gap: 7px; color: var(--muted); font: 11px system-ui, sans-serif; }
.dialog-card input, .dialog-card textarea, .dialog-card select { width: 100%; padding: 10px 12px; color: var(--ink); background: color-mix(in srgb, var(--paper) 82%, white); border: 1px solid var(--line); border-radius: 5px; outline: none; font: 14px/1.5 system-ui, sans-serif; }
.dialog-card textarea { resize: vertical; font-family: "Kaiti SC", KaiTi, serif; font-size: 16px; }
.dialog-card input:focus, .dialog-card textarea:focus, .dialog-card select:focus { border-color: var(--cinnabar); box-shadow: 0 0 0 2px var(--cinnabar-soft); }
.dialog-close { position: absolute; top: 12px; right: 14px; padding: 4px 8px; color: var(--muted); background: transparent; border: 0; font-size: 21px; }
.dialog-seal { width: 34px; height: 34px; display: grid; place-items: center; margin: 0 auto -8px; color: var(--cinnabar); border: 1px solid var(--cinnabar); border-radius: 50%; }
.dialog-card .primary { padding: 11px; color: #f9eee2; background: var(--cinnabar); border: 0; border-radius: 5px; font: 13px system-ui, sans-serif; }
.text-button { color: var(--cinnabar); background: transparent; border: 0; font: 11px system-ui, sans-serif; }
.dialog-card .danger { color: var(--muted); }
.annotation-form blockquote { max-height: 90px; overflow: auto; margin: -4px 0 0; padding: 9px 12px; color: var(--muted); background: var(--paper); border-left: 2px solid var(--cinnabar); font-size: 14px; line-height: 1.7; }
.note-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 0; border: 0; }
.note-kinds label { position: relative; display: block; padding: 10px 10px 10px 30px; background: var(--paper); border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
.note-kinds input { position: absolute; left: 9px; top: 12px; width: auto; accent-color: var(--cinnabar); }
.note-kinds strong, .note-kinds small { display: block; }
.note-kinds strong { color: var(--ink); font: 13px serif; }
.note-kinds small { margin-top: 4px; color: var(--faint); font-size: 9px; }
.visibility { grid-template-columns: 70px 1fr; align-items: center; }

@media (max-width: 760px) {
  :root { --font-size: 19px; }
  .catalog { transform: translateX(-102%); transition: transform .22s; box-shadow: 18px 0 55px rgba(0,0,0,.2); }
  body.catalog-open .catalog { transform: none; }
  .brand button, #open-catalog { display: block; }
  .scrim { position: fixed; inset: 0; z-index: 29; display: block; background: rgba(20,18,15,.42); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.catalog-open .scrim { opacity: 1; pointer-events: auto; }
  main { margin-left: 0; }
  .toolbar { min-height: 54px; padding-inline: 10px; }
  .toolbar-actions button:nth-child(2), .toolbar-actions button:nth-child(3) { display: none; }
  .reader { width: calc(100% - 32px); }
  .chapter-header { padding: 52px 4px 38px; }
  .chapter-header h1 { font-size: 30px; }
  .paper { padding-top: 35px; }
  .text-paragraph { line-height: 2.05; }
  .annotation { font-size: .73em; }
  .selection-menu { max-width: calc(100vw - 20px); }
  .selection-menu button { padding-inline: 8px; font-size: 11px; }
  .note-side { position: static; width: auto; margin: .4em 0 .7em 1.2em; padding-left: 10px; }
  .note-side::before { display: none; }
  .dialog-card { padding: 27px 20px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
