/* ============================================
   AI Personalized Storybook — Style
   深海探險家 / Deep Sea Explorer
   Mobile-first, vertical scroll
   ============================================ */

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

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

:root {
  --primary: #0277bd;
  --primary-light: #039be5;
  --bg-warm: #0a1520;
  --text-dark: #ffffff;
  --text-medium: rgba(255,255,255,0.8);
  --text-light: rgba(255,255,255,0.5);
  --line-green: #06C755;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
  --toolbar-h: 3.2rem;
  --top-bar-h: 2.8rem;
}

html {
  scroll-behavior: smooth;
}

html, body {
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-warm);
  color: var(--text-dark);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
  overflow-y: auto;
}

/* ============================================
   Landing Page (index.html)
   ============================================ */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: linear-gradient(135deg, #0a1520 0%, #0277bd 50%, #004d40 100%);
  text-align: center;
}

.landing-cover {
  width: 260px;
  height: 340px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, #01579b 0%, #0277bd 40%, #0288d1 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(2,119,189,0.5);
  margin-bottom: 2rem;
  position: relative;
  overflow-y: auto;
}

.landing-cover::before {
  content: '';
  position: absolute;
  top: -30%;
  right: -30%;
  width: 60%;
  height: 60%;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.landing-cover .emoji-art {
  font-size: 80px;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.landing-cover h1 {
  color: white;
  font-size: 1.6rem;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
  line-height: 1.3;
}

.landing-cover .subtitle {
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

.landing-info {
  margin-bottom: 2rem;
}

.landing-info h2 {
  font-size: 1.3rem;
  color: #ffffff;
  margin-bottom: 0.3rem;
}

.landing-info p {
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 2rem;
  border: none;
  border-radius: 50px;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-width: 240px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-line {
  background: var(--line-green);
  color: white;
  box-shadow: 0 4px 16px rgba(6,199,85,0.3);
  margin-bottom: 0.8rem;
}

.btn-line:hover {
  background: #05b34d;
  box-shadow: 0 6px 24px rgba(6,199,85,0.4);
}

.btn-demo {
  background: rgba(255,255,255,0.1);
  color: #80deea;
  border: 2px solid rgba(128,222,234,0.4);
  box-shadow: var(--shadow);
}

.btn-demo:hover {
  background: rgba(255,255,255,0.15);
}

.landing-footer {
  margin-top: 2rem;
  color: rgba(255,255,255,0.4);
  font-size: 0.95rem;
}

.landing-footer a {
  color: rgba(255,255,255,0.6) !important;
}

/* ============================================
   Book Reader — vertical scroll layout
   ============================================ */

.book-container {
  width: 100%;
  padding-top: var(--top-bar-h);
  padding-bottom: var(--toolbar-h);
}

.pages-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Each page = full viewport height section */
.page {
  width: 100%;
  min-height: calc(100vh - var(--top-bar-h) - var(--toolbar-h));
  min-height: calc(100dvh - var(--top-bar-h) - var(--toolbar-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1.2rem;
  position: relative;
  overflow-y: auto;
}

/* Snap scrolling on the body */
@supports (scroll-snap-type: y mandatory) {
  body.snap-scroll {
    scroll-snap-type: y proximity;
  }
  body.snap-scroll .page {
    scroll-snap-align: start;
  }
}

/* Page divider — subtle line between pages */
.page + .page::before {
  content: '';
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

/* Illustration area */
.page-illustration {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 4/3;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.2rem;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.2), var(--shadow);
  flex-shrink: 0;
}

.page-illustration .emoji-scene {
  font-size: 56px;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
  line-height: 1.4;
  text-align: center;
}

.page-illustration::after {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background: radial-gradient(circle at 30% 40%, rgba(255,255,255,0.15) 0%, transparent 50%);
  animation: shimmer 8s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(5%, 3%); }
}

/* Text areas */
.page-text {
  text-align: center;
  max-width: 480px;
  width: 100%;
  padding: 0 0.5rem;
}

.text-zh {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.9;
  color: #ffffff;
  margin-bottom: 0.6rem;
}

.text-en {
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.8;
  color: rgba(255,255,255,0.75);
}

/* Cover page */
.page-cover .page-illustration {
  aspect-ratio: 3/4;
  max-width: 240px;
}

.page-cover .cover-title {
  font-size: 2rem;
  font-weight: 900;
  color: #ffffff;
  margin-bottom: 0.2rem;
}

.page-cover .cover-subtitle {
  font-size: 1.15rem;
  color: rgba(255,255,255,0.75);
  margin-bottom: 0.8rem;
}

.page-cover .cover-credits {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.5);
}

.cover-version {
  margin-top: 6px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.3);
  letter-spacing: 0.05em;
}

/* End page */
.page-end .end-text {
  font-size: 1rem;
  color: rgba(255,255,255,0.8);
  margin-top: 1rem;
}

.page-end .end-divider {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.5);
  margin: 1rem 0;
}

.page-end .end-credits {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.5);
  line-height: 1.8;
}

.page-end .end-brand {
  font-size: 0.9rem;
  color: #80deea;
  font-weight: 700;
  margin-top: 0.5rem;
}

/* End page actions */
.end-actions {
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
}

.end-cta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: #0277bd;
  color: #fff;
  padding: 0.8rem 1.8rem;
  border-radius: 50px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 4px 16px rgba(2,119,189,0.35);
  transition: all 0.2s;
}

