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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, #ff6b9d 0%, #c06c84 50%, #6c5b7b 100%);
    min-height: 100vh;
    padding: 20px;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 50%, rgba(255, 107, 157, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(192, 108, 132, 0.3) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

h1 {
    color: white;
    text-align: center;
    margin-bottom: 10px;
    font-size: 3rem;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
    font-weight: 800;
    letter-spacing: -1px;
}

.tagline {
    color: rgba(255, 255, 255, 0.95);
    text-align: center;
    margin-bottom: 30px;
    font-size: 1.2rem;
    font-style: italic;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
    align-items: start;
}

.card-preview {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
}

/* Background layer - behind canvas */
.card-background {
    position: relative;
    width: 800px;
    height: 600px;
    border-radius: 8px;
    overflow: hidden;
    background-color: #f0f0f0;
}

.card-background-img,
.card-background-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none; /* Hidden until background is selected */
}

/* Canvas layer - on top, transparent background */
#cardCanvas {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 800px;
    height: 600px;
    border-radius: 8px;
    pointer-events: auto;
}

.controls {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.control-section {
    margin-bottom: 25px;
}

.control-section:last-child {
    margin-bottom: 0;
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #333;
}

.background-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.bg-option {
    border: 3px solid transparent;
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
    background: #f0f0f0;
}

.bg-option:hover {
    border-color: #ff6b9d;
    transform: scale(1.05);
}

.bg-option.active {
    border-color: #ff6b9d;
    box-shadow: 0 4px 12px rgba(255, 107, 157, 0.5);
}

.bg-option img,
.bg-option video {
    display: block;
    width: 100%;
    height: 100px;
    object-fit: cover;
}

/* Video badge indicator */
.bg-option {
    position: relative;
}

.video-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 107, 157, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

textarea, select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s;
}

textarea {
    resize: vertical;
}

textarea:focus, select:focus {
    outline: none;
    border-color: #ff6b9d;
    box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.1);
}

input[type="range"] {
    width: 100%;
    margin: 8px 0;
    cursor: pointer;
}

input[type="color"] {
    width: 60px;
    height: 40px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 10px;
}

label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0;
    color: #555;
    font-size: 14px;
}

.download-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.download-btn, .save-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
}

.download-options .download-btn {
    margin-bottom: 0;
    font-size: 14px;
    padding: 12px;
}

.download-btn::before, .save-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.download-btn:hover::before, .save-btn:hover::before {
    left: 100%;
}

.download-btn {
    background: linear-gradient(135deg, #ff6b9d 0%, #c06c84 100%);
    color: white;
}

.save-btn {
    background: linear-gradient(135deg, #ff1744 0%, #ff5252 100%);
    color: white;
}

.download-btn:hover, .save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 157, 0.5);
}

.download-btn:active, .save-btn:active {
    transform: translateY(0);
}

.share-link {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    display: none;
}

.share-link:not(:empty) {
    display: block;
}

.share-link p {
    margin: 0 0 10px 0;
    font-weight: bold;
    color: #333;
}

.share-link input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 10px;
}

.share-link button {
    width: 100%;
    padding: 10px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.share-link button:hover {
    background: #5568d3;
}

.share-link .error {
    color: #dc3545;
}

.hint {
    font-size: 14px;
    font-weight: normal;
    color: #888;
}

#textBlocksList {
    max-height: 600px;
    overflow-y: auto;
}

.no-blocks {
    text-align: center;
    color: #888;
    padding: 20px;
    font-style: italic;
}

.text-block {
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.text-block:hover {
    border-color: #ff6b9d;
}

.text-block.active {
    border-color: #ff6b9d;
    background: #fff;
    box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3);
}

.text-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.block-title {
    font-weight: bold;
    color: #333;
}

.delete-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
}

.delete-btn:hover {
    background: #c82333;
}

.text-block textarea {
    width: 100%;
    margin-bottom: 10px;
}

.text-block label {
    display: block;
    margin: 10px 0 5px 0;
    font-weight: bold;
    font-size: 13px;
    color: #555;
}

.text-block select,
.text-block input[type="range"] {
    width: 100%;
    margin-bottom: 10px;
}

.text-block input[type="color"] {
    width: 50px;
    height: 30px;
}

.align-buttons {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.align-btn {
    flex: 1;
    padding: 8px;
    background: #e0e0e0;
    border: 2px solid transparent;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.align-btn:hover {
    background: #d0d0d0;
}

.align-btn.active {
    background: linear-gradient(135deg, #ff6b9d 0%, #c06c84 100%);
    color: white;
    border-color: #ff6b9d;
}

/* Tag-based filtering sections */
.selected-tags-section,
.available-tags-section,
.media-grid-section {
    margin-bottom: 20px;
}

.selected-tags-section h3,
.available-tags-section h3,
.media-grid-section h3 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.selected-tags-container,
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-badge {
    padding: 8px 16px;
    border: 2px solid #ff6b9d;
    background: white;
    color: #ff6b9d;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tag-badge:hover {
    background: linear-gradient(135deg, #fff0f5 0%, #ffe4e1 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(255, 107, 157, 0.2);
}

.tag-badge.selected {
    background: linear-gradient(135deg, #ff6b9d 0%, #c06c84 100%);
    color: white;
    border-color: #c06c84;
}

.tag-badge.clear-all {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

.tag-badge.clear-all:hover {
    background: #c82333;
}

.tag-count {
    background: rgba(255, 107, 157, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
}

.tag-badge.selected .remove-tag {
    font-size: 18px;
    font-weight: bold;
    margin-left: 4px;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-style: italic;
}

/* Media info overlay */
.bg-option {
    position: relative;
    overflow: hidden;
}

.media-info-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.7) 70%, transparent 100%);
    padding: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.bg-option:hover .media-info-overlay {
    opacity: 1;
}

.media-name {
    color: white;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 4px;
}

.media-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mini-tag {
    background: rgba(255, 107, 157, 0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
}

.background-grid {
    margin-top: 10px;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .controls {
        max-width: 600px;
        margin: 0 auto;
    }
}
