/*
 * 07-blocks.css — Building blocks from templates/typst/blocks.typ
 * ─────────────────────────────────────────────────────────────────
 * Figures, videos, embeds, comparison sliders, citations, code-block chrome
 * and the image lightbox. Usable on any page: posts, projects, About.
 */

/* ══ Figures (#fig) ══════════════════════════════════════════════════════════ */

.post-figure,
.media-figure {
  margin-block: 2em;
  text-align:   center;
}

.post-figure img {
  border-radius: var(--radius-md);
  max-width:     100%;
  margin-inline: auto;
  border:        1px solid var(--color-border);
}

/* Wide figures break out of the prose column slightly */
.figure-wide {
  margin-inline: calc(-1 * var(--sp-8));
}
.figure-wide img { max-width: calc(100% + var(--sp-16)); border-radius: var(--radius-lg); }

figcaption {
  margin-top:  var(--sp-2);
  font-size:   var(--text-sm);
  color:       var(--color-text-muted);
  font-style:  italic;
  line-height: 1.5;
}


/* ══ Video (#video) ══════════════════════════════════════════════════════════ */

.media-figure video {
  width:         100%;
  display:       block;
  border-radius: var(--radius-md);
  border:        1px solid var(--color-border);
  background:    #000;
}


/* ══ YouTube embed (#youtube) ════════════════════════════════════════════════ */

.embed-wrap {
  margin-block: 2em;
}

.embed-youtube {
  position:       relative;
  padding-bottom: 56.25%;   /* 16:9 aspect ratio */
  height:         0;
  overflow:       hidden;
  border-radius:  var(--radius-md);
  border:         1px solid var(--color-border);
}

.embed-youtube iframe {
  position: absolute;
  top:      0;
  left:     0;
  width:    100%;
  height:   100%;
  border:   none;
}


/* ══ Teaser (#teaser) ═══════════════════════════════════════════════════════ */
/* Wide looping video or image at the top of a page; breaks out of the text column. */

.teaser {
  margin:     0 calc(-1 * var(--sp-16)) var(--sp-12);
  text-align: center;
}
.teaser video,
.teaser img {
  width:         100%;
  display:       block;
  margin:        0;
  border-radius: var(--radius-lg);
  background:    #000;
  box-shadow:    var(--shadow-md);
}
.teaser figcaption {
  max-width:     68ch;
  margin-inline: auto;
  margin-top:    var(--sp-4);
  font-style:    normal;
}


/* ══ Figure rows (#figure-row / #subfig) ═════════════════════════════════════ */

.figure-row-wrap { margin-block: 2em; }
.figure-row {
  display:     grid;
  gap:         var(--sp-3);
  align-items: start;
}
.subfig { margin: 0; text-align: center; }
.subfig-images {
  display: flex;
  gap:     4px;
}
.subfig-images img {
  flex:          1;
  min-width:     0;
  margin:        0;
  border-radius: var(--radius-sm);
}
.subfig figcaption { margin-top: var(--sp-2); font-style: normal; }


/* ══ Comparison slider (#compare, static/js/compare.js) ══════════════════════ */

.compare-figure { margin-block: 2.5em; }

.compare-slider {
  position:      relative;
  width:         100%;
  aspect-ratio:  16 / 9;
  overflow:      hidden;
  border-radius: var(--radius-md);
  background:    #000;
  cursor:        col-resize;
  user-select:   none;
  -webkit-user-select: none;
  touch-action:  pan-y;
}
.compare-slider img {
  position:        absolute;
  inset:           0;
  width:           100%;
  height:          100%;
  margin:          0;
  border-radius:   0;
  object-fit:      cover;
  pointer-events:  none;
  image-rendering: pixelated;     /* zoomed-in pixels stay crisp */
  transition:      transform 0.3s ease;
}
.compare-slider.is-zoomed img { transform: scale(8); }

.cs-clip {
  position:  absolute;
  inset:     0;
  clip-path: inset(0 0 0 50%);    /* updated by compare.js */
}

