* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: #101010;
  color: #ffffff;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  overflow: hidden;
}

.reader-shell {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  height: 58px;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background-image: linear-gradient(90deg, gray 20%, black 80%);
  border-bottom: 1px solid #303030;
  z-index: 20;
}

.brand {
  height: 58px;
  width: 220px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 16px;
  overflow: hidden;
  flex-shrink: 0;
}

.brand img {
  display: block !important;
  width: auto !important;
  height: 34px !important;
  max-width: 190px !important;
  max-height: 40px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  object-fit: contain !important;
  object-position: left center !important;
}

.toolbar .brand img {
  width: auto !important;
  height: 34px !important;
  max-width: 190px !important;
  max-height: 40px !important;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar button {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: #292929;
  color: #ffffff;
  cursor: pointer;
  font-size: 17px;
}

.toolbar button:hover {
  background: #3a3a3a;
}

.toolbar button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#pageInfo {
  min-width: 92px;
  text-align: center;
  color: #dddddd;
  font-size: 13px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
  background-image: radial-gradient(circle, grey, black);
}

.book {
  position: relative;
  margin: 0 auto;
  transform-origin: center center;
  transition: transform 0.18s ease;
  will-change: transform;
  touch-action: manipulation;
  user-select: none;
  cursor: default;
}

.page {
  overflow: hidden;
  background: #ffffff;
}

.book.zoomed {
  transition: none;
  cursor: grab;
  touch-action: none;
}

.book.zoomed.is-panning {
  cursor: grabbing;
}

.page canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: #101010;
  color: #dddddd;
}

.hint {
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  background: #181818;
  color: #999999;
  font-size: 16px;
  text-align: center;
  font-family: cinzel;
}


/* =========================================================
   BASIC MOBILE
   ========================================================= */

@media (max-width: 700px) {

  .toolbar {
    height: 52px;
    flex-basis: 52px;
    padding: 0 8px;
  }

  .brand {
    display: none;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: center;
  }

  .toolbar button {
    min-width: 34px;
    height: 34px;
  }

  #pageInfo {
    min-width: 72px;
  }

  .stage {
    padding: 8px;
  }

  .hint {
    display: none;
  }
}


/* =========================================================
   V10 — PDF TEXT SELECTION + CLICKABLE LINK LAYERS
   ========================================================= */

.page-content {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.pdf-text-layer,
.pdf-link-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.pdf-text-layer {
  z-index: 2;
  overflow: hidden;
  line-height: 1;
  text-align: initial;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none;
}

.pdf-text-layer span {
  position: absolute;
  display: inline-block;
  margin: 0;
  padding: 0;
  white-space: pre;
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  background: transparent !important;
  user-select: text !important;
  -webkit-user-select: text !important;
  pointer-events: auto;
  cursor: text;
}

.pdf-text-layer span::selection {
  background: rgba(70, 130, 255, 0.35);
}

.pdf-link-layer {
  z-index: 3;
  pointer-events: none;
}

.pdf-link {
  position: absolute;
  display: block;
  background: transparent;
  border: 0;
  outline: none;
  pointer-events: auto;
  cursor: pointer;
  -webkit-user-drag: none;
}

.pdf-link:hover {
  background: rgba(60, 140, 255, 0.10);
}


/*
 * Normal view:
 * Text spans can be selected.
 * PDF links can be clicked.
 */

.book:not(.zoomed) .pdf-text-layer {
  pointer-events: none;
}

.book:not(.zoomed) .pdf-text-layer span {
  pointer-events: auto;
}

.book:not(.zoomed) .pdf-link-layer {
  pointer-events: none;
}


/*
 * Zoomed view:
 * No text selection and no link interaction.
 * The entire enlarged page is dedicated to drag/pan.
 */

.book.zoomed .pdf-text-layer,
.book.zoomed .pdf-link-layer {
  pointer-events: none !important;
}

.book.zoomed .pdf-text-layer span {
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}


/* =========================================================
   PAGE NUMBER INPUT
   ========================================================= */

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

#pageNumberInput {
  width: 46px;
  min-width: 46px;
  box-sizing: border-box;
  padding: 4px 3px;
  text-align: center;
  font: inherit;
  line-height: 1.2;
}

#pageNumberInput::-webkit-inner-spin-button,
#pageNumberInput::-webkit-outer-spin-button {
  opacity: 1;
}

#pageNumberInput:focus {
  outline: 1px solid currentColor;
}


/* =========================================================
   V11 FINAL INTERACTION FIX
   ========================================================= */

