/* --- START OF FILE style.css --- */

/* --- VARIABLES --- */
:root {
    --bg-color: #121212;
    --surface-color: #1E1E1E;
    --surface-color-hover: #2a2a2a;
    --surface-color-elevated: #242424;
    --primary-text-color: #E0E0E0;
    --secondary-text-color: #A0A0A0;
    --disabled-text-color: #707070;
    --accent-color: #00BCD4;
    --accent-color-darker: #0097A7;
    --accent-color-transparent: rgba(0, 188, 212, 0.1);
    --border-color: #383838;
    --error-color: #CF6679;
    --success-color: #66BB6A;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-color-light: rgba(0, 0, 0, 0.15);
    --font-family-main: 'Inter', sans-serif;
    --header-height: 56px;
    --bottom-nav-height: 60px;
    --player-top-bar-height: 56px;
    --player-bottom-controls-height: 200px;
    --border-radius-small: 4px;
    --border-radius-medium: 8px;
    --border-radius-large: 16px;
    --transition-speed: 0.2s;
    --transition-easing: ease-in-out;
}

/* --- BASE STYLES & RESET --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--surface-color);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--surface-color);
}
::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
    border: 2px solid var(--surface-color);
}
::-webkit-scrollbar-thumb:hover {
    background-color: var(--secondary-text-color);
}

body {
    font-family: var(--font-family-main);
    background-color: var(--bg-color);
    color: var(--primary-text-color);
    line-height: 1.6;
    overflow: hidden;
    height: var(--app-height, 100vh);
    width: 100vw;
    display: flex;
    flex-direction: column;
    overscroll-behavior-y: contain;
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.8rem;
    font-weight: 600;
    color: var(--primary-text-color);
}
h1 { font-size: 2.2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.4rem; }
h4 { font-size: 1.1rem; }

p {
    margin-bottom: 1rem;
    color: var(--secondary-text-color);
}
.small-text {
    font-size: 0.85em;
    color: var(--secondary-text-color);
}

a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color var(--transition-speed) var(--transition-easing);
}
a:hover {
    color: var(--accent-color-darker);
    text-decoration: underline;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 1rem;
    border-radius: var(--border-radius-medium);
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--primary-text-color);
    padding: 0.6em 1em;
    transition: background-color var(--transition-speed) var(--transition-easing), border-color var(--transition-speed) var(--transition-easing), box-shadow var(--transition-speed) var(--transition-easing);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color-transparent);
}
input::placeholder {
    color: var(--secondary-text-color);
}

button {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
    white-space: nowrap;
}
button:hover {
    background-color: var(--surface-color-hover);
}
button:active {
    transform: scale(0.98);
}
button:disabled {
    cursor: not-allowed;
    background-color: var(--disabled-text-color);
    color: var(--surface-color);
    opacity: 0.7;
}

.button-primary {
    background-color: var(--accent-color);
    color: var(--bg-color);
    font-weight: 600;
    border-color: var(--accent-color);
}
.button-primary:hover {
    background-color: var(--accent-color-darker);
    border-color: var(--accent-color-darker);
}

.button-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--primary-text-color);
}
.button-secondary:hover {
    background-color: var(--surface-color-hover);
    border-color: var(--secondary-text-color);
}

/* Saved bookmark button styling */
.button-secondary.saved {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--bg-color);
}
.button-secondary.saved:hover {
    background-color: var(--accent-color-darker);
    border-color: var(--accent-color-darker);
    color: var(--bg-color);
}

.button-danger {
    background-color: transparent;
    border: 1px solid var(--error-color);
    color: var(--error-color);
}
.button-danger:hover {
    background-color: var(--error-color);
    color: var(--bg-color);
    border-color: var(--error-color);
}
#more-options-dropdown .button-danger .icon {
    font-size: 0.9em;
}

.button-icon-text .icon {
    font-size: 0.9em;
}

.hidden {
    display: none !important;
}
.centered-text {
    text-align: center;
}

#notification-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 20px);
    left: 0;
    right: 0;
    z-index: 11000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 16px;
}

.notification {
    background: var(--surface-color-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    box-shadow: 0 12px 24px var(--shadow-color);
    padding: 12px 16px;
    color: var(--primary-text-color);
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    animation: notification-slide-in 0.2s ease-out;
    width: min(420px, 100%);
}

.notification.has-action {
    justify-content: space-between;
}

.notification-message {
    flex: 1;
    font-size: 0.95rem;
    line-height: 1.4;
}

.notification-action {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border: none;
    border-radius: var(--border-radius-small);
    padding: 0.5em 0.9em;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.35);
}

.notification-action:hover {
    background-color: var(--accent-color-darker);
}

@media (max-width: 520px) {
    .notification {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .notification.has-action {
        justify-content: center;
        gap: 16px;
    }

    .notification-action {
        width: 100%;
        justify-content: center;
    }
}

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

/* --- MODALS --- */
.modal, .player-modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) var(--transition-easing), visibility 0s var(--transition-speed) var(--transition-easing);
}
.modal.open, .player-modal.open {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
}

.modal-content, .player-modal-content {
    background-color: var(--surface-color-elevated);
    padding: 1.5rem 2rem;
    border-radius: var(--border-radius-large);
    box-shadow: 0 10px 25px var(--shadow-color);
    width: 90%;
    max-width: 400px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close, .player-modal .modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--secondary-text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}
.modal-close:hover, .player-modal .modal-close:hover {
    color: var(--primary-text-color);
}

#login-signup-modal input {
    width: 100%;
}
#login-signup-modal button {
    width: 100%;
}
.modal-error-message {
    color: var(--error-color);
    background-color: rgba(207, 102, 121, 0.1);
    border: 1px solid var(--error-color);
    padding: 0.5rem 0.8rem;
    border-radius: var(--border-radius-medium);
    font-size: 0.9rem;
    text-align: center;
    margin-top: 0.5rem;
    margin-bottom: 0;
}

/* Character Entry Styling */
.character-entry {
    margin-bottom: 1rem;
}

.character-entry h5 {
    margin-bottom: 0.3rem;
    font-weight: 600;
}

.character-entry .aliases,
.character-entry .description {
    font-size: 0.75rem; /* Even smaller to better match character name size */
    margin-bottom: 0.3rem;
    color: var(--secondary-text-color);
    line-height: 1.4;
}

.character-entry .aliases {
    font-style: italic;
}

.character-entry .description {
    opacity: 0.9;
}

/* Temporarily hide playback pacing button */
#player-speed-btn {
    display: none !important;
}

