@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700;900&family=Gaegu:wght@300;400;700&display=swap');

:root {
  --pastel-pink: #f8c8dc;
  --pastel-lavender: #c9b1ff;
  --pastel-mint: #b5ead7;
  --pastel-yellow: #ffeaa7;
  --pastel-sky: #a0d2f0;
  --warm-gold: #f5c542;
  --text-dark: #4a3728;
  --text-light: #7a6555;
  --bg-cream: #fdf6ec;
  --bg-soft: #faf0e6;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Gaegu', 'Noto Sans KR', cursive;
  background: linear-gradient(135deg, #fdf6ec 0%, #f0e6ff 50%, #e6f7f0 100%);
  min-height: 100vh;
  overflow: hidden;
  color: var(--text-dark);
  -webkit-text-size-adjust: 100%;
}
@supports (min-height: 100dvh) { body { min-height: 100dvh; } }

/* ── Cover ── */
.cover-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #fdf6ec 0%, #f8c8dc44 30%, #c9b1ff33 60%, #b5ead744 100%);
  transition: opacity 0.8s, transform 0.8s;
}
.cover-screen.hidden { opacity: 0; pointer-events: none; transform: scale(1.1); }

.cover-title {
  font-family: 'Gaegu', cursive;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
  margin-bottom: 0.5rem;
  animation: floatTitle 3s ease-in-out infinite;
}
.cover-subtitle {
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: var(--text-light);
  margin-bottom: 2rem;
  text-align: center;
}
.cover-rabbit {
  font-size: clamp(4rem, 12vw, 8rem);
  animation: bounce 2s ease-in-out infinite;
  margin-bottom: 2rem;
}
.start-btn {
  font-family: 'Gaegu', cursive;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 700;
  padding: 1rem 3rem;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--pastel-pink), var(--pastel-lavender));
  color: var(--text-dark);
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(201,177,255,0.4);
  transition: transform 0.3s, box-shadow 0.3s;
}
.start-btn:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 12px 40px rgba(201,177,255,0.6);
}

/* ── Book Container ── */
.book-container {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity 0.6s;
}
.book-container.active { opacity: 1; pointer-events: all; }

/* ── Page ── */
.page {
  flex: 1; display: none; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 1rem;
  min-height: 0;
  animation: fadeIn 0.6s ease-out;
}
.page.active { display: flex; }

.page-inner {
  width: 100%; max-width: 800px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.08), 0 0 0 1px rgba(255,255,255,0.5);
  overflow: hidden;
  max-height: calc(100vh - 120px);
  display: flex; flex-direction: column;
}
@supports (height: 100dvh) {
  .page-inner { max-height: calc(100dvh - 120px); }
}

.page-image-wrap {
  width: 100%; aspect-ratio: 1/1; overflow: hidden;
  position: relative; flex-shrink: 0;
  max-height: 50vh;
}
.page-image-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 8s ease-out;
}
.page.active .page-image-wrap img { transform: scale(1.05); }

.page-content {
  padding: 1.5rem 2rem 1rem;
  flex: 1; overflow-y: auto;
}
.page-number {
  font-family: 'Gaegu', cursive;
  font-size: 0.85rem; font-weight: 700;
  color: var(--pastel-lavender);
  margin-bottom: 0.3rem;
  letter-spacing: 2px;
}
.page-text {
  font-family: 'Gaegu', cursive;
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  line-height: 1.8;
  color: var(--text-dark);
  word-break: keep-all;
}

/* ── Audio Button ── */
.audio-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  margin-top: 0.8rem;
  padding: 0.5rem 1.2rem;
  border: 2px solid var(--pastel-lavender);
  border-radius: 50px;
  background: rgba(201,177,255,0.15);
  font-family: 'Gaegu', cursive;
  font-size: 1rem; font-weight: 700;
  color: #7c5cbf;
  cursor: pointer;
  transition: all 0.3s;
}
.audio-btn:hover { background: rgba(201,177,255,0.35); transform: scale(1.05); }
.audio-btn.playing {
  background: linear-gradient(135deg, var(--pastel-pink), var(--pastel-lavender));
  border-color: transparent; color: #fff;
  animation: pulse 1.5s infinite;
}
.audio-btn .icon { font-size: 1.3rem; }

