/* main.css — AI 커스텀 동화 (파스텔 따뜻한 톤, 모바일 우선)
 * index.html 폼과 story.html 프롬프터/플레이어 공용 스타일.
 */

:root {
  --bg: #fff8f1;
  --bg-card: #ffffff;
  --peach: #ffd9b3;
  --peach-deep: #ffb877;
  --pink: #ffc2cf;
  --pink-deep: #ff9bb0;
  --lilac: #d9c8ff;
  --mint: #bfe9d6;
  --text: #4a4039;
  --text-soft: #8a7d72;
  --accent: #ff8a5c;
  --accent-deep: #f2683a;
  --shadow: 0 6px 18px rgba(255, 160, 110, 0.18);
  --radius: 18px;
  --player-h: 116px;  /* 접힘 플레이어 바 실측 높이 (핸들+트랜스포트, 본문 padding-bottom 기준) */
  /* iOS식 세그먼트 컨트롤 토큰 (중립 크림 트랙 + 흰 thumb) */
  --seg-track:#f6ece2; --seg-thumb:#ffffff;
  --seg-shadow:0 1px 3px rgba(150,110,80,.18),0 1px 1px rgba(0,0,0,.04);
  --seg-text:var(--text-soft); --seg-text-active:var(--accent-deep);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

body {
  background-image:
    radial-gradient(circle at 12% 8%, rgba(255, 217, 179, 0.55), transparent 38%),
    radial-gradient(circle at 88% 4%, rgba(217, 200, 255, 0.5), transparent 40%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* ===== 공통 버튼 ===== */
.btn,
.form-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 14px 26px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s;
}
.btn:active,
.form-submit:active { transform: scale(0.97); }
.btn:disabled,
.form-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-soft {
  background: #fff;
  color: var(--accent-deep);
  border: 2px solid var(--peach-deep);
}

/* ===== 입력 폼 (index.html) ===== */
.form-page { padding: 24px 18px 48px; }

.form-wrap {
  max-width: 480px;
  margin: 0 auto;
}

.form-hero {
  text-align: center;
  margin: 18px 0 28px;
}
.form-hero h1 {
  font-size: 1.7rem;
  margin: 0 0 8px;
}
.form-hero p {
  color: var(--text-soft);
  margin: 0;
  font-size: 0.98rem;
}

.form-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 0.98rem;
}

.form-input,
.form-select {
  width: 100%;
  padding: 13px 15px;
  border: 2px solid #f0e2d4;
  border-radius: 14px;
  background: #fffdfb;
  font-size: 1rem;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--peach-deep);
  box-shadow: 0 0 0 4px rgba(255, 184, 119, 0.25);
}

