/* The viewer owns a separate lock; app.js retains ownership of .dialog-open. */
body.cncs-gallery-open { overflow: hidden; }
.cncs-gallery-target { position: relative; }
.gallery-open-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 70px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #ffffff60;
  border-radius: 0;
  background: #11130fe8;
  color: #f0f0eb;
  font: 11px/1.4 Arial, 'Microsoft YaHei', sans-serif;
  box-shadow: 0 2px 12px #0003;
  transition: background .2s, border-color .2s;
}
.gallery-open-button > span:first-child { font-size: 24px; line-height: 1; }
.gallery-open-button:hover { background: #c41c23; border-color: #ee6265; }
.gallery-open-button:focus-visible { outline: 3px solid #f0f0eb; outline-offset: 3px; }

.cncs-gallery {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #11120f;
  color: #f0f0eb;
  overflow: hidden;
  overscroll-behavior: contain;
}
.cncs-gallery::backdrop { background: #11120ff2; }
.cncs-gallery [hidden] { display: none !important; }
.cncs-gallery .gallery-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  width: 100%;
  height: 100%;
  padding: max(20px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left));
}
.cncs-gallery .gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid #f0f0eb2e;
}
.cncs-gallery .gallery-kicker { color: #aaa99e; font: 9px/1.5 monospace; letter-spacing: 1.7px; }
.cncs-gallery h2 { margin: 6px 0 0; font-size: 22px; font-weight: 600; line-height: 1.4; letter-spacing: .2px; }
.cncs-gallery button { touch-action: manipulation; }
.cncs-gallery .gallery-close {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  min-width: 92px;
  min-height: 46px;
  padding: 6px 12px;
  border: 1px solid #f0f0eb50;
  background: transparent;
  color: #f0f0eb;
  font-size: 12px;
  transition: background .2s, border-color .2s;
}
.cncs-gallery .gallery-close > span { font: 29px/1 Arial, sans-serif; }
.cncs-gallery .gallery-close:hover { background: #c41c23; border-color: #ed292b; }
.cncs-gallery button:focus-visible,
.cncs-gallery a:focus-visible { outline: 3px solid #ed292b; outline-offset: 4px; }
.cncs-gallery .gallery-current {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  margin: 0;
}
.cncs-gallery .gallery-image-area {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 20px 0;
  overflow: hidden;
}
.cncs-gallery .gallery-image {
  display: block;
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.cncs-gallery .gallery-image-status {
  grid-area: 1 / 1;
  z-index: 1;
  max-width: 320px;
  padding: 14px 20px;
  background: #11120fe8;
  color: #c6c5bc;
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}
.cncs-gallery .gallery-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px 32px;
  min-width: 0;
  max-height: 25vh;
  max-height: 25dvh;
  padding: 16px 0;
  border-top: 1px solid #f0f0eb2e;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.cncs-gallery .gallery-description { min-width: 0; }
.cncs-gallery .gallery-counter { color: #ff575b; font: 11px/1.5 monospace; letter-spacing: 2px; }
.cncs-gallery .gallery-caption-text { max-width: 950px; margin: 6px 0 0; color: #e2e1d7; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.cncs-gallery .gallery-source {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 18px;
  min-height: 44px;
  padding: 8px 2px;
  color: #f0f0eb;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-color: #f0f0eb60;
}
.cncs-gallery .gallery-source:hover { color: #ff7376; }
.cncs-gallery .gallery-source > span { font-size: 20px; }
.cncs-gallery .gallery-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-top: 1px solid #f0f0eb2e;
  padding-top: 14px;
}
.cncs-gallery .gallery-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 46px;
  min-width: 118px;
  padding: 9px 16px;
  border: 1px solid #f0f0eb50;
  background: #f0f0eb;
  color: #151713;
  font-size: 12px;
  transition: background .2s, color .2s;
}
.cncs-gallery .gallery-controls button > span { font-size: 23px; line-height: 1; }
.cncs-gallery .gallery-controls button:hover:not(:disabled) { background: #ed292b; color: #fff; }
.cncs-gallery .gallery-controls button:disabled { opacity: .4; cursor: default; }
.cncs-gallery .gallery-key-hint { display: flex; align-items: center; gap: 15px; color: #8c8f82; font: 10px/1.5 monospace; letter-spacing: 1px; }
.cncs-gallery .gallery-key-hint > i { width: 3px; height: 3px; background: #ed292b; }

@media (max-width: 600px) {
  .gallery-open-button { top: 9px; right: 9px; min-width: 62px; padding-inline: 9px; font-size: 10px; }
  .cncs-gallery .gallery-shell { padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .cncs-gallery .gallery-toolbar { padding-bottom: 12px; gap: 14px; }
  .cncs-gallery .gallery-kicker { font-size: 8px; letter-spacing: 1px; }
  .cncs-gallery h2 { font-size: 19px; margin-top: 4px; }
  .cncs-gallery .gallery-close { min-width: 80px; gap: 12px; }
  .cncs-gallery .gallery-image-area { padding: 14px 0; }
  .cncs-gallery .gallery-caption { display: block; max-height: 30vh; max-height: 30dvh; padding: 12px 0 6px; }
  .cncs-gallery .gallery-caption-text { font-size: 12px; line-height: 1.6; }
  .cncs-gallery .gallery-counter { font-size: 10px; }
  .cncs-gallery .gallery-source { font-size: 11px; }
  .cncs-gallery .gallery-controls { gap: 12px; padding-top: 12px; }
  .cncs-gallery .gallery-controls button { min-width: 0; width: 50%; min-height: 46px; }
  .cncs-gallery .gallery-key-hint { display: none; }
}
@media (max-height: 500px) {
  .cncs-gallery .gallery-shell { padding-block: max(8px, env(safe-area-inset-top)); }
  .cncs-gallery .gallery-toolbar { padding-bottom: 8px; }
  .cncs-gallery h2 { font-size: 17px; }
  .cncs-gallery .gallery-image-area { padding-block: 8px; }
  .cncs-gallery .gallery-caption { max-height: 25vh; padding-block: 7px; }
  .cncs-gallery .gallery-controls { padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .gallery-open-button,
  .cncs-gallery,
  .cncs-gallery *,
  .cncs-gallery::backdrop { animation: none !important; transition: none !important; }
}