/* --- EMAIL VERIFICATION --- */
.verification-required {
    text-align: center;
    padding: 2rem;
    background: var(--surface-color);
    border-radius: var(--border-radius-large);
    border: 1px solid var(--border-color);
    margin-top: 1rem;
}

.verification-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.verification-required h3 {
    color: var(--primary-text-color);
    margin-bottom: 1rem;
    font-size: 1.4rem;
}

.verification-required p {
    color: var(--secondary-text-color);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.verification-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.verification-actions button {
    flex: 1;
    max-width: 160px;
}

@media (max-width: 480px) {
    .verification-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .verification-actions button {
        max-width: 200px;
        width: 100%;
    }
}

/* --- NOTIFICATIONS --- */
#notification-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    pointer-events: none; /* Allows clicks to go through the container */
}

.notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--surface-color-elevated);
    color: var(--primary-text-color);
    padding: 1rem 2rem;
    border-radius: var(--border-radius-medium);
    box-shadow: 0 4px 15px var(--shadow-color);
    text-align: center;
    max-width: 80%;
    animation: fadeIn 0.3s ease-in-out;
    pointer-events: all; /* Re-enable pointer events for the notification itself */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(0);
    }
}

/* --- PAGE STRUCTURE --- */
.page {
    display: none;
    flex-direction: column;
    flex: 1;
    width: 100%;
    overflow: hidden; /* The page itself doesn't scroll, its children do */
    background-color: var(--bg-color);
}
.page.active {
    display: flex;
}

#home-page {
    overflow-y: auto; /* Home page is simple, it can scroll itself */
}

#player-page {
    overflow: hidden;
}

/* --- CATALOGUE & PROFILE PAGE LAYOUT (for sticky footer) --- */
.catalogue-header {
    background-color: var(--surface-color);
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Hide catalogue header on mobile */
@media (max-width: 768px) {
    .catalogue-header {
        display: none;
    }
}

.catalogue-tabs {
    display: flex;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    flex-shrink: 0;
}
/* --- FIX: Horizontal scrollbar for tabs --- */
.catalogue-tabs::-webkit-scrollbar {
    height: 2px;
}
.catalogue-tabs::-webkit-scrollbar-thumb {
    background-color: var(--accent-color-transparent);
}


.catalogue-content {
    flex-grow: 1;
    overflow-y: auto;
    background-color: var(--bg-color);
    position: relative; /* Needed for child absolute positioning */
}

.bottom-nav {
    display: flex;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 100;
}


/* --- HOME PAGE --- */
.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.home-header-buttons {
    display: flex;
    gap: 1rem;
}

#home-page main {
    padding: 1.5rem;
}
.hero-section {
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}
.hero-section h2 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
}
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}
.info-section {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius-medium);
    box-shadow: 0 4px 8px var(--shadow-color-light);
}
.info-section h3 {
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

/* --- AUTH PAGE --- */
.auth-page-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
    padding: 2rem;
}

.auth-container {
    background-color: var(--surface-color-elevated);
    padding: 2rem;
    border-radius: var(--border-radius-large);
    box-shadow: 0 10px 25px var(--shadow-color);
    width: 100%;
    max-width: 400px;
    text-align: center;
    position: relative; /* allow absolute-positioned children like version badge */
}

.auth-header {
    margin-bottom: 2rem;
}

.auth-header h1 {
    color: var(--accent-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.auth-header p {
    color: var(--secondary-text-color);
    font-size: 0.9rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form input {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    padding: 1rem;
    color: var(--primary-text-color);
    font-size: 1rem;
    width: 100%;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.auth-form input::placeholder {
    color: var(--secondary-text-color);
}

.auth-toggle {
    margin: 1.5rem 0;
    color: var(--secondary-text-color);
    font-size: 0.9rem;
}

.auth-toggle a {
    color: var(--accent-color);
    text-decoration: none;
}

.auth-toggle a:hover {
    color: var(--accent-color-hover);
}

.auth-error {
    color: var(--error-color);
    background-color: rgba(207, 102, 121, 0.1);
    border: 1px solid var(--error-color);
    padding: 0.5rem 0.8rem;
    border-radius: var(--border-radius-medium);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 1rem;
}

.auth-loading {
    opacity: 0.7;
    pointer-events: none;
}

.auth-returning-user {
    background-color: var(--surface-color);
    border: 1px solid var(--accent-color);
    border-radius: var(--border-radius-medium);
    padding: 1rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
    font-size: 0.9rem;
}

.google-auth-btn {
    margin-top: 1rem;
    /* Google auth temporarily disabled */
    display: none !important;
    visibility: hidden;
}

/* Hide Google auth button by ID */
#google-auth {
    display: none !important;
    visibility: hidden;
}

#save-language-btn {
    margin-top: 1rem;
    align-self: flex-start;
}

#manage-genres-btn {
    margin-top: auto;
    align-self: flex-start;
}

#characters-show-all-btn {
    width: 100%;
}

/* Version badge (used on auth views) */
.version-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 0.6rem;
    color: var(--secondary-text-color);
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 4px 8px;
    margin-bottom: 1rem;
}

/* Mobile responsiveness for auth page */
@media (max-width: 480px) {
    .auth-page-container {
        padding: 1rem;
    }

    .auth-container {
        padding: 1.5rem;
    }

    .auth-header h1 {
        font-size: 1.6rem;
    }
}

/* --- PLAYER PAGE (Non-scrolling part) --- */
.player-top-bar {
    height: var(--player-top-bar-height);
    background-color: var(--surface-color-elevated);
    padding: 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    box-shadow: 0 2px 4px var(--shadow-color-light);
    z-index: 750;
    position: relative;
    flex-shrink: 0;
}
.player-icon-button, .player-text-button {
    background: none;
    border: none;
    color: var(--secondary-text-color);
    padding: 0.6rem;
    border-radius: 50%;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}
.player-icon-button.active {
    color: var(--accent-color);
    background-color: var(--accent-color-transparent);
}
.player-text-button {
    border-radius: var(--border-radius-medium);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5em 0.8em;
    color: var(--primary-text-color);
}
.player-icon-button:hover, .player-text-button:hover {
    background-color: var(--surface-color-hover);
    color: var(--primary-text-color);
}

/* Responsive squeeze for player top bar */
@media (max-width: 768px) {
    .player-top-bar {
        padding: 0 0.3rem;
        gap: 0.15rem;
    }
    .player-icon-button, .player-text-button {
        padding: 0.5rem;
        min-width: 36px;
        height: 36px;
        font-size: 1rem;
    }
}

