/* ===== 基础 ===== */
*, *::before, *::after { box-sizing: border-box; }
body, html {
    margin: 0; padding: 0;
    background: #0a0e12;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: #e2e8f0;
    min-height: 100vh;
    scrollbar-width: none;
}
body::-webkit-scrollbar { display: none; }

.xgd-nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; height: 48px;
    background: rgba(10, 14, 23, 0.95);
    border-bottom: 1px solid #1e293b;
    position: sticky; top: 0; z-index: 200;
}
.xgd-nav a { color: #94a3b8; text-decoration: none; font-size: 14px; }
.xgd-nav a:hover { color: #e2e8f0; }
.xgd-nav-logo { font-weight: 600; color: #e2e8f0 !important; }
.xgd-nav-links { display: flex; gap: 16px; }

.hidden { display: none !important; }

/* ===== 容器选择页 ===== */
.picker-view {
    min-height: calc(100vh - 48px);
    padding: 24px 20px 40px;
}
.picker-inner { max-width: 960px; margin: 0 auto; }
.picker-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.picker-subtitle { color: #6b7280; font-size: 0.85rem; margin-bottom: 8px; }
.picker-settings-link {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 0.85rem;
}
.picker-settings-link a {
    color: #60a5fa;
    text-decoration: none;
}
.picker-settings-link a:hover { text-decoration: underline; }
.loot-mode-hint {
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    font-size: 0.75rem;
}

.container-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.container-card {
    position: relative;
    display: flex; align-items: center; gap: 16px;
    padding: 12px 14px;
    border: 1px solid #334155;
    border-radius: 10px;
    background: #151819;
    cursor: pointer;
    overflow: hidden;
    text-align: left;
    transition: border-color 0.2s, background 0.2s;
}
.container-card::before {
    content: '';
    position: absolute; inset: 0;
    background: var(--card-gradient, transparent);
    pointer-events: none;
    border-radius: inherit;
}
.container-card:hover {
    border-color: #475569;
    background: #1a1f24;
}
.container-card img {
    width: 64px; height: 64px;
    border-radius: 8px; object-fit: cover;
    flex-shrink: 0; position: relative; z-index: 1;
}
.container-card span {
    font-size: 0.9rem; font-weight: 600;
    position: relative; z-index: 1;
}

/* ===== 开箱弹窗（对齐 shushu.fan） ===== */
.game-view {
    position: fixed;
    inset: 48px 0 0 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: auto;
}

.crate-overlay {
    position: fixed;
    inset: 48px 0 0 0;
    background: rgba(0, 0, 0, 0.82);
    z-index: 0;
}

.crate-modal {
    position: relative;
    z-index: 1;
    width: min(92vw, 720px);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    background: #1a1a1a url('../assets/images/ui/MiniGame_Sp_10.png') right bottom / cover no-repeat;
    border: 1px solid #333;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.crate-deco-top,
.crate-deco-bottom {
    position: absolute;
    left: 50%;
    width: 103.8%;
    transform: translateX(-50%);
    pointer-events: none;
    user-select: none;
}
.crate-deco-top { bottom: 86%; }
.crate-deco-bottom {
    top: 86%;
    transform: translateX(-50%) scaleX(1.038) scaleY(-1) scaleX(-1);
    opacity: 0.7;
}

.crate-deco-glitch {
    position: absolute;
    left: -2%;
    top: 8%;
    max-width: 22%;
    opacity: 0.8;
    pointer-events: none;
    animation: glitch 4s infinite;
}

@keyframes glitch {
    0%, 90%, 100% { clip-path: inset(0); transform: translate(0); opacity: 0.8; }
    91% { clip-path: inset(20% 0 30% 0); transform: translate(-4px, 2px); opacity: 0.6; }
    92% { clip-path: inset(50% 0 10% 0); transform: translate(4px, -2px); opacity: 0.9; }
    93% { clip-path: inset(10% 0 60% 0); transform: translate(-2px, 0); opacity: 0.5; }
    94% { clip-path: inset(40% 0 20% 0); transform: translate(3px, 1px); opacity: 0.7; }
    95% { clip-path: inset(0); transform: translate(0); opacity: 0.8; }
}

.crate-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #ddd;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    z-index: 10;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.crate-close-btn:hover { color: #fff; background: rgba(0, 0, 0, 0.75); }

.crate-modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px 16px;
    min-height: 320px;
}

.crate-panel {
    width: min-content;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* 标题栏红角装饰 */
.header-frame {
    position: relative;
    overflow: visible;
    margin-bottom: 0;
}
.hc {
    position: absolute;
    background: rgba(255, 53, 53, 0.7);
    z-index: 2;
    pointer-events: none;
}
.hc-bl { width: 8px; height: 2px; bottom: -2px; left: -2px; }
.hc-tl-v { width: 2px; height: 20px; bottom: -2px; left: -2px; }
.hc-tl-h { width: 2px; height: 20px; top: -2px; left: -2px; background: #FF3535; }
.hc-tr-h { width: 8px; height: 2px; top: -2px; right: -2px; }
.hc-tr-v { width: 2px; height: 20px; top: -2px; right: -2px; }
.hc-br-h { width: 2px; top: 16px; bottom: 16px; right: -2px; background: #FF3535; }
.hc-br-v { width: 2px; height: 20px; bottom: -2px; right: -2px; }
.hc-bl-h { width: 8px; height: 2px; bottom: -2px; right: -2px; }

.search-header {
    position: relative;
    height: 70px;
    background: #400000;
    overflow: hidden;
    display: flex;
    align-items: center;
}
.search-header-stripe {
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 8px,
        rgba(90, 26, 26, 0.8) 8px,
        rgba(90, 26, 26, 0.8) 11px
    );
    mask-image: linear-gradient(to right, black 15%, transparent 60%);
    -webkit-mask-image: linear-gradient(to right, black 15%, transparent 60%);
}
.search-header-inner {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 32px;
    flex: 1;
    z-index: 1;
}
.search-header p {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.crate-deco {
    position: absolute;
    right: 16px;
    bottom: 0;
    height: 50%;
    pointer-events: none;
    user-select: none;
}

/* 格子区域 */
.grid-wrap {
    background: #0C0E10;
    display: inline-block;
    padding: 8px;
    align-self: flex-start;
}

#item-grid-container {
    position: relative;
    display: grid;
}

.grid-cell {
    background: transparent;
    border: 1px solid #1e2428;
}

.item-block {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #323436;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
    transition: box-shadow 0.25s ease, left 0.15s ease, top 0.15s ease;
    touch-action: none;
    user-select: none;
    z-index: 1;
}
.item-block.revealed-done { overflow: visible; }
.item-block.draggable { cursor: grab; }
.item-block.draggable:active, .item-block.dragging { cursor: grabbing; }
.item-block.dragging {
    opacity: 0.92;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    z-index: 50;
    overflow: visible;
}
.item-block.dragging .item-face { transition: none; }
.item-block.auto-rotated {
    outline: 1px dashed rgba(251, 191, 36, 0.6);
    outline-offset: -1px;
}

.item-face {
    position: absolute;
    inset: 0;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    transition: transform 0.12s ease;
}
.item-block.revealed-done .item-face { display: block; }
.item-block.rotated .item-face {
    inset: auto;
    width: calc(100% * var(--grid-h) / var(--grid-w));
    height: calc(100% * var(--grid-w) / var(--grid-h));
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
}

.item-block.searching {
    animation: searchPulse 0.6s ease-in-out infinite alternate;
}
.item-block.searching::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    width: min(48px, 45%);
    height: min(48px, 45%);
    background: url('../assets/images/search.png') center/contain no-repeat;
    animation: search-orbit 1.2s linear infinite;
}

@keyframes searchPulse {
    from { box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.05); }
    to { box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.12); }
}

@keyframes search-orbit {
    from {
        transform: translate(-50%, -50%) rotate(0deg) translateX(5px) rotate(0deg);
    }
    to {
        transform: translate(-50%, -50%) rotate(360deg) translateX(5px) rotate(-360deg);
    }
}

/* 出货动效（对齐 shushu：白闪 + 边框扩散 + 物品弹入） */
@keyframes itemReveal {
    0% { opacity: 0; transform: scale(1.4); }
    100% { opacity: 1; transform: scale(1); }
}
@keyframes itemRevealRotated {
    0% { opacity: 0; transform: translate(-50%, -50%) rotate(90deg) scale(1.4); }
    100% { opacity: 1; transform: translate(-50%, -50%) rotate(90deg) scale(1); }
}
@keyframes bgFlash {
    0% { background: rgba(255, 255, 255, 0.5); }
    100% { background: transparent; }
}
@keyframes borderBurst {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}
@keyframes imgFlash {
    0% { filter: brightness(2.5); }
    100% { filter: brightness(1); }
}

.item-block.revealed .item-face {
    animation: itemReveal 0.15s ease-out;
}
.item-block.revealed.rotated .item-face {
    animation: itemRevealRotated 0.15s ease-out;
}
.item-block.revealed.reveal-burst .item-face {
    animation: itemReveal 0.15s ease-out, imgFlash 0.15s ease-out;
}
.item-block.revealed.reveal-burst.rotated .item-face {
    animation: itemRevealRotated 0.15s ease-out, imgFlash 0.15s ease-out;
}

.item-block.revealed.reveal-burst::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 9;
    pointer-events: none;
    animation: bgFlash 0.15s ease-out;
}
.item-block.revealed.reveal-burst::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    border: 2px solid var(--glow-color, #a855f7);
    box-shadow: 0 0 12px var(--glow-color, #a855f7), 0 0 24px var(--glow-color, #a855f7);
    animation: borderBurst 0.2s ease-out forwards;
}
.item-block.revealed.reveal-burst {
    z-index: 10;
    overflow: visible;
}

.item-block.drag-reject { animation: dragReject 0.3s ease; }
@keyframes dragReject {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.grid-cell.drop-valid { background: rgba(56, 190, 117, 0.25) !important; }
.grid-cell.drop-invalid { background: rgba(239, 68, 68, 0.2) !important; }

.item-name-tag {
    position: absolute;
    top: 4px;
    left: 4px;
    max-width: calc(100% - 8px);
    color: #aaa;
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s ease 0.1s;
}
.item-name-tag.visible { opacity: 1; }

/* 底部控制区 */
.crate-footer {
    padding: 0 16px 16px;
}

.drag-hint {
    margin: 0 0 8px;
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
}

.control-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(21, 24, 25, 0.9);
    border: 1px solid #323436;
    padding: 10px;
    margin: 0 0 12px;
    width: 100%;
}
.gain-box { width: 100%; text-align: center; margin-bottom: 10px; }
.gain-box p { margin: 0; font-size: 14px; }
#total-value-span { color: #fbbf24; font-weight: 700; font-size: 1.1rem; }

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    justify-content: center;
}
#search-btn, #refresh-btn, #pick-container-btn {
    min-width: 100px;
    height: 40px;
    padding: 0 14px;
    border: none;
    border-radius: 4px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: filter 0.2s, transform 0.1s;
}
#pick-container-btn { background: #4b5563; }
#pick-container-btn:hover { filter: brightness(1.12); }
.btn-settings-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 88px;
    height: 40px;
    padding: 0 12px;
    border-radius: 4px;
    background: #2d4a6f;
    color: #fff;
    font-size: 14px;
    text-decoration: none;
    transition: filter 0.2s;
}
.btn-settings-link:hover { filter: brightness(1.12); color: #fff; }
#search-btn { background: #38be75; width: 120px; }
#search-btn:hover { filter: brightness(1.1); }
#search-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#refresh-btn { background: #c45c5c; width: 120px; }
#refresh-btn:hover { filter: brightness(1.1); }
#search-btn:active, #refresh-btn:active, #pick-container-btn:active { transform: translateY(1px); }

.drop-rate-container {
    background: rgba(21, 24, 25, 0.9);
    border: 1px solid #323436;
    margin: 0 0 8px;
    overflow: hidden;
}
.drop-rate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    cursor: pointer;
    user-select: none;
}
.drop-rate-header h3 { margin: 0; font-size: 15px; }
.toggle-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.3s;
}
.toggle-btn.collapsed { transform: rotate(-90deg); }
#search-btn:active, #refresh-btn:active, #pick-container-btn:active { transform: translateY(1px); }

