:root {
  --overlay-btn: rgba(255, 255, 255, 0.14);
  --overlay-btn-hover: rgba(255, 255, 255, 0.22);
  --overlay-stroke: rgba(255, 255, 255, 0.2);
  --overlay-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --gallery-signature-size: 22%;
  --gallery-signature-opacity: 0.75;
}

body {
  padding: 0;
}

body.gallery-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.overlay-open {
  overflow: hidden;
}

.social-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(8, 10, 12, 0.55);
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  z-index: 1000;
}

.social-overlay.is-open {
  display: flex;
}

.social-backdrop {
  position: absolute;
  inset: 0;
}

.social-panel {
  position: relative;
  width: min(1040px, 92vw);
  height: min(799px, 84vh);
  border-radius: 28px;
  background: rgba(42, 42, 46, 0.80);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--overlay-shadow);
  overflow: hidden;
  z-index: 1;
}

.social-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: none;
}

.social-panel iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: transparent;
}

@media (max-width: 600px) {
  .social-overlay {
    padding: 0;
    align-items: center;
    justify-content: center;
  }

  .social-panel {
    width: auto;
    min-width: 0;
    flex: 0 1 calc(100% - 40px);
    height: 95dvh;
    max-width: none;
    max-height: 95dvh;
    margin: 0 20px;
    border-radius: 24px;
  }

  .social-close {
    top: 14px;
    right: 14px;
  }
}

.social-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.social-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.social-close:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.social-close:active {
  transform: translateY(0px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(26, 26, 29, 0.85);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: 1 1 auto;
}

body.public-gallery-view .topbar-left {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.title {
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.public-gallery-view .title {
  white-space: normal;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.sort-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-bottom: 1px solid rgba(251, 251, 252, 0.16);
}

.sort-option {
  appearance: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  cursor: pointer;
}

.sort-option:hover,
.sort-option:focus-visible {
  color: var(--ink);
}

.sort-option:focus-visible {
  outline: 2px solid var(--accent-glow);
  outline-offset: 2px;
}

.sort-option.is-active {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 currentColor;
}

@media (max-width: 600px) {
  .topbar-inner {
    flex-wrap: wrap;
  }
  .topbar-left {
    width: 100%;
  }
  .topbar-left .app-logo {
    margin-left: -20px;
  }
  body.gallery-page:not(.public-gallery-view) .title {
    flex-basis: 100%;
  }
  .actions {
    width: 100%;
    justify-content: center;
    margin-top: 6px;
  }
  .sort-control {
    order: 2;
    width: 100%;
    justify-content: center;
  }
  #downloadAllLink {
    order: 1;
  }
  .sort-segmented {
    max-width: 100%;
  }
  .sort-option {
    font-size: 0.75rem;
    padding: 5px 7px;
  }
  .action-btn {
    padding: 2px 10px;
    font-size: 0.75rem;
  }
  .site-footer-sep {
    display: none;
  }
  .site-footer-phone {
    display: block;
    margin-top: 2px;
  }
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(251, 251, 252, 0.14);
  background: rgba(251, 251, 252, 0.06);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
  user-select: none;
}

.action-btn:hover {
  background: rgba(251, 251, 252, 0.11);
  border-color: rgba(251, 251, 252, 0.24);
  transform: translateY(-1px);
}

.action-btn:active {
  transform: translateY(0px);
}

.public-share-copy-icon,
.public-share-copy-icon * {
  fill: none;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 16px 32px;
}

body.gallery-page .wrap {
  width: 100%;
  flex: 1 0 auto;
}

.site-footer {
  width: 100%;
  margin-top: auto;
  padding: 14px 16px 18px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.83rem;
}

.site-footer-text {
  margin: 0;
  line-height: 1.6;
}

.site-footer a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: rgba(251, 251, 252, 0.38);
  text-underline-offset: 3px;
}

.site-footer a:hover {
  text-decoration-color: rgba(251, 251, 252, 0.72);
}

.site-footer-phone {
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 680px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (min-width: 980px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }
}

@media (min-width: 1280px) {
  .grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.thumb {
  --thumb-delete-size: 36px;
  --thumb-delete-offset: 10px;
  --thumb-delete-radius: 10px;
  --thumb-delete-icon-size: 18px;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(42, 42, 46, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  aspect-ratio: 3 / 2;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  touch-action: manipulation;
  box-shadow: 0 12px 24px rgba(26, 26, 29, 0.16);
}

.thumb:hover {
  transform: translateY(-2px);
  border-color: rgba(124, 145, 156, 0.30);
  background: rgba(55, 56, 60, 0.95);
}

.thumb.is-manual-sort {
  cursor: grab;
}

.thumb.is-manual-sort:active,
.thumb.is-drag-source {
  cursor: grabbing;
}

.thumb.is-drag-source {
  opacity: 0.62;
  transform: scale(0.98);
}

.thumb.is-drop-before::before,
.thumb.is-drop-after::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(10, 10, 12, 0.18);
  z-index: 30;
}

.thumb.is-drop-before::before {
  left: 8px;
}

.thumb.is-drop-after::before {
  right: 8px;
}

.thumb .thumb-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.01);
}

