/* ==========================================================================
   PAGE/OUT — WEB MAGAZINE NEXT (REV.01)
   Print Edition Viewer (68-Page B5 Right-to-Left Magazine on Gallery Desk)
   ========================================================================== */

html,
body.print-viewer-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.print-viewer-page {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink-deep);
}

body.print-viewer-page .site-mast {
  position: relative;
  flex: none;
  z-index: 90;
}

body.print-viewer-page .site-mast__inner {
  min-height: 58px;
  padding-block: 4px;
}

.viewer-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.viewer {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Top Viewer Tools Bar
   ========================================================================== */

.tools {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px clamp(12px, 3vw, 40px);
  background: var(--paper-bright);
  border-bottom: 1px solid var(--rule);
}

.identity {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.identity h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 19px;
  line-height: 1.2;
  color: var(--ink-deep);
  white-space: nowrap;
}

.identity .edition-spec {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  white-space: nowrap;
}

.toolgroup {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.format {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.format > span {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.format select,
.page-label select {
  appearance: none;
  min-height: 38px;
  padding: 4px 24px 4px 9px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-xs);
  background: var(--paper-bright)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%23182320' stroke-width='1.5' d='m1 1 4 4 4-4'/%3E%3C/svg%3E")
    right 7px center / 9px auto no-repeat;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-deep);
}

.separator {
  width: 1px;
  height: 18px;
  background: var(--rule);
  flex-shrink: 0;
}

.tool-btn,
.pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-xs);
  background: var(--paper);
  color: var(--ink-deep);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.18s, background-color 0.18s, color 0.18s;
}

.tool-btn:hover,
.pdf-link:hover {
  border-color: var(--forest);
  background: var(--paper-warm);
  color: var(--terracotta);
}

.toolgroup svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  flex-shrink: 0;
}

/* ==========================================================================
   Unobtrusive Bookmark Resume Strip
   ========================================================================== */

.print-bookmark-bar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 7px clamp(12px, 3vw, 40px);
  background: #23332f;
  color: var(--paper-bright);
  border-bottom: 1px solid rgba(201, 164, 92, 0.42);
  font-size: 13px;
}

.print-bookmark-bar[hidden] {
  display: none;
}

.print-bookmark-bar__text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.print-bookmark-bar__badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 2px 7px;
  border: 1px solid var(--brass);
  color: var(--brass-bright);
  border-radius: var(--radius-xs);
  white-space: nowrap;
}

.print-bookmark-bar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.print-bookmark-bar button {
  min-height: 32px;
  padding: 4px 11px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 700;
}

#bookmark-resume-btn {
  background: var(--brass);
  color: #131c19;
  border: 1px solid var(--brass);
}

#bookmark-resume-btn:hover {
  background: var(--brass-bright);
}

#bookmark-clear-btn {
  background: transparent;
  color: rgba(250, 248, 245, 0.85);
  border: 1px solid rgba(250, 248, 245, 0.34);
}

#bookmark-clear-btn:hover {
  border-color: var(--brass-bright);
  color: var(--paper-bright);
}

#bookmark-dismiss-btn {
  background: transparent;
  border: 0;
  color: rgba(250, 248, 245, 0.72);
  padding: 4px 8px;
}

/* ==========================================================================
   Gallery-Desk Viewing Mat Stage (Deep Slate-Green #1B2623 + Brass Framing)
   ========================================================================== */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
  background:
    radial-gradient(ellipse 68% 58% at 50% 42%, rgba(212, 176, 106, 0.08), transparent 72%),
    radial-gradient(ellipse 90% 90% at 50% 50%, #202e2a 0%, #17211e 100%);
  box-shadow: inset 0 1px 0 rgba(212, 176, 106, 0.16), inset 0 -1px 0 rgba(212, 176, 106, 0.14);
}

.stage[data-zoomed="true"] {
  touch-action: pan-x pan-y pinch-zoom;
}

