:root {
    --bg-color: #0d1117;
    --text-color: #ffffff;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --glass-bg: rgba(22, 27, 34, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --card-bg: rgba(13, 17, 23, 0.7);
    --progress-track: rgba(255, 255, 255, 0.1);
    --progress-fill: linear-gradient(90deg, #3b82f6, #60a5fa);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: "Outfit", sans-serif;
    background: var(--bg-color);
    background-image:
        radial-gradient(circle at top right, #1e1b4b, transparent 40%),
        radial-gradient(circle at bottom left, #064e3b, transparent 40%);
    background-attachment: fixed;
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    /* Prevent double-tap zoom on buttons */
    touch-action: manipulation;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem;
    min-height: 100vh;
}

/* ─── Library view ──────────────────────────────────────── */
#library-view header {
    text-align: left;
    margin-bottom: 2rem;
    animation: fadeDown 0.8s ease forwards;
}

@keyframes fadeDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.library-title {
    font-size: clamp(2.5rem, 8vw, 4rem);
    margin-bottom: 1rem;
    font-weight: 900;
    background: linear-gradient(135deg, #60a5fa, #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.library-subtitle {
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: var(--text-muted);
    margin: 0 0 2rem;
}

#rescan-btn {
    padding: 0.6rem 1.4rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2.5rem;
}
#rescan-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2); /* Lighter background on hover */
    transform: translateY(-1px);
}
#rescan-btn:active:not(:disabled) {
    transform: translateY(0);
}
#rescan-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ─── Author grid ──────────────────────────────────────────── */
.authors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
    gap: 1.5rem;
}

.author-card {
    background: rgba(22, 27, 34, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 2rem 1.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
}
.author-card:hover {
    background: rgba(22, 27, 34, 0.6);
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border-color: rgba(59, 130, 246, 0.3);
}

.author-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.1);
}


.author-name {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 0.4rem;
    color: #3166d4;
    text-decoration: none;
    transition: color 0.2s;
}

.author-card:hover .author-name {
    color: #4a86ff;
}
.author-count {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 0;
}

/* ─── Section topbar (author → books) ──────────────────────── */
.section-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    margin-bottom: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
}

.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Book grid ─────────────────────────────────────────────── */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
    gap: 1.25rem;
    padding: 0 1.25rem 2rem;
}

.book-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition:
        transform 0.3s ease,
        box-shadow 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}
.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.2);
}
.book-card:active {
    transform: scale(0.97);
}

.book-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    text-align: center;
}
.book-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 0.4rem;
    line-height: 1.3;
}
.book-narrator {
    color: var(--accent-hover);
    font-size: 0.82rem;
    margin: 0;
}

/* ─── Full-screen player ────────────────────────────────── */
#player-view {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    background-image:
        radial-gradient(circle at top right, #1e1b4b, transparent 50%),
        radial-gradient(circle at bottom left, #064e3b, transparent 50%);
    display: flex;
    flex-direction: column;
    z-index: 200;
    animation: fadeIn 0.25s ease;
    /* Allow vertical scroll if content is taller than viewport */
    overflow-y: auto;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.player-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    flex-shrink: 0;
    /* Stick to top on scroll */
    position: sticky;
    top: 0;
    z-index: 10;
}

.back-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition:
        background 0.2s,
        transform 0.15s;
    white-space: nowrap;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(-2px);
}
.back-btn:active {
    transform: scale(0.95);
}

.share-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition:
        background 0.2s,
        transform 0.15s;
    white-space: nowrap;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    margin-left: auto; /* Push to the right */
}
.share-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}
.share-btn:active {
    transform: scale(0.95);
}

.player-book-info {
    color: var(--text-muted);
    font-size: 0.88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

/* ─── Stage (desktop: side-by-side, mobile: stacked) ───── */
.player-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3rem;
    padding: 2rem 2.5rem;
}

/* ─── Cover ─────────────────────────────────────────────── */
.player-cover-wrap {
    width: clamp(140px, 30vw, 280px);
    height: clamp(140px, 30vw, 280px);
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}
#player-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cover-placeholder {
    font-size: clamp(3rem, 8vw, 6rem);
    line-height: 1;
}

