.hm-bro {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: #000000;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-sizing: border-box;
  overflow: hidden;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
}

.hm-bro[hidden] {
  display: none !important;
}

/* Author display:flex on layers/wrap must not override the HTML hidden attribute (PDF mode hides image layers). */
.hm-bro-layer[hidden],
.hm-bro-pdf-wrap[hidden],
.hm-bro-spinner[hidden],
.hm-bro-error[hidden] {
  display: none !important;
}

body.hm-reader-standalone {
  margin: 0;
  overflow: hidden;
  background: #000000;
}

.hm-reader-standalone .hm-bro {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  min-height: 0;
  z-index: 999999;
}

body.admin-bar.hm-reader-standalone .hm-bro:not([hidden]) {
  top: 32px;
}

@media screen and (max-width: 782px) {
  body.admin-bar.hm-reader-standalone .hm-bro:not([hidden]) {
    top: 46px;
  }
}

.hm-reader-standalone .hm-bro[hidden] {
  display: none !important;
}

.hm-reader-standalone .hm-bro:not([hidden]) {
  display: flex !important;
}

.hm-bro-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 20;
  background-color: #383838;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hm-bro-close:hover {
  background-color: #454545;
}

.hm-bro-close:active {
  background-color: #2e2e2e;
}

.hm-bro-image-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  background: #000000;
}

.hm-bro-content-viewport {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  /* Column + margin:auto on stage centers when content fits; avoids flex cross-axis overflow scrollbar at 1× */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 clamp(48px, 8vw, 64px);
  padding: 0;
  scrollbar-gutter: auto;
  box-sizing: border-box;
}

.hm-bro-content-viewport:not(.hm-bro-content-viewport--overflowing) {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.hm-bro-content-viewport:not(.hm-bro-content-viewport--overflowing)::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.hm-bro-content-viewport.hm-bro-content-viewport--overflowing {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.45) transparent;
}

.hm-bro-content-viewport.hm-bro-content-viewport--overflowing::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.hm-bro-content-viewport.hm-bro-content-viewport--overflowing::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 4px;
}

.hm-bro-content-viewport.hm-bro-content-viewport--overflowing::-webkit-scrollbar-track {
  background: transparent;
}

.hm-bro-page-stage {
  position: relative;
  transform-origin: center center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  box-sizing: border-box;
}

.hm-bro-pdf-wrap {
  position: relative;
  z-index: 4;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hm-bro-pdf-wrap canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  box-shadow: none;
}

.hm-bro-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.hm-bro-layer-a {
  z-index: 2;
  transition: opacity 0.18s ease;
}

.hm-bro-error {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: min(90%, 420px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(180, 40, 40, 0.92);
  color: #fff;
  font-size: 13px;
  text-align: center;
  z-index: 12;
  margin: 0;
}

.hm-bro-nav:disabled {
  opacity: 1;
  cursor: default;
  pointer-events: none;
}

body.hm-reader-open {
  overflow: hidden;
}

.hm-bro-layer-b {
  z-index: 1;
}

.hm-bro-layer img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.hm-bro-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: #383838;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 0;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.hm-bro-nav:not(:disabled):hover {
  background-color: #454545;
}

.hm-bro-nav:not(:disabled):active {
  background-color: #2e2e2e;
}

.hm-bro-prev {
  left: max(8px, env(safe-area-inset-left, 0px));
}

.hm-bro-next {
  right: max(8px, env(safe-area-inset-right, 0px));
}

.hm-bro-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -22px 0 0 -22px;
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: #4a7fb5;
  border-radius: 50%;
  animation: hm-bro-spin 0.75s linear infinite;
  z-index: 10;
}

@keyframes hm-bro-spin {
  to {
    transform: rotate(360deg);
  }
}

.hm-bro-bar {
  width: 100%;
  flex: 0 0 auto;
  flex-shrink: 0;
  box-sizing: border-box;
  z-index: 15;
  padding: 10px clamp(12px, 3vw, 20px) calc(10px + env(safe-area-inset-bottom, 0px));
  background: #000000;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hm-bro-toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.hm-bro-toolbar-row--primary {
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.hm-bro-toolbar-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  margin-left: auto;
  max-width: min(100%, 280px);
}