.stage:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: -3px;
}

.film {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  display: grid;
  justify-items: center;
  align-items: center;
  padding: clamp(10px, 1.8vw, 22px);
}

/* Right-to-Left B5 Magazine Sheet */
.sheet {
  position: relative;
  display: flex;
  flex-direction: row-reverse;
  align-items: stretch;
  line-height: 0;
  background: #f8f5ed;
  border: 1px solid rgba(212, 176, 106, 0.28);
  box-shadow:
    0 24px 56px -14px rgba(5, 11, 9, 0.72),
    0 4px 14px rgba(5, 11, 9, 0.38);
}

.sheet[data-paired="true"]::after {
  content: "";
  position: absolute;
  pointer-events: none;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 22px;
  transform: translateX(-50%);
  background: linear-gradient(
    90deg,
    rgba(16, 22, 20, 0) 0%,
    rgba(16, 22, 20, 0.08) 32%,
    rgba(16, 22, 20, 0.24) 50%,
    rgba(16, 22, 20, 0.08) 68%,
    rgba(16, 22, 20, 0) 100%
  );
  z-index: 2;
}

.leaf {
  position: relative;
  margin: 0;
  width: var(--page-width, 240px);
  height: var(--page-height, 339px);
  aspect-ratio: 182 / 257;
  flex: none;
  background: #f8f5ed;
}

.leaf img {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.hotspot {
  position: absolute;
  z-index: 3;
  display: block;
  border-radius: 2px;
  transition: background-color 0.16s, box-shadow 0.16s;
}

.hotspot:hover {
  background: rgba(181, 139, 66, 0.14);
  box-shadow: inset 0 0 0 1px rgba(184, 74, 57, 0.55);
}

.hotspot:focus-visible {
  outline: 2px solid var(--terracotta);
  outline-offset: 0;
  background: rgba(184, 74, 57, 0.16);
}

.load-status {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 90%;
  padding: 9px 16px;
  background: var(--paper-bright);
  color: var(--ink-deep);
  border: 1px solid var(--brass);
  border-radius: var(--radius-xs);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
  font-size: 13px;
}

.load-status[hidden] {
  display: none;
}

.load-status button {
  margin-left: 8px;
  padding: 2px 6px;
  border: 0;
  background: transparent;
  color: var(--terracotta);
  font-weight: 700;
  text-decoration: underline;
}

/* ==========================================================================
   Bottom Paging & Zoom Controls Bar
   ========================================================================== */

.controls {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 6px clamp(10px, 3vw, 40px) max(6px, env(safe-area-inset-bottom));
  background: var(--paper-bright);
  border-top: 1px solid var(--rule);
}

.paging {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.paging button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 40px;
  padding: 5px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-xs);
  background: var(--paper);
  color: var(--ink-deep);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: background-color 0.16s, border-color 0.16s;
}

.paging button:enabled:hover {
  border-color: var(--forest);
  background: var(--paper-warm);
}

.paging button:disabled {
  opacity: 0.34;
  cursor: default;
}

.page-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.total {
  font-size: 12px;
  color: var(--ink-soft);
}

.page-context {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.zoom {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-xs);
  overflow: hidden;
  flex-shrink: 0;
}

.zoom button {
  min-width: 38px;
  min-height: 38px;
  padding: 4px 6px;
  border: 0;
  background: var(--paper-bright);
  color: var(--ink-deep);
  font-size: 14px;
  font-weight: 700;
  transition: background-color 0.16s;
}

.zoom button:enabled:hover {
  background: var(--paper-warm);
}

.zoom button:disabled {
  opacity: 0.34;
  cursor: default;
}

.zoom #fit {
  font-size: 12px;
  min-width: 46px;
  font-variant-numeric: tabular-nums;
  border-inline: 1px solid var(--rule);
}

/* ==========================================================================
   TOC Modal Dialog
   ========================================================================== */