/* ─── Right panel ───────────────────────────────────────── */
.player-panel {
    flex: 1;
    min-width: 0;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.player-book-meta h2 {
    margin: 0 0 0.35rem;
    font-size: clamp(1.3rem, 4vw, 2rem);
    font-weight: 800;
    line-height: 1.25;
}
.player-book-meta p {
    margin: 0;
    color: var(--text-muted);
    font-size: clamp(0.82rem, 2.5vw, 1rem);
}

/* ─── Shared dropdown styles ────────────────────────────── */
.part-selector {
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    color: white;
    font-family: inherit;
    font-size: clamp(0.82rem, 2.5vw, 0.95rem);
    outline: none;
    cursor: pointer;
    min-height: 44px;
}
.part-selector option {
    background: var(--bg-color);
}

/* ─── Part / chapter navigation row ────────────────────── */
.part-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
}

.part-nav-btn {
    flex-shrink: 0;
}

.part-selector {
    flex: 1;
    min-width: 0;
    text-align: center;
    text-align-last: center;
}

/* ─── Progress bar section ──────────────────────────────── */
.bar-section {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.bar-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.bar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bar-times {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.time-sep {
    opacity: 0.5;
}

/* Seekbar — large touch target via padding */
.seekbar-wrap {
    position: relative;
    cursor: pointer;
    /* 20px top + 20px bottom → 40px total touch target around 6px track */
    padding: 20px 0;
    margin: -12px 0; /* pull back so layout gap looks the same */
    touch-action: none; /* prevents scroll during horizontal scrub */
    -webkit-tap-highlight-color: transparent;
}

.seekbar-track {
    position: relative;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--progress-track);
    overflow: visible;
}

#book-seekbar-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--progress-fill);
    pointer-events: none;
    width: 0%;
}

.seekbar-thumb {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
    left: 0%;
    transition: transform 0.12s;
}

.seekbar-wrap:hover .seekbar-thumb,
.seekbar-wrap:active .seekbar-thumb {
    transform: translate(-50%, -50%) scale(1.4);
}

/* ─── Playback controls ─────────────────────────────────── */
.controls-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.ctrl-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    border-radius: 999px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.65rem 1.1rem;
    min-height: 44px;
    min-width: 44px;
    transition:
        background 0.2s,
        transform 0.12s;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: scale(1.07);
}
.ctrl-btn:active {
    transform: scale(0.94);
}

.play-btn {
    font-size: 1.4rem;
    padding: 0.8rem 1.8rem;
    min-height: 52px;
    background: var(--accent);
    border-color: transparent;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}
.play-btn:hover {
    background: var(--accent-hover);
}