@media (max-width: 600px) {
    .player-top-bar {
        padding: 0 0.2rem;
        gap: 0.1rem;
    }
    .player-icon-button, .player-text-button {
        padding: 0.4rem;
        min-width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
}

@media (max-width: 400px) {
    .player-top-bar {
        padding: 0 0.1rem;
        gap: 0.05rem;
    }
    .player-icon-button, .player-text-button {
        padding: 0.3rem;
        min-width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
}

.dropdown-menu.player-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    right: 0.5rem;
    background-color: var(--surface-color-elevated);
    border-radius: var(--border-radius-medium);
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 760;
    padding: 0.5rem;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity var(--transition-speed) var(--transition-easing), transform var(--transition-speed) var(--transition-easing), visibility 0s var(--transition-speed);
}
    .player-dropdown .dropdown-header {
        font-weight: 600;
        margin: 4px 0 8px;
        color: #e0e0e0;
    }
    .player-dropdown .dropdown-hint {
        font-size: 12px;
        opacity: 0.7;
        margin-top: 8px;
    }
    .player-dropdown .android-only { display: none; }
.dropdown-menu.player-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
}
.player-dropdown .sleep-timer-presets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}
.player-dropdown .sleep-timer-presets button,
.player-dropdown .sleep-action {
    width: 100%;
    display: inline-flex;
    justify-content: center;
    min-height: 40px;
}
.player-dropdown #sleep-cancel-btn {
    min-height: 40px;
}
.player-dropdown .keep-screen-awake-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.4rem 0.3rem 0.2rem;
    font-size: 0.85rem;
    opacity: 0.85;
}
.player-dropdown .keep-screen-awake-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
}
.player-dropdown #sleep-remaining.sleep-remaining-hidden { display: none; }

/* Sleep countdown display on top bar */
#player-sleep-btn.sleep-active {
    font-family: 'Roboto Mono', 'Courier New', monospace;
    font-size: 0.95rem;
    padding: 0.35rem 0.6rem;
    min-width: 56px;
    font-weight: 600;
}
#player-sleep-btn.sleep-active.eop {
    letter-spacing: 0.5px;
    min-width: 50px;
}

#player-sleep-btn #sleep-btn-label {
    margin-left: 4px;
    display: none;
}
.player-top-bar .dropdown-container {
    position: relative;
}
#narration-options-dropdown label {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.8rem;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    color: var(--primary-text-color);
    gap: 0.5rem;
}
#narration-options-dropdown label:hover {
    background-color: var(--surface-color-hover);
}
#narration-options-dropdown input[type="checkbox"] {
    accent-color: var(--accent-color);
    width: 18px;
    height: 18px;
}
#more-options-dropdown button {
    background: none;
    border: none;
    color: var(--primary-text-color);
    text-align: left;
    padding: 0.6rem 1rem;
    width: 100%;
    border-radius: var(--border-radius-small);
    justify-content: flex-start;
}
#more-options-dropdown button:hover {
    background-color: var(--surface-color-hover);
}

.text-pane-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    align-items: center;
    justify-content: center;
    scroll-padding-top: calc(var(--player-top-bar-height) + 1rem);
}
.text-pane-container.text-visible {
    justify-content: flex-start;
    align-items: stretch;
}
.player-cover-art-display {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--border-radius-medium);
}
.player-cover-figure {
    position: relative;
    margin: 0;
    max-width: 420px;
    width: 100%;
}
.player-cover-figure::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--border-radius-medium);
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 6px 22px -6px rgba(0,0,0,0.6);
    pointer-events: none;
}
.player-cover-caption {
    position: absolute;
    left: 10px;
    bottom: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(0,0,0,0.72), rgba(0,0,0,0.38));
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    font-size: 0.78rem;
    line-height: 1.25;
    transition: background .25s ease;
}
.player-cover-figure:hover .player-cover-caption { background: linear-gradient(135deg, rgba(0,0,0,0.82), rgba(0,0,0,0.5)); }
.player-cover-caption .pc-title { font-weight: 600; letter-spacing: .3px; color: #fff; font-size: .82rem; }
.player-cover-caption .pc-author { color: var(--muted-text-color, var(--muted)); font-weight: 500; font-size: .7rem; opacity: .9; }
.player-cover-caption.hidden { display: none; }
.player-text-content-area {
    width: 100%;
    font-size: 1.0rem;
    line-height: 1.5;
    color: var(--secondary-text-color);
    text-align: left;
}
.text-pane {
    flex: 1;
    min-height: 0;
}
#player-text-content.translation-active .text-pane {
    overflow-y: auto;
}
.sentence {
    margin-bottom: 0.5em;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}
.sentence.highlighted {
    color: var(--primary-text-color);
    font-weight: 500;
    padding: 0.2em 0;
    border-radius: var(--border-radius-small);
}

#player-text-content.translation-active {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    height: 100%;
}
.translation-pane {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-left: 2rem;
    border-left: 1px solid var(--border-color);
    font-size: 1.0rem;
    color: var(--secondary-text-color);
    line-height: 1.5;
}
.translation-pane .sentence.highlighted {
    color: var(--primary-text-color);
    font-weight: 500;
}

.player-bottom-controls-area {
    background-color: var(--surface-color-elevated);
    padding: 1rem 1.5rem;
    box-shadow: 0 -2px 5px var(--shadow-color-light);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: 700;
    flex-shrink: 0;
}
.chapter-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}
#player-chapter-info {
    font-weight: 500;
    color: var(--primary-text-color);
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 1rem;
}
.toc-btn {
    font-size: 1.2rem;
    padding: 0.4rem;
    min-width: auto;
}

#toc-list p {
    cursor: pointer;
    padding: 0.5rem;
    margin: 0.25rem 0;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

#toc-list p:hover {
    background-color: var(--surface-color);
}

#toc-list p.current-part {
    background-color: var(--primary-color);
    color: white;
}

#toc-list p.current-part:hover {
    background-color: var(--primary-color-dark, var(--primary-color));
}

.playback-progress-bar-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}
.playback-progress-bar-container input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex-grow: 1;
    height: 8px;
    background: var(--surface-color);
    border-radius: 5px;
    cursor: pointer;
}
.playback-progress-bar-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    border: 2px solid var(--surface-color-elevated);
}
.playback-progress-bar-container input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    border: 2px solid var(--surface-color-elevated);
    cursor: pointer;
}