.page-content {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.pdf-text-layer,
.pdf-link-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}


/* Text layer */

.pdf-text-layer {
  z-index: 40;
  overflow: hidden;
  line-height: 1;
  text-align: initial;
  pointer-events: auto !important;
  user-select: text !important;
  -webkit-user-select: text !important;
  touch-action: auto !important;
}

.pdf-text-layer span {
  position: absolute;
  display: inline-block;
  margin: 0;
  padding: 0;
  white-space: pre;
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  background: transparent !important;
  pointer-events: auto !important;
  cursor: text;
  user-select: text !important;
  -webkit-user-select: text !important;
  touch-action: auto !important;
}

.pdf-text-layer span::selection {
  background: rgba(70, 130, 255, 0.35);
}


/* Link layer */

.pdf-link-layer {
  z-index: 50;
  pointer-events: none;
}

.pdf-link {
  position: absolute;
  display: block;
  background: transparent;
  border: 0;
  outline: none;
  pointer-events: auto !important;
  cursor: pointer;
  -webkit-user-drag: none;
}


/* Normal view */

.book:not(.zoomed) .pdf-text-layer,
.book:not(.zoomed) .pdf-text-layer span {
  pointer-events: auto !important;
  user-select: text !important;
  -webkit-user-select: text !important;
}

.book:not(.zoomed) .pdf-link-layer {
  pointer-events: none;
}


/* Zoomed view */

.book.zoomed .pdf-text-layer,
.book.zoomed .pdf-text-layer span,
.book.zoomed .pdf-link-layer {
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}


/* Do not let book user-select:none block text selection */

.book:not(.zoomed) .page-content,
.book:not(.zoomed) .pdf-text-layer,
.book:not(.zoomed) .pdf-text-layer span {
  user-select: text !important;
  -webkit-user-select: text !important;
}


.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

#pageNumberInput {
  width: 46px;
  min-width: 46px;
  box-sizing: border-box;
  padding: 4px 3px;
  text-align: center;
  font: inherit;
  line-height: 1.2;
}


/* =========================================================
   V12 PERFORMANCE CONTAINMENT
   ========================================================= */

.page-content {
  contain: layout paint style;
  content-visibility: auto;
  contain-intrinsic-size: 1000px 1400px;
}


/* =========================================================
   V13 — FULLSCREEN, SEARCH AND SHARE
   ========================================================= */

.v13-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.v13-tool-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 5px;
  background: rgba(255,255,255,.08);
  color: inherit;
  font: inherit;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.v13-tool-button:hover {
  background: rgba(255,255,255,.16);
}

.v13-overlay-panel {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 90px 20px 30px;
  background: rgba(0,0,0,.62);
  opacity: 0;
  transition: opacity .16s ease;
}

.v13-overlay-panel[hidden] {
  display: none;
}

.v13-overlay-panel.is-open {
  opacity: 1;
}

.v13-panel-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 120px);
  overflow: auto;
  box-sizing: border-box;
  border-radius: 10px;
  padding: 18px;
  background: #fff;
  color: #222;
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
}

.v13-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 16px;
}

.v13-panel-head strong {
  font-size: 18px;
}

.v13-panel-head button {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.v13-search-row {
  display: flex;
  gap: 8px;
}

.v13-search-row input {
  flex: 1;
  min-width: 0;
  height: 42px;
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  font: inherit;
  color: #222;
  background: #fff;
}

.v13-search-row button,
.v13-share-actions button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  background: #222;
  color: #fff;
  font: inherit;
}

.v13-search-status,
.v13-share-status {
  margin: 12px 0;
  font-size: 13px;
  opacity: .75;
}

.v13-search-results {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.v13-search-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  width: 100%;
  text-align: left;
  border: 1px solid #e4e4e4;
  border-radius: 7px;
  padding: 10px 12px;
  background: #fff;
  color: #222;
  cursor: pointer;
}

.v13-search-result:hover {
  background: #f6f6f6;
}

.v13-result-page {
  font-weight: 700;
  font-size: 13px;
}

.v13-result-snippet {
  font-size: 13px;
  line-height: 1.45;
}

.v13-share-card p {
  margin: 0 0 16px;
}

.v13-share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.v13-share-actions button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  background: #222;
  color: #fff;
  font: inherit;
}

.v13-floating-tools {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
}


/* =========================================================
   V13 SMALL SCREENS
   ========================================================= */

