:root {
  color-scheme: light;
  --paper: #fcfbf8; --ink: #1f1c18; --soft: #6b645a; --line: #e2ddd3; --tint: #f3eee3; --accent: #8c3b1f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --bar: 2.75rem;
  --size: 1;
}
:root[data-theme="sepia"] {
  --paper: #f5ebd7; --ink: #3a2c1c; --soft: #7c6a52; --line: #e0d0b2; --tint: #ecdfc4; --accent: #8a3d14;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171614; --ink: #d8d3c9; --soft: #938c80; --line: #34312c; --tint: #25221e; --accent: #e39a6f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --paper: #171614; --ink: #d8d3c9; --soft: #938c80; --line: #34312c; --tint: #25221e; --accent: #e39a6f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); color: var(--ink); scroll-padding-top: calc(var(--bar) + 1rem); overflow-anchor: none; }
body { margin: 0; font: 400 1rem/1.5 var(--sans); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .15em; }
button { font: inherit; color: inherit; background: none; border: 0; padding: .35rem .6rem; border-radius: .35rem; cursor: pointer; }
button:hover { background: var(--tint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus, h2:focus, #note:focus { outline: none; }

/* --- the bar --- */
#bar {
  position: sticky; top: 0; z-index: 3; height: var(--bar); display: flex; align-items: center; gap: 1rem;
  padding: 0 1rem; background: var(--paper); border-bottom: 1px solid var(--line); font-size: .875rem;
}
#bar::after { content: ""; position: absolute; inset: auto 0 -1px 0; height: 2px; background: var(--accent); transform-origin: left; transform: scaleX(var(--done, 0)); }
#home { color: inherit; text-decoration: none; font-weight: 600; }
#where { flex: 1; min-width: 0; margin: 0; color: var(--soft); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#buttons { display: flex; }
#buttons button[aria-expanded="true"] { background: var(--tint); }

/* --- the text --- */
#text {
  position: relative; max-width: 34em; margin: 0 auto; padding: 3rem 1.25rem 4rem;
  font: 400 calc(1.1875rem * var(--size))/1.58 var(--serif); text-wrap: pretty; overflow-wrap: break-word;
}
article + article { margin-top: 6em; }
.n { scroll-margin-top: calc(var(--bar) + 1rem); }
:where(#text, #note) p { margin: 0; }
.p + .p { text-indent: 1.4em; }
.subtitle { text-align: center; font-style: italic; margin-bottom: 1.5em; }
.subtitle + .p, .p + .subtitle { text-indent: 0; }

.heading { font-weight: 500; line-height: 1.25; text-align: center; text-wrap: balance; margin: 0 0 1.6em; }
h1.heading { font-size: 2.2em; }
h2.heading { font-size: 1.5em; }
h3.heading { font-size: 1.25em; }
h4.heading, h5.heading, h6.heading { font-size: 1.05em; }
.work > .heading { margin-bottom: .4em; }
.work > .byline { text-align: center; color: var(--soft); margin-bottom: 4em; }
.byline i { display: block; }
.section + .section, .section .section { margin-top: 2.4em; }
.opening + .section, .opening + .opening { margin-top: 0; }
.dedication, .titlepage { text-align: center; }
.dedication .line { padding: 0; text-indent: 0; }
.poem > .heading { text-align: left; margin-bottom: .8em; }
.poem > .p { font-size: .88em; color: var(--soft); text-indent: 0; }
.poem > .p:has(+ :not(.p)) { margin-bottom: 1em; }

.quote, .poem, .list, .table, .code { margin: 1.1em 0 1.1em 2em; }
.section.poem { margin-top: 1.1em; }
.quote { margin-right: 2em; }
.quote .poem, .quote .table, .quote .quote, .poem .poem { margin-left: 0; }
.poem > .poem > .heading { text-align: center; margin: 1.6em 0 .6em; }
.cite { text-align: right; font-size: .92em; }
.cite::before { content: "— "; }
.stanza + .stanza { margin-top: 1em; }
.line { padding-left: calc(2em + var(--indent, 0) * 1.2em); text-indent: -2em; }
.lead { visibility: hidden; user-select: none; }

.speech { margin: .9em 0; }
.label { font-variant-caps: small-caps; letter-spacing: .04em; }
.label + .p { text-indent: 0; }
.stage-direction { font-style: italic; margin: .6em 0; padding-left: 2em; }
.label em { font-variant-caps: normal; letter-spacing: 0; }
.stage-direction em { font-style: normal; }
[data-terms~="z3998:stage-direction"] { font-style: italic; }
[data-terms~="z3998:persona"] strong { font-weight: inherit; font-variant-caps: small-caps; letter-spacing: .04em; }

.list { padding-left: 1.4em; }
.item > .p { text-indent: 0; margin-top: .4em; }
.list .list { margin: .1em 0; }
.index .list { list-style: none; padding-left: 0; }
.index .list .list { padding-left: 1.6em; margin: 0; }
.index .item { padding-left: 1.4em; text-indent: -1.4em; }
.break { border: 0; text-align: center; margin: 1.6em 0; color: var(--soft); }
.break::after { content: "＊ ＊ ＊"; letter-spacing: .3em; }
.table { border-collapse: collapse; }
.cell { padding: .2em 1.4em .2em 0; text-align: left; vertical-align: top; }
th.cell { border-bottom: 1px solid var(--line); font-weight: 600; }
.code { white-space: pre; overflow-x: auto; font-size: .8em; background: var(--tint); padding: .8em 1em; border-radius: .35rem; }
.note { display: grid; grid-template-columns: 2.2em 1fr; font-size: .94em; margin-bottom: 1.1em; }
.note > * { grid-column: 2; }
.note > .number { grid-column: 1; grid-row: 1; color: var(--soft); }
.back { text-decoration: none; margin-left: .4em; }
[data-terms~="epub:noteref"] a { font-size: .68em; line-height: 0; vertical-align: super; text-decoration: none; padding: .2em .1em; }

/* A passage someone has picked out. */
#text .n.selected { background: var(--tint); box-shadow: 0 0 0 .3em var(--tint); border-radius: .1em; }
.marked { position: relative; }
.marked::after { content: ""; position: absolute; left: -1rem; top: .35em; width: .3rem; height: .9em; background: var(--accent); border-radius: 1px; text-indent: 0; }
@keyframes arrive { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } }
.arrived { animation: arrive 2.4s ease-out; }

#tools {
  position: absolute; top: var(--at); left: 100%; z-index: 2; white-space: nowrap; display: flex; flex-direction: column; align-items: stretch; font: .8125rem/1.5 var(--sans);
  background: var(--paper); border: 1px solid var(--line); border-radius: .5rem; padding: .2rem; box-shadow: 0 2px 10px rgb(0 0 0 / .08);
}
#tools button { text-align: left; }

