/* =========================================================
  Index: Media Gallery (preview grid)
  - "Media Gallery" header like News (sticky under the nav)
  - When the section is ~1/5 in view, images reveal 1-by-1 from bottom
  - No rounded corners (square)
  - v2026-01-30
========================================================= */

/* Section base (pure black) */
#gallery{
  position: relative;
  overflow: visible;     /* sticky header needs overflow visible */
  isolation: isolate;
  background: #000;
  padding-bottom: 56px;
}

#gallery > .wrap{
  position: relative;
  z-index: 1;
}


/* =========================================================
  Header (Title + red line + flowing text)
  - News と同じ雰囲気
  - ✅ Nav の下で sticky
  - ✅ アニメは「表示された瞬間」に開始（JSが .is-in を付与）
========================================================= */

#gallery .mgHead{
  /* --- tuning vars --- */
  --mg-titleSize: clamp(48px, 7vw, 72px);
  --mg-titleStagger: 60ms;
  --mg-titleDur: 720ms;

  /* "Media Gallery" = 13 chars (incl. space) -> (12 * stagger) + dur */
  --mg-titleTotal: calc((12 * var(--mg-titleStagger)) + var(--mg-titleDur));

  --mg-headLineW: min(320px, 70%);
  --mg-headLineH: 3px;
  --mg-headLineDelay: 140ms;
  --mg-headLineDur: 320ms;

  --mg-marqueeSize: 14px;
  --mg-marqueeDur: 18s;
  --mg-marqueeGap: 48px;
  --mg-marqueeDelay: 260ms;

  margin: 0 0 16px;
}

/* Sticky mode: Nav の直下に貼り付く */
#gallery .mgHead--sticky{
  position: sticky;
  top: var(--nh-navH, 72px);
  z-index: 25;

  padding: 14px 0 12px;
  margin-bottom: 14px;

  /* 黒い板 + ぼかし（背景が真っ黒でも“貼り付く”感） */
  background: linear-gradient(
    180deg,
    rgba(0,0,0,.86),
    rgba(0,0,0,.54) 62%,
    rgba(0,0,0,0)
  );
  backdrop-filter: blur(10px);

  border-top: 1px solid rgba(255,255,255,.08);
}

#gallery .mgHead__row{
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

#gallery .mgHead__title{
  margin: 0;
  font-size: var(--mg-titleSize);
  line-height: 1.05;
  letter-spacing: .04em;
  font-weight: 900;
  text-shadow: 0 18px 40px rgba(0,0,0,.55);
}

#gallery .mgHead__ch{
  display: inline-block; /* base（JS無しでも文字が出る） */
}

/* “落下”アニメ（JSが .is-in を付与した時だけ再生） */
.js #gallery .mgHead__ch{
  opacity: 0;
  transform: translate(36px, -36px) rotate(8deg);
  filter: blur(1px);
  will-change: transform, opacity, filter;
}

.js #gallery .mgHead.is-in .mgHead__ch{
  animation: nhMgTitleDrop var(--mg-titleDur) cubic-bezier(.18,.9,.2,1) forwards;
  animation-delay: calc(var(--i) * var(--mg-titleStagger));
}

@keyframes nhMgTitleDrop{
  0%{ opacity:0; transform: translate(36px, -36px) rotate(8deg); filter: blur(1px); }
  60%{ opacity:1; transform: translate(-2px, 2px) rotate(0deg); filter: blur(0); }
  100%{ opacity:1; transform: translate(0,0) rotate(0deg); filter: blur(0); }
}

#gallery .mgHead__line{
  margin-top: 10px;
  width: var(--mg-headLineW);
  height: var(--mg-headLineH);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(225,6,0,1), rgba(255,59,48,0));
  box-shadow: 0 10px 22px rgba(225,6,0,.18);

  transform-origin: left;
  transform: scaleX(1); /* base（JS無しでも線は見える） */
}

/* 線のアニメ（JSが .is-in を付与した時だけ再生） */
.js #gallery .mgHead__line{
  transform: scaleX(0);
}

.js #gallery .mgHead.is-in .mgHead__line{
  animation: nhMgHeadLineIn var(--mg-headLineDur) ease forwards;
  animation-delay: calc(var(--mg-titleTotal) + var(--mg-headLineDelay));
}

