/* =========================================================
   NOTEBOOK — Open notebook with page turning
   ========================================================= */

#notebook-scene {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, rgba(30, 20, 12, 0.95) 0%, #0d0804 100%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 1.2s var(--ease-gentle), visibility 1.2s;
  touch-action: pan-y;
}

#notebook-scene.active {
  opacity: 1;
  visibility: visible;
}

/* Notebook wrapper with 3D perspective */
.notebook-wrapper {
  position: relative;
  width: min(94vw, 860px);
  height: min(86vh, 560px);
  perspective: 2000px;
  transform-style: preserve-3d;
  --left-peek: clamp(96px, 18%, 150px);
}

/* Opening animation from closed */
.notebook-wrapper.opening .notebook {
  animation: notebook-open 1.4s var(--ease-page) forwards;
}

@keyframes notebook-open {
  0% {
    transform: rotateX(15deg) scale(0.85);
    opacity: 0;
  }
  40% {
    transform: rotateX(5deg) scale(0.95);
    opacity: 0.8;
  }
  100% {
    transform: rotateX(0deg) scale(1);
    opacity: 1;
  }
}

/* Shake on wrong password */
.notebook-wrapper.shake {
  animation: notebook-shake 0.5s ease-in-out;
}

@keyframes notebook-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px) rotate(-1deg); }
  30% { transform: translateX(8px) rotate(1deg); }
  45% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

/* The notebook itself */
.notebook {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  touch-action: pan-y;
}

/* Leather back cover */
.notebook-back {
  position: absolute;
  inset: -10px -14px -10px -14px;
  background: linear-gradient(160deg, var(--leather) 0%, var(--leather-dark) 100%);
  border-radius: 14px;
  box-shadow: 6px 10px 30px var(--shadow-deep);
  z-index: 0;
}

.notebook-back::before {
  content: '';
  position: absolute;
  left: var(--left-peek);
  top: 10px;
  bottom: 10px;
  width: 24px;
  transform: translateX(-50%);
  background:
    linear-gradient(90deg, rgba(20, 12, 8, 0.35), rgba(255, 240, 210, 0.08), rgba(20, 12, 8, 0.42));
  border-radius: 12px;
}

.notebook-left {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--left-peek);
  transform-style: preserve-3d;
  z-index: 1;
  pointer-events: none;
}

.left-page-surface,
.left-page-stack {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 8px;
  right: 4px;
  border-radius: 4px 0 0 4px;
}

.left-page-surface {
  box-shadow:
    inset -12px 0 18px rgba(61, 43, 31, 0.12),
    inset 1px 0 2px rgba(255, 255, 255, 0.45),
    -3px 4px 14px rgba(20, 12, 8, 0.18);
  overflow: hidden;
}

.left-page-surface::before {
  content: '';
  position: absolute;
  inset: 0 0 0 auto;
  width: 34px;
  background: linear-gradient(90deg, transparent, rgba(61, 43, 31, 0.18));
}

.left-page-stack {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-aged) 100%);
  border-left: 1px solid rgba(130, 95, 61, 0.18);
  border-bottom: 1px solid rgba(130, 95, 61, 0.18);
  box-shadow: -2px 4px 10px rgba(20, 12, 8, 0.11);
}

.left-page-stack--back {
  transform: translate(-9px, 7px) rotate(-1.1deg);
  opacity: 0.55;
}

.left-page-stack--middle {
  transform: translate(-5px, 4px) rotate(-0.55deg);
  opacity: 0.75;
}

.left-page-stack--front {
  transform: translate(-2px, 1px) rotate(-0.2deg);
  opacity: 0.95;
}

/* Pages container */
.notebook-pages {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--left-peek);
  transform-style: preserve-3d;
  z-index: 2;
  overflow: visible;
}

.notebook-pages::before {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: -1px;
  width: 28px;
  z-index: 80;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(61, 43, 31, 0.28), rgba(61, 43, 31, 0.08), transparent);
}

/* Individual page */
.notebook-page {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  transform-origin: left center;
  transition: transform var(--duration-slow) var(--ease-page);
  z-index: 1;
}

.notebook-page.active {
  z-index: 10;
}

/* Page turning — flipped to left */
.notebook-page.turned {
  transform: rotateY(-180deg);
  z-index: 5;
}

/* Page turning animation in progress */
.notebook-page.turning {
  transition: transform var(--duration-slow) var(--ease-page);
  z-index: 30;
}

/* Page face — front */
.page-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
}

/* Page face — back (visible when turned) */
.page-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  overflow: hidden;
}

