/* Quiet figure previews: preserve the original image sizes and crop. */
.figure-button {
  position: relative;
  isolation: isolate;
  border-radius: 4px;
  opacity: 1;
  transition: transform 180ms cubic-bezier(.2,.7,.3,1);
}

.figure-button img {
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(50,65,78,.12), 0 2px 5px rgba(30,45,60,.07);
  transition: box-shadow 180ms ease;
}

.figure-button:hover { opacity: 1; }

.figure-button::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background-color: rgba(255,255,255,.96);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23465c6c' stroke-width='1.65' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 4h6v6M20 4l-7 7M10 20H4v-6M4 20l7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 15px;
  box-shadow: 0 0 0 1px rgba(40,60,75,.1), 0 2px 6px rgba(30,45,60,.1);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 160ms ease, transform 180ms cubic-bezier(.2,.7,.3,1);
  pointer-events: none;
}

.figure-button:focus-visible::after {
  opacity: 1;
  transform: none;
}

@media (hover: hover) and (pointer: fine) {
  .figure-button:hover,
  .figure-button:focus-visible { transform: translateY(-2px); }
  .figure-button:hover img,
  .figure-button:focus-visible img {
    box-shadow: 0 0 0 1px rgba(61,96,121,.23), 0 5px 12px rgba(30,45,60,.1);
  }
  .figure-button:hover::after { opacity: 1; transform: none; }
}

@media (hover: none), (pointer: coarse) {
  .figure-button::after {
    top: -6px;
    right: -6px;
    width: 19px;
    height: 19px;
    border-radius: 6px;
    background-size: 12px;
    opacity: 1;
    transform: none;
  }
}

#figure-dialog {
  border: 1px solid rgba(82,99,114,.2);
  border-radius: 12px;
  box-shadow: 0 20px 80px rgba(13,26,40,.24), 0 3px 14px rgba(13,26,40,.12);
}

#figure-dialog::backdrop {
  background: rgba(21,29,39,.58);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

#figure-dialog .close-figure {
  border-radius: 50%;
  color: #697987;
  transition: color 160ms ease, background-color 160ms ease;
}

#figure-dialog .close-figure:hover {
  color: #293d4b;
  background: rgba(78,101,121,.08);
}

@media screen {
  html[data-theme="dark"] .figure-button img {
    box-shadow: 0 0 0 1px rgba(217,226,235,.13), 0 2px 7px rgba(0,0,0,.22);
  }
  html[data-theme="dark"] .figure-button::after {
    background-color: rgba(39,46,55,.96);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23d1dfeb' stroke-width='1.65' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 4h6v6M20 4l-7 7M10 20H4v-6M4 20l7-7'/%3E%3C/svg%3E");
    box-shadow: 0 0 0 1px rgba(204,219,231,.17), 0 2px 6px rgba(0,0,0,.2);
  }
  html[data-theme="dark"] #figure-dialog {
    border-color: rgba(197,214,229,.2);
    box-shadow: 0 24px 80px rgba(0,0,0,.4), 0 3px 16px rgba(0,0,0,.3);
  }
  html[data-theme="dark"] #figure-dialog::backdrop { background: rgba(5,9,14,.7); }
  html[data-theme="dark"] #figure-dialog .close-figure { color: #aebfce; }
  html[data-theme="dark"] #figure-dialog .close-figure:hover {
    color: #ecf4fa;
    background: rgba(189,211,230,.09);
  }
}

@media screen and (hover: hover) and (pointer: fine) {
  html[data-theme="dark"] .figure-button:hover img,
  html[data-theme="dark"] .figure-button:focus-visible img {
    box-shadow: 0 0 0 1px rgba(180,207,230,.3), 0 5px 12px rgba(0,0,0,.3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .figure-button, .figure-button img, .figure-button::after,
  #figure-dialog .close-figure { transition: none; }
  .figure-button:hover, .figure-button:focus-visible { transform: none; }
}

@media print {
  .figure-button::after { display: none; }
  .figure-button img { box-shadow: none; }
}
