/* Shared reading design for the English text, the Chinese text, and the glossary.
   Night mast, warm paper, one brass rule. The verse text is not set here. */

:root {
  color-scheme: light;
  --ink: #1c1916;
  --ink-soft: #5c564e;
  --num: #6d5738;
  --paper: #f3eee4;
  --paper-2: #e9e2d6;
  --wash: #f3e2c4;
  --line: rgba(28, 25, 22, 0.16);
  --brass: #a06a32;
  --brass-soft: #c4a574;
  --night: #0c0f12;
  --cream: #f3eee4;
  --mast-bg: #efe8dc;
  --mast-ink: #1c1916;
  --field: #faf7f2;
  --chip: rgba(28, 25, 22, 0.06);
  --selection: #ead7b4;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif;
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mast: 3.05rem;
  --rail: 17rem;
  --spread: min(112rem, calc(100vw - 2.5rem));
}

[data-theme="night"] {
  color-scheme: dark;
  --ink: #f4efe6;
  --ink-soft: #d2c8b8;
  --num: #e4d2b0;
  --paper: #0c0f12;
  --paper-2: #161c22;
  --wash: rgba(196, 165, 116, 0.22);
  --line: rgba(244, 239, 230, 0.16);
  --brass: #e4d2b0;
  --brass-soft: #e4d2b0;
  --mast-bg: #0c0f12;
  --mast-ink: #f4efe6;
  --field: #12181e;
  --chip: rgba(244, 239, 230, 0.08);
  --selection: rgba(196, 165, 116, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --ink: #f4efe6;
    --ink-soft: #d2c8b8;
    --num: #e4d2b0;
    --paper: #0c0f12;
    --paper-2: #161c22;
    --wash: rgba(196, 165, 116, 0.22);
    --line: rgba(244, 239, 230, 0.16);
    --brass: #e4d2b0;
    --brass-soft: #e4d2b0;
    --mast-bg: #0c0f12;
    --mast-ink: #f4efe6;
    --field: #12181e;
    --chip: rgba(244, 239, 230, 0.08);
    --selection: rgba(196, 165, 116, 0.35);
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--mast) + .4rem); }

body {
  margin: 0;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(196, 165, 116, 0.16), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(80, 96, 104, 0.06), transparent 46%),
    var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.75;
  text-rendering: auto;
}

html[lang="zh-CN"] body {
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Songti TC", SimSun, Palatino, Georgia, serif;
  line-height: 1.9;
}

a { color: inherit; text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--brass); }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

::selection { background: var(--selection); color: var(--ink); }

.skip {
  position: absolute;
  left: .6rem;
  top: .4rem;
  z-index: 40;
  padding: .35rem .6rem;
  background: var(--cream);
  color: var(--night);
  transform: translateY(-150%);
}
.skip:focus { transform: none; }

.mast {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-height: var(--mast);
  padding: .35rem clamp(.9rem, 3vw, 1.6rem);
  background: var(--mast-bg);
  color: var(--mast-ink);
  border-bottom: 1px solid var(--line);
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: inherit;
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.mark svg { display: block; }
.mark:hover { color: var(--brass-soft); }

.mast-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .7rem .9rem;
  min-width: 0;
}
.mast nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .15rem .9rem;
  font-family: var(--sans);
  font-size: .92rem;
}
.mast nav a { color: inherit; text-decoration: none; }
.mast nav a:hover { color: var(--brass-soft); }
.mast nav a[aria-current="page"] { box-shadow: inset 0 -1px 0 var(--brass-soft); }

.scripture main {
  max-width: 42rem;
  margin-inline: auto;
  padding: .5rem clamp(1.05rem, 5vw, 1.75rem) 5rem;
  overflow-wrap: anywhere;
}

.scripture main > header { text-align: center; padding: 2.4rem 0 1.2rem; }
.scripture main > header h1 {
  margin: 0;
  font-weight: 500;
  font-size: clamp(2.15rem, 6vw, 3.35rem);
  line-height: 1.18;
  letter-spacing: -0.02em;
}
html[lang="zh-CN"] .scripture main > header h1 { letter-spacing: 0.04em; font-weight: 600; }

.scripture .subtitle {
  margin: .55rem 0 0;
  color: var(--ink-soft);
  font-size: 1.12rem;
  font-style: italic;
}
.scripture .subtitle::after {
  content: "";
  display: block;
  width: 2.75rem;
  height: 1px;
  margin: 1rem auto 0;
  background: var(--brass-soft);
}

.scripture main > header nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem 1.1rem;
  margin-top: 1.15rem;
  font-family: var(--sans);
  font-size: .95rem;
}

#front-note {
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.75;
}