.player-part-skip-button {
    background: none;
    border: none;
    color: var(--primary-text-color);
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: var(--border-radius-small);
}
.player-part-skip-button:hover {
    background-color: var(--surface-color-hover);
}

.media-controls {
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.player-media-button {
    background: none;
    border: none;
    color: var(--primary-text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem;
    border-radius: var(--border-radius-medium);
    flex: 1;
}
.player-media-button .icon {
    font-size: 1.6rem;
    margin-right: 0;
}
.player-media-button .control-text {
    font-size: 0.75rem;
    color: var(--secondary-text-color);
}
.player-media-button:hover {
    background-color: var(--surface-color-hover);
}
.player-media-button.play-pause .icon {
    font-size: 2.5rem;
    color: var(--accent-color);
}
.player-media-button.play-pause:hover .icon {
    color: var(--accent-color-darker);
}

/* --- Player Panels --- */
.player-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 400px;
    background-color: var(--surface-color-elevated);
    box-shadow: 4px 0 15px var(--shadow-color);
    z-index: 900;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform var(--transition-speed) var(--transition-easing);
    visibility: hidden;
}
.player-panel.open {
    transform: translateX(0);
    visibility: visible;
}
.player-panel-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.player-panel-header h3 {
    margin: 0;
    margin-left: 1rem;
    font-size: 1.2rem;
}
.audiobook-list-condensed {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.audiobook-list-condensed .audiobook-item {
    display: flex;
    background-color: var(--surface-color);
    border-radius: var(--border-radius-small);
    overflow: hidden;
    cursor: pointer;
    transition: background-color var(--transition-speed);
}
.audiobook-list-condensed .audiobook-item:hover {
    background-color: var(--surface-color-hover);
}
.audiobook-list-condensed .audiobook-item .cover-art {
    width: 60px;
    height: 90px;
    object-fit: cover;
    flex-shrink: 0;
}
.audiobook-list-condensed .audiobook-item .details {
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- PROGRESS ENHANCEMENT STYLES --- */
.audiobook-item {
    position: relative;
    overflow: hidden;
}

/* Bookmarks section dense styling for titles and authors */
#player-bookmarks-list .audiobook-item .details h4 {
    line-height: 1.1;
    margin-bottom: 0.2rem;
    font-size: 1.05rem;
}

#player-bookmarks-list .audiobook-item .details p {
    line-height: 1.1;
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Current book highlighting */
.audiobook-item.current-book {
    border: 2px solid var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color-transparent);
}

/* Enhanced progress bar for current book */
.audiobook-item.current-book .audiobook-progress-bar {
    height: 8px; /* Even thicker for current book */
    background-color: rgba(255, 215, 0, 0.3); /* Yellow-tinted background */
}

/* Show progress bar even at 0% for current book */
.audiobook-item.current-book .audiobook-progress-fill {
    min-width: 4px; /* Always show at least a small bit for current book */
    background: linear-gradient(90deg, #ffd700, #ffed4e, #ffd700); /* Animated-style yellow */
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.8); /* Stronger glow for current book */
    animation: progressPulse 2s ease-in-out infinite alternate; /* Subtle pulse animation */
}

@keyframes progressPulse {
    0% { opacity: 0.9; }
    100% { opacity: 1; }
}

.audiobook-item.current-book::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-color-darker));
    z-index: 3;
}

/* Progress bar container */
.audiobook-item,
.library-item,
.saved-item,
.featured-book-card {
    position: relative;
}

.audiobook-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px; /* Made even thicker for better visibility */
    background-color: rgba(255, 255, 255, 0.3); /* More visible background */
    z-index: 2;
    border-radius: 0; /* Keep it as a bottom border effect */
    border: 1px solid rgba(255, 255, 255, 0.1); /* Add subtle border */
}

/* Progress fill - YELLOW as requested */
.audiobook-progress-fill {
    height: 100%;
    width: var(--progress, 0%);
    background: linear-gradient(90deg, #ffd700, #ffed4e); /* Bright yellow gradient */
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6); /* Yellow glow effect */
    min-width: 2px; /* Always show at least 2px for current books */
}

/* Current book progress fill - special styling */
.audiobook-item.current-book .audiobook-progress-fill {
    min-width: 4px; /* More visible minimum width for current book */
    background: linear-gradient(90deg, #ffd700, #ffed4e, #ffd700); /* Enhanced gradient */
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.8); /* Stronger glow for current book */
}

/* Progress text overlay */
.audiobook-progress-text {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--primary-text-color);
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: var(--border-radius-small);
    z-index: 3;
    font-weight: 500;
}

/* Status badges */
.audiobook-status-badges {
    position: absolute;
    bottom: 12px;
    right: 4px;
    display: flex;
    gap: 4px;
    z-index: 3;
}

.audiobook-status-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: var(--border-radius-small);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.audiobook-status-badge.current {
    background: var(--accent-color);
    color: var(--bg-color);
}

.audiobook-status-badge.started {
    background: var(--success-color);
    color: var(--bg-color);
}

/* Remove button for saved books */
.audiobook-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--error-color);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.audiobook-remove-btn:hover {
    background: var(--error-color);
    color: var(--bg-color);
}

/* Hide remove button for current books */
.audiobook-item.current-book .audiobook-remove-btn {
    display: none;
}

/* Enhanced hover states for progress items */
.audiobook-item.has-progress:hover .audiobook-progress-fill,
.library-item.has-progress:hover .audiobook-progress-fill,
.saved-item.has-progress:hover .audiobook-progress-fill,
.featured-book-card.has-progress:hover .audiobook-progress-fill {
    box-shadow: 0 0 8px rgba(0, 188, 212, 0.5);
}

.audiobook-item.current-book:hover,
.library-item.current-book:hover,
.saved-item.current-book:hover,
.featured-book-card.current-book:hover {
    border-color: var(--accent-color-darker);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-color), 0 0 0 1px var(--accent-color-transparent);
}

/* Grid view progress styles */
.catalogue-grid .audiobook-item .audiobook-progress-bar,
.catalogue-grid .library-item .audiobook-progress-bar,
.catalogue-grid .saved-item .audiobook-progress-bar,
.catalogue-grid .featured-book-card .audiobook-progress-bar {
    bottom: 0;
    height: 6px;
}

.catalogue-grid .audiobook-item .audiobook-progress-text,
.catalogue-grid .library-item .audiobook-progress-text,
.catalogue-grid .saved-item .audiobook-progress-text,
.catalogue-grid .featured-book-card .audiobook-progress-text {
    bottom: 12px;
    left: 12px;
    right: 12px;
    font-size: 0.8rem;
}

