/**
 * @theme Savannah · Flamingo Magazine
 * @version 1.0
 * @description PROJECT FILE. NOT A CASCADE LAYER. The skin for the TNC
 *              FlipBook 3D reader inside its iframe.
 *
 * Loaded ONLY inside the TNC FlipBook iframe, by the tncfb3d_viewer_head
 * hook in functions.php (§11), after _tokens.css and _fonts.css. It never
 * loads on a theme page, and nothing in functions.php enqueues it.
 *
 * The viewer is a standalone document: none of the six layers reach
 * it. This file skins the plugin's own markup to match FlipbookViewer()
 * in src/routes/2026.06.01.v-32-summer-travel-issue.tsx.
 *
 * SCOPE AND WEIGHT: every selector starts html.fm_viewer body (the class
 * is added by the same hook). That scopes the skin to this site and
 * puts it at (0,2,2)+, over the plugin's body.layout-bottom-fullwidth
 * rules at (0,2,1). This file loads after the plugin's stylesheet, so
 * equal weight also wins.
 *
 * Plugin markup (tnc-flipbook-template.html, v1.2.2):
 *   #canvas-container          the WebGL book
 *   .side-nav.left/.right      #prevBtn #firstBtn / #nextBtn #lastBtn
 *   .bottom-toolbar            .toolbar-left (page) .toolbar-center
 *                              (buttons) .toolbar-right (logo)
 *   #thumbnailsSidebar         the thumbnail panel
 *   #morePopup                 the More menu
 * Hidden items are removed in functions.php (tncfb3d_config), not
 * here — the plugin hides them itself and re-flows the toolbar.
 *
 * Re-verify selectors on every plugin update. A renamed class fails
 * silently: the stock viewer comes back, nothing errors.
 *
 * Design values (the Lovable classes behind each size) are in the
 * build guide.
 */


/* ==========================================================================
   # 01. VIEWER DOCUMENT
   ========================================================================== */

html.fm_viewer {
  /**
   * Match the parent page. A dark color-scheme in the frame and a light
   * one outside makes Chromium paint the iframe OPAQUE, and the row
   * behind it disappears.
   */
  color-scheme: normal;

  /**
   * The zone under the canvas the toolbar sits in.
   * LITERAL: 70px = 44px buttons, 12px padding top and bottom, and the
   * border. The zone adds a 24px gap above the toolbar.
   */
  --fm-toolbar-height: 70px;
  --fm-toolbar-zone: calc(var(--fm-toolbar-height) + var(--jcd-space-lg));
}

/**
 * The plugin's first-paint style sets html, body to its chrome colour
 * until its script runs; (0,1,1) / (0,1,2) beat its (0,0,1).
 */
html.fm_viewer,
html.fm_viewer body {
  background: transparent;
}

html.fm_viewer body {
  font-family: var(--jcd-font-sans);
  color: var(--jcd-color-paper);
}

/**
 * One ring for every control. Paper, not --jcd-color-focus: the token
 * measures 3.11:1 on ink, which _tokens.css flags as the tight case.
 * Paper on this ground is ~19:1.
 */
html.fm_viewer body :focus-visible {
  outline: 2px solid var(--jcd-color-paper);
  outline-offset: 2px;
}


/* ==========================================================================
   # 02. CANVAS PANEL
   ========================================================================== */

/**
 * The toolbar sits below the panel, not over it. The WebGL canvas is
 * transparent (transparentBackground in functions.php), so this
 * background is the panel.
 *
 * VERIFY on staging: the renderer must size itself to the container
 * after the margin. If the book renders under the toolbar, the plugin
 * is reading the window, not the container.
 */
html.fm_viewer body #canvas-container {
  margin-bottom: var(--fm-toolbar-zone);
  transform: none;                                 /* plugin nudges it up 30px */
  border-radius: var(--jcd-radius-sm);
  background-color: var(--jcd-color-ink);
}


/* ==========================================================================
   # 03. HIDDEN CONTROLS (NOT IN THE DESIGN)
   ========================================================================== */

/**
 * The zoom minimap (cover thumbnail, top left) has no equivalent in the
 * Loveable reader. The plugin renders it as aside#minimap inside
 * #minimapContainer and shows it as an empty dark pill before any zoom,
 * so both are hidden.
 *
 * The buttons below are switched off in functions.php, but the plugin
 * only hides them once the PDF has loaded — for the first seconds they
 * all show. Hiding them here removes that flash. Download is left to
 * the config so FM_FLIPBOOK_DOWNLOAD still controls it.
 */