/* Page paper styling */
.page-content {
  position: absolute;
  inset: 4px 8px 4px 0;
  overflow: hidden;
  border-radius: 0 2px 2px 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.page-content.paper-texture {
  box-shadow:
    inset 14px 0 22px rgba(61, 43, 31, 0.1),
    inset 1px 0 3px rgba(0, 0, 0, 0.05),
    2px 0 8px var(--shadow-soft);
}

/* Page edge shadow during turn */
.notebook-page::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.08));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.notebook-page.turning::after {
  opacity: 1;
}

@media (max-width: 760px) {
  .notebook-wrapper {
    width: min(96vw, 520px);
    height: min(78vh, 620px);
    --left-peek: clamp(42px, 13vw, 70px);
  }

  .left-page-surface,
  .left-page-stack {
    left: 4px;
    right: 2px;
  }

  .notebook-back::before {
    left: var(--left-peek);
  }

  .notebook-pages {
    left: var(--left-peek);
  }
}

/* =========================================================
   PASSWORD PAGE
   ========================================================= */
.password-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  position: relative;
}

.password-page .coffee-stain {
  top: 15%;
  right: 10%;
  width: 100px;
  height: 100px;
}

.password-page .coffee-stain--small {
  bottom: 20%;
  left: 8%;
  width: 50px;
  height: 50px;
}

/* EDITABLE: Password page title */
.password-title {
  font-family: var(--font-script);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  color: var(--ink);
  margin-bottom: 0.5rem;
  text-align: center;
}

.password-subtitle {
  font-family: var(--font-hand);
  font-size: 1.2rem;
  color: var(--ink-light);
  margin-bottom: 2rem;
  text-align: center;
}

/* Decorative heart */
.password-heart {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  opacity: 0.6;
  animation: heart-pulse 2s ease-in-out infinite;
}

@keyframes heart-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.password-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 280px;
}

.password-input-wrapper {
  position: relative;
  width: 100%;
}

.password-input {
  width: 100%;
  padding: 0.8rem 1rem;
  font-family: var(--font-hand);
  font-size: 1.4rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--ink-faded);
  outline: none;
  text-align: center;
  letter-spacing: 0.15em;
}

.password-input::placeholder {
  color: var(--ink-faded);
  letter-spacing: 0.05em;
}

.password-input:focus {
  border-bottom-color: var(--rose);
}

.password-submit {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: var(--ink-light);
  padding: 0.5rem 2rem;
  border: 1px solid var(--ink-faded);
  background: transparent;
  transition: all var(--duration-fast) var(--ease-gentle);
  margin-top: 0.5rem;
}

.password-submit:hover {
  color: var(--rose);
  border-color: var(--rose);
  background: rgba(196, 122, 122, 0.05);
}

.password-error {
  font-family: var(--font-hand);
  font-size: 1rem;
  color: var(--rose);
  opacity: 0;
  transition: opacity 0.3s;
  min-height: 1.5rem;
}

.password-error.visible {
  opacity: 1;
}

/* Wax seal decoration */
.wax-seal {
  position: absolute;
  bottom: 15%;
  right: 12%;
  width: 50px;
  height: 50px;
  background: radial-gradient(circle, #a04040 0%, #7a2828 100%);
  border-radius: 50%;
  box-shadow: 2px 3px 6px var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.3);
  transform: rotate(12deg);
}

/* =========================================================
   Navigation controls
   ========================================================= */
.notebook-nav {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1.5rem;
  align-items: center;
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s, visibility 0.6s;
}

.notebook-nav.visible {
  opacity: 1;
  visibility: visible;
}

.nav-btn {
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: rgba(255, 240, 220, 0.7);
  padding: 0.5rem 1.2rem;
  border: 1px solid rgba(255, 240, 220, 0.2);
  background: rgba(30, 20, 12, 0.5);
  transition: all var(--duration-fast);
  backdrop-filter: blur(2px);
}

.nav-btn:hover:not(:disabled) {
  color: var(--rose-soft);
  border-color: var(--rose-soft);
  background: rgba(30, 20, 12, 0.7);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-indicator {
  font-family: var(--font-hand);
  font-size: 1rem;
  color: rgba(255, 240, 220, 0.5);
  min-width: 60px;
  text-align: center;
}

/* Music toggle */
.music-toggle {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(30, 20, 12, 0.6);
  border: 1px solid rgba(255, 240, 220, 0.2);
  color: rgba(255, 240, 220, 0.7);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast);
  cursor: pointer;
}

.music-toggle:hover {
  background: rgba(30, 20, 12, 0.8);
  color: var(--rose-soft);
}

.music-toggle.muted {
  opacity: 0.5;
}
