
:root {
  color-scheme: light;
  --ink: #f8f9f8;
  --muted: #a9b0b2;
  --surface: #191d1f;
  --surface-2: #24292c;
  --stage: #dfe2df;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #e7b94e;
  --page-ratio: 0.65;
  --desktop-book-width: min(calc(100vw - 164px), calc((100vh - 132px) * var(--page-ratio) * 2));
  font-family: Pretendard, "Noto Sans", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--stage); color: var(--ink); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 30;
  min-width: 220px;
  height: 64px;
  display: flex;
  align-items: center;
  padding: 10px 18px;
  pointer-events: none;
}

.viewer-brand { min-width: 0; display: flex; align-items: center; gap: 10px; color: #202628; }
.viewer-brand.has-logo { width: 190px; height: 42px; }
.viewer-brand img { width: 100%; height: 100%; object-fit: contain; object-position: left center; }
.viewer-brand > svg { width: 25px; height: 25px; }
.viewer-brand h1 {
  margin: 0;
  max-width: min(52vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0;
}
.viewer-brand.has-logo h1 { display: none; }
.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.icon-button:hover { background: rgba(255, 255, 255, 0.11); }
.icon-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-button.compact { width: 34px; height: 34px; }

.reader { position: fixed; inset: 0; }
.stage {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 46px 82px 72px;
  background: var(--stage);
  touch-action: pan-y;
}

.book-shell {
  position: relative;
  width: var(--desktop-book-width);
  height: min(calc(100vh - 132px), calc((100vw - 164px) / (var(--page-ratio) * 2)));
  min-width: 260px;
  min-height: 360px;
  display: grid;
  place-items: center;
  transform-origin: center center;
  transition: transform .16s ease;
  filter: drop-shadow(0 12px 18px rgba(28, 34, 35, .16));
}

.page-flip-book {
  width: 100%;
  height: 100%;
}
.page-flip-book canvas { cursor: default; }
.page-flip-book.stf__parent { margin: 0 !important; }

.reference-curl-layer {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.reference-curl-layer.active { display: block; }

.current-bookmark {
  position: absolute;
  z-index: 9;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(25, 29, 31, .18);
  border-radius: 50%;
  background: rgba(255, 255, 255, .94);
  color: #566063;
  cursor: pointer;
  opacity: .58;
  transition: opacity .16s ease, transform .16s ease, color .16s ease, background .16s ease;
}
.book-shell:hover .current-bookmark, .current-bookmark:focus-visible, .current-bookmark.active { opacity: 1; }
.current-bookmark:hover { transform: translateY(-2px); background: white; }
.current-bookmark.active { color: #ba8618; background: #fff9e8; }
.current-bookmark.active svg { fill: currentColor; }
.current-bookmark svg { width: 18px; height: 18px; pointer-events: none; }

.page-edge {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 52px;
  width: calc((100vw - var(--desktop-book-width)) / 2);
  display: flex;
  align-items: center;
  padding: 0 15px;
  border: 0;
  background: transparent;
  color: #505a5d;
  cursor: pointer;
  opacity: .45;
  transition: opacity .16s ease;
}
.page-edge svg { width: 34px; height: 34px; padding: 7px; border-radius: 50%; transition: transform .16s ease, background .16s ease; }
.page-edge:hover { background: transparent; opacity: 1; }
.page-edge:hover svg { background: rgba(255, 255, 255, .62); }
.page-edge.previous:hover svg { transform: translateX(-4px); }
.page-edge.next:hover svg { transform: translateX(4px); }
.page-edge.previous { left: 0; justify-content: flex-start; }
.page-edge.next { right: 0; justify-content: flex-end; }
.page-edge:disabled { opacity: .2; cursor: default; }

.controlbar {
  position: fixed;
  z-index: 12;
  inset: auto 0 0;
  height: 52px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  border-top: 1px solid rgba(25, 29, 31, .12);
  background: rgba(241, 243, 241, .97);
  color: #202628;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, .07);
}
.toolbar-group { min-width: 0; display: flex; align-items: center; gap: 2px; }
.toolbar-left { justify-content: flex-start; }
.toolbar-center { justify-content: center; }
.toolbar-right { justify-content: flex-end; }
.controlbar .icon-button { color: #202628; }
.controlbar .icon-button:hover { background: rgba(25, 29, 31, .08); }
.controlbar .icon-button.active { background: #202628; color: white; }
.page-status { display: flex; align-items: center; gap: 4px; margin: 0 4px; color: #667174; font-size: 12px; }
.page-status input {
  width: 50px;
  height: 30px;
  padding: 0 5px;
  border: 1px solid rgba(25, 29, 31, .15);
  border-radius: 5px;
  background: white;
  color: #202628;
  text-align: center;
}
#zoom-value { min-width: 40px; color: #667174; font-size: 11px; text-align: center; }

.thumbs-panel {
  position: fixed;
  z-index: 50;
  inset: 0 auto 52px 0;
  width: 286px;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  transform: translateX(-101%);
  transition: transform .2s ease;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.thumbs-panel.open { transform: translateX(0); }
.thumbs-header { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 18px; border-bottom: 1px solid var(--line); }
.thumbs-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 14px 10px;
  padding: 14px;
}
.thumb-button { display: grid; gap: 6px; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.thumb-button img { width: 100%; aspect-ratio: var(--page-ratio); object-fit: cover; object-position: top; border: 2px solid transparent; background: white; }
.thumb-button span { font-size: 11px; }
.thumb-button.active img { border-color: var(--accent); }
.thumb-button.active span { color: var(--ink); }
.thumb-button.bookmarked { position: relative; }
.thumb-button.bookmarked::after { content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.panel-empty { position: absolute; top: 72px; right: 18px; left: 18px; margin: 0; color: var(--muted); font-size: 12px; text-align: center; }
.panel-scrim { display: none; }

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 80px;
  transform: translate(-50%, 12px);
  padding: 9px 14px;
  border-radius: 6px;
  background: #fff;
  color: #252a2c;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 700px) {
  .topbar { min-width: 0; height: 54px; padding: 8px 12px; }
  .viewer-brand.has-logo { width: 138px; height: 34px; }
  .viewer-brand h1 { max-width: 52vw; font-size: 12px; }
  .stage { padding: 58px 14px 66px; }
  .book-shell {
    width: min(calc(100vw - 28px), calc((100vh - 124px) * var(--page-ratio)));
    height: min(calc(100vh - 124px), calc((100vw - 28px) / var(--page-ratio)));
    min-width: 0;
    min-height: 0;
  }
  .current-bookmark { top: 9px; right: 9px; width: 36px; height: 36px; opacity: .86; }
  .page-edge { display: none; }
  .controlbar { height: 54px; grid-template-columns: auto minmax(0, 1fr) auto; gap: 3px; padding: 4px 6px; }
  .toolbar-left #zoom-out, .toolbar-left #zoom-in, #zoom-value,
  .toolbar-center .history-control, .toolbar-center .endpoint-control,
  .toolbar-right #share-button, .toolbar-right a, .toolbar-right #fullscreen-button { display: none; }
  .toolbar-group { gap: 0; }
  .controlbar .icon-button { width: 36px; height: 40px; }
  .page-status { margin: 0 2px; }
  .page-status input { width: 46px; }
  .thumbs-panel { top: 0; bottom: 54px; width: min(88vw, 330px); }
  .panel-scrim {
    position: fixed;
    z-index: 45;
    inset: 0 0 54px;
    width: 100%;
    border: 0;
    background: rgba(0, 0, 0, .45);
  }
  .panel-scrim.open { display: block; }
}
