/* ============================================================
   톰 마볼로 리들의 일기장 — 스타일시트
   양피지, 가죽 표지, 잉크 효과
   ============================================================ */

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

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  /* 책상 분위기 — 짙은 마호가니 + 책상 비네팅 */
  background:
    radial-gradient(ellipse at center, #2a1810 0%, #160a06 70%, #0a0503 100%);
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  color: #2b1810;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* 책상 — 일기장이 놓인 공간 */
.desk {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   가죽 표지 (초기 상태)
   ============================================================ */
.diary {
  position: relative;
  width: 100%;
  max-width: 1000px;
  perspective: 2000px;
}

.cover {
  width: 100%;
  max-width: 420px;
  height: 580px;
  margin: 0 auto;
  background:
    radial-gradient(ellipse at 30% 20%, #4a2618 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, #1a0a04 0%, transparent 60%),
    linear-gradient(135deg, #2d1408 0%, #1a0a04 50%, #2d1408 100%);
  border-radius: 4px 14px 14px 4px;
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.7),
    inset 4px 0 0 rgba(0, 0, 0, 0.6),
    0 30px 80px rgba(0, 0, 0, 0.8),
    0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  /* 가죽 텍스처 — 노이즈 SVG */
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.05 0 0 0 0 0.02 0 0 0 0.4 0'/></filter><rect width='200' height='200' filter='url(%23n)'/></svg>"),
    radial-gradient(ellipse at 30% 20%, #4a2618 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, #1a0a04 0%, transparent 60%),
    linear-gradient(135deg, #2d1408 0%, #1a0a04 50%, #2d1408 100%);
}

.cover:hover {
  transform: rotateY(-3deg) translateY(-4px);
}

.cover.opening {
  transform: rotateY(-180deg);
  pointer-events: none;
  opacity: 0;
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s 0.6s;
}

.cover-inner {
  text-align: center;
  color: #d4a574;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  /* 양각된 듯한 효과 */
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.8)) drop-shadow(0 -1px 0 rgba(255, 200, 130, 0.15));
}

.cover-name {
  font-family: 'IM Fell English', serif;
  font-size: 32px;
  letter-spacing: 0.3em;
  font-weight: normal;
}

.cover-divider {
  width: 60px;
  height: 1px;
  background: #d4a574;
  margin: 24px auto;
  opacity: 0.6;
}

.cover-year {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 18px;
  letter-spacing: 0.2em;
  opacity: 0.8;
}

.open-btn {
  position: absolute;
  bottom: 40px;
  background: rgba(212, 165, 116, 0.1);
  border: 1px solid rgba(212, 165, 116, 0.4);
  color: #d4a574;
  padding: 10px 24px;
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  font-size: 15px;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.3s;
}

.open-btn:hover {
  background: rgba(212, 165, 116, 0.2);
  border-color: rgba(212, 165, 116, 0.7);
}

/* ============================================================
   펼쳐진 일기장
   ============================================================ */
.pages {
  display: none;
  width: 100%;
  background: transparent;
  border-radius: 6px;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.6s ease 0.6s, transform 0.6s ease 0.6s;
}

.pages.open {
  display: flex;
  opacity: 1;
  transform: scale(1);
}

.page {
  flex: 1;
  min-height: 640px;
  padding: 50px 44px;
  position: relative;
  /* 양피지 색감 + 얼룩 */
  background:
    radial-gradient(ellipse at 20% 30%, rgba(180, 140, 90, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(160, 120, 70, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, #f4e8d0 0%, #e8d5b0 100%);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='p'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' seed='8'/><feColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 0 0.1 0 0 0 0.12 0'/></filter><rect width='400' height='400' filter='url(%23p)'/></svg>"),
    radial-gradient(ellipse at 20% 30%, rgba(180, 140, 90, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(160, 120, 70, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, #f4e8d0 0%, #e8d5b0 100%);
  box-shadow:
    inset 0 0 40px rgba(120, 80, 40, 0.2);
  display: flex;
  flex-direction: column;
}

.page-left {
  border-radius: 6px 0 0 6px;
  /* 책 가운데 음영 */
  box-shadow:
    inset 0 0 40px rgba(120, 80, 40, 0.2),
    inset -20px 0 30px -20px rgba(60, 30, 10, 0.5);
}

.page-right {
  border-radius: 0 6px 6px 0;
  box-shadow:
    inset 0 0 40px rgba(120, 80, 40, 0.2),
    inset 20px 0 30px -20px rgba(60, 30, 10, 0.5);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: #6b4423;
  font-size: 14px;
  letter-spacing: 0.1em;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(107, 68, 35, 0.25);
  margin-bottom: 24px;
}

.page-title {
  font-size: 16px;
}

/* ============================================================
   메시지 (왼쪽 페이지)
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  /* 잉크 컬러 텍스트 */
  color: #2b1810;
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  font-size: 18px;
  line-height: 1.85;
  /* 스크롤바 */
  scrollbar-width: thin;
  scrollbar-color: rgba(107, 68, 35, 0.3) transparent;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(107, 68, 35, 0.3);
  border-radius: 3px;
}

.msg {
  margin-bottom: 24px;
  animation: ink-bleed 0.8s ease-out;
}

.msg p {
  margin-bottom: 8px;
}

.msg p:last-child {
  margin-bottom: 0;
}

.msg-user {
  /* 사용자 메시지 — 약간 다른 색의 잉크, 들여쓰기 */
  color: #4a2c1a;
  font-style: italic;
  padding-left: 16px;
  border-left: 2px solid rgba(74, 44, 26, 0.25);
}

.msg-user::before {
  content: '— 그대의 질문';
  display: block;
  font-family: 'IM Fell English', serif;
  font-size: 12px;
  color: rgba(74, 44, 26, 0.6);
  margin-bottom: 4px;
  font-style: italic;
}

.msg-riddle {
  /* 톰 리들 메시지 — 어두운 잉크 */
  color: #1a0d05;
}

.msg-riddle::before {
  content: '— T. M. R.';
  display: block;
  font-family: 'IM Fell English', serif;
  font-size: 12px;
  color: rgba(26, 13, 5, 0.55);
  margin-bottom: 4px;
  font-style: italic;
  letter-spacing: 0.05em;
}

.initial-msg::before {
  content: '— T. M. R.';
}

.msg-error {
  color: #6b1a1a;
  font-style: italic;
}

.msg-error::before {
  content: '— ?';
  color: rgba(107, 26, 26, 0.6);
}

/* 잉크 번짐 애니메이션 */
@keyframes ink-bleed {
  0% {
    opacity: 0;
    filter: blur(4px);
    transform: translateY(4px);
  }
  60% {
    opacity: 0.8;
    filter: blur(1px);
  }
  100% {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

/* 타이핑 표시 — 글자가 한 자씩 나타나는 느낌 */
.typing-indicator {
  display: inline-block;
  color: rgba(26, 13, 5, 0.5);
  font-style: italic;
}

/* 사용자의 잉크가 다이어리로 흡수되며 사라지는 애니메이션 (원작 고증) */
@keyframes ink-absorb {
  0% {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
  30% {
    opacity: 0.9;
    filter: blur(1px);
    transform: scale(0.99);
  }
  70% {
    opacity: 0.4;
    filter: blur(3px);
  }
  100% {
    opacity: 0;
    filter: blur(6px);
    transform: scale(0.98);
  }
}

.ink-absorb-anim {
  animation: ink-absorb 2.5s ease-in forwards;
}

.typing-indicator::after {
  content: '';
  animation: dots 1.4s infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* ============================================================
   깃펜 입력 영역 (오른쪽 페이지)
   ============================================================ */
.quill-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.quill-input {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  resize: none;
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  font-size: 18px;
  line-height: 1.85;
  color: #2b1810;
  outline: none;
  /* 흐릿한 가로줄 — 일기장 줄 */
  background-image: linear-gradient(
    to bottom,
    transparent 0,
    transparent 32px,
    rgba(107, 68, 35, 0.12) 32px,
    rgba(107, 68, 35, 0.12) 33px,
    transparent 33px
  );
  background-size: 100% 33px;
  background-attachment: local;
  padding-top: 2px;
}

.quill-input::placeholder {
  color: rgba(107, 68, 35, 0.4);
  font-style: italic;
}

.quill-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(107, 68, 35, 0.2);
}

.quill-hint {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 13px;
  color: rgba(107, 68, 35, 0.65);
}

.quill-submit {
  background: rgba(43, 24, 16, 0.05);
  border: 1px solid rgba(43, 24, 16, 0.4);
  color: #2b1810;
  padding: 10px 20px;
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  font-size: 15px;
  font-style: italic;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.25s;
}

.quill-submit:hover:not(:disabled) {
  background: rgba(43, 24, 16, 0.12);
  border-color: rgba(43, 24, 16, 0.7);
}

.quill-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.quill-icon {
  font-size: 18px;
  transform: rotate(-15deg);
  display: inline-block;
}

/* ============================================================
   반응형
   ============================================================ */
@media (max-width: 900px) {
  body {
    padding: 10px;
  }
  .pages {
    flex-direction: column;
  }
  .page {
    min-height: auto;
    padding: 32px 28px;
  }
  .page-left {
    border-radius: 6px 6px 0 0;
    min-height: 400px;
    box-shadow:
      inset 0 0 40px rgba(120, 80, 40, 0.2),
      inset 0 -20px 30px -20px rgba(60, 30, 10, 0.5);
  }
  .page-right {
    border-radius: 0 0 6px 6px;
    box-shadow:
      inset 0 0 40px rgba(120, 80, 40, 0.2),
      inset 0 20px 30px -20px rgba(60, 30, 10, 0.5);
  }
  .messages, .quill-input {
    font-size: 16px;
  }
  .cover {
    height: 480px;
  }
  .cover-name {
    font-size: 26px;
  }
}

/* ============================================================
   페이지네이션 컨트롤 (이전/다음 장)
   ============================================================ */
.pagination-controls {
  margin-top: 24px;
  display: flex;
  align-items: center;
}

.left-pagination {
  justify-content: flex-start;
}

.right-pagination {
  justify-content: flex-end;
}

.page-btn {
  background: transparent;
  border: none;
  color: #6b4423;
  font-family: 'Cormorant Garamond', 'Nanum Myeongjo', serif;
  font-size: 16px;
  font-style: italic;
  cursor: pointer;
  padding: 8px 12px;
  transition: color 0.3s, transform 0.3s;
  letter-spacing: 0.05em;
}

.page-btn:hover:not(:disabled) {
  color: #2b1810;
  transform: scale(1.05);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: default;
}
