* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #120f1c; overflow: hidden; }
body {
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #2b2433;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }

/* ---------- 무대 ---------- */
#stage { position: absolute; inset: 0; overflow: hidden; }
#bg { position: absolute; inset: 0; background: #000; }

/* 배경들 (그림 대신 그라데이션. 나중에 이미지로 바꾸면 됨) */
.bg-black { background: #0b0a10 !important; }
.bg-campus {
  background:
    linear-gradient(to top, #9fd59a 0 14%, transparent 14%),
    linear-gradient(to top, transparent 14%, #e9dccb 14% 40%, transparent 40%),
    repeating-linear-gradient(to right, transparent 0 9%, rgba(255,255,255,.55) 9% 10.5%, transparent 10.5% 18%),
    radial-gradient(circle at 80% 18%, #fff7d6 0 6%, transparent 7%),
    linear-gradient(#a9d8f5, #e6f4ff 70%) !important;
}
.bg-clubroom {
  background:
    linear-gradient(to top, #6b4b3a 0 18%, transparent 18%),
    linear-gradient(105deg, transparent 8%, #e8b04a 8% 18%, transparent 18%),
    linear-gradient(80deg, transparent 72%, #4f7fb8 72% 82%, transparent 82%),
    linear-gradient(95deg, transparent 40%, rgba(255,255,255,.08) 40% 60%, transparent 60%),
    radial-gradient(circle at 50% 0%, #ffe7b3 0 18%, transparent 50%),
    linear-gradient(#a7765a, #7a5340) !important;
}
.bg-clubroom_night {
  background:
    linear-gradient(to top, #3a2a22 0 18%, transparent 18%),
    linear-gradient(105deg, transparent 8%, #8a6a32 8% 18%, transparent 18%),
    linear-gradient(80deg, transparent 72%, #2f4b6e 72% 82%, transparent 82%),
    radial-gradient(circle at 50% 0%, #ffd27a 0 10%, transparent 40%),
    linear-gradient(#4d3628, #2e2019) !important;
}
.bg-hallway {
  background:
    linear-gradient(to top, #3d4352 0 16%, transparent 16%),
    repeating-linear-gradient(to right, transparent 0 22%, rgba(255,255,255,.07) 22% 24%),
    radial-gradient(ellipse at 50% 0%, #dfe9ff 0 8%, transparent 35%),
    linear-gradient(#5d6577, #383e4c) !important;
}
.bg-night {
  background:
    linear-gradient(to top, #2a2d3f 0 12%, transparent 12%),
    radial-gradient(circle at 22% 38%, rgba(255,214,140,.55) 0 3%, rgba(255,214,140,.15) 10%, transparent 22%),
    linear-gradient(to right, transparent 21.6%, #1d1f2b 21.6% 22.4%, transparent 22.4%),
    linear-gradient(to top, transparent 12%, #232638 12% 46%, transparent 46%),
    radial-gradient(circle at 75% 20%, #fff 0 .25%, transparent .4%),
    radial-gradient(circle at 40% 12%, #fff 0 .2%, transparent .35%),
    radial-gradient(circle at 88% 30%, #fff 0 .2%, transparent .35%),
    linear-gradient(#1c2244, #3b3f6b) !important;
}
.bg-busstop {
  background:
    linear-gradient(to top, #2b2b38 0 12%, transparent 12%),
    linear-gradient(to right, transparent 60%, rgba(160,200,255,.25) 60% 92%, transparent 92%),
    linear-gradient(to top, transparent 12%, transparent 12% 52%, transparent 52%),
    radial-gradient(circle at 76% 40%, rgba(200,225,255,.35) 0 8%, transparent 30%),
    radial-gradient(circle at 20% 15%, #fff 0 .25%, transparent .4%),
    radial-gradient(circle at 50% 25%, #fff 0 .2%, transparent .35%),
    linear-gradient(#232246, #4a3f6e) !important;
}

.bg-stage {
  background:
    linear-gradient(to top, #1a1424 0 20%, transparent 20%),
    conic-gradient(from 160deg at 25% -5%, transparent 0deg, rgba(255,220,240,.45) 8deg, transparent 18deg),
    conic-gradient(from 182deg at 75% -5%, transparent 0deg, rgba(200,220,255,.45) 8deg, transparent 18deg),
    conic-gradient(from 172deg at 50% -5%, transparent 0deg, rgba(255,240,200,.35) 6deg, transparent 14deg),
    radial-gradient(ellipse at 50% 85%, rgba(255,122,162,.35), transparent 50%),
    linear-gradient(#0e0a18, #2a1838) !important;
}

#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
#fade.on { animation: fade .7s ease; }
@keyframes fade { 0% { opacity: 1; } 100% { opacity: 0; } }

#place {
  position: absolute; top: 56px; left: 14px;
  background: rgba(20,16,30,.65); color: #fff;
  padding: 6px 14px; border-radius: 999px; font-size: 13px;
  opacity: 0; transform: translateY(-6px); transition: .4s; pointer-events: none;
}
#place.show { opacity: 1; transform: none; }

/* ---------- 캐릭터 ---------- */
#chars { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; pointer-events: none; }
.char {
  position: absolute; bottom: 0;
  height: min(80%, 92vw);
  aspect-ratio: 2 / 3;
  transform: translateX(-50%);
  transition: left .45s ease, filter .3s, opacity .35s;
  animation: charIn .4s ease;
}
.char svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 6px 14px rgba(0,0,0,.25)); }
.char.dim { filter: brightness(.62) saturate(.8); }
.char[data-at="left"] { left: 20%; }
.char[data-at="center"] { left: 50%; }
.char[data-at="right"] { left: 80%; }
@keyframes charIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.char.talk svg { animation: bob .35s ease; }
@keyframes bob { 50% { transform: translateY(-5px); } }

.emote {
  position: absolute; top: 4%; left: 64%;
  font-size: clamp(26px, 6vw, 44px);
  animation: pop 1.3s ease forwards;
}
@keyframes pop {
  0% { transform: scale(0); opacity: 0; }
  20% { transform: scale(1.25); opacity: 1; }
  35% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

@media (orientation: portrait) {
  #chars { bottom: 22vh; height: 60vh; }
  .char { height: min(100%, 64vw); }
  .char[data-at="left"] { left: 21%; }
  .char[data-at="right"] { left: 79%; }
}

/* ---------- 상단 메뉴 ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) 10px 10px;
  z-index: 5;
}
#topbar button {
  background: rgba(255,255,255,.82); border: 0; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: #4a3d57; font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
#topbar button.on { background: #ff7aa2; color: #fff; }

/* ---------- 대화창 ---------- */
#box {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(940px, calc(100% - 20px));
  min-height: 150px;
  background: rgba(255,250,252,.93);
  border: 2px solid #ffd1df;
  border-radius: 18px;
  padding: 26px 22px 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 4;
}
#nametag {
  position: absolute; top: -16px; left: 18px;
  background: #ff7aa2; color: #fff; font-weight: 700;
  padding: 6px 16px; border-radius: 999px; font-size: 15px;
  box-shadow: 0 3px 8px rgba(0,0,0,.18);
}
#nametag:empty { display: none; }
#text { font-size: clamp(15px, 2.1vw, 19px); line-height: 1.7; white-space: pre-wrap; word-break: keep-all; }
#text.thought { color: #6b5f7a; font-style: italic; }
#text.narr { color: #3d3448; }
#next {
  position: absolute; right: 18px; bottom: 8px; color: #ff7aa2; font-size: 13px;
  opacity: 0; animation: blink 1s infinite;
}
#next.show { opacity: 1; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- 선택지 / 입력 ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(15,10,25,.35);
  padding: 20px;
}
#choices button {
  width: min(560px, 100%);
  padding: 15px 18px; border-radius: 14px;
  border: 2px solid #ffd1df; background: rgba(255,255,255,.95);
  font-size: 16px; color: #3a2e45; font-weight: 600;
  box-shadow: 0 6px 16px rgba(0,0,0,.2);
  animation: choiceIn .3s ease backwards;
  transition: transform .15s, background .15s;
}
#choices button:hover, #choices button:active { background: #ffe6ef; transform: scale(1.02); }
@keyframes choiceIn { from { opacity: 0; transform: translateY(10px); } }

.panel {
  background: #fffafc; border-radius: 18px; padding: 22px;
  width: min(420px, 100%);
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  text-align: center;
}
#inputBox .panel p { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
#nameInput {
  width: 100%; font: inherit; font-size: 18px; text-align: center;
  padding: 12px; border-radius: 12px; border: 2px solid #ffd1df; margin-bottom: 14px;
  user-select: text;
}
button.primary, .panel button {
  border: 0; border-radius: 12px; padding: 12px 22px; font-size: 15px; font-weight: 700;
  background: #efe7f3; color: #4a3d57;
}
button.primary { background: #ff7aa2; color: #fff; }

/* ---------- 토스트 ---------- */
#toasts { position: absolute; top: 56px; right: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 9; pointer-events: none; align-items: flex-end; }
.toast {
  background: rgba(255,255,255,.95); color: #d94d7a; font-weight: 700; font-size: 14px;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: toast 2.4s ease forwards;
}
.toast.guard { color: #5d6bb0; }
@keyframes toast { 0% { opacity: 0; transform: translateX(20px); } 12%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- 타이틀/엔딩 ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 110%, #ff8fb1 0%, #6b4a9b 35%, #1b1534 75%);
  color: #fff; text-align: center; padding: 24px; overflow-y: auto;
}
.stars {
  position: absolute; inset: 0; pointer-events: none; opacity: .8;
  background-image:
    radial-gradient(circle at 10% 20%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 30% 70%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 70% 15%, #fff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 85% 55%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 55% 35%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 20% 45%, #fff 0 1.5px, transparent 2.5px);
  animation: twinkle 4s infinite alternate;
}
@keyframes twinkle { to { opacity: .35; } }
.title-inner, .end-inner { position: relative; width: min(460px, 100%); }
.screen h1 { font-size: clamp(40px, 10vw, 68px); font-weight: 800; letter-spacing: -1px; text-shadow: 0 4px 24px rgba(255,122,162,.7); margin: 6px 0; }
.screen h2 { font-size: clamp(22px, 5vw, 30px); margin: 8px 0 18px; }
.screen .sub { font-size: 15px; opacity: .85; letter-spacing: 2px; }
.screen .tiny { font-size: 12px; opacity: .6; margin-top: 8px; }
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 30px; }
.menu button { border: 0; border-radius: 14px; padding: 14px; font-size: 16px; font-weight: 700; background: rgba(255,255,255,.9); color: #4a3d57; }
.menu button.primary { background: #ff7aa2; color: #fff; }
.menu button:disabled { opacity: .4; }

#endStats { background: rgba(255,255,255,.12); border-radius: 16px; padding: 14px 16px; text-align: left; }
#endHint { margin-top: 16px; font-size: 15px; line-height: 1.6; background: rgba(0,0,0,.25); padding: 12px 14px; border-radius: 12px; word-break: keep-all; }

/* ---------- 모달 ---------- */
#modal { position: absolute; inset: 0; z-index: 30; background: rgba(10,6,20,.55); display: flex; align-items: center; justify-content: center; padding: 18px; }
#modal .panel { width: min(520px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
#modal h2 { font-size: 19px; margin-bottom: 12px; color: #4a3d57; }
#modalBody { overflow-y: auto; text-align: left; margin-bottom: 14px; flex: 1; }
.log-line { padding: 8px 2px; border-bottom: 1px solid #f3e4ea; font-size: 14px; line-height: 1.6; word-break: keep-all; }
.log-line b { color: #d94d7a; margin-right: 6px; }
.log-line.pick { color: #7a6bb0; }

.stat { margin: 10px 0; }
.stat .row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 15px; }
.stat .role { font-size: 12px; font-weight: 500; opacity: .7; }
.bar { height: 10px; border-radius: 99px; background: rgba(0,0,0,.1); overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #ffb3c9, #ff5f8f); transition: width .5s; }
.locks { font-size: 13px; margin-top: 4px; }
#endStats .stat .row { color: #fff; }
#endStats .bar { background: rgba(255,255,255,.2); }

.slot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px; border-radius: 12px; background: #f8eef3; margin-bottom: 8px; cursor: pointer;
}
.slot:hover { background: #ffe3ee; }
.slot .info { font-size: 13px; color: #6b5f7a; }
.slot .info b { display: block; font-size: 15px; color: #3a2e45; }
.slot.empty { opacity: .55; }

/* ---------- 사진 캐릭터 ---------- */
.char.photo { aspect-ratio: 4 / 5; height: min(60%, 34vw); bottom: calc(150px + 4%); }
.char.photo .frame {
  width: 100%; height: 100%;
  border-radius: 46% 46% 18px 18px / 30% 30% 18px 18px;
  overflow: hidden;
  border: 5px solid #fff;
  outline: 3px solid var(--c, #ff7aa2);
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  background: #fff;
}
.char.photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.char.photo.talk .frame { animation: bob .35s ease; }
.char.photo .emote { top: -6%; left: 72%; }
@media (orientation: portrait) {
  .char.photo { height: min(80%, 44vw); bottom: 2%; }
  .char.photo[data-at="center"] { height: min(92%, 54vw); z-index: 1; }
}

/* ---------- 싸이월드 감성 타이틀 ---------- */
.cy-title, .cy-sub, .cy-deco, .cy-count { font-family: "Galmuri11", "Galmuri14", "DungGeunMo", monospace; }
.cy-title { text-shadow: none; position: relative; display: inline-block; margin: 10px 0 2px; padding: 0 28px; }
.cy-text {
  position: relative; display: inline-block;
  font-size: clamp(54px, 15vw, 92px); font-weight: 700; letter-spacing: 2px; line-height: 1.15;
  background: linear-gradient(90deg, #ff9ad5, #ffffff, #9ad8ff, #fff59a, #ff9ad5);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: glitter 3s linear infinite;
  filter: drop-shadow(2px 0 0 #6b2d7a) drop-shadow(-2px 0 0 #6b2d7a) drop-shadow(0 2px 0 #6b2d7a) drop-shadow(0 -2px 0 #6b2d7a) drop-shadow(4px 4px 0 #ff5fa8);
}
@keyframes glitter { to { background-position: 300% 0; } }
.spark { position: absolute; color: #fff7a8; font-size: 22px; text-shadow: 0 0 8px #fff; animation: sparkle 1.4s steps(2) infinite; }
.spark.s1 { top: -6px; left: 0; }
.spark.s2 { top: 4px; right: 0; font-size: 18px; color: #ffb3e0; animation-delay: .35s; }
.spark.s3 { bottom: 0; left: 8px; font-size: 16px; color: #b8e6ff; animation-delay: .7s; }
.spark.s4 { bottom: -4px; right: 10px; animation-delay: 1.05s; }
@keyframes sparkle { 0% { opacity: 1; transform: scale(1); } 50% { opacity: .15; transform: scale(.6); } }
.cy-sub { font-size: 14px; color: #ffe1f1; letter-spacing: 1px; }
.cy-deco { font-size: 13px; color: #fff3a8; margin-top: 4px; animation: sparkle 2s steps(2) infinite; }
.cy-count {
  display: inline-block; margin-top: 12px; font-size: 11px; color: #4a3d57;
  background: #fff; border: 1px solid #ffb3d1; border-radius: 4px; padding: 3px 8px;
}
.cy-count b { color: #ff3b8d; }
