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

:root {
  --accent: #ff5e8a;
  --ink: #2a2436;
  --paper: #fffdfa;
  --ui-font: "M PLUS Rounded 1c", "Segoe UI", system-ui, sans-serif;
  --pop-font: "Mochiy Pop One", "M PLUS Rounded 1c", "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  background: #000;
  font-family: var(--ui-font);
  overflow: hidden;
  user-select: none;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ---------- backgrounds ---------- */
.bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: opacity 0.6s ease;
  opacity: 0;
}
.bg.visible { opacity: 1; }

/* anime cel texture over any background: soft halftone dots + vignette */
#game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,0.045) 1px, transparent 1.6px);
  background-size: 16px 16px;
}
#game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  box-shadow: inset 0 0 140px rgba(20, 8, 30, 0.55);
}

/* ---------- sprites ---------- */
#stage {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
.slot {
  position: absolute;
  bottom: 0;
  width: 34vw;
  height: 78vh;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#slot-left   { left: 2vw; }
#slot-center { left: 33vw; }
#slot-right  { right: 2vw; }

.sprite {
  --sp: 1; /* character size factor, set from the story data */
  max-width: 100%;
  max-height: 100%;
  transition: filter 0.3s ease, opacity 0.3s ease;
}
.sprite img {
  height: calc(78vh * var(--sp));
  width: auto;
  display: block;
  filter: drop-shadow(0 10px 30px rgba(0,0,0,0.5));
}
.sprite.dim { filter: brightness(0.55) saturate(0.55); }

/* cel-shaded chibi placeholder when a character has no sprite art */
.placeholder {
  position: relative;
  width: calc(220px * var(--sp, 1));
  height: calc(400px * var(--sp, 1));
  max-height: calc(64vh * var(--sp, 1));
  border-radius: 110px 110px 22px 22px;
  border: 4px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--pop-font);
  font-size: calc(80px * var(--sp, 1));
  color: rgba(255,255,255,0.95);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  box-shadow: 0 8px 0 rgba(0,0,0,0.35), inset -18px -26px 0 rgba(0,0,0,0.16), inset 14px 18px 0 rgba(255,255,255,0.18);
}
.placeholder::before {
  content: "• ᴗ •";
  position: absolute;
  top: calc(52px * var(--sp, 1));
  left: 0;
  right: 0;
  text-align: center;
  font-size: calc(26px * var(--sp, 1));
  letter-spacing: 2px;
  color: var(--ink);
  text-shadow: none;
}

/* sprite entrance animations */
.anim-fade        { animation: sp-fade 0.5s ease both; }
.anim-slide-left  { animation: sp-slide-left 0.5s cubic-bezier(.2,.8,.3,1) both; }
.anim-slide-right { animation: sp-slide-right 0.5s cubic-bezier(.2,.8,.3,1) both; }
.anim-pop         { animation: sp-pop 0.45s cubic-bezier(.2,1.6,.4,1) both; }
.anim-shake       { animation: sp-shake 0.45s ease both; }

@keyframes sp-fade        { from { opacity: 0; } to { opacity: 1; } }
@keyframes sp-slide-left  { from { opacity: 0; transform: translateX(-80px); } to { opacity: 1; transform: none; } }
@keyframes sp-slide-right { from { opacity: 0; transform: translateX(80px); } to { opacity: 1; transform: none; } }
@keyframes sp-pop         { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: scale(1); } }
@keyframes sp-shake       { 0%,100% { transform: none; } 20% { transform: translateX(-12px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-7px); } 80% { transform: translateX(4px); } }

