:root{
  --gap: 12px;
  --thumbSize: 150px;

  /* プレビュー画像の大きさ（ここを調整） */
  --previewScale: 0.85; /* 0.80〜0.90くらいが使いやすい */
}

body{
  margin: 0;
  /*font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;*/
  background: #f4f4f4;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 480px){
  :root{
    --gap: 10px;
    --thumbSize: 120px;
    --previewScale: 0.88; /* スマホは少し大きめでもOK。余白欲しければ下げる */
  }
}

.gallery{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--thumbSize), 1fr));
  gap: var(--gap);
  padding: 16px;
}

.gallery img{
  width: 100%;
  height: var(--thumbSize);
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .15s ease;
  user-select: none;
  -webkit-user-drag: none;
}
.gallery img:active{ transform: scale(0.98); }

/* ===== Modal ===== */
.modal{
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.88);
  justify-content: center;
  align-items: center;

  /* ノッチ対応 */
  padding:
    calc(14px + env(safe-area-inset-top))
    calc(14px + env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    calc(14px + env(safe-area-inset-left));
}

.modal.active{ display: flex; }

/* 画像を少し小さくして余白を作る（×が見えやすくなる） */
.modal img{
  max-width: calc(100% * var(--previewScale));
  max-height: calc(100% * var(--previewScale));
  border-radius: 12px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;

  /* 縦方向の操作はブラウザに任せる / 横スワイプはJSで扱う */
  touch-action: pan-y;
}

body.modal-open{
  position: fixed;
  width: 100%;
  overflow: hidden;
}

/* ボタン共通 */
.close-btn,
.nav-btn{
  border: none;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

/* 閉じるボタン（視認性アップ：背景を少し濃く） */
.close-btn{
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  background: rgba(0,0,0,0.55);
  font-size: 26px;
  line-height: 44px;
  text-align: center;
}
.close-btn:active{ transform: scale(0.96); }

/* 前後ボタン */
.nav-btn{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.15);
  font-size: 28px;
  line-height: 48px;
  text-align: center;
}
.nav-btn:active{ transform: translateY(-50%) scale(0.96); }

.prev-btn{
  left: calc(10px + env(safe-area-inset-left));
}
.next-btn{
  right: calc(10px + env(safe-area-inset-right));
}

@media (max-width: 480px){
  .nav-btn{
    width: 44px;
    height: 44px;
    font-size: 26px;
    line-height: 44px;
  }
}