:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #111;
  --muted: #666;
  --border: #ddd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111;
    --fg: #eee;
    --muted: #999;
    --border: #333;
  }
}

@font-face {
  font-family: 'Aquifer';
  src: url('font/Aquifer.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Biro Script';
  src: url('font/Biro_Script.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Telegraphem';
  src: url('font/Telegraphem.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

@keyframes hover-float {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(0, -0.2rem); }
  100% { transform: translate(0, 0); }
}

.page-box,
.itch-link,
.explorer-back,
.telegram-note {
  animation: hover-float 6.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .page-box,
  .itch-link,
  .explorer-back,
  .telegram-note {
    animation: none;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Aquifer', Georgia, 'Times New Roman', serif;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
}

main {
  flex: 1;
  min-height: 0;
}

/* --- bookshelf main menu --- */

:root {
  --book-height: 10rem;
  --shelf-height: 1.1rem;
  --shelf-row: calc(var(--book-height) + var(--shelf-height));
}

.grid-wrap {
  position: relative;
  height: 100%;
  background: #2b1d14 url('img/texture/wood.jpg') repeat;
  background-size: 300px;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: flex-end;
  position: relative;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  scrollbar-width: none;
  padding: 1rem 1rem 0;
}

@media (prefers-reduced-motion: reduce) {
  .grid {
    scroll-behavior: auto;
  }
}

.grid-wrap.has-open-book .grid {
  overflow-y: hidden;
}

.grid::-webkit-scrollbar {
  display: none;
}

.grid::after {
  content: '';
  position: absolute;
  top: 1rem;
  left: 0;
  right: 0;
  height: var(--shelf-lines-height, 100%);
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent var(--book-height),
      rgba(0, 0, 0, 0.65) var(--book-height),
      rgba(0, 0, 0, 0.35) calc(var(--book-height) + 0.15rem),
      #4a3323 calc(var(--book-height) + 0.15rem),
      #6b4a30 calc(var(--book-height) + 0.35rem),
      #4a3323 calc(var(--book-height) + 0.55rem),
      #2b1d14 calc(var(--book-height) + 0.75rem),
      transparent var(--shelf-row)
    );
  background-size: 100% var(--shelf-row);
}

.wordmark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(calc(-50% + 1em), -50%);
  margin: 0;
  font-size: 2.75rem;
  font-weight: normal;
  pointer-events: none;
  z-index: 1;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7), 0 0 24px rgba(0, 0, 0, 0.5);
  opacity: 1;
  transition: opacity 0.25s ease;
}

.grid-wrap.has-open-book .wordmark {
  opacity: 0;
  pointer-events: none;
}

.wordmark a {
  pointer-events: auto;
  text-decoration: none;
  color: inherit;
  display: block;
  letter-spacing: 0.7em;
}

.wordmark .subtitle {
  display: block;
  font-size: 0.7rem;
  font-style: normal;
  letter-spacing: 0.15em;
  margin-top: 0.5rem;
  pointer-events: none;
}

/* --- pinned signature note --- */

:root {
  --note-ratio: 2 / 3;
}

.signature-note {
  position: absolute;
  top: calc(1rem + var(--shelf-row) * 1 - 0.6rem - var(--note-scroll-offset, 0px));
  left: 3rem;
  transform: rotate(-3deg);
  transform-origin: top center;
  z-index: 2;
  display: block;
  width: 4rem;
  min-height: 0;
  aspect-ratio: var(--note-ratio);
  border: none;
  padding: 0.25rem;
  overflow: hidden;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: box-shadow 0.2s ease, opacity 0.2s ease;
}

.signature-note::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  filter: url(#scribble);
  z-index: -1;
}

.signature-note:hover,
.signature-note:focus-visible {
  transform: rotate(-3deg) translateY(0.15rem);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.55);
}

.signature-note-pin {
  position: absolute;
  top: 0.05rem;
  left: 50%;
  transform: translateX(-50%);
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3a5ac0, #1f2f7a);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.signature-note-tiny-body {
  display: block;
  font-family: 'Biro Script', cursive;
  font-size: 0.3rem;
  line-height: 1.3;
  color: #241a0f;
  text-align: center;
}

