* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: #191919;
  color: #f4f4f4;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
}

button,
input {
  font: inherit;
}

.ebook-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  height: 64px;
  padding: 10px 16px;
  background: rgba(20, 20, 20, 0.96);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
}

.brand strong {
  font-size: 16px;
  line-height: 1.2;
}

.brand span {
  font-size: 12px;
  color: #cfcfcf;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 8px 11px;
  color: #fff;
  background: #333;
  cursor: pointer;
}

button:hover {
  background: #444;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #ddd;
}

.page-jump input {
  width: 64px;
  padding: 7px 6px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #111;
  color: #fff;
  text-align: center;
}

.stage {
  flex: 1;
  min-height: calc(100vh - 64px);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.08), transparent 40%),
    #191919;
}

.book {
  width: min(96vw, 980px);
  min-height: calc(100vh - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1400px;
}

.page-wrap {
  transform-origin: center center;
  transition: transform 180ms ease;
  display: inline-block;
}

.page-wrap.flip-next {
  animation: flipNext 320ms ease;
}

.page-wrap.flip-prev {
  animation: flipPrev 320ms ease;
}

.page-frame {
  position: relative;
  display: inline-block;
}

.page-image {
  display: block;
  max-width: min(92vw, 920px);
  max-height: calc(100vh - 150px);
  width: auto;
  height: auto;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
  pointer-events: auto;
}

/* 데스크톱용 좌우 화살표 - 화면 폭에 따라 자동 위치 조정 */
.nav-zone {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  width: clamp(70px, 9vw, 160px);
  height: clamp(110px, 16vw, 220px);
  border: none;
  border-radius: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.2s ease, opacity 0.2s ease, color 0.2s ease;
  padding: 0;
}

.nav-zone:hover {
  background: transparent;
  color: #ffffff;
}

.nav-zone:active {
  transform: translateY(-50%) scale(0.96);
}

/* 
  핵심 수정:
  화면이 넓을 때는 페이지 바깥쪽에 여유 있게 배치하고,
  화면이 좁아질수록 화살표가 화면 안쪽으로 자동 이동합니다.
*/
.nav-zone.left {
  left: clamp(8px, calc((100vw - 980px) / 2 - 90px), 120px);
}

.nav-zone.right {
  right: clamp(8px, calc((100vw - 980px) / 2 - 90px), 120px);
}

.nav-zone:disabled {
  opacity: 0.18;
  cursor: not-allowed;
}

.nav-arrow {
  font-size: clamp(76px, 12vw, 168px);
  line-height: 1;
  font-weight: 700;
  margin-top: -10px;
}

/* 모바일용: 이미지 내부 좌/우 25% 터치영역 */
.page-tap-zone {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  z-index: 6;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.page-tap-zone.prev {
  left: 0;
}

.page-tap-zone.next {
  right: 0;
}

.mobile-controls {
  display: none;
  gap: 10px;
  padding: 10px;
  background: #111;
}

.mobile-controls button {
  flex: 1;
  padding: 12px;
}

@keyframes flipNext {
  0% { transform: rotateY(0deg) scale(1); opacity: 1; }
  50% { transform: rotateY(-18deg) scale(0.985); opacity: 0.74; }
  100% { transform: rotateY(0deg) scale(1); opacity: 1; }
}

@keyframes flipPrev {
  0% { transform: rotateY(0deg) scale(1); opacity: 1; }
  50% { transform: rotateY(18deg) scale(0.985); opacity: 0.74; }
  100% { transform: rotateY(0deg) scale(1); opacity: 1; }
}

@media (max-width: 980px) {
  .nav-zone.left {
    left: 8px;
  }

  .nav-zone.right {
    right: 8px;
  }

  .nav-arrow {
    font-size: clamp(70px, 11vw, 110px);
  }
}

@media (max-width: 720px) {
  .toolbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
  }

  .controls #prevBtn,
  .controls #nextBtn,
  .controls #fullscreenBtn {
    display: none;
  }

  .stage {
    min-height: calc(100vh - 140px);
    padding: 12px;
  }

  .page-image {
    max-width: 96vw;
    max-height: calc(100vh - 190px);
  }

  /* 모바일에서는 큰 화살표 숨김 */
  .nav-zone {
    display: none;
  }

  /* 모바일에서는 하단 버튼도 숨김 */
  .mobile-controls {
    display: none;
  }

  /* 모바일에서는 이북 이미지 내부 좌/우 터치 영역 활성화 */
  .page-tap-zone {
    display: block;
  }
}

@media print {
  body {
    display: none !important;
  }
}