dialog#toc {
  padding: 0;
  width: min(480px, calc(100vw - 24px));
  max-height: 82dvh;
  background: var(--paper-bright);
  color: var(--ink-deep);
  border: 1px solid var(--forest);
  border-top: 3px solid var(--brass);
  border-radius: var(--radius-xs);
  box-shadow: 0 28px 64px rgba(10, 18, 16, 0.42);
}

dialog#toc::backdrop {
  background: rgba(14, 22, 19, 0.72);
  backdrop-filter: blur(3px);
}

.toc-top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px 12px;
  background: var(--paper-bright);
  border-bottom: 1px solid var(--rule-strong);
}

.toc-top span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--terracotta);
}

.toc-top h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 23px;
  line-height: 1.25;
}

.toc-top button {
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-xs);
  background: var(--paper);
  font-size: 13px;
  font-weight: 700;
}

#toc-list {
  padding: 4px 20px 14px;
}

#toc-list a {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--rule);
  line-height: 1.45;
  font-size: 14px;
}

#toc-list a:hover {
  color: var(--terracotta);
}

#toc-list .sub {
  font-size: 12.5px;
  color: var(--ink-soft);
  padding-left: 14px;
}

#toc-list .folio {
  min-width: 24px;
  color: var(--terracotta);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#toc-list [aria-current="location"] {
  color: var(--terracotta);
  font-weight: 700;
}

.toc-bookmark-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  background: var(--paper-warm);
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-soft);
}

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

.toc-bookmark-foot button {
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-xs);
  background: var(--paper-bright);
  font-size: 12px;
  font-weight: 700;
}

.noscript-box {
  position: fixed;
  inset: auto 10% 35% 10%;
  padding: 18px;
  background: var(--paper-bright);
  border: 1px solid var(--forest);
  text-align: center;
  z-index: 200;
}

.noscript-box a {
  text-decoration: underline;
  font-weight: 700;
}

/* ==========================================================================
   Responsive Mobile Toolbar (Zero Overflow down to 360px)
   ========================================================================== */

@media (max-width: 860px) {
  .page-context,
  .format > span {
    display: none;
  }
}

@media (max-width: 760px) {
  body.print-viewer-page .site-mast__inner {
    min-height: 52px;
  }

  .tools {
    padding: 5px 10px;
    gap: 8px;
  }

  .identity h1 {
    font-size: 16px;
  }

  .identity .edition-spec {
    display: none;
  }

  .toolgroup {
    gap: 6px;
  }

  .separator {
    display: none;
  }

  .format select {
    min-height: 36px;
    font-size: 12px;
    padding: 4px 20px 4px 7px;
  }

  .tool-btn,
  .pdf-link {
    min-height: 36px;
    padding: 4px 8px;
    font-size: 12px;
    gap: 4px;
  }

  .pdf-link .pdf-ext-label {
    display: none;
  }

  .controls {
    padding: 5px 8px max(5px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .paging {
    gap: 4px;
  }

  .paging button {
    min-height: 40px;
    padding: 5px 8px;
    font-size: 12px;
    gap: 3px;
  }

  .page-label select {
    min-height: 40px;
    padding: 4px 20px 4px 7px;
    font-size: 12px;
  }

  .total {
    font-size: 11px;
  }

  .zoom button {
    min-width: 34px;
    min-height: 40px;
    padding: 3px 4px;
  }

  .zoom #fit {
    min-width: 40px;
    font-size: 11px;
  }

  .film {
    padding: 8px;
  }
}

@media (max-width: 390px) {
  .tools {
    padding: 4px 6px;
    gap: 5px;
  }

  .toolgroup {
    gap: 4px;
  }

  .controls {
    padding: 4px 5px max(4px, env(safe-area-inset-bottom));
    gap: 4px;
  }

  .paging button {
    padding: 4px 6px;
    font-size: 11.5px;
  }

  .zoom button {
    min-width: 30px;
  }

  .zoom #fit {
    min-width: 36px;
  }
}