.signature-note-popup {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.grid-wrap.note-open .signature-note-popup {
  opacity: 1;
  pointer-events: auto;
}

.signature-note-popup-page {
  position: relative;
  width: min(20rem, 70vw);
  aspect-ratio: var(--note-ratio);
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 2.25rem;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  box-shadow: 0 1.2rem 2.5rem rgba(0, 0, 0, 0.6);
  text-align: center;
  color: #241a0f;
  font-family: 'Biro Script', cursive;
  transform: scale(0.9);
  transition: transform 0.25s ease;
}

.signature-note-popup-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  filter: url(#scribble-note);
  z-index: -1;
}

.grid-wrap.note-open .signature-note-popup-page {
  transform: scale(1);
}

.signature-note-close {
  position: absolute;
  top: 0.3rem;
  right: 0.5rem;
  border: none;
  background: none;
  font-size: 2.2rem;
  font-weight: bold;
  line-height: 1;
  color: #241a0f;
  opacity: 0.75;
  cursor: pointer;
  font-family: 'Aquifer', Georgia, 'Times New Roman', serif;
}

.signature-note-close:hover,
.signature-note-close:focus-visible {
  opacity: 1;
}

.signature-note-body {
  display: block;
  margin-top: -1rem;
  font-size: 1.2rem;
  line-height: 1.15;
  text-align: justify;
}

.signature-note-body a {
  color: inherit;
  text-decoration: underline;
}

.signature-note-signature {
  position: absolute;
  bottom: 1.3rem;
  right: 1.1rem;
  font-family: 'Aquifer', Georgia, 'Times New Roman', serif;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: #241a0f;
  text-decoration: none;
  opacity: 0.8;
}

.signature-note-signature:hover,
.signature-note-signature:focus-visible {
  opacity: 1;
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .signature-note,
  .signature-note-popup,
  .signature-note-popup-page {
    transition: none;
  }
}

/* --- pinned telegram note --- */

.telegram-note {
  position: absolute;
  top: calc(1rem + var(--shelf-row) * 3 - var(--shelf-height) - 3rem - var(--note-scroll-offset, 0px));
  left: 8rem;
  width: 4.6rem;
  height: 3rem;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  z-index: 2;
  transform: rotate(-4deg);
  transform-origin: bottom center;
  transition: transform 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
}

.telegram-note img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  filter: drop-shadow(-1px -1px 3px rgba(0, 0, 0, 0.4));
}

.telegram-note:hover,
.telegram-note:focus-visible {
  transform: rotate(-4deg) translateY(-0.3rem);
}

.telegram-note-popup {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.grid-wrap.telegram-open .telegram-note-popup {
  opacity: 1;
  pointer-events: auto;
}

.telegram-note-popup-page {
  position: relative;
  width: min(20rem, 70vw);
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 2.25rem;
  background: #ede6d3 url('img/texture/paper.webp') center / cover;
  box-shadow: 0 1.2rem 2.5rem rgba(0, 0, 0, 0.6);
  text-align: center;
  color: #1a1a1a;
  transform: scale(0.9);
  transition: transform 0.25s ease;
}

.grid-wrap.telegram-open .telegram-note-popup-page {
  transform: scale(1);
}

.telegram-note-close {
  position: absolute;
  top: 0.3rem;
  right: 0.5rem;
  border: none;
  background: none;
  font-size: 2.2rem;
  font-weight: bold;
  line-height: 1;
  color: #1a1a1a;
  opacity: 0.75;
  cursor: pointer;
  font-family: 'Aquifer', Georgia, 'Times New Roman', serif;
}

.telegram-note-close:hover,
.telegram-note-close:focus-visible {
  opacity: 1;
}

.telegram-note-body {
  display: block;
  font-family: 'Telegraphem', monospace;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  line-height: 1.5;
  text-align: left;
  text-transform: uppercase;
}

@media (prefers-reduced-motion: reduce) {
  .telegram-note,
  .telegram-note-popup,
  .telegram-note-popup-page {
    transition: none;
  }
}

.thumb {
  display: block;
  position: relative;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
}

.thumb img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--border);
  display: block;
  filter: grayscale(0.15);
  transition: filter 0.2s ease;
}

.thumb:hover img,
.thumb:focus-visible img {
  filter: grayscale(0);
}

