@font-face {
  font-family: "Rye";
  src: url("../assets/fonts/rye.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("../assets/fonts/imfell.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  font-style: italic;
  src: url("../assets/fonts/imfell-italic.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #0d1017;
  --panel: #161a26;
  --panel-2: #1e2333;
  --ink: #cfd6e8;
  --dim: #7d87a3;
  --sel: #8fb6d9;
  --tide: #5aa7c9;
  --masque: #c98fb6;
  --memory: #d9b86a;
  --blood: #9e2b3c;
  --display: "Rye", Georgia, serif;          /* Victorian, Vampire-Knight spirit */
  --body: "IM Fell English", Georgia, serif; /* aged book text */
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  gap: 10px;
  padding: 10px;
  justify-content: center;
}

/* ---- stage ---- */
#stage-wrap {
  position: relative;
  height: 100%;
  aspect-ratio: 2 / 3;
  max-width: 62vw;
}
#stage {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  overflow: hidden;
  isolation: isolate; /* contain layer z-indexes — they must never beat the overlay */
  background: linear-gradient(#0e1b2b 0%, #0a2033 34%, #06141f 35%, #041019 100%);
}
#stage .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* ---- juice: equip settle ---- */
.layer.pop { animation: equip-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes equip-pop {
  0% { transform: translateY(-14px) scale(1.03); opacity: 0.1; }
  60% { transform: translateY(2px) scale(0.998); opacity: 1; }
  100% { transform: none; }
}

/* hair is created flowing: revealed from the crown down, swaying as it lands */
.layer.pop-hair {
  animation: equip-hair 0.95s cubic-bezier(0.3, 0.8, 0.3, 1);
  transform-origin: 50% 10%;
}
@keyframes equip-hair {
  0%   { clip-path: inset(0 0 100% 0); opacity: 0; transform: rotate(-2.2deg); }
  55%  { clip-path: inset(0 0 0% 0);  opacity: 1; transform: rotate(1.4deg); }
  78%  { transform: rotate(-0.7deg); }
  100% { clip-path: inset(0 0 0% 0);  transform: none; }
}

/* ---- juice: idle life ---- */
/* the doll moves as ONE object — hair and clothes stick to the body */
#doll {
  position: absolute;
  inset: 0;
  z-index: 5;
  animation: tail-drift 7s ease-in-out infinite;
  transform-origin: 50% 30%;
}
@keyframes tail-drift {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px) rotate(0.1deg); }
}

/* bubbles */
.bubble {
  position: absolute;
  bottom: -20px;
  border-radius: 50%;
  border: 1px solid #9fc5de66;
  background: radial-gradient(circle at 35% 30%, #cfe6f544, #4a7a9b22);
  animation: bubble-rise linear infinite;
  pointer-events: none;
}
@keyframes bubble-rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  12% { opacity: 0.8; }
  100% { transform: translateY(-62vh) translateX(10px); opacity: 0; }
}

/* moon caustics */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  top: 35%;
  background:
    radial-gradient(ellipse 60% 18% at 30% 20%, #bfe3ff14, transparent),
    radial-gradient(ellipse 50% 14% at 70% 55%, #bfe3ff10, transparent),
    radial-gradient(ellipse 70% 20% at 50% 85%, #bfe3ff0c, transparent);
  animation: caustics 9s ease-in-out infinite alternate;
  pointer-events: none;
  mix-blend-mode: screen;
}
@keyframes caustics {
  from { transform: translateX(-12px); opacity: 0.8; }
  to { transform: translateX(12px); opacity: 1; }
}

/* fire sparks above the waterline */
.spark {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffbe5a;
  filter: blur(0.4px);
  animation: spark-drift ease-out infinite;
  pointer-events: none;
}
@keyframes spark-drift {
  0% { transform: translate(0, 0); opacity: 0; }
  15% { opacity: 0.9; }
  100% { transform: translate(14px, -46px); opacity: 0; }
}

/* ---- juice: the Walk Ashore reveal ---- */
#stage-wrap.reveal #stage,
#stage-wrap.reveal #watcher-wrap {
  transition: transform 1.6s cubic-bezier(0.5, 0, 0.2, 1);
  /* shared origin: the two layers must move as one world */
  transform-origin: 50% 50%;
  transform: scale(1.7) translateY(21%);
}
#stage-wrap.reveal #ashore { opacity: 0; pointer-events: none; }
#ashore { transition: opacity 0.4s ease; }

/* ---- watcher (the man on the shore) ---- */
#watcher-wrap {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.3, 1);
  transform-origin: 27% 29%;
}
.watcher-pose {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.55s ease;
}
#watcher-wrap.react-tide { animation: w-tide 0.65s ease; }
#watcher-wrap.react-masque { animation: w-masque 0.6s ease; }
#watcher-wrap.react-memory { animation: w-memory 0.65s ease; }
@keyframes w-tide {
  0% { transform: none; }
  40% { transform: translateX(-7px) rotate(-1.1deg); }
  100% { transform: none; }
}
@keyframes w-masque {
  0% { transform: none; }
  35% { transform: translateY(2.5px) scale(1.005); }
  70% { transform: translateY(-1.5px); }
  100% { transform: none; }
}
@keyframes w-memory {
  0% { transform: none; }
  25% { transform: translateY(-4px); }
  55% { transform: translateY(-4px) rotate(-0.5deg); }
  100% { transform: none; }
}

