/*
  Octavo: read-later app page (Screenery template)
  1. Tokens: paper, ink and one rubric red that only ever means "yours" (your marks, your notes, your progress).
     Four sizes do all the work: display, head, body, small. Newsreader for text, Lekton for figures and addresses.
  2. Book furniture: running head, folios, small caps, the opening spread built on the canon with container query units.
  3. The reader (settings, scrolling page, side notes floated into the outer margin), the canon, the queue, editions, price, index.
*/

/* ---------- 1. Tokens ---------- */
:root {
  --paper: #f5f0e6;        /* the ground of the page */
  --leaf: #fbf8f1;         /* a lighter sheet: pages of the spread, the reader page */
  --ink: #1f1b16;
  --ink-2: #574f43;        /* secondary text: 7.0:1 on paper */
  --rule: #cdc3b1;         /* hairlines; decorative only */
  --rule-2: #9d9282;       /* form borders: 3:1 on leaf */
  --red: #a1301c;          /* rubric: your marks, notes, progress, focus */
  --red-tint: #f2dccf;     /* highlight wash */
  --shadow: 32 24 14;      /* rgb of the spread's shadow */

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --mono: "Lekton", ui-monospace, "SF Mono", Menlo, monospace;

  --t-display: clamp(2.5rem, 2rem + 2.2vw, 3.75rem);
  --t-head: clamp(1.6rem, 1.3rem + 1vw, 2.15rem);
  --t-body: 1.1875rem;
  --t-small: 0.875rem;

  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem; --s-8: 4.5rem; --s-9: 7rem;
  --radius: 2px;
  --gutter: clamp(1rem, 4vw, 3.5rem);
  --wide: 1240px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--t-body)/1.55 var(--serif);
  font-optical-sizing: auto;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  hyphens: auto;
  caret-color: var(--red);
  accent-color: var(--red);
  scrollbar-color: var(--rule-2) var(--paper);
}
::selection { background: var(--red-tint); color: var(--ink); }
h1, h2, h3, p, dl, dd, ol, ul, figure { margin: 0; }
h1, h2, h3 { font-weight: 400; text-wrap: balance; hyphens: manual; }
p { text-wrap: pretty; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; text-decoration-color: var(--rule-2); }
a:hover { text-decoration-color: var(--red); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; border-radius: var(--radius); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.sc { font-variant-caps: all-small-caps; letter-spacing: .08em; font-variant-numeric: oldstyle-nums; }
.mono { hyphens: manual; font-family: var(--mono); font-variant-numeric: tabular-nums lining-nums; letter-spacing: 0; }
.small { font-size: var(--t-small); line-height: 1.5; color: var(--ink-2); }
.skip { position: absolute; left: var(--s-4); top: -4rem; z-index: 50; background: var(--ink); color: var(--leaf); padding: var(--s-2) var(--s-4); }
.skip:focus { top: var(--s-3); }

/* Buttons and links */
.btn {
  display: inline-flex; align-items: center; gap: .55em; min-height: 44px; padding: .55em 1.1em;
  border: 1px solid var(--ink); border-radius: var(--radius); background: transparent;
  font-size: 1rem; text-decoration: none; transition: background-color .3s var(--ease), color .3s var(--ease);
}
.btn--ink { background: var(--ink); color: var(--leaf); }
.btn--ink:hover { background: var(--red); border-color: var(--red); }
.link { font-size: 1rem; }
.link--btn {
  display: inline-flex; align-items: center; gap: .5em; min-height: 44px; padding: 0; border: 0; background: none;
  text-decoration: underline; text-decoration-color: var(--rule-2); text-underline-offset: .25em; color: var(--ink-2);
}
.link--btn:hover { color: var(--ink); text-decoration-color: var(--red); }

/* ---------- 2. Running head ---------- */
.head {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s-5);
  padding: var(--s-3) var(--gutter); background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.head__brand { font-size: 1.125rem; letter-spacing: .14em; text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }
.head__chapter { justify-self: center; color: var(--ink-2); font-size: 1rem; font-style: italic; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.head__nav { display: flex; gap: var(--s-5); }
.head__nav a { font-size: 1rem; text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; color: var(--ink-2); }
.head__nav a:hover { color: var(--ink); text-decoration: underline; text-decoration-color: var(--red); }

/* Folios: the page number at the foot of each part; the index refers to them */
.folio { display: block; margin-top: var(--s-8); text-align: right; font-size: 1rem; color: var(--ink-2); }
.part:nth-of-type(odd) .folio { text-align: left; }

/* ---------- The opening spread ---------- */
.opening { padding: clamp(1.25rem, 3vh, 2.5rem) var(--gutter) var(--s-6); }
.spread {
  --w: min(1180px, 100%, calc((100svh - 9.5rem) * 4 / 3));
  position: relative; width: var(--w); margin: 0 auto;
  display: grid; grid-template-columns: 1fr 1fr; aspect-ratio: 4 / 3;
  background: var(--leaf);
  box-shadow: 0 1px 2px rgb(var(--shadow) / .12), 0 18px 40px -18px rgb(var(--shadow) / .35);
}
/* gutter shading where the pages meet */
.spread::after {
  content: ""; position: absolute; inset: 0 auto 0 50%; width: 6%; transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, transparent, rgb(var(--shadow) / .07) 45%, rgb(var(--shadow) / .12) 50%, rgb(var(--shadow) / .07) 55%, transparent);
}
.pg { position: relative; container-type: inline-size; min-width: 0; }
/* Canon margins: inner 1/9 of width, top 1/9 of height (= 1/6 of width), outer 2/9 of width, bottom 2/9 of height (= 1/3 of width). */
.pg__block { position: absolute; top: 16.667cqw; bottom: 33.333cqw; display: flex; flex-direction: column; min-width: 0; }
.pg--verso .pg__block { left: 22.222cqw; right: 11.111cqw; }
.pg--recto .pg__block { left: 11.111cqw; right: 22.222cqw; }
.pg__runhead { position: absolute; top: -9cqw; left: 0; font-size: 3.4cqw; color: var(--ink-2); line-height: 1; }
.pg__runhead--r { left: auto; right: 0; font-style: italic; }
.pg__folio { position: absolute; bottom: 20cqw; left: 22.222cqw; font-size: 3.6cqw; color: var(--ink-2); line-height: 1; }
.pg__foot { position: absolute; bottom: 20cqw; left: 11.111cqw; right: 22.222cqw; display: flex; justify-content: space-between; font: 2.9cqw/1 var(--mono); color: var(--ink-2); }
.pg__foot .pg__folio { position: static; font: 3.6cqw/1 var(--serif); }

.title { font-size: 9.6cqw; line-height: 1.02; letter-spacing: -.015em; font-weight: 400; margin-top: 4cqw; }
.title__lede { margin-top: 5cqw; font-size: 3.55cqw; line-height: 1.5; color: var(--ink); max-width: 60ch; }
.title__go { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 2.5cqw 5cqw; }
.title__go .btn { font-size: max(14px, 3.2cqw); }
.title__go .link { font-size: max(14px, 3.2cqw); min-height: 44px; display: inline-flex; align-items: center; }
.title__plat { margin-top: 4cqw; font-size: max(12px, 2.9cqw); color: var(--ink-2); }

.art__title { font-size: 6.2cqw; line-height: 1.1; font-style: italic; margin-top: 2cqw; text-wrap: balance; }
.art__by { margin-top: 2.5cqw; font-size: 3cqw; color: var(--ink-2); }
.art__p { font-size: 3.55cqw; line-height: 1.5; text-align: justify; hyphens: auto; }
.art__p--first { margin-top: 5cqw; }
.art__p + .art__p { text-indent: 1.5em; }
.mk { background: var(--red-tint); color: inherit; padding: 0 .06em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.mk sup, .sn__n, .art mark sup { color: var(--red); font-size: .68em; line-height: 0; font-variant-numeric: lining-nums; }
.pg__note { position: absolute; left: calc(100% + 3cqw); width: 18cqw; top: 33cqw; font-size: 2.65cqw; line-height: 1.4; font-style: italic; color: var(--red); }
.pg__note sup { font-style: normal; font-size: .9em; }

.canon-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cl { fill: none; stroke: var(--red); stroke-width: 1; vector-effect: non-scaling-stroke; opacity: .2; }
.cl--3 { stroke: var(--rule); opacity: 0; }
.cl--4 { opacity: .32; stroke-dasharray: 3 3; }
/* Signature moment: the construction draws itself, from a visible default. */
@media (prefers-reduced-motion: no-preference) {
  .js .cl { stroke-dasharray: 600; stroke-dashoffset: 0; animation: draw 2.4s var(--ease) both; }
  .js .cl--1 { animation-delay: .15s; }
  .js .cl--2 { animation-delay: .7s; }
  .js .cl--4 { stroke-dasharray: 3 3; animation: block 1.4s var(--ease) 1.5s both; }
  @keyframes draw { from { stroke-dashoffset: 600; opacity: .7; } to { stroke-dashoffset: 0; opacity: .2; } }
  @keyframes block { from { opacity: 0; } to { opacity: .32; } }
}
.opening__cap { width: min(62ch, 100%); margin: var(--s-5) auto 0; text-align: center; font-size: var(--t-small); color: var(--ink-2); }

/* ---------- Parts (chapters) ---------- */
.part { max-width: var(--wide); margin: 0 auto; padding: var(--s-9) var(--gutter) var(--s-6); border-top: 1px solid var(--rule); }
.part__head { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s-4) var(--s-7); align-items: end; margin-bottom: var(--s-7); }
.part__head h2 { font-size: var(--t-head); line-height: 1.15; max-width: 24ch; }
.part__lede { color: var(--ink-2); max-width: 46ch; font-size: 1.0625rem; }

/* ---------- 3. The reader ---------- */
.reader { display: grid; grid-template-columns: 15rem minmax(0, 1fr); grid-template-areas: "ctl page" "marks page"; gap: var(--s-6) var(--s-7); align-items: start; }
.controls { grid-area: ctl; display: grid; gap: var(--s-5); }
.ctl { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: var(--s-2); }
.ctl__label { padding: 0; font-size: 1.0625rem; color: var(--ink); }
.ctl__val { font-size: var(--t-small); color: var(--ink-2); }
.ctl__margins { font-size: var(--t-small); color: var(--ink-2); padding-top: var(--s-3); border-top: 1px solid var(--rule); }
.stepper { display: flex; align-items: center; border: 1px solid var(--rule-2); border-radius: var(--radius); width: max-content; background: var(--leaf); }
.stepper__btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; }
.stepper__btn:hover { color: var(--red); }
.stepper__btn:disabled { color: var(--rule-2); cursor: not-allowed; }
.stepper__val { min-width: 5.5ch; text-align: center; font-size: 1rem; }
input[type="range"] { width: 100%; height: 44px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink-2); }
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink-2); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%; background: var(--leaf); border: 1.5px solid var(--ink); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--leaf); border: 1.5px solid var(--ink); }
input[type="range"]:hover::-webkit-slider-thumb { border-color: var(--red); }
input[type="range"]:focus-visible { outline-offset: 0; }
.themes { display: flex; gap: var(--s-2); }
.theme { position: relative; flex: 1; }
.theme input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.theme span { display: grid; place-items: center; min-height: 44px; padding: 0 var(--s-2); border: 1px solid var(--rule-2); border-radius: var(--radius); font-size: .9375rem; }
.theme--paper span { background: #fbf8f1; color: #1f1b16; }
.theme--vellum span { background: #efe2c6; color: #2b2117; }
.theme--night span { background: #1e1a16; color: #ded5c4; }
.theme input:checked + span { outline: 2px solid var(--red); outline-offset: 2px; }
.theme input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 4px; }

/* The page: the theme sets its own tokens; type settings arrive as custom properties from script.js */
.rpage-wrap { grid-area: page; position: relative; min-width: 0; }
.rpage {
  --size: 19px; --measure: 62; --leading: 1.5;
  --pg-ink: #1f1b16; --pg-ink-2: #574f43; --pg-bg: #fbf8f1; --pg-red: #a1301c; --pg-tint: #f2dccf; --pg-rule: #d8cfbf;
  container-type: inline-size;
  position: relative; height: min(46rem, calc(100svh - 7.5rem)); overflow-y: auto; overflow-x: hidden;
  background: var(--pg-bg); color: var(--pg-ink);
  font-size: var(--size);
  box-shadow: 0 1px 2px rgb(var(--shadow) / .12), 0 22px 44px -24px rgb(var(--shadow) / .4);
  scrollbar-color: var(--pg-rule) var(--pg-bg); scrollbar-width: thin;
  transition: background-color .5s var(--ease), color .5s var(--ease);
  /* page width from the measure: the text block (measure x ~0.5em a character) is two thirds of the page */
  max-width: calc(var(--measure) * 0.75em);
  margin-inline: auto;
}
.rpage:focus-visible { outline-offset: 4px; }
.rpage[data-theme="vellum"] { --pg-ink: #2b2117; --pg-ink-2: #5d4c37; --pg-bg: #efe2c6; --pg-red: #93290f; --pg-tint: #e3c3a4; --pg-rule: #d2bf9c; }
.rpage[data-theme="night"] { --pg-ink: #ded5c4; --pg-ink-2: #aa9e8a; --pg-bg: #1e1a16; --pg-red: #ec937b; --pg-tint: #4d2c22; --pg-rule: #3b342c; }
.rpage ::selection { background: var(--pg-tint); color: var(--pg-ink); }
.rpage__head, .rpage__foot {
  position: sticky; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: var(--s-4);
  padding-inline: calc(100% / 9) calc(100% * 2 / 9); background: var(--pg-bg);
  font-size: max(13px, .72em); color: var(--pg-ink-2); transition: background-color .5s var(--ease);
}
.rpage__head { top: 0; padding-block: 1.4em .9em; }
.rpage__runhead { font-style: italic; }
.rpage__bar { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--pg-rule); }
.rpage__fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--pg-red); height: 2px; top: -.5px; }
.rpage__foot { bottom: 0; padding-block: .9em 1.4em; border-top: 1px solid var(--pg-rule); font-size: max(13px, .7em); }

/* The article: inner padding 1/9 of the page, outer 2/9; notes float out into the outer margin (Tufte-style). */
.art { padding: 2.2em calc(100% * 2 / 9) 3em calc(100% / 9); line-height: var(--leading); transition: line-height .35s var(--ease); }
.art__header { margin-bottom: 1.6em; }
.art__h { font-size: 1.7em; line-height: 1.12; font-style: italic; }
.art .art__meta { text-align: left; }
.art__meta { margin-top: .6em; font-size: .78em; color: var(--pg-ink-2); }
.art__meta .mono { font-size: .95em; }
.art p { text-align: justify; hyphens: auto; }
.art p + p { text-indent: 1.4em; }
.art__first .sc { letter-spacing: .06em; }
.art mark { background: var(--pg-tint); color: inherit; padding: 0 .05em; cursor: pointer; box-decoration-break: clone; -webkit-box-decoration-break: clone; transition: background-color .3s var(--ease); }
.art mark.is-active { outline: 1px solid var(--pg-red); outline-offset: 1px; }
.art mark sup { color: var(--pg-red); }
.art__end { text-align: center; text-indent: 0 !important; margin-top: 1.5em; }
.fleuron { width: 3em; height: 1em; fill: none; stroke: var(--pg-ink-2); stroke-width: 1; }

/* Side notes: float into the outer margin; width is the margin less a gap */
.sn {
  float: right; clear: right; position: relative;
  width: calc(100% / 3 * .84); margin-right: calc(-100% / 3 * .92); margin-top: .2em; margin-bottom: .8em;
  font-size: max(13px, .74em); line-height: 1.4; font-style: italic; color: var(--pg-red);
  text-indent: 0; text-align: left; hyphens: manual;
}
.sn__n { font-style: normal; margin-right: .2em; }
.sn--edit { font-style: normal; color: var(--pg-ink); }
.sn textarea {
  display: block; width: 100%; min-height: 6.5em; padding: .45em .5em; resize: vertical;
  font: inherit; font-size: max(14px, 1em); line-height: 1.4; color: var(--pg-ink); background: var(--pg-bg);
  border: 1px solid var(--pg-ink-2); border-radius: var(--radius);
}
.sn textarea:focus-visible { outline: 2px solid var(--pg-red); outline-offset: 1px; }
.sn__row { display: flex; gap: .6em; margin-top: .35em; align-items: center; flex-wrap: wrap; }
.sn__row button { min-height: 32px; padding: 0 .7em; border: 1px solid var(--pg-ink-2); border-radius: var(--radius); background: none; color: var(--pg-ink); font-size: 13px; }
.sn__row button.sn__save { background: var(--pg-ink); color: var(--pg-bg); border-color: var(--pg-ink); }
.sn__count { font: 12px/1 var(--mono); color: var(--pg-ink-2); margin-left: auto; }
.sn__err { margin-top: .3em; font-size: 13px; color: var(--pg-red); font-style: normal; }
.sn__err:empty { display: none; }
/* narrow pages: notes sit under their line, inside the measure */
@container (max-width: 560px) {
  .art { padding-inline: 1.15em; }
  .art p { text-align: left; }
  .sn { float: none; display: block; width: auto; margin: .5em 0 .7em 1.4em; padding: .45em .6em; background: color-mix(in srgb, var(--pg-tint) 45%, transparent); border-radius: var(--radius); }
  .rpage__head, .rpage__foot { padding-inline: 1.15em; }
}

/* Floating mark tool */
.marktool {
  position: absolute; z-index: 5; display: flex; gap: 1px; padding: 0; border-radius: var(--radius); overflow: hidden;
  background: var(--ink); box-shadow: 0 6px 18px -6px rgb(var(--shadow) / .55);
  transform: translate(-50%, calc(-100% - 10px));
}
.marktool[hidden] { display: none; }
.marktool button { display: inline-flex; align-items: center; gap: .4em; min-height: 40px; padding: 0 .9em; border: 0; background: var(--ink); color: #f5f0e6; font-size: .9375rem; }
.marktool button:hover, .marktool button:focus-visible { background: #3a332b; }
.marktool button:focus-visible { outline-offset: -3px; outline-color: #f2a28d; }
.marktool button[hidden] { display: none; }

/* Marks list */
.marks { grid-area: marks; display: grid; gap: var(--s-3); align-content: start; }
.marks__h { font-size: 1.0625rem; display: flex; align-items: baseline; gap: var(--s-2); padding-top: var(--s-4); border-top: 1px solid var(--rule); }
.marks__h .mono { color: var(--red); font-size: .9375rem; }
.marks__empty { font-size: var(--t-small); color: var(--ink-2); }
.marks__list { list-style: none; padding: 0; display: grid; gap: var(--s-4); counter-reset: m; }
.marks__list li { display: grid; gap: var(--s-1); font-size: var(--t-small); line-height: 1.45; }
.marks__q { font-style: italic; }
.marks__q::before { content: "“"; } .marks__q::after { content: "”"; }
.marks__n { color: var(--red); }
.marks__acts { display: flex; gap: var(--s-4); }
.marks__acts button { min-height: 32px; padding: 0; border: 0; background: none; color: var(--ink-2); font-size: var(--t-small); text-decoration: underline; text-decoration-color: var(--rule-2); text-underline-offset: .22em; }
.marks__acts button:hover { color: var(--ink); text-decoration-color: var(--red); }
.marks__status { font-size: var(--t-small); color: var(--ink-2); min-height: 1.4em; }

/* ---------- The canon ---------- */
.canon { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s-7); align-items: start; }
.canon__fig svg { width: 100%; height: auto; display: block; }
.canon__fig figcaption { margin-top: var(--s-4); max-width: 60ch; }
.cf-page rect { fill: var(--leaf); stroke: var(--rule-2); stroke-width: .8; }
.cf-lines path { fill: none; stroke: var(--red); stroke-width: .7; opacity: .55; }
.cf-block rect { fill: rgb(161 48 28 / .05); stroke: var(--ink); stroke-width: .8; }
.cf-rows path { stroke: var(--ink-2); stroke-width: 1.6; opacity: .3; }
.cf-dim path { fill: none; stroke: var(--ink); stroke-width: .8; }
.cf-dim text { font: 13px var(--mono); fill: var(--ink); text-anchor: middle; }
.canon__text { display: grid; gap: var(--s-4); max-width: 62ch; }
.canon__text p + p { text-indent: 1.4em; }
.canon__live { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4) var(--s-5); margin-top: var(--s-4); padding-block: var(--s-4); border-block: 1px solid var(--rule); }
.canon__live dt { font-size: 1rem; color: var(--ink-2); }
.canon__live dd { font-size: 1rem; }
.side { font-style: italic; }
.side .mono { font-style: normal; }
.keeps { margin-top: var(--s-8); }
.keeps__h { font-size: 1.35rem; font-style: italic; margin-bottom: var(--s-5); }
.keeps__cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-7); }
.keeps__list { display: grid; gap: 0; }
.keeps__list dt { font-size: 1.0625rem; padding-bottom: var(--s-2); border-bottom: 1px solid var(--ink); }
.keeps__list dd { padding: var(--s-2) 0; border-bottom: 1px solid var(--rule); font-size: 1.0625rem; }
.keeps__list--off dd { color: var(--ink-2); text-decoration: line-through; text-decoration-color: rgb(161 48 28 / .55); text-decoration-thickness: 1px; }
.keeps__type { margin-top: var(--s-5); max-width: 70ch; }

