:root {
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --radius: 12px;
}

body.dark-mode {
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
}

/* Header */
header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

.theme-toggle button {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
}

.theme-toggle button:hover {
    background: rgba(128, 128, 128, 0.1);
}

.hero {
    text-align: center;
    padding: 4rem 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.hero p {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 3rem;
    justify-content: center;
    align-items: center;
}

.filter-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: var(--primary);
}

.filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.style-select {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
}

/* Base masonry using columns */
.grid {
    column-count: 3;
    column-gap: 2rem;
}

@media (max-width: 1024px) {
    .grid {
        column-count: 2;
    }
}

@media (max-width: 640px) {
    .grid {
        column-count: 1;
    }
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 2rem;
    break-inside: avoid;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.card-preview {
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f1f5f9;
    /* Fixed light bg for gallery thumbnails */
    min-height: 250px;
    position: relative;
    overflow: hidden;
}

.card-info {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
}

.card-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.card-tags {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.favorite-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: #cbd5e1;
    transition: color 0.2s;
}

.favorite-btn.liked {
    color: #ef4444;
}

.favorite-btn:hover {
    transform: scale(1.1);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-surface);
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    border-radius: var(--radius);
    position: relative;
    z-index: 101;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.icon-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

.preview-sidebar {
    width: 300px;
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
    background: var(--bg-page);
}

.preview-sidebar h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.control-group {
    margin-bottom: 1rem;
}

.control-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.control-group input[type="text"],
.control-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
}

.control-group input[type="color"] {
    width: 100%;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    background: var(--bg-surface);
}

.control-row {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
}

.toggle-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.mt-4 {
    margin-top: 1rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.preview-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #e2e8f0;
    /* Default neutral background to contrast canvas */
}

body.dark-mode .preview-main {
    background: #0f172a;
}

.preview-canvas-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    overflow: auto;
}

.preview-canvas {
    background: #ffffff;
    border-radius: var(--radius);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 800px;
    min-height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s;
    overflow: hidden;
    position: relative;
}

.preview-canvas.dark {
    background: #1e293b;
    color: #f8fafc;
}

.preview-canvas.mobile {
    max-width: 375px;
    min-height: 667px;
}

.code-export {
    height: 300px;
    background: #1e293b;
    display: flex;
    flex-direction: column;
}

.tabs {
    display: flex;
    background: #0f172a;
    padding: 0 1rem;
}

.tab {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: #fff;
    border-bottom-color: var(--primary);
}

.code-block-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

.code-block-container pre {
    margin: 0;
    padding: 1.5rem;
    height: 100%;
    overflow: auto;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.875rem;
    color: #e2e8f0;
}

.primary-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

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

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-surface);
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

@media (max-width: 768px) {
    .modal-body {
        flex-direction: column;
    }

    .preview-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .code-export {
        height: auto;
        flex-shrink: 0;
    }

    .preview-canvas-wrapper {
        min-height: 300px;
    }
}