/* ─── Utilities ─────────────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ─── Responsive: ≤ 700px — mobile layout (bigger, easier to tap) ─── */
@media (max-width: 700px) {
    .app-container {
        padding: 0;
    }

    /* ── Library ─────────────────────────────────────── */
    #library-view header {
        padding: 1.5rem 1rem 1rem;
        margin-bottom: 1.25rem;
    }

    /* 2-column grid so cards are large and comfortable */
    .authors-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        padding: 0 1rem 2.5rem;
    }

    .author-card {
        padding: 1.75rem 1rem 1.25rem;
        border-radius: 20px;
    }

    /* Larger avatar — easier to recognise */
    .author-avatar {
        width: 80px;
        height: 80px;
        font-size: 1.9rem;
        margin-bottom: 0.9rem;
    }

    .author-name {
        font-size: 1.05rem;
    }

    .author-count {
        font-size: 0.88rem;
    }

    /* ── Author / Books view ──────────────────────────── */
    .section-topbar {
        padding: 1rem 1rem;
    }

    .section-title {
        font-size: 1.15rem;
    }

    .back-btn {
        font-size: 1rem;
        padding: 0.65rem 1.2rem;
        min-height: 48px;
    }

    /* Full-width list cards with bigger touch targets */
    .books-grid {
        grid-template-columns: 1fr;
        gap: 0.85rem;
        padding: 0 1rem 2.5rem;
    }

    .book-card {
        flex-direction: row;
        align-items: center;
        gap: 1.1rem;
        padding: 1.1rem 1.25rem;
        border-radius: 18px;
    }

    .book-icon {
        font-size: 2.6rem;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .book-title {
        font-size: 1.1rem;
    }

    .book-narrator {
        font-size: 0.9rem;
        margin-top: 0.25rem;
    }

    /* ── Player ──────────────────────────────────────── */
    .player-topbar {
        padding: 1rem;
    }

    .share-btn {
        font-size: 1rem;
        padding: 0.65rem 1.2rem;
        min-height: 48px;
    }

    /* Stage: no padding — cover goes edge-to-edge */
    .player-stage {
        flex-direction: column;
        align-items: stretch;
        padding: 0;
        gap: 0;
    }

    /* Full-width cover above everything */
    .player-cover-wrap {
        width: 100%;
        height: min(85vw, 380px);
        border-radius: 0;
        align-self: stretch;
        flex-shrink: 0;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }

    .cover-placeholder {
        font-size: clamp(4rem, 18vw, 7rem);
    }

    /* Panel: horizontal padding for meta/controls, but not the seekbar */
    .player-panel {
        max-width: 100%;
        padding: 1.25rem 1.25rem 1.75rem;
        gap: 1.25rem;
    }

    .player-book-meta h2 {
        font-size: clamp(1.3rem, 5vw, 1.8rem);
    }

    .player-book-meta p {
        font-size: 1rem;
    }

    /* Chapter selector row */
    .part-selector {
        font-size: 1rem;
        min-height: 48px;
    }

    .part-nav-btn {
        min-height: 48px;
        min-width: 48px;
    }

    /* Progress bar: break out of panel padding → full viewport width */
    .bar-section {
        margin-left: -1.25rem;
        margin-right: -1.25rem;
    }

    .bar-header {
        padding: 0 1.25rem;
        margin-bottom: 0.4rem;
    }

    /* Thicker seekbar for fat fingers, full width */
    .seekbar-track {
        height: 8px;
        border-radius: 0; /* Edge-to-edge — no rounded ends */
    }

    .seekbar-wrap {
        padding: 18px 0;
        margin: -10px 0;
    }

    .seekbar-thumb {
        width: 26px;
        height: 26px;
    }

    /* Generous controls row */
    .controls-row {
        gap: 1.25rem;
        justify-content: center;
    }

    .ctrl-btn {
        font-size: 1.1rem;
        padding: 0.85rem 1.4rem;
        min-height: 56px;
        min-width: 56px;
    }

    /* Big circular play button */
    .play-btn {
        font-size: 1.8rem;
        padding: 0;
        width: 80px;
        height: 80px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ─── Safe-area insets (iPhone notch / home bar) ─────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 700px) {
        .player-stage {
            padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
        }
    }
}

/* ── Resume Listening Section ────────────────────────────── */
.resume-container {
    background: rgba(22, 27, 34, 0.6);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 1.5rem 2.5rem;
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: fadeDown 0.6s ease-out;
}

.resume-icon {
    font-size: 2rem;
    background: rgba(59, 130, 246, 0.15);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
    color: #fff;
    box-shadow: inset 0 0 20px rgba(59, 130, 246, 0.1);
}

.resume-info {
    flex: 1;
    min-width: 0;
}

.resume-info p {
    margin: 0 0 6px 0;
    color: #3b82f6;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.resume-info h3 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resume-btn {
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff;
    border: none;
    padding: 0.7rem 1.8rem;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3);
}

.resume-btn:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(59, 130, 246, 0.3);
}

@media (max-width: 700px) {
    .resume-container {
        margin: 0 1rem 2rem;
        padding: 1.25rem;
        gap: 1rem;
    }
    .resume-icon {
        width: 50px;
        height: 50px;
        font-size: 1.8rem;
    }
    .resume-info h3 {
        font-size: 1.1rem;
    }
    .resume-btn {
        padding: 0.7rem 1.1rem;
        font-size: 0.9rem;
    }
}
