/* 창빙시 대화 무대 v3 — 상위 캐릭터챗 대화 화면 형식(인물 그림 전체 배경 + 아래부터 쌓이는 메시지)을 따릅니다. */
:root {
  --ink: #0b0912;
  --ink-2: #14111d;
  --glass: rgba(18, 15, 27, 0.62);
  --glass-strong: rgba(14, 12, 22, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #f7f4fb;
  --text-2: #c9c1d6;          /* 지문 */
  --text-3: #9b93a8;
  --gold: #f2b84f;            /* 별빛 강조색: 사용자 말풍선·주요 버튼 */
  --gold-ink: #241706;
  --gold-soft: rgba(242, 184, 79, 0.18);
  --danger: #ef4b5f;
  --radius: 20px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --serif: "AppleMyungjo", "Nanum Myeongjo", "Noto Serif KR", serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; overscroll-behavior: none; text-rendering: optimizeLegibility; word-break: keep-all; overflow-wrap: anywhere; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ── 무대 ─────────────────────────────── */
#stage { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; z-index: 0; opacity: 0; transition: opacity 0.9s var(--ease-out); }
body.stage-ready #stage { opacity: 1; }
#stage-still { position: fixed; inset: 0; z-index: 0; background-size: cover; background-position: 50% 20%; display: none; }
body.no-webgl #stage-still { display: block; }
.scrim { position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0; transition: opacity 0.6s var(--ease-out);
  background: linear-gradient(to bottom, rgba(8, 6, 14, 0.5) 0, rgba(8, 6, 14, 0) 15%, rgba(8, 6, 14, 0) 40%, rgba(8, 6, 14, 0.55) 62%, rgba(8, 6, 14, 0.9) 100%); }
body.is-chat .scrim, body.is-profile .scrim, body.is-call .scrim { opacity: 1; }
body.immersive .scrim { opacity: 0.25; }

/* ── 홈 ───────────────────────────────── */
#home { position: fixed; inset: 0; z-index: 4; overflow-y: auto; background: radial-gradient(120% 70% at 50% -10%, #2a2140 0%, var(--ink) 55%); padding: calc(var(--safe-t) + 14px) 16px calc(var(--safe-b) + 28px); transition: opacity 0.45s var(--ease-out), transform 0.45s var(--ease-out); }
body:not(.is-home) #home { opacity: 0; transform: scale(0.985); pointer-events: none; }
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1080px; margin: 0 auto; }
.logo { margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.logo::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 3px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 12px var(--gold); vertical-align: 0.5em; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; font-size: 15px; font-weight: 600; color: var(--text-3); }
.tab.is-on { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.tab:disabled { cursor: default; }
.home-note { max-width: 1080px; margin: 14px auto 18px; color: var(--text-3); font-size: 13px; }
.cards { list-style: none; margin: 0 auto; padding: 0; max-width: 1080px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; } }
.card { position: relative; aspect-ratio: 2 / 3; border-radius: 18px; overflow: hidden; background: var(--ink-2); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); transform: translateZ(0); }
.card > button { all: unset; position: absolute; inset: 0; cursor: pointer; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; transition: transform 0.8s var(--ease-out); }
.card:hover img { transform: scale(1.04); }
.card .meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 48px 12px 12px; background: linear-gradient(to top, rgba(8, 6, 14, 0.95), rgba(8, 6, 14, 0)); }
.card h3 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.card p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .by { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--text-3); }
.card .by b { color: var(--gold); font-weight: 600; }
.card .badge { position: absolute; top: 10px; left: 10px; padding: 4px 8px; border-radius: 8px; font-size: 11px; font-weight: 700; background: rgba(8, 6, 14, 0.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.card.make { display: grid; place-items: center; text-align: center; background: transparent; border: 1.5px dashed var(--line-2); box-shadow: none; color: var(--text-3); font-size: 14px; }
.card.make strong { display: block; color: var(--text); font-size: 28px; font-weight: 300; margin-bottom: 4px; }
.home-foot { max-width: 1080px; margin: 28px auto 0; font-size: 13px; }
.home-foot a { color: var(--text-3); }

/* ── 대화 공통 ─────────────────────────── */
#chat { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
body.is-home #chat { visibility: hidden; }
#chat > * { pointer-events: auto; }
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: calc(var(--safe-t) + 8px) 8px 8px; transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out); }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--text); transition: background 0.2s; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.who-face { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; object-position: 50% 8%; background: var(--ink-2); box-shadow: 0 0 0 1.5px rgba(242, 184, 79, 0.85), 0 2px 10px rgba(0, 0, 0, 0.4); }
.who-text { display: flex; flex-direction: column; min-width: 0; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45); }
.who-text strong { font-size: 16px; font-weight: 700; line-height: 1.2; }
.who-text span { font-size: 12px; color: rgba(255, 255, 255, 0.72); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 2px; }
.menu { position: absolute; top: calc(var(--safe-t) + 58px); right: 10px; width: min(280px, calc(100vw - 20px)); padding: 6px; border-radius: 16px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45); z-index: 5; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px; border-radius: 10px; font-size: 15px; }
.menu-row:hover { background: rgba(255, 255, 255, 0.06); }
.menu-row input { width: 18px; height: 18px; accent-color: var(--gold); }
.menu-row.as-btn { width: 100%; border: 0; background: transparent; text-align: left; color: var(--text-2); }

