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

:root {
    /* Y2K Pink Theme with Cartoon Black Borders */
    --pink-light: #ffb6c1;
    --pink-main: #ff69b4;
    --pink-dark: #ff1493;
    --pink-glow: #ff85c0;
    --pink-pale: #fff0f5;
    --purple-accent: #da70d6;
    --blue-accent: #87ceeb;
    --white: #ffffff;
    --black: #111111;
    --gray-light: #f8f0f5;
    --gray-mid: #e8dce5;
    --text-dark: #111111;
    --text-light: #333333;
    --shadow-pink: rgba(255, 105, 180, 0.3);
    --glow-pink: rgba(255, 105, 180, 0.5);
    --border-cartoon: 3px solid #111111;
}

body {
    font-family: 'Comic Sans MS', 'Trebuchet MS', cursive, sans-serif;
    background: linear-gradient(135deg, var(--pink-pale) 0%, var(--white) 50%, var(--gray-light) 100%);
    color: var(--text-dark);
    min-height: 100vh;
    font-size: 13px;
}

/* Site Header */
.site-header {
    text-align: center;
    padding: 20px 12px 16px;
}

.site-title {
    font-size: 64px;
    font-weight: 900;
    color: var(--pink-main);
    text-shadow: 4px 4px 0 #111, -2px -2px 0 #111, 2px -2px 0 #111, -2px 2px 0 #111;
    margin: 0;
    letter-spacing: 8px;
    text-transform: uppercase;
}

.site-tagline {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-dark);
    margin: 8px 0 0;
    letter-spacing: 1px;
}

.site-ca {
    font-size: 12px;
    color: var(--text-light);
    margin: 6px 0 0;
    font-family: monospace;
}

.site-links {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
}

.header-link {
    padding: 8px 16px;
    background: var(--pink-main);
    border: 2px solid #111;
    color: #111;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 3px 3px 0 #111;
    transition: all 0.15s ease;
}

.header-link:hover {
    background: var(--pink-dark);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #111;
}

/* Sparkle animation */
@keyframes sparkle {
    0%, 100% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1); }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}

@keyframes shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

.app-container {
    display: flex;
    padding: 0 12px 12px;
    gap: 12px;
}

/* Sidebar Panel */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: linear-gradient(180deg, var(--white) 0%, var(--pink-pale) 100%);
    border: var(--border-cartoon);
    border-radius: 0;
    box-shadow: 5px 5px 0 #111;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 12px;
    height: fit-content;
    max-height: calc(100vh - 140px);
    overflow: hidden;
}

/* Title Bar with sparkles */
.logo {
    background: linear-gradient(90deg, var(--pink-main), var(--purple-accent), var(--pink-main));
    background-size: 200% auto;
    animation: shimmer 3s linear infinite;
    color: white;
    font-size: 20px;
    font-weight: bold;
    padding: 14px 16px;
    text-align: center;
    text-shadow: 2px 2px 0 #111;
    border-radius: 0;
    border-bottom: var(--border-cartoon);
    position: relative;
    letter-spacing: 3px;
}

.logo::before, .logo::after {
    content: '✦';
    position: absolute;
    animation: sparkle 2s ease-in-out infinite;
}

.logo::before {
    left: 20px;
    animation-delay: 0s;
}

.logo::after {
    right: 20px;
    animation-delay: 1s;
}

.logo span {
    color: white;
}

.sidebar-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    flex: 1;
}

.lore {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dark);
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    padding: 12px;
    box-shadow: 3px 3px 0 #111;
}

.section-title {
    font-size: 13px;
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Form Elements with Cartoon Style */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: bold;
    color: var(--text-dark);
    text-transform: uppercase;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 12px;
    font-size: 13px;
    font-family: inherit;
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    color: var(--text-dark);
    box-shadow: 3px 3px 0 #111;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--pink-main);
    box-shadow: 4px 4px 0 var(--pink-main);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

/* Generate Button */
.generate-btn {
    width: 100%;
    padding: 16px 20px;
    background: var(--pink-main);
    border: 3px solid #111;
    border-radius: 0;
    color: #111;
    font-size: 16px;
    font-weight: bold;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow: 5px 5px 0 #111;
    transition: all 0.15s ease;
}

.generate-btn:hover:not(:disabled) {
    background: var(--pink-dark);
    transform: translate(-2px, -2px);
    box-shadow: 7px 7px 0 #111;
}

.generate-btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #111;
}

.generate-btn:disabled {
    background: var(--gray-mid);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Reference Image Upload */
.reference-section {
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    padding: 12px;
    box-shadow: 3px 3px 0 #111;
}

.reference-section .section-title {
    font-size: 11px;
    margin-bottom: 10px;
}

.preview-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.preview-img {
    max-width: 100%;
    max-height: 70px;
    border-radius: 0;
    object-fit: contain;
    border: 2px solid #111;
}

.drop-zone {
    border: 2px dashed #111;
    border-radius: 0;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    background: var(--pink-pale);
    transition: all 0.2s ease;
}

.drop-zone:hover {
    background: var(--pink-light);
    border-style: solid;
}

.drop-zone.drag-over {
    background: var(--pink-light);
    border-style: solid;
}

.drop-zone-text {
    font-size: 11px;
    color: var(--text-dark);
    font-weight: bold;
}

.file-name {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 4px;
}

.clear-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: var(--pink-main);
    border: 2px solid #111;
    border-radius: 0;
    color: #111;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 #111;
}