html.fm_viewer body :is(#minimapContainer, #minimap),
html.fm_viewer body :is(#firstBtn, #lastBtn, #shareBtn, #printBtn, #searchBtn, #tiltBtn, #rotateBtn, #readingModeBtn, #readAloudBtn, #themeToggleBtn, #themeToggleCtrl) {
  display: none !important;   /* the plugin's own visibility code sets inline styles */
}


/* ==========================================================================
   # 04. PAGE ARROWS
   ========================================================================== */

/**
 * 44px circles, 1px white/20 border, white/70 glyph; white on hover.
 * Centred on the canvas, not the frame.
 */
html.fm_viewer body .side-nav {
  top: calc((100% - var(--fm-toolbar-zone)) / 2);
}

html.fm_viewer body .side-nav.left  { left: var(--jcd-space-md); }
html.fm_viewer body .side-nav.right { right: var(--jcd-space-md); }

html.fm_viewer body .nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--jcd-color-inverse-rule);
  border-radius: var(--jcd-radius-pill);
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--jcd-color-inverse-body);
  transition:
    border-color var(--jcd-duration-base) ease-out,
    color var(--jcd-duration-base) ease-out;
}

html.fm_viewer body .nav-btn:hover {
  border-color: var(--jcd-color-paper);
  background: transparent;
  color: var(--jcd-color-paper);
}

html.fm_viewer body .nav-btn svg {
  width: 20px;
  height: 20px;
}


/* ==========================================================================
   # 05. TOOLBAR
   ========================================================================== */

/**
 * A full-width pill under the canvas: zoom group left, page centred,
 * actions right. The plugin nests the buttons in .toolbar-center; with
 * display: contents they join the toolbar's own flex line, and order
 * plus one auto margin produce the three groups without moving any
 * element in the DOM — tab order stays the plugin's.
 */
html.fm_viewer body .bottom-toolbar {
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: var(--jcd-space-sm);
  min-height: var(--fm-toolbar-height);
  padding: var(--jcd-space-sm) var(--jcd-space-md);    /* min-height keeps the bar at 70px */
  border: 0;                                       /* no outline round the bar — client request 2026-10-21; the buttons keep theirs */
  border-radius: var(--jcd-radius-pill);
  background: color-mix(in srgb, var(--jcd-color-ink) 40%, transparent);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}

html.fm_viewer body .bottom-toolbar .toolbar-center {
  display: contents;
}

html.fm_viewer body .bottom-toolbar :is(.toolbar-divider, .toolbar-right) {
  display: none;
}

/* Group 1 — zoom */
html.fm_viewer body #zoomOutBtn      { order: 1; }
html.fm_viewer body .zoom-dropdown   { order: 2; }
html.fm_viewer body #zoomInBtn       { order: 3; }

/* Group 2 — page, centred by its auto margins */
html.fm_viewer body .bottom-toolbar .toolbar-left {
  order: 4;
  display: flex;
  margin-inline: auto;
}

/* Group 3 — actions */
html.fm_viewer body #fmThumbsBtn     { order: 5; }
html.fm_viewer body #downloadBtn     { order: 6; }
html.fm_viewer body #fullscreenBtn   { order: 7; }
html.fm_viewer body #moreBtn         { order: 8; }


/* ==========================================================================
   # 06. TOOLBAR BUTTONS
   ========================================================================== */

/**
 * Round 44px icon buttons (zoom, More) and pill text buttons
 * (Thumbnails, Download PDF, Full Screen), both with the white/20
 * border that goes white on hover.
 */
html.fm_viewer body .bottom-toolbar .toolbar-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--jcd-color-inverse-rule);
  border-radius: var(--jcd-radius-pill);
  background: transparent;
  color: var(--jcd-color-inverse-body);
  transition:
    border-color var(--jcd-duration-base) ease-out,
    color var(--jcd-duration-base) ease-out;
}

html.fm_viewer body .bottom-toolbar .toolbar-btn:hover,
html.fm_viewer body .bottom-toolbar .toolbar-btn.active {
  border-color: var(--jcd-color-paper);
  background: transparent;
  box-shadow: none;
  color: var(--jcd-color-paper);
}

