/* CSS Variables for Light/Dark Mode */
:root {
    /* Light Mode Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --accent-primary: #3182ce;
    --accent-secondary: #2c5282;
    --accent-hover: #2563eb;
    --border-color: #e2e8f0;
    --shadow-sm: rgba(0, 0, 0, 0.05);
    --shadow-md: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    --success: #48bb78;
    --error: #f56565;
    --warning: #ed8936;
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-tertiary: #cbd5e0;
    --accent-primary: #4299e1;
    --accent-secondary: #3182ce;
    --accent-hover: #63b3ed;
    --border-color: #4a5568;
    --shadow-sm: rgba(0, 0, 0, 0.2);
    --shadow-md: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.4);
    --success: #68d391;
    --error: #fc8181;
    --warning: #f6ad55;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

/* Header */
header {
    text-align: center;
    padding: 3rem 0 2rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Theme Toggle */
.theme-toggle-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 50px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

/* Search Section */
.search-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px var(--shadow-md);
}

.search-container {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

#searchInput {
    flex: 1;
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

#searchInput:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

#searchButton {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#searchButton:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-md);
}

#searchButton:active {
    transform: translateY(0);
}

/* Add after .search-input-wrapper styles */
.lucky-container {
    margin-top: 15px;
    text-align: center;
}

.lucky-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px var(--shadow-md);
}

.lucky-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px var(--shadow-md);
}

.lucky-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px var(--shadow-sm);
}

.mode-toggle {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.95rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mode-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* Results Section */
#results {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Character Cards */
.character-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.character-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--shadow-md);
    border-color: var(--accent-primary);
}

.main-character {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
    border: none;
}

.main-character h2,
.main-character p {
    color: white;
}

.character-card h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.character-card h4 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.show-name {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.main-character .show-name {
    color: rgba(255, 255, 255, 0.9);
}

.trope-count {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    font-weight: 600;
}

.main-character .trope-count {
    color: rgba(255, 255, 255, 0.8);
}

/* Tropes Section */
.tropes-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.tropes-section h3 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    border-bottom: 2px solid var(--accent-primary);
    padding-bottom: 0.5rem;
}

.trope-category {
    margin-bottom: 2rem;
}

.trope-category h4 {
    font-size: 1.2rem;
    color: var(--accent-primary);
    margin-bottom: 1rem;
}

.tropes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.trope-tag {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.trope-tag:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

/* Similar Characters Grid */
.similar-characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

#similar-characters h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.similar-card {
    cursor: pointer;
}

.similarity-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    overflow: hidden;
    margin: 1rem 0;
}

.similarity-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--success));
    border-radius: 10px;
    transition: width 0.5s ease;
}

.similarity-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Show Header */
.show-header {
    text-align: center;
    padding: 2rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 2rem;
}

.show-header h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.show-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Show Characters Grid */
.show-characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Loading and Error States */
.loading {
    text-align: center;
    padding: 3rem;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.error-message {
    background: var(--error);
    color: white;
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    margin-top: 4rem;
    border-top: 2px solid var(--border-color);
    color: var(--text-tertiary);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .search-container {
        flex-direction: column;
    }

    .similar-characters-grid,
    .show-characters-grid {
        grid-template-columns: 1fr;
    }

    .theme-toggle-container {
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Suggestions Dropdown */
.suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 80px;
    margin-top: 0.5rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.suggestion-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: var(--bg-secondary);
}

.suggestion-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.suggestion-content {
    flex: 1;
    min-width: 0;
}

.suggestion-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestion-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Make search container relative for dropdown positioning */
.search-container {
    position: relative;
}

/* Trope Tags as Links */
.trope-tag {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-decoration: none;
    cursor: pointer;
}

.trope-tag:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: scale(1.05);
    text-decoration: none;
}

.trope-tag:visited {
    color: var(--text-primary);
}

.trope-tag:hover:visited {
    color: white;
}

/* Add external link icon */
.trope-tag::after {
    content: " ↗";
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.trope-tag:hover::after {
    opacity: 1;
}