.catalogue-grid .audiobook-status-badges {
    bottom: 12px;
    right: 12px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .audiobook-progress-text {
        font-size: 0.7rem;
        padding: 1px 4px;
    }
    
    .audiobook-status-badge {
        font-size: 0.6rem;
        padding: 1px 4px;
    }
}

@media (max-width: 768px) {
    #player-text-content.translation-active {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    .translation-pane {
        padding-left: 0;
        padding-top: 1rem;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}

/* --- FABULINUS STYLES --- */
#fabulinus-floating-btn, #catalogue-fab-ai-chat {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 1rem);
    width: 56px;
    height: 56px;
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 12px var(--shadow-color);
    cursor: pointer;
    z-index: 800;
    transition: background-color var(--transition-speed), transform var(--transition-speed), opacity var(--transition-speed);
    -webkit-user-select: none;
    user-select: none;
}
#fabulinus-floating-btn {
    left: 1.5rem;
    bottom: calc(var(--player-bottom-controls-height) + 1rem);
}
#catalogue-fab-ai-chat {
    left: 1.5rem;
}

#fabulinus-floating-btn:hover, #catalogue-fab-ai-chat:hover {
    background-color: var(--accent-color-darker);
    transform: scale(1.05);
}
#fabulinus-floating-btn:active, #catalogue-fab-ai-chat:active {
    transform: scale(0.95);
}

@keyframes pulse-border {
    from { border-color: var(--accent-color); }
    to { border-color: var(--accent-color-darker); }
}

#fabulinus-chat-modal .player-modal-content {
    width: 96%;
    max-width: 600px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 0.8rem;
}
#fabulinus-chat-modal .modal-close {
    z-index: 10;
}
#fabulinus-chat-modal h3 {
    text-align: center;
    margin-bottom: 0.5rem;
}
.chat-history-display {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--bg-color);
    border-radius: var(--border-radius-medium);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 200px; /* Ensure minimum height so button is visible */
}

.chat-area-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex-grow to work in a flex column */
}

.fabulinus-reload-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10; /* Ensure it's above the messages */
    background-color: var(--surface-color-hover);
    color: var(--secondary-text-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    transition: transform 0.3s ease, background-color 0.2s ease;
}

.fabulinus-reload-btn:hover {
    background-color: var(--surface-color-elevated);
    color: var(--primary-text-color);
    transform: rotate(90deg);
}

.chat-message {
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius-large);
    max-width: 80%;
    line-height: 1.4;
    word-wrap: break-word;
}
.chat-message.user {
    background-color: var(--accent-color);
    color: var(--bg-color);
    align-self: flex-end;
    border-bottom-right-radius: var(--border-radius-small);
}
.chat-message.ai {
    background-color: var(--surface-color);
    color: var(--primary-text-color);
    align-self: flex-start;
    border-bottom-left-radius: var(--border-radius-small);
}
.chat-message.system, .chat-message.thought {
    background-color: #2a2a2a;
    color: #a0a0a0;
    font-style: italic;
    font-size: 0.85em;
    border-left: 3px solid #555;
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
}
.fabulinus-context-scope {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}
.fabulinus-context-scope span {
    font-weight: 500;
    color: var(--primary-text-color);
}
.fabulinus-context-scope label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}
.fabulinus-settings {
    padding: 0.25rem 0;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}
.fabulinus-settings label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}
.fabulinus-status-indicator {
    text-align: center;
    padding: 0.5rem;
    border-radius: var(--border-radius-medium);
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    font-weight: 500;
    transition: all var(--transition-speed) ease-in-out;
}
.fabulinus-status-indicator.connecting {
    color: #FFC107;
    border-color: #FFC107;
}
.fabulinus-status-indicator.listening {
    color: var(--success-color);
    border-color: var(--success-color);
    animation: pulse-border 1.5s infinite alternate;
}
.fabulinus-status-indicator.speaking {
    color: var(--accent-color);
    border-color: var(--accent-color);
    animation: pulse-border 1.2s infinite alternate;
}
.fabulinus-status-indicator.error {
    color: var(--error-color);
    border-color: var(--error-color);
}
.fabulinus-controls {
    display: flex;
    justify-content: center;
}
#fabulinus-session-btn {
    padding: 0.8em 1.5em;
    font-size: 1.1rem;
    min-width: 200px;
    transition: background-color var(--transition-speed) ease-in-out;
}
#fabulinus-session-btn.active {
    background-color: var(--error-color);
    border-color: var(--error-color);
}
#fabulinus-session-btn.active:hover {
    background-color: darkred;
}
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    position: relative;
}
.chat-input-area textarea {
    flex-grow: 1;
    min-height: 50px;
    max-height: 150px;
    padding-right: 50px;
    resize: vertical;
}
.button-icon-circle {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    position: absolute;
    right: 5px;
    bottom: 5px;
    box-shadow: 0 2px 5px var(--shadow-color-light);
}
.button-icon-circle:hover {
    background-color: var(--accent-color-darker);
}
.chat-message.transcript {
    font-style: italic;
    border: 1px dashed var(--border-color);
    min-height: 2.4em;
}
.chat-message.transcript.ai {
    background-color: transparent;
    color: var(--secondary-text-color);
}
.chat-message.transcript.user {
    background-color: transparent;
    color: var(--secondary-text-color);
    border-color: #555;
    align-self: flex-start;
}

/* --- MARKDOWN STYLING IN CHAT MESSAGES --- */
.chat-message h1,
.chat-message h2,
.chat-message h3,
.chat-message h4,
.chat-message h5,
.chat-message h6 {
    margin: 0.5em 0 0.3em 0;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message h1 { font-size: 1.2em; }
.chat-message h2 { font-size: 1.1em; }
.chat-message h3 { font-size: 1.05em; }
.chat-message h4,
.chat-message h5,
.chat-message h6 { font-size: 1em; }

.chat-message p {
    margin: 0.4em 0;
    line-height: 1.5;
}

.chat-message ul,
.chat-message ol {
    margin: 0.5em 0;
    padding-left: 1.2em;
}

.chat-message li {
    margin: 0.2em 0;
    line-height: 1.4;
}

.chat-message blockquote {
    margin: 0.5em 0;
    padding: 0.5em 0.8em;
    border-left: 3px solid var(--accent-color);
    background-color: rgba(var(--accent-color-rgb), 0.1);
    border-radius: 0 var(--border-radius-small) var(--border-radius-small) 0;
    font-style: italic;
}

.chat-message code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.1em 0.3em;
    border-radius: var(--border-radius-small);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.chat-message pre {
    background-color: rgba(255, 255, 255, 0.05);
    padding: 0.8em;
    border-radius: var(--border-radius-medium);
    overflow-x: auto;
    margin: 0.5em 0;
    border: 1px solid var(--border-color);
}

.chat-message pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
}