@media (prefers-reduced-motion: reduce) {
  .thumb img {
    transition: none;
  }
}

/* --- books on the shelf --- */

.book {
  position: relative;
  display: block;
  flex: none;
  width: var(--book-width, 2.4rem);
  height: var(--book-height);
  margin-right: 0.25rem;
  margin-bottom: var(--shelf-height);
  text-decoration: none;
  cursor: pointer;
  perspective: 60rem;
  z-index: 1;
  transition: z-index 0s linear;
}

.book.is-open {
  z-index: 2;
  transition: z-index 0s linear;
}

.book-spine {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: bottom left;
  transform: rotateY(0deg) rotate(var(--tilt, 0deg));
  opacity: 1;
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.4);
}

.book-spine img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.8) sepia(0.1) url(#painterly);
}

.book.is-open .book-spine {
  transform:
    translate(var(--spine-shift-x, 0px), var(--spine-shift-y, -2.5rem))
    rotateY(-22deg) rotate(var(--tilt, 0deg));
  opacity: 0;
  box-shadow: -4px 6px 10px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.linking-book {
  position: absolute;
  left: var(--popup-left, 50%);
  bottom: 0.5rem;
  display: flex;
  width: 22rem;
  height: 15rem;
  transform: translate(var(--popup-shift, -50%), var(--popup-vshift, 0px));
  transform-origin: bottom center;
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  z-index: 3;
  filter: drop-shadow(0 1.2rem 1.5rem rgba(0, 0, 0, 0.55));
  transition: opacity 0.3s ease;
}

.book.is-open .linking-book {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.05s linear;
}

.linking-book-page {
  position: relative;
  width: 50%;
  height: 100%;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  color: #000;
}

.linking-book-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #f2ede1 url('img/texture/paper.webp') center / cover;
  filter: url(#scribble);
  z-index: -1;
}

.linking-book-page-left {
  border-radius: 2px 0 0 2px;
  box-shadow: inset -6px 0 10px -6px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  overflow: hidden;
}

.linking-book-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.linking-book-page-right {
  border-radius: 0 2px 2px 0;
  box-shadow: inset 6px 0 10px -6px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
}

.linking-book-title {
  font-size: 1rem;
  line-height: 1.3;
}

.linking-book-author {
  font-size: 0.85rem;
  margin-top: 0.3rem;
  color: #5a4a37;
}

.linking-book-year {
  font-style: italic;
  font-size: 0.85rem;
  margin-top: 0.2rem;
  color: #5a4a37;
}

@media (prefers-reduced-motion: reduce) {
  .book-spine,
  .linking-book {
    transition: none;
  }
}

/* --- fixed-box explorer, no scrolling --- */

.explorer {
  position: relative;
  display: none;
  grid-template-rows: 1fr auto;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.explorer-main {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.explorer-img {
  position: absolute;
  inset: -5%;
  width: 110%;
  height: 110%;
  object-fit: cover;
  background: var(--border);
  display: block;
  transition: opacity 1.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .explorer-img {
    transition: none;
  }
}

.explorer-panel {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(28rem, 45%);
  height: fit-content;
  max-height: 100%;
  max-width: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 1.5rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #f5f5f5;
}

.explorer-panel::-webkit-scrollbar {
  display: none;
}

.page-box {
  position: relative;
  width: 100%;
  padding: 1.5rem 1.75rem;
  color: #2a2115;
}

.page-box::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(rgba(255, 250, 240, 0.06), rgba(255, 250, 240, 0.06));
  border: 1px solid rgba(245, 237, 220, 0.4);
  filter: url(#scribble);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.2),
    inset 0 1px 3px rgba(255, 255, 255, 0.15),
    0 4px 14px rgba(0, 0, 0, 0.45);
}

.page-box::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--page-h, 100%);
  height: var(--page-w, 100%);
  z-index: -2;
  background: url('img/texture/paper.webp') center / 100% 100%;
  transform: translate(-50%, -50%) rotate(90deg);
}

.page-box h2 {
  color: #120c06;
}

.page-box .meta,
.page-box .tag-group {
  color: #5a4a37;
}

.page-box .tag-group-genre {
  color: #2a2115;
}

.page-box .description {
  color: #3a2f21;
}

.page-box .itch-link {
  color: #2a2115;
}

.explorer-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 1.8rem;
  font-weight: bold;
  line-height: 1;
  text-decoration: none;
  color: #241a0f;
  opacity: 0.8;
  z-index: 1;
  transition: opacity 0.2s ease;
}

