/* =========================================================================== print

   Printing shows the picked cards and nothing else.

   The cards printed are the ones already on the page, at the size they are already drawn:
   no copy is made, no second renderer exists, and nothing is resized. Everything that is
   not a picked card is hidden and the grid is left to flow.
   ================================================================================ */

@media print {

  .topbar,
  .forge-sticky,
  .forge-bar,
  .forge-strip,
  .forge-effect,
  .forge-holder,
  .forge-slot,
  .card-pick,
  .card-delete,
  .toast {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
  }

  /* only a picked card survives */
  .forge-grid > .card-tile:not(.is-picked) {
    display: none !important;
  }

  .forge-section,
  .forge-grid {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
  }

  /*
   * Cards flow across the page. The card carries its own width, so the row breaks where
   * the page does rather than at a number chosen here.
   */
  .card-tile {
    display: inline-block !important;
    vertical-align: top;
    margin: 0 4mm 4mm 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /*
   * A card on paper is exactly one mini-euro card: 44 x 67 mm.
   *
   * `--card-w` is a screen measure, and it is not the right one for paper. At 1x it is 164px,
   * which is 43.39mm -- not 44 -- and the template's own ratio (193.92 / 128.72 = 1.5066) is
   * not mini-euro's (67 / 44 = 1.5227), so no single scale can put both edges in the right
   * place: at 44mm wide a uniformly scaled card is 66.13mm tall. Stating both edges and
   * letting the axes differ is the only way to land in the slot the faction card already
   * fills -- that one is sized in mm below, which is why this discrepancy went unnoticed
   * while a faction card came off the printer taller than the cards beside it.
   *
   * The scale is the template's design box (card.js TEMPLATE.size, 128.72 x 193.92) divided
   * into the slot:
   *   44mm / 128.72px = 166.2992 / 128.72 = 1.291945
   *   67mm / 193.92px = 253.2283 / 193.92 = 1.305839
   * That is a 1.1% stretch on the long edge: a third of a millimetre over the whole card, and
   * it is what makes the cut-out fit a mini-euro sleeve. It is stated here rather than in
   * `scale()` because the printed size is print's business; `transform` overwrites, so this
   * replaces the screen fit outright.
   */
  .forge-grid .card-fit {
    width: 44mm !important;
    height: 67mm !important;
  }

  .forge-grid .card {
    transform: scale(1.291945, 1.305839) !important;
  }

  /*
   * No shadows on paper, and no selection border -- but the faction mark's filter stays.
   *
   * That filter is `brightness(0)`, which is what makes the mark black and lets it darken
   * the artwork instead of painting a colour over it. Stripping every filter here was
   * printing it in full colour.
   */
  .card-tile,
  .card-tile * {
    box-shadow: none !important;
    text-shadow: none !important;
  }

  /*
   * The card's drop shadow is a filter, not a box-shadow, so it survived when the blanket
   * `filter: none` was removed to keep the faction mark black. It is stated per element
   * here, and the mark below is the one thing that keeps a filter.
   */
  .card-tile,
  .card-tile__stage,
  .card-fit,
  .card {
    /*
   * A no-op filter rather than none.
   *
   * On screen the card carries `drop-shadow`, which makes the browser rasterise the whole
   * subtree into its own layer. Printing dropped the filter, so the page was drawn straight
   * onto the surface -- a different path to the ink, and rasterising small glyphs on a
   * different path is a known source of a roughly one-pixel vertical shift that leaves vector
   * frames and artwork alone. `opacity(1)` keeps the layer without changing any pixel, so both
   * renderers take the same route.
   */
  filter: opacity(1) !important;
}

/* the wrappers around the card must take the same path, or the layer is created twice */
.forge-grid .card-tile,
.forge-grid .card-tile__stage,
.forge-grid .card-fit {
  filter: opacity(1) !important;
  }

  /* the mark keeps its own filter: it is what makes it a silhouette */
  .card-tile .card-faction-mark .faction-mark {
    filter: brightness(0) opacity(0.45) !important;
  }
  /*
   * ...and a mark that is still a *glyph* gets the cautious treatment.
   *
   * Faction marks are normally artwork: an `<svg>`, either the faction's own file or -- since
   * tools/fa-paths.py vendored the outlines -- a Font Awesome icon drawn as a path. Those take
   * the filter above and the quarter offset, and print.
   *
   * A `<i>` only appears when the outline file does not cover the icon. Verified in Firefox,
   * which is the browser that prints here: a glyph mark is lost entirely when it is filtered
   * or offset -- with the transform, a relative `left`/`top`, even a percentage one, the
   * silhouette printed as nothing. So a glyph mark is painted black, darkens with `opacity`
   * instead of a filter, and sits centred in the window rather than straddling its corner.
   * Better a silhouette in the wrong spot than none.
   */
  .card-tile .card-faction-mark .faction-mark:has(i) {
    filter: none !important;
    opacity: 0.45 !important;
    transform: none !important;
    position: static !important;
  }
  .card-tile .card-faction-mark .faction-mark i {
    background-image: none !important;
    -webkit-background-clip: border-box !important;
    background-clip: border-box !important;
    -webkit-text-fill-color: #000 !important;
    color: #000 !important;
  }
  .card-tile.is-picked .card-tile__stage,
  .card-tile__stage {
    outline: none !important;
    outline-offset: 0 !important;
    border: 0 !important;
  }

  /* the artwork is the point: print it as drawn */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

}

/* on screen the count line does not exist */
@media screen {
  .print-only {
    display: none;
  }
}

/* ====================================================== faction cards on paper

   A faction's card is landscape by design; the sheet is portrait, so it is turned here --
   at print time only, which is where the turn belongs. It is laid out in a box of the
   card's portrait size, with the landscape card centred inside it and rotated.
   ======================================================================== */

#print-sheet-factions,
#forge-faction-sheet {
  display: block !important;
}

