@font-face {
  font-family: "Cormorant Garamond";
  src: url("../fonts/cormorant-garamond-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cormorant Garamond";
  src: url("../fonts/cormorant-garamond-italic-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-style: italic;
  font-display: swap;
}
:root {
  --cream: #efe4cc;
  --mute: rgba(239, 228, 204, 0.62);
  --flame: #ffcf8a;
  --face: "Cormorant Garamond", "Iowan Old Style", Garamond, Georgia, serif;
  --ease: cubic-bezier(0.16, 0.84, 0.3, 1);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #020308;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#stage { position: fixed; inset: 0; display: block; width: 100vw; height: 100vh; cursor: pointer; }
#ui { position: fixed; inset: 0; pointer-events: none; font-family: var(--face); color: var(--cream); }

#loading { position: fixed; inset: 0; background: #020308; transition: opacity 1.6s ease; }
body.ready #loading { opacity: 0; pointer-events: none; }

/* ---- the title: set quietly, revealed by a slow sweep of light ---- */
#title {
  position: absolute; left: 50%; top: 31%; transform: translate(-50%, -50%);
  text-align: center; white-space: nowrap;
  opacity: 0; transition: opacity 1.4s ease;
}
#title.show { opacity: 1; }
#title h1 { margin: 0; font-weight: 400; display: flex; flex-direction: column; align-items: center; }
#title .t1 {
  font-style: italic; font-weight: 500;
  font-size: clamp(3.8rem, 2.6rem + 6vw, 8.4rem); line-height: 0.86; letter-spacing: 0.005em;
  background: linear-gradient(100deg, var(--cream) 0%, var(--cream) 42%, #fff3da 48%, #ffc77a 50%, #fff3da 52%, var(--cream) 58%, var(--cream) 100%);
  background-size: 320% 100%; background-position: 100% 0;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0.02em 0.04em rgba(0, 0, 0, 0.7)) drop-shadow(0 0 0.35em rgba(2, 4, 12, 0.9));
}
#title .t2 {
  margin-top: 0.55em; font-weight: 400; text-transform: uppercase;
  font-size: clamp(0.85rem, 0.7rem + 0.7vw, 1.3rem); letter-spacing: 0.5em; padding-left: 0.5em;
  color: var(--cream); text-shadow: 0 0 18px rgba(2, 4, 12, 0.95);
}
#title .by {
  margin: 1.6em 0 0; font-style: italic; font-size: clamp(0.85rem, 0.75rem + 0.4vw, 1.1rem);
  letter-spacing: 0.14em; color: var(--mute); text-shadow: 0 0 14px rgba(2, 4, 12, 1);
  display: flex; align-items: center; justify-content: center; gap: 0.9em;
}
#title .by::before, #title .by::after { content: ""; width: 2.4em; height: 1px; background: rgba(239, 228, 204, 0.35); }
#title h1, #title .by {
  -webkit-mask-image: linear-gradient(100deg, #000 0%, #000 40%, transparent 60%);
  mask-image: linear-gradient(100deg, #000 0%, #000 40%, transparent 60%);
  -webkit-mask-size: 300% 100%; mask-size: 300% 100%;
  -webkit-mask-position: 100% 0; mask-position: 100% 0;
}
#title.show h1 { animation: sweep 3.6s var(--ease) 0.1s both; }
#title.show .t1 { animation: glint 4.2s ease-in-out 0.3s both; }
#title.show .by { animation: sweep 3s var(--ease) 1.9s both; }
@keyframes sweep {
  from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
  to { -webkit-mask-position: 0% 0; mask-position: 0% 0; }
}
@keyframes glint {
  from { background-position: 100% 0; }
  to { background-position: 0% 0; }
}

/* ---- the words: letters unfold into place like folded paper, then rest ---- */
#caption {
  position: absolute; left: 50%; top: 10%;
  width: min(32rem, 86vw);
  font-style: italic; font-weight: 500;
  font-size: clamp(1.55rem, 1.2rem + 1.6vw, 2.7rem); line-height: 1.1;
  letter-spacing: 0.005em;
}
#caption[data-align="center"] { transform: translateX(-50%); text-align: center; }
#caption[data-align="right"] { text-align: right; }
#caption[data-align="left"] { text-align: left; }
#caption .line { display: block; margin: 0.06em 0; perspective: 500px; }
#caption .line:nth-child(2) { margin-left: 0.8em; }
#caption .line:nth-child(3) { margin-left: 0.3em; }
#caption .line:nth-child(4) { margin-left: 1.1em; }
#caption[data-align="center"] .line, #caption[data-align="right"] .line { margin-left: 0; }