/* 라디오 칩 (교훈 테마) */
.form-radio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.form-radio {
  position: relative;
}
.form-radio input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}
.form-radio span {
  display: block;
  text-align: center;
  padding: 12px 8px;
  border: 2px solid #f0e2d4;
  border-radius: 14px;
  background: #fffdfb;
  font-size: 0.95rem;
  transition: all 0.15s;
}
.form-radio input:checked + span {
  border-color: var(--accent);
  background: linear-gradient(135deg, #fff0e6, #ffe3d1);
  color: var(--accent-deep);
  font-weight: 700;
}

.form-submit { width: 100%; margin-top: 8px; }

/* 로딩 스피너 */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 248, 241, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 100;
}
.spinner {
  width: 54px;
  height: 54px;
  border: 6px solid var(--peach);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { color: var(--accent-deep); font-weight: 700; }

/* ===== 아바타 "마음에 드세요?" 만족 확인 바 ===== */
.avatar-satisfy {
  margin-top: 12px;
  padding: 12px;
  background: var(--cream, #fff8f1);
  border-radius: 14px;
  text-align: center;
}
.avatar-satisfy[hidden] { display: none; }
.satisfy-q { display: block; font-weight: 800; color: var(--accent-deep); margin-bottom: 10px; }
.satisfy-actions { display: flex; gap: 8px; }
.satisfy-actions .btn { flex: 1 1 0; }

/* ===== 유료 2장 후보 선택 ===== */
.avatar-pick { margin-top: 12px; }
.avatar-pick[hidden] { display: none; }
.pick-q { text-align: center; font-weight: 800; color: var(--accent-deep); margin-bottom: 10px; }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick-card {
  border: 2px solid #f0e2d4; border-radius: 14px; background: #fffdfb;
  padding: 8px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 6px; transition: all .15s;
}
.pick-card:active { transform: scale(.98); }
.pick-card:hover { border-color: var(--accent); }
.pick-card img { width: 100%; aspect-ratio: 4/5; object-fit: cover; border-radius: 10px; background: var(--peach, #ffe9d6); }
.pick-card span { font-weight: 800; font-size: 0.86rem; color: var(--accent-deep); }

/* ===== 샘플 동화 갤러리 ===== */
.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.sample-card {
  display: block;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}
.sample-thumb { aspect-ratio: 4 / 5; background: var(--peach, #ffe9d6); overflow: hidden; }
.sample-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sample-meta { padding: 8px 10px 10px; }
.sample-title { font-weight: 800; font-size: 0.92rem; }
.sample-theme { font-size: 0.76rem; color: var(--text-soft); margin-top: 2px; }

/* ===== 보호자 동의 게이트 (만14세) ===== */
.consent-overlay {
  position: fixed;
  inset: 0;
  background: rgba(60, 48, 40, 0.42);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 120;
}
.consent-overlay[hidden] { display: none; }
.consent-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  max-width: 380px;
  width: 100%;
  padding: 22px 20px 18px;
}
.consent-title { font-size: 1.12rem; font-weight: 800; color: var(--accent-deep); }
.consent-body { margin-top: 10px; font-size: .92rem; line-height: 1.55; color: var(--text); }
.consent-check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 14px;
  padding: 12px;
  background: var(--cream, #fff8f1);
  border-radius: 12px;
  font-size: .88rem;
  line-height: 1.5;
  cursor: pointer;
}
.consent-check input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }
.consent-check a { color: var(--accent-deep); text-decoration: underline; }
.consent-note { margin-top: 10px; font-size: .8rem; color: var(--muted, #8a7d70); }
.consent-actions { display: flex; gap: 10px; margin-top: 16px; }
.consent-actions .btn { flex: 1 1 0; }
.consent-actions .btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== 동화 화면 (story.html) — 그림책 페이저 ===== */
.story-body { overflow: hidden; }

.story-wrap {
  position: relative;
  max-width: 100%;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

/* 상단 모서리 처음으로 / 차일드락 (페이저 위에 떠 있음) */
.back-link-corner,
.childlock-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  z-index: 60;
  border: none;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.back-link-corner { left: 12px; }
.childlock-btn { right: 12px; }
.childlock-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
}

/* 안내 배너 (페이저 위에 떠 있는 토스트) */
.notice-banner {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 520px;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  z-index: 60;
  background: #fff;
  box-shadow: var(--shadow);
}
.notice-warn { background: #fff3d6; color: #9a6a14; }
.notice-error { background: #ffe0e0; color: #b23a3a; }

/* ===== 가로 페이저 ===== */
.blocks-container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE/Edge */
}
.blocks-container::-webkit-scrollbar { display: none; } /* WebKit */

/* 차일드락: 스와이프 잠금 */
body.child-locked .blocks-container {
  overflow-x: hidden;
  touch-action: none;
}

/* 한 컷 = 한 페이지 */
.story-page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  padding: calc(60px + env(safe-area-inset-top, 0px)) 18px
           calc(var(--player-h) + 28px + env(safe-area-inset-bottom, 0px));
  scrollbar-width: none;
}
.story-page::-webkit-scrollbar { display: none; }

.story-block {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* 블록별 AI 삽화 — 컨테이너를 삽화 캐논 비율(4:5)에 맞춰 잘림 0.
 * width 기준으로 4:5 박스를 만들고, 폰 세로에서 너무 커지지 않게 max-height 로 클램프. */
.block-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  height: auto;
  max-height: 64vh;
  margin: 0 auto 12px;
  border-radius: 14px;
  overflow: hidden;
  background: #fdf2e7;
}
.block-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(255, 160, 110, 0.18);
  opacity: 1;
  transition: opacity 0.4s ease;
}
/* 로딩 중: shimmer + 이미지 숨김 */
.block-image-wrap.is-loading .block-image { opacity: 0; }
.block-image-wrap.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    #f4e6d6 0%,
    #fff6ec 40%,
    #f4e6d6 80%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 150% 0; }
  100% { background-position: -150% 0; }
}
/* 실패: 부드러운 그라데이션 placeholder + 안내 (4:5 박스 해제, 낮은 배너로) */
.block-image-wrap.is-failed {
  aspect-ratio: auto;
  height: 30vh;
  max-height: 320px;
  min-height: 160px;
  background: linear-gradient(135deg, #ffe9d6, #ffe0ec, #e8def9);
  display: flex;
  align-items: center;
  justify-content: center;
}
.block-image-wrap.is-failed .block-image { display: none; }
.block-image-wrap.is-failed::after {
  content: "🎨 삽화를 준비하고 있어요";
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.guide-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--lilac), #c4b0ff);
  color: #5b3fa0;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.block-text {
  font-size: 1.12rem;
  line-height: 1.75;
  margin: 0 0 14px;
  color: var(--text);
}

.block-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* 🔊 이 장면 듣기 */
.listen-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  border: 2px solid var(--peach-deep);
  background: #fff;
  color: var(--accent-deep);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s;
}
.listen-btn:active { transform: scale(0.96); }
.listen-icon { font-size: 1.1rem; }

.rec-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  border: 2px solid var(--pink-deep);
  background: #fff;
  color: var(--pink-deep);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.rec-btn:active { transform: scale(0.96); }
.rec-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.rec-icon { font-size: 1.1rem; }

/* 대사 끝 인라인 '직접녹음' 칩 (텍스트 흐름에 붙음) */
.rec-inline {
  min-height: 0;
  padding: 3px 11px;
  font-size: 0.8rem;
  gap: 4px;
  vertical-align: middle;
  margin-left: 8px;
  border-width: 1.5px;
}
.rec-inline .rec-icon { font-size: 0.95rem; }

.rec-status { font-size: 0.9rem; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.status-recording { color: var(--pink-deep); }
.status-done { color: #2f9e6f; }

/* 녹음 중 블록 */
.story-block.recording {
  border-color: var(--pink-deep);
  animation: pulse 1.2s ease-in-out infinite;
}
.story-block.recording .rec-btn {
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  color: #fff;
}
@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 6px 22px rgba(255, 155, 176, 0.5); }
}

/* 녹음 완료 블록 */
.story-block.recorded {
  border-color: var(--mint);
}

/* 재생 중 하이라이트 (가로 페이저: translateY 제거 — 점프 방지) */
.story-block.playing {
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(255, 138, 92, 0.35);
  background: linear-gradient(135deg, #fffaf5, #fff1e6);
}

/* 부모 모드인데 녹음이 없어 기본 성우로 폴백된 블록 */
.story-block.playing.tts-fallback::after {
  content: "🔊 기본 성우";
  display: inline-block;
  margin-left: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-deep);
  vertical-align: middle;
}

.rec-progress {
  text-align: center;
  color: var(--text-soft);
  font-weight: 700;
  margin: 18px 0 8px;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ===== 플레이어 바 (하단 고정, 토스식 접이식) ===== */
.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg-card);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -6px 24px rgba(255, 160, 110, 0.22);
  padding: 8px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}

/* 펼치기 핸들 (상단 중앙, ▲ 탭) */
.expand-handle {
  position: relative;
  align-self: center;
  width: 72px;
  min-height: 26px;
  margin: -2px 0 0;
  padding: 4px 0 2px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.expand-handle-bar {
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: #e8d6c4;
}
.expand-handle-icon {
  font-size: 0.7rem;
  line-height: 1;
  color: var(--text-soft);
  transition: transform 0.25s ease;
}
.player-bar.is-open .expand-handle-icon {
  transform: rotate(180deg);
}

/* n / N 인디케이터 */
.page-indicator {
  min-width: 48px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-soft);
  flex: 0 0 auto;
}

/* ===== 세그먼트 재생바 (접힘 기본 노출) ===== */
.segment-bar {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 22px;
}
.segment-cell {
  flex: 1 1 0;
  min-width: 6px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: #f0e2d4;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, height 0.15s ease;
}
.segment-cell:active { transform: scaleY(0.8); }
/* 완료된 칸 = 채움 */
.segment-cell.is-done {
  background: linear-gradient(90deg, var(--peach-deep), var(--pink));
}
/* 현재 칸 = 강조 */
.segment-cell.is-current {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  height: 12px;
  box-shadow: 0 2px 6px rgba(255, 138, 92, 0.4);
}

/* 핸들로 펼치는 설정 패널 (기본 닫힘 → .is-open 시 노출) */
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 0;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  border-top: 1px solid transparent;
  padding-top: 0;
  transition: max-height 0.25s ease, opacity 0.25s ease,
              transform 0.25s ease, padding-top 0.25s ease;
}
.player-bar.is-open .settings-panel {
  max-height: 45vh;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  border-top-color: #f0e2d4;
  padding-top: 10px;
}

/* 펼침 패널 내 이전/다음 이동 */
.player-nav-row {
  justify-content: center;
  gap: 18px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 통합 iOS식 세그먼트 컨트롤 (언어 / 들려주기 공용) */
.lang-control { flex: 1; }   /* 좌측 라벨과 함께 행을 채움 */
.segmented {
  display: flex;
  width: 100%;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--seg-track);
  box-shadow: inset 0 1px 2px rgba(150, 110, 80, .10);
}
.seg-btn {
  flex: 1 1 0;
  min-height: 40px;
  border: none;
  background: transparent;
  border-radius: 11px;
  font-size: .92rem;
  font-weight: 700;
  color: var(--seg-text);
  cursor: pointer;
  transition: color .15s ease, background .18s ease, box-shadow .18s ease;
}
.seg-btn:active { transform: scale(.98); }
.seg-btn.is-active {
  background: var(--seg-thumb);
  color: var(--seg-text-active);
  box-shadow: var(--seg-shadow);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 그룹 구분선 (소리 그룹 / 배경음악 앞 옅은 선) */
.player-sound-group, .player-bgm-group {
  border-top: 1px solid #f0e2d4;
  padding-top: 8px;
}

/* 단일 언어일 때 '다른 언어로 만들기' 버튼 (세그먼트 아님) */
.lang-make-btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  cursor: pointer;
  box-shadow: var(--shadow);
}
.lang-make-btn:disabled { opacity: 0.6; cursor: default; }

/* 번역 진행 오버레이 */
.translate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 248, 241, 0.92);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.translate-overlay[hidden] { display: none; }
.translate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 8px 24px;
}
.translate-msg {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent-deep);
}

