* {
  box-sizing: border-box;
}

:root {
  --bg1: #d7dbe2;
  --bg2: #f4f6f8;
  --panel: rgba(244, 246, 248, .88);
  --panel-strong: rgba(235, 238, 242, .94);
  --panel-soft: rgba(255, 255, 255, .62);
  --line: rgba(80, 88, 98, .20);
  --text: #1d232b;
  --muted: #65717f;
  --accent: #8f9aa8;
  --accent2: #c7ccd3;
  --accent-soft: rgba(143, 154, 168, .22);
  --shadow: 0 22px 56px rgba(88, 96, 108, .28);
  --radius: 22px;
  --header-h: 72px;
  --gap: 14px;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, .88), transparent 32%),
    radial-gradient(circle at top right, rgba(190, 198, 208, .42), transparent 34%),
    linear-gradient(135deg, #cfd5dd 0%, #eef1f4 48%, #bfc7d1 100%);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

button,
input,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: .36;
  cursor: not-allowed;
}

.book-app {
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  overflow: hidden;
}

.app-header {
  position: fixed;
  top: 6px;
  left: 10px;
  right: 10px;
  z-index: 6000;
  min-height: var(--header-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(245, 247, 250, .86);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(-100% - 20px));
  transition:
    opacity .22s ease,
    transform .22s ease;
}

.app-header.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

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

.app-logo {
  margin: 0;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 800;
  letter-spacing: .05em;
  white-space: nowrap;
}

.icon-button,
.download-button,
.nav-button,
.page-jump button,
.side-tab,
.search-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, .56);
  text-decoration: none;
  border-radius: 13px;
  transition:
    transform .18s ease,
    border-color .18s ease,
    box-shadow .18s ease,
    background .18s ease;
}

.icon-button:hover,
.download-button:hover,
.nav-button:hover,
.page-jump button:hover,
.side-tab:hover,
.search-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: rgba(255, 255, 255, .82);
}

.icon-button {
  width: 52px;
  min-width: 52px;
  height: 44px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  overflow: visible;
}

.menu-button {
  position: relative;
  flex-direction: column;
  gap: 5px;
}

.menu-button span {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
  transition: transform .18s ease, opacity .18s ease;
  transform-origin: center;
}

.menu-button.is-open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-button.is-open span:nth-child(2) {
  opacity: 0;
}

.menu-button.is-open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.page-status {
  min-width: 92px;
  text-align: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .55);
  font-weight: 800;
}

.pdf-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.download-button {
  display: inline-grid;
  place-items: center;
  min-width: 72px;
  height: 44px;
  padding: 0 12px;
  font-weight: 800;
  white-space: nowrap;
}

.download-button.is-hidden {
  display: none;
}

.app-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--gap);
  overflow: hidden;
  transition: grid-template-columns .24s ease;
}

.app-body.panel-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.side-panel {
  position: relative;
  z-index: 4000;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
  opacity: 1;
  transition: opacity .18s ease, transform .24s ease;
}

.side-panel:not(.is-open) {
  opacity: 0;
  transform: translateX(-10px);
  pointer-events: none;
}

.side-open-button {
  position: absolute;
  left: 14px;
  top: 50%;
  z-index: 3900;
  width: 46px;
  min-height: 112px;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .82), rgba(199, 204, 211, .52));
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 34px rgba(80, 88, 98, .24);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .08em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: translateY(-50%) translateX(-16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity .2s ease,
    transform .2s ease,
    border-color .18s ease,
    box-shadow .18s ease,
    background .18s ease;
}

.side-open-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}

.side-open-button:hover {
  border-color: var(--accent);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .96), rgba(220, 225, 232, .78));
  box-shadow:
    0 18px 42px rgba(80, 88, 98, .30),
    0 0 0 4px var(--accent-soft);
}

.side-panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  flex: 1;
}

.side-tab {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
}