@keyframes nhMgHeadLineIn{
  from{ transform: scaleX(0); }
  to{ transform: scaleX(1); }
}

#gallery .mgHead__marquee{
  margin-top: 14px;
  overflow: hidden;
  white-space: nowrap;

  font-size: var(--mg-marqueeSize);
  color: rgba(255,255,255,.74);
  letter-spacing: .02em;

  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);

  opacity: 1; /* base */
  transform: translateY(0);
}

/* マーキーの “ふわっ” 表示（JSが .is-in を付与した時だけ） */
.js #gallery .mgHead__marquee{
  opacity: 0;
  transform: translateY(4px);
}

.js #gallery .mgHead.is-in .mgHead__marquee{
  animation: nhMgMarqueeIn 320ms ease forwards;
  animation-delay: calc(var(--mg-titleTotal) + var(--mg-headLineDelay) + var(--mg-marqueeDelay));
}

@keyframes nhMgMarqueeIn{
  to{ opacity: 1; transform: translateY(0); }
}

#gallery .mgHead__marqueeTrack{
  display: inline-flex;
  width: max-content;
  animation: nhMgMarquee var(--mg-marqueeDur) linear infinite;
}

#gallery .mgHead__marqueeText{
  padding-right: var(--mg-marqueeGap);
}

@keyframes nhMgMarquee{
  0%{ transform: translateX(0); }
  100%{ transform: translateX(-50%); }
}

@media (max-width: 640px){
  #gallery .mgHead{
    --mg-titleSize: clamp(40px, 11vw, 62px);
    --mg-marqueeSize: 13px;
  }
}


/* =========================================================
  Grid (preview images)
  - 3 columns (center is bigger)
  - no rounded corners
  - reveal by JS: .mgCard.is-in (rises from bottom of the viewport)
========================================================= */

#gallery .mgBody{
  padding-top: 4px;
}

#gallery .mgGrid{
  display: grid;
  /* ✅ PCと同じ「3列（中央太め）」をスマホでも維持 */
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 14px; /* column gap */
  margin-top: 12px;

  /* ✅ これがないと “行の高さ” に引っ張られてカードが伸びて
     下に黒い余白（=カード背景）が出る */
  align-items: start;
}

/*
  ✅ Desktop 3-column layout の「黒い余白」対策
  - 1行グリッド（左/中央/右）にして、各列の中を “縦積み” する
  - こうすると中央が大きくても左右の下が空かず、上に詰まって見える
*/
#gallery .mgCol{
  display:flex;
  flex-direction:column;
  gap: 14px;
  min-width: 0;
}

/* ✅ 左右列は少し上寄せ（見え方を揃える） */
#gallery .mgCol--left  .mgImg,
#gallery .mgCol--right .mgImg{
  background-position: 50% 0%;
}

#gallery .mgCard{
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;

  /* full width inside column */
  width: 100%;

  border-radius: 0;
  overflow: hidden;

  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.04);
  box-shadow: 0 14px 36px rgba(0,0,0,.28);

  transition: transform 160ms ease, border-color 160ms ease;
}
#gallery .mgCard:hover{
  transform: translateY(-2px);
  border-color: rgba(255,255,255,.22);
}

#gallery .mgImg{
  border-radius: 0;
  aspect-ratio: 4 / 5;

  /* ✅ 高さは “この要素自身” が持つ（カードを伸ばさない） */
  flex: 0 0 auto;

  background-image:
    var(--img),
    radial-gradient(900px 520px at 18% 10%, rgba(225,6,0,.12), transparent 62%),
    linear-gradient(135deg, rgba(255,255,255,.06), rgba(0,0,0,.45));
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;

  filter: saturate(1.06) contrast(1.04);
}

/* ✅ reveal: initial hidden (JS mode only) */
.js #gallery .mgCard{
  opacity: 0;
  /* ✅ “画面の下から上に移動してくる” 感（= viewport基準） */
  transform: translateY(100vh);
  filter: blur(12px);
  pointer-events: none;
  transition:
    opacity 520ms ease,
    transform 680ms cubic-bezier(.18,.9,.2,1),
    filter 980ms ease;
  will-change: opacity, transform, filter;
}

