/* ── 최후의 세레나데 — 기본 스타일 (모바일 세로 기준) ───────────── */

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

html, body {
  height: 100%;
  background: #050308;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: #f2ede6;
}

#frame {
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#stage {
  position: relative;
  width: min(100vw, 56dvh);   /* 데스크톱에서는 세로폰 비율로 중앙 정렬 */
  max-width: 520px;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  cursor: pointer;
}

/* ── 배경 ── */
#bg-layer .bg {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 1.1s ease;
  background-size: cover;
  background-position: center;
}
#bg-layer .bg.visible { opacity: 1; }

/* ── 캐릭터 ── */
#char-layer {
  position: absolute; inset: 0;
  pointer-events: none;
}
.char {
  position: absolute;
  bottom: 22dvh;
  width: 44%;
  opacity: 0;
  transition: opacity .7s ease, transform .7s ease, width .35s ease, left .35s ease, right .35s ease, filter .4s ease;
  transform: translateY(12px);
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.45));
}
/* 화자 강조: 말하는 캐릭터가 앞으로, 나머지는 어둡게 */
.char.speaking { z-index: 3; }
.char.dimmed { filter: drop-shadow(0 6px 18px rgba(0,0,0,.45)) brightness(.6) saturate(.85); z-index: 1; }

/* 미니게임·선택지 중에는 캐릭터를 젖혀서 화면 확보 */
#char-layer { transition: opacity .4s ease; }
#stage.collecting #char-layer,
#stage.choosing #char-layer { opacity: .12; pointer-events: none; }
.char.visible { opacity: 1; transform: translateY(0); animation: charFloat 5s ease-in-out infinite; }
.char.pos-left  { left: 4%; right: auto; margin-left: 0; }
.char.pos-right { right: 4%; left: auto; margin-left: 0; }
.char.pos-center { left: 50%; right: auto; margin-left: -22%; }
.char.shot-close { bottom: 18dvh; width: 78%; }
.char.shot-close.pos-left { left: -10%; }
.char.shot-close.pos-right { right: -10%; }
.char.shot-close.pos-center { left: 50%; margin-left: -39%; }
.char.shot-wide { bottom: 18dvh; width: 66%; }
.char.shot-wide.pos-left { left: -3%; }
.char.shot-wide.pos-right { right: -3%; }
.char.shot-wide.pos-center { left: 50%; margin-left: -33%; }
.char.shot-bandi { width: 22%; bottom: 46dvh; }
.char.shot-bandi.pos-left { left: 12%; }
.char.shot-bandi.pos-right { right: 12%; }
.char.shot-bandi.pos-center { left: 50%; margin-left: -11%; }
.char.shot-bandi.visible { animation: bandiFloat 3.4s ease-in-out infinite; }
@keyframes bandiFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-16px) rotate(2deg); }
}
.char svg, .char img { width: 100%; height: auto; display: block; }
@keyframes charFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ── 효과 ── */
#fx-heat {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(255,110,40,.22), transparent 55%),
    radial-gradient(ellipse at 50% 0%, rgba(255,170,60,.10), transparent 50%);
  mix-blend-mode: screen;
}
#fx-heat.on { opacity: 1; animation: heatPulse 4.5s ease-in-out infinite; }
@keyframes heatPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
#fx-flash {
  position: absolute; inset: 0;
  pointer-events: none;
  background: #fff;
  opacity: 0;
}
#fx-flash.go { animation: flashAnim .5s ease-out; }
@keyframes flashAnim { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes shakeAnim {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
#stage.shake { animation: shakeAnim .45s ease; }

/* ── 대사창 ── */
#dialog {
  position: absolute;
  left: 3.5%; right: 3.5%;
  bottom: max(env(safe-area-inset-bottom), 14px);
  min-height: 21dvh;
  padding: 16px 18px 26px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(14,8,16,.78), rgba(10,6,12,.9));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.09);
  opacity: 0;
  transition: opacity .4s ease;
}
#dialog.visible { opacity: 1; }
#name-plate {
  display: none;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
#name-plate.visible { display: block; }
#text-box {
  font-size: 16.5px;
  line-height: 1.75;
  letter-spacing: .01em;
  word-break: keep-all;
  min-height: 3.4em;
}
#text-box.narration { color: #cfc6bd; font-size: 15.5px; }
#next-hint {
  position: absolute;
  right: 18px; bottom: 10px;
  font-size: 11px;
  color: rgba(255,255,255,.65);
  opacity: 0;
}
#next-hint.visible { opacity: 1; animation: hintBlink 1.2s ease-in-out infinite; }
@keyframes hintBlink {
  0%, 100% { transform: translateY(0); opacity: .9; }
  50% { transform: translateY(3px); opacity: .35; }
}

