/**
 * 頭像框系統（avatar frames）
 * 用法：把圓形頭像 <img> 包進 .avatar-framed 再加 .frame-<id>
 * <span class="avatar-framed frame-sakura"><img ...></span>
 * 純 CSS 繪製，無圖片資源。
 */

.avatar-framed {
    position: relative;
    display: inline-block;
    border-radius: 50%;
    line-height: 0;
}

.avatar-framed > img {
    border-radius: 50%;
    display: block;
}

/* 框本體：蓋在頭像外緣的圓環 */
.avatar-framed::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}

/* 無框時不顯示環 */
.avatar-framed.frame-none::before {
    display: none;
}

/* ============ 成就框：銅 / 銀 / 金 ============ */

.avatar-framed.frame-bronze::before {
    background:
        conic-gradient(from 210deg,
            #8c5a2b, #d9954a 25%, #6e4420 50%, #c98940 75%, #8c5a2b);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    box-shadow: inset 0 0 4px rgba(60, 35, 10, 0.6);
}

.avatar-framed.frame-silver::before {
    background:
        conic-gradient(from 150deg,
            #9ba3ad, #f2f5f8 20%, #7d868f 45%, #e4e9ee 70%, #aab2bb 90%, #9ba3ad);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    box-shadow: inset 0 0 4px rgba(40, 48, 58, 0.5);
}

.avatar-framed.frame-gold::before {
    background:
        conic-gradient(from 120deg,
            #a5772a, #ffe08a 18%, #c9962f 40%, #fff3c4 60%, #b98a2e 80%, #a5772a);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    box-shadow:
        inset 0 0 5px rgba(120, 80, 10, 0.55),
        0 0 6px rgba(255, 205, 90, 0.45);
}

/* ============ 商店框 ============ */

/* 鳥居朱紅框：朱漆質感 */
.avatar-framed.frame-torii::before {
    background:
        linear-gradient(160deg,
            #d8453a 0%, #b32821 35%, #8f1d17 70%, #b32821 100%);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    box-shadow:
        inset 0 2px 3px rgba(255, 160, 140, 0.5),
        inset 0 -2px 4px rgba(70, 10, 6, 0.7);
}

/* 櫻吹雪框：粉色環 + 三片飄落花瓣 */
.avatar-framed.frame-sakura::before {
    background:
        conic-gradient(from 30deg,
            #f8a8c0, #fdd7e2 25%, #ef8dab 55%, #fce4ec 80%, #f8a8c0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
    box-shadow: 0 0 6px rgba(244, 143, 177, 0.5);
}

/* 花瓣共用形狀（半圓+尖角的花瓣輪廓） */
.avatar-framed.frame-sakura::after,
.avatar-framed.frame-sakura .frame-petal,
.avatar-framed.frame-sakura .frame-petal::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: #f48fb1;
    border-radius: 80% 0 55% 55%;
    pointer-events: none;
    z-index: 3;
    opacity: 0.9;
}

.avatar-framed.frame-sakura::after {
    top: -6px;
    left: 18%;
    background: #f8bbd0;
    animation: frame-petal-fall 6s ease-in-out infinite;
}

.avatar-framed.frame-sakura .frame-petal {
    top: -2px;
    right: 8%;
    width: 7px;
    height: 7px;
    animation: frame-petal-fall 6s ease-in-out 2s infinite;
}

.avatar-framed.frame-sakura .frame-petal::after {
    top: 20px;
    right: -14px;
    width: 6px;
    height: 6px;
    background: #ec6f9c;
    animation: frame-petal-fall 6s ease-in-out 4s infinite;
}

@keyframes frame-petal-fall {
    0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    15%  { opacity: 0.95; }
    70%  { opacity: 0.85; }
    100% { transform: translate(-10px, 105%) rotate(220deg); opacity: 0; }
}

/* 金箔流光框：金環 + 掃光 */
.avatar-framed.frame-goldleaf::before {
    background:
        conic-gradient(from 0deg,
            #b8860b, #ffd700 20%, #daa520 45%, #fff8dc 65%, #cfa227 85%, #b8860b);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    box-shadow:
        inset 0 0 5px rgba(130, 90, 10, 0.5),
        0 0 8px rgba(255, 215, 0, 0.55);
}

/* 掃光層：亮帶掃過金環 */
.avatar-framed.frame-goldleaf::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 3;
    background:
        conic-gradient(from 0deg,
            transparent 0deg, transparent 300deg,
            rgba(255, 255, 235, 0.95) 330deg, transparent 360deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
    animation: frame-goldleaf-sweep 2.5s linear infinite;
}

@keyframes frame-goldleaf-sweep {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ============ 深色主題微調 ============ */

[data-theme="dark"] .avatar-framed.frame-silver::before {
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.6), 0 0 5px rgba(220, 228, 236, 0.35);
}

[data-theme="dark"] .avatar-framed.frame-torii::before {
    box-shadow:
        inset 0 2px 3px rgba(255, 160, 140, 0.4),
        inset 0 -2px 4px rgba(0, 0, 0, 0.8),
        0 0 6px rgba(216, 69, 58, 0.4);
}

[data-theme="dark"] .avatar-framed.frame-sakura::before {
    box-shadow: 0 0 8px rgba(244, 143, 177, 0.65);
}

/* ============ 頭像框選擇區（profile modal） ============ */

.frames-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e5dcc9;
    text-align: left;
}

.frames-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.frames-section-title {
    margin: 0;
    font-size: 1rem;
    color: #5d4037;
}

.frames-saisen {
    font-size: 0.85rem;
    color: #b8860b;
    font-weight: bold;
}

.frames-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.frame-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.02);
    transition: border-color 0.15s, background 0.15s;
}

.frame-cell:hover {
    background: rgba(198, 40, 40, 0.05);
}

.frame-cell.equipped {
    border-color: #c62828;
    background: rgba(198, 40, 40, 0.07);
}

.frame-cell.locked {
    opacity: 0.55;
    cursor: not-allowed;
}

.frame-cell .frame-preview img {
    width: 44px;
    height: 44px;
    object-fit: cover;
}

.frame-cell .frame-label {
    font-size: 0.72rem;
    color: #444;
    text-align: center;
    line-height: 1.2;
}

.frame-cell .frame-state {
    font-size: 0.68rem;
    color: #777;
    min-height: 0.9em;
    line-height: 1.2;
}

.frame-cell.equipped .frame-state {
    color: #c62828;
    font-weight: bold;
}

.frame-buy-btn {
    font-size: 0.7rem;
    padding: 2px 10px;
    border-radius: 8px;
    border: 1px solid #c62828;
    background: #fff;
    color: #c62828;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.frame-buy-btn:hover {
    background: #c62828;
    color: #fff;
}

.frames-msg {
    margin: 8px 0 0;
    font-size: 0.75rem;
    color: #c62828;
    min-height: 1em;
}

@media (max-width: 480px) {
    .frames-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

[data-theme="dark"] .frames-section {
    border-top-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .frames-section-title {
    color: #e0d5c5;
}

[data-theme="dark"] .frame-cell {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .frame-cell .frame-label {
    color: #ddd;
}

[data-theme="dark"] .frame-cell .frame-state {
    color: #aaa;
}

[data-theme="dark"] .frame-buy-btn {
    background: transparent;
    color: #ef9a9a;
    border-color: #ef9a9a;
}

/* ============ 動態效果減量 ============ */

@media (prefers-reduced-motion: reduce) {
    .avatar-framed.frame-goldleaf::after,
    .avatar-framed.frame-sakura::after,
    .avatar-framed.frame-sakura .frame-petal,
    .avatar-framed.frame-sakura .frame-petal::after {
        animation: none;
    }
    /* 花瓣停在可見狀態 */
    .avatar-framed.frame-sakura::after,
    .avatar-framed.frame-sakura .frame-petal,
    .avatar-framed.frame-sakura .frame-petal::after {
        opacity: 0.9;
    }
}

.frames-msg.flash { animation: frames-msg-flash .8s ease; }
@keyframes frames-msg-flash {
    0%, 60% { color: #dc2626; transform: scale(1.06); }
    100% { transform: scale(1); }
}

.frame-buy-btn.confirming {
    background: #b91c1c;
    color: #fff;
    animation: frames-msg-flash .4s ease;
}