.end-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(2,119,189,0.5);
}

.end-cta:active {
  transform: scale(0.97);
}

.end-cta-icon {
  font-size: 1.4rem;
}

.end-cta-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.end-cta-text small {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.8;
}

/* ============================================
   Top controls bar
   ============================================ */
.top-controls {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  z-index: 100;
  background: rgba(10,21,32,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.lang-toggle {
  display: flex;
  gap: 0;
}

.lang-toggle button {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: rgba(255,255,255,0.6);
  transition: all 0.2s;
}

.lang-toggle button:first-child {
  border-radius: 16px 0 0 16px;
}

.lang-toggle button:last-child {
  border-radius: 0 16px 16px 0;
}

.lang-toggle button:not(:first-child) {
  border-left: none;
}

.lang-toggle button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary-light);
}

.lang-toggle button.active + button {
  border-left-color: var(--primary-light);
}

.autoplay-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.autoplay-toggle:hover { border-color: #80deea; color: #80deea; }
.autoplay-toggle.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-light);
}

/* Hide text based on language mode */
body.lang-zh .text-en,
body.lang-zh .cover-subtitle { display: none !important; }
body.lang-en .text-zh,
body.lang-en .cover-title { display: none !important; }

/* ============================================
   Bottom toolbar
   ============================================ */
.toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--toolbar-h);
  background: rgba(10,21,32,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
}

.toolbar-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 0.35rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
}

.toolbar-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* Progress dots — scrollable when many pages */
.progress-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  overflow-x: auto;
  max-width: 60%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.progress-dots::-webkit-scrollbar { display: none; }

.progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: all 0.3s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.progress-dot:hover {
  background: rgba(255,255,255,0.5);
  transform: scale(1.2);
}

.progress-dot.active {
  background: #80deea;
  width: 20px;
  border-radius: 5px;
}

/* Audio play button */
.toolbar-btn.audio-btn.playing {
  color: #80deea;
  animation: pulse-audio 1.5s ease-in-out infinite;
}

@keyframes pulse-audio {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Audio player bar */
.audio-bar {
  position: fixed;
  bottom: calc(var(--toolbar-h) + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10,21,32,0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 5px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 60;
  max-width: 380px;
  width: calc(100% - 32px);
}
.audio-bar.hidden { display: none; }
.ab-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: rgba(255,255,255,0.8);
  padding: 4px 5px;
  border-radius: 50%;
  line-height: 1;
}
.ab-btn:hover { background: rgba(255,255,255,0.1); }
.ab-close { font-size: 0.8rem; color: rgba(255,255,255,0.4); }
.ab-time {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.6);
  min-width: 30px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ab-slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.ab-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #80deea;
  border: 2px solid rgba(10,21,32,0.8);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}