.cs-divider {
  position:       absolute;
  top:            0;
  bottom:         0;
  left:           50%;            /* updated by compare.js */
  width:          2px;
  background:     rgba(255, 255, 255, 0.85);
  transform:      translateX(-50%);
  box-shadow:     0 0 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.cs-handle {
  position:        absolute;
  top:             50%;
  left:            50%;
  transform:       translate(-50%, -50%);
  width:           38px;
  height:          38px;
  border-radius:   50%;
  background:      rgba(255, 255, 255, 0.95);
  box-shadow:      0 2px 12px rgba(0, 0, 0, 0.3);
  display:         flex;
  align-items:     center;
  justify-content: center;
  color:           #1a1814;
}
.cs-handle svg { width: 14px; height: 14px; }

.cs-label {
  position:        absolute;
  bottom:          0.85rem;
  font-family:     var(--font-mono);
  font-size:       0.72rem;
  font-weight:     500;
  letter-spacing:  0.06em;
  text-transform:  uppercase;
  color:           #fff;
  background:      rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding:         0.28rem 0.65rem;
  border-radius:   var(--radius-sm);
  pointer-events:  none;
  transition:      opacity 0.2s;
}
.cs-label-left  { left:  0.85rem; }
.cs-label-right { right: 0.85rem; }

/* Light pill, bottom-centre between the two labels: stands out on any image */
.cs-zoom-btn {
  position:       absolute;
  bottom:         0.85rem;
  left:           50%;
  transform:      translateX(-50%);
  z-index:        1;
  padding:        0.35rem 0.9rem;
  font-family:    var(--font-mono);
  font-size:      0.72rem;
  font-weight:    600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color:          #1a1814;
  background:     rgba(255, 255, 255, 0.92);
  border:         none;
  border-radius:  999px;
  box-shadow:     0 2px 10px rgba(0, 0, 0, 0.35);
  cursor:         pointer;
  transition:     background var(--transition), box-shadow var(--transition);
}
.cs-zoom-btn:hover {
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5);
}

/* Narrow screens: long labels would run into it at the bottom */
@media (max-width: 600px) {
  .cs-zoom-btn { bottom: auto; top: 0.85rem; }
  .cs-label    { max-width: calc(50% - 1.2rem); font-size: 0.65rem; }   /* long labels wrap instead of colliding */
  .cs-label-right { text-align: right; }
}

.compare-caption {
  margin-top: var(--sp-3);
  text-align: left;
  font-style: normal;
}
.compare-caption strong { color: var(--color-text); font-weight: 600; }


/* ══ Citation (#citation, project pages, publications) ═══════════════════════ */

.citation-block {
  position:      relative;
  margin-block:  1em;
  background:    var(--color-bg-subtle);
  border:        1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.citation-block pre {
  margin:        0;
  padding:       var(--sp-5) 6rem var(--sp-5) var(--sp-6);
  font-family:   var(--font-mono);
  font-size:     var(--text-sm);
  line-height:   1.7;
  white-space:   pre-wrap;
  word-break:    break-word;
  background:    none;
  border:        none;
}
.citation-block code {
  font-family: inherit;
  color:       var(--color-text);
  background:  none;
  border:      none;
  padding:     0;
}
.citation-block .copy-btn {
  position: absolute;
  top:      var(--sp-3);
  right:    var(--sp-3);
}


/* ══ Code blocks: language + copy button (blocks.typ, main.js) ═══════════════ */

.code-block {
  margin-block:  1.5em;
  border:        1px solid var(--color-border);
  border-radius: var(--radius-md);
  background:    var(--color-bg-subtle);
  overflow:      hidden;
}
.code-head {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-6);
  border-bottom:   1px solid var(--color-border);
}
.code-lang {
  font-family:    var(--font-mono);
  font-size:      var(--text-xs);
  letter-spacing: 0.04em;
  color:          var(--color-text-faint);
}
.code-block pre {
  margin:        0 !important;
  border:        none !important;
  border-radius: 0 !important;
}

/* Shared small copy button (code blocks, citations) */
.copy-btn {
  padding:       0.25rem 0.7rem;
  font-family:   var(--font-mono);
  font-size:     var(--text-xs);
  color:         var(--color-text-muted);
  background:    var(--color-bg-card);
  border:        1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor:        pointer;
  transition:    color var(--transition), border-color var(--transition);
}
.copy-btn:hover     { color: var(--color-accent); border-color: var(--color-accent); }
.copy-btn.is-copied { color: oklch(58% 0.13 150); border-color: currentColor; }


/* ══ Lightbox (click an image to see it full size; main.js) ══════════════════ */

.post-figure img,
.subfig-images img { cursor: zoom-in; }

.lightbox {
  max-width:  none;
  max-height: none;
  width:      100vw;
  height:     100vh;
  margin:     0;
  padding:    var(--sp-8);
  border:     none;
  background: transparent;
  cursor:     zoom-out;
}
.lightbox::backdrop {
  background:      rgba(8, 8, 10, 0.88);
  backdrop-filter: blur(4px);
}
.lightbox[open] {
  display:         flex;
  align-items:     center;
  justify-content: center;
}
.lightbox img {
  max-width:     100%;
  max-height:    100%;
  object-fit:    contain;
  border-radius: var(--radius-md);
  box-shadow:    0 10px 40px rgba(0, 0, 0, 0.5);
}


/* ══ Responsive ══════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .teaser { margin-inline: 0; }
}

@media (max-width: 600px) {
  .figure-wide     { margin-inline: 0; }
  .figure-wide img { max-width: 100%; }
  .figure-row      { grid-template-columns: 1fr !important; }   /* overrides the inline columns */
}
