html,
body.gallery-viewer-page {
  height: 100%;
  margin: 0;
}

.gallery-viewer-page {
  --gv-bg: #211f1d;
  --gv-panel: rgba(255, 248, 235, 0.94);
  --gv-red: #8d2424;
  --gv-gold: #c09853;
  --gv-cream: #fff8eb;
  --gv-ink: #2f2d2b;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--gv-bg);
  color: #fff;
  font-family: "Inter", sans-serif;
}

.gallery-viewer-header {
  min-height: 72px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(103, 25, 25, 0.95);
  border-bottom: 1px solid rgba(234, 216, 183, 0.35);
  z-index: 5;
}

.gallery-viewer-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(192, 152, 83, 0.5);
  border-radius: 8px;
  padding: 0.56rem 0.82rem;
  background: rgba(255, 255, 255, 0.94);
  color: var(--gv-red);
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease;
}

.gallery-viewer-button:hover {
  background: #fff;
  transform: translateY(-1px);
}

.gallery-viewer-button:focus-visible,
.gallery-side-button:focus-visible,
.gallery-thumb:focus-visible {
  outline: 3px solid #f1cf8c;
  outline-offset: 3px;
}

.gallery-viewer-title {
  min-width: 0;
  text-align: center;
}

.gallery-viewer-title p {
  margin: 0 0 3px;
  color: rgba(255, 248, 235, 0.68);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.gallery-viewer-title h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Merriweather", serif;
  font-size: clamp(1rem, 2.2vw, 1.42rem);
  font-weight: 900;
}

.gallery-viewer-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 25% 15%, rgba(192, 152, 83, 0.12), transparent 32%),
    #211f1d;
}

.gallery-viewer-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 14px 16px 12px;
}

.hidden {
  display: none !important;
}

.gallery-state {
  flex: 1;
  min-height: 340px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.gallery-state h2 {
  margin: 0;
  font-family: "Merriweather", serif;
  font-size: clamp(1.4rem, 4vw, 2rem);
  color: var(--gv-cream);
}

.gallery-state p {
  margin: 0;
  color: rgba(255, 248, 235, 0.78);
}

.gallery-state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.gallery-main {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.gallery-image-frame {
  position: relative;
  width: min(100%, 1380px);
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  margin: 0;
  overflow: hidden;
  border-radius: 10px;
  background: #111;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.32);
  touch-action: pan-y;
}

.gallery-image-frame::after {
  content: "Đang tải ảnh...";
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 1;
  display: none;
  transform: translate(-50%, -50%);
  color: rgba(255, 248, 235, 0.78);
  font-size: 0.875rem;
  font-weight: 700;
}

.gallery-image-frame.is-loading::after {
  display: block;
}

.gallery-image-frame.is-loading img {
  opacity: 0.24;
}

.gallery-image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.gallery-image-frame.is-zoomed img {
  transform: scale(1.75);
  cursor: zoom-out;
}

.gallery-side-button {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 46px;
  height: 72px;
  transform: translateY(-50%);
  border: 1px solid rgba(234, 216, 183, 0.36);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.34);
  color: #fff;
  font-size: 2.5rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.gallery-side-prev {
  left: 12px;
}

.gallery-side-next {
  right: 12px;
}

.gallery-side-button:disabled,
.gallery-thumb:disabled {
  opacity: 0.45;
}

.gallery-info {
  width: min(100%, 1380px);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  color: var(--gv-cream);
}

.gallery-counter {
  margin: 0 0 4px;
  color: #ead8b7;
  font-size: 0.88rem;
  font-weight: 900;
}

.gallery-image-title {
  margin: 0;
  color: #fff;
  font-family: "Merriweather", serif;
  font-size: clamp(1rem, 2.1vw, 1.35rem);
}

.gallery-caption {
  max-width: 760px;
  margin: 5px 0 0;
  color: rgba(255, 248, 235, 0.78);
  line-height: 1.55;
}

.gallery-hint {
  max-width: 320px;
  margin: 0;
  color: rgba(255, 248, 235, 0.58);
  font-size: 0.82rem;
  text-align: right;
}

.gallery-thumbnails {
  width: min(100%, 1380px);
  margin: 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 2px;
  scrollbar-width: thin;
}

.gallery-thumb {
  flex: 0 0 auto;
  width: 82px;
  height: 58px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #111;
}

.gallery-thumb.is-active {
  border-color: var(--gv-gold);
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-width: 768px) {
  .gallery-viewer-page {
    height: 100dvh;
    max-width: 100vw;
  }

  .gallery-viewer-header {
    min-height: 68px;
    max-height: 82px;
    gap: 8px;
    padding: 8px 9px;
  }

  .gallery-viewer-button {
    min-height: 44px;
    border-radius: 7px;
    padding: 0.38rem 0.48rem;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  #fullscreen-btn {
    width: 44px;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    font-size: 0;
  }

  #fullscreen-btn::before {
    content: "\26F6";
    font-size: 16px;
  }

  .gallery-viewer-title p {
    margin-bottom: 2px;
    font-size: 0.58rem;
    letter-spacing: 0.1em;
  }

  .gallery-viewer-title h1 {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 0.86rem;
    line-height: 1.18;
  }

  .gallery-viewer-shell {
    gap: 7px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .gallery-main {
    min-height: 0;
  }

  .gallery-image-frame {
    width: 100%;
    height: 100%;
    border-radius: 8px;
  }

  .gallery-side-button {
    width: 44px;
    height: 48px;
    border-radius: 9px;
    font-size: 1.9rem;
    background: rgba(0, 0, 0, 0.28);
  }

  .gallery-side-prev {
    left: 5px;
  }

  .gallery-side-next {
    right: 5px;
  }

  .gallery-info {
    display: block;
    min-height: 54px;
  }

  .gallery-counter {
    font-size: 0.75rem;
  }

  .gallery-image-title {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    font-size: 0.92rem;
  }

  .gallery-caption {
    display: -webkit-box;
    max-width: none;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-top: 3px;
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .gallery-hint {
    display: none;
  }

  .gallery-thumbnails {
    gap: 6px;
    padding-top: 3px;
  }

  .gallery-thumb {
    width: 58px;
    height: 44px;
    border-radius: 7px;
  }

  .gallery-viewer-page #ai-toggle {
    right: 10px !important;
    bottom: 78px !important;
    width: 44px !important;
    height: 44px !important;
  }

  .gallery-viewer-page #ai-box {
    right: 10px !important;
    bottom: 128px !important;
    height: min(520px, calc(100dvh - 150px)) !important;
  }
}

@media (max-width: 420px) {
  .gallery-viewer-header {
    padding-left: 7px;
    padding-right: 7px;
  }

  .gallery-viewer-button {
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    font-size: 0.7rem;
  }

  .gallery-viewer-shell {
    padding-left: 6px;
    padding-right: 6px;
  }
}

@media (max-height: 700px) and (max-width: 768px) {
  .gallery-thumbnails {
    display: none;
  }
}
