/* ==========================================================================
   edge.css — 蒼夜シアター「最先端レイヤー」(2026-06-13)
   既存の style.css / theater.css / motion.js(GSAP) の上に載せる追加層。
   - CSS Scroll-Driven Animations(animation-timeline)は @supports で段階適用。
     非対応ブラウザは従来表示のまま(プログレッシブエンハンスメント)。
   - transform を奪うとGSAP・ホバーズームと競合するため、
     スクロール連動は clip-path / 専用要素のみで行う。
   ========================================================================== */

/* ---------- 0. 土台: ゴースト数字を持つセクションのみ内文を前面に ----------
   (edge.js が .has-ghost を付与。全 .sec への一括 z-index 変更は
    既存スタッキングを崩す恐れがあるため対象を限定する) */
.sec.has-ghost > .inner { position: relative; z-index: 1; }

/* ---------- 1. フィルムグレイン(全画面・常時) ----------
   feTurbulence のノイズを荷重 4.5% で重ねて銀塩フィルムの質感を出す。
   レイヤーはビューポート等倍に留め、background-position の8コマ
   ステップアニメで粒子を揺らす(巨大GPUレイヤーによるクラッシュ回避)。 */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  opacity: .045;
  animation: edge-grain .9s steps(1) infinite;
}

@keyframes edge-grain {
  0%, 100% { background-position: 0 0; }
  12.5%    { background-position: -14px -20px; }
  25%      { background-position: 21px 9px; }
  37.5%    { background-position: -9px 25px; }
  50%      { background-position: 25px -13px; }
  62.5%    { background-position: -25px 16px; }
  75%      { background-position: 11px -25px; }
  87.5%    { background-position: -18px -7px; }
}

