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

:root {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --text-primary: #ffffff;
    --text-secondary: #98989d;
    --text-tertiary: #636366;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --separator: rgba(84, 84, 88, 0.65);
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    line-height: 1.4;
    overscroll-behavior: none;
}

.app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-bottom: env(safe-area-inset-bottom);
}

/* Views */
.view {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: calc(100vh - 65px);
    padding-bottom: 65px;
}

.view.active {
    display: flex;
}

/* Header */
.header {
    padding: max(env(safe-area-inset-top), 12px) 0 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 0.5px solid var(--separator);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.8px;
    padding: 8px 20px 12px;
    margin: 0;
}

/* Search Section */
.search-container {
    background: var(--bg-primary);
    padding: 16px 16px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.search-bar {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
}

.search-bar input {
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 400;
    outline: none;
    transition: background 0.2s ease;
}

.search-bar input:focus {
    background: var(--bg-tertiary);
}

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

.search-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
}

.search-result-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 8px;
    transition: all 0.15s ease;
    border: none;
    -webkit-tap-highlight-color: transparent;
    align-items: center;
}

.search-result-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

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

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

.book-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.3px;
}

.book-author {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 2px;
    font-weight: 400;
}

.book-year {
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: rgba(28, 28, 30, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--separator);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
    max-width: 600px;
    margin: 0 auto;
}

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

.nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 1.5;
    transition: all 0.2s ease;
}

.nav-item span {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: -0.1px;
}

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

.nav-item.active svg {
    transform: translateY(-1px);
}

.nav-item:active {
    transform: scale(0.95);
    opacity: 0.6;
}

/* Content */
.content {
    flex: 1;
    padding: 16px;
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Filter section for Books view */
.filter-section {
    background: var(--bg-secondary);
    padding: 12px 16px;
    margin: -16px -16px 16px -16px;
    border-bottom: 0.5px solid var(--separator);
}

.search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

.search-input:focus {
    outline: none;
    background: var(--bg-tertiary);
}

.tag-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tag-filters::-webkit-scrollbar {
    display: none;
}

.tag-filter {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 18px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.tag-filter:active {
    transform: scale(0.96);
    opacity: 0.8;
}

.tag-filter.active {
    background: var(--accent);
    color: #ffffff;
}

.book-list {
    display: block;
    min-height: 100%;
}

.book-list.empty::after {
    content: 'No books';
    display: block;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 16px;
    font-weight: 400;
    padding: 80px 20px;
}

.book-card {
    display: flex;
    gap: 14px;
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: 14px;
    margin-bottom: 10px;
    border: none;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.book-card:active {
    background: var(--bg-tertiary);
    transform: scale(0.98);
}

.book-card .book-cover {
    width: 80px;
    height: 120px;
}

.book-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-card-header {
    flex: 1;
}

.book-card .book-title {
    font-size: 17px;
    margin-bottom: 4px;
    white-space: normal;
    letter-spacing: -0.4px;
    line-height: 1.3;
}

.book-card .book-author {
    font-size: 15px;
    margin-bottom: 6px;
}

.book-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 8px;
}

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

.action-group {
    display: flex;
    gap: 4px;
}

.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    -webkit-tap-highlight-color: transparent;
    min-height: 36px;
}

.btn:active {
    transform: scale(0.95);
    opacity: 0.7;
    transition: transform 0.05s;
}

.btn-danger {
    background: #ff453a;
    color: var(--text-primary);
}

.btn-danger:hover {
    background: #ff6961;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    display: block;
}

.btn-icon.active {
    background: var(--accent);
    color: var(--text-primary);
    cursor: default;
}

.btn-icon.active:active {
    transform: none;
    opacity: 1;
}

.btn-icon:disabled {
    pointer-events: none;
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(84, 84, 88, 0.4);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(84, 84, 88, 0.6);
}

/* Loading state */
.loading {
    text-align: center;
    padding: 24px;
    color: var(--text-tertiary);
    font-size: 15px;
    font-weight: 400;
}

/* Error message */
.error-message {
    text-align: center;
    padding: 24px;
    color: #ff453a;
    font-size: 15px;
    font-weight: 500;
    background: rgba(255, 69, 58, 0.1);
    border-radius: 12px;
    margin: 8px 0;
    line-height: 1.5;
}

/* Keyboard open state */
body.keyboard-open .bottom-nav {
    display: none;
}

/* Settings View */
.settings-content {
    max-width: 500px;
    margin: 0 auto;
}

.settings-section {
    background: var(--bg-secondary);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 16px;
}

.settings-section h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.settings-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.settings-description a {
    color: var(--accent);
    text-decoration: none;
}

.settings-description a:active {
    opacity: 0.7;
}

.settings-field {
    margin-bottom: 20px;
}

.settings-field label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.settings-field input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: background 0.2s ease;
}

