@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;
}
/* Hussar Bold, the designer's own web font file, unmodified (SIL OFL 1.1, Reserved Font Name Hussar) */
@font-face { font-family: "Hussar"; src: url("../fonts/hussar-bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("../fonts/fraunces-italic-latin.woff2") format("woff2"); font-weight: 300 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Dancing Script"; src: url("../fonts/dancing-script-latin.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Caveat"; src: url("../fonts/caveat-latin.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }

/* the face for the words and the title; switch with ?font= (see js/main.js). Hussar Bold is the default. */
:root {
  --story: "Hussar", "Avenir Next", "Futura", "Helvetica Neue", sans-serif;
  --story-style: normal; --story-weight: 700; --story-scale: 0.74; --story-settings: normal;
  --story-spacing: 0.012em; --story-leading: 1.26; --story-words: 0.16em; --story-width: 38rem;
  --t1-weight: 700; --t1-scale: 0.78; --t1-spacing: 0.01em; --t1-leading: 0.92;
  --t2-transform: uppercase; --t2-spacing: 0.42em; --t2-scale: 0.82; --t2-style: normal; --t2-weight: 700;
  --by-style: normal; --by-scale: 0.82; --by-transform: uppercase; --by-spacing: 0.24em;
  --ui: "Hussar", "Avenir Next", sans-serif; --ui-style: normal; --ui-weight: 700; --ui-transform: lowercase; --ui-scale: 0.78;
}
body[data-font="cormorant"] {
  --story: "Cormorant Garamond", "Iowan Old Style", Garamond, Georgia, serif;
  --story-style: italic; --story-weight: 500; --story-scale: 1; --story-spacing: 0.005em; --story-leading: 1.12; --story-words: normal; --story-width: 32rem;
  --t1-weight: 500; --t1-scale: 1; --t1-spacing: 0.005em; --t1-leading: 0.86;
  --t2-transform: uppercase; --t2-spacing: 0.5em; --t2-scale: 1; --t2-style: normal; --t2-weight: 400;
  --by-style: italic; --by-scale: 1; --by-transform: none; --by-spacing: 0.14em;
}
body:not([data-font="hussar"]) { --ui: "Cormorant Garamond", "Iowan Old Style", Garamond, Georgia, serif; --ui-style: italic; --ui-weight: 400; --ui-transform: none; --ui-scale: 1; }
body[data-font="fraunces"], body[data-font="script"], body[data-font="hand"] {
  --story-spacing: 0.005em; --story-leading: 1.12; --story-words: normal; --story-width: 32rem; --t1-scale: 1; --t1-spacing: 0.005em; --t1-leading: 0.86;
  --by-style: var(--story-style); --by-scale: 1; --by-transform: none; --by-spacing: 0.14em;
}
body[data-font="fraunces"] {
  --story: "Fraunces", Georgia, serif; --story-style: italic; --story-weight: 400; --story-scale: 0.95; --story-settings: "SOFT" 100, "WONK" 1, "opsz" 72;
  --t1-weight: 400; --t2-spacing: 0.42em; --t2-scale: 0.8; --t2-style: italic; --t2-weight: 300;
}
body[data-font="script"] {
  --story: "Dancing Script", cursive; --story-style: normal; --story-weight: 500; --story-scale: 1.02;
  --t1-weight: 600; --t2-transform: none; --t2-spacing: 0.04em; --t2-scale: 1.9; --t2-weight: 500;
}
body[data-font="hand"] {
  --story: "Caveat", cursive; --story-style: normal; --story-weight: 500; --story-scale: 1.22;
  --t1-weight: 600; --t2-transform: none; --t2-spacing: 0.05em; --t2-scale: 2.0; --t2-weight: 500;
}
:root {
  --cream: #efe4cc;
  --mute: rgba(239, 228, 204, 0.62);
  --flame: #ffcf8a;
  --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(--ui); 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 h1, #title .by { font-family: var(--story); font-variation-settings: var(--story-settings); }
#title .t1 {
  font-style: var(--story-style); font-weight: var(--t1-weight);
  font-size: calc(clamp(3.8rem, 2.6rem + 6vw, 8.4rem) * var(--t1-scale)); line-height: var(--t1-leading); letter-spacing: var(--t1-spacing);
  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: var(--t2-weight); text-transform: var(--t2-transform); font-style: var(--t2-style);
  font-size: calc(clamp(0.85rem, 0.7rem + 0.7vw, 1.3rem) * var(--t2-scale)); letter-spacing: var(--t2-spacing); padding-left: var(--t2-spacing);
  color: var(--cream); text-shadow: 0 0 18px rgba(2, 4, 12, 0.95);
}
#title .by {
  margin: 1.6em 0 0; font-style: var(--by-style); font-size: calc(clamp(0.85rem, 0.75rem + 0.4vw, 1.1rem) * max(1, var(--story-scale)) * var(--by-scale));
  text-transform: var(--by-transform); letter-spacing: var(--by-spacing); 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(var(--story-width), 86vw);
  font-family: var(--story); font-style: var(--story-style); font-weight: var(--story-weight); font-variation-settings: var(--story-settings);
  font-size: calc(clamp(1.55rem, 1.2rem + 1.6vw, 2.7rem) * var(--story-scale)); line-height: var(--story-leading);
  text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
  letter-spacing: var(--story-spacing); word-spacing: var(--story-words);
}
#caption { isolation: isolate; }
/* a soft pool of shade under the words, so they read over any part of the picture */
#caption::before {
  content: ""; position: absolute; inset: -1.4em -2.2em; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(2, 4, 12, 0.5), rgba(2, 4, 12, 0.28) 55%, rgba(2, 4, 12, 0));
  opacity: 0; transition: opacity 1.6s ease;
}
#caption:has(.line:not(.out))::before { opacity: 1; }
#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); }
/* when the page turns, the words leave at once so they never float over the turning sheet */
#caption .line.out.fast .ch { animation: fadeaway 0.28s ease-out both; animation-delay: 0s; }
@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: var(--ui-style); font-weight: var(--ui-weight); text-transform: var(--ui-transform); font-size: calc(1.05rem * var(--ui-scale)); 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-family: var(--story); font-style: var(--story-style); font-weight: var(--story-weight); font-variation-settings: var(--story-settings);
  font-size: calc(clamp(2.2rem, 1.6rem + 3.4vw, 4.4rem) * var(--story-scale)); 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: calc(clamp(1.4rem, 6.4vw, 1.95rem) * var(--story-scale)); width: 86vw; }
body.portrait[data-font="hussar"] #caption { font-size: calc(clamp(1.4rem, 6.4vw, 1.95rem) * 0.8); }
body.portrait #ending { top: 10%; }
body.portrait #title { top: 27%; }

#sound {
  position: absolute; left: max(4.6rem, calc(env(safe-area-inset-left) + 3.8rem)); bottom: max(0.62rem, calc(env(safe-area-inset-bottom) - 0.2rem));
  pointer-events: auto; cursor: pointer; background: none; border: 0; padding: 0.3em 0.4em;
  font-family: var(--ui); font-style: var(--ui-style); font-weight: var(--ui-weight); font-size: calc(0.85rem * var(--ui-scale)); letter-spacing: 0.1em;
  color: rgba(239, 228, 204, 0.4); transition: color 0.6s;
}
#sound.on { color: rgba(255, 205, 140, 0.8); }
#sound:hover { color: rgba(239, 228, 204, 0.8); }
#sound[hidden] { display: none; }
