:root {
    /* Material You inspired color palette - Black and White theme */
    --md-sys-color-primary: #000000; /* Black */
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #E1E1E1; /* Light Grey */
    --md-sys-color-on-primary-container: #000000;
    --md-sys-color-secondary: #424242; /* Dark Grey */
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #F5F5F5;
    --md-sys-color-on-secondary-container: #000000;
    --md-sys-color-tertiary: #705573; /* Muted Lavender-Blue */
    --md-sys-color-on-tertiary: #FFFFFF;
    --md-sys-color-tertiary-container: #FAD8FD;
    --md-sys-color-on-tertiary-container: #29132D;
    --md-sys-color-error: #B3261E;
    --md-sys-color-on-error: #FFFFFF;
    --md-sys-color-error-container: #F9DEDC;
    --md-sys-color-on-error-container: #410E0B;
    --md-sys-color-background: #FFFFFF; /* Pure White background */
    --md-sys-color-on-background: #1C1B1F; /* Dark text on light background */
    --md-sys-color-surface: #FFFFFF; /* Pure White surface */
    --md-sys-color-on-surface: #1C1B1F;
    --md-sys-color-surface-variant: #F0F0F0; /* Light grey for contrast */
    --md-sys-color-on-surface-variant: #666666; /* Distinct grey for muted text */
    --md-sys-color-outline: #000000; /* Black borders for high contrast */
    --md-sys-color-inverse-surface: #1C1B1F;
    --md-sys-color-inverse-on-surface: #FFFFFF;
    --md-sys-color-shadow: #000000;

    /* Mapping existing variables to Material You palette */
    --bg-color: var(--md-sys-color-background);
    --card-bg: var(--md-sys-color-surface);
    --text-main: var(--md-sys-color-on-surface);
    --text-muted: var(--md-sys-color-on-surface-variant);
    --accent: var(--md-sys-color-primary);
    --accent-hover: var(--md-sys-color-primary-container); /* Use container color for hover background */
    --border: var(--md-sys-color-outline);
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.card-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Editor Shell & Sidebar */
.app-shell {
    display: flex;
    flex-direction: column; /* Arrange children in a column */
    height: 100vh; /* Take full viewport height */
    overflow: hidden;
}

.app-nav {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-main);
    padding: 0;
}

@media (max-width: 850px) {
    .app-nav {
        flex-wrap: wrap;
    }
    .menu-toggle {
        display: block;
    }
    .app-nav .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 12px;
        padding-top: 16px;
        padding-bottom: 8px;
    }
    .app-nav .nav-links.active {
        display: flex;
    }
}

.app-nav .nav-links a, .app-nav .nav-links button {
    display: inline-block;
    padding: 4px 16px;
    background-color: #ffffff;
    color: #000000;
    border: 1.5px solid #000000;
    cursor: pointer;
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.9rem;
    letter-spacing: 0.3px;
    transition: all 0.2s;
}

@media (max-width: 850px) {
    .app-nav a {
        margin-left: 0 !important;
        text-align: center;
    }
}

.app-nav .nav-links a:hover, .app-nav .nav-links button:hover {
    background-color: #000000;
    color: #ffffff !important;
    border-color: #000000;
}

.sidebar {
    width: 320px;
    background: #f9f9f9;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    border-radius: 0;
    box-sizing: border-box;
    overflow-y: auto;
}

.sidebar h2 { font-size: 1.25rem; margin-bottom: 24px; font-weight: 600; }

.tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--md-sys-color-surface-variant); /* Lighter border for tabs */
    margin: -24px -24px 24px -24px;
}

.tab-btn {
    flex: 1;
    padding: 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500; /* Slightly less bold */
    color: var(--text-muted);
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--text-main);
    border-bottom: 2px solid var(--text-main);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.input-group { margin-bottom: 20px; }
.input-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 0; }
.char-counter { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.input-group input,
.input-group textarea {
    width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; /* Rounded inputs */ font-size: 14px; outline: none; box-sizing: border-box; transition: border-color 0.2s, box-shadow 0.2s;
}
.input-group input:focus, .input-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-hover); } /* Focus ring */

