* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --bg: #0f172a;
    --bg-light: #1e293b;
    --bg-card: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --error: #ef4444;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 2rem 1rem;
    text-align: center;
    box-shadow: 0 4px 6px var(--shadow);
}

.header-content h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: white;
}

.header-content p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

/* Search */
.search-wrapper {
    padding: 1.5rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.search-box {
    position: relative;
    max-width: 500px;
    margin: 0 auto;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 0.875rem 3rem 0.875rem 3rem;
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s ease;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.clear-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.clear-btn:hover {
    background: var(--bg-card);
    color: var(--text);
}

.clear-btn.show {
    display: flex;
}

/* Loader */
.loader {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    gap: 1rem;
}

.loader.show {
    display: flex;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader p {
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding-bottom: 2rem;
}

/* Character Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 8px 24px var(--shadow);
}

.card:hover::before {
    transform: scaleX(1);
}

.card-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 0.75rem;
    border: 3px solid var(--primary);
    background: var(--bg-light);
}

.card-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.card-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: auto;
}

.star {
    font-size: 0.9rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow-y: auto;
}

.modal.show {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-light);
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Fetch Section */
.fetch-section {
    text-align: center;
    padding: 2rem;
}

.fetch-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.fetch-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.fetch-btn:active {
    transform: translateY(0);
}

.fetch-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Details Section */
.details-section {
    margin-top: 1.5rem;
}

.info-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.info-item {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.info-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.info-value {
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Prompt Section */
.prompt-section {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.prompt-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

.prompt-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: var(--bg-light);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateY(-2px);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.prompt-content {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 0.875rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
    color: var(--text);
}

.prompt-content::-webkit-scrollbar {
    width: 8px;
}

.prompt-content::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 4px;
}

.prompt-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.prompt-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    display: none;
    z-index: 2000;
    animation: toastSlide 0.3s ease;
    max-width: 300px;
}

.toast.show {
    display: block;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--error);
}

@keyframes toastSlide {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .header-content h1 {
        font-size: 1.5rem;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .card {
        padding: 1rem;
    }

    .card-avatar {
        width: 60px;
        height: 60px;
    }

    .modal-container {
        margin: 1rem;
        max-height: 95vh;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .prompt-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toast {
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .card-name {
        font-size: 0.9rem;
    }

    .card-desc {
        font-size: 0.8rem;
    }
}