.chat-message strong, 
.chat-message b {
    font-weight: 600;
}

.chat-message em, 
.chat-message i {
    font-style: italic;
}

.chat-message del,
.chat-message s {
    text-decoration: line-through;
    opacity: 0.8;
}

.chat-message hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1em 0;
}

.chat-message table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
    font-size: 0.9em;
}

.chat-message th,
.chat-message td {
    padding: 0.3em 0.5em;
    border: 1px solid var(--border-color);
    text-align: left;
}

.chat-message th {
    background-color: var(--surface-color);
    font-weight: 600;
}

@media (min-width: 769px) {
    #fabulinus-chat-modal .player-modal-content {
        max-width: 700px;
        padding: 1.5rem;
    }
}

/* --- CATALOGUE & PROFILE PAGE --- */
.catalogue-tab {
    /* --- FIX: Allow tabs to size naturally --- */
    flex-grow: 1;
    flex-shrink: 0;
    min-width: 80px; /* Ensure tabs don't get too small */
    padding: 0.75rem 0.5rem;
    background: none;
    border: none;
    color: var(--secondary-text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    position: relative;
}
.catalogue-tab i {
    font-size: 1.25rem;
}
.catalogue-tab span {
    font-size: 0.75rem;
    white-space: nowrap;
}
.catalogue-tab:hover {
    color: var(--primary-text-color);
}
.catalogue-tab.active {
    color: var(--accent-color);
}
.catalogue-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background-color: var(--accent-color);
    border-radius: 3px 3px 0 0;
}

/* Responsive squeeze for catalogue tabs */
@media (max-width: 768px) {
    .catalogue-tab {
        padding: 0.6rem 0.3rem;
        min-width: 70px;
        gap: 0.2rem;
    }
    .catalogue-tab i {
        font-size: 1.1rem;
    }
    .catalogue-tab span {
        font-size: 0.7rem;
    }
}

@media (max-width: 600px) {
    .catalogue-tab {
        padding: 0.5rem 0.2rem;
        min-width: 60px;
        gap: 0.15rem;
    }
    .catalogue-tab i {
        font-size: 1rem;
    }
    .catalogue-tab span {
        font-size: 0.65rem;
    }
}

@media (max-width: 400px) {
    .catalogue-tab {
        padding: 0.4rem 0.1rem;
        min-width: 50px;
        gap: 0.1rem;
    }
    .catalogue-tab i {
        font-size: 0.9rem;
    }
    .catalogue-tab span {
        font-size: 0.6rem;
    }
}

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

.bottom-nav-item {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--secondary-text-color);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    transition: color 0.2s;
}
.bottom-nav-item:hover {
    color: var(--primary-text-color);
}
.bottom-nav-item.active {
    color: var(--accent-color);
}
.bottom-nav-item i {
    font-size: 1.25rem;
}
.bottom-nav-item span {
    font-size: 0.75rem;
}


/* --- PROFILE PAGE STYLES --- */
#profile-page .catalogue-content {
    padding: 1.5rem;
}
.profile-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    width: 100%;
    align-items: stretch;
}
.profile-section {
    background-color: transparent;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: var(--border-radius-medium);
    flex: 1 1 350px;
    display: flex;
    flex-direction: column;
}
.profile-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.profile-section-header h3 {
    margin: 0;
}
.profile-logout-btn {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    height: auto;
}
.profile-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-grow: 1;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.form-group label {
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}
.profile-form button {
    margin-top: auto;
    align-self: flex-start;
}
.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
#profile-avatar-display {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--border-color);
    background-color: var(--bg-color);
}
#profile-avatar-input + label {
    cursor: pointer;
}

/* Disabled state for avatar change during alpha */
#profile-avatar-input[disabled] + label,
.button-secondary[aria-disabled="true"] {
    pointer-events: none;
    opacity: 0.6;
}

.avatar-note {
    margin-top: 0.5rem;
    color: var(--secondary-text-color);
    font-size: 0.9rem;
}

/* Small utility spacing/alignment classes used in profile page */
.mt-1 { margin-top: 1rem; }
.mt-auto { margin-top: auto; }
.align-self-start { align-self: flex-start; }
.parental-control-section {
    margin-top: 2rem;
}

/* PREFERENCES TAB SPECIFIC */
.genre-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem 0;
}
.genre-checkboxes label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--surface-color);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-large);
    cursor: pointer;
    transition: background-color 0.2s;
}
.genre-checkboxes label:hover {
    background-color: var(--surface-color-hover);
}
.genre-tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    min-height: 24px;
}

/* --- CATALOGUE PAGE: SPECIFIC STYLES --- */
.search-container {
    position: relative;
    flex-grow: 1;
    margin: 1.5rem;
}
#catalogue-search-input {
    width: 100%;
    padding-left: 2.5rem;
    background-color: var(--bg-color);
}
.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--secondary-text-color);
}
.featured-grid, .library-list, .saved-list, .search-results {
    padding: 1.5rem;
}
.featured-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 200px));
    gap: 1.5rem;
    justify-content: center; /* Center rows when they don't fill full width */
}

