/* ========================================================================== */
/* TABLE OF CONTENTS */
/* 1. Design Tokens & System Variables                                        */
/* 2. Global Reset & Base Styles                                               */
/* 3. Header & Search                                                         */
/* 4. Navigation & Filters                                                    */
/* 5. Sort Controls                                                           */
/* 6. Library Grid                                                            */
/* 7. Book Cards (Structure)                                                  */
/* 8. Book Cards (Interactions & Stats)                                       */
/* 9. Rating & Stars                                                          */
/* 10. External Link Badge                                                    */
/* 11. Modal Foundation                                                       */
/* 12. Sync Conflict Modal                                                    */
/* 13. Format Selection Modal                                                 */
/* 14. Forms & Inputs                                                         */
/* 15. Buttons (Core)                                                         */
/* 16. Danger Dialogs                                                         */
/* 17. Account & Cloud                                                        */
/* 18. Sync Button Locked State                                               */
/* 19. Animations                                                             */
/* ========================================================================== */

/* ========================================================================== */
/* 1. DESIGN TOKENS & SYSTEM VARIABLES                                        */
/* ========================================================================== */
:root {
    /* Semantic Color Palette */
    --bg-deep: #121214;
    --bg-surface: #1e1e22;
    --bg-focus: #1a1a1e;
    --bg-elevated: #252529;
    --bg-elevated-hover: #2d2d33;
    --bg-elevated-active: #2a2a2f;

    --accent-primary: #8b5cf6;
    --accent-glow: #6d28d9;
    --accent-primary-rgb: 139, 92, 246;

    --text-on-accent: #ffffff;
    --text-main: #e2e8f0;
    --text-main-rgb: 226, 232, 240;
    --text-muted: #94a3b8;
    --border-color: #2d2d33;

    --success: #4CAF50;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --danger-rgb: 220, 38, 38;
    --danger-soft: rgba(220, 38, 38, 0.12);
    --favorite: #f43f5e;
    --favorite-rgb: 244, 63, 94;
    --rating: #fbbf24;
    --rating-strong: #ffcc00;
    --rating-rgb: 255, 204, 0;

    --overlay-bg: rgba(0, 0, 0, 0.8);
    --overlay-bg-transparent: rgba(0, 0, 0, 0);
    --surface-hover: rgba(255, 255, 255, 0.05);
    --accent-ring: rgba(var(--accent-primary-rgb), 0.1);

    /* Effects & Elevation */
    --shadow-purple: 0 4px 14px 0 rgba(var(--accent-primary-rgb), 0.2);
}


.secondary-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
    background: var(--surface-hover);
}
/* ========================================================================== */
/* 2. GLOBAL RESET & BASE STYLES                                              */
/* ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Hide scrollbars across browsers while maintaining functionality */
html, body {
    -ms-overflow-style: none;  /* IE/Edge */
    scrollbar-width: none;     /* Firefox */
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    display: none;             /* Chrome/Safari */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-deep);
    color: var(--text-main);
    line-height: 1.6;
    padding: 20px;
}

/* ========================================================================== */
/* 3. HEADER & SEARCH                                                         */
/* ========================================================================== */
.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 20px;
}

.search-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-grow: 1;
    user-select: none;
    -webkit-user-select: none;
}

.account-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

.account-btn:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-purple);
    transform: translateY(-2px);
}

#search {
    width: 100%;
    display: block;
    background: var(--bg-surface);
    color: var(--text-main);
    padding: 12px 20px;
    border-radius: 50px;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease-in-out;
    user-select: text;
    -webkit-user-select: text;

    /* Default State */
    border: 1px solid var(--border-color);
    box-shadow: none;
}

#search::placeholder {
    color: var(--text-muted);
}

#search:hover {
    box-shadow: 0 0 15px rgba(var(--accent-primary-rgb), 0.4),
                inset 0 0 5px rgba(var(--accent-primary-rgb), 0.2);
}

