/* ========== Root ========== */
.bk-root {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    overflow: hidden; /* clips to game container */
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Excalifont', sans-serif;
}

/* ========== Main Panel ========== */
.bk-panel {
    width: 640px;
    height: 510px;
    background: linear-gradient(180deg, #4A2E15 0%, #3E2418 100%);
    border-radius: 10px;
    border: 4px solid #2A1A0A;
    box-shadow:
        0 0 0 1px rgba(255, 200, 100, 0.08),
        0 12px 40px rgba(0, 0, 0, 0.7),
        inset 0 1px 0 rgba(255, 200, 100, 0.06);
    display: flex;
    flex-direction: column;
    overflow: visible; /* Fix #6: allow tooltips to extend outside panel */
    position: relative;
}

/* Wood grain texture */
.bk-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        repeating-linear-gradient(
            87deg,
            transparent,
            transparent 6px,
            rgba(0, 0, 0, 0.04) 6px,
            rgba(0, 0, 0, 0.04) 7px
        ),
        repeating-linear-gradient(
            93deg,
            transparent,
            transparent 11px,
            rgba(255, 200, 100, 0.02) 11px,
            rgba(255, 200, 100, 0.02) 12px
        );
    pointer-events: none;
    z-index: 0;
}

/* ========== Category Tabs ========== */
.bk-tabs {
    display: flex;
    gap: 2px;
    padding: 10px 16px 0;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 3px solid #2A1A0A;
    position: relative;
    z-index: 10;
    flex-wrap: wrap;
    max-height: 68px; /* Fix #9: cap at ~2 rows to prevent crushing shelf area */
    overflow: hidden;
}

.bk-tab {
    padding: 6px 16px;
    font-size: 13px;
    color: rgba(255, 220, 160, 0.5);
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    border: 1px solid transparent;
    border-bottom: none;
    transition: all 0.2s ease;
    user-select: none;
    font-family: 'Pixel32_CN', 'Excalifont', sans-serif;
    position: relative;
    top: 3px;
    white-space: nowrap;
}

.bk-tab:hover {
    color: rgba(255, 220, 160, 0.85);
    background: rgba(255, 200, 100, 0.06);
}

.bk-tab-active {
    color: #FFD88A;
    background: linear-gradient(180deg, rgba(255, 200, 100, 0.12), transparent);
    border-color: rgba(255, 200, 100, 0.15);
    text-shadow: 0 0 10px rgba(255, 200, 100, 0.3);
}

/* ========== Shelf Area ========== */
.bk-shelf-area {
    flex: 1;
    padding: 40px 20px 30px; /* Fix #6: extra bottom padding for tooltip space */
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
    overflow: visible;
}

/* Side panels (left & right wooden edges) */
.bk-shelf-area::before,
.bk-shelf-area::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    width: 12px;
    background: linear-gradient(90deg, #3E2418, #5C3A1E 50%, #3E2418);
    z-index: 5;
    pointer-events: none;
}
.bk-shelf-area::before { left: 4px; }
.bk-shelf-area::after  { right: 4px; }

/* ========== Single Shelf ========== */
.bk-shelf {
    display: flex;
    flex-direction: column;
}

.bk-book-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-evenly;
    padding: 0 20px;
    min-height: 138px;
}

/* ========== Individual Book ========== */
.bk-book {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.bk-book:hover {
    transform: translateY(-10px) rotate(-2deg);
    z-index: 10;
}

.bk-cover {
    width: 90px;
    height: 128px;
    object-fit: cover;
    border-radius: 2px 5px 5px 2px;
    display: block;
    box-shadow:
        3px 3px 8px rgba(0, 0, 0, 0.6),
        -1px 0 3px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.5);
}

/* Spine highlight */
.bk-book::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg,
        rgba(255, 255, 255, 0.2),
        rgba(255, 255, 255, 0.05) 50%,
        rgba(0, 0, 0, 0.15));
    border-radius: 2px 0 0 2px;
    pointer-events: none;
    z-index: 1;
}

/* ========== Tooltip (below book) ========== */
.bk-tooltip {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 8, 3, 0.95);
    color: #FFD88A;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    border: 1px solid rgba(255, 200, 100, 0.25);
    font-family: 'Pixel32_CN', 'Excalifont', sans-serif;
    z-index: 30;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* Arrow pointing up */
.bk-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: rgba(15, 8, 3, 0.95);
}

.bk-book:hover .bk-tooltip {
    opacity: 1;
}

/* ========== Shelf Board (wooden plank) ========== */
.bk-board {
    height: 14px;
    background: linear-gradient(180deg,
        #7A5233 0%,
        #6B4226 20%,
        #5C3A1E 60%,
        #4A2E15 100%);
    border-radius: 0 0 3px 3px;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 200, 100, 0.12),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3);
    position: relative;
    margin: 0 12px;
}

/* Front lip of shelf */
.bk-board::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 0; right: 0;
    height: 6px;
    background: linear-gradient(180deg, #4A2E15, #3A2210);
    border-radius: 0 0 3px 3px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* ========== Pagination ========== */
.bk-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 0 16px;
    position: relative;
    z-index: 1;
}

.bk-page-btn {
    width: 36px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 200, 100, 0.08);
    border: 1px solid rgba(255, 200, 100, 0.2);
    border-radius: 4px;
    color: #FFD88A;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.bk-page-btn:hover {
    background: rgba(255, 200, 100, 0.18);
    border-color: rgba(255, 200, 100, 0.4);
    transform: scale(1.05);
}

.bk-page-disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.bk-page-label {
    color: rgba(255, 220, 160, 0.7);
    min-width: 50px;
    text-align: center;
    font-family: 'PressStart2P', monospace;
    font-size: 10px;
}

/* ========== Empty / Loading state ========== */
.bk-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 220, 160, 0.4);
    font-size: 14px;
    padding: 40px;
}

/* ========== Close Button ========== */
.bk-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 20px;
    color: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    font-family: sans-serif;
    z-index: 20;
}

.bk-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}
