/*
 * The loading window (ADR-073): the notebook opens, and its pages turn from
 * right to left, as in any book. A file of its own, linked from index.html,
 * so it shows before the app's code and styles arrive (the content security
 * policy allows no inline style). The app's own loading screens use the same
 * classes, from src/shell/NotebookLoader.tsx.
 *
 * Its colours are the mark's (public/favicon.svg), so it needs none of the
 * app's tokens, which have not loaded yet when index.html first paints.
 */
.loader-screen {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1.25rem;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: 2rem 1rem;
  box-sizing: border-box;
  color: #4f6b5c;
  font:
    500 0.875rem/1.4 system-ui,
    sans-serif;
}
html:not(.app-ready) body {
  margin: 0;
  background: #f3f5f1;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme='light']):not(.app-ready) body {
    background: #0c1712;
  }
  :root:not([data-theme='light']) .loader-screen {
    color: #9bb3a6;
  }
}
html[data-theme='dark']:not(.app-ready) body {
  background: #0c1712;
}
:root[data-theme='dark'] .loader-screen {
  color: #9bb3a6;
}
.loader-screen p {
  margin: 0;
}

/* The book: two halves either side of the spine, at the middle of .notebook-loader. */
.notebook-loader {
  --w: 56px;
  --h: 76px;
  --gold: #eac980;
  --gold-dark: #b8924a;
  --page: #fbf3dd;
  --green: #1a4730;
  --open-at: 0.4s;
  --open-for: 1.1s;
  --turn: 2.4s;
  position: relative;
  width: calc(var(--w) * 2);
  height: var(--h);
  perspective: 600px;
}
.notebook-loader * {
  box-sizing: border-box;
}
.nl-book {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(18deg) translateX(calc(var(--w) / -2));
  animation: nl-center var(--open-for) cubic-bezier(0.5, 0, 0.2, 1) var(--open-at) forwards;
}
/* Everything hinges on the spine: the left edge of the right half. */
.nl-back,
.nl-block,
.nl-page,
.nl-cover {
  position: absolute;
  top: 0;
  left: var(--w);
  width: var(--w);
  height: var(--h);
  transform-origin: left center;
  transform-style: preserve-3d;
}
.nl-back {
  border-radius: 0 4px 4px 0;
  background: var(--gold-dark);
  transform: translateZ(0);
}
/* What lies on the left once the cover is open: the inside of the cover, then pages. */
.nl-left {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--w);
  height: var(--h);
  border-radius: 4px 0 0 4px;
  background: var(--gold-dark);
  opacity: 0;
  /* Above the open cover, below the pages that turn onto it. */
  transform: translateZ(1px);
  animation: nl-show 0.01s linear calc(var(--open-at) + var(--open-for) * 0.55) forwards;
}
.nl-left::after {
  content: '';
  position: absolute;
  inset: 3px 0 3px 3px;
  border-radius: 3px 0 0 3px;
  background: var(--page)
    repeating-linear-gradient(to bottom, transparent 0 10px, rgba(26, 71, 48, 0.14) 10px 11px) 0
    11px / 100% calc(100% - 22px) no-repeat;
}
.nl-block {
  top: 3px;
  height: calc(var(--h) - 6px);
  width: calc(var(--w) - 3px);
  border-radius: 0 3px 3px 0;
  background: var(--page)
    repeating-linear-gradient(to bottom, transparent 0 10px, rgba(26, 71, 48, 0.14) 10px 11px) 0
    11px / 100% calc(100% - 22px) no-repeat;
  box-shadow: inset 6px 0 8px -6px rgba(0, 0, 0, 0.25);
  transform: translateZ(1px);
}
/* A turning page: the same lines on both sides, darker as it stands up. */
.nl-page {
  top: 3px;
  height: calc(var(--h) - 6px);
  width: calc(var(--w) - 3px);
  opacity: 0;
  transform: translateZ(2px) rotateY(0deg);
  animation: nl-turn var(--turn) cubic-bezier(0.45, 0, 0.3, 1) infinite;
}
.nl-page::before,
.nl-page::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0 3px 3px 0;
  background: var(--page)
    repeating-linear-gradient(to bottom, transparent 0 10px, rgba(26, 71, 48, 0.14) 10px 11px) 0
    11px / 100% calc(100% - 22px) no-repeat;
  backface-visibility: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.nl-page::after {
  border-radius: 3px 0 0 3px;
  transform: rotateY(180deg);
}
.nl-page-1 {
  animation-delay: calc(var(--open-at) + var(--open-for));
}
.nl-page-2 {
  animation-delay: calc(var(--open-at) + var(--open-for) + var(--turn) / 3);
}
.nl-page-3 {
  animation-delay: calc(var(--open-at) + var(--open-for) + var(--turn) * 2 / 3);
}
/* The cover: blank on the outside, its plain inside showing once it lies open. */
.nl-cover {
  transform: translateZ(4px) rotateY(0deg);
  animation: nl-open var(--open-for) cubic-bezier(0.5, 0, 0.2, 1) var(--open-at) forwards;
}
.nl-cover-front,
.nl-cover-inside {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}
.nl-cover-front {
  display: grid;
  place-items: center;
  border-radius: 0 4px 4px 0;
  background:
    linear-gradient(var(--green), var(--green)) right 9px top 0 / 3px 100% no-repeat,
    linear-gradient(to right, var(--gold-dark) 0 9px, var(--gold) 9px);
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.45);
}
.nl-cover-inside {
  border-radius: 4px 0 0 4px;
  background: var(--gold-dark);
  transform: rotateY(180deg);
}

@keyframes nl-open {
  to {
    transform: translateZ(0.5px) rotateY(-180deg);
  }
}
@keyframes nl-center {
  to {
    transform: rotateX(18deg) translateX(0);
  }
}
@keyframes nl-show {
  to {
    opacity: 1;
  }
}
/* Each page lifts from the right, turns over the spine and settles on the left,
   then waits out of sight to start again, so the book never runs out of pages. */
@keyframes nl-turn {
  0% {
    opacity: 1;
    transform: translateZ(2px) rotateY(0deg);
  }
  60% {
    opacity: 1;
    transform: translateZ(2px) rotateY(-180deg);
  }
  66%,
  100% {
    opacity: 0;
    transform: translateZ(2px) rotateY(-180deg);
  }
}

/* No motion wanted: the notebook lies open, and nothing moves. */
@media (prefers-reduced-motion: reduce) {
  .nl-book,
  .nl-cover,
  .nl-left,
  .nl-page {
    animation: none !important;
  }
  .nl-book {
    transform: rotateX(18deg);
  }
  .nl-cover {
    transform: translateZ(0.5px) rotateY(-180deg);
  }
  .nl-left {
    opacity: 1;
  }
}