#turn { max-width: 40rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; display: flex; justify-content: space-between; gap: 2rem; font-size: .875rem; border-top: 1px solid var(--line); }
#turn a { text-decoration: none; color: inherit; max-width: 45%; }
#turn a:hover b { text-decoration: underline; }
#turn span { display: block; color: var(--soft); }
#turn b { font-weight: 500; }
#turn .next { margin-left: auto; text-align: right; }

/* --- panel and note --- */
#panel { position: fixed; z-index: 4; inset: 0 0 0 auto; width: min(23rem, 100vw); overflow-y: auto; overscroll-behavior: contain; background: var(--paper); border-left: 1px solid var(--line); font-size: .9375rem; }
#panel > header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; height: var(--bar); padding: 0 .5rem 0 1.1rem; background: var(--paper); border-bottom: 1px solid var(--line); }
#panel h2 { font-size: .9375rem; margin: 0; }
#panel-body { padding: 1rem 1.1rem 3rem; }
#panel h3 { font-size: .8125rem; color: var(--soft); font-weight: 600; margin: 1.6rem 0 .5rem; }
#panel ol, #panel ul { list-style: none; margin: 0; padding: 0; }
#panel ol ol { padding-left: 1rem; }
#panel .contents a { display: block; padding: .28rem .5rem; margin: 0 -.5rem; border-radius: .35rem; color: inherit; text-decoration: none; }
#panel .contents a:hover { background: var(--tint); }
#panel .contents a[aria-current] { background: var(--tint); color: var(--accent); font-weight: 600; }
#panel dl { margin: 0; display: grid; gap: .6rem; }
#panel dt { color: var(--soft); font-size: .8125rem; }
#panel dd { margin: 0; overflow-wrap: anywhere; }
#panel code { font: .8125rem ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
#panel .path { display: flex; flex-wrap: wrap; gap: .15rem; margin: 0 0 1rem -.6rem; font-size: .8125rem; }
#panel .path button[aria-current] { font-weight: 600; color: var(--accent); }
#panel .acts { display: flex; gap: .5rem; margin-top: .8rem; }
#panel .acts button, #panel fieldset button { border: 1px solid var(--line); }
#panel .bookmarks li { display: flex; gap: .5rem; align-items: start; padding: .7rem 0; border-bottom: 1px solid var(--line); }
#panel .bookmarks a { flex: 1; color: inherit; text-decoration: none; min-width: 0; }
#panel .bookmarks q { font-family: var(--serif); quotes: none; display: block; }
#panel .bookmarks small { color: var(--soft); }
#panel fieldset { border: 0; padding: 0; margin: 0 0 1.5rem; }
#panel legend { color: var(--soft); font-size: .8125rem; font-weight: 600; margin-bottom: .4rem; padding: 0; }
#panel label { display: flex; gap: .5rem; align-items: center; padding: .2rem 0; }
#panel input { accent-color: var(--accent); }
#panel input[type="range"] { width: 100%; }
.none { color: var(--soft); }