/* ── 선택지 ── */
#choice-layer {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 0 8%;
  background: rgba(5,3,8,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#choice-layer.visible { display: flex; }
.choice-btn {
  width: 100%;
  padding: 15px 18px;
  font-size: 15.5px;
  font-family: inherit;
  color: #f6f1e8;
  word-break: keep-all;
  background: linear-gradient(180deg, rgba(50,32,48,.92), rgba(30,18,32,.92));
  border: 1px solid rgba(255,180,110,.35);
  border-radius: 14px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
}
.choice-btn:active { transform: scale(.97); border-color: rgba(255,200,140,.8); }

/* ── 소리 채집 미니게임 ── */
#collect-layer {
  position: absolute; inset: 0;
  display: none;
  background: rgba(6,4,10,.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#collect-layer.visible { display: block; }
.cl-head {
  position: absolute; top: 7dvh; left: 0; right: 0;
  text-align: center;
  pointer-events: none;
}
.cl-eyebrow { font-size: 12px; letter-spacing: .3em; color: rgba(255,225,170,.75); margin-bottom: 10px; }
.cl-title { font-size: 20px; font-weight: 700; color: #ffeeD2; text-shadow: 0 1px 10px rgba(0,0,0,.6); margin-bottom: 8px; }
.cl-count { font-size: 13px; color: rgba(255,255,255,.7); letter-spacing: .15em; }
.cl-done {
  position: absolute; bottom: 16dvh; left: 0; right: 0;
  text-align: center;
  font-size: 15px;
  color: #ffeccb;
  opacity: 0;
  transition: opacity .5s ease;
  pointer-events: none;
}
.cl-done.visible { opacity: 1; animation: hintBlink 1.6s ease-in-out infinite; }
.cl-hint { font-size: 12px; color: rgba(255,235,190,.65); margin-top: 8px; letter-spacing: .1em; }
.cl-slots {
  position: absolute; bottom: 8dvh; left: 0; right: 0;
  display: flex; justify-content: center; gap: 10px;
  pointer-events: none;
}
.cl-slot {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px dashed rgba(255,230,175,.4);
  background: rgba(0,0,0,.25) center/78% no-repeat;
  transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.cl-slot.filled {
  border: 2px solid rgba(255,225,160,.9);
  box-shadow: 0 0 16px rgba(255,210,130,.55);
  transform: scale(1.08);
}

/* 리듬 노트: 아이템 일러스트 + 조여드는 링 */
.note-item {
  position: absolute;
  width: 92px; height: 92px;
  margin: -46px 0 0 -46px;
  cursor: pointer;
  touch-action: manipulation;
}
.ni-img {
  position: absolute; inset: 8px;
  width: calc(100% - 16px); height: calc(100% - 16px);
  object-fit: contain;
  filter: drop-shadow(0 0 14px rgba(255,215,140,.65));
  animation: niPulse 0.9s ease-in-out infinite;
  pointer-events: none;
}
.ni-ring {
  position: absolute; inset: 0;
  border: 3px solid rgba(255,228,165,.95);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(255,205,125,.5), inset 0 0 10px rgba(255,205,125,.3);
  animation: ringShrink 1.75s linear forwards;
  pointer-events: none;
}
@keyframes ringShrink {
  from { transform: scale(2.6); opacity: .45; }
  85%  { opacity: 1; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes niPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}
.note-item.caught .ni-img {
  animation: none;
  transition: transform .5s ease, opacity .5s ease;
  transform: scale(1.55);
  opacity: 0;
}
.note-item.caught .ni-ring {
  animation: none;
  transition: transform .3s ease, opacity .3s ease;
  transform: scale(1.3);
  opacity: 0;
}
.note-item.missed {
  transition: transform .4s ease, opacity .4s ease;
  transform: translateY(14px);
  opacity: 0;
}
.grade-pop {
  position: absolute;
  transform: translate(-50%, -130%);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .06em;
  color: #cfe8ff;
  text-shadow: 0 1px 8px rgba(0,0,0,.7);
  animation: gradeRise .9s ease-out forwards;
  pointer-events: none;
}
.grade-pop.perfect {
  font-size: 20px;
  color: #ffe08a;
  text-shadow: 0 0 16px rgba(255,190,90,.9), 0 1px 8px rgba(0,0,0,.7);
}
@keyframes gradeRise {
  from { opacity: 0; margin-top: 6px; }
  20%  { opacity: 1; }
  to   { opacity: 0; margin-top: -26px; }
}

/* ── 이벤트 CG (특별 삽화) ── */
#cg-layer {
  position: absolute; inset: 0;
  background: center/cover no-repeat;
  opacity: 0;
  transition: opacity 1.1s ease;
  pointer-events: none;
}
#cg-layer.visible { opacity: 1; }

/* 지우 발광 스프라이트 — 실루엣 밖 글로우는 CSS로 */
.char[data-sprite="glow_full"] img {
  filter: drop-shadow(0 0 22px rgba(160,255,232,.6)) drop-shadow(0 0 60px rgba(160,255,232,.35));
}

/* ── 가사 연출 ── */
#text-box.lyric {
  text-align: center;
  font-style: italic;
  font-size: 17.5px;
  color: #ffe9c9;
  text-shadow: 0 0 14px rgba(255,190,110,.35);
}

/* ── 영상 ── */
#video-layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
  background: #000;
}
#video-layer.visible { display: block; }
#video-placeholder {
  position: absolute; inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 45%, #1c1026, #070409 75%);
}
#video-placeholder.visible { display: flex; }
.vp-card { text-align: center; padding: 0 10%; }
.vp-icon {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  border: 2px solid rgba(255,255,255,.45);
  border-radius: 50%;
  display: flex; justify-content: center; align-items: center;
  font-size: 20px; color: rgba(255,255,255,.8);
}
.vp-caption { font-size: 17px; font-weight: 600; margin-bottom: 10px; }
.vp-note { font-size: 12.5px; color: rgba(255,255,255,.5); }

/* ── 타이틀 카드 (챕터 제목 연출) ── */
#title-card {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  text-align: center;
  background: rgba(4,2,6,.88);
  opacity: 0;
  transition: opacity 1.4s ease;
}
#title-card.visible { display: flex; }
#title-card.shown { opacity: 1; }
.tc-main {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .12em;
  line-height: 1.5;
  background: linear-gradient(180deg, #ffe8c8, #f5a95c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tc-sub { font-size: 13.5px; color: #b8aca2; letter-spacing: .08em; }

/* ── 엔드 카드 ── */
#end-card {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 30px;
  background: rgba(4,2,6,.92);
  text-align: center;
  padding: 0 10%;
}
#end-card.visible { display: flex; }
.ec-text { font-size: 16px; line-height: 2; color: #ded5ca; word-break: keep-all; }
#ec-home, #ec-cookie {
  padding: 13px 34px;
  font-size: 15px;
  font-family: inherit;
  color: #ffe6c4;
  background: transparent;
  border: 1px solid rgba(255,200,140,.55);
  border-radius: 999px;
  cursor: pointer;
}
#ec-home:active, #ec-cookie:active { background: rgba(255,200,140,.12); }
#ec-cookie {
  color: #fff3dd;
  background: rgba(255,200,140,.14);
  box-shadow: 0 0 18px rgba(255,190,110,.25);
}

