#gallery-modal,
.gallery-nav,
.gallery-nav:focus,
.gallery-nav:active,
#gallery-modal-content,
#gallery-close,
#gallery-download,
#gallery-info,
#gallery-play {
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

@property --play-progress {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

#gallery-modal {
  display: none;
  position: fixed;
  z-index: 3000;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.82);
  background-image:
    radial-gradient(circle at 50% 15%, rgba(42, 42, 42, 0.52), rgba(8, 8, 8, 0.95) 56%, #000 100%);
  justify-content: center;
  align-items: center;
  overflow: hidden;
  cursor: default;
}

#gallery-stage {
  position: absolute;
  inset: 82px 22px 96px;
  cursor: pointer;
}

#gallery-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(96vw, calc(100vw - 80px));
  max-height: calc(100vh - 190px);
  object-fit: contain;
  margin: auto;
  display: block;
  cursor: pointer;
  border-radius: 12px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.58);
}

.gallery-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  z-index: 130;
  pointer-events: none;
}

.gallery-actions-left,
.gallery-actions-right {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.gallery-control {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.27);
  background: rgba(0, 0, 0, 0.56);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 132;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1;
  padding: 0;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.gallery-control:hover,
.gallery-control:focus-visible {
  background: rgba(38, 38, 38, 0.88);
  border-color: rgba(255, 255, 255, 0.65);
  transform: translateY(-1px);
}

#gallery-info.loading {
  opacity: 0.62;
}

#gallery-info {
  font-size: 1.7rem;
  font-weight: 700;
}

#gallery-download,
#gallery-close {
  font-size: 1.6rem;
}

#loader-container {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3500;
  pointer-events: none;
}

#gallery-loader {
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-top: 4px solid #fff;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  animation: gallery-spin 0.9s linear infinite;
}

@keyframes gallery-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  background: rgba(0, 0, 0, 0.54);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  z-index: 120;
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 1;
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
}

.gallery-nav:hover,
.gallery-nav:focus-visible {
  background: rgba(30, 30, 30, 0.9);
}

.gallery-prev {
  left: 18px;
}

.gallery-next {
  right: 18px;
}

.gallery-next.is-close {
  background: #fff;
  border-color: #fff;
  color: #101010;
}

.gallery-nav.nav-hidden {
  opacity: 0;
  transform: translateY(-50%) scale(0.97);
  pointer-events: none;
}

#gallery-exif {
  position: absolute;
  top: 68px;
  left: 18px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 0.85rem 0.92rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  width: min(360px, calc(100vw - 36px));
  max-height: calc(100vh - 228px);
  overflow: auto;
  display: none;
  z-index: 140;
}

#gallery-exif.open {
  display: block;
}

.exif-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
  margin-bottom: 8px;
  line-height: 1.28;
}

.exif-row:last-child {
  margin-bottom: 0;
}

.exif-key {
  font-weight: 600;
  color: rgba(255, 255, 255, 0.88);
}

.exif-value {
  text-align: right;
  color: rgba(255, 255, 255, 0.98);
  word-break: break-word;
}

.exif-placeholder {
  font-style: italic;
  color: rgba(255, 255, 255, 0.76);
}

.gallery-meta-bar {
  position: absolute;
  bottom: 16px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 120;
  pointer-events: none;
}

#gallery-filename,
#gallery-position {
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 0.45rem 0.72rem;
  font-size: 0.82rem;
  line-height: 1.2;
  white-space: nowrap;
}

#gallery-filename {
  flex: 1;
  min-width: 0;
  position: relative;
  isolation: isolate;
  text-align: left;
  overflow: hidden;
  --filename-progress: 0%;
}

#gallery-filename::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(255, 255, 255, 0.95) var(--filename-progress),
      rgba(0, 0, 0, 0.62) var(--filename-progress),
      rgba(0, 0, 0, 0.62) 100%
    );
  z-index: 0;
}

