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

:root {
  --pastel-sage: #a8c3b1;
  --pastel-sage-hover: #96b4a0;
  --pastel-mint: #cbdcd0;
  --cream: #FAF8F5;
  --warm-white: #FFFFFF;
  --text-dark: #2f3e33;
  --text-mid: #5c6f61;
  --text-light: #8fa093;
  --shadow-book: rgba(47, 62, 51, 0.15);
  --shadow-soft: rgba(47, 62, 51, 0.08);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f4f7f5;
  font-family: 'Noto Sans KR', sans-serif;
}

/* ── BACKGROUND ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 80%, rgba(168, 195, 177, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 20%, rgba(203, 220, 208, 0.35) 0%, transparent 60%),
    linear-gradient(135deg, #f4f7f5 0%, #e5ece8 50%, #d8e5dd 100%);
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(168, 195, 177, 0.15) 1px, transparent 0);
  background-size: 32px 32px;
  z-index: 0;
}

/* ── HEADER ── */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 60px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(168, 195, 177, 0.3);
  box-shadow: 0 4px 20px rgba(47, 62, 51, 0.05);
}

#header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

#header .brand-leaf {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--pastel-sage), var(--pastel-mint));
  border-radius: 50% 10% 50% 10%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 10px rgba(168, 195, 177, 0.3);
}

#header .brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
}

#header .brand-sub {
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 10px;
  color: var(--text-light);
}

#header .brand-main {
  font-family: 'Noto Serif KR', serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dark);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#page-info {
  color: var(--text-mid);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(168, 195, 177, 0.5);
  border-radius: 8px;
  background: rgba(168, 195, 177, 0.15);
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.25s ease;
}

.icon-btn:hover {
  background: var(--pastel-sage);
  border-color: var(--pastel-sage);
  color: #fff;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

#fullscreen-btn .icon-compress {
  display: none;
}

body.is-fullscreen #fullscreen-btn .icon-expand {
  display: none;
}

body.is-fullscreen #fullscreen-btn .icon-compress {
  display: block;
}

/* ── FULLSCREEN ── */
body.is-fullscreen #zoom-hint {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

/* ── MAIN STAGE ── */
#stage {
  position: fixed;
  inset: 60px 0 70px 0;
  z-index: 1;
  overflow: hidden;
  perspective: 2000px;
  touch-action: none;
}

#zoom-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  will-change: transform;
}

#stage.is-zoomed {
  cursor: grab;
}

#stage.is-panning {
  cursor: grabbing;
}

#stage.is-zoomed,
#stage.is-panning {
  user-select: none;
  -webkit-user-select: none;
}

/* ── BOOK WRAPPER ── */
#book-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 30px 60px rgba(0,0,0,0.5));
}

/* ── FLIP BOOK ── */
#flipbook {
  position: relative;
  width: var(--book-width, 380px);
  height: var(--book-height, 540px);
}

/* ── PAGE CONTAINER ── */
.page-container {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  transform-origin: left center;
  z-index: 1;
}

.page-container.flipped {
  transform: rotateY(-180deg);
  z-index: 2;
}

.page-container.animating {
  z-index: 50;
}

/* ── CANVAS FACES ── */
.page-front,
.page-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 2px 8px 8px 2px;
  overflow: hidden;
  background: var(--cream);
}

.page-back {
  transform: rotateY(180deg);
  border-radius: 8px 2px 2px 8px;
}

.page-front canvas,
.page-back canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Page shadow/shine overlay */
.page-front::after,
.page-back::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgba(0,0,0,0.08) 0%,
    transparent 15%,
    transparent 85%,
    rgba(0,0,0,0.05) 100%
  );
}

/* Spine shadow */
.page-front::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  background: linear-gradient(to right, rgba(0,0,0,0.12), transparent);
  z-index: 1;
}

/* ── SINGLE PAGE ── */
#single-page {
  position: relative;
  width: var(--book-width, 380px);
  height: var(--book-height, 540px);
  border-radius: 2px 8px 8px 2px;
  overflow: hidden;
  background: var(--cream);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

#single-page canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── BOOK SPINE ── */
#book-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 8px;
  transform: translateX(-50%);
  background: linear-gradient(to right, #0d2b1a, #1a4a2e, #0d2b1a);
  z-index: 200;
  border-radius: 1px;
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
  pointer-events: none;
}

/* Double page layout */
#double-page {
  display: flex;
  position: relative;
  width: calc(var(--book-width, 380px) * 2);
  height: var(--book-height, 540px);
}

#double-page .left-side,
#double-page .right-side {
  width: var(--book-width, 380px);
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--cream);
}

#double-page .left-side {
  border-radius: 8px 0 0 8px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.2);
}

#double-page .right-side {
  border-radius: 0 8px 8px 0;
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}

#double-page canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Flip animation overlay */
#flip-overlay {
  position: absolute;
  top: 0;
  width: var(--book-width, 380px);
  height: var(--book-height, 540px);
  transform-origin: left center;
  transform-style: preserve-3d;
  z-index: 100;
  pointer-events: none;
  display: none;
}

#flip-overlay.active {
  display: block;
}

#flip-overlay .flip-front,
#flip-overlay .flip-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

#flip-overlay .flip-back {
  transform: rotateY(180deg);
}

#flip-overlay canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── LOADING ── */
#loading {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f4f7f5 0%, #e5ece8 100%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loading.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-leaf {
  width: 64px;
  height: 64px;
  margin-bottom: 24px;
  animation: leafSpin 2s ease-in-out infinite;
}

@keyframes leafSpin {
  0%, 100% { transform: rotate(-10deg) scale(1); }
  50% { transform: rotate(10deg) scale(1.1); }
}

