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

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

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #000000;
  --fg: #ffffff;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'FaggioSerif', serif;
  overflow: hidden;
}

body {
  overscroll-behavior: none;
  touch-action: none;
  transition: background-color 1.8s ease;
}

.scroll-space {
  display: none;
}

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background-color: transparent;
  background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.025), transparent 34%);
}

.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.72) 0%,
      rgba(0, 0, 0, 0.08) 20%,
      rgba(0, 0, 0, 0.08) 80%,
      rgba(0, 0, 0, 0.72) 100%
    );
}

.scene__inner {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 850px;
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
  z-index: 3;
}

.book {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 178px;
  height: 258px;
  border-radius: 8px;
  cursor: pointer;
  will-change: transform;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  pointer-events: auto;
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.16),
    inset -10px 0 0 rgba(0, 0, 0, 0.10);
}

.book::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 10px;
  background: var(--book-spine, rgba(255, 255, 255, 0.25));
  border-radius: 5px 0 0 5px;
  pointer-events: none;
}

.book::after {
  content: "";
  position: absolute;
  right: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--book-edge, rgba(255, 255, 255, 0.45));
  border-radius: 2px;
  pointer-events: none;
}

.book__hitbox {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  cursor: pointer;
}

.book__title {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 48px);
  font-size: 20px;
  font-weight: 700;
  font-family: 'ABCStefan', sans-serif;
  color: #fff;
  text-align: center;
  letter-spacing: 0.07em;
  line-height: 1.4;
  word-break: break-word;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

.book__svg {
  position: absolute;
  top: 12px;
  right: 50px;
  bottom: 12px;
  left: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: fill;
  border-radius: 6px;
  pointer-events: none;
  display: block;
}

.book__text {
  position: absolute;
  top: 100px;
  left: 24px;
  right: 12px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.52);
  line-height: 1.6;
  word-break: break-all;
  pointer-events: none;
  user-select: none;
}

.book-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.book-overlay--visible {
  opacity: 1;
}

.book-open {
  display: flex;
  width: min(840px, 90vw);
  height: min(540px, 80vh);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.18);
  transform: scale(0.86);
  transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.book-overlay--visible .book-open {
  transform: scale(1);
}

.book-open__cover {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 40px 36px;
  position: relative;
  background: #f5f0e8;
  gap: 24px;
  overflow-y: auto;
}

.book-open__cover::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: rgba(0, 0, 0, 0.18);
}

.book-open__cover-title {
  font-size: 13px;
  font-weight: bold;
  color: #3a3530;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: 'FaggioSerif', serif;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  padding-bottom: 18px;
  word-break: break-word;
}

.book-open__page {
  flex: 1;
  background: #f5f0e8;
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.book-open__alphabet {
  font-size: 13px;
  color: #3a3530;
  letter-spacing: 0.1em;
  font-family: 'FaggioSerif', serif;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  padding-bottom: 18px;
}

.book-open__body {
  font-size: 11px;
  color: #5a5550;
  line-height: 1.9;
  font-family: 'FaggioSerif', serif;
}

.book-close {
  position: absolute;
  top: 24px;
  right: 28px;
  width: 42px;
  height: 42px;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.78);
  font-size: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s ease, color 0.2s ease;
}

.book-close:hover {
  background: rgba(0, 0, 0, 0.14);
  color: #000;
}

@media (max-width: 768px) {
  .book {
    width: 122px;
    height: 182px;
  }

  .book__title {
    font-size: 14px;
  }

  .site-header__title {
    font-size: 22px;
    letter-spacing: 0.08em;
  }

  .site-header__subtitle {
    font-size: 13px;
    white-space: normal;
    max-width: 260px;
    text-align: center;
  }

  .book-open__cover,
  .book-open__page {
    padding: 28px 22px;
  }
}

@media (max-width: 600px) {
  .book-open {
    flex-direction: column;
    height: 90vh;
  }

  .book-open__cover {
    flex: 0 0 42%;
  }

  .book-open__cover::after {
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: auto;
    height: 5px;
  }

  .site-header {
    top: 16px;
  }

  .view-toggle {
    bottom: 16px;
  }
}