/* ---------- dialogue box ---------- */
#dialogue {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 3.2vh;
  width: min(940px, 93vw);
  z-index: 20;
}
#nameplate {
  display: inline-block;
  position: relative;
  z-index: 2;
  padding: 7px 30px;
  margin-left: 26px;
  margin-bottom: -8px;
  transform: skew(-10deg);
  font-family: var(--pop-font);
  font-size: 19px;
  letter-spacing: 1px;
  color: #fff;
  background: var(--accent);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 4px 4px 0 rgba(42, 36, 54, 0.55);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.28);
}
#textbox {
  position: relative;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 26px 30px 32px;
  min-height: 112px;
  color: var(--ink);
  font-size: var(--dialog-size, 20px);
  font-weight: 500;
  line-height: 1.6;
  box-shadow: 0 7px 0 rgba(42, 36, 54, 0.7), 0 20px 44px rgba(0,0,0,0.4);
}
/* corner deco: three dots, anime UI style */
#textbox::after {
  content: "";
  position: absolute;
  top: 12px;
  right: 18px;
  width: 44px;
  height: 8px;
  background-image: radial-gradient(var(--accent) 3.4px, transparent 4px);
  background-size: 15px 8px;
  background-repeat: repeat-x;
  opacity: 0.85;
}
#cursor {
  display: inline-block;
  margin-left: 10px;
  color: var(--accent);
  font-style: normal;
  animation: cursor-bounce 0.7s ease-in-out infinite;
  opacity: 0;
}
#cursor.on { opacity: 1; }
@keyframes cursor-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(20deg); }
}

/* ---------- choices ---------- */
#choices {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(24, 12, 34, 0.5);
  backdrop-filter: blur(3px);
}
#choice-prompt {
  font-family: var(--pop-font);
  color: #fff;
  font-size: 26px;
  margin-bottom: 12px;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    5px 5px 0 rgba(0,0,0,0.4);
}
#choice-list { display: flex; flex-direction: column; gap: 16px; width: min(560px, 88vw); }
.choice-btn {
  padding: 15px 28px;
  font-size: 18px;
  font-family: var(--ui-font);
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  transform: skew(-5deg);
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(42, 36, 54, 0.8);
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
.choice-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: skew(-5deg) translateY(-3px) scale(1.03);
  box-shadow: 0 8px 0 rgba(42, 36, 54, 0.8);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.25);
}

/* ---------- fx ---------- */
#fx-flash, #fx-black {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 40;
}
#fx-flash { background: #fff; }
#fx-black { background: #000; transition: opacity 0.6s ease; }
#fx-flash.go { animation: flash-anim 0.4s ease; }
@keyframes flash-anim { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }

#game.shake { animation: screen-shake 0.5s ease; }
@keyframes screen-shake {
  0%,100% { transform: none; }
  15% { transform: translate(-14px, 4px); }
  30% { transform: translate(12px, -6px); }
  45% { transform: translate(-10px, 6px); }
  60% { transform: translate(8px, -4px); }
  75% { transform: translate(-5px, 2px); }
}

/* ---------- title & end screens ---------- */
#title-screen, #end-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background-size: cover;
  background-position: center;
  transition: opacity 0.7s ease;
  overflow: hidden;
}
#title-screen.fade-out { opacity: 0; pointer-events: none; }

/* rotating anime sunburst behind the title */
#title-rays {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 240vmax;
  height: 240vmax;
  margin: -120vmax 0 0 -120vmax;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.055) 0deg 7deg, transparent 7deg 16deg);
  animation: rays-spin 60s linear infinite;
  pointer-events: none;
}
@keyframes rays-spin { to { transform: rotate(360deg); } }

/* falling sakura petals */
.petal {
  position: absolute;
  top: -50px;
  font-size: 24px;
  opacity: 0.85;
  pointer-events: none;
  animation: petal-fall linear infinite;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}
