/*
 * 飄落花瓣背景特效（Falling petals）
 * 來源：AIMRAN Library「Falling petals」，由 React 轉為 Blade 元件 + 獨立 CSS。
 * 搭配 resources/views/components/falling-petals.blade.php 使用：<x-falling-petals />
 *
 * 可調整的 CSS 變數（元件 props 會寫進 inline style 覆蓋這裡的預設值）：
 *   --c1 / --c2  花瓣漸層色      --c3  底部光暈色
 *   --k  速度倍率 0.2 ~ 3        --d   花瓣大小倍率 0.5 ~ 2      --o  不透明度 0.2 ~ 1
 *   --bg 底色                    --tint 底部光暈濃度
 */
.pt-petals {
    --c1: #fbcfe8;
    --c2: #f472b6;
    --c3: #312e81;
    --k: 1.6;
    --d: 1.6;
    --o: 1;
    /* 淺色模式沿用登入頁原本的底色，只在底部加一點淡淡的光暈，不蓋掉原本的畫面。 */
    --bg: #e6f7ff;
    --tint: 14%;

    /* 整頁固定的裝飾層：放在泡泡（z-index:-1）後面、登入卡片後面。 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    overflow: hidden;
    /* 純裝飾，不可攔截滑鼠／觸控，避免影響登入欄位操作。 */
    pointer-events: none;
    container-type: size;
    isolation: isolate;
    /* 把重繪範圍鎖在這一層，避免再發生輸入框抖動。 */
    contain: strict;
    background-color: var(--bg);
    background: radial-gradient(ellipse at 50% 120%, color-mix(in srgb, var(--c3) var(--tint), var(--bg)), var(--bg) 70%);
}

/* 深色模式：改用原設計的深色底與較濃的靛色光暈。 */
@media (prefers-color-scheme: dark) {
    .pt-petals:not(.pt-petals--light) {
        --bg: #05060a;
        --tint: 70%;
    }
}

/* theme="dark" 時不看系統設定，強制深色。 */
.pt-petals--dark {
    --bg: #05060a;
    --tint: 70%;
}

.pt-petals i {
    position: absolute;
    top: -8%;
    left: var(--x);
    width: calc(var(--sz) * var(--d));
    height: calc(var(--sz) * var(--d));
    aspect-ratio: 1;
    border-radius: 150% 0 150% 0;
    background: linear-gradient(135deg, var(--c1), var(--c2));
    box-shadow: 0 0 12px rgba(244, 114, 182, 0.4); /* 舊瀏覽器不支援 color-mix 時的備援 */
    box-shadow: 0 0 12px color-mix(in srgb, var(--c2) 40%, transparent);
    opacity: var(--o);
    /* 只動 transform / translate，由 GPU 合成，不觸發版面重排。 */
    animation:
        pt-petals-f calc(var(--t) / var(--k)) linear infinite,
        pt-petals-s calc(var(--t) / 4 / var(--k)) ease-in-out infinite alternate;
    animation-delay: var(--dl);
    will-change: transform;
}

.pt-petals i:nth-child(odd) {
    border-radius: 0 150% 0 150%;
}

/* 往下飄並做 3D 翻轉 */
@keyframes pt-petals-f {
    from {
        transform: translateY(0) rotate3d(1, 1, 0, 0deg);
    }

    to {
        transform: translateY(120vh) rotate3d(1, 1, 0, 720deg); /* 不支援 cqh 時的備援 */
        transform: translateY(120cqh) rotate3d(1, 1, 0, 720deg);
    }
}

/* 左右搖擺，像被微風吹動 */
@keyframes pt-petals-s {
    from {
        translate: calc(var(--sw) * -1) 0;
    }

    to {
        translate: var(--sw) 0;
    }
}

/* 手機／平板：花瓣數量減半，避免小螢幕太擁擠並節省效能。 */
@media (max-width: 768px) {
    .pt-petals i:nth-child(n + 14) {
        display: none;
    }
}

/*
 * 使用者的系統關閉動畫（prefers-reduced-motion）時：
 * 原本做成完全靜止，但畫面看起來像特效卡住，所以改成「溫和版」——
 * 仍然飄落，但速度放慢為 1/2.5、取消左右搖擺，沒有快速的大幅動作。
 */
@media (prefers-reduced-motion: reduce) {
    .pt-petals i {
        animation: pt-petals-f calc(var(--t) * 2.5 / var(--k)) linear infinite;
        /* 延遲等比例放大，花瓣在畫面上的分布才會和正常模式一樣。 */
        animation-delay: calc(var(--dl) * 2.5);
    }
}
