/* -------------------------------------------------------------------------
   Reading view layout
------------------------------------------------------------------------- */

#reading-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* -------------------------------------------------------------------------
   Generation progress indicator
------------------------------------------------------------------------- */

.generation-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: #f2f2f7;
    border-radius: 10px;
    color: #6e6e73;
    font-size: 15px;
}

.progress-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #c7c7cc;
    border-top-color: #007aff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* -------------------------------------------------------------------------
   Chunk text display
------------------------------------------------------------------------- */

.chunks-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 200px; /* clearance for sticky audio bar + nav row */
    max-width: 680px;      /* comfortable reading width */
    margin: 0 auto;
    width: 100%;
}

.chunk-div {
    padding: 14px 18px;
    border-radius: 10px;
    line-height: 1.85;
    font-size: 1.05rem;
    color: #3a3a3c;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}

.chunk-div[dir="rtl"] {
    text-align: right;
    line-height: 2.1;
    font-size: 1.08rem;
    border-left: none;
    border-right: 3px solid transparent;
}

.chunk-div:hover {
    background: #f5f5f7;
}

.chunk-div.placeholder {
    color: #aeaeb2;
    cursor: default;
}

/* Active chunk: stronger highlight so it's unmissable */
.chunk-div.active-chunk {
    background: #e8f1ff;
    color: #1d1d1f;
    border-left-color: #007aff;
}

.chunk-div[dir="rtl"].active-chunk {
    border-left-color: transparent;
    border-right-color: #007aff;
}

/* Non-active chunks while audio is playing: dim slightly */
.chunks-container.playing .chunk-div:not(.active-chunk) {
    color: #8e8e93;
}

.chunks-container.playing .chunk-div:not(.active-chunk):hover {
    color: #3a3a3c;
}

/* -------------------------------------------------------------------------
   Sticky audio bar
------------------------------------------------------------------------- */

.audio-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(0,0,0,0.07);
    box-shadow: 0 -2px 24px rgba(0,0,0,0.06);
    padding: 12px 24px 18px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.audio-bar audio {
    display: none;
}

/* Nav row: تبدیل جدید / کتابخانه */
.player-nav {
    width: 100%;
    max-width: 560px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 8px;
}

.player-nav-btn {
    background: #f2f2f7;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #007aff;
    cursor: pointer;
    padding: 6px 12px;
    text-decoration: none;
    transition: background 0.15s ease;
    font-family: inherit;
    display: inline-block;
    line-height: 1;
}

.player-nav-btn:hover {
    background: #e5e5ea;
}

/* -------------------------------------------------------------------------
   Scrubber row: [0:00] ——track—— [4:32]
------------------------------------------------------------------------- */

.player-scrubber {
    width: 100%;
    max-width: 560px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-time-label {
    font-size: 11px;
    font-weight: 500;
    color: #8e8e93;
    font-variant-numeric: tabular-nums;
    min-width: 34px;
    text-align: center;
    flex-shrink: 0;
}

.player-track {
    flex: 1;
    height: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.player-track::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 3px;
    background: #e5e5ea;
    border-radius: 99px;
    transition: height 0.15s ease;
}

.player-track:hover::before {
    height: 4px;
}

.player-track-fill {
    position: absolute;
    left: 0;
    width: 0%;
    height: 3px;
    background: #007aff;
    border-radius: 99px;
    pointer-events: none;
    transition: height 0.15s ease;
    z-index: 1;
}

.player-track:hover .player-track-fill {
    height: 4px;
}

.player-track-thumb {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #007aff;
    border-radius: 50%;
    left: 0%;
    transform: translateX(-50%) scale(0);
    pointer-events: none;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 5px rgba(0,122,255,0.5);
    z-index: 2;
}

.player-track:hover .player-track-thumb {
    transform: translateX(-50%) scale(1);
}

/* -------------------------------------------------------------------------
   Controls row — all centered together
------------------------------------------------------------------------- */

.player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    max-width: 560px;
}

/* Left spacer balances the right side */
.player-controls .spacer {
    flex: 1;
}

/* Right spacer holds speed + download, right-aligned */
.player-controls .spacer--right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
}

.player-btn {
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    border-radius: 10px;
    color: #1d1d1f;
    transition: background 0.12s ease, transform 0.1s ease;
    gap: 3px;
    flex-shrink: 0;
}

.player-btn:hover {
    background: #f2f2f7;
}

.player-btn:active {
    transform: scale(0.91);
}

/* Skip buttons */
.player-btn--skip svg {
    width: 24px;
    height: 24px;
}

.player-btn--skip span {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #aeaeb2;
    line-height: 1;
}

/* Play / Pause — large central button */
.player-btn--primary {
    width: 54px;
    height: 54px;
    background: #007aff;
    border-radius: 50%;
    color: white;
    box-shadow: 0 3px 14px rgba(0,122,255,0.35);
    padding: 0;
    margin: 0 16px;
    gap: 0;
    flex-direction: row;
    flex-shrink: 0;
}

.player-btn--primary:hover {
    background: #0066dd;
    box-shadow: 0 5px 18px rgba(0,122,255,0.45);
}

.player-btn--primary:active {
    transform: scale(0.94);
}

.player-btn--primary svg {
    width: 20px;
    height: 20px;
}

#icon-play {
    transform: translateX(2px);
}

/* Icon-only (download) */
.player-btn--icon svg {
    width: 20px;
    height: 20px;
}

/* Speed pill */
.player-speed {
    appearance: none;
    background: #f2f2f7;
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    color: #3a3a3c;
    cursor: pointer;
    min-width: 50px;
    text-align: center;
}

.player-speed:hover {
    background: #e5e5ea;
}

.player-speed:focus {
    outline: none;
    background: #e5e5ea;
}

/* -------------------------------------------------------------------------
   Responsive
------------------------------------------------------------------------- */

@media (max-width: 480px) {
    .audio-bar {
        padding: 10px 16px 16px;
        gap: 8px;
    }

    .player-btn--primary {
        width: 48px;
        height: 48px;
        margin: 0 10px;
    }

    .player-btn--skip svg {
        width: 22px;
        height: 22px;
    }

    .player-btn {
        padding: 6px 8px;
    }
}

/* Loading placeholder while fetching from library */
.chunks-loading {
    padding: 40px;
    text-align: center;
    color: #8e8e93;
    font-size: 15px;
}

/* -------------------------------------------------------------------------
   Title input
------------------------------------------------------------------------- */

#title-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #d2d2d7;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

#title-input:focus {
    outline: none;
    border-color: #007aff;
}

/* -------------------------------------------------------------------------
   Library link in header
------------------------------------------------------------------------- */

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.library-link {
    color: white;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    opacity: 0.9;
    padding: 6px 14px;
    border: 1.5px solid rgba(255,255,255,0.6);
    border-radius: 8px;
    transition: all 0.15s ease;
}

.library-link:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* -------------------------------------------------------------------------
   Responsive
------------------------------------------------------------------------- */

@media (max-width: 600px) {
    .chunk-div {
        font-size: 1rem;
        padding: 10px 12px;
    }

    .audio-bar {
        padding: 10px 12px;
    }

    .reading-actions {
        flex-direction: column;
    }
}