.player-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-soft);
  min-width: 86px;
}

.player-select {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid #f0e2d4;
  border-radius: 12px;
  background: #fffdfb;
  font-size: 0.95rem;
  color: var(--text);
}

.player-transport {
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0;
}
/* 접힘 행: 이전/다음(작게) + 재생(메인) + 세그먼트바 + 인디케이터 */
.player-transport .ctrl-btn {
  width: 44px;
  height: 44px;
  font-size: 1.05rem;
  flex: 0 0 auto;
}
.player-transport .ctrl-btn-main {
  width: 58px;
  height: 58px;
  font-size: 1.4rem;
}
/* 이전/다음 = 테두리 없는 글씨 버튼 (텍스트만, 누르면 동작) */
.player-transport .ctrl-nav {
  width: auto;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0 8px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--accent-deep);
  flex: 0 0 auto;
}
.player-transport .ctrl-nav:disabled { color: var(--text-soft); opacity: 0.5; }

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--peach-deep);
  background: #fff;
  color: var(--accent-deep);
  font-size: 1.2rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
}
.ctrl-btn:active { transform: scale(0.92); }
.ctrl-btn-main {
  width: 66px;
  height: 66px;
  font-size: 1.5rem;
  color: #fff;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: var(--shadow);
}
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.player-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--peach-deep), var(--pink));
  outline: none;
}
.player-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.player-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
}