.side-tab.is-active {
  color: var(--text);
  border-color: rgba(143, 154, 168, .62);
  background: linear-gradient(135deg, rgba(255, 255, 255, .72), rgba(199, 204, 211, .36));
  box-shadow: 0 0 0 3px rgba(143, 154, 168, .12);
}

.close-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  font-size: 24px;
  line-height: 1;
}

.side-panel-body {
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}

.side-content {
  display: none;
  height: 100%;
  min-height: 0;
}

.side-content.is-active {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.side-title {
  margin: 0 0 14px;
  font-size: 22px;
  letter-spacing: .04em;
}

.toc-list,
.thumbnail-list,
.search-results {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.toc-list::-webkit-scrollbar,
.thumbnail-list::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
  width: 7px;
}

.toc-list::-webkit-scrollbar-thumb,
.thumbnail-list::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
  background: rgba(80, 88, 98, .22);
  border-radius: 999px;
}

.toc-row {
  margin-bottom: 9px;
}

.toc-row .toc-item {
  margin-bottom: 0;
}

.toc-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 13px 12px;
  margin-bottom: 9px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .36);
  text-align: left;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.toc-item span:first-child {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.toc-item span:last-child {
  color: var(--muted);
  font-weight: 800;
}

.toc-item:hover,
.toc-row.is-active > .toc-item {
  transform: translateX(2px);
  border-color: rgba(143, 154, 168, .65);
  background: var(--accent-soft);
}

.toc-toggle-row > .toc-item span:first-child::before {
  content: "▶";
  display: inline-block;
  width: 1.2em;
  margin-right: 4px;
  color: var(--muted);
  font-size: .82em;
  transition: transform .18s ease;
}

.toc-toggle-row.is-open > .toc-item span:first-child::before {
  transform: rotate(90deg);
}

.toc-children {
  margin-top: 8px;
}

.toc-children[hidden] {
  display: none;
}

.toc-heading {
  cursor: default;
}

.toc-heading:hover {
  transform: none;
}

.toc-level-1 > .toc-item {
  background: rgba(255, 255, 255, .50);
  border-color: rgba(143, 154, 168, .32);
  font-size: 15px;
  font-weight: 900;
}

.toc-level-2 {
  margin-left: 10px;
}

.toc-level-2 > .toc-item {
  width: calc(100% - 10px);
  background: rgba(255, 255, 255, .36);
  font-size: 14px;
  font-weight: 800;
}

.toc-level-3 {
  margin-left: 22px;
}

.toc-level-3 > .toc-item {
  width: calc(100% - 22px);
  background: rgba(255, 255, 255, .24);
  font-size: 13px;
  font-weight: 700;
}

.toc-level-3 > .toc-item span:first-child::before {
  content: "・";
  margin-right: 2px;
  color: var(--muted);
}

.toc-toggle-row.toc-level-3 > .toc-item span:first-child::before {
  content: "▶";
}

.thumbnail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 10px;
}

.thumbnail-spacer {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  pointer-events: none;
}

.thumbnail-spacer::after {
  content: "";
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
}

.thumbnail-item {
  min-width: 0;
  display: block;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 7px;
  color: var(--text);
  background: rgba(255, 255, 255, .32);
  text-align: center;
}

.thumbnail-item img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  background: #fff;
}

.thumbnail-item span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.thumbnail-item:hover,
.thumbnail-item.is-active {
  border-color: rgba(143, 154, 168, .68);
  background: var(--accent-soft);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, .50);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-button {
  height: 42px;
  padding: 0 14px;
  font-weight: 800;
}

.search-status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.search-result-item {
  width: 100%;
  display: block;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .36);
  text-align: left;
}

.search-result-item:hover {
  border-color: rgba(143, 154, 168, .65);
  background: var(--accent-soft);
}

.search-result-page {
  display: block;
  margin-bottom: 6px;
  color: #56616f;
  font-size: 13px;
  font-weight: 900;
}

.search-result-snippet {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.search-result-snippet mark {
  padding: 0 2px;
  border-radius: 3px;
  color: #06101a;
  background: #ffe66d;
}

.viewer-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: hidden;
}

