* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    text-align: center;
    padding: 10px 20px;
}

.app-logo {
    max-height: 80px;
    max-width: 100%;
    object-fit: contain;
    filter: brightness(1.1);
}

.app-title {
    margin: 10px 0 0 0;
    font-size: 2.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.player-section {
    padding: 30px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

#player-container {
    display: flex;
    align-items: center;
    gap: 25px;
    margin-bottom: 10px;
    height: 240px;
}

#book-cover-container {
    margin-left: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.book-cover-wrapper {
    border-radius: 12px;
    overflow: hidden;
}

#controls-container {
    flex: 1;
}

.current-book-thumbnail {
    width: 160px;
}

.current-track-info {
    flex: 1;
    text-align: center;
}

.current-series {
    font-size: 1.2em;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 8px;
}

.series-part {
    font-weight: bold;
}

.by-text,
.author-part {
    font-weight: normal;
    color: #999;
    font-style: italic;
    font-size: 0.9em;
}

.by-text {
    margin: 0 1px;
}

.current-book-title {
    font-size: 1.6em;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 8px;
}

.current-chapter-title {
    font-size: 1.1em;
    color: #7f8c8d;
    margin-bottom: 5px;
}

.custom-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 10px 0 5px 0;
    flex-wrap: wrap;
}

.control-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.6em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    line-height: 0.8;
    font-family: monospace;
}

.control-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.control-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.control-btn:disabled:hover {
    background: #6c757d;
    transform: none;
    box-shadow: none;
}

/* Sleep Control */
.sleep-control {
    margin-top: 5px;
    text-align: center;
}

.sleep-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    color: white;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.sleep-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.sleep-btn.active {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    animation: sleep-glow 3s ease-in-out infinite;
}

.sleep-btn.sleep-disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sleep-btn.sleep-disabled:hover {
    background: #6c757d;
    transform: none;
    box-shadow: none;
}

.sleep-btn-inline {
    margin-left: 10px;
}

@keyframes sleep-glow {
    0% { 
        transform: scale(1);
        box-shadow: 0 0 5px rgba(46, 204, 113, 0.4);
    }
    50% { 
        transform: scale(1.03);
        box-shadow: 0 0 20px rgba(46, 204, 113, 0.8), 0 0 30px rgba(46, 204, 113, 0.4);
    }
    100% { 
        transform: scale(1);
        box-shadow: 0 0 5px rgba(46, 204, 113, 0.4);
    }
}

/* App Footer */
.app-footer {
    text-align: center;
    padding: 20px;
    margin-top: 40px;
    border-top: 1px solid #eee;
}

.version-link {
    color: #999;
    text-decoration: none;
    font-size: 0.8em;
    padding: 5px 10px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.version-link:hover {
    color: #667eea;
    background: #f8f9fa;
    text-decoration: none;
}

/* PWA Mode */
.pwa-mode {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Tablet Mode - when width < 50% of height */
.viewport-tablet #player-container {
    flex-direction: column;
    align-items: center;
    height: auto;
    gap: 15px;
}

.viewport-tablet .current-book-thumbnail {
    width: 120px;
    height: auto;
    max-height: 180px;
    object-fit: contain;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
}

.modal-close {
    font-size: 1.5em;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 30px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-cancel {
    background: #6c757d;
    color: white;
}

.modal-cancel:hover {
    background: #5a6268;
}

.modal-confirm {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-confirm:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
}

.modal-confirm:disabled {
    background: #6c757d !important;
    cursor: not-allowed !important;
    opacity: 0.5 !important;
}

.modal-confirm:disabled:hover {
    background: #6c757d !important;
}

/* Sleep Settings Styles */
.sleep-setting {
    margin-bottom: 20px;
}

.sleep-setting label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.sleep-setting input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1em;
}

.sleep-setting input:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

.sleep-info {
    margin-top: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
}

.sleep-info small {
    color: #666;
    font-style: italic;
}

.control-btn:active {
    transform: scale(0.95);
}

.time-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    font-size: 0.9em;
    color: #666;
}

.progress-container {
    flex: 1;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
}

.progress-bar {
    width: 100%;
    height: 100%;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    width: 0%;
    transition: width 0.1s ease;
    border-radius: 3px;
}

/* Book progress bar */
.book-progress-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    font-size: 0.85em;
    color: #888;
}

.book-progress-container {
    flex: 1;
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    overflow: hidden;
}

.book-progress-bar {
    width: 100%;
    height: 100%;
    position: relative;
}

.book-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #95a5a6, #7f8c8d);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 2px;
}

#book-current-time,
#book-total-time {
    font-size: 0.8em;
    color: #999;
    min-width: 45px;
}

.playlist-section {
    padding: 30px;
}

/* Library Header Component */
.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e9ecef;
}

.library-title {
    font-size: 1.5em;
    font-weight: 600;
    color: #2c3e50;
    display: flex;
    align-items: center;
}


.library-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.search-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-container label {
    font-size: 0.9em;
    color: #666;
    font-weight: 500;
}

#library-search {
    padding: 8px 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 0.9em;
    width: 200px;
    transition: border-color 0.3s ease;
}

#library-search:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

