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

:root {
    --zAngle: 2;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Support for mobile browser safe areas */
    
}

body {
    background-image: 
        radial-gradient(ellipse at center, rgba(0,0,0,0.3) 5%, rgba(0,0,0,0.9) 100%),
        url('images/pattern.svg');
    background-repeat: no-repeat, repeat;
    background-size: cover, auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.container {
    width: 100%;
    /* Use dvh (dynamic viewport height) for mobile browsers with dynamic UI */
    /* height: 100dvh; */
    /* Fallback for browsers that don't support dvh */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 50px;
    box-sizing: border-box;

    /* padding: max(50px, env(safe-area-inset-top)) max(50px, env(safe-area-inset-right)) max(130px, env(safe-area-inset-bottom)) max(50px, env(safe-area-inset-left)); */
}

@media (max-width: 768px) {
    .container {
        padding: max(50px, env(safe-area-inset-top)) max(50px, env(safe-area-inset-right)) max(50px, env(safe-area-inset-bottom)) max(50px, env(safe-area-inset-left));
    }
}

.card-viewport {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* perspective: 1000px; */
}

.card-stack {
    position: relative;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    
    max-width: 100%;
    height: 100%;
    
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
}

/* Static deck card */
.card-deck {
    position: absolute;
    width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    overflow: hidden;
    
    z-index: 1;
}

.card-deck img {
    width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    
}

/* Flipping card container */
.card-container {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform: rotateY(0deg) rotateZ(0);
    transition: transform 0.3s ease-out;
    z-index: 2;
    align-items: center;
    justify-content: center;
    display: flex
;
    /* box-shadow: 13px -10px 60px 9px rgba(0, 0, 0, 1); */

    
}

.card-container.is-flipping {
    animation: cardFlip 0.4s cubic-bezier(0.23,0.64,0.66,1.28) forwards;
}

.card-container.is-flipped {
    transform: rotateY(180deg) rotateZ(calc(var(--zAngle) * 1deg));
    cursor: grab;
}

.card-container.is-dragging {
    transition: none;
    cursor: grabbing;
}

/* Card faces */
.card-face {
    position: absolute;
    width: 100%;
    max-height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 2px 2px 30px 9px rgba(0, 0, 0, 1)
}

.card-face img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Front face - starts facing backward (hidden) */
.card-face-front {
    transform: rotateY(180deg);
}

/* Back face - starts facing forward (visible) */
.card-face-back {
    transform: rotateY(0deg);
}

@keyframes cardFlip {
    0% {
        transform: rotateY(0deg) rotateZ(0deg);
    }
    90% {
        transform: rotateY(181deg) rotateZ(calc(var(--zAngle) * 1deg));
    }
    100% {
        transform: rotateY(180deg) rotateZ(calc(var(--zAngle) * 1deg));
    }
}

/* Hold indicator (optional visual feedback) */
.card-stack:active .card-container.is-flipped::after {
    content: '';
    position: absolute;
    inset: 0;
    /* background: rgba(255, 255, 255, 0.1); */
    opacity: 0.5;
    pointer-events: none;
    border-radius: 12px;
}

.card-stack:active .card-container.is-flipped::after img{

    opacity: 0.5;
}



/* Responsive design for mobile */
@media (max-width: 768px) {
    .card-stack {
        padding: 30px;
    }
    
    .card-deck,
    .card-face {
        border-radius: 8px;
    }
}

@media (max-width: 480px) {
    .card-stack {
        padding: 20px;
    }
    
    .card-deck,
    .card-face {
        border-radius: 6px;
        /* box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); */
    }
}

/* Mobile tap areas */
.mobile-tap-area {
    position: fixed;
    left: 0;
    right: 0;
    height: 50px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 100;
    display: none;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-tap-top {
    top: 0;
    top: env(safe-area-inset-top);
}

.mobile-tap-bottom {
    bottom: 0;
    bottom: env(safe-area-inset-bottom);
}

/* Show tap areas only on mobile/tablet */
@media (max-width: 1024px) {
    .mobile-tap-area {
        display: block;
    }
}

/* Optional: Add visual feedback on touch (remove if you want completely invisible) */
/* .mobile-tap-area:active {
    background: rgba(255, 255, 255, 0.05);
} */

/* Modal Styles */
[x-cloak] {
    display: none !important;
}

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

.modal-content {
    background: white;
    border-radius: 10px;
    width: 100%;
    /* max-width: 1400px; */
    /* Use dvh for mobile browsers with dynamic UI */
    height: 100%;
    /* Fallback for browsers that don't support dvh */
    /* height: calc(100vh - 40px); */
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-grid {
    display: grid;
    grid-template-columns: 70% 30%;
    height: 100%;
    position: relative;
}

.modal-grid::after {
    content: '';
    position: absolute;
    top: 0;
    left: 70%;
    width: 1px;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

/* Left Panel - Preview */
.modal-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow: hidden;
    position: relative;
}

.preview-card-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    perspective: 1000px;
}

.preview-card {
    max-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: cardAppear 0.4s cubic-bezier(0.23,0.64,0.66,1.28) forwards;
    transform-style: preserve-3d;
}

.preview-card img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: block;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 18px;
}

@keyframes cardAppear {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Right Panel - List */
.modal-list {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-list h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-expand {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    color: #666;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-expand:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.modal-expand:active {
    transform: scale(0.9);
}

.modal-close,
.modal-clear {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover,
.modal-clear:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.modal-close:active,
.modal-clear:active {
    transform: scale(0.9);
}

.modal-clear:hover {
    color: #dc3545;
}

.card-list-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.card-list-scroll::-webkit-scrollbar {
    width: 8px;
}

.card-list-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.card-list-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.card-list-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.card-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.02);
}

.card-list-item:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: translateX(4px);
}

.card-list-item.active {
    background: rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

.card-list-thumb {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: #f0f0f0;
}

.card-list-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-list-info {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.card-list-name {
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.card-list-meta {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
}

.card-list-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.history-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    border-radius: 3px;
    transition: all 0.2s ease;
    opacity: 0;
}

.card-list-item:hover .history-delete-btn {
    opacity: 1;
}

.history-delete-btn:hover {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.history-delete-btn:active {
    transform: scale(0.9);
}

/* Mobile-friendly delete button */
@media (max-width: 768px) {
    .history-delete-btn {
        opacity: 1;
        padding: 0;
        width: 30px;
        height: 30px;
        flex-shrink: 0;
        margin-left: 4px;
    }
    
    .history-delete-btn svg {
        width: 18px;
        height: 18px;
    }
}

.empty-history {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.empty-history p {
    color: #999;
    font-size: 14px;
    line-height: 1.6;
}

/* Modal Transitions */
.modal-enter {
    transition: opacity 0.3s ease;
}

.modal-enter-start {
    opacity: 0;
}

.modal-enter-end {
    opacity: 1;
}

.modal-leave {
    transition: opacity 0.2s ease;
}

.modal-leave-start {
    opacity: 1;
}

.modal-leave-end {
    opacity: 0;
}

/* Mobile Responsive - Vertical Layout */
@media (max-width: 768px) {
 
    
    .modal-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 80% 20%;
        transition: grid-template-rows 0.3s ease;
    }

    .modal-grid.modal-grid-expanded {
        grid-template-rows: 20% 80%;
    }
    
    .modal-grid::after {
        left: 0;
        top: 80%;
        width: 100%;
        height: 1px;
    }

    .modal-grid.modal-grid-expanded::after {
        top: 0;
    }
    
    .modal-preview {
        padding: 20px;
    }
    
    .modal-header {
        padding: 12px 15px;
    }
    
    .modal-list h2 {
        font-size: 16px;
    }

    .modal-expand {
        display: flex;
    }
    
    .card-list-scroll {
        padding: 8px;
    }
    
    .card-list-item {
        padding: 8px;
        gap: 10px;
    }
    
    .card-list-thumb {
        width: 35px;
        height: 35px;
    }
    
    .card-list-name {
        font-size: 13px;
    }
}