/* ---------- The queue ---------- */
.queue { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--s-7); align-items: start; }
.save { display: grid; gap: var(--s-5); }
.save__form { display: grid; gap: var(--s-2); }
.save__label { font-size: 1.0625rem; }
.save__row { display: flex; gap: var(--s-2); }
.save__input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 var(--s-3); font-size: 1rem;
  background: var(--leaf); border: 1px solid var(--rule-2); border-radius: var(--radius);
}
.save__input::placeholder { color: #6e6556; }
.save__input:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }
.save__input[aria-invalid="true"] { border-color: var(--red); }
.save__btn { min-width: 6.5rem; justify-content: center; }
.save__btn[aria-busy="true"] { cursor: progress; background: #3a332b; border-color: #3a332b; }
.save__msg { font-size: var(--t-small); color: var(--red); min-height: 0; }
.save__msg:empty { display: none; }
.save__msg.is-ok { color: var(--ink); }
.save__msg .retry { margin-left: .4em; padding: 0; border: 0; background: none; color: var(--ink); text-decoration: underline; text-underline-offset: .2em; min-height: 32px; font-size: inherit; }
.save__progress { display: grid; gap: var(--s-1); font-size: var(--t-small); color: var(--ink-2); }
.save__progress[hidden] { display: none; }
.save__step { display: flex; align-items: center; gap: .6em; }
.save__step::before { content: ""; width: .55em; height: .55em; border: 1px solid var(--rule-2); border-radius: 50%; }
.save__step.is-now { color: var(--ink); }
.save__step.is-now::before { border-color: var(--red); background: var(--red); }
.save__step.is-done::before { background: var(--ink-2); border-color: var(--ink-2); }
@media (prefers-reduced-motion: no-preference) { .save__step.is-now::before { animation: pulse 1s ease-in-out infinite alternate; } @keyframes pulse { to { opacity: .35; } } }
.offline { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border: 1px solid var(--ink-2); border-radius: var(--radius); background: var(--leaf); font-size: var(--t-small); }
.offline[hidden] { display: none; }

.contents__top { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s-4); flex-wrap: wrap; border-bottom: 1px solid var(--ink); padding-bottom: var(--s-2); }
.tabs { display: flex; gap: var(--s-5); }
.tab { min-height: 44px; padding: 0; border: 0; background: none; font-size: 1.0625rem; color: var(--ink-2); border-bottom: 2px solid transparent; display: inline-flex; align-items: center; gap: .4em; }
.tab .mono { font-size: .875rem; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); }
.contents__sum { font-size: var(--t-small); color: var(--ink-2); padding-bottom: var(--s-2); }
.qlist { list-style: none; padding: 0; }
.qi { padding: var(--s-3) 0; border-bottom: 1px solid var(--rule); display: grid; gap: var(--s-1); transition: background-color .8s var(--ease); }
.qi.is-new { background: var(--red-tint); }
.qi__main { display: flex; align-items: baseline; gap: var(--s-2); }
.qi__title { font-size: 1.125rem; line-height: 1.3; text-decoration: none; }
a.qi__title { text-decoration: underline; text-decoration-color: var(--rule-2); }
.qi__lead { flex: 1; min-width: 1.5rem; border-bottom: 1px dotted var(--ink-2); transform: translateY(-.3em); }
.qi__min { white-space: nowrap; font-size: 1rem; min-width: 2ch; text-align: right; }
.qi__min::after { content: " min"; color: var(--ink-2); font-size: .8125rem; }
.qi__foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.qi__meta { font-size: .8125rem; color: var(--ink-2); }
.qi__meta .wait { color: var(--red); }
.qi__acts { display: flex; gap: var(--s-4); }
.qi__acts button { min-height: 32px; padding: 0; border: 0; background: none; font-size: .9375rem; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--rule-2); text-underline-offset: .22em; }
.qi__acts button:hover { color: var(--ink); text-decoration-color: var(--red); }
.qempty { padding: var(--s-7) 0; text-align: center; display: grid; gap: var(--s-2); justify-items: center; }
.qempty[hidden] { display: none; }
.qempty__h { font-size: 1.35rem; font-style: italic; }
.qempty .small { max-width: 40ch; }
.undo { font-size: var(--t-small); color: var(--ink-2); min-height: 2.75rem; display: flex; align-items: center; gap: var(--s-3); }
.undo button { min-height: 32px; padding: 0; border: 0; background: none; color: var(--ink); text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: .22em; font-size: inherit; display: inline-flex; align-items: center; gap: .3em; }