#search:focus {
    background: var(--bg-focus);
    border: 1px solid var(--accent-primary);
    box-shadow: 0 0 15px rgba(var(--accent-primary-rgb), 0.4),
                inset 0 0 5px rgba(var(--accent-primary-rgb), 0.2);
}

.search-add-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.4rem;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.search-add-btn:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-purple);
    transform: translateY(-2px);
}

/* ========================================================================== */
/* 4. NAVIGATION & FILTERS                                                    */
/* ========================================================================== */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 0;
    margin-bottom: 30px;
    user-select: none;
    width: 100%;
}

.filter-container {
    display: flex;
    gap: 12px;
    padding: 4px;
    position: relative;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;

    /* The Mask: Uses your JS variables to fade the edges */
    -webkit-mask-image: linear-gradient(
        to right,
        rgba(0, 0, 0, calc(1 - var(--left-opacity, 0))) 0%,
        black 60px,
        black calc(100% - 60px),
        rgba(0, 0, 0, calc(1 - var(--right-opacity, 1))) 100%
    );
    mask-image: linear-gradient(
        to right,
        rgba(0, 0, 0, calc(1 - var(--left-opacity, 0))) 0%,
        black 60px,
        black calc(100% - 60px),
        rgba(0, 0, 0, calc(1 - var(--right-opacity, 1))) 100%
    );
}

.filter-container::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.25s ease;
    position: relative;
    white-space: nowrap;
}

.filter-btn:hover { color: var(--text-main); }

.filter-btn.active {
    color: var(--accent-primary);
    pointer-events: none;
    cursor: default;
}

.nav-indicator {
    position: absolute;
    bottom: 6px;
    left: 0;
    height: 1.5px;
    background: linear-gradient(90deg, transparent, var(--accent-primary) 20%, var(--accent-primary) 80%, transparent);
    box-shadow: 0 2px 10px rgba(var(--accent-primary-rgb), 0.3);
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    pointer-events: none;
    opacity: 0.8;
}

.add-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--accent-primary);
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 10px;
}

.add-btn:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-purple);
    transform: translateY(-2px);
    filter: brightness(1.2);
}

/* ========================================================================== */
/* 5. SORT CONTROLS                                                           */
/* ========================================================================== */
.sort-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-surface);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.sort-controls label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

#sort-select {
    flex: 1;
    background: var(--bg-deep);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: inherit;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

#sort-select:hover {
    border-color: var(--accent-primary);
}

#sort-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ========================================================================== */
/* 6. LIBRARY GRID                                                            */
/* ========================================================================== */
#library {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    padding: 10px;
    overflow-x: hidden;
    position: relative;
    min-height: 400px;
}

/* ========================================================================== */
/* 7. BOOK CARDS (STRUCTURE)                                                  */
/* ========================================================================== */
.book-card {
    background: var(--bg-surface);
    min-height: 200px;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;

    /* Optimization for "Flight" animations */
    will-change: transform, opacity;
    backface-visibility: hidden;
    opacity: 1;
    user-select: none;
    -webkit-user-select: none;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--shadow-purple);
    border-color: var(--accent-primary);
}

.card-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.card-header h3 {
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 4px;
    word-break: break-word;
}

.card-author {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 0;
    font-weight: 600;
    max-width: 80%;
}

.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(var(--accent-primary-rgb), 0.1);
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    margin-bottom: 8px;
}