/*
 * The box the sheet lays out: portrait, the footprint of one card.
 */
/*
 * A faction's card: landscape by design, turned into one portrait slot.
 *
 * The design is 88 x 57.8 -- the slot's 44 : 67 turned on its side. That ratio is the whole
 * point: turned, the card is 57.8 wide by 88 tall, and 44 / 57.8 = 0.761 makes it 44 by 67
 * exactly. An 88 x 66.8 design could only ever reach 44 by 58, which is why it sat short of
 * the cards beside it however it was scaled.
 */
.forge-grid .faction-print {
  position: relative;
  display: inline-block;
  vertical-align: top;
  width: 44mm;
  height: 67mm;
  margin: 0 3mm 3mm 0;
  break-inside: avoid;
  page-break-inside: avoid;
}

.forge-grid .faction-print .faction-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 88mm;
  height: 57.8mm;
  transform-origin: center center;
  transform: translate(-50%, -50%) rotate(90deg) scale(0.761);
}

.forge-grid .faction-print .faction-card__panel {
  font-size: 11.5pt;
}

/* ============================================ two factions to a page

   A faction's block is two faction faces plus its six card places: eight slots, one row of
   four and its second row. Two of those fill an A4 sheet exactly, so the break goes after
   every second faction.
   ================================================================= */



@media print {
  /* only the factions being printed take room: empty sections were making 11 pages */
  .forge-section:not(:has(.card-tile.is-picked)):not(:has(.faction-print)) {
    display: none !important;
  }
}

@media print {
  /*
   * A folded section must still print.
   *
   * Folding hides the grid with `display: none`, so its cards had no layout to measure and
   * every one of them was fitted to nothing -- the tiny cards. Folding is a screen
   * convenience; paper shows everything that was picked.
   */
  .forge-section.is-folded .forge-grid,
  .forge-section .forge-grid {
    display: flex !important;
    /*
     * `display: flex` alone is a single row: the grid's own wrap was lost with it, and the
     * cards piled up on one line. The wrap has to be stated as well.
     */
    flex-wrap: wrap !important;
    gap: 1.6mm !important;
  }
}

@media print {
  /* a faction hidden on screen is not printed */
  .forge-section.is-print-hidden {
    display: none !important;
  }
}