.align-picker {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.align-btn {
    flex: 1;
    padding: 4px;
    background: #fff;
    border: 1px solid #000000;
    border-radius: 6px; /* Slightly tighter radius for smaller buttons */
    cursor: pointer;
    font-size: 12px;
    color: #000000;
    transition: all 0.2s;
}

.align-btn.active { /* Active state uses primary container */
    background: #000000;
    color: #ffffff;
    border-color: #000000;
}
.align-btn:hover:not(.active) { /* Hover for non-active buttons */
    background: var(--md-sys-color-surface-variant);
}

.social-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.layout-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.layout-grid.horizontal {
    flex-direction: row;
}

/* Preview Card Layout Variations */

/* Grid Style: Links are shown in 2 columns */
.card-layout.grid-view #links-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.card-layout.grid-view #links-container li {
    margin-bottom: 0;
}

/* Compact Style: Reduced padding and smaller elements */
.card-layout.compact-view main {
    padding: 12px;
}

.card-layout.compact-view h2 { font-size: 1.4rem; }
.card-layout.compact-view p { font-size: 0.85rem; margin-bottom: 16px; }
.card-layout.compact-view .socials-container { margin-bottom: 16px; gap: 8px; }
.card-layout.compact-view .social-link { width: 30px; height: 30px; }
.card-layout.compact-view .card-divider { margin-bottom: 16px; }
.card-layout.compact-view .link-btn { padding: 8px 16px; font-size: 0.9rem; border-radius: 8px; }

.layout-grid.horizontal .theme-card {
    flex: 1;
}

.layout-grid.horizontal .card-content {
    justify-content: center;
}

.theme-card {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--md-sys-color-surface-variant);
    background: var(--md-sys-color-surface-variant);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    color: var(--text-muted);
    user-select: none;
}

.theme-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.theme-card.active {
    border-color: var(--accent);
    background: var(--card-bg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Font selection previews */
#font-btn-sans .theme-name { font-family: "Inter", sans-serif; }
#font-btn-serif .theme-name { font-family: Georgia, serif; text-transform: none; }

/* Dynamic font preview for theme selection cards */
#editor-tab-layout.font-serif .theme-card:not([id^="font-btn-"]) .theme-name { font-family: Georgia, serif; text-transform: none; }
#editor-tab-layout.font-sans .theme-card:not([id^="font-btn-"]) .theme-name { font-family: "Inter", sans-serif; }

.theme-card .card-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: relative;
    z-index: 10;
}

.theme-info {
    flex: 1;
}

.theme-name {
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: var(--text-main);
    display: block;
    margin-bottom: 0;
}

.theme-desc {
    font-size: 11px;
    line-height: 1.3;
    margin: 0;
}

.theme-swatches {
    display: flex;
    align-items: center;
}

.swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-left: -8px;
    flex-shrink: 0;
}

.swatch:first-child {
    margin-left: 0;
}