/* ---------- 2. スクロール進捗バー(純CSS / scroll()タイムライン) ---------- */
.edge-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  z-index: 2001;
  pointer-events: none;
  background: linear-gradient(90deg, var(--c-ice, #87b8d6), rgba(135, 184, 214, .25));
  transform: scaleX(0);
  transform-origin: 0 50%;
  display: none;
}

@supports (animation-timeline: scroll()) {
  .edge-progress {
    display: block;
    animation: edge-progress-grow linear both;
    animation-timeline: scroll(root block);
  }
}

@keyframes edge-progress-grow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* ---------- 2b. オーバーレイ表示中の隔離 ----------
   写真LB(html.lb-open)/動画モーダル(html.tm-open)/ローダー(html.is-loading)/
   モバイルメニュー(html.nav-open) の鑑賞・操作面をグレインや進捗線で汚さない。
   これらのクラスは既存JSが付与しており本番ファイルは無改変。 */
html.lb-open body::after,
html.tm-open body::after,
html.is-loading body::after { display: none; }

html.lb-open .edge-progress,
html.tm-open .edge-progress,
html.is-loading .edge-progress,
html.nav-open .edge-progress { display: none; }

/* ---------- 3. ゴーストシーン数字(エディトリアルの大型タイポ) ----------
   edge.js が .sec-hd__no の数字を抽出して .sec-ghost を末尾に注入する。
   アウトラインのみの透過数字がセクション右下に半分沈む。 */
.sec-ghost {
  position: absolute;
  right: -.04em;
  bottom: -.14em;
  z-index: 0;
  font-family: "Outfit", sans-serif;
  font-weight: 600;
  font-size: clamp(7rem, 21vw, 19rem);
  line-height: 1;
  letter-spacing: -.03em;
  color: transparent;
  -webkit-text-stroke: 1px rgba(135, 184, 214, .14);
  user-select: none;
  pointer-events: none;
}

/* モバイル: 背の低いCTA/関連セクションで巨大数字が次セクションへ食い込むのを抑制 */
@media (max-width: 768px) {
  .sec-ghost {
    font-size: clamp(6rem, 18vw, 11rem);
    bottom: -.06em;
  }
}

@supports (animation-timeline: view()) {
  .sec-ghost {
    animation: edge-ghost-drift linear both;
    animation-timeline: view(block);
    animation-range: entry 0% exit 100%;
  }
  @keyframes edge-ghost-drift {
    from { transform: translateY(14%); }
    to   { transform: translateY(-14%); }
  }
}

/* ---------- 4. 画像のシネマティックワイプ(スクロール連動・スクラブ) ----------
   transform は触らず clip-path のみ — GSAPリヴィール/ホバーズームと共存。
   ビューポート進入に連動して「現像されるように」開く。 */
@supports (animation-timeline: view()) {
  .art-card__media img,
  .journal-card__media img,
  .video-card__fig img,
  .feature-screen__media img,
  .jr-photo img {
    animation: edge-wipe linear both;
    animation-timeline: view(block);
    /* 範囲を entry 内で完結させる: 要素が完全にビューへ入った時点(entry 100%)で
       ワイプ完了 → 画面内に「クロップされたまま静止する画像」を出さない。
       折り返し下の未到達画像は from を保持するが不可視なので問題なし。 */
    animation-range: entry 5% entry 100%;
  }
  @keyframes edge-wipe {
    from { clip-path: inset(12% 7% 12% 7%); }
    to   { clip-path: inset(0 0 0 0); }
  }
}

/* ---------- 5. ヒーロー Ken Burns(22秒の緩慢なドリフト) ----------
   既存 style.css の .sec-hero .hero-media__poster{animation:heroLive}(0,2,0)を
   同特異度+後勝ち(edge.cssは最後尾読込)で置換し演出を1本化する。
   reduced-motion では既存と同様 no-preference ゲートで自動停止。 */
@media (prefers-reduced-motion: no-preference) {
  .sec-hero .hero-media__poster {
    animation: edge-kenburns 22s ease-in-out infinite alternate;
  }
}

@keyframes edge-kenburns {
  from { transform: scale(1); }
  to   { transform: scale(1.06) translateY(-1.2%); }
}

/* ---------- 6. リールのシネスコ端フェード ---------- */
.reel__track {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 5%, #000 95%, transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 5%, #000 95%, transparent 100%);
}

/* ---------- 7. マイクロインタラクション ---------- */

/* 文字選択・スクロールバー・フォーカスリングの統一 */
::selection {
  background: var(--c-ice, #87b8d6);
  color: #0a0c0f;
}

html {
  scrollbar-color: rgba(135, 184, 214, .35) transparent;
  scrollbar-width: thin;
}

:focus-visible {
  outline: 2px solid var(--c-ice, #87b8d6);
  outline-offset: 3px;
}

/* ナビ: 下線が左から引かれる */
.site-nav a .en {
  background-image: linear-gradient(var(--c-ice, #87b8d6), var(--c-ice, #87b8d6));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition: background-size .45s cubic-bezier(.22, 1, .36, 1);
  padding-bottom: 2px;
}

.site-nav a:hover .en,
.site-nav a[aria-current="page"] .en {
  background-size: 100% 1px;
}

/* モバイル全画面メニュー(max-width:1179px)では下線アニメを無効化。
   既存は border-bottom:0 で下線を消しているが background 下線は別物のため
   ここで明示的に打ち消し、大型中央メニューをクリーンに保つ。 */
@media (max-width: 1179px) {
  .site-nav a .en {
    background-image: none;
    padding-bottom: 0;
  }
}

/* カードの浮上(translate プロパティ = GSAP の transform と干渉しない) */
.art-card,
.videos-card,
.video-card,
.journal-card,
.tour-item {
  transition: translate .5s cubic-bezier(.22, 1, .36, 1);
}

.art-card:hover,
.videos-card:hover,
.video-card:hover,
.journal-card:hover {
  translate: 0 -5px;
}

/* 再生ボタンの呼吸 */
.videos-card:hover .videos-card__play,
.feature-screen:hover .feature-screen__play {
  animation: edge-play-pulse 1.6s ease-in-out infinite;
}

@keyframes edge-play-pulse {
  0%, 100% { scale: 1; }
  50%      { scale: 1.06; }
}

/* ---------- 8. reduced-motion: 動きを全停止 ----------
   既存 style.css の *{animation:none !important} に加え、edge側でも明示停止。
   将来 style.css 側の全停止が外れても edge の動きが残らないよう !important を付す。 */
@media (prefers-reduced-motion: reduce) {
  body::after { animation: none !important; }
  .edge-progress { display: none !important; }
  .sec-ghost,
  .sec-hero .hero-media__poster,
  .videos-card:hover .videos-card__play,
  .feature-screen:hover .feature-screen__play { animation: none !important; }
  @supports (animation-timeline: view()) {
    .art-card__media img,
    .journal-card__media img,
    .video-card__fig img,
    .feature-screen__media img,
    .jr-photo img { animation: none !important; }
  }
  .art-card, .videos-card, .video-card, .journal-card, .tour-item { transition: none !important; }
}