.clear-btn:hover {
    background: var(--pink-dark);
}

/* Links Section */
.links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
    border-top: 2px solid #111;
}

.link-btn {
    padding: 8px 14px;
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    color: #111;
    text-decoration: none;
    font-size: 11px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 3px 3px 0 #111;
    transition: all 0.15s ease;
}

.link-btn:hover {
    background: var(--pink-light);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #111;
}

.link-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 #111;
}

.link-btn.active {
    background: var(--pink-main);
    color: #111;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: var(--border-cartoon);
    border-radius: 0;
    box-shadow: 5px 5px 0 #111;
    overflow: hidden;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: linear-gradient(180deg, var(--pink-pale) 0%, var(--white) 100%);
    border-bottom: var(--border-cartoon);
    gap: 12px;
}

.meme-count {
    font-size: 13px;
    font-weight: bold;
    color: var(--text-dark);
    background: var(--pink-light);
    padding: 6px 12px;
    border: 2px solid #111;
    box-shadow: 2px 2px 0 #111;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input {
    padding: 8px 12px;
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    color: var(--text-dark);
    font-size: 12px;
    font-family: inherit;
    width: 140px;
    box-shadow: 2px 2px 0 #111;
}

.search-input:focus {
    outline: none;
    border-color: var(--pink-main);
}

.sort-select {
    padding: 8px 12px;
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    color: var(--text-dark);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 2px 2px 0 #111;
}

/* Grid Area */
.grid-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--pink-pale);
    margin: 8px;
    border: 2px solid #111;
    box-shadow: inset 3px 3px 0 rgba(0,0,0,0.1);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.grid.zoom-1 { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.grid.zoom-2 { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid.zoom-3 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.zoom-4 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.zoom-5 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

/* Grid Item with Cartoon Border */
.grid-item {
    background: var(--white);
    border: 3px solid #111;
    border-radius: 0;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: 4px 4px 0 #111;
    position: relative;
}

.grid-item:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #111;
}

.grid-item:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 #111;
}

.grid-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--pink-pale);
}

.grid-item .prompt {
    padding: 8px 10px;
    font-size: 10px;
    color: var(--text-dark);
    background: var(--white);
    border-top: 2px solid #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
}

/* Pending/Processing States */
.grid-item.pending,
.grid-item.processing {
    opacity: 0.9;
}

.grid-item.pending img,
.grid-item.processing img {
    filter: grayscale(30%) brightness(1.1);
}

.pending-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 182, 193, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #111;
    font-weight: bold;
    border-radius: 0;
}

.processing-bar {
    width: 70%;
    height: 10px;
    background: var(--white);
    border: 2px solid #111;
    border-radius: 0;
    margin-top: 8px;
    overflow: hidden;
}

.processing-fill {
    height: 100%;
    background: var(--pink-main);
    border-radius: 0;
    animation: progress 1.5s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 10%; }
    50% { width: 90%; }
    100% { width: 10%; }
}

/* Loading States */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px;
    color: var(--text-dark);
    font-weight: bold;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--pink-light);
    border-top-color: var(--pink-main);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.load-more {
    display: block;
    margin: 16px auto;
    padding: 12px 24px;
    background: var(--pink-main);
    border: 3px solid #111;
    border-radius: 0;
    color: #111;
    font-size: 13px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 4px 4px 0 #111;
    transition: all 0.15s ease;
}

.load-more:hover {
    background: var(--pink-dark);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #111;
}

/* Image Viewer Modal */
.image-viewer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.image-viewer.active {
    display: flex;
}

.viewer-content {
    background: var(--white);
    border: 4px solid #111;
    border-radius: 0;
    box-shadow: 10px 10px 0 rgba(0,0,0,0.5);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viewer-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
}

.viewer-prompt {
    padding: 14px 18px;
    font-size: 14px;
    color: var(--text-dark);
    background: var(--pink-pale);
    border-top: 3px solid #111;
    font-weight: bold;
}

.viewer-actions {
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    background: var(--white);
    border-top: 2px solid #111;
}

.viewer-btn {
    padding: 10px 18px;
    background: var(--pink-main);
    border: 2px solid #111;
    border-radius: 0;
    color: #111;
    font-size: 12px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 3px 3px 0 #111;
    transition: all 0.15s ease;
}

.viewer-btn:hover {
    background: var(--pink-dark);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #111;
}

.close-viewer {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    font-weight: bold;
    text-shadow: 2px 2px 0 #111;
    transition: transform 0.2s ease;
}

.close-viewer:hover {
    transform: scale(1.2);
    color: var(--pink-main);
}

/* Viewer created by JS */
.viewer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.viewer.active {
    display: flex;
}

