:root {
  --night: #130E38;
  --iris: #2A1C78;
  --milk: #F3EEFF;
  --mint: #7CF7D4;
  --orchid: #E58CFF;
  --peach: #FFB38A;
  --ink: #1B1642;
  --paper: #F5F2FF;
  --display: "Unbounded", system-ui, sans-serif;
  --text: "Literata", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
button, a { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }
.reader-view:not(.night) :focus-visible { outline-color: #5B3FE0; }

/* ---------- The shelf ---------- */

body.shelf-view {
  color: var(--milk);
  background:
    radial-gradient(60vmax 42vmax at 88% -12%, rgba(229, 140, 255, .38), transparent 62%),
    radial-gradient(52vmax 40vmax at -12% 34%, rgba(124, 247, 212, .2), transparent 60%),
    linear-gradient(180deg, #130E38 0%, #2A1C78 68%, #3C2A9C 100%);
  background-attachment: fixed;
}
body.shelf-view::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .7;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent 60%),
    radial-gradient(1px 1px at 31% 9%, #fff, transparent 60%),
    radial-gradient(1.5px 1.5px at 54% 22%, #fff, transparent 60%),
    radial-gradient(1px 1px at 71% 6%, #fff, transparent 60%),
    radial-gradient(1px 1px at 83% 31%, #fff, transparent 60%),
    radial-gradient(1.5px 1.5px at 93% 14%, #fff, transparent 60%),
    radial-gradient(1px 1px at 6% 44%, #fff, transparent 60%),
    radial-gradient(1px 1px at 44% 38%, #fff, transparent 60%);
}

.wrap {
  position: relative;
  --gutter: clamp(1.25rem, 5vw, 3rem);
  max-width: 68rem;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) var(--gutter) 4rem;
}

.masthead h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.5rem, 10vw, 5.75rem);
  line-height: .98;
  letter-spacing: -.02em;
  margin: 0;
}
.masthead p {
  font-size: clamp(1.15rem, 2.4vw, 1.4rem);
  line-height: 1.5;
  max-width: 30ch;
  margin: 1.1rem 0 0;
  color: #DCD3FF;
}

.shelf { margin-top: clamp(0rem, 2vw, 1.5rem); }
.spines {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  min-height: 356px;
  margin-inline: calc(var(--gutter) * -1);
  padding: 66px var(--gutter) 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.spines::-webkit-scrollbar { display: none; }

.spine {
  flex: 0 0 auto;
  width: 72px;
  height: var(--h, 250px);
  padding: 16px 0;
  border: 0;
  border-radius: 12px 12px 2px 2px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #0F0B2E;
  background: linear-gradient(180deg, var(--a), var(--b));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45), 0 0 44px -6px var(--a);
  transition: transform .25s ease, box-shadow .25s ease;
  animation: rise .7s cubic-bezier(.2, .8, .2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 70ms + .55s);
}
.spine[aria-pressed="true"] {
  transform: translateY(-16px);
  box-shadow: inset 0 0 0 2px #fff, 0 0 64px 2px var(--a);
}
.spine-title {
  writing-mode: vertical-rl;
  max-height: 100%;
  overflow: hidden;
  font-family: var(--display);
  font-weight: 600;
  font-size: .95rem;
  line-height: 1.15;
  text-align: center;
}
.spine.ghost {
  cursor: default;
  background: none;
  border: 1.5px dashed rgba(243, 238, 255, .3);
  box-shadow: none;
}

.beam {
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--mint), #fff 30%, var(--orchid) 70%, var(--peach));
  box-shadow: 0 0 24px 2px rgba(243, 238, 255, .7), 0 18px 60px 8px rgba(124, 247, 212, .25);
  transform-origin: left;
  animation: draw .9s cubic-bezier(.2, .8, .2, 1) backwards;
}
.shelf-note { margin: 1rem 0 0; color: #C2B8F7; font-size: 1.05rem; }

@keyframes draw { from { transform: scaleX(0); } }
@keyframes rise { from { transform: translateY(46px); opacity: 0; } }

.panel { margin-top: clamp(2rem, 5vw, 3.25rem); max-width: 40rem; }
.panel h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.6rem, 5.4vw, 2.6rem);
  line-height: 1.1;
  margin: 0;
}
.panel .meta { margin: .7rem 0 0; color: var(--mint); font-size: 1.08rem; }
.panel .blurb { margin: 1rem 0 0; font-size: 1.22rem; line-height: 1.6; color: #EEE8FF; }
.actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.6rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 1.6rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1rem;
}
.btn.primary { background: var(--milk); color: var(--ink); }
.btn.quiet { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px currentColor; }

.toc { margin-top: 1.6rem; }
.toc h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1rem;
  margin: 1.6rem 0 .4rem;
  color: #C2B8F7;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: flex;
  gap: .9rem;
  align-items: baseline;
  min-height: 48px;
  padding: .6rem 0;
  text-decoration: none;
  font-size: 1.15rem;
  border-bottom: 1px solid rgba(243, 238, 255, .16);
}
.toc a span:first-child { flex: 0 0 2.2ch; text-align: right; opacity: .65; font-variant-numeric: tabular-nums; }
.toc a[aria-current="true"] { color: var(--mint); }

.message { max-width: 34rem; font-size: 1.25rem; line-height: 1.6; }

/* ---------- The reader ---------- */

body.reader-view { background: var(--paper); color: var(--ink); }
body.reader-view.night { background: #120E33; color: #E9E4FF; }

.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4px;
  z-index: 6;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, #3BD4AE, #B45CF0, #FF9A66);
}

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .6rem clamp(.7rem, 3vw, 1.5rem);
  background: rgba(245, 242, 255, .9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.night .bar { background: rgba(18, 14, 51, .9); }
.bar .grow { flex: 1; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 46px;
  padding: 0 .95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  box-shadow: inset 0 0 0 1.5px currentColor;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--display);
  font-size: .82rem;
  font-weight: 500;
}

.page {
  max-width: 35em;
  margin: 0 auto;
  padding: 2.4rem 1.3rem 5rem;
  font-size: var(--read-size, 20px);
  line-height: 1.75;
}
.part {
  font-family: var(--display);
  font-weight: 400;
  font-size: .78em;
  line-height: 1.4;
  margin: 0 0 2.4em;
  opacity: .72;
}
.ch-num { font-family: var(--display); font-size: .78em; margin: 0; opacity: .72; }
.ch-who {
  font-family: var(--display);
  font-weight: 600;
  font-size: 2.5em;
  line-height: 1;
  letter-spacing: -.02em;
  margin: .12em 0 .45em;
}
.dateline { font-style: italic; opacity: .78; margin: 0 0 2.2em; }
.page p { margin: 0 0 1.1em; }
.page hr {
  width: 72px;
  height: 3px;
  margin: 2.4em auto;
  border: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #3BD4AE, #B45CF0, #FF9A66);
}
.page h2.sub {
  font-family: var(--display);
  font-weight: 500;
  font-size: .82em;
  line-height: 1.35;
  margin: 2.6em 0 1em;
}
.toc a .aside { font-style: italic; opacity: .85; }
.so-far { margin-top: 3rem; font-style: italic; opacity: .8; }
.turn { display: grid; gap: .8rem; margin-top: 3.2rem; }
.turn .btn.primary { background: var(--ink); color: var(--paper); min-height: 62px; }
.night .turn .btn.primary { background: var(--milk); color: var(--ink); }

dialog.chapters {
  width: min(32rem, 100vw - 1.5rem);
  max-height: 86dvh;
  padding: 1.2rem 1.4rem 1.6rem;
  border: 0;
  border-radius: 22px;
  background: var(--night);
  color: var(--milk);
}
dialog.chapters::backdrop { background: rgba(19, 14, 56, .6); }
dialog.chapters .head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
dialog.chapters h2 { font-family: var(--display); font-weight: 500; font-size: 1.2rem; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