.hm-bro-progress-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex: 0 0 auto;
  min-width: 76px;
}

.hm-bro-count {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.hm-bro-pct {
  color: rgba(255, 255, 255, 0.58);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1;
}

.hm-bro-scrub-wrap {
  flex: 1 1 120px;
  min-width: 64px;
  max-width: none;
  padding: 6px 0;
}

@media (min-width: 601px) {
  .hm-bro-scrub-wrap {
    max-width: 520px;
  }
}

.hm-bro-scrub {
  position: relative;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  cursor: pointer;
}

.hm-bro-scrub-fill {
  position: relative;
  height: 100%;
  background: #4a7fb5;
  border-radius: 999px;
  width: 0%;
  transition: width 0.2s;
  pointer-events: none;
}

.hm-bro-scrub-fill::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  margin-right: -6px;
  border-radius: 50%;
  background: #4a7fb5;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.hm-bro-icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hm-bro-icon-btn:focus-visible {
  outline: 2px solid #4a7fb5;
  outline-offset: 2px;
}

.hm-bro-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.hm-bro-zoom[hidden] {
  display: none !important;
}

.hm-bro-zoom-btn {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  font-size: 17px;
  line-height: 1;
}

.hm-bro-zoom-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.hm-bro-zoom-reset {
  width: auto;
  min-width: 36px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hm-bro-jump-label {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  white-space: nowrap;
}

.hm-bro-jump {
  position: static;
  transform: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.hm-bro-jump input {
  width: 72px;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #000000;
  color: #fff;
  text-align: center;
  outline: none;
  font-size: 14px;
  border-radius: 8px;
  padding: 6px 4px;
  box-sizing: border-box;
}

.hm-bro-jump input[aria-invalid="true"] {
  border-color: #e57373;
}

.hm-bro-jump button {
  min-height: 36px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: #4a7fb5;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.hm-bro-jump-hint {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: #ffb4b4;
  margin: 0;
}

/* Mobile + landscape phones: full-width reading area; nav floats over side gutters */
@media (max-width: 767px), (max-height: 520px) and (max-width: 932px) {
  .hm-bro-image-wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }

  .hm-bro-content-viewport {
    margin: 0;
    width: 100%;
    max-width: 100%;
    padding:
      max(2px, env(safe-area-inset-top, 0px))
      max(2px, env(safe-area-inset-right, 0px))
      0
      max(2px, env(safe-area-inset-left, 0px));
  }

  .hm-bro-page-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
  }

  .hm-bro-layer {
    position: absolute;
    inset: 0;
  }

  .hm-bro-pdf-wrap {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
  }

  .hm-bro-layer img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .hm-bro-nav {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 22px;
    font-weight: 300;
    z-index: 6;
  }

  .hm-bro-prev {
    left: max(4px, env(safe-area-inset-left, 0px));
  }

  .hm-bro-next {
    right: max(4px, env(safe-area-inset-right, 0px));
  }

  .hm-bro-close {
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
  }
}

/* Mobile toolbar: single row — meta | scrub | jump (reference layout) */
@media (max-width: 600px), (max-height: 520px) and (max-width: 932px) {
  .hm-bro-bar {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
  }

  .hm-bro-toolbar-row--primary {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
  }

  .hm-bro-progress-meta {
    flex: 0 0 auto;
    min-width: 52px;
  }

  .hm-bro-scrub-wrap {
    flex: 1 1 48px;
    min-width: 40px;
    max-width: none;
    padding: 8px 2px;
  }

  .hm-bro-toolbar-actions {
    flex: 0 0 auto;
    margin-left: auto;
    max-width: none;
    width: auto;
    justify-content: flex-end;
  }

  .hm-bro-jump {
    gap: 6px;
  }

  .hm-bro-jump-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .hm-bro-jump input {
    width: 48px;
    min-height: 34px;
    padding: 4px 4px;
    font-size: 14px;
  }

  .hm-bro-jump button {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 13px;
  }

  .hm-bro-count {
    font-size: 14px;
  }

  .hm-bro-close {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 380px) {
  .hm-bro-count {
    font-size: 13px;
  }

  .hm-bro-jump-label {
    flex: 1 1 100%;
    text-align: center;
  }
}

.hm-rtb-wrap {
  position: relative;
  display: inline-block;
  white-space: nowrap;
}

.hm-rtb-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #1a1a1a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 16px;
  border-radius: 10px;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  z-index: 100;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.hm-rtb-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #fff;
}

