:root {
  color-scheme: dark;
  --wood-1: #20150f;
  --wood-2: #3a271b;
  --gold: #d8b56d;
  --ink: #f8f2e8;
  --bar: rgba(25, 17, 12, .94);
  --paper: #fffdf7;
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--wood-1); }
button, input { font: inherit; }
button { color: inherit; }
.reader { height: 100dvh; display: grid; grid-template-rows: 62px minmax(0, 1fr) 70px; color: var(--ink); background: radial-gradient(circle at 50% 10%, #604631 0, var(--wood-2) 33%, var(--wood-1) 100%); }
.topbar { z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 18px; background: var(--bar); border-bottom: 1px solid rgba(216,181,109,.35); backdrop-filter: blur(12px); }
.brand { min-width: 0; display: flex; align-items: center; gap: 11px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold); }
h1 { overflow: hidden; margin: 0; font-family: Georgia, "Noto Serif KR", serif; font-size: clamp(15px, 2.2vw, 21px); font-weight: 700; letter-spacing: .02em; text-overflow: ellipsis; white-space: nowrap; }
.brand p { margin: 2px 0 0; color: #cbbda9; font-size: 11px; letter-spacing: .12em; }
.icon-btn { width: 42px; height: 42px; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.17); border-radius: 12px; background: rgba(255,255,255,.06); font-size: 22px; cursor: pointer; }
.viewer { position: relative; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 18px 24px; perspective: 1800px; overscroll-behavior: contain; }
.book-stage { position: relative; display: grid; grid-template-columns: 1fr 1fr; width: min(1180px, calc(100vw - 48px)); height: min(760px, calc(100dvh - 170px)); transform-style: preserve-3d; filter: drop-shadow(0 20px 28px rgba(0,0,0,.48)); }
.paper { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center; background: var(--paper); backface-visibility: hidden; }
.left-paper { border-radius: 10px 2px 2px 10px; box-shadow: inset -13px 0 25px -21px #321; }
.right-paper { border-radius: 2px 10px 10px 2px; box-shadow: inset 13px 0 25px -21px #321; }
.paper.hidden { display: none; }
.paper canvas { position: absolute; display: block; max-width: none; max-height: none; }
.annotation-layer { position: absolute; inset: 0; pointer-events: none; }
.annotation-link { position: absolute; pointer-events: auto; cursor: pointer; border-radius: 2px; background: transparent; transition: background .15s, box-shadow .15s; }
.annotation-link:hover, .annotation-link:focus-visible { outline: 0; background: rgba(255, 198, 48, .17); box-shadow: inset 0 0 0 2px rgba(172,117,13,.62); }
.page-label { position: absolute; z-index: 4; bottom: 5px; right: 9px; padding: 2px 6px; border-radius: 8px; color: #5c4b3c; background: rgba(255,255,255,.72); font-size: 10px; pointer-events: none; }
.left-paper .page-label { right: auto; left: 9px; }
.spine { z-index: 3; position: absolute; left: 50%; top: 0; bottom: 0; width: 20px; transform: translateX(-50%); pointer-events: none; background: linear-gradient(90deg, transparent, rgba(38,22,12,.15) 30%, rgba(255,255,255,.18) 50%, rgba(38,22,12,.16) 70%, transparent); }
.book-stage.cover-mode { grid-template-columns: 1fr; width: min(590px, calc(100vw - 48px)); }
.book-stage.cover-mode .spine { display: none; }
.book-stage.cover-mode .right-paper { display: none; }
.book-stage.cover-mode .left-paper { border-radius: 8px; box-shadow: none; }
.loading { position: absolute; z-index: 30; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 30px; text-align: center; color: #f8f1e6; background: rgba(31,20,13,.92); transition: opacity .25s, visibility .25s; }
.loading.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading span { color: #cdbfae; font-size: 13px; }
.loader { width: 38px; height: 38px; border: 3px solid rgba(255,255,255,.16); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.toolbar { z-index: 10; display: flex; align-items: stretch; justify-content: center; gap: 5px; padding: 7px 10px max(7px, env(safe-area-inset-bottom)); background: var(--bar); border-top: 1px solid rgba(216,181,109,.32); backdrop-filter: blur(12px); }
.toolbar button { min-width: 58px; border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer; transition: background .15s, border-color .15s; }
.toolbar button:hover, .toolbar button:focus-visible { outline: 0; border-color: rgba(216,181,109,.4); background: rgba(255,255,255,.08); }
.toolbar button:disabled { opacity: .34; cursor: default; }
.toolbar button span { display: block; color: #f8eee0; font-size: 24px; line-height: 25px; }
.toolbar button em { display: block; color: #cbbdab; font-size: 10px; font-style: normal; }
.page-form { align-self: center; display: flex; align-items: center; gap: 7px; height: 44px; margin: 0 5px; padding: 0 11px; border: 1px solid rgba(216,181,109,.34); border-radius: 11px; background: rgba(0,0,0,.2); }
.page-form input { width: 64px; height: 30px; padding: 3px 5px; border: 0; border-radius: 6px; color: #2c1d13; background: #fffdf7; text-align: center; font-weight: 700; }
.page-form span { min-width: 52px; color: #d9cdbc; font-size: 13px; white-space: nowrap; }
.toast { z-index: 40; position: fixed; left: 50%; bottom: 86px; transform: translate(-50%, 12px); max-width: calc(100vw - 30px); padding: 10px 15px; border: 1px solid rgba(216,181,109,.45); border-radius: 12px; color: #fff; background: rgba(24,15,10,.9); box-shadow: 0 8px 30px rgba(0,0,0,.3); opacity: 0; visibility: hidden; transition: .2s; }
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.flip-leaf { z-index: 20; position: absolute; top: 0; width: 50%; height: 100%; background-color: var(--paper); background-position: center; background-repeat: no-repeat; background-size: contain; box-shadow: 0 8px 25px rgba(0,0,0,.34); backface-visibility: hidden; transform-style: preserve-3d; pointer-events: none; }
.flip-leaf.next { left: 50%; transform-origin: left center; animation: flipNext .6s cubic-bezier(.55,.05,.22,1) forwards; }
.flip-leaf.prev { left: 0; transform-origin: right center; animation: flipPrev .6s cubic-bezier(.55,.05,.22,1) forwards; }
@keyframes flipNext { 0% { transform: rotateY(0); filter: brightness(1); } 55% { filter: brightness(.62); } 100% { transform: rotateY(-180deg); filter: brightness(.94); } }
@keyframes flipPrev { 0% { transform: rotateY(0); filter: brightness(1); } 55% { filter: brightness(.62); } 100% { transform: rotateY(180deg); filter: brightness(.94); } }
.sr-only { position: absolute!important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 779px) {
  .reader { grid-template-rows: 56px minmax(0, 1fr) 66px; }
  .topbar { padding: 7px 10px; }
  .brand-mark { width: 31px; height: 31px; }
  .brand p { display: none; }
  .icon-btn { width: 38px; height: 38px; }
  .viewer { padding: 10px; }
  .book-stage, .book-stage.cover-mode { grid-template-columns: 1fr; width: min(680px, calc(100vw - 20px)); height: calc(100dvh - 142px); }
  .book-stage .left-paper, .book-stage.cover-mode .left-paper { display: none; }
  .book-stage .right-paper, .book-stage.cover-mode .right-paper { display: grid; border-radius: 8px; box-shadow: none; }
  .book-stage .spine { display: none; }
  .right-paper .page-label { right: 8px; left: auto; }
  .toolbar { gap: 1px; padding-inline: 3px; }
  .toolbar button { min-width: 43px; padding: 2px; }
  .toolbar button span { font-size: 22px; }
  .toolbar button em { font-size: 9px; }
  .page-form { gap: 4px; margin: 0 2px; padding: 0 7px; }
  .page-form input { width: 51px; }
  .page-form span { min-width: 43px; font-size: 11px; }
  .flip-leaf, .flip-leaf.next, .flip-leaf.prev { left: 0; width: 100%; transform-origin: left center; }
}
@media (max-width: 430px) {
  #zoomOutBtn, #zoomInBtn, #fullscreenBtn { display: none; }
}