/* --- FIX: RESTORED BOOK CARD STYLES --- */
.featured-book-card {
    background-color: var(--surface-color);
    border-radius: var(--border-radius-medium);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Allow the card to shrink if needed */
    width: 100%; /* Ensure card takes full grid space */
}
.featured-book-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.featured-book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
}
.featured-book-info {
    padding: 0.75rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.featured-book-title {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    height: calc(2 * 1.3em);
}
.featured-book-author {
    font-size: 0.8rem;
    color: var(--secondary-text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.featured-book-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 0.75rem 0.75rem;
    margin-top: auto;
    flex-wrap: wrap; /* Allow wrapping to create two rows */
}
.featured-book-actions button {
    flex: 0 1 auto; /* Don't force equal distribution */
    padding: 0.5rem;
    font-size: 0.8rem;
    min-width: 0; /* Allow buttons to shrink */
    max-width: 100%; /* Prevent overflow */
    overflow: hidden; /* Prevent text overflow */
    text-overflow: ellipsis; /* Add ellipsis for long text */
    white-space: nowrap; /* Prevent text wrapping */
}

/* First row: Ask and Save buttons - equal width */
.featured-book-actions .ask-ai-btn {
    flex: 1 1 calc(50% - 0.25rem); /* Take half width minus gap */
    order: 1;
}

.featured-book-actions .button-secondary:not(.ask-ai-btn) {
    flex: 1 1 calc(50% - 0.25rem); /* Take half width minus gap */
    order: 2;
}

/* Second row: Listen button - full width */
.featured-book-actions .listen-btn {
    flex: 1 1 100%; /* Take full width */
    order: 3;
    margin-top: 0.5rem; /* Add some space from first row */
}

/* --- LIBRARY CONTROLS --- */
.library-controls {
    padding-top: 1rem;
}

/* --- FIX: RESTORED LIST ITEM STYLES --- */
.library-list, .saved-list, .search-results {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.library-item, .search-result-item, .saved-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background-color: var(--surface-color);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.library-item:hover, .search-result-item:hover, .saved-item:hover {
    background-color: var(--surface-color-hover);
}
.search-result-cover {
    width: 60px;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 1rem;
    flex-shrink: 0;
}
.search-result-info {
    flex: 1;
}
.search-result-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.search-result-author {
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}

.saved-item {
    position: relative;
}

/* Position buttons in top right corner for saved items */
.saved-item .featured-book-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
    flex-direction: row;
    z-index: 5;
}

/* Make all buttons in saved items the same size and single row */
.saved-item .featured-book-actions {
    flex-wrap: nowrap; /* Override featured book wrap behavior */
}

.saved-item .featured-book-actions button {
    flex: none; /* Override featured book flex properties */
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0.9rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    order: unset; /* Reset any order properties from featured books */
}

/* Ensure listen button is same size as others */
.saved-item .featured-book-actions .listen-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    margin-top: 0 !important; /* Override featured book margin */
    flex: none !important; /* Override featured book flex */
    order: unset !important; /* Override featured book order */
}

/* Apply the same styling to library and search items */
.library-item {
    position: relative;
}

/* Position buttons in top right corner for library items */
.library-item .featured-book-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
    flex-direction: row;
    flex-wrap: nowrap; /* Override featured book wrap behavior */
    z-index: 5;
}

/* Make all buttons in library items the same size and single row */
.library-item .featured-book-actions button {
    flex: none; /* Override featured book flex properties */
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0.9rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    order: unset; /* Reset any order properties from featured books */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Ensure listen button is same size as others in library items */
.library-item .featured-book-actions .listen-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    margin-top: 0 !important; /* Override featured book margin */
    flex: none !important; /* Override featured book flex */
    order: unset !important; /* Override featured book order */
}

/* Apply the same styling to search result items */
.search-result-item {
    position: relative;
}

/* Position buttons in top right corner for search result items */
.search-result-item .featured-book-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
    flex-direction: row;
    flex-wrap: nowrap; /* Override featured book wrap behavior */
    z-index: 5;
}

/* Make all buttons in search result items the same size and single row */
.search-result-item .featured-book-actions button {
    flex: none; /* Override featured book flex properties */
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0.9rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    order: unset; /* Reset any order properties from featured books */
}

/* Ensure listen button is same size as others in search results */
.search-result-item .featured-book-actions .listen-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    margin-top: 0 !important; /* Override featured book margin */
    flex: none !important; /* Override featured book flex */
    order: unset !important; /* Override featured book order */
}

/* Ensure listen button is same size as others in search result items */
.search-result-item .featured-book-actions .listen-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
}
.saved-item-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    font-size: 1.2rem;
}

/* Mobile responsiveness for audiobook items - prevent title overlap with buttons */
@media (max-width: 600px) {
    .library-item .search-result-info,
    .search-result-item .search-result-info,
    .saved-item .search-result-info {
        padding-right: 110px; /* Make room for buttons */
    }
    
    .library-item .search-result-title,
    .search-result-item .search-result-title,
    .saved-item .search-result-title {
        word-wrap: break-word;
        overflow-wrap: break-word;
        line-height: 1.3;
        -webkit-hyphens: auto;
        hyphens: auto;
    }
}

/* --- FIX: AI CHAT LAYOUT --- */
#ai-chat-tab.active {
    display: flex; /* Use flexbox for layout */
    flex-direction: column;
    height: 100%;
    padding: 1rem;
    /* gap: 1rem; */ /* This was not targeting the correct elements */
}

#ai-chat-tab .fabulinus-container-redesigned {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Make the container take all available space */
    min-height: 0; /* Prevent overflow issues */
    gap: 0.8rem; /* Apply gap here to space out the internal elements */
}

#ai-chat-tab #catalogue-fabulinus-messages {
    flex-grow: 1; /* Make message area expand */
    overflow-y: auto;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    padding: 1rem;
}

#ai-chat-tab .fabulinus-controls button {
    padding: 0.8em 1.5em;
}

#ai-chat-tab .fabulinus-settings {
    padding-top: 0.5rem;
}

/* Reload Button Styles */
.fabulinus-reload-btn {
    position: absolute;
    top: 10px;
    right: 18px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--secondary-text-color);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s ease-in-out;
    z-index: 100;
    min-width: 26px;
    min-height: 26px;
}

.fabulinus-reload-btn:hover {
    background-color: var(--surface-color-hover);
    color: var(--primary-text-color);
    border-color: var(--accent-color);
}

@media (min-width: 768px) {
    .featured-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 220px));
        justify-content: center;
    }
}

/* --- CATALOGUE DETAILS VIEW SYSTEM --- */
.list-view, .details-view {
    width: 100%;
    min-height: 300px;
}

.details-view {
    display: flex;
    flex-direction: column;
}

.details-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.details-header .back-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.details-header .back-button:hover {
    background-color: var(--surface-color-hover);
}

.details-header .breadcrumb {
    font-size: 0.9rem;
    color: var(--secondary-text-color);
    margin-left: auto;
}

.details-content {
    flex: 1;
}

/* Book Details Layout */
.book-details-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.book-details-cover-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.book-details-cover {
    width: 200px;
    height: 300px;
    object-fit: cover;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.book-details-info {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.book-details-title {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-text-color);
}

.book-details-author {
    font-size: 1.1rem;
    color: var(--secondary-text-color);
    margin-bottom: 1rem;
}

.book-details-author a {
    color: var(--accent-color);
    text-decoration: none;
}

.book-details-author a:hover {
    text-decoration: underline;
}

.book-details-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: var(--secondary-text-color);
}