.ab-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #80deea;
  border: 2px solid rgba(10,21,32,0.8);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

/* Touch hint arrows — hidden in scroll mode */
.touch-hint {
  display: none;
}

/* Page backgrounds — ocean theme */
.page-bg-1  { background: linear-gradient(160deg, #01579b 0%, #0277bd 100%); }
.page-bg-2  { background: linear-gradient(160deg, #0a1520 0%, #0d2137 100%); }
.page-bg-3  { background: linear-gradient(160deg, #004d40 0%, #00695c 100%); }
.page-bg-4  { background: linear-gradient(160deg, #0d1b2a 0%, #1a237e 100%); }
.page-bg-5  { background: linear-gradient(160deg, #1b0a2e 0%, #311b92 100%); }
.page-bg-6  { background: linear-gradient(160deg, #bf360c 0%, #4e342e 100%); }
.page-bg-7  { background: linear-gradient(160deg, #01579b 0%, #006064 100%); }
.page-bg-8  { background: linear-gradient(160deg, #b71c1c 0%, #880e4f 100%); }
.page-bg-9  { background: linear-gradient(160deg, #0d2137 0%, #01579b 100%); }
.page-bg-10 { background: linear-gradient(160deg, #004d40 0%, #0277bd 100%); }

/* Illustration backgrounds — ocean theme */
.illust-bg-1  { background: linear-gradient(135deg, #01579b, #0277bd, #0288d1); }
.illust-bg-2  { background: linear-gradient(135deg, #0d2137, #1a3a5c, #0a1520); }
.illust-bg-3  { background: linear-gradient(135deg, #004d40, #00695c, #00897b); }
.illust-bg-4  { background: linear-gradient(135deg, #0d1b2a, #1a237e, #283593); }
.illust-bg-5  { background: linear-gradient(135deg, #1b0a2e, #4a148c, #311b92); }
.illust-bg-6  { background: linear-gradient(135deg, #bf360c, #6d4c41, #4e342e); }
.illust-bg-7  { background: linear-gradient(135deg, #01579b, #006064, #00838f); }
.illust-bg-8  { background: linear-gradient(135deg, #b71c1c, #c62828, #880e4f); }
.illust-bg-9  { background: linear-gradient(135deg, #0d2137, #0277bd, #01579b); }
.illust-bg-10 { background: linear-gradient(135deg, #004d40, #0277bd, #0288d1); }

/* Install banner */
.install-banner {
  position: fixed;
  bottom: calc(var(--toolbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(2,119,189,0.95);
  padding: 0.6rem 1.2rem;
  border-radius: 50px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  z-index: 200;
  animation: slideUp 0.5s ease;
  font-size: 0.85rem;
  color: white;
  white-space: nowrap;
}

.install-banner.hidden { display: none; }

.install-banner button {
  background: #80deea;
  color: #01579b;
  border: none;
  padding: 0.35rem 0.9rem;
  border-radius: 20px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.8rem;
}

.install-banner .dismiss {
  background: none;
  color: rgba(255,255,255,0.5);
  padding: 0.3rem;
  font-size: 1rem;
}

@keyframes slideUp {
  from { transform: translate(-50%, 100%); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* Page enter animation */
.page {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.page.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================
   Responsive — tablet & desktop
   ============================================ */
@media (min-width: 768px) {
  .page {
    padding: 2rem;
  }

  .page-illustration {
    max-width: 420px;
  }

  .text-zh {
    font-size: 1.6rem;
  }

  .text-en {
    font-size: 1.3rem;
  }

  .page-cover .cover-title {
    font-size: 2.8rem;
  }

  .page-cover .cover-subtitle {
    font-size: 1.4rem;
  }

  .page-cover .page-illustration {
    max-width: 300px;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .text-zh {
    font-size: 1.1rem;
  }
  .text-en {
    font-size: 0.95rem;
  }
  .page-cover .cover-title {
    font-size: 1.7rem;
  }
  .page-illustration {
    max-width: 260px;
  }
}

.toolbar-page {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.5);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
