/* 감정서가 펼쳐졌을 때만 문서와 열린 창에 같은 팔레트를 씁니다. */
:root:where([data-reading-example], :has(body[data-screen="manual"] #sheet:not([hidden]))) {
  color-scheme: dark;
  --bg: #171717;
  --fg: #ecebe8;
  --text: #d2d0cc;
  --sub: #a4a39f;
  --dim: #84847e;
  --surface: #212121;
  --tile: #292929;
  --focus-muted: #b4b2ae;
  --dialog-bg: var(--surface);
  --paper: var(--fg);
  --muted: var(--sub);
  --rule: #42423f;
  background: var(--bg);
  color: var(--fg);
}
:root[data-reading-theme="paper"]:where([data-reading-example], :has(body[data-screen="manual"] #sheet:not([hidden]))) {
  color-scheme: light;
  --control-scheme: light;
  --bg: #f1f0ec;
  --fg: #222220;
  --text: #30302e;
  --sub: #62625e;
  --dim: #696964;
  --surface: #eae9e4;
  --tile: #e1e0d9;
  --focus-muted: #595953;
  --line: rgb(32 32 30 / .18);
  --edge: rgb(32 32 30 / .48);
  --rule: #c7c7bf;
  --err: #922e25;
  --el-0-d: #285f45;
  --el-1-d: #963d34;
  --el-2-d: #71531e;
  --el-3-d: #424e61;
  --el-4-d: #245984;
}
.reading-settings-trigger {
  width: fit-content; min-height: 44px; padding: 0 4px;
  border: 0; background: none; color: var(--sub);
  font: inherit; font-size: .875rem; cursor: pointer;
}
.reading-settings-trigger:hover, .settings-close:hover { text-decoration: underline; text-underline-offset: .22em; }
.chart-heading .reading-settings-trigger { grid-column: 1; justify-self: start; }
.reader-settings { display: block; margin-inline-start: auto; }
.reader-tools, .settings-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.reading-settings-dialog {
  box-sizing: border-box; width: min(340px, calc(100% - 32px)); max-height: 85dvh;
  margin: auto; inset: 0; padding: 18px 24px 14px; overflow: auto;
  color: var(--fg); background: var(--surface); border: 1px solid var(--edge, var(--rule));
  border-radius: 8px; font: inherit;
}
.reading-settings-dialog::backdrop { background: rgb(0 0 0 / .52); }
html:has(.reading-settings-dialog[open]) { overflow: hidden; }
.settings-head { margin-bottom: 18px; }
.settings-head h2 { margin: 0; font-size: 1.25rem; }
.settings-close { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--sub); font: inherit; font-size: .875rem; }
.reading-settings-dialog fieldset { margin: 0; padding: 0; min-width: 0; border: 0; }
.reading-settings-dialog legend { padding: 0; font-size: .875rem; color: var(--sub); }
.reading-tones { display: flex; gap: 8px; margin-block: 6px 16px; }
.reading-tones label, .focus-choice {
  display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer;
}
.reading-tones label { flex: 1; padding-inline: 12px; border: 1px solid var(--rule); border-radius: 4px; }
.reading-tones label:has(:checked) { border-color: var(--fg); }
.focus-choice { justify-content: space-between; border-top: 1px solid var(--rule); padding-top: 6px; }
.reading-settings-dialog input { width: 1.05rem; height: 1.05rem; margin: 0; accent-color: var(--fg); }

/* 공개 예시도 개인 감정서와 같은 바탕에서 읽습니다. */
[data-reading-example] .chapter p { max-width: 35rem; font-size: 1.0625rem; line-height: 1.85; }
[data-reading-example] .chapter .cite { color: inherit; }
[data-reading-example] #reason { background: var(--surface); border-color: var(--rule); }
[data-reading-example] :is(.mast nav a:hover, .back:hover, .endnotes li:target) { color: var(--fg); }
[data-reading-example][data-reading-theme="paper"] .el0 { color: var(--el-0-d); }
[data-reading-example][data-reading-theme="paper"] .el1 { color: var(--el-1-d); }
[data-reading-example][data-reading-theme="paper"] .el2 { color: var(--el-2-d); }
[data-reading-example][data-reading-theme="paper"] .el3 { color: var(--el-3-d); }
[data-reading-example][data-reading-theme="paper"] .el4 { color: var(--el-4-d); }
@media (prefers-contrast: no-preference) and (forced-colors: none) {
  .has-focus .chapter:not(.is-current):not(:focus-within) p,
  .has-focus .line:not(.is-current):not(:has(:focus-visible)) .line__body { color: var(--focus-muted); }
  .has-focus .chapter.is-current p, .has-focus .line.is-current .line__body { color: var(--fg); }
}
@media (prefers-reduced-motion: no-preference) {
  .has-focus .chapter p, .has-focus .line__body { transition: color 200ms ease-out; }
}
