:root{
  --gap: 12px;
  --radius: 14px;
  --max: 980px;
}

*{ box-sizing: border-box; }

body{
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #fafafa;
  line-height: 1.5;
}

a{ color: inherit; }

.container{
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px;
}

/* ===== Header ===== */
header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

h1{
  margin: 0;
  font-size: 20px;
}

/* ===== Tabs ===== */
.tabs{
  display: inline-flex;
  background: #eee;
  padding: 6px;
  border-radius: 999px;
  gap: 6px;
  margin-bottom: 16px;
}

.tab{
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}

.tab.is-active{
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}

/* ===== Gallery Grid ===== */
.grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--gap);
}

.card{
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eaeaea;
}

.card img{
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

/* ===== Modal ===== */
.modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;

  display: none;

  /* セーフエリア考慮 */
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-right: calc(12px + env(safe-area-inset-right));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
}

.modal.is-open{
  display: flex;
  justify-content: center;
  align-items: center;
}

.modalFrame{
  width: 100%;
  max-width: 980px;

  /* スマホでボタン分の余白を確保しやすいように */
  background: #111;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  position: relative;
}

.modalImg{
  width: 100%;
  height: auto;

  /* 画面に収める */
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  object-fit: contain;
  display: block;
  background: #111;
}

.modalClose{
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));

  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;

  font-size: 30px;
  font-weight: 700;

  cursor: pointer;
  background: rgba(255,255,255,0.95);
}

/* ===== Prev/Next Buttons (default: middle sides) ===== */
.navBtn{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);

  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: none;

  font-size: 34px;
  line-height: 44px;

  cursor: pointer;
  background: rgba(255,255,255,0.92);
  z-index: 2;
}

.navPrev{ left: 10px; }
.navNext{ right: 10px; }

.navBtn.is-disabled,
.navBtn:disabled{
  opacity: 0.35;
  cursor: default;
}

/* ===== Mobile: move buttons to bottom (no overlap) ===== */
@media (max-width: 520px){
  /* 下部に操作エリアを作る（画像と被らない） */
  .modalFrame{
    padding-bottom: 56px; /* ← ここが“被り回避”のキモ */
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .modalImg{
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 56px);
  }

  .navBtn{
    top: auto;
    bottom: 8px;
    transform: none;

    width: 44px;
    height: 44px;
    font-size: 30px;
    line-height: 44px;

    /* 目立ちすぎないよう少し透過 */
    background: rgba(255,255,255,0.88);
  }

  .navPrev{ left: 12px; }
  .navNext{ right: 12px; }
}
