:root {
    --chapter-bar-bg: #ffffff;
    --chapter-bar-border: rgba(15, 23, 42, 0.08);
    --chapter-bar-shadow: 0 20px 45px rgba(15, 23, 42, 0.15);
    --chapter-bar-text: #0f172a;
    --chapter-bar-muted: #6b7280;
    --chapter-highlight: #1d4ed8;
}

.chapter-floating-shell {
    position: fixed;
    left: 50%;
    bottom: clamp(12px, 3vw, 28px);
    transform: translateX(-50%);
    width: min(520px, 94vw);
    z-index: 999;
    font-family: "Be Vietnam Pro", "Segoe UI", sans-serif;
    color: var(--chapter-bar-text);
}

.chapter-floating-bar {
    display: grid;
    grid-template-columns: 1fr minmax(0, 1.6fr) 1fr;
    gap: 0.35rem;
    background: var(--chapter-bar-bg);
    border-radius: 999px;
    border: 1px solid var(--chapter-bar-border);
    box-shadow: var(--chapter-bar-shadow);
    padding: 0.35rem;
}

.chapter-floating-bar button {
    border: none;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    font: 600 0.9rem/1.1 inherit;
    padding: 0.65rem 0.6rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: background 0.2s ease, color 0.2s ease;
}

.chapter-floating-bar button:is(:hover, :focus-visible) {
    background: rgba(15, 23, 42, 0.08);
    outline: none;
}

.chapter-floating-bar button[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
}

.chapter-button {
    justify-content: space-between;
    padding-inline: 1rem;
    background: rgba(15, 23, 42, 0.04);
}

.chapter-button__label {
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-button__icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
}

.chapter-floating-shell__overlays {
    position: relative;
    width: 100%;
}

.chapter-picker {
    position: absolute;
    left: 0;
    bottom: calc(100% + 12px);
    width: 100%;
    max-height: 320px;
    background: #fff;
    border-radius: 16px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 -18px 45px rgba(15, 23, 42, 0.25);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    padding: 0.85rem;
    z-index: 10;
}

.chapter-picker.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chapter-picker__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.chapter-picker__head button {
    font-size: 0.85rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: transparent;
    cursor: pointer;
}

.chapter-picker__story {
    display: block;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.chapter-picker__story a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}

.chapter-picker__story small {
    display: block;
    font-size: 0.78rem;
    color: var(--chapter-bar-muted);
    font-weight: 500;
}

.chapter-picker__story svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--chapter-bar-muted);
}

.chapter-picker__list {
    max-height: 220px;
    overflow-y: auto;
    padding-right: 0.4rem;
}

.chapter-picker__list button {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    text-align: left;
    padding: 0.55rem 0.65rem;
    border-radius: 12px;
    border: none;
    background: transparent;
    font: 500 0.9rem/1.3 inherit;
    color: var(--chapter-bar-text);
    cursor: pointer;
    transition: background 0.15s ease;
}

.chapter-picker__list button span.meta {
    font-size: 0.78rem;
    color: var(--chapter-bar-muted);
}

.chapter-picker__list button:is(:hover, :focus-visible) {
    background: rgba(29, 78, 216, 0.08);
    outline: none;
}

.chapter-picker__list button.is-active {
    background: rgba(29, 78, 216, 0.14);
    color: var(--chapter-highlight);
    font-weight: 600;
}

/* Loading state */
.chapter-floating-shell.is-loading .chapter-button__label::after {
    content: '...';
    animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Responsive */
@media (max-width: 520px) {
    .chapter-floating-shell {
        width: min(480px, 96vw);
    }

    .chapter-floating-bar {
        padding: 0.25rem;
    }

    .chapter-floating-bar button {
        font-size: 0.8rem;
        padding: 0.55rem 0.35rem;
    }

    .chapter-button__label {
        font-size: 0.9rem;
    }
}