.word { display: inline-block; white-space: nowrap; animation: drift 7s ease-in-out var(--wd, 0s) infinite alternate; }
.ch {
  display: inline-block;
  color: var(--cream);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.7), 0 0 0.6em rgba(2, 4, 14, 0.9);
  animation: unfold 1.6s var(--ease) both;
  animation-delay: var(--d, 0s);
  transform-origin: 50% 0%;
}
.word.hot .ch {
  color: var(--flame);
  text-shadow: 0 1px 1px rgba(40, 14, 0, 0.8), 0 0 0.45em rgba(255, 150, 60, 0.6), 0 0 1.2em rgba(255, 120, 40, 0.25);
}
@keyframes unfold {
  0% { opacity: 0; transform: translateY(var(--y, -0.2em)) rotateX(82deg) rotate(var(--r, 4deg)); filter: blur(5px); }
  60% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes drift {
  from { transform: translateY(0) rotate(-0.35deg); }
  to { transform: translateY(-0.035em) rotate(0.35deg); }
}
#caption .line.out .ch { animation: fadeaway 0.9s ease-in both; animation-delay: calc(var(--d, 0s) * 0.15); }
@keyframes fadeaway { to { opacity: 0; transform: translateY(0.12em); filter: blur(4px); } }

#hint {
  position: absolute; left: 50%; bottom: max(1.6rem, calc(env(safe-area-inset-bottom) + 1.2rem));
  transform: translateX(-50%); margin: 0;
  font-style: italic; font-size: 1.05rem; letter-spacing: 0.16em;
  color: var(--mute); text-shadow: 0 0 12px rgba(2, 4, 12, 1);
  opacity: 0; transition: opacity 1.4s ease; white-space: nowrap;
}
#hint.show { opacity: 1; animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: 0.4; } 50% { opacity: 0.9; } }

#ending {
  position: absolute; left: 50%; top: 13%; transform: translateX(-50%); margin: 0;
  font-style: italic; font-weight: 500; font-size: clamp(2.2rem, 1.6rem + 3.4vw, 4.4rem); white-space: nowrap;
  opacity: 0; perspective: 600px;
}
#ending .ch { color: var(--flame); animation-duration: 2.2s; text-shadow: 0 1px 1px rgba(40, 14, 0, 0.8), 0 0 0.5em rgba(255, 150, 60, 0.5), 0 0 1em rgba(2, 4, 14, 0.9); }
#ending.show { opacity: 1; }

#dots {
  position: absolute; right: max(1.1rem, env(safe-area-inset-right)); bottom: max(1.1rem, env(safe-area-inset-bottom));
  display: flex; gap: 8px;
}
#dots i { width: 5px; height: 5px; border-radius: 50%; background: rgba(239, 228, 204, 0.22); transition: background 0.8s, transform 0.8s; }
#dots i.on { background: rgba(255, 205, 140, 0.9); transform: scale(1.2); box-shadow: 0 0 8px rgba(255, 170, 80, 0.6); }
body[data-page="cover"] #dots { opacity: 0; }

#version {
  position: absolute; left: max(1rem, env(safe-area-inset-left)); bottom: max(0.9rem, env(safe-area-inset-bottom));
  font-family: ui-monospace, Menlo, monospace; font-size: 0.62rem; letter-spacing: 0.08em; color: rgba(239, 228, 204, 0.32);
}

body.portrait #caption { font-size: clamp(1.4rem, 6.4vw, 1.95rem); width: 86vw; }
body.portrait #ending { top: 10%; }
body.portrait #title { top: 27%; }
