@font-face {
  font-family: "Harry P";
  src: url("./assets/fonts/harry-p/HARRYP__.TTF") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

@font-face {
  font-family: "Riddle Hand";
  src: url("./assets/fonts/hurricane.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

@font-face {
  font-family: "Fell Diary";
  src: url("./assets/fonts/im-fell-english.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

:root {
  --ink: #25130c;
  --paper: #b97845;
  --paper-light: #d69a60;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

.ink-filters {
  position: fixed;
  width: 0;
  height: 0;
  overflow: hidden;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #120905;
}

.scene {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: clamp(14px, 2.5vw, 40px);
  isolation: isolate;
  background:
    radial-gradient(ellipse at 58% 22%, rgba(212, 116, 54, 0.34), transparent 34%),
    radial-gradient(ellipse at 50% 76%, rgba(103, 44, 18, 0.24), transparent 48%),
    repeating-linear-gradient(9deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 8px),
    linear-gradient(145deg, #402013 0%, #1b0d08 46%, #090403 100%);
}

.scene::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 38%, rgba(0, 0, 0, 0.76) 112%);
}

.table-shadow {
  position: absolute;
  width: min(94vw, 1320px);
  height: 26vh;
  bottom: 3vh;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.66);
  filter: blur(42px);
  transform: perspective(600px) rotateX(62deg);
}

.diary {
  position: relative;
  width: min(97vw, 1600px);
  height: min(91vh, 920px);
  transform: perspective(1800px) rotateX(2deg) rotateZ(-0.18deg);
  transform-origin: center center;
  transition: transform 2.5s cubic-bezier(0.42, 0, 0.2, 1);
  filter: drop-shadow(0 42px 42px rgba(0, 0, 0, 0.64));
}

.diary.focus-date {
  transform: perspective(1800px) translate(-18%, 16%) scale(1.52) rotateX(1deg);
}

.cover-edge {
  position: absolute;
  inset: -10px -14px -18px -24px;
  border-radius: 32px 22px 30px 36px;
  background: linear-gradient(135deg, #261008, #0d0503 72%);
  box-shadow: inset 0 0 0 2px rgba(128, 68, 35, 0.22);
}

.page-stack {
  position: absolute;
  top: 7px;
  bottom: -12px;
  width: 50.5%;
  background:
    repeating-linear-gradient(180deg, #6b3d26 0 1px, #c08a59 1px 3px, #8e5938 3px 4px),
    #8d5635;
  box-shadow:
    4px 7px 0 #6e3e27,
    8px 12px 18px rgba(0, 0, 0, 0.44);
}

.page-stack-left {
  left: -8px;
  border-radius: 28px 4px 8px 34px;
  transform: perspective(900px) rotateY(2deg);
}

.page-stack-right {
  right: -12px;
  border-radius: 4px 28px 34px 8px;
  transform: perspective(900px) rotateY(-2deg);
  box-shadow:
    8px 6px 0 #6e3e27,
    13px 11px 0 #9c6742,
    17px 17px 25px rgba(0, 0, 0, 0.5);
}

.book-spread {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 30px 24px 25px 34px;
  background: #c99058;
  box-shadow:
    inset 8px 0 22px rgba(62, 26, 12, 0.18),
    inset -8px 0 22px rgba(61, 25, 11, 0.16),
    inset 0 0 0 1px rgba(73, 34, 17, 0.4);
}

.book-page {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background:
    radial-gradient(circle at 60% 22%, rgba(255, 232, 190, 0.13), transparent 34%),
    linear-gradient(105deg, rgba(111, 55, 28, 0.25), transparent 16%, rgba(154, 91, 51, 0.12)),
    url("./assets/parchment-texture.png") center / cover;
}

.book-page-left {
  left: 0;
  border-radius: 30px 2px 4px 34px;
  box-shadow:
    inset -30px 0 45px rgba(70, 31, 14, 0.21),
    inset 8px 0 13px rgba(255, 224, 177, 0.1),
    inset 0 -6px 9px rgba(69, 31, 15, 0.16);
}

.book-page-right {
  right: 0;
  border-radius: 2px 24px 25px 4px;
  background-position: 35% center;
  box-shadow:
    inset 32px 0 48px rgba(65, 28, 13, 0.2),
    inset -7px 0 12px rgba(78, 35, 17, 0.14),
    inset 0 -6px 9px rgba(69, 31, 15, 0.16);
}

.center-gutter {
  position: absolute;
  z-index: 2;
  top: -1%;
  bottom: -1%;
  left: 50%;
  width: clamp(20px, 2.5vw, 40px);
  transform: translateX(-50%);
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(55, 23, 10, 0.38) 43%, rgba(24, 9, 4, 0.5) 50%, rgba(255, 218, 165, 0.1) 56%, transparent);
  filter: blur(2px);
}

.paper-light,
.paper-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.paper-light {
  background:
    radial-gradient(ellipse at 52% 18%, rgba(255, 221, 168, 0.2), transparent 45%),
    linear-gradient(180deg, rgba(255, 218, 161, 0.08), transparent 42%);
}

.paper-grain {
  opacity: 0.17;
  mix-blend-mode: multiply;
  background:
    repeating-radial-gradient(circle at 18% 22%, rgba(69, 30, 14, 0.16) 0 0.6px, transparent 0.9px 5px),
    repeating-linear-gradient(88deg, transparent 0 7px, rgba(85, 42, 21, 0.04) 8px 9px);
}

.writing-surface {
  position: absolute;
  inset: clamp(28px, 4vw, 66px) clamp(38px, 5vw, 82px) clamp(42px, 5vw, 76px);
  overflow: hidden;
}

#handwritingCanvas,
.fade-snapshot {
  display: block;
  width: 100%;
  height: 100%;
}

#handwritingCanvas {
  position: relative;
  z-index: 2;
  touch-action: none;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M4 20L8 16 18 2l4 3L12 18z' fill='%2325130c'/%3E%3C/svg%3E") 3 21, crosshair;
}

.fade-snapshot {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}

.fade-snapshot.active {
  animation: ink-fade 1.9s cubic-bezier(0.48, 0.02, 0.78, 0.64) forwards;
}

.story-text {
  position: absolute;
  inset: 7% 8% 10%;
  z-index: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  overflow: hidden;
  text-align: center;
  font-family: "Riddle Hand", "Harry P", cursive;
  font-size: clamp(2.4rem, 4.5vw, 5.2rem);
  line-height: 1.02;
  letter-spacing: 0.015em;
  color: rgba(37, 19, 12, 0.96);
  white-space: pre-wrap;
  opacity: 0;
  filter: blur(0.15px);
  pointer-events: none;
  text-shadow: 0.4px 0 rgba(31, 12, 7, 0.35);
}

.story-text.visible {
  opacity: 1;
}

.story-text.fade-enter {
  animation: ink-write-in 2.8s cubic-bezier(0.22, 0.7, 0.24, 1) both;
}

.story-text.ink-soak-out {
  animation: ink-soak-out 2.2s cubic-bezier(0.45, 0, 0.75, 1) forwards;
}

.story-text.writing::after {
  content: "";
  display: inline-block;
  width: 0.08em;
  height: 0.75em;
  margin-left: 0.05em;
  background: currentColor;
  animation: blink 0.8s steps(1) infinite;
}

.status-text {
  position: absolute;
  z-index: 5;
  left: clamp(48px, 8vw, 130px);
  bottom: clamp(13px, 2vw, 28px);
  margin: 0;
  font-family: "Fell Diary", Georgia, serif;
  font-size: clamp(0.65rem, 1vw, 0.82rem);
  font-style: italic;
  letter-spacing: 0.07em;
  color: rgba(52, 25, 14, 0.43);
  transition: opacity 400ms ease;
}

.page-storm {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: none;
  overflow: hidden;
  pointer-events: none;
  perspective: 1600px;
}

.page-storm.active {
  display: block;
}

.page-storm i {
  position: absolute;
  inset: 0 50% 0 0;
  transform-origin: right center;
  border-radius: 28px 2px 4px 34px;
  background:
    linear-gradient(90deg, rgba(102, 57, 31, 0.18), transparent 20%, rgba(255, 225, 179, 0.12)),
    url("./assets/parchment-texture.png") center / cover;
  box-shadow:
    18px 2px 24px rgba(39, 15, 6, 0.38),
    inset -18px 0 22px rgba(74, 34, 16, 0.16);
  animation: page-whip 360ms cubic-bezier(0.62, 0.02, 0.36, 0.98) both;
  animation-delay: calc(var(--page-index) * 46ms);
}


.memory-scene {
  position: absolute;
  z-index: 12;
  inset: 0;
  visibility: hidden;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  background: #090b0b;
}

.memory-scene.active {
  visibility: visible;
  animation: memory-arrival 7s ease both;
}

.memory-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, #fff 0, #fff9dc 8%, rgba(210, 227, 213, 0.78) 24%, transparent 58%);
  animation: memory-flash 2.2s ease-out both;
}

.memory-vignette {
  position: absolute;
  inset: 0;
  z-index: 4;
  background:
    radial-gradient(ellipse at center, transparent 24%, rgba(0, 0, 0, 0.72) 90%),
    repeating-linear-gradient(180deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 4px);
}

.memory-corridor {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(2, 8, 7, 0.9), transparent 28%, transparent 72%, rgba(2, 8, 7, 0.9)),
    linear-gradient(180deg, #17231f, #314337 54%, #111915 55%, #050706);
  filter: sepia(0.25) contrast(1.18) saturate(0.65);
  transform: scale(1.08);
  animation: memory-drift 7s ease-out both;
}

.arch {
  position: absolute;
  top: 6%;
  width: 20%;
  height: 70%;
  border: clamp(10px, 1.2vw, 18px) solid #0b110f;
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  opacity: 0.82;
}

.arch-one { left: 14%; }
.arch-two { right: 14%; }

.memory-figure {
  position: absolute;
  bottom: 12%;
  width: 6%;
  height: 31%;
  border-radius: 48% 48% 16% 16%;
  background: #050706;
  box-shadow: 0 -32px 0 -12px #050706;
}

.figure-riddle { left: 42%; }
.figure-headmaster { right: 37%; height: 36%; }

.memory-caption {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 8%;
  margin: 0;
  text-align: center;
  font-family: "Fell Diary", serif;
  font-size: clamp(1rem, 2vw, 1.8rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(226, 230, 213, 0.74);
}

.memory-date {
  position: absolute;
  z-index: 13;
  top: clamp(30px, 6vh, 68px);
  right: clamp(65px, 10vw, 155px);
  margin: 0;
  font-family: "Riddle Hand", cursive;
  font-size: clamp(2.5rem, 5vw, 5.8rem);
  line-height: 1;
  color: rgba(38, 19, 11, 0.92);
  opacity: 0;
  filter: blur(3px);
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 1.2s ease, filter 1.2s ease, transform 1.2s ease;
}

.memory-date.visible {
  opacity: 1;
  filter: blur(0.15px);
  transform: translateY(0);
}

.spine-flash {
  position: absolute;
  z-index: 14;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) scaleY(0.05);
  transform-origin: center;
  background: #fffbe8;
  box-shadow:
    0 0 8px 3px #fff,
    0 0 28px 10px rgba(255, 233, 170, 0.95),
    0 0 80px 32px rgba(255, 185, 78, 0.62);
}

.spine-flash::before,
.spine-flash::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 95vw;
  height: 34vh;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.98), rgba(255,220,142,0.48) 20%, transparent 67%);
  filter: blur(7px);
}

