:root {
  --bg: #111318;
  --panel: #1a1f29;
  --panel-2: #232a36;
  --text: #eef2f7;
  --muted: #b2bccb;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0;
/*  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);*/
  --radius: 14px;
  --toolbar-height: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

body {
  overflow: hidden;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: var(--toolbar-height) 1fr;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(17, 19, 24, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.toolbar__left,
.toolbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar__right {
  justify-content: flex-end;
}

.toolbar__center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.toolbar__center #status {
  min-width: 110px;
  text-align: center;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  min-width: 44px;
  height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 15px;
}

button:hover {
  background: var(--panel-2);
}

#downloadBtn {
  font-size: 18px;
  line-height: 1;
}

/* Layout with thumbnail strip */
.viewer-layout {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
}

.viewer-layout.thumbnails-hidden {
  grid-template-columns: 0 minmax(0, 1fr);
}

.thumbs-panel {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: rgba(17, 19, 24, 0.7);
  overflow: hidden;
}

.thumbs-list {
  height: 100%;
  overflow-y: scroll;   /* always show scrollbar */
  overflow-x: hidden;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumb-item {
  appearance: none;
  width: 100%;
  height: auto;
  min-width: 0;
  min-height: unset;
  display: block;
  flex: 0 0 auto;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  overflow: hidden;
  margin: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thumb-item:hover {
  background: var(--panel-2);
}

.thumb-item.is-active {
  border-color: rgba(255, 255, 255, 0.28);
  background: var(--panel-2);
}

.thumb-image-wrap {
  width: 100%;
  aspect-ratio: 0.72 / 1;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  display: block;
}

.thumb-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.thumb-placeholder {
  color: #666;
  font-size: 12px;
  text-align: center;
  padding: 10px;
}

.thumb-label {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.viewer-shell {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.book-wrapper {
  width: min(96vw, 1400px);
  height: min(84vh, 920px);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.book {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.mobile-pages {
  display: none;
}

.page-arrow-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.page-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 72px;
  min-width: 0;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(20, 24, 32, 0.55);
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
  z-index: 10;
  pointer-events: auto;
}

.page-arrow-left {
  left: 8px;
}

.page-arrow-right {
  right: 8px;
}

.page-arrow:hover {
  background: var(--panel-2);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-50%) scale(1.05);
}

.page-arrow:active {
  transform: translateY(-50%) scale(0.96);
}

.page-arrow:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.zoom-reset-hidden {
  display: none;
}

/* PDF pages */
.page {
  background: white;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
  position: relative;
}

.page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: white;
  user-select: none;
  -webkit-user-drag: none;
}

.page-inner {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: white;
}

.page-placeholder {
  color: #666;
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

/* StPageFlip styling */
.stf__parent {
  box-shadow: var(--shadow);
}

.stf__block {
  border-radius: 8px;
  overflow: hidden;
}

@media (max-width: 900px) {
  .viewer-layout {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .viewer-layout.thumbnails-hidden {
    grid-template-columns: 0 minmax(0, 1fr);
  }
}

@media (max-width: 720px) and ((hover: none) or (pointer: coarse)) {
  :root {
    --toolbar-height: 52px;
  }

  html {
    height: auto;
    min-height: 100%;
    overflow-x: auto;
    overflow-y: auto;
  }

  body.mobile-viewer {
    height: auto;
    min-height: 100%;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior: auto;
  }

  .mobile-viewer .app {
    height: var(--toolbar-height);
    display: block;
  }

  .toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    height: var(--toolbar-height);
    padding: 6px 8px;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 30;
  }

  .toolbar__left {
    width: auto;
  }

  .toolbar__center {
    min-width: 0;
    gap: 4px;
  }

  .toolbar__right {
    width: auto;
    gap: 4px;
  }

  .toolbar button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
  }

  .toolbar__center #status {
    min-width: 0;
    width: 86px;
    font-size: 12px;
  }

  #fullscreenBtn,
  #zoomResetBtn,
  #zoomIndicator,
  .toolbar__center #prevBtn,
  .toolbar__center #nextBtn {
    display: none;
  }

  .viewer-layout {
    position: static;
    display: block;
    grid-template-columns: 0 minmax(0, 1fr);
    min-height: 0;
    height: 0;
    pointer-events: none;
  }

  .thumbs-panel {
    position: fixed;
    top: var(--toolbar-height);
    left: 0;
    bottom: 0;
    width: min(56vw, 170px);
    z-index: 20;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease;
    pointer-events: auto;
  }

  .thumbs-list {
    padding: 6px;
    gap: 6px;
    align-items: center;
  }

  .thumb-item {
    width: min(100%, 128px);
    padding: 5px;
    border-radius: 8px;
  }

  .thumb-image-wrap {
    border-radius: 5px;
  }

  .thumb-label {
    margin-top: 4px;
    font-size: 10px;
  }

  .viewer-layout.thumbnails-hidden .thumbs-panel {
    transform: translateX(-100%);
  }

  .viewer-layout:not(.thumbnails-hidden) .thumbs-panel {
    transform: translateX(0);
  }

  .viewer-shell {
    position: static;
    display: block;
    padding: 0;
    width: 100%;
    height: 0;
    min-width: 0;
    min-height: 0;
    overflow: visible;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    scroll-behavior: auto;
  }

  .book-wrapper {
    display: none;
  }

  .mobile-pages {
    position: relative;
    z-index: 1;
    width: 100%;
    height: auto;
    min-height: 0;
    max-width: none;
    max-height: none;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    visibility: visible;
    overflow: visible;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  .mobile-pages::after {
    content: "";
    display: block;
    flex: 0 0 max(72px, env(safe-area-inset-bottom, 0px));
    width: 1px;
  }

  .mobile-pages .page {
    display: flex;
    min-width: 1px;
    min-height: 1px;
    flex: 0 0 auto;
    border-radius: 3px;
    scroll-margin-top: 12px;
  }

  .mobile-pages .page img {
    object-fit: fill;
  }

  .mobile-pages .page canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: white;
  }

.mobile-viewer .page-arrow-layer {
    display: none;
  }
}

.access-expired-dialog {
  position: fixed;
  z-index: 9999;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}

.access-expired-dialog__panel {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 8px;
  color: var(--text, #fff);
  background: var(--surface, #181b22);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.access-expired-dialog__panel h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
}

.access-expired-dialog__panel p {
  margin: 0;
  line-height: 1.5;
}
