:root {
  --paper: #F5F1E8;
  --ink: #1C1815;
  --oxblood: #7E4F5D;
  --faint: rgba(28, 24, 21, 0.18);
  --quiet: rgba(28, 24, 21, 0.55);
  --measure: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16130F;
    --ink: #DCD3C4;
    --oxblood: #B4808E;
    --faint: rgba(220, 211, 196, 0.18);
    --quiet: rgba(220, 211, 196, 0.55);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "EB Garamond", Garamond, Sabon, "Palatino Linotype", Palatino, Georgia, serif;
  font-size: clamp(1.0625rem, 0.95rem + 0.55vw, 1.25rem);
  line-height: 1.65;
  font-variant-numeric: oldstyle-num;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  animation: fade 0.5s ease-out both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
}

a {
  color: var(--oxblood);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

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

/* ------------------------------------------------------------ title page */

.titlepage {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3rem, 10vh, 7rem) 1.5rem 5rem;
  text-align: center;
}

.device {
  width: 82px;
  height: auto;
  opacity: 0.85;
  margin-bottom: 2.5rem;
}

.titlepage h1 {
  font-weight: 400;
  font-size: clamp(2.4rem, 1.6rem + 3.2vw, 3.4rem);
  line-height: 1.12;
  letter-spacing: 0.005em;
  margin: 0;
}

.byline {
  margin: 1.1rem 0 0;
  font-style: italic;
  color: var(--quiet);
  font-size: 1.05rem;
}

.rule {
  border: 0;
  border-top: 1px solid var(--faint);
  width: 4.5rem;
  margin: 3.5rem auto;
}

.contents-head {
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--quiet);
  margin: 0 0 2rem;
}

/* The contents is the best design opportunity: set it as a diagram, not a list. */
.contents {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

.contents li {
  display: grid;
  grid-template-columns: 2.6rem 1fr auto;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--faint);
}

.contents li:last-child { border-bottom: 0; }

.contents .num {
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  color: var(--oxblood);
}

.contents a {
  color: var(--ink);
  text-decoration: none;
}

.contents a:hover { text-decoration: underline; }

.contents a.frame {
  font-style: italic;
  color: var(--quiet);
}

.contents .place {
  font-style: italic;
  font-size: 0.92rem;
  color: var(--quiet);
  text-align: right;
}

.colophon-link {
  margin-top: 3.5rem;
  font-size: 0.85rem;
}

.colophon-link a { color: var(--quiet); }

/* -------------------------------------------------------------- chapters */

.chapter {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.75rem, 5vh, 3rem) 1.5rem 4rem;
}

/* Running head, as on a printed page. Doubles as the way home from the top of
   a chapter; the pagenav at the foot covers the other end. */
.runninghead {
  display: block;
  text-align: center;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--quiet);
  text-decoration: none;
  margin-bottom: clamp(2.75rem, 7vh, 4.5rem);
}

.runninghead:hover { color: var(--oxblood); }

.chapter header { text-align: center; margin-bottom: 3rem; }

.category {
  margin: 0;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--quiet);
}

.numeral {
  font-weight: 400;
  font-size: 2rem;
  color: var(--oxblood);
  margin: 0.7rem 0 0;
  letter-spacing: 0.06em;
}

.placename {
  margin: 0.5rem 0 0;
  font-style: italic;
  font-size: 1.25rem;
}

.frame-title {
  font-weight: 400;
  font-style: italic;
  font-size: 1.6rem;
  margin: 0;
}

.prose p {
  margin: 0 0 1.35rem;
  hanging-punctuation: first;
}

/* Calvino sets the frame narrative in italic; so do we. */
.frame-prose p { font-style: italic; }

.attrib {
  margin: 2.5rem 0 0;
  text-align: right;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--quiet);
}

.fleuron {
  text-align: center;
  color: var(--oxblood);
  opacity: 0.65;
  margin: 3rem 0;
  font-size: 0.9rem;
}

.pagenav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: baseline;
  border-top: 1px solid var(--faint);
  padding-top: 1.5rem;
  font-size: 0.85rem;
}

.pagenav a { text-decoration: none; }
.pagenav a:hover { text-decoration: underline; }
.pagenav a[rel="next"] { text-align: right; }
.pagenav .toc-link { color: var(--quiet); }

@media (max-width: 34rem) {
  .pagenav {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.85rem;
    text-align: center;
  }
  .pagenav a[rel="next"] { text-align: center; }
  .contents li { grid-template-columns: 2.2rem 1fr; }
  .contents .place { grid-column: 2; text-align: left; }
}

/* The hand. Set in the paper colour: invisible in ordinary reading, but it
   survives selection, find-in-page and copy-paste. Authors can find themselves;
   nobody else is troubled by it. */
.hand {
  text-align: right;
  color: var(--paper);
  margin: 2.5rem 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  user-select: text;
}
