* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  background: #030303;
  color: #f3f0e8;
  font-family: Arial, Helvetica, sans-serif;
  -webkit-overflow-scrolling: touch;
}

body.viewer-open {
  overflow: hidden;
}

button {
  font: inherit;
}

.app {
  width: 100vw;
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  background: #030303;
}

.topbar {
  flex: 0 0 auto;
  min-height: 64px;
  padding: 14px max(14px, 3vw) 12px;
  border-bottom: 1px solid #171717;
}

.categories {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  overflow: hidden;
}

.category-button {
  flex: 0 0 auto;
  height: 34px;
  max-width: 190px;
  padding: 0 10px;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  background: #0b0b0b;
  color: #bdb8ae;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-button:hover,
.category-button:focus {
  color: #fff8ea;
  border-color: #5a5245;
  outline: none;
}

.category-button.active {
  color: #050505;
  background: #efe2c4;
  border-color: #efe2c4;
}

.category-count {
  color: #7e776b;
  margin-left: 5px;
}

.category-button.active .category-count {
  color: #403a32;
}

.stage {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px max(22px, 5vw) 30px;
  overflow: hidden;
}

.photo-grid {
  width: min(100%, 1120px);
  height: min(100%, 680px);
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  overflow: hidden;
}

.masonry-column {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.photo-tile {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 4px solid #efe2c4;
  border-radius: 0;
  background: #efe2c4;
  cursor: pointer;
  overflow: hidden;
}

.photo-tile:focus {
  outline: 2px solid #efe2c4;
  outline-offset: 2px;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  filter: saturate(0.96) contrast(1.02);
  transform: scale(1);
  transition: transform 180ms ease, opacity 180ms ease;
}

.photo-tile:hover img,
.photo-tile:focus img {
  transform: scale(1.035);
}

.empty-state {
  margin: auto;
  color: #8f887c;
  font-size: 15px;
}

.viewer {
  position: fixed;
  z-index: 50;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
}

.viewer.open {
  display: block;
}

.viewer-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.86);
}

.viewer-shell {
  position: absolute;
  top: max(36px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  width: auto;
  height: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  min-height: 0;
}

.viewer-image-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050505;
  border: 1px solid #171717;
  border-radius: 6px;
  overflow: hidden;
}

.viewer-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}

.metadata-panel {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  border: 1px solid #24211c;
  border-radius: 6px;
  background: #0a0a0a;
  overflow: hidden;
}

.metadata {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.metadata::-webkit-scrollbar {
  display: none;
}

.metadata-section {
  margin-bottom: 0;
}

.metadata-list {
  margin: 0;
}

.metadata-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.35;
}

.metadata-row dt {
  color: #8a8378;
  overflow-wrap: anywhere;
}

.metadata-row dd {
  margin: 0;
  color: #e4ddcf;
  overflow-wrap: anywhere;
}

.close-button {
  position: fixed;
  z-index: 2;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #34302a;
  border-radius: 8px;
  background: #0d0d0d;
  color: #eee4d2;
  cursor: pointer;
  line-height: 30px;
  text-align: center;
}

.close-button:hover,
.close-button:focus {
  color: #050505;
  background: #efe2c4;
  outline: none;
}

@media (max-width: 720px) {
  .app {
    height: 100dvh;
  }

  .topbar {
    min-height: 0;
    padding: 8px 6px 6px;
  }

  .categories {
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
  }

  .category-button {
    height: 30px;
    max-width: 128px;
    padding: 0 8px;
    font-size: 12px;
  }

  .stage {
    padding: 8px 4px 10px;
  }

  .photo-grid {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    justify-content: center;
  }

  .viewer-shell {
    top: max(48px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(126px, 34dvh);
    gap: 10px;
  }

  .metadata-panel {
    padding: 12px;
  }

  .metadata-row {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 8px;
    margin-bottom: 6px;
    font-size: 11px;
  }
}

@media (max-height: 520px) {
  .topbar {
    min-height: 44px;
    padding-top: 6px;
    padding-bottom: 5px;
  }

  .category-button {
    height: 30px;
  }

  .stage {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .viewer-shell {
    top: max(44px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
  }
}