.loot-mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}
.loot-mode-btn {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #3f4a54;
    border-radius: 6px;
    background: #1a1f24;
    color: #94a3b8;
    font-size: 13px;
    cursor: pointer;
}
.loot-mode-btn.active {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.15);
    color: #e2e8f0;
}

.loot-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #3f4a54;
    border-radius: 6px;
    background: #0f1318;
    color: #e2e8f0;
    font-size: 13px;
    outline: none;
}
.loot-search:focus { border-color: #3b82f6; }

.loot-search-results {
    max-height: 160px;
    overflow-y: auto;
    margin: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.loot-search-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #2a3238;
    border-radius: 6px;
    background: #151a1f;
    color: #e2e8f0;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}
.loot-search-item:hover:not(.is-added) { border-color: #3b82f6; background: #1a2230; }
.loot-search-item.is-added { opacity: 0.45; cursor: default; }
.loot-search-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loot-search-size { color: #6b7280; font-size: 11px; }
.loot-search-empty, .custom-loot-empty { margin: 6px 0; font-size: 12px; color: #6b7280; text-align: center; }

.custom-loot-label { margin: 8px 0 6px; font-size: 12px; color: #9ca3af; }
.custom-loot-hint { margin: 8px 0 4px; font-size: 11px; color: #6b7280; text-align: center; }
.loot-selected-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 32px;
}
.loot-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px 4px 4px;
    border-radius: 6px;
    background: #1e2832;
    border: 1px solid #334155;
    font-size: 11px;
    max-width: 100%;
}
.loot-chip-rarity {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    flex-shrink: 0;
}
.rarity-green { background: rgba(34, 197, 94, 0.25); color: #4ade80; }
.rarity-blue { background: rgba(59, 130, 246, 0.25); color: #60a5fa; }
.rarity-purple { background: rgba(168, 85, 247, 0.25); color: #c084fc; }
.rarity-yellow { background: rgba(234, 179, 8, 0.25); color: #facc15; }
.rarity-red { background: rgba(239, 68, 68, 0.25); color: #f87171; }
.rarity-key { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.loot-chip-remove {
    border: none;
    background: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}
.loot-chip-remove:hover { color: #f87171; }
.btn-link {
    display: block;
    margin: 0 auto;
    border: none;
    background: none;
    color: #60a5fa;
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
}

.drop-rate-controls {
    max-height: 680px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 0 15px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.drop-rate-controls.collapsed { max-height: 0; padding: 0 15px; }
.drop-rate-item { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.drop-rate-item label { width: 90px; text-align: right; }
.drop-rate-item input[type="range"] { flex: 1; accent-color: #3b82f6; }
.drop-rate-item span { width: 36px; text-align: center; font-weight: 600; }
.divider { border: none; border-top: 1px solid #333; margin: 4px 0; }
.total-rate { text-align: center; font-size: 12px; color: #888; margin: 0; }
#reset-rates-btn {
    display: block;
    margin: 10px auto;
    width: 120px;
    height: 36px;
    background: #3286f3;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
}
.footer-note {
    font-size: 11px;
    text-align: center;
    color: #555;
    margin-top: 8px;
}
.footer-note a { color: #3b82f6; }

@media (max-width: 520px) {
    .crate-modal { width: 100%; max-height: calc(100dvh - 56px); }
    .crate-modal-body { padding: 44px 6px 6px; }
    .game-view { padding: 8px; inset: 48px 0 0 0; }
    .crate-footer { padding: 0 8px 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
    .button-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .button-group > * {
        width: 100%;
        min-width: 0;
        height: 44px;
        font-size: 13px;
    }
    #search-btn, #refresh-btn { width: 100%; }
    .xgd-nav-links { display: none; }
    .container-grid { grid-template-columns: 1fr; }
    .search-header p { font-size: 16px; }
    .search-header-inner { padding: 0 40px 0 16px; }
}