.card-notes {
    margin-top: 12px;
    padding: 10px;
    background: rgba(var(--accent-primary-rgb), 0.06);
    border-left: 3px solid var(--accent-primary);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    max-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================================================== */
/* 8. BOOK CARDS (INTERACTIONS & STATS)                                       */
/* ========================================================================== */
.fav-btn {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: transform 0.2s, color 0.2s;
    line-height: 1;
}

.fav-btn.active {
    color: var(--favorite);
    filter: drop-shadow(0 0 5px rgba(var(--favorite-rgb), 0.4));
}

.fav-btn:hover { transform: scale(1.2); }

.card-stats {
    margin-top: auto;
    width: 100%;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.card-stats p {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* ========================================================================== */
/* 9. RATING & STARS                                                          */
/* ========================================================================== */
.rating-display {
    display: flex;
    align-items: center;
    width: 100%;
    margin-top: 8px;
    color: var(--rating);
    letter-spacing: 2px;
    font-size: 0.9rem;
}

.star-rating {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}

.stars-filled {
    color: var(--rating-strong);
    text-shadow: 0 0 5px rgba(var(--rating-rgb), 0.3);
}

.stars-empty {
    color: rgba(var(--text-main-rgb), 0.1);
}

/* ========================================================================== */
/* 10. EXTERNAL LINK BADGE                                                    */
/* ========================================================================== */
.url-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(var(--accent-primary-rgb), 0.15);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.4);
    transition: all 0.2s ease;
    margin-left: auto; /* Aligns to far right */
}

.url-link::before {
    content: '🔗';
    font-size: 0.9rem;
}

.url-link:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-purple);
    transform: translateY(-1px);
}

/* ========================================================================== */
/* 11. MODAL FOUNDATION                                                       */
/* ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg-transparent);
    z-index: 1000;

    /* Performance: promote to own layer */
    will-change: background;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: background 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.35s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    background: var(--overlay-bg);
    transition: background 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear;
}

.modal-content {
    background: var(--bg-surface);
    padding: 30px;
    border-radius: 20px;
    border: 1px solid var(--accent-primary);

    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);

    width: min(90%, 80vw);
    max-width: 450px;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;

    transform: scale(0.85) translateY(20px);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.35s cubic-bezier(0.16, 1, 0.3, 1);

    /* Text rendering fix */
    -webkit-font-smoothing: antialiased;
}

.sync-diff-summary {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(var(--accent-primary-rgb), 0.08);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.3);
    color: var(--text-main);
    font-size: 0.9rem;
}

.sync-diff-summary h4 {
    margin: 0 0 8px 0;
    font-size: 0.95rem;
    color: var(--accent-primary);
}

.sync-diff-summary ul {
    margin: 6px 0 0 18px;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.sync-diff-summary .summary-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.sync-diff-summary .summary-pill {
    background: rgba(var(--accent-primary-rgb), 0.12);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.35);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--text-main);
}

#theme-modal .modal-content {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

#recommendations-modal .modal-content {
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#recommendations-modal h2 {
    margin: 0 0 16px 0;
    flex-shrink: 0;
}

.recommendations-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    flex: 1;
}

.recommendations-search-input {
    flex-shrink: 0;
}

#recommendations-selection {
    overflow-y: auto;
    flex: 1;
    margin-bottom: 12px;
}

.recommendations-buttons {
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .modal-content {
        width: min(95vw, 95%) !important;
        max-width: min(95vw, 95%) !important;
        max-height: 80vh;
        padding: 20px;
    }

    #recommendations-modal .modal-content {
        max-width: min(95vw, 95%);
        max-height: 80vh;
    }

    #theme-modal .modal-content {
        max-width: min(95vw, 95%);
        max-height: 80vh;
    }
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
}

.modal-content h2 {
    margin-bottom: 20px;
    color: var(--accent-primary);
    font-size: 1.6rem;
    letter-spacing: -0.5px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

/* ========================================================================== */
/* 12. SYNC CONFLICT MODAL                                                    */
/* ========================================================================== */
.sync-modal-content {
    max-width: min(520px, 80vw);
    max-height: 80vh;
}

.conflict-subtitle {
    color: var(--text-muted);
    margin: 0;
    margin-top: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.timestamp-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding: 12px 14px;
    background: rgba(var(--accent-primary-rgb), 0.08);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.2);
    border-radius: 8px;
    animation: fadeIn 0.3s ease-in-out;
}

.timestamp-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.timestamp-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.timestamp-value {
    color: var(--accent-primary);
    font-size: 0.9rem;
    font-weight: 600;
    margin-left: auto;
}

.sync-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 24px;
}