.viewer .viewer-content {
    background: var(--white);
    border: 4px solid #111;
    border-radius: 0;
    box-shadow: 10px 10px 0 rgba(0,0,0,0.5);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viewer .viewer-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
}

.viewer-buttons {
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    background: var(--white);
    border-top: 3px solid #111;
}

.viewer-buttons button,
.viewer-buttons a {
    padding: 10px 18px;
    background: var(--pink-main);
    border: 2px solid #111;
    border-radius: 0;
    color: #111;
    font-size: 12px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 3px 3px 0 #111;
    transition: all 0.15s ease;
    text-decoration: none;
    text-align: center;
}

.viewer-buttons button:hover,
.viewer-buttons a:hover {
    background: var(--pink-dark);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #111;
}

/* Pending spinner in grid */
.pending-spinner {
    width: 100%;
    aspect-ratio: 1;
    background: var(--pink-pale);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid #111;
}

.prompt-text {
    padding: 8px 10px;
    font-size: 10px;
    color: var(--text-dark);
    background: var(--white);
    border-top: 2px solid #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
}

.ref-tag {
    color: var(--pink-main);
    font-weight: bold;
}

/* Flash Messages */
.flash-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flash {
    padding: 14px 20px;
    background: var(--white);
    border: 3px solid #111;
    border-radius: 0;
    box-shadow: 4px 4px 0 #111;
    font-weight: bold;
    max-width: 350px;
    animation: slideIn 0.3s ease;
}

.flash.success {
    background: #90EE90;
}

.flash.error {
    background: #FFB6C1;
}

.flash.warning {
    background: #FFE4B5;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1500;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--white);
    border: 4px solid #111;
    border-radius: 0;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 8px 8px 0 #111;
}

.modal-content h3 {
    font-size: 18px;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-form label {
    font-size: 12px;
    font-weight: bold;
}

.modal-form input,
.modal-form select {
    padding: 10px;
    border: 2px solid #111;
    border-radius: 0;
    font-family: inherit;
    box-shadow: 2px 2px 0 #111;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dark);
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 10px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-light);
}

/* Responsive */
@media (max-width: 900px) {
    .site-title {
        font-size: 48px;
    }
    
    .app-container {
        flex-direction: column;
        padding: 8px;
    }
    
    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        position: relative;
        top: 0;
        max-height: none;
    }
    
    .sidebar-content {
        max-height: 300px;
        overflow-y: auto;
    }
    
    .main-content {
        min-height: 60vh;
        height: auto;
    }
    
    .grid-wrapper {
        min-height: 400px;
        overflow-y: auto;
    }
    
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 500px) {
    .site-title {
        font-size: 36px;
        letter-spacing: 4px;
    }
    
    .site-tagline {
        font-size: 12px;
    }
    
    .site-ca {
        font-size: 9px;
        word-break: break-all;
    }
    
    .toolbar {
        flex-wrap: wrap;
    }
    
    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .grid-wrapper {
        min-height: 50vh;
    }
    
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* CA Copy Button */
.ca-section {
    background: var(--white);
    border: 2px solid #111;
    padding: 10px;
    box-shadow: 3px 3px 0 #111;
}

.ca-btn {
    width: 100%;
    padding: 10px;
    background: var(--pink-light);
    border: 2px solid #111;
    border-radius: 0;
    font-family: inherit;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 2px 2px 0 #111;
    transition: all 0.15s ease;
}

.ca-btn:hover {
    background: var(--pink-main);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 #111;
}

.ca-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 #111;
}

/* Placeholder for pending items */
.placeholder-box {
    width: 100%;
    aspect-ratio: 1;
    background: var(--pink-pale);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Tutorial Overlay */
.tutorial-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.tutorial-overlay.active {
    display: flex;
}

.tutorial-content {
    background: var(--white);
    border: 4px solid #111;
    box-shadow: 10px 10px 0 #111;
    max-width: 400px;
    width: 90%;
    padding: 30px;
    text-align: center;
    position: relative;
}

.tutorial-header {
    font-size: 24px;
    font-weight: bold;
    color: var(--pink-main);
    text-shadow: 2px 2px 0 #111;
    margin-bottom: 16px;
}

.tutorial-body {
    font-size: 14px;
    color: var(--text-dark);
    margin-bottom: 20px;
    line-height: 1.6;
}

.tutorial-body ul {
    text-align: left;
    margin: 10px 0;
    padding-left: 20px;
}

.tutorial-body li {
    margin: 6px 0;
    font-style: italic;
}

.tutorial-btn {
    padding: 14px 30px;
    background: var(--pink-main);
    border: 3px solid #111;
    color: #111;
    font-size: 16px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 4px 4px 0 #111;
    transition: all 0.15s ease;
}

.tutorial-btn:hover {
    background: var(--pink-dark);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #111;
}

.tutorial-skip {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 6px 12px;
    background: transparent;
    border: 2px solid #111;
    color: var(--text-light);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
}

.tutorial-skip:hover {
    background: var(--pink-pale);
}
