body {
  margin: 0;
  padding: 24px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  color: #111;
  background: #fff;
  /* Lets the page-number bar sit at the bottom of the window on short pages */
  box-sizing: border-box;
  min-height: 100vh;
  /* On phones, 100vh is the screen without the browser's toolbars, so pages came out a little
     too tall (they scrolled, and the bottom row hid under the toolbar). dvh is the height you
     actually see right now — whether Safari's address bar is full size or shrunk — so the
     bottom row always lands at the bottom of the screen, on every page. Browsers without it
     keep the 100vh above. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Page numbers at the bottom right: 𐡷 1 2 3 𐡸 */
.pager {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 14px;
  margin-top: auto;
  padding-top: 32px;
  font-size: 18px;
}

.pager .current {
  text-decoration: underline;
}

.pager .disabled {
  color: #ccc;
}

/* Previous / next are fleurons (𐡷 𐡸, from the bundled font) rather than arrows */
.pager .arrow {
  font-family: "Fleuron", serif;
  font-size: 22px;
  line-height: 0; /* the fleuron font reaches lower than the text; without this the bottom row
                     grows a little and Contact sits higher on pages with page numbers */
  text-decoration: none;
}

.pager .arrow:hover {
  text-decoration: none;
  opacity: 0.6;
}

.pager .arrow:disabled:hover,
.pager .arrow.disabled:hover {
  opacity: 1;
}

h1 {
  margin: 0 0 24px;
  font-size: 24px;
  font-weight: normal;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Short explanation at the top of the Archive and Catalogue pages */
.intro {
  position: relative;
  z-index: 100000; /* above the photos, even ones dragged over it */
  max-width: 36em;
  margin: 0 0 24px;
  font: 18px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.intro a {
  text-decoration: underline;
}

/* Archive / Catalogue listing: one item per line */
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entries li {
  margin: 0 0 8px;
  font-size: 18px; /* so wrapped lines are spaced for 18px text */
  line-height: 1.4;
}

/* The line itself: always one line, cut off with an ellipsis if too long */
.entries .line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.author,
.note-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-weight: bold;
}

.details {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 18px;
}

/* Catalogue lines are never cut off (the price is at the end); they wrap instead */
.entries-catalogue .line {
  white-space: normal;
  overflow: visible;
}

/* Single entry page */
.entry {
  margin: 0 0 24px;
  font-size: 18px;
  line-height: 1.4;
}

.note-body {
  max-width: 36em;
  font-size: 18px;
  margin: 0 0 24px;
  line-height: 1.5;
}

.note-body p {
  margin: 0 0 1em;
}

.photo {
  margin: 0;
}

/* Archive / Catalogue item page: text on the left half, photo on the right half */
.book {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
  font-size: 18px;
  line-height: 1.4;
}

.book-text p {
  margin: 0;
}

.book-imprint,
.book-price,
.book-details {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.book-text .book-details {
  margin-top: 1em;
}

.book-text .book-details p + p {
  margin-top: 1em;
}

.book-photo .photo img {
  max-height: calc(100vh - 160px);
  max-height: calc(100svh - 160px);
}

/* More than one photo: numbers under the photo (1 2 3) pick which one shows (public/book.js) */
@font-face {
  font-family: "Fleuron";
  src: url("fonts/NotoSansPalmyrene-Regular.ttf") format("truetype");
  unicode-range: U+10877-10878;
}

/* The figure is as wide as the photo showing, so the numbers below it are centred on it */
.gallery {
  display: flex;
  width: fit-content;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}

/* On computers the numbers hang just below the photo without taking up room of their own, so
   the photo stays full size and Contact stays at the bottom of the window. (On phones the text
   comes after the photo, so there the numbers take their own line.) */
@media (min-width: 701px) {
  .gallery {
    position: relative;
  }

  .gallery-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1; /* above the bottom row (Contact), which reaches up into this space */
  }
}

.gallery .frames img[hidden] {
  display: none;
}

.gallery-nav {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 8px;
  font-size: 18px;
}

.gallery-nav button {
  padding: 4px 2px;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.gallery-nav button:hover,
.gallery-nav button.current {
  text-decoration: underline;
}

@media (max-width: 700px) {
  /* On phones the photo comes first, the text below it */
  .book {
    grid-template-columns: 1fr;
  }

  .book-photo {
    order: -1;
  }
}

.photo img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  max-height: 80svh;
  height: auto;
}

/* Home page contact link, pinned to the bottom of the window */
.contact-link {
  align-self: flex-start; /* only as wide as the word, so it doesn't cover List */
  margin: auto 0 0;
  padding-top: 24px;
  font-size: 24px;
}

/* Bottom of the page: Contact on the left, page numbers (← 1 2 3 →) on the right */
.foot {
  position: relative;
  margin-top: auto;
  padding-top: 32px;
  /* the row's own right and bottom padding, where the page numbers sit (changed on phones) */
  --foot-pad-right: 0px;
  --foot-pad-bottom: 0px;
}

.foot .contact-link,
.foot .pager {
  margin: 0;
  padding: 0;
}

/* The page numbers are placed in the row's bottom-right corner rather than beside Contact, so
   they never change the row's height: Contact is in exactly the same place on every page,
   with or without page numbers, in every browser. */
.foot .pager {
  position: absolute;
  right: var(--foot-pad-right);
  bottom: calc(var(--foot-pad-bottom) + 1px); /* +1px: the numbers sit on Contact's line */
}

/* Contact page: the email address, centred in the window */
main.centered {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-email {
  margin: 0;
  font-size: 24px;
}

/* Archive / Current photo pages: the list icon and the search box, side by side below the header */
.pile-tools {
  position: relative;
  z-index: 100000; /* above the photos */
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 16px;
}

.pile-tools .list-link {
  margin: 0 0 0 -4px;
}

/* The search: a magnifying glass; clicked, a text box opens out to its left and the glass
   (now the search button) moves along to the right of it */
.pile-search {
  display: flex;
  align-items: center;
  margin: 0;
}

.pile-search input {
  box-sizing: border-box;
  width: 0;
  min-width: 0;
  margin: 0;
  padding: 4px 0;
  font: 15px "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: inherit;
  background: #fff;
  border: 0 solid #111; /* no border while closed, so the glass sits exactly where the box opens */
  border-radius: 0;
  outline: none;
  opacity: 0;
  visibility: hidden;
  -webkit-appearance: none;
  appearance: none;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.2s ease, visibility 0s 0.25s;
}

.pile-search.open input {
  width: min(220px, 55vw);
  padding: 4px 8px;
  border-width: 1px;
  opacity: 1;
  visibility: visible;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
}

/* Phones: 16px, the smallest size at which iPhones don't zoom in when you tap the box */
@media (max-width: 700px) {
  .pile-search input {
    font-size: 16px;
  }
}

.pile-search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.pile-search button {
  display: block;
  margin: 0;
  padding: 0;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 0;
}

.pile-search button svg {
  display: block;
  overflow: visible; /* the glass's edge reaches the very edge of the drawing */
}

.pile-search.open button {
  margin-left: 10px; /* to the right of the open box */
}

.pile-search button:hover {
  opacity: 0.6;
}

.pile-empty {
  font: 18px "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #999;
}

.pile-empty[hidden] {
  display: none;
}

/* Page numbers with nothing to show for the search are left out */
.pager button[hidden] {
  display: none;
}

/* List icon on the Archive / Catalogue photo pages: just below the header, on the left */
.list-link {
  position: relative;
  z-index: 100000; /* above the photos */
  align-self: flex-start;
  margin: 0 0 16px -4px; /* -4px: the icon lines up with the header despite the padding */
  line-height: 0;
}

.list-link a {
  display: inline-block;
  padding: 4px; /* a slightly bigger target to click */
  color: inherit;
}

.list-link svg {
  display: block;
}

.list-link a:hover {
  opacity: 0.6;
}

/* The same icon in the list pages' header ("The Grottoes · Archive · [icon]"), sized to the text */
.list-icon svg {
  display: inline-block;
  width: auto;
  height: 0.9em;
  vertical-align: -0.12em;
}

/* Text and links always stay above the draggable photos, so they can be read and clicked */
header,
nav,
.contact-link {
  position: relative;
  z-index: 100000;
}

/* Piles: photos piled in the middle of the screen, draggable anywhere */
.pile-item {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 220px;
  height: auto;
  visibility: hidden; /* until placed by pile.js */
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.pile-item.placed {
  visibility: visible;
}

.pile-item[hidden] {
  display: none;
}

.pile-item.dragging {
  cursor: grabbing;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

nav ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 24px;
  font-style: italic;
}

/* Pile pages: the page numbers are buttons (they swap piles without leaving the page) */
.pager button {
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.pager button:hover {
  text-decoration: underline;
}

.pager button.current {
  text-decoration: underline;
  cursor: default;
}

.pager button:disabled {
  color: #ccc;
  text-decoration: none;
  cursor: default;
}

/* Item pages: fleurons at the left and right edges of the window go to the newer / older
   item (the ← → keys do the same).
   At either end of the list there's no fleuron on that side. */
.item-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100000;
  padding: 12px 4px;
  font: 26px/1 "Fleuron", serif;
  color: inherit;
  text-decoration: none;
}

.item-newer {
  left: 20px;
}

.item-older {
  right: 20px;
}

a.item-nav:hover {
  opacity: 0.6;
}

/* On phones the fleurons sit a little in from the edges, over the photo where they meet it */
@media (max-width: 700px) {
  .item-nav {
    padding: 12px 6px;
    font-size: 26px;
    /* Half of the screen with Safari's toolbars at full size. "50%" follows the window as the
       toolbars shrink and grow while scrolling, which made the fleurons jump up and down;
       this stays put. Browsers without svh keep the 50% above. */
    top: 50svh;
    transform: translate3d(0, -50%, 0); /* drawn on its own layer: no shaking while scrolling */
  }

  .item-newer {
    left: 6px;
  }

  .item-older {
    right: 6px;
  }
}

/* Until its photo has loaded, an item's text and photo are held back so they appear together */
.item-waiting .book {
  visibility: hidden;
}

/* Phones: on the photo pages (home, Archive and Catalogue piles) the bottom row (Contact, and
   the page numbers where there are any) sits at the bottom of the screen, floating over the
   photos with no background of its own — like the header at the top.
   It's placed at the bottom of the page (which on these pages is exactly one screen tall)
   rather than pinned to the screen edge: Safari on newer iPhones paints a solid white strip
   behind anything pinned to the bottom edge, which cut the photos off. */
@media (max-width: 700px) {
  body {
    position: relative; /* the row below is placed against the page */
    padding-bottom: 88px; /* room for the row, so it never covers the end of a page */
  }

  .foot,
  body > .contact-link {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200000; /* above the photos and everything else */
    margin: 0;
    padding: 12px 24px 24px;
    --foot-pad-right: 24px;
    --foot-pad-bottom: 24px;
    pointer-events: none; /* the photos underneath stay draggable around the text… */
  }

  .foot a,
  .foot button,
  body > .contact-link a {
    pointer-events: auto; /* …while Contact and the page numbers stay tappable */
  }

  /* Item pages and list pages are read top to bottom, so there the row (Contact, and the
     page numbers on lists) simply comes at the end of the page. Only the photo pages pin it. */
  body:has(.book),
  body:has(.entries) {
    padding-bottom: 24px;
  }

  body:has(.book) .foot,
  body:has(.entries) .foot {
    position: relative;
    margin-top: auto; /* on a short page, still at the bottom of the screen */
    padding: 32px 0 0;
    --foot-pad-right: 0px;
    --foot-pad-bottom: 0px;
  }
}