/* 프로필 시트(대화 시작 전) */
.profile { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 20px calc(var(--safe-b) + 22px); transition: opacity 0.5s var(--ease-out), transform 0.6s var(--ease-out); }
body:not(.is-profile) .profile { opacity: 0; transform: translateY(24px); pointer-events: none; }
.profile-kicker { margin: 0 0 6px; font-size: 13px; color: var(--gold); font-weight: 600; letter-spacing: 0.01em; }
.profile-name { margin: 0; font-family: var(--serif); font-size: 40px; line-height: 1.1; font-weight: 700; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5); }
.profile-hook { margin: 10px 0 12px; font-size: 16px; line-height: 1.6; color: var(--text-2); max-width: 34em; }
.profile-tags { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.profile-tags li { padding: 5px 10px; border-radius: 999px; font-size: 13px; color: var(--text-2); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); }
.profile-cta { display: flex; gap: 10px; }
.btn-primary { flex: 1; height: 54px; border: 0; border-radius: 16px; background: var(--gold); color: var(--gold-ink); font-size: 17px; font-weight: 700; box-shadow: 0 8px 26px rgba(242, 184, 79, 0.28); transition: transform 0.2s var(--ease-out), filter 0.2s; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.98); }
.btn-ghost { height: 54px; padding: 0 20px; border-radius: 16px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.06); font-size: 16px; font-weight: 600; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

/* 메시지 기록: 아래에서 위로 쌓이고, 위쪽은 인물이 보이도록 서서히 사라집니다. */
.log { position: absolute; left: 0; right: 0; top: 44dvh; bottom: var(--composer-h, 132px); overflow-y: auto; overscroll-behavior: contain; padding: 40px 14px 10px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 56px); mask-image: linear-gradient(to bottom, transparent 0, #000 56px); transition: opacity 0.4s var(--ease-out); }
.log::-webkit-scrollbar { display: none; }
.log > :first-child { margin-top: auto; }
body.is-profile .log, body.is-profile .composer { opacity: 0; pointer-events: none; }
.msg { max-width: min(88%, 560px); font-size: 16px; line-height: 1.65; animation: msg-in 0.42s var(--ease-out) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
.msg.char { align-self: flex-start; padding: 12px 15px 13px; border-radius: 6px 20px 20px 20px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(16px) saturate(130%); -webkit-backdrop-filter: blur(16px) saturate(130%); }
.msg.char .name { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 700; color: var(--gold); }
.msg.char p { margin: 0; }
.msg.char p + p { margin-top: 6px; }
.msg .narr { color: var(--text-2); }
.msg .line { color: var(--text); font-weight: 500; }
.msg.user { align-self: flex-end; padding: 10px 15px 11px; border-radius: 20px 6px 20px 20px; background: var(--gold); color: var(--gold-ink); font-weight: 500; }
.msg .caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 1px; vertical-align: -0.15em; background: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { align-self: flex-start; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 6px 20px 20px 20px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); font-size: 13px; color: var(--text-2); animation: msg-in 0.3s var(--ease-out) both; }
.typing i { display: inline-flex; gap: 4px; }
.typing i b { width: 6px; height: 6px; border-radius: 50%; background: var(--text-2); animation: dot 1.2s infinite ease-in-out; }
.typing i b:nth-child(2) { animation-delay: 0.15s; }
.typing i b:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.sys { align-self: center; padding: 6px 12px; border-radius: 999px; font-size: 12px; color: var(--text-3); background: rgba(8, 6, 14, 0.45); }

/* 입력 */
.composer { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 6px 12px calc(var(--safe-b) + 8px); transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; max-width: 78vw; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.08); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: msg-in 0.35s var(--ease-out) both; }
.chip:hover { background: rgba(255, 255, 255, 0.14); }
.chip .spark { color: var(--gold); margin-right: 4px; }
.input-row { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px; border-radius: 26px; background: rgba(28, 24, 38, 0.78); border: 1px solid var(--line-2); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%); transition: border-color 0.2s; }
.input-row:focus-within { border-color: rgba(242, 184, 79, 0.6); }
#input { flex: 1; min-height: 38px; max-height: 120px; padding: 8px 0; border: 0; outline: 0; resize: none; background: transparent; font-size: 16px; line-height: 1.4; }
#input::placeholder { color: var(--text-3); }
.send { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--gold); color: var(--gold-ink); transition: transform 0.2s var(--ease-spring), opacity 0.2s; }
.send svg { stroke-width: 2.4; width: 20px; height: 20px; }
.send:disabled { opacity: 0.35; cursor: default; }
.send:not(:disabled):active { transform: scale(0.9); }
.disclaimer { margin: 7px 0 0; text-align: center; font-size: 11.5px; color: rgba(255, 255, 255, 0.5); }