.viewer-toolbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  width: min(820px, calc(100% - 36px));
  display: grid;
  grid-template-columns: auto auto minmax(210px, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(245, 247, 250, .86);
  backdrop-filter: blur(18px);
  box-shadow: 0 16px 42px rgba(80, 88, 98, .28);
  transform: translateX(-50%);
  opacity: 1;
  pointer-events: auto;
  transition:
    opacity .2s ease,
    transform .2s ease;
}

.viewer-toolbar.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(24px);
}

.nav-button {
  min-width: 82px;
  height: 40px;
  padding: 0 12px;
  font-weight: 800;
  white-space: nowrap;
}

.page-jump {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 6px;
}

.page-jump label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .1em;
}

.page-jump input {
  width: 70px;
  max-width: 100%;
  height: 38px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: rgba(255, 255, 255, .60);
  text-align: center;
  outline: none;
}

.page-jump input:focus {
  border-color: var(--accent);
}

.page-total {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.page-jump button {
  height: 38px;
  padding: 0 14px;
  font-weight: 800;
}

.toolbar-hide-button,
.toolbar-show-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, .72);
  text-decoration: none;
  transition:
    transform .18s ease,
    border-color .18s ease,
    box-shadow .18s ease,
    background .18s ease;
}

.toolbar-hide-button:hover,
.toolbar-show-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: rgba(255, 255, 255, .92);
}

.toolbar-hide-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.toolbar-show-button {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 58;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(245, 247, 250, .78);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 30px rgba(80, 88, 98, .24);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity .18s ease,
    transform .18s ease,
    border-color .18s ease,
    box-shadow .18s ease,
    background .18s ease;
}

.toolbar-show-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.toolbar-show-button.is-visible:hover {
  transform: translateX(-50%) translateY(-1px);
}

.book-stage {
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 18px;
  overflow: hidden;
  cursor: zoom-in;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, .78), rgba(255, 255, 255, .20) 52%, rgba(170, 178, 188, .24)),
    linear-gradient(90deg, rgba(80, 88, 98, .05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(80, 88, 98, .045) 1px, transparent 1px);
  background-size: 100% 100%, 30px 30px, 30px 30px;
}

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

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

.flipbook-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  padding: 16px 58px var(--toolbar-space, 120px);
  transform:
    translate3d(var(--book-pan-x, 0px), var(--book-pan-y, 0px), 0);
  transform-origin: center center;
  transition:
    transform .06s ease-out,
    padding .2s ease;
  will-change: transform;
}

.viewer-panel.toolbar-collapsed {
  --toolbar-space: 42px;
}

.flipbook {
  position: absolute !important;
  margin: 0 !important;
  transform: scale(var(--book-preview-scale, 1)) !important;
  transform-origin: center center !important;
}

.flipbook .page,
.flipbook .hard {
  background: #fff;
  overflow: hidden;
}

.flipbook .page-wrapper {
  background: transparent;
}

.flipbook-page {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
}

.flipbook-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      90deg,
      rgba(0, 0, 0, .10),
      rgba(255, 255, 255, .04) 30%,
      rgba(0, 0, 0, .08)
    );
  opacity: .16;
  z-index: 7;
}

.flipbook-page > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}

.flipbook-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #666;
  background: #fff;
  font-size: 12px;
  z-index: 10;
}

.tile-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
}

.tile-layer.is-active {
  opacity: 1;
}

.tile-layer img {
  position: absolute;
  display: block;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
}

.search-highlight-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.search-highlight-box {
  position: absolute;
  border-radius: 3px;
  background: rgba(255, 230, 0, .42);
  box-shadow:
    0 0 0 1px rgba(255, 230, 0, .75),
    0 0 12px rgba(255, 230, 0, .42);
  mix-blend-mode: multiply;
  animation: searchHighlightPulse 1.2s ease-in-out infinite;
}

@keyframes searchHighlightPulse {
  0% {
    opacity: .48;
  }

  50% {
    opacity: .9;
  }

  100% {
    opacity: .48;
  }
}

