/* 움직이는 이야기책 — 모양. 원작 바닷속 올리 이야기(Santa Tracker)의 화면 배치(가장자리 빨간 넘김 버튼, 아래 진행 막대,
   물결 가림막 넘김, 글이 아래에서 떠오름)를 보고 새로 그렸다. 원작 CSS·그림은 복사하지 않았다. */
html, body { height: 100%; }
body { background: var(--night); overscroll-behavior: none; display: flex; flex-direction: column; overflow: hidden; }
body > .topbar { flex: none; }

.book { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; --focus: var(--gold); }

/* 그림 칸: 4:3 장면을 칸 높이에 맞추고, 칸보다 넓으면 쪽마다 정한 곳(focus)을 보여 준다 */
.view { position: relative; flex: 0 1 calc(100vw * 1.05); min-height: min(200px, 75vw); overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.scene { position: absolute; top: 0; height: 100%; aspect-ratio: 4 / 3; container-type: size; overflow: hidden; background: var(--sky); }
.scene > .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; -webkit-user-drag: none; }
.amb, .fxl { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.fxl { z-index: 3; }

/* 자리표시 바탕 (자료에 그림이 없는 쪽: 표지·말씀 쪽) */
.bgph { position: absolute; inset: 0; }
.ph-sea, .ph-ground { position: absolute; left: 0; right: 0; bottom: 0; }
.ph-rainbow { position: absolute; left: 8%; width: 84%; aspect-ratio: 2 / 1; bottom: 20%;
  background: radial-gradient(circle at 50% 100%, transparent 54%, #8A63F0 54% 60%, #3C7DFF 60% 66%, #4DBE7A 66% 72%,
    #FFC531 72% 78%, #FF9440 78% 84%, #FF4F45 84% 90%, transparent 90%); opacity: .9; }

/* 움직이는 물건 자리표시: 단색 둥근 덩어리 + 작은 이름 (그림이 오면 img) */
.sp { position: absolute; left: 0; top: 0; display: grid; place-items: center; font-size: max(10px, 1.7cqw); font-weight: 900; line-height: 1;
  color: var(--ink); text-align: center; will-change: transform, opacity; }
.sp img { width: 100%; height: 100%; object-fit: contain; }
.sp.has-art { aspect-ratio: auto; border-radius: 0; box-shadow: none; } /* 그림이 오면 도형 장식(배 지붕·날개·잎)은 끔 */
.sp.has-art::before, .sp.has-art::after { display: none; }
.sp.has-art img { height: auto; display: block; }
.sp--round { aspect-ratio: 1; border-radius: 50%; box-shadow: inset -3px -4px 0 rgba(28, 37, 84, .14); }
.sp--blob { aspect-ratio: 1.15 / 1; border-radius: 48% 48% 40% 40%; box-shadow: inset -3px -4px 0 rgba(28, 37, 84, .14); }
.sp--bird { aspect-ratio: 1.3 / 1; border-radius: 60% 60% 50% 50% / 70% 70% 40% 40%; box-shadow: inset -3px -4px 0 rgba(28, 37, 84, .12); }
.sp--bird::before { content: ""; position: absolute; left: 22%; top: -18%; width: 46%; height: 60%; border-radius: 50% 50% 0 50%; background: inherit; transform: rotate(20deg); animation: sb-flap .22s ease-in-out infinite alternate; transform-origin: 80% 100%; }
.sp--bird.leaf::after { content: ""; position: absolute; left: -26%; top: 36%; width: 34%; height: 22%; border-radius: 0 80% 0 80%; background: #4FA35A; }
@keyframes sb-flap { to { transform: rotate(-30deg) scaleY(.7); } }
.sp--step { aspect-ratio: .62; border-radius: 50%; }
.sp--plank { aspect-ratio: 5 / 1; border-radius: 4px; box-shadow: inset 0 -3px 0 rgba(107, 67, 43, .4); }
.sp--spark { aspect-ratio: 1; background: none !important; }
.sp--spark::before { content: "✦"; font-size: 4.2cqw; color: #fff; text-shadow: 0 0 8px #fff, 0 0 16px #FFE38A; }
.sp--ark { aspect-ratio: 2.3 / 1; border-radius: 10% 10% 48% 48% / 16% 16% 84% 84%; box-shadow: inset 0 -10px 0 var(--wood-dark); }
.sp--ark::before { content: ""; position: absolute; left: 24%; right: 24%; bottom: 96%; height: 44%; border-radius: 10px 10px 0 0; background: var(--roof);
  box-shadow: inset 0 -8px 0 var(--roof-dark); }
.sp--ark::after { content: ""; position: absolute; left: 12%; right: 12%; top: 22%; height: 18%;
  background: radial-gradient(circle, #3A2416 0 38%, transparent 40%) 0 50% / 14% 100% repeat-x; }
.pair { display: flex; gap: 4px; align-items: flex-end; }
.pair .sp { position: relative; }

/* 분위기 움직임: 햇살 · 흘러가는 구름 · 비 · 물결 */
.rays { position: absolute; width: 140cqw; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%;
  background: repeating-conic-gradient(var(--c) 0deg 7deg, transparent 7deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 0 8%, rgba(0, 0, 0, .55) 30%, transparent 62%); mask: radial-gradient(circle, #000 0 8%, rgba(0, 0, 0, .55) 30%, transparent 62%);
  animation: sb-spin 90s linear infinite; }
.rays.boost { animation: sb-spin 90s linear infinite, sb-boost 1.4s ease-out; }
@keyframes sb-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes sb-boost { 30% { opacity: 1; filter: brightness(1.6); } }
.cloud { position: absolute; left: 0; aspect-ratio: 2.4 / 1; border-radius: 999px; }
.cloud::before, .cloud::after { content: ""; position: absolute; border-radius: 50%; background: inherit; }
.cloud::before { width: 46%; aspect-ratio: 1; left: 14%; bottom: 30%; }
.cloud::after { width: 34%; aspect-ratio: 1; right: 16%; bottom: 36%; }
.rain i { position: absolute; top: -6%; width: .35cqw; min-width: 2px; height: 4%; border-radius: 2px; background: rgba(220, 236, 255, .75);
  transform: rotate(12deg); animation: sb-fall var(--d, .8s) linear infinite; animation-delay: var(--dl, 0s); }
.rain i.extra { background: rgba(240, 248, 255, .95); }
@keyframes sb-fall { to { transform: translate(-6cqw, 112cqh) rotate(12deg); } }
.waves { position: absolute; left: 0; bottom: -2%; width: 200%; animation: sb-slide 7s linear infinite; opacity: .55;
  background: radial-gradient(circle at 50% 0, transparent 0 58%, var(--c) 60%) 0 0 / 8cqw 100% repeat-x; }
@keyframes sb-slide { to { transform: translateX(-50%); } }

/* 누르는 곳: 평소엔 보이지 않고, 오래 안 누르면 반짝(힌트), 키보드 초점이면 고리 */
.spot { position: absolute; z-index: 4; min-width: var(--tap); min-height: var(--tap); aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%;
  background: transparent; transform: translate(-50%, -50%); cursor: pointer; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
.spot:focus-visible { outline: 4px solid var(--gold); outline-offset: 0; }
.spot.hint::after { content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 4px dashed rgba(255, 246, 227, .95);
  box-shadow: 0 0 0 4px rgba(246, 183, 60, .45); animation: sb-hint 1.1s ease-in-out infinite; }
@keyframes sb-hint { 50% { transform: scale(1.12); opacity: .55; } }

.found { position: absolute; z-index: 5; right: 12px; top: 10px; padding: 4px 12px; border-radius: 999px; background: rgba(28, 37, 84, .72);
  color: var(--cream); font-size: 16px; font-weight: 800; pointer-events: none; }
.found.bump { animation: sb-bump .5s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes sb-bump { 40% { transform: scale(1.25); background: var(--gold); color: var(--ink); } }

/* 글 칸: 원작처럼 넘긴 뒤 한 줄씩 아래에서 떠오른다 */
.text { position: relative; flex: 1 1 auto; min-height: 112px; overflow: auto; padding: 14px 20px 8px; background: var(--cream); color: var(--ink);
  font-size: clamp(19px, 5vw, 23px); font-weight: 600; line-height: 1.55; text-align: center; }
.line { opacity: 0; transform: translateY(var(--rise, 30px)); }
.line + .line { margin-top: 6px; }
.line.in { opacity: 1; transform: none; transition: transform var(--rise-ms, 1.8s) cubic-bezier(.19, 1, .22, 1), opacity .7s ease; }
.line.title { font-size: clamp(26px, 7vw, 40px); font-weight: 900; line-height: 1.25; }
.line.sub { font-size: 16px; font-weight: 700; opacity: 0; color: var(--wood); }
.line.sub.in { opacity: 1; }
.line.ref { font-size: 17px; font-weight: 800; color: var(--advent); }
.text .say-row { margin: 8px 0 4px; text-align: left; font-size: 17px; }
.text .bubble, .sheet .bubble { background: #fff; }
.text .say-row .bubble::after, .sheet .say-row .bubble::after { border-right-color: #fff; }
.voice-btn { margin: 8px auto 0; min-height: 44px; padding: 0 16px; font-size: 16px; }

/* 넘김 버튼: 원작처럼 화면 가장자리에 붙은 빨간 반쪽 알약 (휴대폰은 아래, 넓은 화면은 가운데 높이) */
.nav { position: relative; z-index: 6; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--cream); }
.turn-btn { width: 82px; height: 58px; border: 0; cursor: pointer; background: var(--joy); color: #fff; font-size: 30px; font-weight: 900; line-height: 1;
  transition: transform .1s ease, box-shadow .1s linear, opacity .3s linear; touch-action: manipulation; }
.turn-btn--prev { border-radius: 0 40px 40px 0; box-shadow: 4px 6px 0 #A7232A; margin-left: -5px; padding-left: 5px; }
.turn-btn--next { border-radius: 40px 0 0 40px; box-shadow: -4px 6px 0 #A7232A; margin-right: -5px; padding-right: 5px; }
.turn-btn:active { transform: translateY(4px); box-shadow: none; }
.turn-btn.is-hidden { opacity: 0; pointer-events: none; }
.turn-btn--next.last { background: var(--gold); color: var(--ink); box-shadow: -4px 6px 0 var(--gold-dark); font-size: 20px; }
.dots { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(28, 37, 84, .2); }
.dots i.on { background: var(--gold); transform: scale(1.3); }
.slider { display: none; flex: 1; max-width: 860px; }
.slider input { width: 100%; height: 30px; -webkit-appearance: none; appearance: none; border-radius: 30px; background: #9FCEFF; cursor: grab; outline-offset: 4px; }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 68px; height: 33px; border-radius: 17px; background: var(--gold); box-shadow: 4px 0 0 var(--gold-dark); }
.slider input::-moz-range-thumb { width: 68px; height: 33px; border: 0; border-radius: 17px; background: var(--gold); }
@media (min-width: 900px) {
  .nav { padding: 12px 24px 16px; justify-content: center; } /* 넘김 단추가 fixed 로 빠지면 막대만 남아 왼쪽에 붙었음 (10/17) */
  .dots { display: none; }
  .slider { display: block; }
  .turn-btn { position: fixed; top: 50%; width: 110px; height: 75px; font-size: 36px; }
  .turn-btn--prev { left: 0; } .turn-btn--next { right: 0; }
  .text { padding: 16px 140px 8px; }
}

/* 물결 가림막 (원작 lottie 대신 두 겹 둥근 면이 옆으로 쓸고 지나감) */
.turn { position: absolute; inset: 0; z-index: 20; pointer-events: none; overflow: hidden; }
.turn.on { pointer-events: auto; }
.turn i { position: absolute; top: -40%; left: -20%; width: 140%; height: 180%; border-radius: 46%; transform: translateX(120%); }

/* 효과 조각 */
.pop { position: absolute; left: 0; top: 0; font-size: max(18px, 3.4cqw); font-weight: 900; text-shadow: 0 2px 0 rgba(28, 37, 84, .25); will-change: transform, opacity; }
.ring { position: absolute; left: 0; top: 0; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .9); will-change: transform, opacity; }
.glow { position: absolute; border-radius: 50%; transform: translate(-50%, -50%); }

/* 끝 화면: 아래에서 올라오는 판 */
.scrim { position: fixed; inset: 0; z-index: 39; background: rgba(28, 37, 84, .4); }
.sheet { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; max-height: 88svh; overflow: auto; overscroll-behavior: contain;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: var(--cream);
  box-shadow: 0 -8px 30px rgba(28, 37, 84, .25); animation: sb-up .35s cubic-bezier(.2, .9, .3, 1); }
.sheet > * { max-width: 520px; margin-left: auto; margin-right: auto; }
.sheet .end { padding: 0; gap: 12px; }
@media (max-width: 420px) { /* 10/15 검수: 375 에서 셋째 단추가 화면 밖으로 → 한 줄에 셋 */
  .sheet .btn-row { flex-wrap: nowrap; gap: 6px; }
  .sheet .btn-row > * { padding-left: 12px; padding-right: 12px; font-size: 15px; white-space: nowrap; }
}
.sheet .parent-q { background: #fff; width: 100%; text-align: left; }
@keyframes sb-up { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  .rays, .waves, .rain i, .sp--bird::before, .spot.hint::after { animation: none !important; }
  .rain i { top: var(--y, 10%); }
  .line, .line.in { transform: none; transition: opacity .2s; }
  .sheet { animation: none; }
}

@media (min-aspect-ratio: 3/4) { .view { flex: 1 1 auto; } .text { flex: none; } } /* 넓은 화면: 그림이 남는 높이를 다 씀 */

/* 가로 휴대폰: 그림 왼쪽, 글·넘김 단추 오른쪽 ('다음 장'이 첫 화면 안, 고칠 일 1) */
@media (orientation: landscape) and (max-height: 500px) {
  .book { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .book > * { grid-column: 2; }
  .book > .view { grid-column: 1; grid-row: 1 / span 2; min-height: 0; }
  .book > .text { grid-row: 1; overflow-y: auto; }
  .book > .nav { grid-row: 2; }
}