.link-input-item { background: var(--card-bg); border: 1px solid var(--border); padding: 16px; border-radius: 12px; /* Rounded item cards */ margin-bottom: 16px; position: relative; box-shadow: 0 1px 3px rgba(0,0,0,0.05); } /* Subtle shadow */
.link-input-item input, .link-input-item textarea { width: 100%; border: 1px solid var(--md-sys-color-surface-variant); padding: 10px; margin-bottom: 8px; border-radius: 8px; /* Rounded inputs within items */ box-sizing: border-box; font-size: 13px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.link-input-item input:last-child { margin-bottom: 0; }

.remove-btn {
    position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 0; background: #ffffff; color: #000000; border: 1px solid #000000; 
    cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-primary { 
    background: #ffffff; 
    color: #000000; 
    border: 1.5px solid #000000; 
    padding: 10px; 
    border-radius: 20px; 
    cursor: pointer; 
    font-weight: 700; 
    width: 100%; 
    transition: all 0.2s; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); 
}
.btn-primary:hover { background-color: #000000; color: #ffffff; border-color: #000000; box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.btn-secondary { background: #ffffff; border: 1.5px solid #000000; padding: 5px 12px; border-radius: 20px; cursor: pointer; width: 100%; color: #000000; font-weight: 600; font-size: 13px; margin-bottom: 24px; transition: all 0.2s; }
.btn-secondary:hover { background: #000000; color: #ffffff; }

.social-icon-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px; /* Slightly reduced margin */
    margin-top: 8px;
}

.selector-btn {
    width: 40px;
    height: 40px;
    background: #fff;
    border: 1px solid #000000;
    border-radius: 12px; /* Rounded selector buttons */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-main);
    transition: all 0.2s;
}

.selector-btn svg {
    width: 20px;
    height: 20px;
}

/* Ensure all icon SVGs inherit the text color for proper inversion */
.app-nav a svg path,
.app-nav button svg path,
header a svg path,
.link-btn svg path,
.selector-btn svg path, 
.social-link svg path, 
.link-input-item svg path {
    fill: currentColor;
}

.selector-btn.active { /* Active state uses primary container */
    background: #000000;
    color: #ffffff;
    border-color: #000000;
}

.selector-btn:hover:not(.active) { /* Hover for non-active buttons */
    background: var(--md-sys-color-surface-variant);
    border-color: var(--md-sys-color-outline);
}

.sidebar-divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 8px 0 24px 0;
}

.security-container {
    margin-top: 24px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
}

.link-input-item svg {
    width: 100%;
    height: 100%;
}

.layout-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--md-sys-color-surface-variant); /* Lighter border */
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 8px; /* Rounded layout items */
    font-size: 13px;
    font-weight: 500;
    cursor: grab;
    user-select: none;
}
.reorder-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 6px; /* Slightly larger hit area */
}
.reorder-btn:hover { color: var(--text-main); }

.layout-item:active {
    cursor: grabbing;
}

.preview-pane {
    flex: 1; 
    background: #ffffff; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    padding: 20px; 
    overflow: hidden;
}

.content-area {
    display: flex;
    flex: 1; /* Take remaining vertical space */
    overflow: hidden; /* Hide overflow if content is too large */
}