.explorer-close:hover,
.explorer-close:focus-visible {
  opacity: 1;
}

.page-box h2 {
  font-weight: normal;
  font-size: 1.3rem;
  margin: 0 0 0.25rem;
}

.meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 0.5rem;
}

.meta a {
  text-decoration: underline;
}

.page-divider {
  display: none;
  width: 100%;
  border: none;
  border-top: 1px solid rgba(42, 33, 21, 0.25);
  margin: 0 0 0.75rem;
}

.page-image-box {
  display: none;
  margin: 0 0 0.75rem;
}

.page-image-box img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.keywords {
  margin: 0 0 0.75rem;
}

.tag-group {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  margin: 0 0 0.1rem;
}

.tag-group-genre {
  color: var(--fg);
  font-style: normal;
}

.text-boxes {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 0 0 0.75rem;
}

.text-section {
  position: relative;
  min-width: 0;
}

.text-section h3 {
  margin: 0 0 0.3rem;
  font-size: 0.7rem;
  font-weight: normal;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #3d3121;
  border-bottom: 1px solid rgba(42, 33, 21, 0.25);
  padding-bottom: 0.2rem;
}

.text-section p {
  margin: 0;
}

@media (min-width: 60rem) {
  .explorer-panel {
    width: min(46rem, 70%);
  }

  .page-box h2,
  .page-box .meta {
    text-align: left;
  }

  .page-box .itch-link {
    display: block;
    text-align: right;
  }

  .text-boxes {
    flex-direction: row;
    align-items: stretch;
    text-align: left;
    gap: 0;
  }

  .text-section {
    flex: 1 1 50%;
    padding: 0 1.5rem;
  }

  .text-section:first-child {
    padding-left: 0;
    border-right: 1px solid rgba(42, 33, 21, 0.2);
    box-shadow: 2px 0 6px -3px rgba(0, 0, 0, 0.3);
  }

  .text-section:last-child {
    padding-right: 0;
  }

  .text-section h3 {
    text-align: left;
  }
}

@media (max-width: 48rem) {
  :root {
    --book-height: 7.5rem;
  }

  .wordmark {
    font-size: 1.6rem;
    width: 90%;
    transform: translate(-50%, -50%);
  }

  .wordmark a {
    letter-spacing: 0.35em;
  }

  .book {
    width: min(var(--book-width, 2.4rem), 3rem);
  }

  .wordmark .subtitle {
    font-size: 0.6rem;
  }

  .signature-note {
    left: 1rem;
    width: 3rem;
  }

  .signature-note-body {
    line-height: 0.95;
  }

  .linking-book {
    width: min(18rem, 88vw);
    height: min(12rem, 60vw);
  }

  .linking-book-page-right {
    padding: 0.5rem;
  }

  .linking-book-title {
    font-size: 0.85rem;
  }

  .linking-book-author,
  .linking-book-year {
    font-size: 0.7rem;
  }

  .explorer-panel {
    display: block;
    width: calc(100% - 1.5rem);
    height: calc(100% - 1.5rem);
    max-height: calc(100% - 1.5rem);
    padding: 0.75rem;
    background: linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.55));
    overflow-y: auto;
  }

  .page-box {
    flex: none;
    padding: 1.25rem 1.25rem 1.5rem;
    box-sizing: border-box;
  }

  .explorer-img {
    display: none;
  }

  .page-divider,
  .page-image-box {
    display: block;
  }

  .explorer-neighbors {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .thumb-small {
    width: 3.5rem;
  }
}

.description {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

.review {
  font-size: 0.95rem;
  margin: 0;
}

.itch-link {
  display: inline-block;
  font-size: 0.85rem;
  text-decoration: underline;
}

.explorer-neighbors {
  flex: none;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  margin-top: 0.75rem;
  padding-bottom: 0.25rem;
}

.explorer-neighbors:empty {
  display: none;
}

.thumb-small {
  flex: none;
  width: 4.5rem;
}

.thumb-small img {
  aspect-ratio: 1 / 1;
}
