:root {
  --tibiu-image-preview-z: var(--tibiu-layer-image-preview, 1350);
  --tibiu-image-preview-toolbar: rgba(16, 17, 20, 0.72);
  --tibiu-image-preview-control: rgba(255, 255, 255, 0.14);
  --tibiu-image-preview-control-hover: rgba(255, 255, 255, 0.24);
}

body.tibiu-image-preview-lock {
  overflow: hidden;
  touch-action: none;
}

.tibiu-image-preview {
  position: fixed;
  inset: 0;
  z-index: var(--tibiu-image-preview-z);
  display: none;
  color: #fff;
  pointer-events: none;
}

.tibiu-image-preview.is-mounted {
  display: block;
}

.tibiu-image-preview.is-active {
  pointer-events: auto;
}

.tibiu-image-preview__mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tibiu-image-preview.is-active .tibiu-image-preview__mask {
  opacity: 1;
}

.tibiu-image-preview__stage {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 72px 76px 88px;
  box-sizing: border-box;
  opacity: 0;
  transform: scale(0.985);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tibiu-image-preview.is-active .tibiu-image-preview__stage {
  opacity: 1;
  transform: scale(1);
}

.tibiu-image-preview__img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: grab;
  transform-origin: center center;
  will-change: transform;
}

.tibiu-image-preview__img.is-dragging {
  cursor: grabbing;
}

.tibiu-image-preview__topbar,
.tibiu-image-preview__toolbar {
  position: absolute;
  z-index: 2;
  left: 50%;
  display: flex;
  align-items: center;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--tibiu-image-preview-toolbar);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.22);
}

.tibiu-image-preview__topbar {
  top: 18px;
  min-height: 40px;
  padding: 0 12px;
}

.tibiu-image-preview__toolbar {
  bottom: calc(18px + env(safe-area-inset-bottom));
  gap: 6px;
  padding: 8px;
}

.tibiu-image-preview__counter {
  min-width: 48px;
  padding: 0 6px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.tibiu-image-preview__btn,
.tibiu-image-preview__nav {
  border: 0;
  background: var(--tibiu-image-preview-control);
  color: #fff;
  box-shadow: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, opacity 0.18s ease;
}

.tibiu-image-preview__btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.tibiu-image-preview__btn img,
.tibiu-image-preview__nav img {
  width: 19px;
  height: 19px;
  display: block;
  filter: brightness(0) invert(1);
  opacity: 0.96;
  pointer-events: none;
}

.tibiu-image-preview__nav img {
  width: 24px;
  height: 24px;
}

.tibiu-image-preview__btn:hover,
.tibiu-image-preview__nav:hover {
  background: var(--tibiu-image-preview-control-hover);
}

.tibiu-image-preview__btn[disabled],
.tibiu-image-preview__nav[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.tibiu-image-preview__close {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
}

.tibiu-image-preview__nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  transform: translateY(-50%);
  font-size: 26px;
  font-weight: 700;
}

.tibiu-image-preview__nav--prev {
  left: 20px;
}

.tibiu-image-preview__nav--next {
  right: 20px;
}

.tibiu-image-preview__loading,
.tibiu-image-preview__error {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.tibiu-image-preview__loading::before {
  content: "";
  width: 34px;
  height: 34px;
  display: block;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #fff;
  animation: tibiuImagePreviewSpin 0.85s linear infinite;
}

.tibiu-image-preview__error {
  display: none;
  max-width: min(78vw, 360px);
  padding: 16px 18px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tibiu-image-preview[data-loading="0"] .tibiu-image-preview__loading {
  display: none;
}

.tibiu-image-preview[data-error="1"] .tibiu-image-preview__error {
  display: block;
}

.tibiu-image-preview[data-error="1"] .tibiu-image-preview__img {
  visibility: hidden;
}

@keyframes tibiuImagePreviewSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .tibiu-image-preview__stage {
    padding: 64px 12px 82px;
  }

  .tibiu-image-preview__topbar {
    top: 12px;
  }

  .tibiu-image-preview__close {
    top: 12px;
    right: 12px;
  }

  .tibiu-image-preview__toolbar {
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100% - 24px);
    justify-content: center;
    box-sizing: border-box;
  }

  .tibiu-image-preview__btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .tibiu-image-preview__btn img {
    width: 18px;
    height: 18px;
  }

  .tibiu-image-preview__nav {
    display: none;
  }
}