.sorting-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.sorting-btn:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.sorting-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sorting-btn:disabled:hover {
    background: #6c757d;
    transform: none;
    box-shadow: none;
}

.playlist-section h2 {
    margin-bottom: 20px;
    color: #2c3e50;
    font-weight: 300;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
    font-size: 1.1em;
}

.error {
    text-align: center;
    padding: 20px;
    color: #e74c3c;
    background: #fdf2f2;
    border-radius: 8px;
    margin: 20px 0;
}

.playlist {
    display: grid;
    gap: 10px;
}

.track-item {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.track-item:hover {
    background: #f8f9fa;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.track-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.track-item.active:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
}

.track-title {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 5px;
}

.track-artist {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 3px;
}

.track-item.active .track-artist {
    color: rgba(255,255,255,0.8);
}

.track-album {
    color: #999;
    font-size: 0.8em;
    font-style: italic;
}

.track-item.active .track-album {
    color: rgba(255,255,255,0.7);
}

/* Hierarchical audiobook library styles */
.author-group {
    margin-bottom: 12px;
}

.author-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s ease;
}

.author-header:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.series-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.series-thumbnail {
    width: 80px;
    height: 80px;
    object-fit: contain;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: transform 0.3s ease;
}

.series-thumbnail:hover {
    transform: scale(1.05);
}

.series-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

.author-header h3 {
    margin: 0;
    font-size: 1.2em;
    font-weight: 500;
}

.series-name {
    font-size: 1.3em;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.author-name {
    font-size: 1.0em;
    font-weight: 300;
    opacity: 0.9;
    margin: 5px 0 0 0;
    font-style: italic;
}

.books-container {
    margin-left: 16px;
    overflow: hidden;
    transition: max-height 0.4s ease;
    max-height: 0; /* Start collapsed by default */
}

.author-group.expanded .books-container {
    max-height: 100000px; /* Allow expansion */
}

.series-arrow {
    color: rgba(255,255,255,0.9);
    font-weight: bold;
    font-size: 1.2em;
    transition: transform 0.3s ease;
    transform: rotate(-90deg); /* Start pointing up */
}

.author-group.expanded .series-arrow {
    transform: rotate(90deg); /* Point down when expanded */
}

.book-group {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.book-header {
    padding: 10px 16px;
    cursor: pointer;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s ease;
}

.book-info {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    position: relative;
}

.book-info .control-btn {
    position: absolute;
    right: 35px;
    top: 50%;
    transform: translateY(-50%);
}

.book-thumbnail {
    height: 60px;
    object-fit: contain;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: transform 0.2s ease;
}

.book-thumbnail:hover {
    transform: scale(1.05);
}


.book-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.book-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.book-year {
    color: #7f8c8d;
    font-size: 0.9em;
    font-weight: 400;
    opacity: 0.8;
}

.book-header:hover {
    background: #e9ecef;
}

.book-title {
    font-weight: 600;
    font-size: 1.1em;
    color: #2c3e50;
}

.book-author {
    font-size: 0.95em;
    font-style: italic;
    color: #666;
    margin: 4px 0;
    opacity: 0.9;
}

.book-meta {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.chapter-count {
    color: #7f8c8d;
    font-size: 0.9em;
}

.book-duration {
    color: #667eea;
    font-size: 0.9em;
    font-weight: 500;
    background: rgba(102, 126, 234, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
}

.dropdown-arrow {
    color: #667eea;
    font-weight: bold;
    transition: transform 0.3s ease;
    transform: rotate(-90deg); /* Start pointing up */
}

.book-group.expanded .dropdown-arrow {
    transform: rotate(90deg); /* Point down when expanded */
}

.chapters-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    background: white;
}

.book-group.expanded .chapters-container {
    max-height: 100000px; /* Allow expansion */
}

.chapter-item {
    padding: 8px 16px;
    border-bottom: 1px solid #f1f3f4;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chapter-item:last-child {
    border-bottom: none;
}

.chapter-item:hover {
    background: #f8f9fa;
    padding-left: 25px;
}

.chapter-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

/* Progress bar for active chapter */
.chapter-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--chapter-progress, 100%);
    background: rgba(255, 255, 255, 0.1);
    border-left: 2px solid rgba(255, 255, 255, 0.3);
    transition: width 0.3s ease;
    z-index: 1;
}

/* Ensure text stays above progress bar */
.chapter-item.active .chapter-title,
.chapter-item.active .chapter-duration {
    position: relative;
    z-index: 2;
}

.chapter-item.active:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
    padding-left: 20px;
}

.chapter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chapter-title {
    font-size: 0.95em;
    flex: 1;
}

.chapter-duration {
    font-size: 0.85em;
    color: #7f8c8d;
    font-weight: 500;
    margin-left: 10px;
}

.chapter-item.active .chapter-duration {
    color: rgba(255,255,255,0.8);
}

.book-group.expanded {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* Responsive design */
@media (max-width: 600px) {
    .container {
        margin: 0;
        border-radius: 0;
    }
    
    .player-section,
    .playlist-section {
        padding: 20px;
    }
    
    header h1 {
        font-size: 1.5em;
    }
    
    .custom-controls {
        gap: 10px;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 1em;
    }
}
