@font-face {
  font-family: "Nanum";
  src: local("Nanum Myeongjo");
}

:root {
  --paper: #f2e9d8;
  --paper-dark: #e6d9bf;
  --ink: #2a2620;
  --ink-soft: #5a5245;
  --accent: #33415c;
  --accent-soft: #6b7a99;
  --line: #d8c9a3;
  --unsure: #a05a3a;
  --shadow: rgba(30, 24, 10, 0.18);
  --header-h: 52px;
  --footer-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper-dark);
  color: var(--ink);
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- header ---------- */
.topbar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.topbar .book-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .page-label {
  font-size: 12px;
  color: var(--ink-soft);
  flex: 0 0 auto;
  margin-left: 10px;
}

/* ---------- main viewer ---------- */
.viewer {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-stage {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}

.page-slide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 320ms cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}

.page-slide.no-anim { transition: none; }

/* image pane */
.img-pane {
  position: relative;
  flex: 0 0 46%;
  background: #1c1a16;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-pane img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  transform-origin: center center;
  transform: translate(0px, 0px) scale(1);
}

.img-pane img.settling {
  transition: transform 180ms ease;
}

.zoom-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(20,18,14,0.55);
  color: #f2e9d8;
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 200ms ease;
}

/* text pane */
.text-pane {
  flex: 1 1 54%;
  background: var(--paper);
  overflow-y: auto;
  padding: 16px 18px 24px;
  -webkit-overflow-scrolling: touch;
}

.text-pane::-webkit-scrollbar { width: 3px; }
.text-pane::-webkit-scrollbar-thumb { background: var(--line); }

.pane-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--accent-soft);
  margin: 0 0 4px;
}

.page-tag {
  display: inline-block;
  font-size: 12px;
  color: var(--accent);
  background: rgba(51, 65, 92, 0.09);
  border: 1px solid rgba(51, 65, 92, 0.25);
  padding: 2px 9px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.unsure-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--unsure);
  background: rgba(160, 90, 58, 0.1);
  border: 1px solid rgba(160, 90, 58, 0.28);
  padding: 1px 8px;
  border-radius: 20px;
  margin-left: 6px;
}

.block-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 18px 0 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.block-title::before {
  content: "";
  width: 3px;
  height: 12px;
  background: var(--accent);
  display: inline-block;
  border-radius: 2px;
}

.transcript-text {
  font-family: "Nanum Myeongjo", "Noto Serif KR", serif;
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: keep-all;
  min-height: 1.4em;
}

.interp-text {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: keep-all;
  min-height: 1.4em;
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink 0.9s steps(1) infinite;
}
.caret.done { display: none; }

@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- footer / controls ---------- */
.footer {
  flex: 0 0 auto;
  height: var(--footer-h);
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 20;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff8ea;
  color: var(--accent);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.nav-btn:active { transform: scale(0.92); }
.nav-btn:disabled { opacity: 0.3; }

.progress-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}

.progress-track {
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 250ms ease;
}

.progress-count {
  font-size: 11px;
  color: var(--ink-soft);
}

/* swipe edge affordance */
.edge-tap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 15%;
  z-index: 5;
}
.edge-tap.left { left: 0; }
.edge-tap.right { right: 0; }

/* wide screens: side by side */
@media (min-width: 760px) {
  .page-slide { flex-direction: row; }
  .img-pane { flex: 0 0 50%; }
  .text-pane { flex: 0 0 50%; }
  .transcript-text { font-size: 18px; }
}

@media (min-width: 1100px) {
  body { align-items: center; }
  .app {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    height: 100dvh;
    box-shadow: 0 0 40px var(--shadow);
  }
}