/* ── Navigation ── */
.nav-bar {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.nav-btn {
  font-family: 'Gaegu', cursive;
  font-size: 1.1rem; font-weight: 700;
  padding: 0.6rem 1.8rem;
  border: none; border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s;
}
.nav-btn.prev {
  background: linear-gradient(135deg, var(--pastel-mint), var(--pastel-sky));
  color: var(--text-dark);
}
.nav-btn.next {
  background: linear-gradient(135deg, var(--pastel-pink), var(--pastel-lavender));
  color: var(--text-dark);
}
.nav-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.nav-btn:disabled { opacity: 0.3; cursor: default; transform: none; box-shadow: none; }

.page-indicator {
  font-family: 'Gaegu', cursive;
  font-size: 1rem; font-weight: 700;
  color: var(--text-light);
  min-width: 60px; text-align: center;
}

/* ── Progress dots ── */
.progress-dots {
  display: flex; gap: 6px; justify-content: center;
  padding: 0.5rem;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--pastel-pink);
  opacity: 0.3;
  transition: all 0.3s;
  cursor: pointer;
}
.dot.active { opacity: 1; transform: scale(1.4); background: var(--pastel-lavender); }
.dot.visited { opacity: 0.6; }

/* ── Sparkles ── */
.sparkle {
  position: fixed;
  width: 6px; height: 6px;
  background: var(--warm-gold);
  border-radius: 50%;
  pointer-events: none;
  animation: sparkle 2s ease-out forwards;
  z-index: 200;
}

/* ── Animations ── */
@keyframes floatTitle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201,177,255,0.5); }
  50% { box-shadow: 0 0 0 10px rgba(201,177,255,0); }
}
@keyframes sparkle {
  0% { transform: scale(0) rotate(0deg); opacity: 1; }
  50% { transform: scale(1) rotate(180deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(360deg); opacity: 0; }
}

/* ── Voice Bar ── */
.voice-bar {
  display: flex; align-items: center; justify-content: center; gap: 0.8rem;
  padding: 0.6rem 1rem;
  margin-bottom: 0.5rem;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(8px);
  border-radius: 50px;
  position: sticky; top: 8px; z-index: 50;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.voice-label {
  font-family: 'Gaegu', cursive, sans-serif;
  font-size: 0.95rem; font-weight: 700;
  color: #7a6555;
}
.voice-select {
  font-family: 'Gaegu', cursive, sans-serif;
  font-size: 0.95rem; font-weight: 700;
  padding: 0.4rem 0.8rem;
  border: 2px solid #c9b1ff;
  border-radius: 20px;
  background: rgba(201,177,255,0.12);
  color: #4a3728;
  cursor: pointer;
  transition: all 0.3s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%237c5cbf' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.voice-select:hover { border-color: #f8c8dc; background-color: rgba(248,200,220,0.2); }
.voice-select:focus { border-color: #f8c8dc; box-shadow: 0 0 0 3px rgba(248,200,220,0.3); }
.voice-status {
  font-family: 'Gaegu', cursive, sans-serif;
  font-size: 0.85rem;
  color: #7c5cbf;
  min-width: 60px;
  transition: opacity 0.3s;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .page { padding: 0.5rem; }
  .page-content { padding: 0.9rem 1.1rem 0.7rem; }
  .page-inner {
    border-radius: 16px;
    max-height: calc(100vh - 96px);
  }
  @supports (height: 100dvh) {
    .page-inner { max-height: calc(100dvh - 96px); }
  }
  .page-image-wrap { aspect-ratio: 5 / 4; max-height: 42vh; }
  .page-text { font-size: 1.05rem; line-height: 1.7; }
  .page-number { font-size: 0.8rem; margin-bottom: 0.2rem; }
  .audio-btn { padding: 0.55rem 1.1rem; font-size: 0.95rem; min-height: 40px; }
  .nav-bar {
    gap: 0.5rem;
    padding: 0.55rem 0.6rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }
  .nav-btn {
    padding: 0.55rem 1rem;
    font-size: 0.95rem;
    min-height: 42px;
    flex: 0 1 auto;
  }
  .page-indicator { font-size: 0.9rem; min-width: 44px; }
  .voice-bar {
    padding: 0.45rem 0.7rem;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0.3rem 0.5rem 0.4rem;
    top: 6px;
  }
  .voice-label { font-size: 0.85rem; }
  .voice-select {
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    padding-right: 22px;
    background-position: right 8px center;
  }
  .voice-status { font-size: 0.75rem; min-width: 0; }
  .progress-dots { padding: 0.35rem; gap: 5px; }
  .dot { width: 7px; height: 7px; }
  .start-btn {
    padding: 0.85rem 2rem;
    font-size: 1.15rem;
    min-height: 48px;
  }
  .cover-screen { padding: 1.2rem; }
  .cover-rabbit { margin-bottom: 1.2rem; }
  .cover-subtitle { margin-bottom: 1.4rem; }
}
@media (max-width: 380px) {
  .nav-btn { padding: 0.5rem 0.8rem; font-size: 0.9rem; }
  .page-indicator { font-size: 0.85rem; min-width: 40px; }
  .page-text { font-size: 1rem; }
}
@media (hover: none) {
  .nav-btn:hover, .audio-btn:hover, .start-btn:hover { transform: none; box-shadow: inherit; }
}
@media (min-width: 1200px) {
  .page-inner { max-width: 900px; }
}
