/* === PWA viewport & safe-area fixes === */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-bg: #000000; /* Должен совпадать с theme_color/background_color */
}

html, body {
    height: 100%;
    margin: 0;
    background: var(--app-bg);
    color-scheme: dark;
}

@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
        background: var(--app-bg);
        overscroll-behavior: none;
    }
}

/* Additional mobile-specific styles */

/* Mobile container adjustments */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        margin: 0;
        width: 100%;
        max-width: 100%;
    }
    
    body {
        margin: 0;
        padding: 0;
        overflow-x: hidden;
    }
    
    .books-grid {
        padding: 0 5px;
        gap: 10px;
    }
    
    /* Better modal centering on mobile */
    .modal {
        padding: 10px;
        align-items: center;
        justify-content: center;
    }
    
    .modal-content {
        width: 100%;
        max-width: calc(100vw - 20px);
        max-height: calc(100dvh - 20px); /* REPLACED vh -> dvh */
        margin: 0;
    }
    
    /* Better header and navigation on mobile */
    .header {
        padding: 15px 10px;
    }
    
    .status-tabs {
        padding: 0 10px;
        gap: 15px;
    }
    
    .status-tab {
        font-size: 14px;
        padding: 10px 15px;
    }
    
    /* Better add book button positioning on mobile */
    .add-book-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    .books-grid {
        padding: 0 2px;
        gap: 8px;
    }
    
    .modal {
        padding: 5px;
        align-items: center;
        justify-content: center;
    }
    
    .modal-content {
        max-width: calc(100vw - 10px);
        max-height: calc(100dvh - 10px); /* REPLACED vh -> dvh */
        margin: 0;
    }
    
    .header {
        padding: 10px 5px;
    }
    
    .status-tabs {
        padding: 0 5px;
        gap: 10px;
    }
    
    .status-tab {
        font-size: 12px;
        padding: 8px 12px;
    }
}

/* Touch-friendly tap targets */
.book-card,
.tab,
.btn,
.add-book-btn {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Better touch scrolling on iOS */
.modal-content,
.container {
    -webkit-overflow-scrolling: touch;
}

/* Prevent zoom on input focus (iOS) */
input,
select,
textarea {
    font-size: 16px !important;
}

/* Loading animation */
@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Book card hover effects for touch devices */
@media (hover: none) and (pointer: coarse) {
    .book-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Enhanced drag and drop feedback */
.sortable-ghost {
    opacity: 0.3;
    background: rgba(102, 126, 234, 0.1);
    transform: rotate(5deg);
}

.sortable-chosen {
    transform: scale(1.05) rotate(2deg);
    z-index: 1000;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

/* Long press indicator */
.book-card.long-press {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(74, 158, 255, 0.4);
    border: 2px solid #4A9EFF;
    animation: longPressPulse 0.5s ease-in-out;
}

@keyframes longPressPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(74, 158, 255, 0.2);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 8px 25px rgba(74, 158, 255, 0.4);
    }
    100% {
        transform: scale(1.05);
        box-shadow: 0 8px 25px rgba(74, 158, 255, 0.4);
    }
}

/* Status indicators */
.status-queue {
    border-left: 4px solid #ffc107;
}

.status-reading {
    border-left: 4px solid #007bff;
}

.status-read {
    border-left: 4px solid #28a745;
}

/* PWA splash screen colors */
@media (display-mode: standalone) {
    body {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* 3D Book Animation Styles */
.book-3d-container {
    perspective: 1000px;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh; /* REPLACED vh -> dvh */
    z-index: 3000;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease-out, backdrop-filter 0.4s ease-out, background 0.4s ease-out;
    pointer-events: auto;
}

.book-3d-card {
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 1.0s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                left 1.0s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                top 1.0s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                width 1.0s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                height 1.0s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    cursor: pointer;
    transform-origin: center center;
}

.book-3d-card.flipped {
    transform-origin: center center !important;
}

.book-3d-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    overflow: visible;
}

.book-3d-front {
    z-index: 2;
}

.book-3d-back {
    transform: rotateY(180deg);
    background: #1a1a1a;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: visible;
}

/* Back side content styling */
.book-details-3d {
    color: white;
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    position: relative;
    justify-content: space-between;
}

/* Fixed header */
.book-details-3d h3 {
    margin: 0 0 15px 0;
    font-size: 22px;
    text-align: center;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    flex-shrink: 0;
}

/* Scrollable content area */
.book-details-3d form {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
    margin: 0;
    min-height: 0;
}

/* Fixed action buttons */
.book-details-3d .action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #333;
}

/* Custom scrollbar for form content */
.book-details-3d form::-webkit-scrollbar {
    width: 6px;
}

.book-details-3d form::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.book-details-3d form::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.book-details-3d form::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Better scrolling on mobile */
.book-details-3d form {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Swipe navigation indicators */
.tab-content {
    transition: transform 0.3s ease;
}

.tab-content.swipe-left {
    transform: translateX(-10px);
}

.tab-content.swipe-right {
    transform: translateX(10px);
}

/* Swipe hint animation */
@keyframes swipeHint {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

.tab-content.swipe-hint {
    animation: swipeHint 2s ease-in-out infinite;
}

.book-details-3d .form-group {
    margin-bottom: 15px;
}

.book-details-3d .form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 12px;
    color: #ccc;
}

.book-details-3d .form-group input,
.book-details-3d .form-group select,
.book-details-3d .form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #333;
    border-radius: 8px;
    font-size: 14px;
    background: #2a2a2a;
    color: #fff;
    box-sizing: border-box;
}

.book-details-3d .rating-input {
    display: flex;
    gap: 3px;
    justify-content: center;
    margin-top: 5px;
}

.book-details-3d .rating-star {
    font-size: 28px;
    color: #ddd;
    cursor: pointer;
    transition: all 0.2s ease;
}

.book-details-3d .rating-star:hover,
.book-details-3d .rating-star.active {
    color: #ffd700;
}

.book-details-3d .btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.book-details-3d .btn-primary {
    background: #000000;
    color: white;
}

.book-details-3d .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.book-details-3d .btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white;
}