.scripture h2, .scripture h3, .scripture h4 { line-height: 1.35; font-weight: 500; }
.scripture h2 {
  margin: 2.8rem 0 .8rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
  font-size: clamp(1.55rem, 3vw, 1.95rem);
}
.scripture h3 { margin: 1.9rem 0 .45rem; font-size: 1.28rem; }
html[lang="zh-CN"] .scripture h2,
html[lang="zh-CN"] .scripture h3 { font-weight: 600; }

.verse {
  margin-block: .55em;
  padding-inline-start: 2.45em;
  text-indent: -2.45em;
  font-size: 1.125rem;
  line-height: 1.8;
}
html[lang="zh-CN"] .verse { font-size: 1.155rem; line-height: 1.95; }

.verse-number {
  display: inline-block;
  width: 2.45em;
  text-indent: 0;
  font-variant-numeric: tabular-nums;
  font-size: .84em;
  color: var(--num);
}

.summary, .reference {
  border-inline-start: 2px solid var(--brass-soft);
  padding-inline-start: .85rem;
  color: var(--ink-soft);
}
.reference { font-size: .92em; }

.scripture :target { scroll-margin-top: calc(var(--mast) + .6rem); }
.scripture section:target > h2,
.scripture section:target > h3,
.scripture p:target {
  background: var(--wash);
  box-shadow: inset 3px 0 0 var(--brass);
  border-radius: 2px;
}

.scripture li + li { margin-top: .4em; }

#outline li { color: var(--ink-soft); }
#outline a { color: var(--ink); }

.back { margin: 1.2rem 0 0; font-family: var(--sans); font-size: .92rem; }

.colophon {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0 clamp(1.05rem, 5vw, 1.75rem) 2.5rem;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .88rem;
}
.glossary .colophon { max-width: 62rem; }

/* Glossary */
.glossary main {
  max-width: 62rem;
  margin-inline: auto;
  padding: .4rem clamp(1rem, 4vw, 1.75rem) 4rem;
  overflow-wrap: anywhere;
}
.glossary header { text-align: center; padding-top: 1.6rem; }
.glossary h1 {
  margin: 0;
  font-size: clamp(1.9rem, 5vw, 2.7rem);
  line-height: 1.3;
  font-weight: 600;
}
.glossary h1 small {
  display: block;
  margin-top: .35rem;
  font-size: .46em;
  font-weight: 400;
  font-style: italic;
  color: var(--ink-soft);
  font-family: var(--serif);
}
.glossary .intro { color: var(--ink-soft); max-width: 42rem; margin: 1rem auto 0; }

.glossary .tools {
  position: sticky;
  top: var(--mast);
  z-index: 8;
  background: var(--paper);
  padding: .7rem 0 .55rem;
  border-bottom: 1px solid var(--line);
}
#filter {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  color: var(--ink);
  background: var(--field);
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: 2px;
}
.glossary nav.cats {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .95rem;
  justify-content: center;
  margin-top: .55rem;
  font-family: var(--sans);
  font-size: .92rem;
}
.glossary .index {
  columns: 16rem;
  column-gap: 2rem;
  padding: 0;
  list-style: none;
  margin: .6rem 0 0;
}
.glossary .index li { break-inside: avoid; margin: .2rem 0; }
.glossary h2 {
  margin-top: 2.4rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.glossary h2 small, .glossary .en-name { font-weight: 400; color: var(--ink-soft); }
.glossary article .en-name {
  display: block;
  margin-top: .15rem;
  font-size: .98rem;
  font-family: var(--serif);
  font-style: italic;
}
.glossary .pinyin {
  font-style: italic;
  color: var(--ink-soft);
  font-weight: 400;
  font-size: .82em;
  margin-inline-start: .4em;
}
.glossary article {
  border-bottom: 1px solid var(--line);
  padding: 1.05rem 0 1.15rem;
  scroll-margin-top: 8.5rem;
}
.glossary article:target { background: var(--wash); }
.glossary h3 { margin: 0; font-size: 1.32rem; line-height: 1.4; }
.glossary .defs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem 1.8rem;
  margin-top: .55rem;
}
.glossary .defs p { margin: 0; }
.glossary .defs .en { font-family: var(--serif); font-size: .98em; }
.glossary .refs, .glossary .see { font-size: .92em; margin: .65rem 0 0; }
.glossary .refs a {
  display: inline-block;
  background: var(--chip);
  border-radius: 2px;
  padding: .05em .45em;
  margin: .15em .2em .15em 0;
  text-decoration: none;
}
.glossary .refs a:hover { background: var(--wash); }
.glossary .label { color: var(--ink-soft); margin-inline-end: .3em; }
.glossary footer { margin-top: 2.5rem; color: var(--ink-soft); font-size: .92em; text-align: center; }
.hidden { display: none !important; }