#gallery-filename .filename-text {
  position: relative;
  z-index: 1;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
}

#gallery-filename::after {
  content: attr(data-filename);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 0.45rem 0.72rem;
  box-sizing: border-box;
  z-index: 2;
  overflow: hidden;
  clip-path: inset(0 calc(100% - var(--filename-progress)) 0 0);
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #0a0a0a;
  pointer-events: none;
}

#gallery-position {
  min-width: 72px;
  text-align: center;
}

#gallery-play {
  position: relative;
  font-size: 1.2rem;
  font-weight: 600;
  --autoplay-duration: 5s;
  --play-progress: 0deg;
}

#gallery-play.playing::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  background:
    conic-gradient(
      rgba(255, 255, 255, 0.96) 0deg,
      rgba(255, 255, 255, 0.96) var(--play-progress, 0deg),
      rgba(255, 255, 255, 0.2) var(--play-progress, 0deg),
      rgba(255, 255, 255, 0.2) 360deg
    );
  mask: radial-gradient(ellipse at center, transparent 67%, #000 74%);
  animation: none;
  pointer-events: none;
}

#gallery-play.playing.playing-anim::after {
  animation: gallery-play-fill var(--autoplay-duration) linear forwards;
}

@keyframes gallery-play-fill {
  from {
    --play-progress: 0deg;
  }
  to {
    --play-progress: 360deg;
  }
}

@media (max-width: 860px) {
  #gallery-stage {
    inset: 74px 10px 110px;
  }

  #gallery-modal-content {
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 210px);
    border-radius: 10px;
  }

  .gallery-top-bar {
    padding: 10px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .gallery-actions-left,
  .gallery-actions-right {
    gap: 8px;
  }

  .gallery-control {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    font-size: 1.3rem;
    padding: 0;
  }

  .gallery-nav {
    top: auto;
    bottom: 62px;
    transform: none;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    font-size: 1.9rem;
  }

  .gallery-prev {
    left: 10px;
  }

  .gallery-next {
    right: 10px;
  }

  .gallery-nav.nav-hidden {
    opacity: 0;
    transform: translateY(5px);
  }

  #gallery-exif {
    top: 58px;
    left: 10px;
    width: calc(100vw - 20px);
    max-height: calc(100vh - 224px);
  }

  .gallery-meta-bar {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  #gallery-filename,
  #gallery-position {
    font-size: 0.76rem;
    padding: 0.42rem 0.6rem;
  }

  #gallery-play {
    font-size: 1.05rem;
  }

  #gallery-info {
    font-size: 1.45rem;
  }

  #gallery-download,
  #gallery-close {
    font-size: 1.4rem;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  #gallery-stage {
    inset: 44px 10px 60px;
  }

  #gallery-modal-content {
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 112px);
    border-radius: 8px;
  }

  .gallery-top-bar {
    padding: 8px 10px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .gallery-actions-left,
  .gallery-actions-right {
    gap: 6px;
  }

  .gallery-control {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    font-size: 1.1rem;
  }

  #gallery-play {
    font-size: 0.95rem;
  }

  #gallery-info {
    font-size: 1.22rem;
  }

  #gallery-download,
  #gallery-close {
    font-size: 1.18rem;
  }

  .gallery-nav {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.7rem;
  }

  .gallery-prev {
    left: 8px;
  }

  .gallery-next {
    right: 8px;
  }

  .gallery-nav.nav-hidden {
    opacity: 0;
    transform: translateY(-50%) scale(0.96);
  }

  .gallery-meta-bar {
    left: 10px;
    right: 10px;
    bottom: 8px;
    gap: 8px;
  }

  #gallery-filename,
  #gallery-position {
    padding: 0.32rem 0.52rem;
    font-size: 0.7rem;
  }

  #gallery-exif {
    top: 50px;
    left: 10px;
    width: min(360px, calc(100vw - 20px));
    max-height: calc(100vh - 120px);
  }
}