.sync-button {
    appearance: none;
    -webkit-appearance: none;

    background: var(--bg-elevated);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;

    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: inherit;
}

.sync-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.sync-button:not(:disabled):hover {
    background: var(--bg-elevated-hover);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.sync-button:not(:disabled):active {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.sync-button.ready {
    border-color: var(--accent-primary);
    background: var(--bg-elevated-active);
}

.sync-button strong {
    display: block;
    color: var(--text-main);
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 6px;
    pointer-events: none;
}

.sync-button p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.4;
    pointer-events: none;
}

.sync-icon {
    font-size: 2.2rem;
    flex-shrink: 0;
    text-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: float 3s ease-in-out infinite;
}

.sync-info {
    flex: 1;
    text-align: left;
}

.sync-countdown {
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), transparent);
    border-radius: 0;
    width: 0%;
    transition: width 0.1s linear;
}

/* ========================================================================== */
/* 13. FORMAT SELECTION MODAL                                                 */
/* ========================================================================== */
.format-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.format-btn {
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-family: inherit;
}

.format-btn:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(var(--accent-primary-rgb), 0.2);
}

.format-btn:active {
    transform: translateY(1px);
}

.format-btn:disabled,
.format-btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    border-color: var(--border-color);
    background: var(--bg-elevated);
    box-shadow: none;
}

.format-btn:disabled strong,
.format-btn[aria-disabled="true"] strong,
.format-btn:disabled p,
.format-btn[aria-disabled="true"] p {
    color: var(--text-muted);
}

.format-icon {
    font-size: 1.8rem;
}

.format-btn strong {
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 600;
}

.format-btn p {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 0;
    line-height: 1.3;
}

/* ========================================================================== */
/* 13.5 RECOMMENDATIONS MODAL                                                 */
/* ========================================================================== */
.recommendations-actions {
    margin-top: 16px;
}

.action-section h3 {
    color: var(--text-main);
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.recommendations-search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-deep);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    margin-bottom: 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.recommendations-search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.1);
}

.recommendations-selection {
    height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    background: var(--bg-deep);
}

.recommendations-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.recommendations-buttons button {
    flex: 1;
    min-height: 44px;
}

.recommendations-selection::-webkit-scrollbar {
    width: 8px;
}

.recommendations-selection::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: 4px;
}

.recommendations-selection::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.recommendations-selection::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.recommendation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: var(--bg-surface);
    border: 2px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
}

.recommendation-item:hover {
    background: var(--bg-elevated-hover);
    border-color: rgba(var(--accent-primary-rgb), 0.3);
    transform: translateX(4px);
}

.recommendation-item.selected {
    background: var(--bg-elevated-hover);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.recommendation-item input[type="checkbox"] {
    display: none;
}

.recommendation-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.recommendation-item-title {
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.95rem;
}

.recommendation-item-link {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========================================================================== */
/* 14. FORMS & INPUTS                                                         */
/* ========================================================================== */
#book-form { display: flex; flex-direction: column; gap: 15px; }

#book-form h2 { margin-bottom: 20px; color: var(--accent-primary); }

#book-form input,
#book-form select {
    background: var(--bg-deep);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px;
    border-radius: 5px;
    font-family: inherit;
}

#book-form textarea {
    background: var(--bg-deep);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px;
    border-radius: 5px;
    font-family: inherit;
    resize: vertical;
}

.input-group { display: flex; gap: 10px; }
.input-group input { width: 50%; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
}

/* ========================================================================== */
/* 15. BUTTONS (CORE)                                                         */
/* ========================================================================== */
/* Purple primary actions */
.submit-btn,
.primary-btn,
#google-login-btn {
    background: var(--accent-primary);
    color: var(--text-on-accent);
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
}

.submit-btn:hover,
.primary-btn:hover,
#google-login-btn:hover {
    background: var(--accent-glow);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--accent-primary-rgb), 0.3);
}

.submit-btn:active,
.primary-btn:active,
#google-login-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.submit-btn {
    padding: 10px 20px;
    border-radius: 8px;
}