/* ===== 커버 페이지 ===== */
.cover-page,
.end-page {
  justify-content: center;
  align-items: center;
}
.cover-card,
.end-card {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 22px 20px 26px;
  box-shadow: var(--shadow);
}
/* 커버 대표 그림 — block-image-wrap(4:5) 상속. 높이 기준으로 적당히 크게,
 * 폭은 비율로(4:5). 좌우는 카드 파스텔 여백. */
.cover-image {
  width: auto;
  height: min(46vh, 420px);
  aspect-ratio: 4 / 5;
  max-height: 46vh;
  margin: 0 auto;
}
.cover-title {
  font-size: 1.6rem;
  margin: 16px 0 6px;
}
.cover-subtitle {
  color: var(--text-soft);
  margin: 0 0 20px;
  font-size: 1rem;
}
.cover-start-btn {
  width: 100%;
  font-size: 1.15rem;
  padding: 16px 26px;
  min-height: 56px;
}

/* ===== 끝 페이지 ===== */
.end-emoji { font-size: 3.2rem; line-height: 1; }
.end-title { font-size: 2rem; margin: 12px 0 24px; }
.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.end-actions .btn {
  width: 100%;
  min-height: 56px;
  font-size: 1.1rem;
}

/* 하단 페이드 제거: 대사 끝줄·직접녹음 칩을 흐리게 가려 혼란을 줘서 비활성화 */
.story-page::after { display: none; }

