/* 앱 셸 — 화면 전환 무대, 마스코트 레이어, 공용 컴포넌트.
   화면 고유 스타일은 css/screens.css 로 분리한다. */

*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--c-cream);
  color: var(--c-ink);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── 무대 ─────────────────────────────────────────────
   화면(section.screen)은 겹쳐 쌓이고, .is-active 만 보인다.
   마스코트는 화면 사이에서 재생성되지 않도록 별도 고정 레이어에 산다. */

#stage {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp-safe-t) var(--sp-edge) var(--sp-safe-b);
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 0, 0);
  transition: opacity var(--d-normal) var(--e-out), visibility 0s linear var(--d-normal);
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--d-normal) var(--e-out), visibility 0s;
}

/* ── 마스코트 레이어 ───────────────────────────────────
   iframe 은 원본 mascot.js(WebGL)를 그대로 돌린다. 화면이 위치·크기만
   커스텀 프로퍼티로 지시하고, 실제 이동은 transform 으로만 한다. */

#mascot-layer {
  position: fixed;
  left: 50%;
  top: 50%;
  width: var(--mascot-size, 62vw);
  aspect-ratio: 1;
  border: 0;
  z-index: 2;
  pointer-events: none; /* 온보딩 동안 잠금 — 홈에서 해제 */
  opacity: 0;
  transform: translate3d(-50%, -50%, 0) translate3d(var(--mascot-x, 0), var(--mascot-y, 0), 0)
    scale(var(--mascot-scale, 1));
  transition: transform var(--d-slow) var(--e-out), opacity var(--d-normal) var(--e-out),
    width var(--d-slow) var(--e-out);
}

#mascot-layer.is-visible { opacity: 1; }
#mascot-layer.is-interactive { pointer-events: auto; }
/* 옷장처럼 시트(z-index 10) 위에 캐릭터가 보여야 하는 화면 */
#mascot-layer.is-above-sheet { z-index: 11; }

/* 이름 확정 후 "쇼쇽" 하고 뒤로 빠지는 퇴장 */
#mascot-layer.is-receding {
  transform: translate3d(-50%, -50%, 0) translate3d(var(--mascot-x, 0), 12vh, 0) scale(0.18);
  opacity: 0;
  transition: transform 560ms cubic-bezier(0.55, -0.2, 0.75, 0.3), opacity 400ms ease-in 140ms;
}

/* ── 공용 컴포넌트 ─────────────────────────────────── */

/* 말풍선 — 온보딩 대사의 유일한 그릇. 꼬리 없이 둥근 알약형(시안 그대로). */
.bubble {
  align-self: center;
  max-width: 19rem;
  margin: 0;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-bubble);
  background: var(--c-card);
  box-shadow: var(--sh-bubble);
  font-size: var(--t-bubble);
  font-weight: 700;
  line-height: 1.42;
  text-align: center;
  animation: bubble-in var(--d-slow) var(--e-back) both;
}

.bubble--user {
  align-self: stretch;
  max-width: none;
  border-radius: var(--r-bubble) var(--r-bubble) 6px var(--r-bubble);
  background: #e9e3d5;
  box-shadow: none;
  font-weight: 600;
  text-align: left;
}

.bubble--user .kw { color: var(--c-primary); }

@keyframes bubble-in {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* CTA — 화면당 하나. 바닥에 고정되는 굵은 알약. */
.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 3.375rem;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-size: 1.0625rem;
  font-weight: 700;
  box-shadow: var(--sh-cta);
  transition: transform var(--d-fast) var(--e-out), background-color var(--d-fast) linear,
    box-shadow var(--d-fast) var(--e-out);
}

.cta:active {
  transform: scale(0.972);
  background: var(--c-primary-press);
  box-shadow: 0 4px 12px rgba(96, 64, 236, 0.24);
}

.cta:focus-visible {
  outline: 3px solid rgba(96, 64, 236, 0.35);
  outline-offset: 3px;
}

.cta[disabled] {
  background: #d8d4cb;
  color: #fbfaf7;
  box-shadow: none;
  pointer-events: none;
}

.cta--quiet {
  background: #8b8479;
  box-shadow: none;
}

.cta--ghost {
  background: rgba(96, 64, 236, 0.08);
  color: var(--c-primary);
  box-shadow: none;
}

.cta .ico { width: 1.125rem; height: 1.125rem; }

/* 텍스트 링크 — CTA 아래 보조 행동 */
.linkline {
  margin: var(--sp-3) 0 0;
  font-size: var(--t-body-sm);
  color: var(--c-ink-mute);
  text-align: center;
}

.linkline button {
  color: var(--c-primary);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 화면 바닥 도크 — CTA 와 링크를 담는다 */
.dock {
  margin-top: auto;
  padding-top: var(--sp-4);
}

/* 카드 — 약관·권한 화면의 흰 판 */
.card {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: var(--sp-6) var(--sp-5) var(--sp-4);
  border-radius: var(--r-card);
  background: var(--c-card);
  box-shadow: var(--sh-card);
}

.card h1 {
  margin: 0 0 var(--sp-3);
  font-size: var(--t-title);
  font-weight: 800;
  line-height: 1.32;
}

.card .lead {
  margin: 0 0 var(--sp-6);
  color: var(--c-ink-mute);
  font-size: var(--t-body);
  line-height: 1.55;
}

/* 언덕 — 하단을 덮는 도트 텍스처 지면. 화면에 무게중심을 준다. */
.hill {
  position: absolute;
  right: -12%;
  bottom: 0;
  left: -12%;
  height: 34%;
  border-radius: 52% 52% 0 0 / 34% 34% 0 0;
  background-color: var(--c-hill);
  background-image: radial-gradient(var(--c-hill-dot) 1.4px, transparent 1.5px);
  background-size: 14px 14px;
  z-index: 1;
  pointer-events: none;
}

/* 접근성: 화면 낭독용 숨김 텍스트 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* 토스트 — 미연결 기능 안내 등 짧은 피드백 */
.toastline {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-safe-b) + 5.5rem);
  z-index: 40;
  max-width: min(84vw, 22rem);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: rgba(47, 43, 56, 0.92);
  color: #fff;
  font-size: var(--t-body-sm);
  text-align: center;
  opacity: 0;
  transform: translate3d(-50%, 8px, 0);
  transition: opacity var(--d-normal) var(--e-out), transform var(--d-normal) var(--e-out);
  pointer-events: none;
}

.toastline.is-on {
  opacity: 1;
  transform: translate3d(-50%, 0, 0);
}
