:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #8b5cf6;
    --bg-color: #e5e5e5;
    --grid-color: #d0d0d0;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.9);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 40px 40px;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 0;
    margin: 0;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
}

/* App Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.deck-name-header {
    padding: 0.5rem 0.75rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 250px;
    transition: all 0.2s ease;
}

.deck-name-header:hover {
    background: rgba(0, 0, 0, 0.02);
}

.deck-name-header:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.deck-name-header::placeholder {
    color: var(--text-secondary);
}

.back-image-thumbnail {
    width: 50px;
    height: 70px;
    border-radius: 6px;
    border: 2px dashed rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    overflow: hidden;
    position: relative;
}

.back-image-thumbnail:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.thumbnail-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    opacity: 0.4;
}

.thumbnail-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-count {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding-right: 0.5rem;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    color: var(--text-primary);
    border: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
}

.btn-icon svg {
    display: block;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn:hover:not(.btn-primary) {
    background: #f9fafb;
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.card-item {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    padding: 0.75rem;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card-item:hover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.card-image-container {
    width: 100%;
    aspect-ratio: 5 / 7;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    position: relative;
    cursor: pointer;
    background: #f3f4f6;
    border: 2px dashed transparent;
    transition: all 0.3s ease;
}

.card-image-container:hover {
    border-color: rgba(0, 0, 0, 0.2);
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.card-image-placeholder svg {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.card-name-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.card-name-input:hover {
    background: rgba(0, 0, 0, 0.02);
}

.card-name-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.card-delete-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: #ef4444;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    transition: all 0.2s ease;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    z-index: 10;
}

.card-delete-btn svg {
    stroke: white;
}

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

.card-delete-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6);
}

.add-card-btn {
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border: 2px dashed rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 5 / 8;
    min-height: 220px;
}

.add-card-btn:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.add-card-btn svg {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.modal-close:hover {
    color: var(--text-secondary);
}

.modal-body {
    margin-bottom: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Crop Container */
.crop-container {
    max-height: 60vh;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.crop-container img {
    max-width: 100%;
    display: block;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    margin-top: 1rem;
}

.zoom-btn {
    flex-shrink: 0;
}

.zoom-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.zoom-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.zoom-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.zoom-level {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 45px;
    text-align: right;
}

.btn-fit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Modal Content Padding */
.modal-content {
    padding: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 1rem;
    }

    .header-left {
        flex-wrap: wrap;
    }

    .deck-name-header {
        flex: 1;
        min-width: 200px;
    }

    .header-right {
        justify-content: space-between;
    }

    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }

    .zoom-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .zoom-slider-container {
        width: 100%;
        order: 3;
    }

    .btn-fit {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }
}

/* Additional Button Styles */
.btn-secondary {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.3);
    color: var(--secondary);
}

.btn-secondary:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--secondary);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #dc2626;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* Image Source Modal Styles */
.image-source-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* URL Input Styles */
.url-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.url-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

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

/* Error and Loading Messages */
.error-message {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    color: #dc2626;
    font-size: 0.875rem;
}

.loading-message {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 6px;
    color: var(--primary);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