.hm-rtb-wrap:hover .hm-rtb-tooltip {
  display: block;
}

.hm-rtb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: #fff;
  color: #4172b0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  padding: 14px 40px;
  border-radius: 7px;
  border: 2px solid #4172b0;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(65, 114, 176, 0.12), 0 1px 3px rgba(0, 0, 0, 0.06);
  white-space: nowrap;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
  text-decoration: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.hm-rtb-btn:hover {
  background: #eef4fb;
  color: #356299;
  border-color: #356299;
  box-shadow: 0 4px 16px rgba(65, 114, 176, 0.16);
}

.hm-rtb-btn:focus-visible {
  outline: 2px solid #4172b0;
  outline-offset: 3px;
  background: #eef4fb;
}

.hm-rtb-btn:active {
  background: #e3edf8;
  box-shadow: 0 1px 6px rgba(65, 114, 176, 0.14);
}

@media (max-width: 767px) {
  .hm-rtb-btn {
    font-size: 14px;
    font-weight: 600;
    padding: 12px 28px;
    border-radius: 7px;
  }
}

/* Browser Fullscreen API (reader root or documentElement) */
html:fullscreen,
html:-webkit-full-screen {
  background: #000000;
}

html:fullscreen body,
html:-webkit-full-screen body {
  background: #000000;
}

.hm-bro:fullscreen,
.hm-bro:-webkit-full-screen,
.hm-bro.hm-bro--browser-fullscreen,
.hm-bro.hm-bro--browser-fullscreen-fallback {
  background: #000000;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
}

.hm-bro:fullscreen .hm-bro-content-viewport,
.hm-bro:-webkit-full-screen .hm-bro-content-viewport,
.hm-bro.hm-bro--browser-fullscreen .hm-bro-content-viewport,
.hm-bro.hm-bro--browser-fullscreen-fallback .hm-bro-content-viewport {
  margin: 0 clamp(40px, 7vw, 56px);
  padding: 0;
}

.hm-bro:fullscreen .hm-bro-pdf-wrap canvas,
.hm-bro:-webkit-full-screen .hm-bro-pdf-wrap canvas,
.hm-bro.hm-bro--browser-fullscreen .hm-bro-pdf-wrap canvas {
  max-height: min(100%, calc(100dvh - 5.5rem));
  box-shadow: none;
}

.hm-bro:fullscreen .hm-bro-layer img,
.hm-bro:-webkit-full-screen .hm-bro-layer img,
.hm-bro.hm-bro--browser-fullscreen .hm-bro-layer img {
  max-height: min(100%, calc(100dvh - 5.5rem));
}

@media (max-width: 767px), (max-height: 520px) and (max-width: 932px) {
  .hm-bro:fullscreen .hm-bro-content-viewport,
  .hm-bro:-webkit-full-screen .hm-bro-content-viewport,
  .hm-bro.hm-bro--browser-fullscreen .hm-bro-content-viewport,
  .hm-bro.hm-bro--browser-fullscreen-fallback .hm-bro-content-viewport {
    margin: 0;
    padding:
      max(2px, env(safe-area-inset-top, 0px))
      max(2px, env(safe-area-inset-right, 0px))
      0
      max(2px, env(safe-area-inset-left, 0px));
  }

  .hm-bro:fullscreen .hm-bro-pdf-wrap canvas,
  .hm-bro:-webkit-full-screen .hm-bro-pdf-wrap canvas,
  .hm-bro.hm-bro--browser-fullscreen .hm-bro-pdf-wrap canvas,
  .hm-bro.hm-bro--browser-fullscreen-fallback .hm-bro-pdf-wrap canvas {
    max-height: 100%;
  }

  .hm-bro:fullscreen .hm-bro-layer img,
  .hm-bro:-webkit-full-screen .hm-bro-layer img,
  .hm-bro.hm-bro--browser-fullscreen .hm-bro-layer img,
  .hm-bro.hm-bro--browser-fullscreen-fallback .hm-bro-layer img {
    max-height: 100%;
  }
}