#note { position: fixed; z-index: 5; left: 50%; bottom: 1rem; transform: translateX(-50%); width: min(38rem, calc(100vw - 2rem)); max-height: 45vh; overflow-y: auto; overscroll-behavior: contain; background: var(--paper); border: 1px solid var(--line); border-radius: .6rem; padding: 1rem 1.25rem; box-shadow: 0 6px 30px rgb(0 0 0 / .18); font: calc(1.0625rem * var(--size))/1.5 var(--serif); }
#note footer { display: flex; justify-content: space-between; align-items: center; margin-top: .6rem; font: .8125rem var(--sans); }

/* --- library --- */
.library { list-style: none; padding: 0; margin: 2rem 0 0; }
.library li { padding: 1.4rem 0; border-top: 1px solid var(--line); }
.library h2 { font-size: 1.35em; font-weight: 500; margin: 0; line-height: 1.25; }
.library h2 a { color: inherit; text-decoration: none; }
.library h2 a:hover { text-decoration: underline; }
.library p { color: var(--soft); }
.library .go { font: .875rem var(--sans); margin-top: .5rem; }
.library .go a + a { margin-left: 1.2rem; }

#say { position: fixed; z-index: 6; left: 50%; bottom: 1.5rem; transform: translateX(-50%); margin: 0; padding: .45rem .9rem; border-radius: .5rem; background: var(--ink); color: var(--paper); font-size: .875rem; opacity: 0; pointer-events: none; transition: opacity .2s; }
#say.on { opacity: 1; }

@media (min-width: 76rem) { body.with-panel #text, body.with-panel #turn { translate: -11.5rem 0; } }
@media (max-width: 62rem) {
  #tools { position: fixed; inset: auto auto 1rem 50%; translate: -50% 0; flex-direction: row; }
  #say { bottom: 4.5rem; }
}
@media (max-width: 40rem) {
  #text { padding-top: 2rem; }
  #where { display: none; }
  #buttons { margin-left: auto; }
  #bar { gap: .25rem; padding: 0 .5rem 0 1rem; }
  #buttons button { padding: .35rem .45rem; }
  .quote, .poem, .list, .table, .code { margin-left: 1em; }
  .quote { margin-right: 1em; }
  .marked::after { left: -.8rem; }
  /* No room to set the parts of a shared line end to end. */
  .lead { display: none; }
  .line:has(> .lead) { padding-left: 6em; }
}
@media (prefers-reduced-motion: reduce) { .arrived { animation: none; } #say { transition: none; } }