.book-details-3d .btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}

.book-details-3d .btn-secondary {
    background: #f8f9fa;
    color: #666;
    border: 1px solid #e1e5e9;
}

.book-details-3d .btn-secondary:hover {
    background: #e9ecef;
}

.book-details-3d .btn-status {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.book-details-3d .btn-status:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

.book-details-3d .btn-status:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.book-details-3d .btn-status:disabled:hover {
    transform: none;
    box-shadow: none;
}

.book-details-3d .current-status {
    padding: 12px 15px;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    text-align: center;
    font-weight: 500;
}

/* Close button for 3D modal */
.book-3d-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.book-3d-close:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .book-details-3d {
        font-size: 14px;
    }
    
    .book-details-3d h3 {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .book-3d-back {
        padding: 15px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .container {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .book-card {
        background: #2d2d2d;
        border: 1px solid #404040;
    }
    
    .modal-content {
        background: #2d2d2d;
        color: #ffffff;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        background: #404040;
        border-color: #555;
        color: #ffffff;
    }
}

/* Styles for fallback modal status display */
.modal-content .current-status {
    padding: 12px 15px;
    background: #2a2a2a;
    border: 2px solid #333;
    border-radius: 12px;
    font-size: 14px;
    color: #fff;
    text-align: center;
    font-weight: 500;
    margin-top: 5px;
}

/* Disable context menu and selection on book covers */
.book-cover img,
.book-cover-placeholder {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
}

/* Smooth drag animation */
.book-card.dragging {
    transform: rotate(5deg) scale(1.05);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}

.book-card.dragging .book-cover {
    transform: scale(1.1);
    transition: transform 0.2s ease-out;
}

/* Hide default sortable ghost */
.sortable-ghost {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Hide original element during finger tracking */
.book-card.sortable-chosen {
    opacity: 0.3 !important;
}

/* Smooth finger tracking */
.book-card.finger-tracking {
    position: fixed !important;
    pointer-events: none;
    transform: rotate(5deg) scale(1.05);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
    z-index: 99999;
    transition: none;
    width: 120px;
    height: 180px;
}

.book-card.finger-tracking .book-cover {
    transform: scale(1.1);
    transition: none;
    width: 100% !important;
    height: 100% !important;
}

.book-card.finger-tracking .book-cover img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}
