/* =============================================================
   Reader Sidebar — barra lateral flutuante do leitor de capítulos
   Referência visual: toonlivre.net
   ============================================================= */

/* ---- Posicionamento base ---- */
.reader-sidebar {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    user-select: none;
}

/* ---- Botão individual (círculo escuro) ---- */
.reader-sidebar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(22, 22, 30, 0.90);
    color: #c8c8d8;
    cursor: pointer;
    transition: background 0.18s, color 0.18s, transform 0.15s;
    text-decoration: none;
    flex-shrink: 0;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}

.reader-sidebar__btn:hover {
    background: rgba(38, 38, 52, 0.97);
    color: #ffffff;
    transform: scale(1.08);
}

.reader-sidebar__btn.is-disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Botão de próximo capítulo (base da sidebar) */
.reader-sidebar__btn--next {
    margin-top: 4px;
}

/* ---- Botão recolher/expandir ---- */
.reader-sidebar__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(22, 22, 30, 0.90);
    color: #c8c8d8;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.45);
    flex-shrink: 0;
}

.reader-sidebar__toggle:hover {
    background: rgba(38, 38, 52, 0.97);
    color: #ffffff;
}

.reader-sidebar__toggle-icon {
    transition: transform 0.25s ease;
}

/* ---- Estado colapsado ---- */
.reader-sidebar.is-collapsed .reader-sidebar__body {
    display: none;
}

.reader-sidebar.is-collapsed .reader-sidebar__btn--next {
    display: none;
}

/* Gira o ícone quando expandido → aponta para direita (>) */
.reader-sidebar.is-collapsed .reader-sidebar__toggle-icon {
    transform: rotate(180deg);
}

/* ---- Corpo (lista de botões) ---- */
.reader-sidebar__body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* ---- Wrapper de item com popup ---- */
.reader-sidebar__item {
    position: relative;
}

/* ---- Popup genérico ---- */
.reader-sidebar__popup {
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    background: #16161e;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.55);
    overflow: hidden;
    z-index: 9100;
}

.reader-sidebar__popup--wide {
    width: 230px;
}

.reader-sidebar__popup-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255,255,255,0.04);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    font-size: 13px;
    font-weight: 600;
    color: #e0e0f0;
}

.reader-sidebar__popup-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: #888;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}

.reader-sidebar__popup-close:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

/* ---- Lista de capítulos no popup ---- */
.reader-sidebar__popup-list {
    max-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.reader-sidebar__popup-list::-webkit-scrollbar {
    width: 4px;
}

.reader-sidebar__popup-list::-webkit-scrollbar-track {
    background: transparent;
}

.reader-sidebar__popup-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.14);
    border-radius: 2px;
}