/* The design has no tooltips; every button keeps its aria-label. */
html.fm_viewer body .bottom-toolbar .tooltip {
  display: none;
}

/**
 * Text buttons. The label is generated content: each button's
 * accessible name comes from its aria-label, which outranks CSS
 * content, so screen readers hear the plugin's own label once.
 */
html.fm_viewer body :is(#fmThumbsBtn, #downloadBtn, #fullscreenBtn) {
  width: auto;
  padding: 0 var(--jcd-space-md);
  font-family: var(--jcd-font-sans);
  font-size: var(--jcd-text-btn);
  font-weight: var(--jcd-weight-semi);
  line-height: 1;
  letter-spacing: var(--jcd-tracking-nav);
  text-transform: uppercase;
  white-space: nowrap;
}

html.fm_viewer body :is(#fmThumbsBtn, #downloadBtn, #fullscreenBtn) svg {
  display: none;
}

html.fm_viewer body #fmThumbsBtn::after   { content: "Thumbnails"; }
html.fm_viewer body #downloadBtn::after   { content: "Download PDF"; }
html.fm_viewer body #fullscreenBtn::after { content: "Full Screen"; }

html.fm_viewer:is(:fullscreen, :has(:fullscreen)) body #fullscreenBtn::after {
  content: "Exit Full Screen";
}


/* ==========================================================================
   # 07. ZOOM READOUT
   ========================================================================== */

/**
 * The plugin's zoom <select> becomes the design's "100%" between − and
 * +. It stays a working select: click it for the preset levels.
 *
 * LITERAL: 11px readout text, here and in # 08. It is a readout, not body
 * text, and no type token is that small.
 */
html.fm_viewer body .zoom-dropdown::after {
  display: none;                                   /* the chevron */
}

html.fm_viewer body .zoom-select {
  min-width: 48px;
  padding: 0 var(--jcd-space-xs);
  border: 0;
  background: transparent;
  color: var(--jcd-color-inverse-muted);
  font-family: var(--jcd-font-sans);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-align-last: center;
}

html.fm_viewer body .zoom-select option,
html.fm_viewer body .zoom-select optgroup {
  background-color: var(--jcd-color-ink);
  color: var(--jcd-color-paper);
}


/* ==========================================================================
   # 08. PAGE INDICATOR
   ========================================================================== */

/**
 * "PAGE 12–13 / 148". The design's typed page field has no plugin
 * equivalent; Thumbnails and search cover jumping to a page.
 */
html.fm_viewer body .page-indicator {
  min-width: 0;
  padding: 0;
  background: transparent;
  color: var(--jcd-color-inverse-muted);
  font-family: var(--jcd-font-sans);
  font-size: 11px;
  font-weight: var(--jcd-weight-regular);
  font-variant-numeric: tabular-nums;
}

html.fm_viewer body .page-indicator::before {
  content: "Page" / "";
  margin-right: var(--jcd-space-sm);
  font-size: var(--jcd-text-kicker);
  letter-spacing: var(--jcd-tracking-nav);
  text-transform: uppercase;
}


/* ==========================================================================
   # 09. THUMBNAIL DRAWER
   ========================================================================== */

/**
 * The design's drawer is a horizontal strip above the toolbar, not the
 * plugin's left sidebar. Same element, re-laid out; it still opens and
 * closes through the plugin's own .active class.
 *
 * LITERAL: 72px thumbnails at 3:4, from the design.
 */
html.fm_viewer body .thumbnails-sidebar {
  top: auto;
  left: 0;
  right: 0;
  bottom: calc(var(--fm-toolbar-height) + var(--jcd-space-md));   /* 16px above the toolbar */
  width: auto;
  height: auto;
  border: 1px solid color-mix(in srgb, var(--jcd-color-paper) 10%, transparent);
  border-radius: var(--jcd-radius-sm);
  background: color-mix(in srgb, var(--jcd-color-ink) 90%, transparent);
  transform: translateY(var(--jcd-space-sm));
  opacity: 0;
  transition:
    transform var(--jcd-duration-base) var(--jcd-ease-out),
    opacity var(--jcd-duration-base) ease-out,
    visibility 0s linear var(--jcd-duration-base);
}

