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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #ff6b35;
    --accent-hover: #ff8555;
    --danger: #e91429;
    --border: #333;
    --nav-height: 70px;
    --header-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#main-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 100;
}

.install-btn {
    display: none;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
}

.install-btn svg {
    width: 100%;
    height: 100%;
}

@media (max-width: 767px) {
    .install-btn {
        display: block;
    }
}

.install-instructions {
    text-align: left;
}

.install-instructions p {
    margin: 16px 0 8px;
    color: var(--text-primary);
}

.install-instructions p:first-child {
    margin-top: 0;
}

.install-instructions ol {
    margin: 0 0 0 20px;
    color: var(--text-secondary);
}

.install-instructions li {
    margin: 4px 0;
}

.hidden {
    display: none !important;
}

/* Panels */
#panels {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    visibility: hidden;
}

.panel.active {
    transform: translateX(0);
    visibility: visible;
}

.panel-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}

.panel-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.now-playing-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.book-header {
    position: relative;
}

/* Buttons */
.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
}

.icon-btn-lg {
    width: 48px;
    height: 48px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn-lg:hover {
    background: var(--bg-tertiary);
}

.icon-btn-lg.active {
    background: var(--danger);
    border-color: var(--danger);
}

.icon-btn-lg.active svg {
    fill: currentColor;
}

.icon-btn-lg svg {
    width: 24px;
    height: 24px;
}

.primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 32px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

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

.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-tertiary);
}

.secondary-btn svg {
    width: 18px;
    height: 18px;
}

.secondary-btn.in-library {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.secondary-btn.in-library:hover {
    background: var(--accent-hover);
}

/* Discover Bar */
.discover-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 8px 12px;
    flex: 1;
    min-width: 0;
}

.search-box svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    outline: none;
    min-width: 0;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

#category-select {
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.8125rem;
    cursor: pointer;
    outline: none;
    max-width: 100px;
    flex-shrink: 0;
}

/* Book List */
.book-list {
    padding: 0 8px;
}

.book-list.list-view {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-list.grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
    padding: 16px;
}

.book-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.book-item:hover {
    background: var(--bg-tertiary);
}

.book-item.playing {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
}

.book-item-cover {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

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

.book-item-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-item-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Play Button */
.play-item-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    flex-shrink: 0;
}

.play-item-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.play-item-btn svg {
    width: 14px;
    height: 14px;
}

.play-item-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Add to Library Button */
.add-library-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    flex-shrink: 0;
}

.add-library-btn:hover {
    background: var(--border);
}

.add-library-btn svg {
    width: 14px;
    height: 14px;
}

.add-library-btn.in-library {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.add-library-btn.in-library:hover {
    background: var(--accent-hover);
}

/* Grid view */
.grid-view .book-item {
    flex-direction: column;
    padding: 8px;
    gap: 8px;
}

.grid-view .book-item-cover {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}

.grid-view .book-item-info {
    width: 100%;
    text-align: center;
}

.grid-view .book-item-title {
    font-size: 0.8125rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.grid-view .book-item-meta {
    font-size: 0.75rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Library List */
.library-list {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.library-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 12px;
    cursor: pointer;
}

.library-item .book-item-cover {
    width: 64px;
    height: 64px;
    border-radius: 8px;
}

.library-item .book-item-info {
    flex: 1;
    min-width: 0;
}

/* Progress bar for library items */
.progress-bar-small {
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-fill-small {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Resume button */
.resume-btn {
    width: 44px;
    height: 44px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}

.resume-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

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

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state span {
    font-size: 0.875rem;
}

/* Profile Panel */
.profile-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    border-bottom: 1px solid var(--border);
}

.profile-avatar {
    width: 80px;
    height: 80px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.profile-avatar svg {
    width: 40px;
    height: 40px;
    color: var(--text-secondary);
}

.profile-section h2 {
    font-size: 1.25rem;
}

.settings-list {
    padding: 8px 0;
}

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

.setting-value {
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
}

.setting-buttons {
    display: flex;
    gap: 8px;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 12px;
    text-align: center;
}

.backup-textarea {
    width: 100%;
    height: 80px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.75rem;
    padding: 10px;
    resize: none;
    margin-bottom: 12px;
}

.backup-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-content .primary-btn {
    width: 100%;
    margin-bottom: 8px;
}

.coming-soon {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Book Detail */
.book-detail {
    padding: 20px;
}

.book-hero {
    text-align: center;
    margin-bottom: 20px;
}

#book-cover {
    width: 180px;
    height: 180px;
    border-radius: 12px;
    object-fit: cover;
    background: var(--bg-tertiary);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.book-info {
    text-align: center;
    margin-bottom: 24px;
}

#book-title {
    font-size: 1.375rem;
    font-weight: 600;
    margin-bottom: 8px;
}

#book-categories {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 20px;
}

.book-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
}

.chapter-list h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

#chapters, .chapters-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.chapter-item:hover {
    background: var(--bg-tertiary);
}

.chapter-item.playing {
    background: var(--bg-tertiary);
}

.chapter-item.playing .chapter-number {
    background: var(--accent);
    color: white;
}

.chapter-number {
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 500;
    flex-shrink: 0;
}

.chapter-title {
    flex: 1;
    font-size: 0.9375rem;
}

.chapter-playing-icon {
    color: var(--accent);
}

.chapter-playing-icon svg {
    width: 20px;
    height: 20px;
}

/* Player Panel */
.player-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}

.player-artwork {
    width: 100%;
    max-width: 180px;
    aspect-ratio: 1;
    margin-bottom: 20px;
}

#player-cover-large {
    width: 100%;
    height: 100%;
    border-radius: 16px;
    object-fit: cover;
    background: var(--bg-tertiary);
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.player-details {
    text-align: center;
    margin-bottom: 24px;
    width: 100%;
}

#player-title-large {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 4px;
}

