/* PageOnBook mobile navigation and viewer controls — v1.4 */
@media (max-width: 1050px) {
  .site-shell {
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }

  /* Keep every product function available as a thumb-friendly mobile menu. */
  .topbar nav[aria-label="주요 메뉴"] {
    position: fixed;
    z-index: 950;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    min-height: 60px;
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(21, 34, 56, 0.16);
    background: rgba(255, 253, 248, 0.97);
    box-shadow: 0 -10px 28px rgba(21, 34, 56, 0.12);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }

  .topbar nav[aria-label="주요 메뉴"] a,
  .topbar nav[aria-label="주요 메뉴"] button {
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 50px;
    margin: 0;
    padding: 7px 4px;
    border: 0;
    border-radius: 10px;
    color: var(--ink);
    background: transparent;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .topbar nav[aria-label="주요 메뉴"] a:focus-visible,
  .topbar nav[aria-label="주요 메뉴"] button:focus-visible {
    outline: 3px solid rgba(239, 106, 91, 0.35);
    outline-offset: -3px;
  }

  .topbar nav[aria-label="주요 메뉴"] a:active,
  .topbar nav[aria-label="주요 메뉴"] button:active {
    color: var(--coral);
    background: rgba(239, 106, 91, 0.1);
  }
}

@media (max-width: 650px) {
  .topbar {
    width: calc(100% - 24px);
  }

  .header-actions {
    gap: 10px;
  }

  .small-cta {
    white-space: nowrap;
  }

  /* Keep all four actions inside the phone viewport after a book is opened. */
  .viewer-actions {
    top: 2px;
    right: 4px;
    left: 4px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    width: auto;
  }

  .viewer-actions button {
    justify-content: center;
    min-width: 0;
    min-height: 42px;
    padding: 8px 4px;
    overflow: hidden;
    font-size: 10px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .book-stage:has(.viewer-actions) .book-wrap {
    margin-top: 44px;
  }

  .book-stage:has(.viewer-actions) .stage-glow {
    transform: translateY(22px);
  }

  .download-modal,
  .library-modal,
  .share-modal,
  .publication-modal,
  .image-order-modal,
  .auth-modal,
  .limit-modal {
    max-width: calc(100vw - 20px);
  }
}

@media (max-width: 370px) {
  .brand strong {
    font-size: 16px;
  }

  .small-cta {
    padding: 10px 9px;
    font-size: 10px;
  }

  .topbar nav[aria-label="주요 메뉴"] a,
  .topbar nav[aria-label="주요 메뉴"] button {
    font-size: 11px;
  }

  .viewer-actions button {
    font-size: 9px;
  }
}
