/* =========================================================
   상자 시뮬레이터
   ========================================================= */
.lb-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 16px;
    border-radius: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
}

.lb-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.lb-tab.active {
    background: var(--card-bg);
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.lb-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.lb-layout[hidden],
.lb-stats[hidden] {
    display: none;
}

/* 상자 찾기 */
.lb-finder {
    position: sticky;
    top: calc(var(--header-height) + 16px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - var(--header-height) - 40px);
    min-height: 300px;
}

.lb-search {
    position: relative;
}

.lb-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.lb-search input {
    width: 100%;
    box-sizing: border-box;
    min-height: 44px;
    padding-left: 40px;
    border-radius: 10px;
}

.lb-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
}

.lb-list-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 2px 2px 4px;
}

.lb-list-empty {
    padding: 20px 8px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.lb-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text-main);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.lb-list-item:hover {
    border-color: var(--primary-color);
}

.lb-list-item.active {
    border-color: var(--primary-color);
    background: rgba(var(--primary-color-rgb), 0.1);
}

.lb-list-item img {
    flex-shrink: 0;
    border-radius: 8px;
}

.lb-list-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.lb-list-name {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-list-sub {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 선택한 상자 */
.lb-main {
    min-width: 0;
}

.lb-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 320px;
    border: 1px dashed var(--border-color);
    border-radius: 14px;
    color: var(--text-muted);
}

.lb-empty i {
    font-size: 36px;
    opacity: 0.5;
}

.lb-box[hidden],
.lb-result[hidden] {
    display: none;
}

.lb-box-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-color);
}

.lb-box-head img {
    border-radius: 12px;
    background: rgba(var(--primary-color-rgb), 0.08);
}

.lb-box-info h2 {
    margin: 0;
    font-size: 19px;
}

.lb-box-info .text-muted {
    font-size: 13px;
    margin-top: 2px;
}

.lb-open-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 12px 0;
}

.lb-open-btn {
    min-height: 46px;
    border: 1px solid var(--primary-color);
    border-radius: 10px;
    background: rgba(var(--primary-color-rgb), 0.08);
    color: var(--primary-color);
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.lb-open-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: #fff;
}

.lb-open-btn:disabled,
.lb-reopen:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* 개봉 결과 (참고 이미지 스타일) */
.lb-result {
    --lb-card: #172031;
    --lb-card-border: #2b3a55;
    --lb-row: #1f2c45;
    --lb-row-border: #31446a;
    --lb-rare-row: #3a2740;
    --lb-rare-border: #6d4a78;
    --lb-uncommon-row: #2a2a48;
    --lb-uncommon-border: #4f4f86;
    --lb-pill: #141b29;
    --lb-gold: #e2bd62;
    --lb-text: #eef2f8;
    max-width: 460px;
    margin: 0 auto 14px;
}

[data-theme="light"] .lb-result {
    --lb-card: #f4f6fb;
    --lb-card-border: #d7deea;
    --lb-row: #e6ecf7;
    --lb-row-border: #c8d4ea;
    --lb-rare-row: #f2e4f1;
    --lb-rare-border: #d4a8cf;
    --lb-uncommon-row: #e8e6f8;
    --lb-uncommon-border: #c3bfeb;
    --lb-pill: #ffffff;
    --lb-gold: #a77a14;
    --lb-text: #1e293b;
}

.lb-reopen {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 50px;
    margin-bottom: 12px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(180deg, #e6c879, #d2ab55);
    color: #2b2210;
    font-family: inherit;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(210, 171, 85, 0.3);
}

.lb-reopen:hover:not(:disabled) {
    filter: brightness(1.05);
}

.lb-result-card {
    position: relative;
    padding: 18px 16px 14px;
    border: 1px solid var(--lb-card-border);
    border-radius: 18px;
    background: var(--lb-card);
    color: var(--lb-text);
}

.lb-result-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 12px;
}

.lb-result-icon img {
    display: block;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--lb-row-border);
    background: var(--lb-row);
}

.lb-result-x {
    font-size: 20px;
    font-weight: 700;
    opacity: 0.7;
}

.lb-result-count {
    padding: 6px 16px;
    border-radius: 10px;
    background: var(--lb-pill);
    color: var(--lb-gold);
    font-size: 22px;
    font-weight: 800;
}

.lb-result-title {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 10px;
    background: var(--lb-pill);
    text-align: center;
    font-size: 15px;
    font-weight: 700;
}

.lb-result-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lb-result-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border: 1px solid var(--lb-row-border);
    border-radius: 10px;
    background: var(--lb-row);
}

.lb-result-row.tier-rare {
    background: var(--lb-rare-row);
    border-color: var(--lb-rare-border);
}

