/* ============================================================
   달빛 마을 아이들 — Korean Children's Story Stylesheet
   Works fully offline. No external fonts, images, or CDNs.
   ============================================================ */

/* -------- CSS Variables (Light theme default) -------- */
:root {
  --bg: #fffaf0;
  --bg-soft: #f5e6d3;
  --bg-card: #fff8ee;
  --text: #3d2817;
  --text-soft: #6b4423;
  --accent: #d2691e;
  --accent-soft: #e8a87c;
  --accent-deep: #a0522d;
  --link: #b8860b;
  --link-hover: #8b6914;
  --border: #d4a574;
  --border-soft: #e8d5b5;
  --shadow: rgba(139, 69, 19, 0.18);
  --shadow-soft: rgba(139, 69, 19, 0.08);
  --nav-bg: rgba(255, 250, 240, 0.92);
  --progress: #e67e22;
  --btn-bg: #fff;
  --btn-text: #5d4037;
  --sky-from: #ffe4c4;
  --sky-to: #ffdab9;
  --mountain-1: #8fbc8f;
  --mountain-2: #6b8e6b;
  --mountain-3: #556b2f;
  --river: #87ceeb;
  --ground: #90c290;
  --ground-deep: #6b8e3d;
}

/* -------- Dark theme -------- */
body.dark-mode {
  --bg: #1a1428;
  --bg-soft: #241c38;
  --bg-card: #2a2048;
  --text: #f0e6d2;
  --text-soft: #c4b898;
  --accent: #ffa040;
  --accent-soft: #d4a060;
  --accent-deep: #b8730d;
  --link: #ffd700;
  --link-hover: #ffdf4f;
  --border: #4a3870;
  --border-soft: #3a2c58;
  --shadow: rgba(0, 0, 0, 0.5);
  --shadow-soft: rgba(0, 0, 0, 0.3);
  --nav-bg: rgba(26, 20, 40, 0.92);
  --progress: #ffa040;
  --btn-bg: #3a2c58;
  --btn-text: #f0e6d2;
  --sky-from: #0d0820;
  --sky-to: #1a1240;
  --mountain-1: #2c3858;
  --mountain-2: #1f2a48;
  --mountain-3: #142038;
  --river: #2a4858;
  --ground: #2c3a28;
  --ground-deep: #1a2818;
}

/* -------- Large-text mode -------- */
body.large-text {
  font-size: 1.5rem;
}
body.large-text h1 { font-size: 3rem; }
body.large-text h2 { font-size: 2.5rem; }
body.large-text h3 { font-size: 2rem; }
body.large-text .story-text { font-size: 1.6rem; line-height: 2.1; }
body.large-text .chapter-list li { font-size: 1.35rem; }
body.large-text .btn { font-size: 1.2rem; padding: 0.8rem 1.8rem; }

/* -------- Reset & base -------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", "Noto Sans KR", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  transition: background 0.5s ease, color 0.5s ease;
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 1.05rem;
}

/* -------- Reading progress bar -------- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 5px;
  width: 0%;
  background: linear-gradient(90deg, var(--progress), var(--accent-soft));
  z-index: 1000;
  transition: width 0.1s ease;
  box-shadow: 0 0 8px var(--progress);
}

/* -------- Top navigation -------- */
.top-nav {
  position: sticky;
  top: 0;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 2px solid var(--border-soft);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  flex-wrap: wrap;
  gap: 0.6rem;
  box-shadow: 0 2px 12px var(--shadow-soft);
}

.nav-brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-deep);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.nav-brand .moon {
  display: inline-block;
  width: 22px;
  height: 22px;
  background: radial-gradient(circle at 35% 35%, #fff8dc, #ffd700 40%, #daa520 75%, #b8860b);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
  animation: moonGlow 4s ease-in-out infinite;
}

@keyframes moonGlow {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 215, 0, 0.6); }
  50% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.9); }
}

.nav-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0.45rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.nav-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.nav-btn:active { transform: translateY(0); }

.nav-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* -------- Page layout -------- */
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
}