.petal:nth-child(1) { left: 6%;  font-size: 20px; animation-duration: 11s; animation-delay: 0s; }
.petal:nth-child(2) { left: 18%; font-size: 28px; animation-duration: 14s; animation-delay: 3s; }
.petal:nth-child(3) { left: 31%; font-size: 17px; animation-duration: 10s; animation-delay: 6s; }
.petal:nth-child(4) { left: 45%; font-size: 24px; animation-duration: 13s; animation-delay: 1.5s; }
.petal:nth-child(5) { left: 58%; font-size: 19px; animation-duration: 12s; animation-delay: 8s; }
.petal:nth-child(6) { left: 70%; font-size: 27px; animation-duration: 15s; animation-delay: 4s; }
.petal:nth-child(7) { left: 82%; font-size: 21px; animation-duration: 11.5s; animation-delay: 9s; }
.petal:nth-child(8) { left: 92%; font-size: 25px; animation-duration: 13.5s; animation-delay: 2s; }
@keyframes petal-fall {
  0%   { transform: translateY(-60px) translateX(0) rotate(0deg); }
  25%  { transform: translateY(28vh) translateX(-34px) rotate(95deg); }
  50%  { transform: translateY(55vh) translateX(26px) rotate(190deg); }
  75%  { transform: translateY(80vh) translateX(-22px) rotate(280deg); }
  100% { transform: translateY(108vh) translateX(14px) rotate(360deg); }
}

/* optional logo image in place of the text title */
#title-image {
  position: relative;
  max-width: min(72vw, 680px);
  max-height: 44vh;
  object-fit: contain;
  filter: drop-shadow(0 10px 30px rgba(0,0,0,0.55));
  animation: title-in 0.9s cubic-bezier(.2,.8,.3,1) both, title-float 4s 1s ease-in-out infinite;
}

/* anime logo title: white fill, thick ink outline, hard accent drop */
#title-text {
  position: relative;
  font-family: var(--pop-font);
  font-weight: 400;
  font-size: clamp(48px, 9vw, 108px);
  letter-spacing: 4px;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink), 4px 0 0 var(--ink),
    7px 8px 0 var(--accent);
  animation: title-in 0.9s cubic-bezier(.2,.8,.3,1) both, title-float 4s 1s ease-in-out infinite;
}
@keyframes title-float { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }

#subtitle-text {
  position: relative;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 30px;
  padding: 8px 26px;
  transform: skew(-6deg);
  font-size: 16px;
  letter-spacing: 1px;
  box-shadow: 4px 4px 0 rgba(42, 36, 54, 0.5);
  animation: title-in 0.9s 0.22s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes title-in { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; } }

#start-btn, #end-btn {
  position: relative;
  margin-top: 26px;
  padding: 16px 56px;
  font-family: var(--pop-font);
  font-size: 21px;
  letter-spacing: 3px;
  color: #fff;
  background: var(--accent);
  border: 4px solid var(--ink);
  border-radius: 50px;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
  box-shadow: 0 7px 0 var(--ink), 0 16px 34px rgba(0,0,0,0.45);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  animation: title-in 0.9s 0.45s cubic-bezier(.2,.8,.3,1) both;
}
#start-btn:hover, #end-btn:hover {
  transform: translateY(-4px) scale(1.05) rotate(-1.5deg);
  box-shadow: 0 11px 0 var(--ink), 0 22px 44px rgba(0,0,0,0.5);
}
#start-btn:active, #end-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 var(--ink); }

#admin-link {
  position: absolute;
  bottom: 18px;
  right: 22px;
  color: #fff;
  background: rgba(42, 36, 54, 0.6);
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  padding: 5px 16px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#admin-link:hover { background: var(--accent); border-color: #fff; }

#end-screen { background: rgba(24, 12, 34, 0.93); }
#end-screen h2 {
  font-family: var(--pop-font);
  font-weight: 400;
  font-size: 62px;
  letter-spacing: 6px;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    6px 7px 0 var(--accent);
}
#end-screen p {
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 rgba(42, 36, 54, 0.5);
  padding: 14px 26px;
  font-size: 18px;
  font-weight: 500;
  max-width: 620px;
  text-align: center;
  line-height: 1.6;
}

.hidden { display: none !important; }
