/* ============================================================
   SITE POLISH — loaded last on every page.

   Two jobs:
   1. Justified prose across the whole site (index + all pages).
   2. A single figure / gallery / lightbox component so project
      and blog pages present screenshots the same way instead of
      each page inventing its own image markup.
   ============================================================ */

/* ---- 1. JUSTIFIED PROSE ------------------------------------

   Applied only to running prose. Headings, labels, captions,
   table cells, code and UI chrome stay left-aligned — justifying
   short strings is what makes justified layouts look broken.

   hyphens:auto is not optional here: English prose justified in a
   narrow column without hyphenation opens rivers of white space.
   ------------------------------------------------------------ */

.home-bio-text,
.home-bio-text2,
.entry-desc,
.p-body p,
.p-card p,
.p-feature-desc,
.p-usecase-desc,
.p-arch-desc,
.p-callout,
.ap-page-sub,
.ap-card-desc,
.blog-body p,
.blog-subtitle,
.blog-callout,
.rf-figure-note,
.course-desc,
.contact-intro p,
.resume-summary p {
  text-align: justify;
  text-justify: inter-word;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
}

/* Last line of a justified block should never be stretched. */
.home-bio-text,
.home-bio-text2,
.entry-desc,
.p-body p,
.p-card p,
.blog-body p {
  text-align-last: left;
}

/* Anything that is a list, table, code block or badge keeps its
   own alignment even if it happens to sit inside a matched block. */
.p-body table, .p-body table *,
.p-body pre, .p-body code,
.blog-body table, .blog-body table *,
.blog-body pre, .blog-body code,
.p-card-title, .blog-section-title,
.rf-cap {
  text-align: left !important;
  hyphens: none !important;
}

/* ---- 2. FIGURE / GALLERY ----------------------------------- */

.rf-media {
  margin: 26px 0 0;
}

.rf-media + .rf-media { margin-top: 18px; }

/* Section lead-in text above a gallery */
.rf-media-lead {
  font-size: 14px;
  line-height: 1.7;
  color: var(--body, #4b5563);
  margin: 0 0 16px;
  max-width: 68ch;
  text-align: justify;
  text-align-last: left;
  hyphens: auto;
}

/* --- grid variants --- */
.rf-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.rf-grid.rf-1 { grid-template-columns: minmax(0, 1fr); }
.rf-grid.rf-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* Phone screenshots: many narrow portrait shots in one row */
.rf-grid.rf-phones {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* --- the figure itself --- */
.rf-figure {
  margin: 0;
  border: 1px solid var(--border, #e6e6e2);
  border-radius: 12px;
  overflow: hidden;
  background: #fafaf8;
  display: flex;
  flex-direction: column;
}

.rf-figure > .rf-shot {
  display: block;
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  background: #fafaf8;
  cursor: zoom-in;
  overflow: hidden;
  line-height: 0;
}

.rf-figure img,
.rf-figure video {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  background: #fafaf8;
}

/* Wide desktop captures get a fixed viewport so a 2500px-wide
   screenshot doesn't dwarf a 700px-tall one beside it. */
.rf-figure.rf-crop img {
  height: 210px;
  object-fit: cover;
  object-position: top center;
}
.rf-grid.rf-1 .rf-figure.rf-crop img { height: 330px; }

/* Portrait phone shots keep their full aspect ratio. */
.rf-figure.rf-phone { background: #fff; }
.rf-figure.rf-phone img { object-fit: contain; }

.rf-figure video { cursor: default; background: #000; }

.rf-cap {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted, #8a8a85);
  padding: 9px 13px;
  border-top: 1px solid var(--border-light, #eeeeeb);
  background: #fff;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.rf-cap b {
  color: var(--body, #3f3f3f);
  font-weight: 600;
  flex-shrink: 0;
}

/* zoom affordance */
.rf-shot::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0);
  transition: background .16s ease;
  pointer-events: none;
}
.rf-shot:hover::after { background: rgba(20, 20, 20, .05); }
.rf-shot:focus-visible {
  outline: 2px solid #4a6fb5;
  outline-offset: -2px;
}

/* --- download / artefact row --- */
.rf-file {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 16px;
  padding: 11px 16px;
  border: 1px solid var(--border, #e6e6e2);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink, #1f1f1f);
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease;
}
.rf-file:hover { border-color: #cfcfc9; background: #fafaf8; }
.rf-file svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }
.rf-file span { font-weight: 400; color: var(--muted, #8a8a85); }

/* ---- 3. LIGHTBOX ------------------------------------------- */

.rf-lb {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 12, .92);
  padding: 40px 28px 64px;
}
.rf-lb.open { display: flex; }
.rf-lb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
.rf-lb-cap {
  position: absolute;
  left: 0; right: 0; bottom: 20px;
  text-align: center;
  color: rgba(255, 255, 255, .72);
  font-size: 12.5px;
  padding: 0 40px;
}
.rf-lb-close {
  position: absolute;
  top: 16px; right: 18px;
  width: 38px; height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.rf-lb-close:hover { background: rgba(255, 255, 255, .2); }
.rf-lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px; height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.rf-lb-nav:hover { background: rgba(255, 255, 255, .2); }
.rf-lb-prev { left: 18px; }
.rf-lb-next { right: 18px; }
body.rf-lb-open { overflow: hidden; }

/* ---- 4. RESPONSIVE ----------------------------------------- */

@media (max-width: 900px) {
  .rf-grid, .rf-grid.rf-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rf-figure.rf-crop img { height: 170px; }
  .rf-grid.rf-1 .rf-figure.rf-crop img { height: 240px; }
}

@media (max-width: 560px) {
  .rf-grid, .rf-grid.rf-3 { grid-template-columns: minmax(0, 1fr); }
  .rf-grid.rf-phones { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rf-figure.rf-crop img,
  .rf-grid.rf-1 .rf-figure.rf-crop img { height: auto; object-fit: contain; }
  .rf-lb { padding: 20px 12px 54px; }
  .rf-lb-nav { width: 36px; height: 36px; }

  /* Narrow columns are where justification hurts most, and where
     hyphenation support is least reliable. Fall back to ragged
     right below the point where it stops looking deliberate. */
  .home-bio-text, .home-bio-text2, .entry-desc,
  .p-body p, .p-card p, .blog-body p, .blog-subtitle,
  .p-feature-desc, .p-usecase-desc, .p-arch-desc,
  .ap-card-desc, .rf-media-lead {
    text-align: left;
    hyphens: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rf-shot::after, .rf-file { transition: none !important; }
}
