:root{
  --fade-ms:1200ms;
  --modal-pad:10px;
  --arrow-inset:10px;
}

/* wrapper & title */
.ah-wrap{max-width:1200px;margin:40px auto;padding:0 10px;box-sizing:border-box;text-align:center}
.ah-title{font-size:2rem;margin-bottom:20px;color:#2b3a46}
.ah-title span{display:block;font-size:.9rem;color:#6a7b85;margin-top:5px;letter-spacing:.05em}

/* stage & tiles */
.ah-stage{position:relative;width:100%;max-width:1200px;aspect-ratio:1200/600;margin:0 auto}
.ah-gallery{position:absolute;inset:0;display:grid;grid-template-columns:repeat(8,1fr);grid-template-rows:repeat(4,1fr)}
.ah-tile{position:relative;overflow:hidden;background:#e9ecef;cursor:pointer}

/* 通常はブラー無し（2回目以降の更新もここを使う） */
.ah-tile img{
  position:absolute;inset:0;width:100%;height:100%;object-fit:cover;
  transition: opacity var(--fade-ms) ease;
  opacity:0;
  will-change:opacity;
}
.ah-tile img.ah-front{opacity:1}
.ah-tile img.ah-back{opacity:0}
.ah-tile.ah-swapping img.ah-front{opacity:0}
.ah-tile.ah-swapping img.ah-back{opacity:1}

/* 初回のみブラーを効かせる（.ah-wrap に .ah-initial が付いている間だけ） */
.ah-initial .ah-tile img{
  transition: opacity var(--fade-ms) ease, filter var(--fade-ms) ease;
  filter:blur(16px);
  opacity:.2;
  will-change:opacity,filter;
}
.ah-initial .ah-tile img.ah-front{
  filter:blur(0);
  opacity:1;
}

/* PC layout */
.ah-t1 { grid-area:1 / 1 / 3 / 3; }
.ah-t2 { grid-area:1 / 3 / 3 / 5; }
.ah-t3 { grid-area:1 / 5 / 2 / 6; }
.ah-t4 { grid-area:2 / 5 / 3 / 6; }
.ah-t5 { grid-area:1 / 6 / 3 / 9; }
.ah-t6 { grid-area:3 / 1 / 5 / 4; }
.ah-t7 { grid-area:3 / 4 / 4 / 5; }
.ah-t8 { grid-area:4 / 4 / 5 / 5; }
.ah-t9 { grid-area:3 / 5 / 5 / 7; }
.ah-t10{ grid-area:3 / 7 / 5 / 9; }

/* スマホlayout */
@media(max-width:640px){
  .ah-wrap{padding:0 20px}
  .ah-stage{aspect-ratio:4/8}
  .ah-gallery{grid-template-columns:repeat(4,1fr);grid-template-rows:repeat(8,1fr)}
  .ah-t1 { grid-area:1 / 1 / 3 / 3; } .ah-t2 { grid-area:1 / 3 / 3 / 5; }
  .ah-t3 { grid-area:3 / 1 / 4 / 2; } .ah-t4 { grid-area:4 / 1 / 5 / 2; } .ah-t5 { grid-area:3 / 2 / 5 / 5; }
  .ah-t9 { grid-area:5 / 1 / 7 / 3; } .ah-t10{ grid-area:5 / 3 / 7 / 5; }
  .ah-t6 { grid-area:7 / 1 / 9 / 4; } .ah-t7 { grid-area:7 / 4 / 8 / 5; } .ah-t8 { grid-area:8 / 4 / 9 / 5; }
}

/* 白線 */
.ah-seams{position:absolute;inset:0;pointer-events:none;z-index:5}
.ah-seam{position:absolute;background:#fff}

/* progress 1px 黒ライン */
.ah-progress{
  max-width:1200px;margin:20px auto 0;height:1px;position:relative;background:none;overflow:hidden;
}
.ah-progress-bar{
  position:absolute;inset:0 auto 0 0;width:0%;height:100%;
  background:rgba(0,0,0,.9);
  box-shadow:0 0 2px rgba(0,0,0,.25);
  border-radius:1px;
  animation:none;
  will-change:width;
}
@keyframes ah-fill{0%{width:0%}100%{width:100%}}
@media(max-width:640px){.ah-progress{margin-top:16px}}

/* modal */
.ah-modal{display:none;position:fixed;inset:0;background:rgba(0,0,0,.58);align-items:center;justify-content:center;z-index:9999;backdrop-filter:blur(4px)}
.ah-modal.active{display:flex}
.ah-modal::before{
  content:"";position:absolute;inset:-10%;
  background:radial-gradient(120% 120% at 50% 50%,rgba(255,255,255,.06) 0%,rgba(0,0,0,.10) 55%,rgba(0,0,0,.22) 100%);
  pointer-events:none;
}

.ah-modal-content{
  position:relative;background:#fffefe;padding:var(--modal-pad);margin:20px;border-radius:5px;
  box-shadow:0 26px 54px rgba(0,0,0,.26),0 7px 22px rgba(0,0,0,.16);
  outline:1px solid rgba(255,255,255,.6);
  max-width:calc(100vw - 40px);max-height:calc(100vh - 40px);
  display:flex;align-items:center;justify-content:center;
  transition:width .28s ease,height .28s ease;
  opacity:0;transform:translateY(12px) scale(.982);
  will-change:opacity,transform;
}
.ah-modal-content::before{
  content:"";position:absolute;inset:0;border-radius:inherit;
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.035),inset 0 1px 0 rgba(255,255,255,.65);
  pointer-events:none;
}
.ah-modal.active .ah-modal-content{animation:ahIn .38s cubic-bezier(.22,.61,.36,1) forwards}
@keyframes ahIn{from{opacity:0;transform:translateY(12px) scale(.982)}to{opacity:1;transform:translateY(0) scale(1)}}
@media(min-width:768px){.ah-modal-content{width:70vw}}
@media(max-width:640px){.ah-modal-content{padding:5px}}

.ah-modal-content img{
  max-width:100%;max-height:100%;object-fit:contain;
  opacity:0;transition:opacity .42s ease-out;
  will-change:opacity;
}

/* arrows */
.ah-modal-content .ah-nav{
  position:absolute;top:50%;transform:translateY(-50%);
  width:44px;height:44px;border-radius:50%;
  background:rgba(255,255,255,.5);
  box-shadow:0 8px 20px rgba(0,0,0,.16);
  cursor:pointer;user-select:none;z-index:10;display:grid;place-items:center;
  transition:opacity .2s,transform .2s,box-shadow .25s;
}
.ah-modal-content .ah-nav::after{
  content:"";display:block;width:20px;height:20px;
  background-repeat:no-repeat;background-position:center;background-size:contain;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'><path d='M8 4l8 8-8 8'/></svg>");
}
.ah-modal-content .ah-prev{left:calc(var(--modal-pad) + var(--arrow-inset))}
.ah-modal-content .ah-next{right:calc(var(--modal-pad) + var(--arrow-inset))}
.ah-modal-content .ah-prev::after{transform:scaleX(-1)}
.ah-modal-content .ah-nav:hover{opacity:.95;transform:translateY(-50%) scale(1.04);box-shadow:0 10px 28px rgba(0,0,0,.22)}
@media(max-width:640px){
  .ah-modal-content .ah-nav{width:28px;height:28px}
  .ah-modal-content .ah-nav::after{width:14px;height:14px}
  .ah-modal-content .ah-prev{left:15px}
  .ah-modal-content .ah-next{right:15px}
}

/* pager dots */
.ah-pager{position:absolute;left:50%;transform:translateX(-50%);bottom:calc(var(--modal-pad) + 12px);display:flex;gap:8px;z-index:11}
.ah-dot{width:6px;height:6px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);border:0;cursor:pointer;padding:0;transition:all .25s}
.ah-dot.is-active{transform:scale(1.7);box-shadow:0 2px 6px rgba(0,0,0,.4)}
@media(max-width:640px){.ah-pager{bottom:calc(10px + 8px);gap:6px}}

.ah-close{position:absolute;top:10px;right:20px;font-size:40px;color:#fff;cursor:pointer}

@media (prefers-reduced-motion: reduce){
  .ah-modal-content{animation:none !important;opacity:1 !important;transform:none !important}
  .ah-modal-content img{transition:none !important;opacity:1 !important}
}