.lb-result-row.tier-uncommon {
    background: var(--lb-uncommon-row);
    border-color: var(--lb-uncommon-border);
}

.lb-row-icon img {
    display: block;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.08);
}

.lb-row-name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-row-count {
    flex-shrink: 0;
    min-width: 64px;
    padding: 4px 10px;
    border-radius: 8px;
    background: var(--lb-pill);
    color: var(--lb-gold);
    text-align: center;
    font-weight: 800;
}

.lb-result-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
    margin-top: 10px;
    font-size: 12px;
    opacity: 0.85;
}

.tier-text-rare {
    color: #d68be0;
}

[data-theme="light"] .tier-text-rare {
    color: #9b3fa6;
}

.tier-text-uncommon {
    color: #8f8ef0;
}

.lb-skip {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    border: 1px solid var(--lb-row-border);
    border-radius: 999px;
    background: var(--lb-pill);
    color: var(--lb-text);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}

/* 하나씩 나타나는 애니메이션 (희귀한 것부터) */
.lb-result-card.is-animating .lb-result-row {
    opacity: 0;
    animation: lbRowIn 0.36s ease forwards;
    animation-delay: calc(var(--i) * 110ms + 250ms);
}

.lb-result-card.is-animating .lb-result-row.tier-rare {
    animation-name: lbRareIn;
    animation-duration: 0.6s;
}

.lb-result-card.is-done .lb-result-row {
    opacity: 1;
    animation: none;
}

.lb-result-card .lb-result-row.tier-rare {
    box-shadow: 0 0 0 1px rgba(214, 139, 224, 0.25), 0 0 16px rgba(214, 139, 224, 0.25);
}

@keyframes lbRowIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@keyframes lbRareIn {
    0% { opacity: 0; transform: scale(0.92); box-shadow: 0 0 0 rgba(214, 139, 224, 0); }
    60% { opacity: 1; transform: scale(1.03); box-shadow: 0 0 28px rgba(214, 139, 224, 0.6); }
    100% { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .lb-result-card.is-animating .lb-result-row {
        opacity: 1;
        animation: none;
    }
}

/* 확률표 */
.lb-odds {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-color);
}

.lb-odds summary {
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.lb-odds-body {
    max-height: 420px;
    overflow-y: auto;
    padding: 0 10px 10px;
}

.lb-odds-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px 64px;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}

.lb-odds-head {
    position: sticky;
    top: 0;
    border-top: none;
    background: var(--bg-color);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
}

.lb-odds-name {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-odds-name img {
    flex-shrink: 0;
    border-radius: 6px;
}

.lb-odds-pct,
.lb-odds-actual {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.lb-odds-row.tier-rare .lb-odds-pct {
    color: #c06ecc;
    font-weight: 700;
}

.lb-odds-row.tier-uncommon .lb-odds-pct {
    color: #7a79e0;
    font-weight: 700;
}

.lb-odds-actual {
    color: var(--text-muted);
}

.lb-error {
    padding: 14px;
    color: #dc2626;
    font-size: 13px;
}

/* 통계 */
.lb-stats-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.lb-stat-total {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--text-muted);
}

.lb-stat-total strong {
    font-size: 24px;
    color: var(--text-main);
}

.lb-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.lb-stat-card {
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-color);
    min-width: 0;
}

.lb-stat-wide {
    grid-column: 1 / -1;
}

.lb-stat-card h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.lb-stat-card h3 .text-muted {
    font-size: 12px;
    font-weight: 400;
}

.lb-stat-card h3 i {
    color: var(--primary-color);
}

.lb-stat-bag,
.lb-rare-row,
.lb-lucky-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 4px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.lb-stat-bag:hover,
.lb-rare-row:hover,
.lb-lucky-row:hover {
    background: rgba(var(--primary-color-rgb), 0.06);
}

.lb-stat-bag .rank {
    width: 18px;
    font-weight: 800;
    color: var(--primary-color);
    text-align: center;
}

.lb-stat-bag .name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-stat-bag .bar {
    width: 80px;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    overflow: hidden;
}

.lb-stat-bag .bar span {
    display: block;
    height: 100%;
    background: var(--primary-color);
}

.lb-stat-bag .value {
    width: 54px;
    text-align: right;
    font-weight: 700;
}

.lb-rare-row .txt {
    flex: 1;
    min-width: 0;
    line-height: 1.5;
}

.lb-rare-row .meta {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
}

.lb-lucky-head,
.lb-lucky-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 90px 90px;
    gap: 8px;
}