/* ===== 태블릿/PC: 2단 split 폐지 → 단일 컬럼 중앙, 그림 크게 ===== */
@media (min-width: 768px) {
  .story-block {
    max-width: 640px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  /* 세로(높이) 기준으로 크게, 폭은 4:5 비율로 자동. 좌우는 페이지 파스텔 여백. */
  .story-block .block-image-wrap {
    width: auto;
    height: min(78vh, 700px);
    max-height: 78vh;
    aspect-ratio: 4 / 5;
    margin: 0 auto 16px;
  }
  .block-text {
    max-width: 60ch;
    line-height: 1.85;
    text-align: center;
  }
  .block-controls { justify-content: center; }
  /* 커버 그림도 태블릿/PC 에서 더 크게(4:5 유지). */
  .cover-image {
    height: min(64vh, 560px);
    max-height: 64vh;
  }
}

/* 데스크톱에서 조금 더 넓게 */
@media (min-width: 600px) {
  .cover-title { font-size: 1.8rem; }
  .block-text { font-size: 1.15rem; }
}

/* ===== 생성 진행 / 실패 화면 (story.html generating·failed) ===== */
.gen-wrap {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(60px + env(safe-area-inset-top, 0px)) 20px
           calc(40px + env(safe-area-inset-bottom, 0px));
}

.gen-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: 24px;
  padding: 34px 26px 30px;
  box-shadow: 0 12px 36px rgba(255, 160, 110, 0.22);
  text-align: center;
}

/* 마스코트 / 일러스트 — 부드러운 둥실 애니메이션 */
.gen-mascot {
  font-size: 3.4rem;
  line-height: 1;
  margin-bottom: 14px;
  animation: gen-float 2.4s ease-in-out infinite;
}
@keyframes gen-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* 생성중 로딩 스피너 (이모지 마스코트 대체) */
.gen-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border: 6px solid var(--peach);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.gen-spinner.is-failed {
  animation: none;
  border-color: #e7d8c8;
  border-top-color: #e7d8c8;
}

.gen-step {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-deep);
  margin: 0 0 20px;
  min-height: 1.5em;
}

/* 진행바 */
.gen-bar-track {
  position: relative;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #fbeada;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(255, 160, 110, 0.25);
}
.gen-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--peach-deep), var(--accent), var(--pink-deep));
  background-size: 200% 100%;
  animation: gen-bar-shine 2s linear infinite;
  transition: width 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes gen-bar-shine {
  0% { background-position: 0% 0; }
  100% { background-position: 200% 0; }
}
.gen-bar-track.is-failed .gen-bar-fill {
  background: linear-gradient(90deg, var(--pink-deep), #ff8a8a);
  animation: none;
}

.gen-count {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent-deep);
  margin: 12px 0 0;
}

.gen-hint {
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.7;
  margin: 18px 0 0;
}

.gen-actions {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gen-actions .btn {
  width: 100%;
  min-height: 54px;
  font-size: 1.08rem;
  text-decoration: none;
}
.gen-fail-msg {
  color: var(--pink-deep);
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0;
}

/* 실패 전용 카드 */
.gen-failed-emoji { font-size: 3.4rem; line-height: 1; }
.gen-failed-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 14px 0 10px;
}
.gen-failed-desc {
  color: var(--text-soft);
  font-size: 0.96rem;
  line-height: 1.7;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .gen-mascot { animation: none; }
  .gen-spinner { animation: none; }
  .gen-bar-fill { animation: none; }
}

/* ===== 등장인물(내 캐릭터) — 프로필 목록 + 아바타 빌더 (profiles.html) ===== */

/* 프로필 카드 그리드 */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 12px 12px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
}
.profile-thumb {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, #ffe9d6, #e8def9);
}
.profile-thumb.is-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
}
.profile-name {
  font-weight: 800;
  font-size: 0.98rem;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-kind { font-size: 0.82rem; color: var(--text-soft); }
.profile-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.mini-btn {
  border: 1.5px solid #f0e2d4;
  background: #fffdfb;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
}
.mini-btn.edit { color: var(--accent-deep); border-color: var(--peach-deep); }
.mini-btn.del { color: var(--pink-deep); border-color: var(--pink); }
.mini-btn:active { transform: scale(0.96); }

/* + 새 캐릭터 카드 */
.profile-add {
  justify-content: center;
  border: 2px dashed var(--peach-deep);
  background: #fffaf5;
  color: var(--accent-deep);
  cursor: pointer;
  min-height: 150px;
  font-family: inherit;
}
.profile-add-plus { font-size: 2rem; line-height: 1; }
.profile-add-text { font-weight: 800; font-size: 0.92rem; }

/* ===== 빌더 ===== */
.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.builder-title { font-size: 1.15rem; font-weight: 800; margin: 0; }
.builder-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #fff1e6;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
}

