* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #0e0d0c;
  font-family: 'EB Garamond', serif;
  touch-action: none;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #171513 0%, #0a0908 100%);
  overflow: hidden;
}

/* ---------- STAGE BACKGROUND GRID CORNERS ---------- */
/* these sit on the dark stage behind the notebook, in all four screen corners */
.grid-corner {
  position: absolute;
  width: 130px;
  height: 130px;
  opacity: 0.14;
  pointer-events: none;
  z-index: 1;
  background-image:
    repeating-linear-gradient(to right, rgba(255,255,255,0.55) 0, rgba(255,255,255,0.55) 1px, transparent 1px, transparent 15px),
    repeating-linear-gradient(to bottom, rgba(255,255,255,0.55) 0, rgba(255,255,255,0.55) 1px, transparent 1px, transparent 15px);
}
.grid-corner.tl { top: 0; left: 0; -webkit-mask-image: linear-gradient(135deg, #000 35%, transparent 85%); mask-image: linear-gradient(135deg, #000 35%, transparent 85%); }
.grid-corner.tr { top: 0; right: 0; -webkit-mask-image: linear-gradient(-135deg, #000 35%, transparent 85%); mask-image: linear-gradient(-135deg, #000 35%, transparent 85%); }
.grid-corner.bl { bottom: 0; left: 0; -webkit-mask-image: linear-gradient(45deg, #000 35%, transparent 85%); mask-image: linear-gradient(45deg, #000 35%, transparent 85%); }
.grid-corner.br { bottom: 0; right: 0; -webkit-mask-image: linear-gradient(-45deg, #000 35%, transparent 85%); mask-image: linear-gradient(-45deg, #000 35%, transparent 85%); }

/* ---------- COVER ---------- */
#cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  transition: transform 1.1s cubic-bezier(.7,0,.2,1), opacity 1s ease;
}

#cover.opened {
  transform: translateX(-100%) rotateY(-15deg);
  opacity: 0;
  pointer-events: none;
}

.book {
  width: min(86vw, 360px);
  height: min(78vh, 520px);
  background-image: url('../img/cover.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 3px 10px 10px 3px;
  box-shadow:
    0 25px 60px rgba(0,0,0,0.6),
    inset -3px 0 8px rgba(0,0,0,0.35),
    inset 0 0 0 1px rgba(255,255,255,0.03);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow: hidden;
}

.book::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 14px;
  background: linear-gradient(90deg, rgba(0,0,0,0.4), transparent);
  border-radius: 3px 0 0 3px;
  z-index: 2;
}

.lock {
  width: 62px;
  height: 62px;
  background: linear-gradient(160deg, #d4af6a, #a5793a);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.55), inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 3px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.15s ease;
  border: none;
  position: relative;
  z-index: 3;
}

.lock:active { transform: scale(0.93); }

.lock svg { width: 30px; height: 30px; }

.lock-hint {
  font-family: 'Caveat', cursive;
  color: rgba(255,255,255,0.85);
  font-size: 1.05rem;
  margin-top: 1rem;
  letter-spacing: 0.3px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  position: relative;
  z-index: 3;
}

/* ---------- PASSWORD PANEL ---------- */
#passPanel {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(5,4,4,0.94);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 2rem;
  opacity: 0;
  transition: opacity 0.4s ease;
}

#passPanel.show { display: flex; opacity: 1; }

.pass-card {
  width: min(88vw, 340px);
  background: #16130f;
  border: 1px solid rgba(212,175,106,0.25);
  border-radius: 14px;
  padding: 2.2rem 1.8rem;
  text-align: center;
  position: relative;
}

.pass-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 1.2rem;
  opacity: 0.7;
}

.pass-label {
  font-family: 'Caveat', cursive;
  color: rgba(255,255,255,0.55);
  font-size: 1.05rem;
  margin-bottom: 1.2rem;
}

#passInput {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  color: #f0e6d2;
  font-family: 'EB Garamond', serif;
  font-size: 1.1rem;
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

#passInput:focus { border-color: rgba(212,175,106,0.6); }

.pass-submit {
  margin-top: 1.1rem;
  width: 100%;
  background: linear-gradient(160deg, #d4af6a, #a5793a);
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  color: #1a1408;
  font-family: 'EB Garamond', serif;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s;
}

.pass-submit:active { transform: scale(0.97); }

.pass-close {
  position: absolute;
  top: 12px;
  right: 14px;
  color: rgba(255,255,255,0.35);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  background: none;
  border: none;
}

/* ---------- BUBBLES ---------- */
#bubbleZone {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.bubble {
  position: absolute;
  max-width: 240px;
  background: #f0e6d2;
  color: #2a2118;
  padding: 0.65rem 1rem;
  border-radius: 16px;
  font-family: 'Kalam', cursive;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  animation: bubbleIn 0.4s cubic-bezier(.2,1.4,.4,1) forwards, bubbleOut 0.4s ease forwards;
  animation-delay: 0s, 2.6s;
  pointer-events: auto;
}

.bubble.corner-tl { top: 5%; left: 5%; border-radius: 4px 16px 16px 16px; }
.bubble.corner-tr { top: 5%; right: 5%; border-radius: 16px 4px 16px 16px; }
.bubble.corner-bl { bottom: 8%; left: 5%; border-radius: 16px 16px 16px 4px; }
.bubble.corner-br { bottom: 8%; right: 5%; border-radius: 16px 16px 4px 16px; }

.bubble.special {
  background: #1c1812;
  color: #e8d9b8;
  border: 1px solid rgba(212,175,106,0.4);
}

.bubble.playable {
  cursor: pointer;
  padding-right: 2.6rem;
}

.bubble .sun { color: #d98b3a; font-weight: 700; }
.bubble .moon { color: #9fb3d9; font-weight: 700; }
.bubble.italic-line { font-style: italic; }
.bubble .kr { font-family: 'EB Garamond', serif; letter-spacing: 1px; }

.play-icon {
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-icon svg { width: 16px; height: 16px; }

.play-icon.playing svg .bar {
  animation: eq 0.7s ease-in-out infinite alternate;
}
.play-icon.playing svg .bar:nth-child(2) { animation-delay: 0.15s; }
.play-icon.playing svg .bar:nth-child(3) { animation-delay: 0.3s; }

@keyframes eq {
  0% { transform: scaleY(0.4); }
  100% { transform: scaleY(1); }
}

@keyframes bubbleIn {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes bubbleOut {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.bubble.playable {
  animation: bubbleIn 0.4s cubic-bezier(.2,1.4,.4,1) forwards;
}

.shake { animation: shake 0.4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

/* ---------- DIARY PAGES ---------- */
#diary {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #0e0d0c;
  z-index: 10;
}

#diary.show { display: flex; }

.page-stack {
  position: relative;
  width: min(90vw, 380px);
  height: min(80vh, 560px);
}

.page {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent, transparent 33px,
      rgba(120,140,170,0.35) 33px, rgba(120,140,170,0.35) 34px
    ),
    linear-gradient(135deg, #f4ecd8 0%, #ede2c8 50%, #f0e8d4 100%);
  border-radius: 4px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.55);
  padding: 3rem 2rem 2rem 3.2rem;
  overflow: hidden;
  transform-origin: left center;
  transition: transform 0.55s cubic-bezier(.5,0,.2,1), opacity 0.5s ease;
  display: flex;
  flex-direction: column;
  clip-path: polygon(
    0.6% 1.2%, 8% 0%, 19% 0.8%, 33% 0%, 47% 0.6%, 61% 0%, 76% 0.9%, 89% 0%, 99.4% 1.4%,
    100% 9%, 99.3% 22%, 100% 36%, 99.5% 51%, 100% 65%, 99.4% 79%, 100% 91%, 99.2% 98.8%,
    91% 100%, 78% 99.3%, 64% 100%, 50% 99.4%, 36% 100%, 22% 99.3%, 9% 100%, 0.4% 98.7%,
    1% 88%, 0.3% 74%, 1.1% 60%, 0% 46%, 0.8% 32%, 0% 18%
  );
}

.page::before {
  content: '';
  position: absolute;
  left: 1.7rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(200,80,80,0.25);
}

.page::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at top left, rgba(255,255,255,0.15), transparent 60%),
    radial-gradient(circle at 12% 8%, rgba(140,110,60,0.16) 0%, transparent 14%),
    radial-gradient(circle at 88% 5%, rgba(140,110,60,0.13) 0%, transparent 12%),
    radial-gradient(circle at 6% 92%, rgba(140,110,60,0.15) 0%, transparent 13%),
    radial-gradient(circle at 93% 95%, rgba(140,110,60,0.12) 0%, transparent 11%);
  pointer-events: none;
  mix-blend-mode: multiply;
}

.tear-drop {
  position: absolute;
  pointer-events: none;
  background: radial-gradient(circle at 38% 28%, rgba(255,255,255,0.3), rgba(140,120,80,0.22) 45%, rgba(105,88,55,0.34) 75%, rgba(90,74,46,0.4) 100%);
  box-shadow: inset 0 0 8px rgba(80,64,38,0.35);
  mix-blend-mode: multiply;
  filter: blur(0.3px);
}

.tear-streak {
  position: absolute;
  width: 6px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(130,110,70,0.26), rgba(130,110,70,0.06));
  mix-blend-mode: multiply;
  filter: blur(0.4px);
}

.wrinkle-fold {
  position: absolute;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 46%, rgba(90,75,50,0.1) 49%, rgba(255,255,255,0.25) 51%, transparent 54%);
  mix-blend-mode: multiply;
}

.page-number {
  position: absolute;
  bottom: 14px;
  right: 20px;
  font-family: 'Caveat', cursive;
  color: rgba(60,50,40,0.4);
  font-size: 1rem;
}

.page-text {
  font-family: 'Kalam', cursive;
  font-weight: 400;
  color: #3a2f22;
  font-size: 1.05rem;
  line-height: 33px;
  white-space: pre-wrap;
  overflow: hidden;
}

.page.current { z-index: 5; transform: rotateY(0deg) translateX(0); }
.page.next { z-index: 4; transform: translateX(6px) scale(0.98); opacity: 0.9; }
.page.behind { z-index: 3; transform: translateX(10px) scale(0.96); opacity: 0.7; }
.page.gone { transform: translateX(-115%) rotateZ(-8deg); opacity: 0; z-index: 6; }
.page.hidden-page { display: none; }

.swipe-hint {
  position: absolute;
  bottom: -34px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Caveat', cursive;
  color: rgba(255,255,255,0.3);
  font-size: 1rem;
}

.dots {
  position: absolute;
  top: -28px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: background 0.3s;
}

.dot.active { background: rgba(212,175,106,0.9); }