.lb-lucky-head {
    padding: 0 4px 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.lb-lucky-row .name {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-lucky-row .up {
    color: #16a34a;
    font-weight: 700;
}

.lb-lucky-row .down {
    color: var(--text-muted);
}

/* 반응형 */
@media (max-width: 1024px) {
    .lb-layout {
        grid-template-columns: 1fr;
    }

    .lb-finder {
        position: static;
        max-height: none;
        min-height: 0;
    }

    .lb-list {
        max-height: 320px;
    }

    .lb-box {
        scroll-margin-top: calc(var(--header-height) + 10px);
    }
}

@media (max-width: 600px) {
    .lb-open-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .lb-stats-grid {
        grid-template-columns: 1fr;
    }

    .lb-odds-row,
    .lb-lucky-head,
    .lb-lucky-row {
        grid-template-columns: minmax(0, 1fr) 64px 56px;
    }

    .lb-stat-bag .bar {
        display: none;
    }

    .lb-rare-row {
        flex-wrap: wrap;
    }
}

/* 상자 종류 필터 */
.lb-cats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.lb-cat[data-cat="all"] {
    grid-column: 1 / -1;
}

/* 한 줄 목록으로 바뀌는 태블릿 폭: 다섯 개를 한 줄에 */
@media (min-width: 640px) and (max-width: 1024px) {
    .lb-cats {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .lb-cat[data-cat="all"] {
        grid-column: auto;
    }
}

.lb-cat {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.lb-cat i {
    font-size: 12px;
}

.lb-cat-n {
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--hover-bg, rgba(127, 127, 127, 0.12));
    font-size: 11px;
    font-weight: 600;
}

.lb-cat-n:empty {
    display: none;
}

.lb-cat:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.lb-cat.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: #fff;
}

.lb-cat.active .lb-cat-n {
    background: rgba(255, 255, 255, 0.22);
}

.lb-cat:disabled {
    opacity: 0.45;
    cursor: default;
}

.lb-cat:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.lb-more {
    flex-shrink: 0;
    width: 100%;
    min-height: 40px;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.lb-more:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 한 줄 화면에서 목록으로 돌아가는 버튼 (넓은 화면에서는 목록이 옆에 있어 숨김) */
.lb-back {
    display: none;
    flex-shrink: 0;
    align-self: flex-start;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.lb-back:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.lb-finder {
    scroll-margin-top: calc(var(--header-height) + 10px);
}

@media (max-width: 1024px) {
    .lb-back {
        display: flex;
    }
}

.lb-empty[hidden],
.lb-box[hidden] {
    display: none;
}

.lb-back {
    width: fit-content;
    margin: 0 0 10px auto;
}

.lb-empty-narrow {
    display: none;
}

@media (max-width: 1024px) {
    .lb-empty-wide {
        display: none;
    }

    .lb-empty-narrow {
        display: block;
    }
}

/* 희귀 획득 줄: 긴 이름이 날짜와 겹치지 않게 */
.lb-rare-row {
    text-align: left;
}

.lb-rare-row .txt {
    white-space: normal;
    overflow-wrap: anywhere;
}

.lb-rare-row .meta {
    margin-left: 6px;
    white-space: nowrap;
    text-align: right;
}

/* ---------- 검색어 지우기 버튼 (브라우저 기본 X 대신) ---------- */
#lbSearch::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.lb-search input {
    padding-right: 44px;
}

.lb-search-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(127, 127, 127, 0.18);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.lb-search-clear[hidden] {
    display: none;
}

.lb-search-clear:hover {
    background: var(--primary-color);
    color: #fff;
}

.lb-search-clear:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 검색 아이콘 (왼쪽) 위치는 그대로, 지우기 버튼의 i 는 위의 absolute 규칙을 따르지 않게 */
.lb-search .lb-search-clear i {
    position: static;
    transform: none;
    color: inherit;
}

/* ---------- 다시 열기 버튼: 결과 카드 아래쪽에 카드와 같은 색 계열로 ---------- */
.lb-result-card .lb-reopen {
    width: 100%;
    min-height: 44px;
    margin: 14px 0 0;
    border: 1px solid var(--lb-gold);
    border-radius: 12px;
    background: rgba(226, 189, 98, 0.1);
    color: var(--lb-gold);
    font-size: 15px;
    font-weight: 700;
    box-shadow: none;
    transition: background 0.15s, color 0.15s;
}

.lb-result-card .lb-reopen:hover:not(:disabled) {
    background: var(--lb-gold);
    color: #2b2210;
    filter: none;
}

.lb-result-card .lb-reopen:focus-visible {
    outline: 2px solid var(--lb-gold);
    outline-offset: 2px;
}

/* ---------- 선택된 종류 버튼: 마우스를 올려도 글자가 보이게 ---------- */
.lb-cat.active:hover:not(:disabled) {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: #fff;
    filter: brightness(1.1);
}
