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

svg.hand-drawn-filter {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
}

:root {
    --bg-primary: #f0f0f0;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #e0e0e0;
    --text-primary: #000000;
    --text-secondary: #333333;
    --text-muted: #666666;
    --accent: #e53935;
    --accent-hover: #c62828;
    --border: #000000;
    --success: #22c55e;
    --error: #ef4444;
}

body {
    font-family: 'Comic Sans MS', 'Comic Sans', 'Chalkboard SE', 'Comic Neue', cursive;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

.app-container {
    display: flex;
    min-height: 100vh;
    align-items: flex-start;
}

.sidebar-wrapper {
    display: flex;
    align-items: flex-start;
    padding: 24px;
}

.sidebar {
    width: 320px;
    min-width: 320px;
    background: #ffffff;
    border: none;
    border-radius: 2px;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: fit-content;
    overflow: visible;
    position: relative;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: #ffffff;
    border: 3px solid #000000;
    border-radius: 2px;
    box-shadow: 5px 5px 0 #000000;
    filter: url(#squiggle);
    z-index: -1;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--accent);
}

.lore {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.prompt-input {
    width: 100%;
    padding: 14px 16px;
    background: #ffffff;
    border: 3px solid #000000;
    border-radius: 2px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: 4px 4px 0 #000000;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 4px 4px 0 var(--accent);
}

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

.generate-btn {
    width: 100%;
    padding: 14px 20px;
    background: var(--accent);
    border: 3px solid #000000;
    border-radius: 2px;
    color: white;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 4px 4px 0 #000000;
    text-transform: uppercase;
}

.generate-btn:hover {
    background: var(--accent-hover);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000000;
}

.generate-btn:active {
    transform: translate(3px, 3px);
    box-shadow: 1px 1px 0 #000000;
}

.upload-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-input {
    display: none;
}

.file-label {
    display: block;
    padding: 12px 16px;
    background: #ffffff;
    border: 3px dashed #000000;
    border-radius: 2px;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.file-label:hover {
    border-color: var(--accent);
    color: var(--text-secondary);
}

.file-input:focus + .file-label {
    border-color: var(--accent);
    box-shadow: 4px 4px 0 var(--accent);
}

.file-label.drag-over {
    border-color: var(--accent);
    border-style: solid;
    background: #fff5f5;
    box-shadow: 4px 4px 0 var(--accent);
    color: var(--accent);
}

.file-label.has-file {
    border-color: #000000;
    border-style: solid;
    background: #ffffff;
    color: var(--text-primary);
    padding: 8px;
    box-shadow: 4px 4px 0 #000000;
}

.preview-img {
    max-width: 100%;
    max-height: 80px;
    border-radius: 6px;
    object-fit: contain;
}

.drop-zone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.clear-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--text-muted);
    color: white;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    background: #e74c3c;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 4px;
}

.ref-tag {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 0.7em;
    padding: 2px 6px;
    border: 2px solid #000000;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.links-section {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

.link-btn {
    padding: 8px 14px;
    background: #ffffff;
    border: 2px solid #000000;
    border-radius: 4px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.1s ease;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 2px 2px 0 #000000;
}

.link-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 #000000;
}

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

.link-btn.ca-btn {
    font-size: 11px;
    padding: 6px 10px;
}

.main-content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.stats {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stats strong {
    color: var(--text-primary);
    font-weight: 600;
}

.search-sort {
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-input {
    padding: 10px 14px;
    background: #ffffff;
    border: 2px solid #000000;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    width: 200px;
    transition: all 0.2s ease;
    box-shadow: 2px 2px 0 #000000;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 2px 2px 0 var(--accent);
}

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

.sort-select {
    padding: 10px 14px;
    background: #ffffff;
    border: 2px solid #000000;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 2px 2px 0 #000000;
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 2px 2px 0 var(--accent);
}

.zoom-controls {
    display: flex;
    gap: 4px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background: #ffffff;
    border: 2px solid #000000;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 #000000;
}

.zoom-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 #000000;
}

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

.gif-btn {
    padding: 6px 12px;
    background: var(--accent);
    border: 2px solid #000000;
    border-radius: 4px;
    color: white;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 2px 2px 0 #000000;
}

.gif-btn:hover {
    background: var(--accent-hover);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 #000000;
}

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

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

.grid-item {
    background: #ffffff;
    border-radius: 2px;
    overflow: visible;
    transition: all 0.1s ease;
    cursor: pointer;
    border: none;
    position: relative;
}

.grid-item::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: #ffffff;
    border: 3px solid #000000;
    border-radius: 2px;
    box-shadow: 4px 4px 0 #000000;
    filter: url(#squiggle);
    z-index: -1;
    transition: all 0.1s ease;
}

.grid-item:hover {
    transform: translate(-2px, -2px);
}

.grid-item:hover::before {
    box-shadow: 6px 6px 0 #000000;
}

.grid-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.grid-item .prompt-text {
    padding: 12px;
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    border-top: 2px solid #000000;
}

.grid-item.pending {
    background: var(--bg-hover);
}

.grid.compact-mode .grid-item .prompt-text {
    display: none;
}

.grid.compact-mode .grid-item {
    border-radius: 4px;
}

.pending-spinner {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
}

.pending-spinner .spinner {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

.message {
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    border-left: 3px solid var(--accent);
}

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

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

.queue-box {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.queue-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.queue-icon {
    animation: spin 2s linear infinite;
}

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

.queue-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 13px;
}

.queue-item.processing {
    border: 1px solid var(--accent);
}

.queue-status {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 24px;
}

.pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.queue-prompt {
    color: var(--text-secondary);
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

.load-indicator {
    display: none;
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}

.load-indicator.visible {
    display: block;
}

.viewer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.viewer.active {
    display: flex;
}

.viewer-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    max-width: 80vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.viewer img {
    max-width: 100%;
    max-height: calc(80vh - 120px);
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 16px;
}

.viewer-prompt {
    font-size: 15px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
}

.viewer-buttons {
    display: flex;
    gap: 12px;
}

.viewer-buttons button {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.viewer-buttons button:hover,
.viewer-buttons .download-link:hover {
    background: var(--bg-hover);
}

.viewer-buttons .download-link {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
}

@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        position: relative;
        padding: 24px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .links-section {
        margin-top: 16px;
    }
    
    .main-content {
        padding: 24px;
    }
    
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .search-sort {
        flex-wrap: wrap;
    }
    
    .search-input {
        flex: 1;
        min-width: 150px;
    }
    
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }
}

@media (max-width: 500px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .sidebar {
        padding: 20px 16px;
    }
    
    .main-content {
        padding: 16px;
    }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-primary);
}

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

.modal-form label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-form input,
.modal-form select {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
}

.modal-form input:focus,
.modal-form select:focus {
    outline: none;
    border-color: var(--accent);
}

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

.modal-buttons button {
    flex: 1;
    padding: 12px 16px;
}

.gif-status {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.gif-status .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
}