.reader-sidebar__chapter-link,
.reader-sidebar__popup-item {
    display: block;
    padding: 9px 14px;
    font-size: 13px;
    color: #b0b0c8;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-sidebar__chapter-link:last-child,
.reader-sidebar__popup-item:last-child {
    border-bottom: none;
}

.reader-sidebar__chapter-link:hover,
.reader-sidebar__popup-item:hover {
    background: rgba(255,255,255,0.06);
    color: #ffffff;
}

.reader-sidebar__chapter-link.is-active,
.reader-sidebar__chapter-link.is-current,
.reader-sidebar__popup-item.is-active,
.reader-sidebar__popup-item.is-current {
    color: var(--color-primary, #0cff8a);
    font-weight: 600;
    background: rgba(12,255,138,0.06);
}

/* ---- Popup de configurações ---- */
.reader-sidebar__settings {
    padding: 12px 14px;
}

.reader-sidebar__settings-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #666680;
    margin: 0 0 8px;
}

.reader-sidebar__settings-label + .reader-sidebar__settings-label {
    margin-top: 14px;
}

.reader-sidebar__settings-row {
    display: flex;
    gap: 6px;
}

.reader-sidebar__mode-btn {
    flex: 1;
    padding: 7px 0;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    background: transparent;
    color: #a0a0b8;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.reader-sidebar__mode-btn:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.reader-sidebar__mode-btn.is-active {
    background: var(--color-primary, #0cff8a);
    border-color: var(--color-primary, #0cff8a);
    color: #0a0a12;
    font-weight: 700;
}

.reader-sidebar__settings-row--zoom {
    align-items: center;
    justify-content: space-between;
}

.reader-sidebar__zoom-step {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    background: transparent;
    color: #c8c8d8;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.reader-sidebar__zoom-step:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.reader-sidebar__zoom-val {
    font-size: 13px;
    font-weight: 600;
    color: #e0e0f0;
    min-width: 42px;
    text-align: center;
}

/* ---- Responsivo: esconde em telas muito pequenas ---- */
@media (max-width: 480px) {
    .reader-sidebar {
        right: 8px;
    }

    .reader-sidebar__btn,
    .reader-sidebar__toggle {
        width: 38px;
        height: 38px;
    }

    .reader-sidebar__popup {
        width: 180px;
        right: calc(100% + 8px);
    }
}

/* =============================================================
   Barra inferior mobile — leitor de capítulos
   ============================================================= */
.reader-mobile-bar,
.reader-mobile-sheet,
.reader-mobile-sheet-backdrop {
    display: none;
}

@media (min-width: 0px) {
    /* Menu unificado: mobile, tablet, desktop e TV usam a mesma barra inferior. */
    .reader-sidebar {
        display: none !important;
    }

    body.single-chapter .chapter-reader-container {
        padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    }

    .reader-mobile-bar {
        position: fixed;
        left: 50%;
        right: auto;
        width: min(920px, calc(100vw - 16px));
        max-width: calc(100vw - max(16px, env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px)));
        transform: translateX(-50%);
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        z-index: 9998;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 5px;
        padding: 6px;
        background: rgba(5, 10, 20, .96);
        border: 1px solid rgba(119, 145, 190, .34);
        border-radius: 18px;
        box-shadow: 0 10px 35px rgba(0, 0, 0, .52);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
    }

    .reader-mobile-bar__item {
        min-width: 0;
        min-height: 56px;
        margin: 0;
        padding: 6px 2px 5px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 1px solid rgba(111, 139, 186, .38);
        border-radius: 12px;
        background: linear-gradient(180deg, rgba(17, 28, 48, .98), rgba(12, 21, 37, .98));
        color: #f2f5ff;
        text-decoration: none;
        font: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .reader-mobile-bar__item svg {
        width: 20px;
        height: 20px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
        flex: 0 0 auto;
    }

    .reader-mobile-bar__item svg circle {
        fill: currentColor;
        stroke: none;
    }

    .reader-mobile-bar__item span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 10px;
        line-height: 1.05;
        font-weight: 700;
        letter-spacing: .01em;
    }

    .reader-mobile-bar__item:active,
    .reader-mobile-bar__item.is-active {
        background: rgba(28, 48, 79, .98);
        border-color: rgba(152, 180, 230, .72);
        color: #fff;
    }

    .reader-mobile-bar__item.is-disabled {
        opacity: .34;
        pointer-events: none;
    }

    .reader-mobile-sheet-backdrop {
        position: fixed;
        inset: 0;
        z-index: 9998;
        display: block;
        background: rgba(0, 0, 0, .58);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }

    .reader-mobile-sheet-backdrop[hidden],
    .reader-mobile-sheet[hidden] {
        display: none !important;
    }

    .reader-mobile-sheet {
        position: fixed;
        left: 50%;
        right: auto;
        width: min(720px, calc(100vw - 16px));
        transform: translateX(-50%);
        bottom: calc(78px + env(safe-area-inset-bottom, 0px));
        z-index: 9999;
        display: block;
        max-height: min(68vh, 520px);
        padding: 8px 12px 14px;
        overflow: auto;
        color: #eef3ff;
        background: rgba(8, 14, 26, .985);
        border: 1px solid rgba(119, 145, 190, .34);
        border-radius: 18px;
        box-shadow: 0 -8px 36px rgba(0, 0, 0, .48);
        -webkit-overflow-scrolling: touch;
    }

    .reader-mobile-sheet__handle {
        width: 38px;
        height: 4px;
        margin: 1px auto 8px;
        border-radius: 999px;
        background: rgba(255,255,255,.22);
    }

    .reader-mobile-sheet__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 10px;
    }

    .reader-mobile-sheet__header strong {
        font-size: 15px;
    }

    .reader-mobile-sheet__header button {
        width: 34px;
        height: 34px;
        padding: 0;
        border: 1px solid rgba(255,255,255,.12);
        border-radius: 10px;
        background: rgba(255,255,255,.05);
        color: #fff;
        font-size: 24px;
        line-height: 1;
    }

    .reader-mobile-sheet__controls {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 7px;
        margin-bottom: 14px;
    }

    .reader-mobile-action {
        min-height: 42px;
        padding: 8px 5px;
        border: 1px solid rgba(111, 139, 186, .32);
        border-radius: 10px;
        background: rgba(16, 28, 47, .95);
        color: #eef3ff;
        font-size: 12px;
        font-weight: 600;
    }

    .reader-mobile-sheet__label {
        display: block;
        margin-bottom: 7px;
        color: #aebad0;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .07em;
    }

    .reader-mobile-sheet__chapter-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .reader-mobile-sheet__chapter-list a {
        padding: 9px 10px;
        overflow: hidden;
        border: 1px solid rgba(255,255,255,.09);
        border-radius: 9px;
        background: rgba(255,255,255,.035);
        color: #cdd6e7;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
    }

    .reader-mobile-sheet__chapter-list a.is-current {
        border-color: var(--color-primary, #0cff8a);
        color: var(--color-primary, #0cff8a);
    }

    body.reader-mobile-sheet-open {
        overflow: hidden;
    }
}

@media (max-width: 360px) {
    .reader-mobile-bar {
        left: 50%;
        right: auto;
        width: calc(100vw - 8px);
        bottom: max(4px, env(safe-area-inset-bottom, 0px));
        gap: 3px;
        padding: 4px;
        border-radius: 15px;
    }

    .reader-mobile-bar__item {
        min-height: 52px;
        border-radius: 10px;
    }

    .reader-mobile-bar__item span {
        font-size: 9px;
    }
}