html.fm_viewer body .thumbnails-sidebar.active {
  transform: none;
  opacity: 1;
  transition:
    transform var(--jcd-duration-base) var(--jcd-ease-out),
    opacity var(--jcd-duration-base) ease-out,
    visibility 0s linear 0s;
}

/* Opened and closed from the Thumbnails button, which also takes Esc. */
html.fm_viewer body .thumbnails-header {
  display: none;
}

html.fm_viewer body .thumbnails-grid {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: var(--jcd-space-sm);
  padding: var(--jcd-space-md);
  overflow-x: auto;
  overflow-y: hidden;
}

html.fm_viewer body .thumbnail {
  flex: 0 0 72px;
  width: 72px;
  aspect-ratio: 3 / 4;
  border: 1px solid color-mix(in srgb, var(--jcd-color-paper) 10%, transparent);
  border-radius: var(--jcd-radius-none);
  background: transparent;
}

html.fm_viewer body .thumbnail:hover {
  border-color: color-mix(in srgb, var(--jcd-color-paper) 60%, transparent);
}


/* ==========================================================================
   # 10. MORE MENU AND LOADER
   ========================================================================== */

html.fm_viewer body .more-popup {
  bottom: calc(var(--fm-toolbar-height) + var(--jcd-space-sm));
  left: auto;
  right: 0;
  border: 1px solid color-mix(in srgb, var(--jcd-color-paper) 10%, transparent);
  border-radius: var(--jcd-radius-sm);
  background: var(--jcd-color-ink);
  font-family: var(--jcd-font-sans);
}

html.fm_viewer body #loading {
  color: var(--jcd-color-inverse-muted);
  font-family: var(--jcd-font-sans);
}

html.fm_viewer body .loading-title {
  font-size: var(--jcd-text-kicker);
  font-weight: var(--jcd-weight-semi);
  letter-spacing: var(--jcd-tracking-kicker);
  text-transform: uppercase;
}

html.fm_viewer body .progress-bar {
  background: var(--jcd-color-accent);
}


/* ==========================================================================
   # 11. SMALL SCREENS
   ========================================================================== */

/**
 * DELIBERATE DEPARTURE from the design. Loveable lets the toolbar wrap
 * onto two or three lines; the canvas zone above is a fixed height, so
 * a wrapped toolbar would sit over the pages. Instead the toolbar stays
 * one line: text buttons fall back to their icons, and on phones the
 * zoom group goes — pinch-zoom replaces it on touch.
 *
 * Queries measure the IFRAME, which is the width of its row.
 */
@media (max-width: 768px) {
  html.fm_viewer body :is(#fmThumbsBtn, #downloadBtn, #fullscreenBtn) {
    width: 44px;
    padding: 0;
  }

  html.fm_viewer body :is(#fmThumbsBtn, #downloadBtn, #fullscreenBtn) svg {
    display: block;
  }

  html.fm_viewer body :is(#fmThumbsBtn, #downloadBtn, #fullscreenBtn)::after,
  html.fm_viewer:is(:fullscreen, :has(:fullscreen)) body #fullscreenBtn::after {
    content: none;
  }

  html.fm_viewer body .side-nav.left  { left: var(--jcd-space-sm); }
  html.fm_viewer body .side-nav.right { right: var(--jcd-space-sm); }
}

@media (max-width: 560px) {
  /**
   * One line on a 300px frame: 44px targets kept, the padding, gap and
   * the "Page" label give the room. 60 = 44 + 8 top + 8 bottom.
   */
  html.fm_viewer {
    --fm-toolbar-height: 60px;
  }

  html.fm_viewer body .bottom-toolbar {
    width: auto;
    max-width: none;
    flex-wrap: nowrap;
    gap: var(--jcd-space-xs);
    padding: var(--jcd-space-sm);
  }

  html.fm_viewer body :is(#zoomOutBtn, #zoomInBtn, .zoom-dropdown) {
    display: none;
  }

  html.fm_viewer body .bottom-toolbar .toolbar-left {
    margin-inline: var(--jcd-space-sm) auto;       /* page left, actions right */
  }

  html.fm_viewer body .page-indicator::before {
    content: none;                                 /* "1 / 116" alone */
  }
}

@media (prefers-reduced-motion: reduce) {
  html.fm_viewer body .thumbnails-sidebar,
  html.fm_viewer body .thumbnails-sidebar.active {
    transition: none;
  }
}