@media (max-width: 640px) {

  .v13-controls {
    gap: 3px;
  }

  .v13-tool-button {
    width: 32px;
    height: 32px;
  }

  .v13-overlay-panel {
    padding: 70px 10px 15px;
  }

  .v13-panel-card {
    max-height: calc(100vh - 85px);
    padding: 14px;
  }

  .v13-search-row {
    flex-direction: column;
  }

  .v13-search-row button {
    width: 100%;
  }
}

.v13-share-actions button:disabled {
  opacity: .6;
  cursor: default;
}


/* =========================================================
   V15 DESKTOP SHARE OPTIONS
   ========================================================= */

.v15-social-share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.v15-social-share-actions button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 13px;
  cursor: pointer;
  background: #222;
  color: #fff;
  font: inherit;
}

.v15-social-share-actions button:hover {
  opacity: .88;
}

.v15-social-share-actions button:disabled {
  opacity: .6;
  cursor: default;
}


/* =========================================================
   V15 MOBILE RESPONSIVE
   =========================================================
   
   IMPORTANT:
   - 2 columns
   - No display: contents
   - Keeps controls inside viewport
   - Works below 420px
   - Does not modify page-flip JavaScript
   ========================================================= */

@media (max-width: 700px) {

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .reader-shell {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    min-width: 0;
  }


  /* =======================================================
     TOOLBAR
     ======================================================= */

  .toolbar {
    width: 100%;
    height: auto;
    min-height: 52px;
    flex: 0 0 auto;
    padding: 7px 8px;
    box-sizing: border-box;
    display: block;
    overflow: visible;
  }

  .brand {
    display: none;
  }


  /* =======================================================
     2 COLUMN GRID
     ======================================================= */

  .toolbar-actions {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    justify-items: stretch;
    box-sizing: border-box;
  }


  /* =======================================================
     V13 CONTROLS
     ======================================================= */

  /*
   * IMPORTANT:
   * Do NOT use display: contents.
   *
   * Keeping this as flex prevents the controls
   * from breaking the grid layout.
   */

  .v13-controls {
    width: 100%;
    min-width: 0;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 1;
    box-sizing: border-box;
  }


  /* =======================================================
     ALL TOOLBAR BUTTONS
     ======================================================= */

  .toolbar button,
  .v13-tool-button {
    min-width: 0;
    height: 38px;
    min-height: 38px;
    padding: 0 8px;
    box-sizing: border-box;
    font-size: 16px;
    touch-action: manipulation;
  }


  /* V13 buttons share available width */

  .v13-tool-button {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
  }


  /* =======================================================
     PAGE JUMP
     ======================================================= */

  .page-jump {
    width: 100%;
    min-width: 0;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    box-sizing: border-box;
  }

  #pageNumberInput {
    width: 48px;
    min-width: 48px;
    max-width: 48px;
    height: 34px;
    box-sizing: border-box;
  }

  #pageTotal {
    white-space: nowrap;
    font-size: 13px;
  }

  #pageInfo {
    width: 100%;
    min-width: 0;
  }


  /* =======================================================
     MAGAZINE STAGE
     ======================================================= */

  .stage {
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 8px;
    box-sizing: border-box;
    overflow: hidden;
  }

  .book {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    margin: 0 auto;
    box-sizing: border-box;
  }

  .page {
    max-width: 100%;
    box-sizing: border-box;
  }

  .page canvas {
    display: block;
    max-width: 100%;
    width: 100%;
    height: auto;
  }

  .hint {
    display: none;
  }
}


/* =========================================================
   MOBILE — 420px AND BELOW
   ========================================================= */

@media (max-width: 420px) {

  .toolbar {
    padding-left: 6px;
    padding-right: 6px;
  }

  .toolbar-actions {
    gap: 5px;
  }

  .toolbar button,
  .v13-tool-button {
    height: 36px;
    min-height: 36px;
    font-size: 15px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .v13-controls {
    gap: 3px;
  }

  #pageNumberInput {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
  }

  #pageTotal {
    font-size: 12px;
  }

  .stage {
    padding: 6px;
  }
}


/* =========================================================
   MOBILE — 360px AND BELOW
   ========================================================= */

@media (max-width: 360px) {

  .toolbar {
    padding-left: 5px;
    padding-right: 5px;
  }

  .toolbar-actions {
    gap: 4px;
  }

  .toolbar button,
  .v13-tool-button {
    height: 34px;
    min-height: 34px;
    font-size: 14px;
    padding: 0 4px;
  }

  .v13-controls {
    gap: 2px;
  }

  #pageNumberInput {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
  }

  #pageTotal {
    font-size: 11px;
  }

  .stage {
    padding: 5px;
  }
}