.js #gallery .mgCard.is-in{
  opacity: 1;
  transform: translateY(0);
  filter: blur(0px);
  pointer-events: auto;
}


/* =========================================================
  VIEW ALL bar
  - News と同じ “全幅バー” の感じ
========================================================= */

#gallery .mgViewAll{
  position: relative;
  margin-top: 18px;
  border-top: 1px solid rgba(255,255,255,.72);
  border-bottom: 1px solid rgba(255,255,255,.72);
  overflow: hidden;
}

#gallery .mgViewAll::before{
  content:"";
  position:absolute;
  inset:0;
  background: linear-gradient(90deg, rgba(120,0,0,1), rgba(150,0,0,1));
  transform-origin: left;
  transform: scaleX(1); /* base */
}

#gallery .mgViewAll__link{
  position: relative;
  z-index: 1;

  display:flex;
  align-items:center;
  justify-content:center;
  gap: 18px;

  padding: 18px 0;
  text-decoration:none;

  color: rgba(255,255,255,.98);
  font-weight: 900;
  font-size: clamp(38px, 6vw, 72px);
  letter-spacing: .08em;
  text-transform: uppercase;

  text-shadow: 0 18px 40px rgba(0,0,0,.42);
}

/* global a:hover の薄れを無効化 */
#gallery .mgViewAll__link:hover{ opacity: 1; }

#gallery .mgViewAll__arrow{
  display:inline-block;
  transform: translateY(1px);
}

/* JSが動く時だけ：最初は隠して、入ってきた瞬間にアニメ */
.js #gallery .mgViewAll::before{
  transform: scaleX(0);
}
.js #gallery .mgViewAll__link{
  opacity: 0;
  transform: translateX(-46px);
}

.js #gallery .mgViewAll.is-in::before{
  animation: nhMgViewAllFill 520ms ease forwards;
}

.js #gallery .mgViewAll.is-in .mgViewAll__link{
  animation: nhMgViewAllText 560ms cubic-bezier(.18,.9,.2,1) forwards;
  animation-delay: 520ms;
}

@keyframes nhMgViewAllFill{
  to{ transform: scaleX(1); }
}
@keyframes nhMgViewAllText{
  to{ opacity: 1; transform: translateX(0); }
}

@media (max-width: 640px){
  /* ✅ スマホは画面いっぱい（左右の隙間ゼロ） */
  #gallery .mgViewAll{
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  #gallery .mgViewAll__link{
    padding: 16px 0;
    font-size: clamp(34px, 10vw, 60px);
  }
}


/* =========================================================
  Motion reduction (動きを減らしたい人向け)
========================================================= */

@media (prefers-reduced-motion: reduce){
  /* Header */
  .js #gallery .mgHead__ch{
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
  .js #gallery .mgHead__line{
    animation: none !important;
    transform: none !important;
  }
  .js #gallery .mgHead__marquee{
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .js #gallery .mgHead__marqueeTrack{
    animation: none !important;
    transform: none !important;
  }

  /* Cards */
  .js #gallery .mgCard{
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    pointer-events: auto !important;
  }
  #gallery .mgCard:hover{
    transform: none !important;
  }

  /* VIEW ALL */
  .js #gallery .mgViewAll::before{
    animation: none !important;
    transform: scaleX(1) !important;
  }
  .js #gallery .mgViewAll__link{
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* =========================================================
  Lightbox (Index preview)
  - Click a preview image -> show that image
========================================================= */

.mgModal{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.mgModal[aria-hidden="false"]{
  display: flex;
}

.mgModal__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(6px);
}

.mgModal__panel{
  position: relative;
  z-index: 1;
  width: min(980px, calc(100% - 28px));
  max-height: calc(100% - 28px);

  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(11,13,18,.86);
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
  overflow: hidden;
}

.mgModal__imgwrap{
  background: rgba(0,0,0,.25);
}

.mgModal__img{
  display: block;
  width: 100%;
  height: auto;
  max-height: 72vh;
  object-fit: contain;
}

.mgModal__meta{
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.10);
}

.mgModal__title{
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: .02em;
}

.mgModal__cap{
  margin: 0;
  color: rgba(255,255,255,.78);
  font-size: 13px;
}

.mgModal__close{
  position: absolute;
  top: 12px;
  right: 12px;
}