/* ── 빛 트랜지션 (게임 진입) ── */
#light-wipe {
  position: absolute; inset: 0;
  z-index: 40;
  pointer-events: none;
  background: radial-gradient(circle at 50% 55%, rgba(255,248,228,1) 0%, rgba(255,224,168,.98) 45%, rgba(255,192,124,.94) 100%);
  opacity: 0;
}
#light-wipe.in { animation: lightIn .85s ease-in forwards; }
#light-wipe.out { animation: lightOut 1.2s ease-out forwards; }
@keyframes lightIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes lightOut { from { opacity: 1; } to { opacity: 0; } }

/* ── 타이틀 화면 ── */
#title-screen {
  position: absolute; inset: 0;
  display: none;
  z-index: 20;
}
#title-screen.visible { display: block; }
.ts-sky {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 66%, rgba(255,205,130,.85), rgba(255,132,72,.4) 26%, transparent 48%),
    linear-gradient(180deg, #170f2e 0%, #4b1f44 30%, #a33a48 55%, #e07a45 74%, #f4b063 84%, #241521 84.5%, #120a12 100%);
  animation: skyBreath 9s ease-in-out infinite, skyDrift 26s ease-in-out infinite alternate;
}
@keyframes skyBreath {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}
@keyframes skyDrift {
  from { transform: scale(1) translateY(0); }
  to { transform: scale(1.07) translateY(-1.2%); }
}