@media (max-width: 44rem) {
  .glossary .defs { grid-template-columns: 1fr; gap: .55rem; }
  .verse { font-size: 1.075rem; }
  .mast nav { font-size: .86rem; gap: .15rem .7rem; }
  .theme-toggle { width: 2rem; height: 2rem; }
  .mast-end { gap: .45rem .6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mast, .glossary .tools { backdrop-filter: none; }
  html { scroll-behavior: auto; }
  [data-theme="night"] body { background-attachment: scroll; }
}

.theme-toggle {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
}
.theme-toggle .sun { display: none; }
[data-theme="night"] .theme-toggle .moon { display: none; }
[data-theme="night"] .theme-toggle .sun { display: block; }
.theme-toggle:hover { color: var(--brass); }

.sidetoc { display: none; }

[data-theme="night"] body {
  background-color: var(--paper);
  background-image:
    radial-gradient(1.2px 1.2px at 8% 16%, rgba(244, 239, 230, .75), transparent),
    radial-gradient(1px 1px at 18% 42%, rgba(244, 239, 230, .4), transparent),
    radial-gradient(1.4px 1.4px at 72% 12%, rgba(228, 210, 176, .8), transparent),
    radial-gradient(1px 1px at 84% 38%, rgba(244, 239, 230, .45), transparent),
    radial-gradient(1.1px 1.1px at 40% 22%, rgba(244, 239, 230, .35), transparent),
    radial-gradient(1px 1px at 56% 68%, rgba(244, 239, 230, .3), transparent),
    radial-gradient(1.3px 1.3px at 28% 74%, rgba(228, 210, 176, .55), transparent),
    radial-gradient(1px 1px at 92% 78%, rgba(244, 239, 230, .4), transparent),
    radial-gradient(ellipse at 78% -12%, rgba(232, 206, 156, .16), transparent 46%),
    radial-gradient(ellipse at 6% -8%, rgba(120, 142, 150, .14), transparent 40%);
  background-attachment: fixed;
}

@media (prefers-reduced-motion: reduce) {
  [data-theme="night"] body { background-attachment: scroll; }
}

@media (min-width: 1180px) {
  .sidetoc {
    display: block;
    position: fixed;
    z-index: 20;
    top: calc(var(--mast) + .85rem);
    left: max(1rem, calc((100vw - var(--spread)) / 2));
    width: var(--rail);
    max-height: calc(100vh - var(--mast) - 1.8rem);
    overflow: auto;
    overscroll-behavior: contain;
    font-family: var(--sans);
    font-size: .8rem;
    line-height: 1.35;
    padding: 0 .35rem 1rem 0;
    color: var(--ink-soft);
  }
  .sidetoc-label {
    margin: .15rem 0 .6rem;
    font-size: .72rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--brass);
  }
  .sidetoc ul { list-style: none; margin: 0; padding: 0; }
  .sidetoc .vol > a,
  .sidetoc .ch > a {
    display: block;
    text-decoration: none;
    border-radius: 2px;
  }
  .sidetoc .vol > a { color: var(--ink); padding: .32rem .2rem; }
  .sidetoc .ch > a { color: var(--ink-soft); padding: .1rem .2rem .1rem .7rem; }
  .sidetoc a:hover { color: var(--brass); }
  .sidetoc a[aria-current="location"] { color: var(--brass); box-shadow: inset 2px 0 0 var(--brass); }
  .sidetoc .vol > ul { margin: 0 0 .35rem; }

  .scripture main,
  .scripture .colophon,
  .glossary main,
  .glossary .colophon {
    width: min(84rem, calc(var(--spread) - var(--rail) - 2.75rem));
    max-width: none;
    margin-left: max(calc(var(--rail) + 2.75rem), calc((100vw - var(--spread)) / 2 + var(--rail) + 2.5rem));
    margin-right: auto;
  }
  .verse, .summary, .reference, #front-note, .back,
  .scripture h2, .scripture h3 {
    max-width: 44rem;
    margin-inline: auto;
  }
  #outline, #appendix, #outline h2, #outline h3, #appendix h2 {
    max-width: none;
    margin-inline: 0;
  }
  .scripture main > header h1 { font-size: clamp(2.6rem, 4vw, 4.1rem); }
  .glossary .intro { max-width: 46rem; }
}

@media (min-width: 1440px) {
  #outline h3 + ul {
    columns: 2;
    column-gap: 2.4rem;
  }
  #outline li { break-inside: avoid; }
}

@media print {
  body { background: white; color: black; }
  .mast, .skip, .colophon, .sidetoc, .theme-toggle, .scripture main > header nav, .back, .glossary .tools { display: none !important; }
  .scripture main, .glossary main { max-width: none; width: auto; margin: 0; padding: 0; }
  a { color: black; text-decoration: none; }
  .scripture section:target > h2,
  .scripture section:target > h3,
  .scripture p:target,
  .glossary article:target { background: none; box-shadow: none; }
  .scripture h2, .scripture h3, .scripture h4 { break-after: avoid; }
  .verse, .summary, .reference, #front-note { max-width: none; }
}
