html:has(#photoGallery[open]) { overflow: hidden; }

.pg-dialog {
  width: min(750px, calc(100% - 24px));
  max-width: calc(100% - 2 * max(12px, env(safe-area-inset-left), env(safe-area-inset-right)));
  max-height: 90vh;
  max-height: calc(100dvh - max(14px, env(safe-area-inset-top)) - max(14px, env(safe-area-inset-bottom)));
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--white);
  color: var(--ink);
}
.pg-dialog::backdrop { background: rgb(44 38 24 / .48); }
.pg-dialog .pg-bar { gap: 14px; padding: 10px 20px; }
.pg-dialog .pg-bar h2 { font: 800 22px/1.35 var(--serif); }
.pg-dialog button { min-height: 44px; }
.pg-dialog button:disabled { opacity: .6; cursor: wait; }
.pg-body { padding: 18px 20px 21px; }
.pg-intro, .pg-publish { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pg-intro { justify-content: space-between; margin-bottom: 14px; }
.pg-intro p { font-weight: 650; }
.pg-dialog .minor, .pg-dialog .primary { padding: 6px 15px; }
.pg-form {
  display: grid;
  gap: 6px;
  padding: clamp(13px, 3vw, 21px);
  margin-bottom: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.pg-form label { margin-top: 8px; font-weight: 650; }
.pg-form label:first-child { margin-top: 0; }
.pg-form small { color: var(--muted); font-size: 13px; font-weight: 400; }
.pg-form input, .pg-form textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #b9ad98;
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
.pg-form input:focus-visible, .pg-form textarea:focus-visible { outline: 3px solid #32695e; outline-offset: 2px; }
.pg-form textarea { resize: vertical; }
.pg-form .pg-preview { display: block; width: auto; max-width: 100%; max-height: 160px; margin-block: 5px; border-radius: 8px; }
.pg-publish { margin-top: 10px; }
.pg-form [role=status]:not(:empty), .pg-notice:not(:empty), .pg-status:not(:empty) {
  margin-block: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 14px;
}
.pg-form [role=status]:not(:empty) { color: var(--red-dark); }
.pg-notice:not(:empty) { color: #3d5c37; }
.pg-status:not(:empty) { padding-block: 8px; }
.pg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 12px; }
.pg-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--white);
  text-align: left;
}
.pg-card:hover, .pg-card:focus-visible { border-color: var(--red); }
.pg-card:active { background: var(--soft-red); }
.pg-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 7px; background: var(--paper); }
.pg-card-info { display: grid; gap: 2px; padding: 6px 5px 4px; overflow-wrap: anywhere; }
.pg-card-info strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 14px;
}
.pg-card time, .pg-figure time { color: var(--muted); font-size: 12px; }
#pgNext { display: block; margin: 12px auto 0; }
.pg-figure { margin: 0; }
.pg-figure img { display: block; width: 100%; height: auto; max-height: 70dvh; object-fit: contain; background: var(--paper); }
.pg-figure figcaption { display: grid; gap: 4px; padding: 12px 18px; overflow-wrap: anywhere; white-space: pre-wrap; }
#pgImageStatus:not(:empty) { margin-inline: 18px; }
@media (min-width: 651px) and (max-width: 900px) {
  .top-inner:has(#photosNav), .top-inner:has(#photosNav) nav { gap: 12px; }
}
@media (max-width: 650px) {
  .top-inner:has(#photosNav) { height: auto; flex-wrap: wrap; justify-content: center; gap: 0; padding: 6px 0 0; }
  .top-inner:has(#photosNav) .brand { margin: 0 auto; }
  .top-inner:has(#photosNav) nav { flex-basis: 100%; min-height: 44px; height: auto; margin: 0; justify-content: space-around; gap: 2px; }
}
@media (max-width: 480px) {
  .pg-dialog .pg-bar { padding: 8px 13px; }
  .pg-body { padding: 13px; }
  .pg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
}