/* ======================
   SITE HEADER
   ====================== */

.site-header {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 9000;
  pointer-events: none;
  user-select: none;
}

.site-header__title {
  font-family: 'ABCStefan', sans-serif;
  font-size: 40px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  margin-bottom: 4px;
}

.site-header__subtitle {
  font-family: 'ABCStefan', sans-serif;
  font-size: 19px;
  letter-spacing: 0.06em;
  color: #888;
  white-space: nowrap;
}

/* ======================
   BACK BUTTON
   ====================== */

#back-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 9000;
  border: 2px solid #fff;
  background: transparent;
  color: #fff;
  padding: 10px 14px;
  font-size: 14px;
  font-family: 'ABCStefan', sans-serif;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

#back-btn:hover {
  background: #fff;
  color: #000;
}

/* ======================
   VIEW TOGGLE
   ====================== */

.view-toggle {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 9000;
  user-select: none;
}

.view-toggle__btn {
  background: none;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 1px 3px 2px 4px / 3px 1px 4px 2px;
  font-family: 'ABCStefan', sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 6px 10px;
  transition: color 0.2s ease, border-color 0.2s ease;
  outline: none;
  -webkit-font-smoothing: antialiased;
  transform: rotate(-0.4deg);
  filter: url(#rough);
}

.view-toggle__btn--active {
  color: #fff;
  font-weight: 700;
  border-color: #fff;
  transform: rotate(0.3deg);
}

.view-toggle__btn:hover:not(.view-toggle__btn--active) {
  color: rgba(255, 255, 255, 0.8);
}

.view-toggle__sep {
  width: 1px;
  height: 10px;
  background: rgba(255, 255, 255, 0.3);
}

/* ======================
   LIBRARY SEARCH
====================== */

.library-search {
  position: fixed;
  top: 30px;
  right: 24px;
  z-index: 80;

  width: 280px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;

  pointer-events: auto;
}

.library-search__input {
  width: 100%;
  border: 3.5px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;

  padding: 9px 13px;

  font-family: 'ABCStefan', sans-serif;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-align: left;

  outline: none;
  border-radius: 3px 5% 4px 6% / 5px 3% 6px 4%;

  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  filter: url(#rough);

  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.library-search__input:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.library-search__input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.library-search__status {
  min-height: 14px;
  padding-right: 8px;

  font-family: 'ABCStefan', sans-serif;
  font-size: 12px;
  font-style: italic;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.65);
  text-align: right;
}

/* Libro trovato dalla ricerca */
.book.book--search-match {
  filter: saturate(1.2) contrast(1.04);
  box-shadow:
    0 24px 50px rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(0, 0, 0, 0.75),
    inset -10px 0 0 rgba(0, 0, 0, 0.10);
}

/* Mobile: search sotto i pulsanti, sempre a destra */
@media (max-width: 1100px) {
  .library-search {
    top: 160px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: min(260px, calc(100vw - 28px));
  }

  .library-search__input {
    font-size: 14px;
    padding: 8px 11px;
  }
}

.view-toggle {
  z-index: 90;
}

#back-btn {
  z-index: 90;
}

/* ======================
   RESPONSIVE — 480px
   ====================== */

@media (max-width: 480px) {
  .site-header__title {
    font-size: 19px;
    letter-spacing: 0.06em;
  }

  .site-header__subtitle {
    text-align: center;
    white-space: normal;
    font-size: 12px;
  }

  .library-search {
    top: 90px;
    bottom: auto;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: min(220px, calc(100vw - 40px));
  }

  .library-search__input {
    font-size: 12px;
    padding: 6px 10px;
  }

  .view-toggle {
    bottom: 14px;
  }

  .book-open__cover,
  .book-open__page {
    padding: 20px 16px;
    gap: 16px;
  }

  .book-close {
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    font-size: 18px;
  }
}