/* ── 회차 복선: 하늘이 조금씩 식는다 ── */
.ts-sky::after {
  content: '';
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#title-screen.ng1 .ts-sky::after {
  opacity: 1;
  background: linear-gradient(180deg, rgba(38,78,108,.30), rgba(32,92,92,.20) 60%, transparent 90%);
}
#title-screen.ng2 .ts-sky::after {
  opacity: 1;
  background: linear-gradient(180deg, rgba(30,95,125,.48), rgba(38,120,110,.32) 55%, rgba(210,245,255,.07));
}
#title-screen.ng2 .ts-title {
  animation: titleGlowTeal 5.5s ease-in-out infinite;
}
@keyframes titleGlowTeal {
  0%, 100% { text-shadow: 0 2px 24px rgba(10,40,50,.65), 0 0 24px rgba(140,235,215,.18); }
  50% { text-shadow: 0 2px 24px rgba(10,40,50,.65), 0 0 44px rgba(150,245,225,.6); }
}

/* 회차 복선: 이따금 떨어지는 별똥별 */
.ts-star {
  position: absolute;
  top: 10%; left: -12%;
  width: 90px; height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,236,180,.95));
  box-shadow: 0 0 10px rgba(255,225,160,.8);
  opacity: 0;
  transform: rotate(16deg);
  pointer-events: none;
}
#title-screen.ng1 .ts-star,
#title-screen.ng2 .ts-star {
  animation: starStreak 8s ease-in infinite 2.5s;
}
@keyframes starStreak {
  0%, 86% { opacity: 0; transform: translate(0, 0) rotate(16deg); }
  88% { opacity: 1; }
  100% { opacity: 0; transform: translate(115vw, 38vh) rotate(16deg); }
}

/* 피어오르는 빛 입자 */
.ts-motes {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.mote {
  position: absolute;
  bottom: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,238,190,.95) 0%, rgba(255,190,110,.55) 55%, transparent 78%);
  box-shadow: 0 0 9px 2px rgba(255,205,130,.5);
  opacity: 0;
  animation: moteRise 12s linear infinite, moteFlicker 3s ease-in-out infinite;
  will-change: transform, opacity;
}
.mote-teal {
  background: radial-gradient(circle, rgba(215,255,242,.95) 0%, rgba(140,235,210,.5) 55%, transparent 78%);
  box-shadow: 0 0 9px 2px rgba(150,240,215,.45);
}
@keyframes moteRise {
  0%   { transform: translate(0, 0) scale(.8); opacity: 0; }
  8%   { opacity: .95; }
  50%  { transform: translate(var(--drift, 0px), -46dvh) scale(1.06); opacity: .8; }
  90%  { opacity: .45; }
  100% { transform: translate(calc(var(--drift, 0px) * -0.6), -94dvh) scale(.65); opacity: 0; }
}
@keyframes moteFlicker {
  0%, 100% { filter: brightness(.9); }
  50% { filter: brightness(1.7); }
}
.ts-body {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-bottom: 6dvh;
}
.ts-sub {
  font-size: 13px;
  letter-spacing: .3em;
  color: rgba(255,240,220,.85);
  margin-bottom: 14px;
  text-shadow: 0 1px 8px rgba(0,0,0,.5);
}
.ts-title {
  font-size: 52px;
  font-weight: 900;
  line-height: 1.28;
  letter-spacing: .1em;
  text-align: center;
  color: #fff6e8;
  text-shadow: 0 2px 24px rgba(60,10,20,.65);
  margin-bottom: 7dvh;
  animation: titleGlow 5.5s ease-in-out infinite;
}
@keyframes titleGlow {
  0%, 100% { text-shadow: 0 2px 24px rgba(60,10,20,.65), 0 0 24px rgba(255,190,110,.15); }
  50% { text-shadow: 0 2px 24px rgba(60,10,20,.65), 0 0 42px rgba(255,208,132,.55); }
}
.ts-buttons { display: flex; flex-direction: column; gap: 13px; width: 62%; max-width: 260px; }
.ts-buttons button {
  padding: 14px 0;
  font-size: 15.5px;
  font-family: inherit;
  font-weight: 600;
  color: #fff2df;
  background: rgba(20,10,18,.5);
  border: 1px solid rgba(255,225,180,.5);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.ts-buttons button:active { background: rgba(255,220,170,.18); }
.ts-buttons button:disabled { opacity: .35; cursor: default; }
