/* ==========================================================================
   アニメーション軽量化の共通部品（モバイル発熱削減 PR2）
   spec: docs/features/mobile-perf-css-animations/spec.md §5.1 / §5.6

   - 虹枠は「角度を変えない conic-gradient を正方形に描き、その正方形を
     transform: rotate() で回す」方式にする。カスタムプロパティの角度を
     アニメーションさせる方式はコンポジタで動かせず、毎フレーム再描画になるため。
   - 回転レイヤー（.rainbow-spin）は既定で非表示。表示するかどうかは、
     虹を描いていたのと同じ CSS ファイル・同じセレクタが決める（spec §5.3）。
   ========================================================================== */

/* カード型の回転レイヤー（R3〜R8 共通）
   ホストの最後の子として置く。ホスト側は虹が有効なときだけ
   position: relative / isolation: isolate / background: transparent にする */
.rainbow-spin {
    display: none;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    overflow: hidden;              /* 切り抜きはこれだけ（mask を併用しない。二重のアンチエイリアスを避ける） */
    z-index: -1;                   /* ホストが isolation: isolate の中でだけ使う */
    pointer-events: none;
    container-type: size;
}

/* 回転する正方形。一辺はホストの対角線 + 2px（どの角度でもホストの矩形を覆い切る）。
   cq 単位・hypot() 非対応環境では直前の width: 200% が残る（縦横比 1.73 まで覆える） */
.rainbow-spin::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    width: calc(hypot(100cqw, 100cqh) + 2px);
    aspect-ratio: 1;
    background: var(--rainbow-spin-gradient, conic-gradient(from 0deg,
        #ffc8c8, #ffe6b0, #fffaaa, #b8f0b8, #b0d8ff, #d4b0ff, #ffb8e0, #ffc8c8));
    transform: translate(-50%, -50%) rotate(0deg);
    animation: rainbow-spin-rotate var(--rainbow-spin-duration, 3s) linear infinite;
}

/* from を明記する（WebKit は基底の transform との暗黙補間で回転しないことがある）。
   keyframes 名はクラス名 .rainbow-spin と区別するため -rotate を付ける */
@keyframes rainbow-spin-rotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* 画面外停止（offscreen-animation-pause.js が付与する）。
   対象要素自身とその疑似要素だけを止め、子孫には波及させない
   （子孫の 1 回限りのフェードイン等を止めると見た目が変わるため） */
.is-anim-paused,
.is-anim-paused::before,
.is-anim-paused::after {
    animation-play-state: paused !important;
}

/* 進捗バーの虹色フロー（P13 回転数イベント進捗 / P14 進捗バー共通・spec §5.5）。
   .progress-fill の中に <span class="progress-fill__flow"> を置き、その ::before（幅 9 倍の帯）を
   transform: translateX で動かす（background-position のアニメーションは毎フレーム再描画になるため）。
   帯の模様の幅 = バー幅の 3 倍、-6 倍 → 0 の移動で、旧実装
   （background-size: 300% / background-position: 300% → 0%）と同じ位置関係になる。
   切り抜きはこの要素の overflow だけで行い、.progress-fill 自体には overflow を付けない
   （.progress-fill::after のツヤが角丸の外に出ている現行の見た目を切らないため） */
.progress-fill__flow {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    overflow: hidden;
    pointer-events: none;
}
.progress-fill__flow::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 900%;
    background: linear-gradient(90deg, #FFA8A8 0%, #FFE68A 15%, #A8E6B0 30%, #8DC4FF 45%, #C9A4E0 60%, #FFA8A8 75%, #FFE68A 90%, #A8E6B0 100%);
    background-size: calc(100% / 3) 100%;
    transform: translateX(calc(-200% / 3));
    animation: progress-fill-flow 2s linear infinite;
}
@keyframes progress-fill-flow {
    from { transform: translateX(calc(-200% / 3)); }
    to { transform: translateX(0); }
}