.book-details-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.book-details-genre-tag {
    background-color: var(--surface-color);
    color: var(--accent-color);
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
    font-size: 0.8rem;
    border: 1px solid var(--accent-color);
}

.book-details-description {
    line-height: 1.6;
    color: var(--primary-text-color);
    margin-bottom: 2rem;
    text-align: left;
}

.book-details-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.book-details-actions button {
    min-width: 180px;
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
    gap: 0.4rem;
}

.book-details-actions button i {
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Save button states */
.book-details-actions button.saved {
    background-color: var(--accent-color);
    color: var(--background-color);
    border-color: var(--accent-color);
}

.book-details-actions button.saved:hover {
    background-color: var(--accent-color-darker);
    border-color: var(--accent-color-darker);
}

.book-details-actions button.saved:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .book-details-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 2rem;
    }
    
    .book-details-cover-section {
        flex-shrink: 0;
        align-items: flex-start;
    }
    
    .book-details-info {
        text-align: left;
        margin: 0;
    }
    
    .book-details-meta {
        justify-content: flex-start;
    }
    
    .book-details-genres {
        justify-content: flex-start;
    }
    
    .book-details-actions {
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
    }
    
    .book-details-actions button {
        min-width: 160px;
    }
}

@media (max-width: 480px) {
    .book-details-actions button {
        min-width: 140px;
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        gap: 0.3rem;
    }
    
    .book-details-actions button i {
        font-size: 0.8rem;
    }
}

/* --- FEEDBACK FEATURE --- */

/* Feedback Tab */
.feedback-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    transition: var(--transition-speed) var(--transition-easing);
}

.feedback-tab-button {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 8px;
    border-radius: var(--border-radius-medium) 0 0 var(--border-radius-medium);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    cursor: pointer;
    box-shadow: -2px 0 8px var(--shadow-color);
    transition: var(--transition-speed) var(--transition-easing);
    font-family: var(--font-family-main);
}

.feedback-tab-button:hover {
    background: var(--accent-color-darker);
    transform: translateX(-2px);
}

.feedback-tab-text {
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 1px;
}

/* Feedback Panel */
.feedback-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: var(--surface-color-elevated);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 16px var(--shadow-color);
    z-index: 1001;
    transition: right 0.3s var(--transition-easing);
    display: flex;
    flex-direction: column;
}

.feedback-panel.open {
    right: 0;
}

.feedback-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.feedback-panel-header h3 {
    color: var(--primary-text-color);
    margin: 0;
    font-size: 18px;
}

.feedback-close-btn {
    background: none;
    border: none;
    color: var(--secondary-text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-small);
    transition: var(--transition-speed) var(--transition-easing);
}

.feedback-close-btn:hover {
    background: var(--surface-color-hover);
    color: var(--primary-text-color);
}

.feedback-panel-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#feedback-message {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    color: var(--primary-text-color);
    padding: 12px;
    font-family: var(--font-family-main);
    font-size: 14px;
    resize: none;
    transition: border-color var(--transition-speed) var(--transition-easing);
    flex: 1;
    min-height: 120px;
}

#feedback-message:focus {
    outline: none;
    border-color: var(--accent-color);
}

#feedback-message::placeholder {
    color: var(--disabled-text-color);
}

.feedback-char-count {
    text-align: right;
    color: var(--secondary-text-color);
    font-size: 12px;
}

.feedback-actions {
    margin-top: auto;
}

.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s var(--transition-easing);
}

.feedback-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .feedback-panel {
        width: 100%;
        right: -100%;
    }
    
    .feedback-tab {
        right: 0;
    }
    
    .feedback-panel-content {
        padding: 16px;
    }
    
    #feedback-message {
        min-height: 100px;
    }
    
    /* Featured book actions - mobile view: show only icons */
    .featured-book-actions {
        gap: 0.4rem;
        padding: 0 0.5rem 0.5rem; /* Reduced padding for mobile */
        justify-content: flex-end; /* Right-align buttons on mobile */
    }
    
    .featured-book-actions button {
        padding: 0.4rem;
        min-width: 40px; /* Ensure touch-friendly size */
        font-size: 0; /* Hide button text */
        flex: 0 0 auto; /* Don't grow on mobile */
        max-width: 44px; /* Limit button width */
    }
    
    /* Keep icons visible at normal size */
    .featured-book-actions button .fas,
    .featured-book-actions button .fab {
        font-size: 1rem;
    }
    
    /* Mobile: revert to horizontal layout with icon-only buttons */
    .featured-book-actions .ask-ai-btn {
        flex: 0 0 auto;
        width: 40px;
        min-width: 40px;
        max-width: 40px;
        order: 1;
        margin-top: 0;
    }
    
    .featured-book-actions .button-secondary:not(.ask-ai-btn) {
        flex: 0 0 auto;
        width: 40px;
        min-width: 40px;
        max-width: 40px;
        order: 2;
        margin-top: 0;
    }
    
    .featured-book-actions .listen-btn {
        flex: 0 0 auto;
        width: 40px;
        min-width: 40px;
        max-width: 40px;
        order: 3;
        margin-top: 0;
    }
}

/* PWA Install Button Animation */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(100px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pwa-install-button {
    font-family: var(--font-family-main);
}

.pwa-install-button:hover {
    background: #0056b3 !important;
}

.pwa-install-button:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 8px rgba(0,123,255,0.4) !important;
}

/* PWA Install Button - Catalogue Tab Style */
.pwa-install-tab {
    background: #007bff !important;
    color: white !important;
    flex-grow: 0 !important; /* Prevent growing to fill space */
    flex-shrink: 0 !important;
    min-width: 80px !important;
    max-width: 100px !important; /* Limit width */
}

.pwa-install-tab:hover {
    background: #0056b3 !important;
    color: white !important;
}

.pwa-install-tab i {
    color: white !important;
}

.pwa-install-tab span {
    color: white !important;
}

/* Responsive PWA tab sizing */
@media (max-width: 768px) {
    .pwa-install-tab {
        min-width: 70px !important;
        max-width: 85px !important;
    }
}

@media (max-width: 600px) {
    .pwa-install-tab {
        min-width: 60px !important;
        max-width: 75px !important;
    }
}

@media (max-width: 400px) {
    .pwa-install-tab {
        min-width: 50px !important;
        max-width: 65px !important;
    }
}

/* PWA Install Button - Player Bar Style */
.pwa-install-player-btn {
    background: #007bff !important;
    color: white !important;
}

.pwa-install-player-btn:hover {
    background: #0056b3 !important;
    color: white !important;
}

.pwa-install-player-btn i {
    color: white !important;
}