.settings-field input:focus {
    background: var(--bg-primary);
}

.field-hint {
    display: block;
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: 6px;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-primary);
    margin-right: 8px;
}

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

.sync-status {
    margin-top: 16px;
    padding: 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.sync-info {
    background: rgba(10, 132, 255, 0.1);
    color: var(--accent);
}

.sync-success {
    background: rgba(52, 199, 89, 0.1);
    color: #34c759;
}

.sync-error {
    background: rgba(255, 69, 58, 0.1);
    color: #ff453a;
}

/* Rating Styles */
.book-rating {
    font-size: 14px;
    color: var(--accent);
    font-weight: 600;
    margin-top: 4px;
}

.detail-rating {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
}

.detail-rating label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.star-rating {
    display: flex;
    gap: 8px;
    align-items: center;
}

.star {
    font-size: 32px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

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

.star.filled {
    color: var(--accent);
}

.star:hover {
    transform: scale(1.1);
}

/* Tags Styles */
.book-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.tag-badge {
    display: inline-block;
    padding: 3px 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent);
}

.detail-tags {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
}

.detail-tags label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

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

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
}

.tag-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.tag-remove:hover {
    color: var(--text-primary);
}

.tag-remove:active {
    transform: scale(0.9);
}

.tag-input {
    flex: 1;
    min-width: 120px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: background 0.2s ease;
}

.tag-input:focus {
    background: var(--bg-primary);
}

.tag-input::placeholder {
    color: var(--text-tertiary);
}

/* Sort Controls */
.sort-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-right: 20px;
}

.sort-select {
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.sort-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sort {
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--accent);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.btn-sort:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.btn-sort:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .settings-section {
        padding: 16px;
    }
    
    .settings-section h2 {
        font-size: 18px;
    }
    
    .star-rating {
        gap: 4px;
    }
    
    .star {
        font-size: 28px;
    }
}

/* Book Detail Modal */
.book-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.book-detail-modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    padding: 24px;
    animation: modalSlideIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 18px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
}

.modal-close:active {
    transform: scale(0.9);
    background: var(--bg-primary);
}

.detail-cover-container {
    text-align: center;
    margin-bottom: 24px;
}

.detail-cover {
    max-width: 200px;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
}

.detail-info {
    padding: 0 8px;
}

.detail-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.8px;
    margin-bottom: 8px;
    line-height: 1.2;
}

.detail-author {
    font-size: 19px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.detail-year {
    font-size: 15px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.detail-isbn {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: inline-block;
}

.detail-actions {
    display: flex;
    gap: 8px;
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    justify-content: space-between;
    align-items: center;
}

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

.detail-actions .btn-icon {
    min-width: 44px;
    min-height: 44px;
}

.detail-description {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

@media (max-width: 480px) {
    .modal-content {
        padding: 20px;
        border-radius: 16px;
    }

    .detail-title {
        font-size: 24px;
    }

    .detail-author {
        font-size: 17px;
    }
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.book-card, .search-result-item {
    animation: slideIn 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .header h1 {
        font-size: 32px;
    }
    
    .content {
        padding: 12px;
    }
    
    .search-container {
        padding: 12px;
    }
    
    .book-card {
        padding: 12px;
    }
    
    .book-card-actions {
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .btn-small {
        padding: 7px 10px;
        font-size: 13px;
        flex: 1 1 auto;
        min-width: 70px;
    }
}

/* iPhone notch and safe areas */
@supports (padding: max(0px)) {
    .app {
        padding-bottom: max(65px, env(safe-area-inset-bottom));
    }
    
    .bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* Landscape mode */
@media (max-height: 500px) and (orientation: landscape) {
    .header h1 {
        font-size: 24px;
        padding: 6px 20px 8px;
    }
    
    .bottom-nav {
        padding: 4px 0;
    }
    
    .nav-item {
        padding: 4px 0;
    }
    
    .nav-item svg {
        width: 20px;
        height: 20px;
    }
}