/* -------- Home / index page -------- */
.hero {
  text-align: center;
  padding: 2rem 1rem 2.5rem;
}

.hero h1 {
  font-size: 2.6rem;
  color: var(--accent-deep);
  margin-bottom: 0.4rem;
  letter-spacing: -1px;
  text-shadow: 1px 1px 0 var(--accent-soft);
}

.hero .subtitle {
  font-size: 1.2rem;
  color: var(--text-soft);
  margin-bottom: 2rem;
}

/* -------- SVG illustration frame -------- */
.illustration {
  width: 100%;
  margin: 0 auto 2rem;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 30px var(--shadow);
  border: 3px solid var(--border);
  background: var(--sky-to);
  position: relative;
}

.illustration svg {
  display: block;
  width: 100%;
  height: auto;
}

/* -------- Story text -------- */
.story-text {
  max-width: 680px;
  margin: 0 auto;
  font-size: 1.15rem;
  line-height: 2;
  color: var(--text);
  text-align: justify;
  word-break: keep-all;
}

.story-text p {
  margin-bottom: 1.3rem;
  animation: fadeUp 0.7s ease both;
}

.story-text p:nth-child(2) { animation-delay: 0.1s; }
.story-text p:nth-child(3) { animation-delay: 0.2s; }
.story-text p:nth-child(4) { animation-delay: 0.3s; }
.story-text p:nth-child(5) { animation-delay: 0.4s; }
.story-text p:nth-child(6) { animation-delay: 0.5s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -------- Chapter heading -------- */
.chapter-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.chapter-header .ch-num {
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 4px;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.chapter-header h2 {
  font-size: 2rem;
  color: var(--accent-deep);
  text-shadow: 1px 1px 0 var(--accent-soft);
}

/* -------- Chapter list (index) -------- */
.chapter-list {
  list-style: none;
  max-width: 620px;
  margin: 1rem auto;
  display: grid;
  gap: 0.7rem;
}

.chapter-list li a {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.4rem;
  background: var(--bg-card);
  border: 2px solid var(--border-soft);
  border-radius: 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 1.1rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.chapter-list li a::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 6px;
  background: var(--accent);
  transform: scaleY(0);
  transition: transform 0.3s ease;
  transform-origin: top;
}

.chapter-list li a:hover {
  border-color: var(--accent);
  background: var(--bg-soft);
  transform: translateX(6px);
  box-shadow: 0 4px 14px var(--shadow-soft);
}

.chapter-list li a:hover::before { transform: scaleY(1); }

.chapter-list .ch-mark {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 50px;
}

.chapter-list .ch-title {
  font-weight: 600;
  flex: 1;
}

/* -------- Bottom navigation (Prev/Next) -------- */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px dashed var(--border-soft);
  gap: 1rem;
  flex-wrap: wrap;
}

.bottom-nav .btn {
  flex: 1;
  min-width: 140px;
  max-width: 260px;
}

.btn {
  display: inline-block;
  padding: 0.7rem 1.4rem;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 2px solid var(--border);
  border-radius: 16px;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  text-align: center;
}

.btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* -------- Settings panel -------- */
.settings-hint {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-soft);
  opacity: 0.8;
}

.settings-hint kbd {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--accent-deep);
}

/* -------- Footer -------- */
.foot {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px dashed var(--border-soft);
  color: var(--text-soft);
  font-size: 0.9rem;
}