#ashore {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  min-width: 224px;
  min-height: 76px;
  padding: 0 34px;
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.08em;
  color: #4a4066;
  text-shadow: 0 1px 0 #ffffff88;
  background: url("../assets/ui/btn_blank.png") center / 100% 100% no-repeat;
  border: 0;
  cursor: pointer;
}
#ashore:hover { filter: brightness(1.07) drop-shadow(0 0 10px #b9a6e455); }
#ashore:hover { filter: brightness(1.08); }

/* ---- wardrobe ---- */
#wardrobe {
  width: min(320px, 34vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  padding: 10px;
  gap: 10px;
  align-self: flex-start;  /* shrink-wrap: the panel is as tall as its content */
  height: auto;
  max-height: 100%;
}
#slot-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
#slot-tabs button {
  flex: 1;
  padding: 7px 2px;
  font: inherit;
  font-size: 13px;
  text-transform: capitalize;
  color: var(--dim);
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
#slot-tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--sel); }

#thumbs {
  flex: none; /* no stretching — the grid is exactly its rows */
  overflow: hidden; /* the collection fits — no scroller */
  display: grid;
  /* minmax(0,1fr): tracks may shrink below the images' intrinsic width */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  align-content: start;
}
.thumb { min-width: 0; }
.thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  padding: 4px;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.thumb.equipped { border-color: var(--sel); box-shadow: 0 0 10px #8fb6d955; }
.thumb .vibe {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 13px;
  filter: drop-shadow(0 1px 2px #000);
}
.thumb.hero::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  border: 2px solid var(--memory);
  animation: glint 2.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes glint {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.9; }
}

#tally {
  display: flex;
  gap: 14px;
  justify-content: center;
  padding: 6px 0 2px;
  font-size: 15px;
  color: var(--dim);
}
#tally .lead { color: var(--ink); }

/* ---- overlay (title / tail select / ending) ---- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0d1017ee;
  text-align: center;
  padding: 24px;
}
#overlay.title {
  background:
    linear-gradient(#0d101744 30%, #0d1017cc 72%, #0d1017f2 100%),
    url("../assets/bg/title.jpg") center 18% / cover no-repeat #0d1017;
  justify-content: flex-end;
  padding-bottom: 7vh;
}
#overlay.title h1 { font-size: 56px; }
#overlay[hidden] { display: none; }
#overlay h1 {
  font-family: var(--display);
  font-size: 46px;
  font-weight: 400;
  letter-spacing: 0.12em;
  margin: 0;
  color: #e6dcc3;
  text-shadow: 0 0 22px #9e2b3c66, 0 2px 0 #000;
}
#overlay p { max-width: 52ch; color: var(--dim); margin: 0; }
#overlay .tails { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
#overlay .tails button {
  width: 130px;
  height: 200px;
  background: var(--panel-2) center/cover no-repeat;
  border: 2px solid #313950;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  text-transform: capitalize;
  text-shadow: 0 1px 3px #000;
}
#overlay .tails button:hover { border-color: var(--sel); }
#overlay button.primary {
  min-width: 210px;
  min-height: 72px;
  padding: 0 32px;
  font-family: var(--display);
  font-size: 15px;
  color: #4a4066;
  text-shadow: 0 1px 0 #ffffff88;
  background: url("../assets/ui/btn_blank.png") center / 100% 100% no-repeat;
  border: 0;
  cursor: pointer;
}
#overlay button.primary:hover { filter: brightness(1.07) drop-shadow(0 0 10px #b9a6e455); }

.vibe-icon { object-fit: contain; vertical-align: middle; filter: drop-shadow(0 1px 2px #000c); }
#tally span { display: inline-flex; align-items: center; gap: 4px; }

@media (max-width: 700px) {
  #app { flex-direction: column; align-items: center; overflow-y: auto; }
  #stage-wrap { max-width: 100%; width: 100%; height: auto; }
  #wardrobe { width: 100%; }
}
