:root {
    --primary: #1E3A8A;
    --primary-dark: #1e40af;
    --secondary: #10B981;
    --accent: #F59E0B;
    --background: #F5F5F5;
    --surface: #FFFFFF;
    --text-primary: #212121;
    --text-secondary: #757575;
    --divider: #E0E0E0;
    --error: #EF4444;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-elevated: 0 4px 12px rgba(0,0,0,0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: pan-y;
    overscroll-behavior: none;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    height: 100vh;
    background: var(--background);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* App Bar */
.app-bar {
    background: var(--primary);
    color: white;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.app-bar h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.15px;
}

.app-bar .icon-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 80px;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.screen {
    display: none;
    animation: fadeIn 0.3s ease;
    padding: 16px;
}

.screen.active {
    display: block;
}

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

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:active {
    transform: scale(0.98);
}

.stat-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.stat-card h3 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-card p {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Section */
.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding: 0 4px;
}

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.action-btn {
    background: var(--surface);
    border: none;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.action-btn:active {
    transform: scale(0.98);
}

.action-btn .material-icons {
    font-size: 32px;
    color: var(--primary);
}

.action-btn span:last-child {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Search Bar */
.search-bar {
    background: var(--surface);
    border-radius: 28px;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.search-bar .material-icons {
    color: var(--text-secondary);
    margin-right: 12px;
}

.search-bar input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-primary);
    flex: 1;
}

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

/* Filter Chips */
.filter-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

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

.chip {
    background: var(--surface);
    border: 1px solid var(--divider);
    border-radius: 16px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: inherit;
}

.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.chip:active {
    transform: scale(0.95);
}

/* Card List */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.book-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.book-card:active {
    transform: scale(0.98);
}

.book-card-header {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.book-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.book-icon .material-icons {
    color: white;
    font-size: 28px;
}

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

.book-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-author {
    font-size: 14px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.not-started {
    background: #FEE2E2;
    color: #991B1B;
}

.status-badge.reading {
    background: #D1FAE5;
    color: #065F46;
}

.status-badge.completed {
    background: #DBEAFE;
    color: #1E40AF;
}

.book-pages {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.book-pages .material-icons {
    font-size: 16px;
}

/* Progress Bar */
.progress-container {
    margin-top: 12px;
}

.progress-bar {
    height: 6px;
    background: var(--divider);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), #059669);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

/* Activity Stats */
.activity-stats {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.activity-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.activity-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.activity-bar {
    height: 8px;
    background: var(--divider);
    border-radius: 4px;
    overflow: hidden;
}

.activity-progress {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.activity-progress.secondary {
    background: var(--secondary);
}

.activity-progress.accent {
    background: var(--accent);
}

.activity-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 32px;
}

.empty-icon {
    font-size: 80px;
    color: var(--divider);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    min-height: 44px;
}

.btn-primary:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--divider);
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.btn-secondary:active {
    background: rgba(30, 58, 138, 0.05);
}

.btn-danger {
    background: var(--error);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.btn-danger:active {
    transform: scale(0.98);
    background: #DC2626;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

/* Bottom Navigation */
.bottom-nav {
    background: var(--surface);
    height: 64px;
    display: flex;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    z-index: 100;
}

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

.nav-item .material-icons {
    font-size: 24px;
    transition: transform 0.2s;
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
}

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

.nav-item.active .material-icons {
    transform: scale(1.1);
}

.nav-item:active .material-icons {
    transform: scale(0.95);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 80px;
    right: max(calc(50% - 224px), 16px);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--secondary);
    border: none;
    box-shadow: var(--shadow-elevated);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab .material-icons {
    color: white;
    font-size: 28px;
}

.fab:active {
    transform: scale(0.9);
}

#library-screen .fab,
#wishlist-screen .fab {
    display: flex;
}

#dashboard-screen .fab,
#reading-log-screen .fab {
    display: none;
}

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

.modal-overlay.active {
    display: flex;
    animation: fadeInOverlay 0.3s ease;
}

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

/* Bottom Sheet */
.bottom-sheet {
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

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

.bottom-sheet-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.bottom-sheet-content {
    padding: 24px 20px;
    overflow-y: auto;
    flex: 1;
}

/* Input Groups */
.input-group {
    position: relative;
    margin-bottom: 24px;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 16px 12px 8px;
    border: 1px solid var(--divider);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color 0.2s;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.input-group label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--text-secondary);
    pointer-events: none;
    transition: all 0.2s;
    background: var(--surface);
    padding: 0 4px;
}

.input-group input:focus + label,
.input-group input:not(:placeholder-shown) + label,
.input-group input:valid + label,
.input-group select:focus + label,
.input-group select:valid + label {
    top: 0;
    font-size: 12px;
    color: var(--primary);
}

.input-group select + label {
    top: 0;
    font-size: 12px;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
}

.form-actions button {
    flex: 1;
}

/* Detail Modal */
.detail-modal {
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.detail-header {
    padding: 12px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--divider);
}

.detail-actions {
    display: flex;
    gap: 4px;
}

.detail-content {
    padding: 32px 24px;
    overflow-y: auto;
    flex: 1;
    text-align: center;
}

.detail-cover {
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 16px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-cover .material-icons {
    font-size: 64px;
    color: white;
}

#detail-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.detail-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.progress-section {
    background: var(--background);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

#detail-progress-text {
    font-size: 14px;
    color: var(--text-secondary);
}

#detail-progress-percent {
    font-size: 18px;
    font-weight: 700;
    color: var(--secondary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    text-align: center;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.detail-value {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

/* Dialog */
.dialog {
    background: var(--surface);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    padding: 24px;
    animation: scaleIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: auto;
}

.modal-overlay.active.center {
    align-items: center;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.dialog h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.dialog-actions button {
    min-width: 80px;
}

/* Snackbar */
.snackbar {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #323232;
    color: white;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-elevated);
    z-index: 2000;
    max-width: calc(100% - 32px);
    width: max-content;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.snackbar.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

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

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

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

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

/* Loading Skeleton */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* Responsive */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 480px) {
    .fab {
        right: 16px;
    }
}
