/* Print-friendly styles for blog posts. Included on every page but only
   changes the layout/visuals when the user invokes the browser print dialog
   (or window.print()). */

/* ----------------------------------------------------------------------------
   On-screen print button styling (only visible on blog posts)
   ---------------------------------------------------------------------------- */
/* Screen layout: print button sits to the right of the title, vertically centred */
.post-header-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.post-header-titles {
  flex: 1 1 auto;
  min-width: 0;
}

.print-button,
a.print-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25em;
  height: 3.25em;
  padding: 0;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-nav);
  cursor: pointer;
}

.print-button:hover,
.print-button:focus,
a.print-button:hover,
a.print-button:focus {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text);
}

a.print-button::before {
  margin: 0;
}

.print-button::before {
  content: '';
  display: inline-block;
  width: 1.6em;
  height: 1.6em;
  background-color: currentColor;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 10V6l8-4 8 4v4'/%3E%3Cpath d='M4 10h16'/%3E%3Cpath d='M4 10v6h4v-2h8v2h4v-6'/%3E%3Cpath d='M8 16v4l8 4 8-4v-4'/%3E%3Cpath d='M8 16l8 4 8-4'/%3E%3Cpath d='M16 14v6'/%3E%3C/svg%3E");
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9V2h12v7'/%3E%3Cpath d='M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/%3E%3Cpath d='M6 14h12v8H6z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

/* ----------------------------------------------------------------------------
   Print dialog overrides
   ---------------------------------------------------------------------------- */
@media print {
  /* Suggest A5 as the default page size */
  @page {
    size: A5;
    margin: 15mm;
  }

  /* Reset the dark theme to a printer-friendly light palette */
  :root {
    --bg: #ffffff;
    --text: #000000;
    --text2: #222222;
    --text-secondary: #444444;
    --accent: #000000;
    --border: #cccccc;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 100%;
  }

  /* Hide site chrome that isn't part of the article */
  .skip-link,
  .site-nav,
  .site-footer,
  .print-button,
  .post-header-divider,
  .post-divider,
  .site-footer::before {
    display: none !important;
  }

  /* Use the full page width, remove side padding from the layout */
  .page-wrapper,
  .page-content,
  main {
    display: block !important;
    padding: 0 !important;
  }

  .page-content {
    padding: 0 !important;
  }

  main {
    max-width: none !important;
    padding: 0 !important;
  }

  .wrapper {
    padding: 0 !important;
  }

  .content {
    max-width: none !important;
  }

  /* Fit the printed page to the content; avoid creating an extra blank page */
  html, body, .page-wrapper, .page-content, main, .wrapper, article.content {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  article.content {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  /* ASCII dashed-frame title card, shown only when printing */
  .post-header-frame {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 70%;
    margin: 0 auto var(--space-md);
    padding: var(--space-sm);
    border: 2px dashed var(--border);
  }

  .post-header-top,
  .post-header-bottom {
    width: 100%;
  }

  .post-header-frame h1 {
    margin: 0 0 var(--space-xs);
  }

  .post-header-frame .post-tagline {
    margin: 0;
    color: var(--text-secondary);
  }

  .post-frame-separator {
    width: 100%;
    border: 0;
    border-top: 2px dashed var(--border);
    margin: var(--space-sm) 0;
  }

  .post-header-frame .post-meta-line {
    margin: 0;
  }

  /* Typography tweaks for paper */
  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    margin-top: 1.5em;
  }

  p {
    orphans: 3;
    widows: 3;
  }

  pre, blockquote, figure, img, table {
    page-break-inside: avoid;
  }

  /* Show URLs after external links so printed readers can still see them */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #444;
    word-break: break-all;
  }

  /* Skip nav/internal links and links that are just anchors/images */
  a[href^="#"]::after,
  a[href^="mailto:"]::after,
  .image-link[href]::after,
  a.image-link[href]::after {
    content: none !important;
  }

  /* Make code blocks readable without dark background */
  pre {
    background: #f5f5f5 !important;
    border: 1px solid #ddd;
    color: #000 !important;
  }

  code {
    background: #f5f5f5 !important;
    color: #000 !important;
  }

  /* Ensure images don't overflow the printed page */
  img, video, figure {
    max-width: 100% !important;
    height: auto !important;
  }

  figcaption {
    color: #444;
  }
}