.zoom-indicator {
  position: absolute;
  right: 18px;
  bottom: 88px;
  z-index: 65;
  min-width: 64px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(245, 247, 250, .82);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .18s ease, transform .18s ease;
}

.zoom-indicator.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.stage-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5000;
  width: 58px;
  height: 88px;
  border: 1px solid rgba(80, 88, 98, .28);
  border-radius: 999px;
  color: #1d232b;
  font-size: 42px;
  line-height: 1;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .92), rgba(210, 216, 224, .86));
  backdrop-filter: blur(10px);
  box-shadow:
    0 14px 34px rgba(80, 88, 98, .28),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  transition:
    transform .18s ease,
    border-color .18s ease,
    background .18s ease,
    box-shadow .18s ease;
  pointer-events: auto;
  touch-action: manipulation;
}

.stage-nav:hover {
  transform: translateY(-50%) scale(1.06);
  border-color: rgba(120, 130, 144, .55);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .98), rgba(228, 232, 238, .94));
  box-shadow:
    0 18px 42px rgba(80, 88, 98, .34),
    0 0 0 4px rgba(143, 154, 168, .18),
    inset 0 1px 0 rgba(255, 255, 255, 1);
}

.stage-nav:disabled {
  opacity: .28;
  cursor: not-allowed;
}

.stage-prev {
  left: 22px;
}

.stage-next {
  right: 22px;
}

