* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0b0f1a;
  color: #dae2fd;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  overscroll-behavior: none;
}

#header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-top)) 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #0b0f1acc;
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #1c2338;
}

#header h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

#downloadBtn {
  font-size: 13px;
  font-weight: 700;
  color: #0b0f1a;
  background: #8fb8ff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

#downloadBtn:disabled {
  opacity: 0.6;
}

.hint {
  margin: 8px 12px;
  font-size: 12px;
  color: #8f909e;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 3px;
  padding: 3px;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #171f33;
  border: none;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile .num {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 10px;
  font-weight: 700;
  color: #dae2fd;
  background: #000000a0;
  padding: 1px 4px;
  border-radius: 4px;
  pointer-events: none;
}

#viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000000ee;
  display: flex;
  align-items: center;
  justify-content: center;
}

#viewer.hidden {
  display: none;
}

.stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.stage img {
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: #f2f5ff;
  text-shadow: 0 1px 6px #000000cc;
  pointer-events: none;
}

.viewer-btn {
  position: absolute;
  z-index: 21;
  background: #00000080;
  color: #dae2fd;
  border: none;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.viewer-close {
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  width: 38px;
  height: 38px;
}

.viewer-prev, .viewer-next {
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
}

.viewer-prev { left: 6px; }
.viewer-next { right: 6px; }