#close-modal,
#close-account-modal,
#cancel-delete,
#cancel-disconnect,
#cancel-import,
.ghost-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: color 0.2s;
}

#close-modal:hover,
#close-account-modal:hover,
#cancel-delete:hover,
#cancel-disconnect:hover,
#cancel-import:hover,
.ghost-btn:hover {
    color: var(--text-main);
}

/* Red danger actions */
#delete-btn,
#confirm-delete-btn,
#confirm-import-btn,
.danger-btn {
    background: var(--danger);
    color: var(--text-on-accent);
    border: 1px solid var(--danger);
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
}

#delete-btn:hover,
#confirm-delete-btn:hover,
#confirm-import-btn:hover,
.danger-btn:hover {
    background: var(--danger-dark);
    border-color: var(--danger-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--danger-rgb), 0.3);
}

#delete-btn:active,
#confirm-delete-btn:active,
#confirm-import-btn:active,
.danger-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

#delete-btn {
    padding: 10px 15px;
    border-radius: 8px;
    margin-right: auto;
}

/* ========================================================================== */
/* 16. DANGER DIALOGS (CONFIRM DELETE/IMPORT)                                 */
/* ========================================================================== */
.delete-confirm-content {
    border: 1px solid rgba(var(--danger-rgb), 0.5) !important;
    text-align: center;
}

.delete-confirm-content h3 {
    color: var(--danger) !important;
    margin-bottom: 10px;
}

#confirm-delete-btn,
#confirm-import-btn {
    padding: 10px 20px;
    border-radius: 8px;
}

/* ========================================================================== */
/* 17. ACCOUNT & CLOUD INTERFACE                                              */
/* ========================================================================== */
#account-modal .modal-content {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Matched to form gap */
}

.account-status {
    padding: 15px;
    background: var(--bg-deep); /* Matches #book-form input background */
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.status-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    width: 100%;
}

.theme-actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
}

.secondary-action-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 10px;
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.secondary-action-btn:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
    background: var(--surface-hover);
}

.account-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
}

.primary-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
}

.danger-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
}

.ghost-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
    border-radius: 8px;
}

.ghost-btn:hover {
    color: var(--text-main);
    background: var(--surface-hover);
}

#close-account-modal {
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: color 0.2s;
}

#close-account-modal:hover {
    color: var(--text-main);
}

#google-login-btn {
    padding: 10px 20px;
    border-radius: 8px;
}

/* Theme Customization */
.theme-subtext {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: -8px;
    margin-bottom: 16px;
}

.theme-settings {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

#theme-modal.theme-advanced-collapsed [data-advanced="true"] {
    display: none;
}

.theme-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-deep);
}

.theme-field span {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 600;
}

#theme-modal input[type="color"] {
    width: 44px;
    height: 36px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.theme-toggle {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

/* ========================================================================== */
/* 18. SYNC BUTTON LOCKED STATE                                               */
/* ========================================================================== */
.sync-btn {
    transition: opacity 0.8s ease-in-out, background-color 0.4s ease;
    position: relative;
    overflow: hidden;
}

.sync-btn.btn-locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.sync-btn.btn-locked::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: currentColor; /* Matches the button's text color automatically */
    transition: width 2s linear;
}

.sync-btn.btn-locked.loading::after {
    width: 100%;
}

/* ========================================================================== */
/* 19. ANIMATIONS                                                             */
/* ========================================================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-4px); }
}

@keyframes flyInRight {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes flyInLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes flyOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}

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

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

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

.fly-in-right { opacity: 0; animation: flyInRight 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.fly-in-left { opacity: 0; animation: flyInLeft 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.fly-out-right { animation: flyOutRight 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards !important; }
.fly-out-left { animation: flyOutLeft 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards !important; }
.fade-in-only { opacity: 0; animation: fadeInOnly 0.2s ease forwards; }
.fade-out-only { animation: fadeOutOnly 0.15s ease forwards !important; }