@media (max-width: 900px) {
  :root {
    --header-h: 54px;
    --gap: 10px;
  }

  html,
  body {
    overflow: hidden;
  }

  .book-app {
    padding: 68px 10px 10px;
  }

  .app-header {
    top: 6px;
    left: 8px;
    right: 8px;
    z-index: 7000;
    min-height: 54px;
    padding: 7px 8px;
    border-radius: 15px;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
  }

  .brand-row {
    min-width: 0;
    flex: 1;
    gap: 8px;
  }

  .app-logo {
    max-width: none;
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    letter-spacing: .02em;
  }

  .header-actions {
    flex-shrink: 0;
    gap: 5px;
  }

  .page-status {
    display: none;
  }

  .pdf-actions {
    display: flex;
    max-width: 112px;
    gap: 4px;
    overflow: hidden;
  }

  .download-button {
    min-width: 44px;
    max-width: 54px;
    height: 36px;
    padding: 0 6px;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .icon-button {
    width: 42px;
    min-width: 42px;
    height: 36px;
  }

  .menu-button span {
    width: 19px;
  }

  .app-body,
  .app-body.panel-collapsed {
    position: relative;
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 4000;
    width: min(82vw, 320px);
    max-width: 100%;
  }

  .side-panel:not(.is-open) {
    transform: translateX(calc(-100% - 12px));
  }

  .side-open-button {
    display: none !important;
  }

  .viewer-panel {
    padding: 8px;
    border-radius: 15px;
  }

  .book-stage {
    border-radius: 14px;
    touch-action: none;
  }

  .flipbook-viewport {
    padding: 8px 40px var(--toolbar-space, 104px);
    touch-action: none;
  }

  .flipbook {
    touch-action: none;
  }

  .book-stage.is-zoomed {
    touch-action: none;
  }

  .viewer-toolbar {
    left: 50%;
    bottom: 10px;
    width: min(540px, calc(100% - 20px));
    grid-template-columns: repeat(5, minmax(0, 1fr));
    border-radius: 16px;
    padding: 7px;
    gap: 6px;
  }

  .viewer-toolbar .page-jump {
    grid-column: 1 / -1;
    order: -1;
  }

  .nav-button {
    min-width: 0;
    height: 34px;
    padding: 0 6px;
    font-size: 11px;
  }

  .page-jump {
    gap: 5px;
  }

  .page-jump input {
    width: 56px;
    height: 34px;
    padding: 6px;
    font-size: 12px;
  }

  .page-total {
    font-size: 12px;
  }

  .page-jump button {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .toolbar-hide-button {
    width: auto;
    min-width: 0;
    height: 34px;
    font-size: 14px;
  }

  .toolbar-show-button {
    bottom: 8px;
    height: 34px;
    font-size: 12px;
  }

  .viewer-panel.toolbar-collapsed {
    --toolbar-space: 32px;
  }

  .stage-nav {
    width: 42px;
    height: 60px;
    font-size: 30px;
    z-index: 5000;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .stage-prev {
    left: 8px;
  }

  .stage-next {
    right: 8px;
  }

  .zoom-indicator {
    right: 12px;
    bottom: 104px;
  }
}

@media (max-width: 520px) {
  .app-logo {
    max-width: none;
    font-size: 13px;
  }

  .pdf-actions {
    max-width: 104px;
  }

  .download-button {
    min-width: 40px;
    max-width: 50px;
    font-size: 10px;
  }

  .page-jump label {
    display: none;
  }

  .page-jump input {
    width: 58px;
  }

  .flipbook-viewport {
    padding: 8px 34px var(--toolbar-space, 106px);
  }

  .viewer-panel.toolbar-collapsed {
    --toolbar-space: 30px;
  }

  .stage-nav {
    width: 38px;
    height: 56px;
    font-size: 28px;
  }

  .thumbnail-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ============================================================
   Page link hotspots
   ============================================================ */

.page-link-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

.page-link-hotspot {
  position: absolute;
  display: block;
  border: 0;
  padding: 0;
  border-radius: 4px;
  background: rgba(0, 132, 255, 0);
  cursor: pointer;
  pointer-events: auto;
  touch-action: auto;
}

.page-link-hotspot:hover {
  background: rgba(0, 132, 255, .16);
  box-shadow: inset 0 0 0 2px rgba(0, 132, 255, .55);
}

.page-link-hotspot:focus-visible {
  outline: 3px solid rgba(0, 132, 255, .75);
  outline-offset: 2px;
}

/* 編集モード */

body.is-link-edit-mode .page-link-layer {
  pointer-events: auto;
}

body.is-link-edit-mode .page-link-hotspot {
  background: rgba(0, 132, 255, .18);
  box-shadow:
    inset 0 0 0 2px rgba(0, 132, 255, .72),
    0 6px 18px rgba(0, 0, 0, .18);
}

.page-link-hotspot-label {
  position: absolute;
  left: 4px;
  top: 4px;
  max-width: calc(100% - 8px);
  padding: 2px 5px;
  border-radius: 4px;
  color: #fff;
  background: rgba(0, 88, 180, .88);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.page-link-drag-box {
  position: absolute;
  z-index: 20;
  border: 2px dashed rgba(0, 132, 255, .92);
  background: rgba(0, 132, 255, .18);
  border-radius: 4px;
  pointer-events: none;
}

.link-editor-panel {
  position: fixed;
  right: 16px;
  top: 86px;
  z-index: 9000;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 110px);
  display: grid;
  grid-template-rows: auto auto minmax(120px, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(80, 88, 98, .24);
  border-radius: 18px;
  color: #1d232b;
  background: rgba(245, 247, 250, .94);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 52px rgba(80, 88, 98, .34);
}

.link-editor-panel h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: .04em;
}

.link-editor-help {
  margin: 0;
  color: #65717f;
  font-size: 12px;
  line-height: 1.6;
}

.link-editor-textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  padding: 10px;
  border: 1px solid rgba(80, 88, 98, .24);
  border-radius: 12px;
  color: #1d232b;
  background: rgba(255, 255, 255, .82);
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.link-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-editor-actions button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(80, 88, 98, .24);
  border-radius: 10px;
  color: #1d232b;
  background: rgba(255, 255, 255, .76);
  font-weight: 800;
}

.link-editor-actions button:hover {
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 0 0 3px rgba(143, 154, 168, .18);
}

@media (max-width: 900px) {
  .link-editor-panel {
    left: 10px;
    right: 10px;
    top: 68px;
    width: auto;
    max-height: calc(100dvh - 88px);
  }
}

.link-editor-panel.is-collapsed {
  width: auto;
  max-width: calc(100vw - 32px);
  grid-template-rows: auto;
  padding: 10px 12px;
}

.link-editor-panel.is-collapsed .link-editor-help,
.link-editor-panel.is-collapsed .link-editor-textarea,
.link-editor-panel.is-collapsed .link-editor-actions {
  display: none;
}

.link-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.link-editor-header h2 {
  margin: 0;
}

.link-editor-toggle {
  min-width: 34px;
  min-height: 30px;
  border: 1px solid rgba(80, 88, 98, .24);
  border-radius: 10px;
  color: #1d232b;
  background: rgba(255, 255, 255, .76);
  font-weight: 900;
  cursor: pointer;
}

.link-editor-toggle:hover {
  background: rgba(255, 255, 255, .95);
}

/* ============================================================
   Viewer toolbar layout
   PC: one line / Mobile: compact two-line layout
   ============================================================ */

.viewer-toolbar {
  width: min(960px, calc(100vw - 32px));
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
}

/* ボタンが勝手に伸びるのを防止 */
.viewer-toolbar > .nav-button {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 82px;
  white-space: nowrap;
}

.viewer-toolbar > #indexPageButton {
  min-width: 76px;
}

.viewer-toolbar > #prevPage,
.viewer-toolbar > #nextPage {
  min-width: 92px;
  max-width: 110px;
}

.viewer-toolbar > .page-jump {
  flex: 0 0 auto !important;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  white-space: nowrap;
}

.viewer-toolbar > .page-jump input {
  flex: 0 0 64px;
  width: 64px;
  min-width: 64px;
}

.viewer-toolbar > .page-jump button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.viewer-toolbar > .toolbar-hide-button {
  flex: 0 0 auto !important;
  width: 42px;
  min-width: 42px;
}

/* ============================================================
   Mobile toolbar
   スマホでは無理に1行にせず、崩れない2段構成にする
   ============================================================ */

@media (max-width: 760px) {
  .viewer-toolbar {
    width: calc(100vw - 16px);
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 22px;
  }

  /* 1段目：INDEX PAGE入力 移動 ↓ */
  .viewer-toolbar > #indexPageButton {
    order: 1;
    flex: 0 0 76px !important;
    min-width: 76px;
  }

  .viewer-toolbar > .page-jump {
    order: 2;
    flex: 1 1 calc(100% - 124px) !important;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 5px;
    height: 36px;
    white-space: nowrap;
  }

  .viewer-toolbar > .toolbar-hide-button {
    order: 3;
    flex: 0 0 36px !important;
    width: 36px;
    min-width: 36px;
    height: 36px;
  }

  /* 2段目：最初 前へ 次へ 最後 */
  .viewer-toolbar > #firstPage {
    order: 4;
  }

  .viewer-toolbar > #prevPage {
    order: 5;
  }

  .viewer-toolbar > #nextPage {
    order: 6;
  }

  .viewer-toolbar > #lastPage {
    order: 7;
  }

  .viewer-toolbar > .nav-button {
    height: 36px;
    padding-inline: 10px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }

  .viewer-toolbar > #firstPage,
  .viewer-toolbar > #prevPage,
  .viewer-toolbar > #nextPage,
  .viewer-toolbar > #lastPage {
    flex: 0 0 calc((100% - 18px) / 4) !important;
    min-width: 0;
    max-width: none;
  }

  .viewer-toolbar > .page-jump label,
  .viewer-toolbar > .page-jump .page-total {
    font-size: 11px;
  }

  .viewer-toolbar > .page-jump input {
    flex: 0 0 48px;
    width: 48px;
    min-width: 48px;
    height: 34px;
    font-size: 12px;
  }

  .viewer-toolbar > .page-jump button {
    flex: 0 0 auto;
    height: 34px;
    padding-inline: 8px;
    font-size: 12px;
    white-space: nowrap;
  }
}