#player-chapter-large {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.player-progress-large {
    width: 100%;
    margin-bottom: 24px;
}

.player-progress-large input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
}

.player-progress-large input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.time-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.player-controls-large {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 32px;
}

.control-btn-lg {
    width: 56px;
    height: 56px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn-lg:focus,
.control-btn-lg:active {
    background: transparent;
}

.control-btn-lg svg {
    width: 32px;
    height: 32px;
}

.control-btn-lg span {
    font-size: 0.625rem;
    font-weight: 600;
    margin-top: -4px;
}

.play-btn-lg {
    width: 72px;
    height: 72px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.play-btn-lg:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.play-btn-lg svg {
    width: 32px;
    height: 32px;
}

.chapter-pills {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
    padding: 0 10px;
}

.chapter-pill {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 16px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chapter-pill:hover {
    background: var(--border);
    color: var(--text-primary);
}

.chapter-pill.active {
    background: var(--accent);
    color: white;
}

/* Bottom Navigation */
#bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--nav-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    flex-shrink: 0;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 12px;
    transition: color 0.2s;
    min-width: 60px;
}

.nav-item:hover {
    color: var(--text-primary);
}

.nav-item.active {
    color: var(--accent);
}

.nav-item svg {
    width: 24px;
    height: 24px;
}

.nav-item span {
    font-size: 0.625rem;
    font-weight: 500;
}

/* Now Playing Nav Item */
.nav-item.now-playing {
    position: relative;
    padding: 4px;
}

.nav-item.now-playing img {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    display: none;
}

.nav-item.now-playing.has-cover img {
    display: block;
}

.nav-item.now-playing.has-cover .nav-cover-placeholder {
    display: none;
}

.nav-cover-placeholder {
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-cover-placeholder svg {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
}

/* Play/Pause Nav Button */
.nav-item.play-pause {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: 50%;
    padding: 0;
    min-width: 48px;
}

.nav-item.play-pause svg {
    width: 24px;
    height: 24px;
    color: white;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 320px;
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 20px;
}

.sleep-options, .speed-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.sleep-option, .speed-option {
    padding: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.sleep-option:hover, .speed-option:hover {
    background: var(--bg-tertiary);
}

.sleep-option.active, .speed-option.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.sleep-status {
    text-align: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 16px;
    color: var(--accent);
}

.modal-close {
    width: 100%;
    padding: 14px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--border);
}

/* Audio Loading Bar */
.audio-loading-bar {
    position: fixed;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover), var(--accent));
    background-size: 200% 100%;
    animation: loadingSlide 1.5s ease-in-out infinite;
    z-index: 400;
}

@keyframes loadingSlide {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (min-width: 768px) {
    .book-list.grid-view {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    #book-cover {
        width: 220px;
        height: 220px;
    }

    .player-artwork {
        max-width: 213px;
    }
}