/* 몰입 보기: 인물만 남깁니다. */
.immerse-hint { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 26px); transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px; font-size: 13px; background: rgba(8, 6, 14, 0.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); opacity: 0; pointer-events: none; transition: opacity 0.5s; }
body.immersive .topbar, body.immersive .log, body.immersive .composer, body.immersive .profile { opacity: 0; pointer-events: none; }
body.immersive .topbar { transform: translateY(-10px); }
body.immersive .composer { transform: translateY(14px); }
body.immersive .immerse-hint { opacity: 1; animation: hint-out 0.5s 2.6s forwards; }
@keyframes hint-out { to { opacity: 0; } }

/* ── 데스크톱: 인물은 왼쪽, 대화는 오른쪽 기둥(배경은 화면 가득) ── */
@media (min-width: 960px) and (min-aspect-ratio: 1/1) {
  .scrim { background: linear-gradient(to left, rgba(8, 6, 14, 0.86) 0, rgba(8, 6, 14, 0.66) 24%, rgba(8, 6, 14, 0) 46%), linear-gradient(to bottom, rgba(8, 6, 14, 0.45) 0, rgba(8, 6, 14, 0) 14%); }
  .topbar { padding: 14px 18px; }
  .log, .composer { left: auto; right: 0; width: clamp(400px, 34vw, 520px); }
  .log { top: 76px; padding: 40px 22px 12px; }
  .composer { padding: 6px 22px 18px; }
  .msg { max-width: 100%; font-size: 16.5px; }
  .profile { left: auto; right: 0; width: clamp(400px, 34vw, 520px); padding: 0 32px 40px; }
  .profile-name { font-size: 52px; }
  .menu { right: 18px; top: 66px; }
}

/* ── 통화 ─────────────────────────────── */
#call { position: fixed; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; padding: calc(var(--safe-t) + 22px) 20px calc(var(--safe-b) + 24px); background: linear-gradient(to bottom, rgba(8, 6, 14, 0.55) 0, rgba(8, 6, 14, 0) 22%, rgba(8, 6, 14, 0) 52%, rgba(8, 6, 14, 0.88) 100%); }
#call[hidden] { display: none; }
.call-top { display: flex; flex-direction: column; align-items: center; gap: 4px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5); }
.call-top strong { font-size: 24px; font-weight: 700; }
.call-top span { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.call-caption { margin: auto 0 18px; max-width: 32em; min-height: 3.3em; text-align: center; font-size: 17px; line-height: 1.6; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
#call.no-captions .call-caption { visibility: hidden; }
.call-wave { display: flex; align-items: center; gap: 4px; height: 36px; margin-bottom: 16px; }
.call-wave i { width: 4px; height: 6px; border-radius: 2px; background: var(--gold); transition: height 0.08s linear; }
.call-type { width: min(420px, 100%); margin: 0 0 18px; }
.call-type input { width: 100%; height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--line-2); background: rgba(28, 24, 38, 0.7); outline: 0; font-size: 16px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.call-actions { display: flex; gap: 36px; }
.round { display: flex; flex-direction: column; align-items: center; gap: 8px; border: 0; background: none; font-size: 13px; color: var(--text-2); }
.round svg { width: 64px; height: 64px; padding: 19px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); color: var(--text); }
.round[aria-pressed="false"] svg { background: rgba(255, 255, 255, 0.05); color: var(--text-3); }
.round.end svg { background: var(--danger); stroke-width: 0; fill: #fff; }
.call-note { margin: 18px 0 0; font-size: 11.5px; color: rgba(255, 255, 255, 0.45); text-align: center; max-width: 30em; }
body.is-call #chat { opacity: 0; pointer-events: none; }

/* ── 기타 ─────────────────────────────── */
.toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 70px); transform: translate(-50%, -8px); z-index: 9; padding: 10px 16px; border-radius: 12px; font-size: 14px; background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); opacity: 0; pointer-events: none; transition: opacity 0.3s, transform 0.3s var(--ease-out); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; z-index: 10; background: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