/* ---------- Editions ---------- */
.editions { list-style: none; padding: 0; border-top: 1px solid var(--ink); }
.ed { display: grid; grid-template-columns: 10rem 12rem minmax(0, 1fr); gap: var(--s-2) var(--s-5); padding: var(--s-5) 0; border-bottom: 1px solid var(--rule); }
.ed__n { font-size: 1.125rem; }
.ed__d { font-size: .9375rem; color: var(--ink-2); padding-top: .2em; }
.ed__body { display: grid; gap: var(--s-2); max-width: 64ch; }

/* ---------- Price ---------- */
.price { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-7); }
.tier { display: grid; gap: var(--s-3); align-content: start; padding: var(--s-5) 0; border-top: 1px solid var(--ink); max-width: 52ch; }
.tier__name { font-size: 1.125rem; }
.tier__cost { font-size: var(--t-head); line-height: 1.15; }
.tier--bound .tier__cost { color: var(--red); }
.price__go { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--s-4) var(--s-5); align-items: center; margin-top: var(--s-5); }

/* ---------- Index and colophon ---------- */
.index-part { max-width: var(--wide); margin: 0 auto; padding: var(--s-8) var(--gutter) var(--s-7); border-top: 1px solid var(--rule); }
.index__h { font-size: var(--t-head); margin-bottom: var(--s-5); }
.index { list-style: none; padding: 0; columns: 3 16rem; column-gap: var(--s-7); font-size: 1rem; line-height: 1.5; }
.index li { break-inside: avoid; padding-left: 1em; text-indent: -1em; }
.index a { display: inline-block; min-width: 24px; min-height: 24px; text-indent: 0; text-align: center; font-variant-numeric: oldstyle-nums; }
.colophon { margin-top: var(--s-7); padding-top: var(--s-5); border-top: 1px solid var(--rule); display: grid; gap: var(--s-2); max-width: 70ch; }
.colophon a { display: inline-block; min-height: 24px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .head__chapter { display: none; }
  .head { grid-template-columns: auto 1fr; }
  .head__nav { justify-self: end; gap: var(--s-4); }
  .reader { grid-template-columns: 13rem minmax(0, 1fr); gap: var(--s-5); }
}
@media (max-width: 900px) {
  .part { padding-top: var(--s-8); }
  .part__head, .canon, .queue { grid-template-columns: 1fr; }
  .part__head { gap: var(--s-3); margin-bottom: var(--s-6); }
  .reader { grid-template-columns: 1fr; grid-template-areas: "ctl" "page" "marks"; }
  .controls { grid-template-columns: auto 1fr 1fr; gap: var(--s-4) var(--s-5); align-items: end; }
  .ctl--theme { grid-column: 1 / 3; }
  .ctl--reset { justify-self: start; }
  .ctl__margins { display: none; }
  .rpage { height: min(40rem, calc(100svh - 7rem)); }
  .ed { grid-template-columns: 9rem 1fr; }
  .ed__body { grid-column: 1 / -1; }
  .price { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .head__nav a:nth-child(n+4) { display: none; }
  .spread { grid-template-columns: 1fr; aspect-ratio: auto; width: 100%; box-shadow: none; background: none; }
  .spread::after, .canon-lines { display: none; }
  .pg { background: var(--leaf); box-shadow: 0 1px 2px rgb(var(--shadow) / .12), 0 14px 30px -16px rgb(var(--shadow) / .35); }
  .pg--verso { background: none; box-shadow: none; }
  .pg--verso .pg__block { position: static; padding: var(--s-4) 0 var(--s-6); }
  .pg--verso .pg__runhead, .pg--verso > .pg__folio { display: none; }
  .title { font-size: clamp(2.4rem, 11vw, 3.2rem); margin: 0; }
  .title__lede { font-size: 1.0625rem; margin-top: var(--s-4); }
  .title__go { margin-top: var(--s-5); gap: var(--s-3) var(--s-5); }
  .title__go .btn, .title__go .link { font-size: 1rem; }
  .title__plat { font-size: var(--t-small); margin-top: var(--s-4); }
  .pg--recto { aspect-ratio: 2 / 3; }
  .pg--recto .pg__block { left: 9cqw; right: 9cqw; }
  .pg--recto .pg__foot { left: 9cqw; right: 9cqw; font-size: 3.4cqw; }
  .art__p { font-size: 4.6cqw; }
  .art__title { font-size: 7.6cqw; }
  .art__by, .pg__runhead { font-size: 3.8cqw; }
  .art__p--more { display: none; }
  .pg__note { position: static; width: auto; margin-top: 4cqw; font-size: 3.6cqw; }
  .controls { grid-template-columns: auto 1fr; }
  .ctl--size { grid-column: 1; grid-row: 1; }
  .ctl--reset { grid-column: 2; grid-row: 1; justify-self: end; align-self: end; }
  .ctl--measure, .ctl--leading, .ctl--theme { grid-column: 1 / -1; }
  .keeps__cols { grid-template-columns: 1fr; gap: var(--s-5); }
  .canon__live { grid-template-columns: 1fr; }
  .ed { grid-template-columns: 1fr; gap: var(--s-1); }
  .qi__title { font-size: 1.0625rem; }
}
@media (max-width: 420px) {
  .head { gap: var(--s-3); }
  .head__nav { gap: var(--s-3); }
  .opening__cap { text-align: left; }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