/* -------- SVG common animations -------- */
@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes floatY2 {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
@keyframes sway {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}
@keyframes swaySoft {
  0%, 100% { transform: rotate(-0.8deg); }
  50% { transform: rotate(0.8deg); }
}
@keyframes twinkle {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
@keyframes drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(40px); }
}
@keyframes waterShine {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}
@keyframes lanternFlicker {
  0%, 100% { opacity: 0.85; }
  45% { opacity: 1; }
  50% { opacity: 0.7; }
  55% { opacity: 0.95; }
}
@keyframes birdFly {
  0% { transform: translate(0, 0); }
  50% { transform: translate(30px, -10px); }
  100% { transform: translate(60px, 0); }
}
@keyframes petalFall {
  0% { transform: translate(0,0) rotate(0); opacity: 0.9; }
  100% { transform: translate(-20px, 40px) rotate(360deg); opacity: 0; }
}
@keyframes grassDance {
  0%, 100% { transform: skewX(0); }
  50% { transform: skewX(3deg); }
}
@keyframes fireflyGlow {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}
@keyframes smokeRise {
  0% { transform: translateY(0) scaleX(1); opacity: 0.5; }
  100% { transform: translateY(-30px) scaleX(1.5); opacity: 0; }
}
@keyframes ripple {
  0% { r: 2; opacity: 0.8; }
  100% { r: 18; opacity: 0; }
}
@keyframes leafSpin {
  0% { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}

/* Apply animations to SVG classes */
.svg-cloud { animation: drift 18s linear infinite alternate; }
.svg-cloud2 { animation: drift 25s linear infinite alternate-reverse; }
.svg-tree-sway { transform-origin: bottom center; animation: sway 6s ease-in-out infinite; }
.svg-tree-sway2 { transform-origin: bottom center; animation: swaySoft 7s ease-in-out infinite; }
.svg-float { animation: floatY 4s ease-in-out infinite; }
.svg-float2 { animation: floatY2 5s ease-in-out infinite; }
.svg-twinkle { animation: twinkle 3s ease-in-out infinite; }
.svg-twinkle2 { animation: twinkle 4s ease-in-out infinite; animation-delay: 1s; }
.svg-water { animation: waterShine 4s ease-in-out infinite; }
.svg-water2 { animation: waterShine 5s ease-in-out infinite; animation-delay: 1.5s; }
.svg-lantern { animation: lanternFlicker 2.5s ease-in-out infinite; }
.svg-lantern2 { animation: lanternFlicker 3s ease-in-out infinite; animation-delay: 0.6s; }
.svg-bird { animation: birdFly 8s ease-in-out infinite; }
.svg-bird2 { animation: birdFly 10s ease-in-out infinite; animation-delay: 1s; }
.svg-grass { transform-origin: bottom; animation: grassDance 3s ease-in-out infinite; }
.svg-firefly { animation: fireflyGlow 2s ease-in-out infinite; }
.svg-firefly2 { animation: fireflyGlow 2.5s ease-in-out infinite; animation-delay: 0.7s; }
.svg-smoke { animation: smokeRise 4s ease-out infinite; }
.svg-smoke2 { animation: smokeRise 5s ease-out infinite; animation-delay: 1s; }
.svg-petal { animation: petalFall 6s linear infinite; }
.svg-petal2 { animation: petalFall 8s linear infinite; animation-delay: 2s; }
.svg-leaf { transform-origin: center; animation: leafSpin 12s linear infinite; }

/* Dark-mode SVG adjustments (don't override scene colors) */
body.dark-mode .svg-sky-bright { opacity: 0; }
body.dark-mode .svg-sky-dark { opacity: 1; }

/* -------- Responsive -------- */
@media (max-width: 700px) {
  .hero h1 { font-size: 1.8rem; }
  .hero .subtitle { font-size: 1rem; }
  .story-text { font-size: 1.05rem; }
  .page { padding: 1rem 0.8rem 3rem; }
  .top-nav { padding: 0.6rem 0.8rem; }
  .nav-brand { font-size: 1.05rem; }
  .nav-btn { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
  .chapter-header h2 { font-size: 1.5rem; }
  .chapter-list li a { padding: 0.8rem 1rem; font-size: 1rem; }
  .bottom-nav .btn { min-width: 110px; font-size: 0.95rem; }
  body.large-text { font-size: 1.25rem; }
  body.large-text h1 { font-size: 2rem; }
  body.large-text h2 { font-size: 1.7rem; }
  body.large-text .story-text { font-size: 1.3rem; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.5rem; }
  .nav-brand .label { display: none; }
  .nav-btn .label { display: none; }
}

/* Print-friendly */
@media print {
  .top-nav, .progress-bar, .bottom-nav, .settings-hint { display: none; }
  .illustration { box-shadow: none; border: 1px solid #999; }
}

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