/* 모드 전환 탭 (옵션 / 그림 올리기) */
.mode-toggle {
  display: flex;
  gap: 8px;
  padding: 5px;
  border-radius: 999px;
  background: #fdeede;
  margin-bottom: 18px;
}
.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 12px 8px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-soft);
  cursor: pointer;
  min-height: 48px;
  transition: all 0.18s;
}
.mode-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  box-shadow: var(--shadow);
}

/* 그림 올리기 안내 + 파일 입력 */
.draw-guide {
  background: #fff5ec;
  border: 2px solid #ffe1cc;
  border-radius: 14px;
  padding: 13px 15px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-soft);
  margin: 0 0 18px;
}
.draw-guide strong { color: var(--pink-deep); }
.draw-file-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px dashed #f0c9a8;
  border-radius: 14px;
  background: #fffdfb;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.draw-file-input::file-selector-button {
  margin-right: 12px;
  padding: 8px 14px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}

/* 아바타 미리보기 */
.avatar-preview {
  width: 200px;
  height: 200px;
  max-width: 70vw;
  margin: 0 auto 18px;
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(135deg, #ffe9d6, #ffe0ec, #e8def9);
  box-shadow: var(--shadow);
}
.avatar-preview-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-preview-ph {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-soft);
  text-align: center;
}
.avatar-preview-emoji { font-size: 2.6rem; }
.avatar-preview-hint { font-size: 0.82rem; font-weight: 700; line-height: 1.4; }

/* 빌더 필드 */
.bf { margin-bottom: 16px; }
.bf-label { display: block; font-weight: 800; font-size: 0.92rem; margin-bottom: 8px; }
.bf-input,
.bf-select {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid #f0e2d4;
  border-radius: 14px;
  background: #fffdfb;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
}
.bf-input:focus,
.bf-select:focus {
  outline: none;
  border-color: var(--peach-deep);
  box-shadow: 0 0 0 4px rgba(255, 184, 119, 0.25);
}

/* 종류 토글 */
.kind-toggle {
  display: flex;
  gap: 8px;
  padding: 5px;
  border-radius: 999px;
  background: #fdeede;
}
.kind-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-soft);
  cursor: pointer;
  min-height: 48px;
  transition: all 0.18s;
}
.kind-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  box-shadow: var(--shadow);
}

/* 칩 그리드 (종/성별) */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.chip-grid-3 { grid-template-columns: repeat(3, 1fr); }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 2px solid #f0e2d4;
  background: #fffdfb;
  border-radius: 14px;
  padding: 12px 4px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  min-height: 48px;
  transition: all 0.15s;
}
.chip-emoji { font-size: 1.4rem; line-height: 1.1; }
.chip.is-active {
  border-color: var(--accent);
  background: linear-gradient(135deg, #fff0e6, #ffe3d1);
  color: var(--accent-deep);
}
.chip:active { transform: scale(0.96); }

/* 색칩 스와치 */
.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #f0e2d4;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch:active { transform: scale(0.92); }
.swatch.is-active {
  box-shadow: 0 0 0 3px var(--accent);
  transform: scale(1.06);
}

/* 빌더 액션 */
.builder-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
}
.gen-btn { width: 100%; flex-direction: column; gap: 2px; min-height: 58px; }
.gen-cost {
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0.95;
}
.gen-cost.is-free { color: #fff5e9; }
.gen-cost.is-paid { color: #fff; }
.save-btn { width: 100%; min-height: 50px; }
.builder-msg {
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--pink-deep);
  font-weight: 700;
  min-height: 1.2em;
}
.builder-msg a { color: var(--accent-deep); font-weight: 800; }
.builder-msg.is-error {
  color: #e0483e;
  background: #ffeceb;
  border-radius: 12px;
  padding: 10px 12px;
}

/* 로딩 오버레이가 hidden 속성을 존중하도록 */
.loading-overlay[hidden] { display: none; }

@media (min-width: 600px) {
  .profile-grid { grid-template-columns: repeat(3, 1fr); }
}
