/* Base Variables & Theme */
:root {
    --bg-color: #0f172a;
    /* Slate 900 */
    --text-color: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */

    --primary-color: #3b82f6;
    /* Blue 500 */
    --primary-hover: #2563eb;
    /* Blue 600 */
    --secondary-color: #1e293b;
    /* Slate 800 */
    --accent-color: #8b5cf6;
    /* Violet 500 */

    --danger-color: #ef4444;
    /* Red 500 */
    --success-color: #10b981;
    /* Emerald 500 */

    --panel-bg: rgba(30, 41, 59, 0.7);
    /* Glass slate 800 */
    --panel-border: rgba(255, 255, 255, 0.08);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 15px rgba(59, 130, 246, 0.5);

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    --font-main: 'Outfit', sans-serif;
    --transition: all 0.2s ease-in-out;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    background-image:
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

.slide-up {
    animation: slideUp 0.5s ease-out forwards;
    opacity: 0;
}

/* Navigation */
.top-nav {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--panel-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand span {
    color: var(--primary-color);
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary-color);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    outline: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

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

.btn-success:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--panel-border);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.btn-danger:hover {
    background: var(--danger-color);
    color: white;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.dashboard-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    background: linear-gradient(135deg, #f8fafc 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.deck-card {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.deck-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: var(--shadow-lg);
}

.deck-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.deck-card-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.version-badge {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
}

.deck-card-body {
    flex-grow: 1;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.deck-card-footer {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    background: var(--panel-bg);
    border: 1px dashed var(--panel-border);
    border-radius: var(--radius-xl);
}

.empty-icon {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.glass-panel {
    background: var(--secondary-color);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 500px;
    transform: scale(0.95);
    transition: var(--transition);
}

.modal.active .glass-panel {
    transform: scale(1);
}

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

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

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

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--panel-border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 9999;
}

.toast {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--primary-color);
    color: var(--text-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--panel-border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Utilities */
.w-100 {
    width: 100%;
}

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

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 1rem;
}

.text-sm {
    font-size: 0.85rem;
}

.text-muted {
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

.divider {
    border: 0;
    border-top: 1px solid var(--panel-border);
    margin: 1.5rem 0;
}

/* Designer Layout */
.designer-sidebar {
    width: 350px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
}

.designer-preview {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-family: var(--font-main);
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s;
}

/* Item Lists (Sections/Cards) */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.list-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
}

.list-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
}

.list-item.selected {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
}

.item-actions {
    display: flex;
    gap: 0.25rem;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Preview Canvas */
.preview-toolbar {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.preview-tabs {
    display: flex;
    gap: 1rem;
}

.preview-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.preview-tab.active {
    color: var(--text-color);
    border-bottom-color: var(--primary-color);
}

.save-status {
    font-size: 0.85rem;
    color: var(--success-color);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.save-status.show {
    opacity: 1;
}

.preview-canvas-container {
    flex-grow: 1;
    padding: 2rem;
    background: #e2e8f0;
    /* Light bg to simulate paper */
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.canvas-wrapper {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

/* The actual physical Card (A5 Portrait approx) */
.card-canvas {
    width: 148.5mm;
    height: 210mm;
    background: white;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    /* Slight rounding for preview */
    color: #0f172a;
    /* Dark text for paper */
    position: relative;
    overflow: hidden;
    transform-origin: top center;
    transform: scale(0.85);
    /* Fit on screen better */
    display: flex;
    flex-direction: column;
}

.card-editor-overlay {
    width: 350px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    color: var(--text-color);
}

/* Card Visuals (Inside the Card) */
.c-cover {
    padding: 2rem;
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.c-cover h1 {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.c-cover .c-version {
    font-size: 1.5rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 3rem;
}

.c-cover .c-text {
    font-size: 1.2rem;
    color: #334155;
}

.c-header {
    background: var(--section-color, #3b82f6);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 4px solid rgba(0, 0, 0, 0.2);
    gap: 1rem;
    /* prevent badge and text from touching */
}

.c-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1 1 auto;
    min-width: 0;
    /* allows text truncation */
}

.c-header-right {
    text-align: right;
    flex: 0 1 auto;
    max-width: 45%;
    /* Don't let section name crush the title */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    /* Align texts nicely to the right */
}

.c-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1.2;
    word-wrap: break-word;
    /* Wrap long text */
}

.c-badge {
    background: white;
    color: black;
    font-weight: 800;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-size: 1.2rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.c-body {
    padding: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.6;
    flex-grow: 1;
    /* allow spreading out */
}

.c-footer {
    padding: 0.5rem 1.5rem;
    font-size: 0.70rem;
    color: #64748b;
    text-align: center;
    border-top: 1px solid #e2e8f0;
    margin-top: auto;
}

.c-body img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.inline-image-wrapper {
    display: inline-block;
    position: relative;
    resize: both;
    overflow: hidden;
    min-width: 100px;
    min-height: 100px;
    max-width: 100%;
    margin: 1rem 0;
    border: 1px dashed transparent;
}

.inline-image-wrapper:hover {
    border: 1px dashed #cbd5e1;
}

.inline-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    margin: 0;
    display: block;
    pointer-events: none;
    /* Allows the wrapper to be resized smoothly */
}

.inline-image-wrapper .img-controls {
    display: none;
    position: absolute;
    top: 5px;
    right: 5px;
    gap: 5px;
    background: rgba(255, 255, 255, 0.9);
    padding: 4px;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.inline-image-wrapper:hover .img-controls {
    display: flex;
}

.btn-small {
    padding: 0.25rem;
    font-size: 0.8rem;
    width: 24px;
    height: 24px;
}

/* Table specific for cards */
.c-content-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.c-content-table th,
.c-content-table td {
    border: 1px solid #cbd5e1;
    padding: 0.5rem;
}

.c-content-table th {
    background: #f1f5f9;
    font-weight: 600;
}

/* true-size canvas */
.card-canvas.true-size {
    transform: scale(var(--canvas-scale, 1));
    transition: transform 0.2s ease;
    transform-origin: top center;
}

/* Base formatting for the inline editable blocks */
.dynamic-content {
    min-height: 200px;
    outline: none;
    padding: 0.5rem;
    position: relative;
    cursor: text;
    overflow: hidden;
    /* Never scroll, perfectly fit */
    flex-grow: 1;
    transform-origin: top left;
}

.dynamic-content ul,
.dynamic-content ol {
    margin: 1rem 0;
    padding-left: 2.5rem;
    line-height: inherit;
}

.dynamic-content li {
    margin-bottom: 0.5rem;
}

.dynamic-content:empty:before {
    content: "Click to add content...";
    color: #94a3b8;
    pointer-events: none;
}

/* Title Input in Header */
.header-title-input {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    outline: none;
    width: 100%;
    font-family: inherit;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.5);
}

.header-title-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

/* WYSIWYG Toolbar */
.wysiwyg-toolbar {
    position: fixed;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    display: flex;
    gap: 0.25rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transform: translateY(-120%);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    align-items: center;
}

.wysiwyg-toolbar.active {
    opacity: 1;
    transform: translateY(-100%) translateY(-10px);
}

.w-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    width: 30px;
    height: 30px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.w-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.w-divider {
    width: 1px;
    height: 20px;
    background: var(--panel-border);
    margin: 0 0.25rem;
}

.w-select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    color: white;
    border-radius: 4px;
    padding: 0.2rem;
    outline: none;
}

.w-select option {
    color: black;
}

/* Add Block Menu */
.add-block-menu {
    position: absolute;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 999;
    padding: 0.25rem;
}

.add-block-menu.active {
    display: flex !important;
}

.add-btn {
    background: transparent;
    border: none;
    text-align: left;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.add-btn:hover {
    background: #f1f5f9;
}

/* Inline specific block styling */
.img-block-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 1rem 0;
}

.img-block-wrapper img {
    max-width: 100%;
    border-radius: 4px;
    display: block;
}

.img-delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.img-block-wrapper:hover .img-delete-btn {
    display: flex;
}