.loader-text {
  color: var(--text-dark);
  font-family: 'Noto Serif KR', serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.15em;
  margin-bottom: 20px;
}

.loader-bar {
  width: 200px;
  height: 4px;
  background: rgba(168, 195, 177, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.loader-progress {
  height: 100%;
  background: linear-gradient(90deg, var(--pastel-mint), var(--pastel-sage));
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ── NAVIGATION ── */
#nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(168, 195, 177, 0.3);
  box-shadow: 0 -4px 20px rgba(47, 62, 51, 0.05);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: 1px solid rgba(168, 195, 177, 0.5);
  border-radius: 30px;
  background: rgba(168, 195, 177, 0.15);
  color: var(--text-dark);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.05em;
}

.nav-btn:hover:not(:disabled) {
  background: var(--pastel-sage);
  border-color: var(--pastel-sage);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(168, 195, 177, 0.4);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: rgba(168, 195, 177, 0.05);
  border-color: rgba(168, 195, 177, 0.2);
  color: var(--text-light);
}

.nav-btn svg {
  width: 16px;
  height: 16px;
}

/* Table of contents dot nav */
#toc-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
}

.toc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(168, 195, 177, 0.4);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid rgba(168, 195, 177, 0.2);
}

.toc-dot.active {
  background: var(--pastel-sage);
  transform: scale(1.4);
  border-color: var(--pastel-sage);
  box-shadow: 0 0 8px rgba(168, 195, 177, 0.6);
}

.toc-dot:hover {
  background: var(--pastel-sage-hover);
}

/* ── FLOATING QUICK CONTROLS ── */
#quick-controls {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(168, 195, 177, 0.35);
  border-radius: 30px;
  box-shadow: 0 10px 30px rgba(47, 62, 51, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#quick-controls:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--pastel-sage);
  box-shadow: 0 15px 40px rgba(47, 62, 51, 0.12), 0 0 15px rgba(168, 195, 177, 0.2);
  transform: translateY(-50%) scale(1.02);
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-mid);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  outline: none;
}

.control-btn:hover:not(:disabled) {
  background: rgba(168, 195, 177, 0.2);
  color: var(--text-dark);
  transform: scale(1.1);
}

.control-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.control-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.control-btn svg {
  width: 20px;
  height: 20px;
  transition: stroke-width 0.2s ease, transform 0.2s ease;
}

.control-divider {
  width: 20px;
  height: 1px;
  background: rgba(168, 195, 177, 0.25);
  margin: 4px 0;
}

#side-fullscreen-btn .icon-compress {
  display: none;
}

body.is-fullscreen #side-fullscreen-btn .icon-expand {
  display: none;
}

body.is-fullscreen #side-fullscreen-btn .icon-compress {
  display: block;
}

/* For fullscreen handling of quick-controls */
body.is-fullscreen #quick-controls {
  right: 16px;
  background: rgba(255, 255, 255, 0.55);
  border-color: rgba(168, 195, 177, 0.25);
}

body.is-fullscreen #quick-controls:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--pastel-sage);
}

@media (max-width: 600px) {
  #quick-controls {
    right: 12px;
    padding: 6px;
    gap: 6px;
  }
  .control-btn {
    width: 36px;
    height: 36px;
  }
  .control-btn svg {
    width: 16px;
    height: 16px;
  }
  .control-divider {
    width: 16px;
  }
}

/* ── ZOOM ── */
#zoom-hint {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 50;
  color: var(--text-light);
  font-size: 11px;
  letter-spacing: 0.1em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  pointer-events: none;
  animation: fadeHint 4s ease forwards;
}

@keyframes fadeHint {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ── PAGE TURN SOUND VISUAL ── */
.turn-ripple {
  position: fixed;
  border-radius: 50%;
  border: 2px solid var(--pastel-sage);
  pointer-events: none;
  animation: rippleOut 0.6s ease-out forwards;
  z-index: 200;
}

@keyframes rippleOut {
  from { transform: scale(0); opacity: 1; }
  to { transform: scale(4); opacity: 0; }
}

/* ── FADE-IN ANIMATION FOR SINGLE PAGE ── */
@keyframes pageFadeIn {
  from { opacity: 0.6; transform: scale(0.995); }
  to { opacity: 1; transform: scale(1); }
}

.page-fade-in {
  animation: pageFadeIn 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  :root {
    --book-width: 300px;
    --book-height: 425px;
  }
}

@media (max-width: 900px) {
  #quick-controls {
    display: none !important;
  }
}

@media (max-width: 600px) {
  :root {
    --book-width: 240px;
    --book-height: 340px;
  }
  #header {
    height: 50px;
    padding: 0 16px;
  }
  #header .brand {
    gap: 8px;
  }
  #header .brand-leaf {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  #header .brand-sub {
    font-size: 8px;
  }
  #header .brand-main {
    font-size: 12px;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
  }
  .icon-btn svg {
    width: 16px;
    height: 16px;
  }
  #nav-bar {
    height: 60px;
    gap: 8px;
    justify-content: space-between;
    padding: 0 12px;
  }
  .nav-btn {
    padding: 8px 16px;
    font-size: 12px;
    gap: 4px;
  }
  .nav-btn svg {
    width: 14px;
    height: 14px;
  }
  #toc-nav {
    flex: 1;
    justify-content: center;
    gap: 4px;
    padding: 0 4px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #toc-nav::-webkit-scrollbar {
    display: none;
  }
  .toc-dot {
    width: 6px;
    height: 6px;
    flex-shrink: 0;
  }
  .toc-dot.active {
    transform: scale(1.3);
  }
  #stage {
    inset: 50px 0 60px 0;
  }
  #zoom-hint {
    top: 65px;
    right: 10px;
  }
}

@media (max-width: 480px) {
  #header .brand-sub {
    display: none;
  }
}