.thumb-signature {
  position: absolute;
  right: 3.5%;
  bottom: 3.5%;
  width: auto;
  height: var(--gallery-signature-size);
  max-width: 60%;
  opacity: var(--gallery-signature-opacity);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 2;
  transform: none;
  filter: var(--gallery-signature-shadow);
}

.thumb-download-badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(26, 26, 29, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1;
  z-index: 12;
  pointer-events: none;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.thumb-action-group {
  position: absolute;
  right: var(--thumb-delete-offset);
  bottom: var(--thumb-delete-offset);
  z-index: 20;
  display: flex;
  gap: 8px;
}

.thumb-delete,
.thumb-edit {
  width: var(--thumb-delete-size);
  height: var(--thumb-delete-size);
  border-radius: var(--thumb-delete-radius);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(26, 26, 29, 0.85);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.thumb:hover .thumb-action-group > *,
.thumb:focus-within .thumb-action-group > * {
  opacity: 1;
  transform: translateY(-2px);
}

.thumb-delete:hover,
.thumb-edit:hover {
  background: rgba(42, 42, 46, 0.98);
}

.thumb-delete svg,
.thumb-edit svg {
  width: var(--thumb-delete-icon-size);
  height: var(--thumb-delete-icon-size);
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 679px) {
  .thumb {
    --thumb-delete-size: 48px;
    --thumb-delete-offset: 13px;
    --thumb-delete-radius: 13px;
    --thumb-delete-icon-size: 24px;
  }
}

.thumb-portrait .thumb-photo {
  object-fit: cover;
  transform: scale(1.01);
}

.thumb-portrait {
  aspect-ratio: 2 / 3;
  width: calc(100% * 2 / 3);
  justify-self: center;
}

.empty {
  padding: 28px 12px;
  color: var(--muted);
  font-size: 14px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}


/* Touch devices: no hover state, keep delete button visible by default */
@media (pointer: coarse) {
  .thumb-action-group > * {
    display: grid;
    opacity: 1;
    transform: none;
  }
}

.download-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: rgba(8, 10, 12, 0.55);
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  z-index: 1200;
}

.download-overlay.is-open {
  display: flex;
}

.download-backdrop {
  position: absolute;
  inset: 0;
}

.download-panel {
  position: relative;
  width: min(420px, 92vw);
  border-radius: 22px;
  background: rgba(42, 42, 46, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--overlay-shadow);
  padding: 26px 22px 22px;
  z-index: 1;
  text-align: center;
}

.download-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--overlay-stroke);
  background: var(--overlay-btn);
  color: var(--ink);
  cursor: pointer;
}

.download-close:hover {
  background: var(--overlay-btn-hover);
}

.download-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.download-title {
  margin: 0 0 8px;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.05rem, 2vw, 1.2rem);
}

.download-hint {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.88rem;
}

.download-choice-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.download-choice-actions .action-btn {
  cursor: pointer;
  font: inherit;
}

.download-loading-step {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.download-spinner {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 3px solid rgba(251, 251, 252, 0.18);
  border-top-color: rgba(251, 251, 252, 0.9);
  animation: download-spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes download-spin {
  to {
    transform: rotate(360deg);
  }
}

.download-cancel-btn {
  cursor: pointer;
  font: inherit;
  margin-top: 4px;
}