/* Mobile View Switcher Bar */
.mobile-view-tabs {
    display: none; /* Hidden on desktop */
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.m-tab-btn {
    flex: 1;
    padding: 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.m-tab-btn.active {
    color: var(--text-main);
    border-bottom: 2px solid var(--text-main);
}

@media (max-width: 850px) {
    .app-shell {
        height: auto;
        overflow: visible;
    }
    .content-area {
        height: auto;
        overflow: visible;
        flex: none;
    }

    .mobile-view-tabs {
        display: flex;
    }

    .sidebar {
        height: auto;
        overflow-y: visible;
        width: 100%;
        border-left: none;
    }

    /* Logic to toggle visibility on mobile */
    .content-area.view-preview .sidebar {
        display: none;
    }
    .content-area.view-editor .preview-pane {
        display: none;
    }
    .preview-pane {
        height: auto;
        overflow-y: visible;
        align-items: flex-start;
    }
    .preview-pane .card-layout {
        margin: 0 auto;
        box-shadow: none;
    }
}

.card-layout { 
    width: 100%;
    max-width: 430px;
    min-height: 200px;
    background-color: var(--card-bg, #ffffff); /* Use theme card background */
    box-shadow: none;
    border: 1px solid #000;
    border-radius: 0;
    margin: 0 auto;
}

@media (min-width: 851px) {
    /* Show a fixed phone-like mockup with internal scrolling ONLY on desktop */
    .preview-pane .card-layout {
        min-height: 0;
        max-width: 360px;
        aspect-ratio: 9 / 16;
        height: auto;
        max-height: 85vh;
        margin: auto;
        overflow: hidden;
    }

    .preview-pane .card-layout main {
        overflow-y: auto;
        flex: 1;
    }
}

header {
    padding: 20px;
    text-align: center;
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-main);
}

header a {
    display: inline-block;
    padding: 8px 16px;
    background-color: var(--btn-bg, #ffffff);
    color: var(--btn-text, #000000);
    border: 1.5px solid var(--border, #000000);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
    font-weight: 700;
    margin: 4px;
    transition: all 0.2s;
}

header a:hover {
    background-color: var(--btn-text, #000000);
    color: var(--btn-bg, #ffffff);
}

h1, #main-heading { margin: 0; font-size: 1.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-main); }
h1, h2, p { transition: text-align 0.2s ease-in-out; } /* Smooth transition for alignment changes */

main {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.container {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
    width: 100%;
    text-align: center;
}

.socials-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.social-link {
    width: 36px;
    height: 36px;
    background-color: var(--btn-bg, #ffffff);
    color: var(--btn-text, #000000);
    border: 1.5px solid var(--border);
    border-radius: 50%; /* Circular social links */
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 700;
    font-size: 14px;
    transition: opacity 0.2s, transform 0.1s;
}

.social-link i,
.social-link svg {
    width: 18px; /* Adjusted for better visual balance */
    height: 18px; /* Adjusted for better visual balance */
    user-select: none;
}

.social-link:hover,
.social-link:active {
    background-color: var(--btn-text, #000000);
    color: var(--btn-bg, #ffffff);
    transform: translateY(-2px);
}

.card-divider {
    border: 0;
    border-top: 1px solid var(--border);
    width: 100%;
    margin-bottom: 20px; /* Slightly reduced margin */
}

h2 { margin-top: 0; font-size: 1.25rem; }
p { color: var(--text-muted); margin-bottom: 24px; }

ul { list-style: none; padding: 0; margin: 0; }
li { margin-bottom: 12px; }

.link-btn {
    display: block;
    padding: 12px 20px;
    background-color: var(--btn-bg, #ffffff);
    color: var(--btn-text, #000000);
    text-decoration: none;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-weight: 700;
    transition: transform 0.1s ease, opacity 0.2s ease;
}

.link-btn:hover,
.link-btn:active {
    background-color: var(--btn-text, #000000);
    color: var(--btn-bg, #ffffff);
    border-color: var(--btn-text, #000000);
    transform: translateY(-1px);
}

footer {
    padding: 10px 0 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    background-color: transparent;
    border-top: 1px solid var(--md-sys-color-surface-variant); /* Lighter border */
    color: var(--text-muted);
    font-size: 0.75rem;
}

footer p {
    margin: 0;
}

footer a {
    color: inherit;
    text-decoration: none;
}

.footer-links {
    margin-top: 0;
    display: flex;
    justify-content: center;
    gap: 16px;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    opacity: 0.8;
}

.footer-links a:hover {
    opacity: 1;
    text-decoration: underline;
}

.notification-banner {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--md-sys-color-inverse-surface); /* Darker background for notification */
    color: var(--md-sys-color-inverse-on-surface);
    padding: 12px 24px;
    font-weight: 500;
    border-radius: 8px; /* Rounded notification banner */
    font-size: 14px;
    z-index: 11000;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    border: 1px solid var(--border);
}

.notification-banner.show {
    transform: translateX(-50%) translateY(0);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none; /* Controlled by JS */
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.modal-content {
    background: var(--md-sys-color-surface);
    padding: 32px;
    max-width: 400px;
    width: 75%;
    position: relative;
    border: 1px solid var(--md-sys-color-outline);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15); /* Material You style shadow */
    border-radius: 28px; /* Large rounded corners for modal */
    text-align: center;
}

.modal-content h3 { margin-top: 0; }
.modal-content p { font-size: 14px; margin-bottom: 24px; }
.modal-actions {
    display: flex;
    gap: 12px;
}

/* Modal Close Button */
.modal-close-x {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-main);
    opacity: 0.5;
    transition: opacity 0.2s;
}
.modal-close-x:hover { opacity: 1; }

#published-modal .modal-content {
    max-width: 320px;
    padding: 24px;
}