.spine-flash::after {
  width: 120vw;
  height: 9px;
  filter: blur(2px);
  background: linear-gradient(90deg, transparent, #fff6cf 22%, #fff 50%, #fff6cf 78%, transparent);
}

.spine-flash.active {
  animation: spine-ignition 1.35s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

.screen-flash {
  position: fixed;
  z-index: 100;
  inset: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  background: #fff;
}

.screen-flash.active {
  visibility: visible;
  animation: screen-whiteout 4.5s ease-out forwards;
}

@keyframes ink-fade {
  0% { opacity: 1; filter: url("#inkSoak") blur(0) saturate(1); transform: scale(1); }
  24% { opacity: 0.92; filter: url("#inkSoak") blur(0.25px) saturate(1.35); transform: scale(1.001, 1.004); }
  56% { opacity: 0.58; filter: url("#inkSoak") blur(1.1px) saturate(1.08); transform: scale(1.005, 1.016); }
  82% { opacity: 0.18; filter: url("#inkSoak") blur(3px) saturate(0.68); transform: scale(1.012, 1.035); }
  100% { opacity: 0; filter: url("#inkSoak") blur(6px) saturate(0.4); transform: scale(1.02, 1.065); }
}

@keyframes ink-write-in {
  0% {
    opacity: 0;
    clip-path: inset(0 100% 0 0);
    filter: url("#inkSoak") blur(2.8px);
  }
  16% {
    opacity: 0.58;
  }
  58% {
    opacity: 0.84;
    filter: url("#inkSoak") blur(0.75px);
  }
  100% {
    opacity: 1;
    clip-path: inset(0 0 0 0);
    filter: url("#inkSoak") blur(0.12px);
  }
}

@keyframes ink-soak-out {
  0% {
    opacity: 1;
    filter: url("#inkSoak") blur(0.15px);
    transform: scale(1);
    text-shadow: 0.4px 0 rgba(31, 12, 7, 0.35);
  }
  28% {
    opacity: 0.86;
    filter: url("#inkSoak") blur(0.55px);
    transform: scale(1.003, 1.012);
    text-shadow:
      0 1px 1px rgba(37, 19, 12, 0.48),
      0 3px 4px rgba(71, 34, 17, 0.22);
  }
  68% {
    opacity: 0.34;
    filter: url("#inkSoak") blur(2.3px);
    transform: scale(1.012, 1.035);
    text-shadow:
      0 2px 3px rgba(37, 19, 12, 0.3),
      0 7px 10px rgba(71, 34, 17, 0.18);
  }
  100% {
    opacity: 0;
    filter: url("#inkSoak") blur(7px);
    transform: scale(1.025, 1.07);
    text-shadow: 0 12px 18px rgba(71, 34, 17, 0.08);
  }
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

@keyframes page-whip {
  0% { transform: rotateY(0deg) skewY(0) scaleX(1); opacity: 1; }
  45% { transform: rotateY(92deg) skewY(-1deg) scaleX(1.03); opacity: 1; }
  100% { transform: rotateY(178deg) skewY(-1.5deg) scaleX(1); opacity: 0.22; }
}

@keyframes spine-ignition {
  0% { opacity: 0; transform: translateX(-50%) scaleY(0.03); }
  24% { opacity: 1; transform: translateX(-50%) scaleY(1); }
  72% { opacity: 1; width: 7px; filter: brightness(1.4); }
  100% { opacity: 1; width: 18px; transform: translateX(-50%) scaleY(1.12); filter: brightness(2); }
}

@keyframes screen-whiteout {
  0% { visibility: visible; opacity: 0; }
  14% { opacity: 1; }
  34% { opacity: 1; }
  100% { visibility: visible; opacity: 0; }
}

@keyframes memory-arrival {
  0% { opacity: 0; }
  18%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes memory-flash {
  0% { opacity: 0; transform: scale(0.2); }
  18% { opacity: 1; transform: scale(1.35); }
  45% { opacity: 0.92; }
  100% { opacity: 0; transform: scale(2); }
}

@keyframes memory-drift {
  0% { opacity: 0; transform: scale(1.18); filter: blur(7px) sepia(0.3) saturate(0.5); }
  28% { opacity: 1; filter: blur(0.8px) sepia(0.25) saturate(0.65); }
  100% { opacity: 1; transform: scale(1.02); filter: blur(0) sepia(0.25) saturate(0.65); }
}

@media (max-width: 700px) {
  .scene { padding: 8px; }
  .diary { width: 98vw; height: 86vh; transform: none; }
  .book-spread { border-radius: 16px 10px 14px 18px; }
  .writing-surface { inset: 28px 22px 58px; }
  .story-text { inset: 4%; font-size: clamp(2.4rem, 11vw, 4.2rem); }
  .status-text { left: 34px; right: 45px; }
}
