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

:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 16px;
    --radius-sm: 12px;
    --header-gradient: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #60a5fa 100%);
    --icon-bg: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    --callout-bg: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    --callout-border: #bfdbfe;
    --code-bg: #1e293b;
    --code-text: #e2e8f0;
}

/* Dark Mode */
[data-theme="dark"] {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #1e293b;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5), 0 4px 6px -2px rgba(0,0,0,0.4);
    --header-gradient: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
    --icon-bg: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
    --callout-bg: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    --callout-border: #3b82f6;
    --code-bg: #0f172a;
    --code-text: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

/* Header */
header {
    position: relative;
    padding: 32px 0 60px;
    text-align: center;
    overflow: hidden;
}

.header-bg {
    position: absolute;
    inset: 0;
    background: var(--header-gradient);
    z-index: 0;
}

.header-bg::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60%;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 1200 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 60 C300 120 600 0 900 60 C1050 90 1150 80 1200 60 L1200 120 L0 120Z' fill='%23f8fafc'/%3E%3C/svg%3E") no-repeat bottom;
    background-size: 100% auto;
}

[data-theme="dark"] .header-bg::after {
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 1200 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 60 C300 120 600 0 900 60 C1050 90 1150 80 1200 60 L1200 120 L0 120Z' fill='%230f172a'/%3E%3C/svg%3E") no-repeat bottom;
    background-size: 100% auto;
}

.header-content {
    position: relative;
    z-index: 1;
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.theme-toggle {
    position: absolute;
    right: 24px;
    top: 24px;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
}

.theme-toggle svg {
    width: 22px;
    height: 22px;
}

.theme-toggle .icon-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: block;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: 50px;
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 1.2rem;
}

.logo-text {
    font-size: 1rem;
    font-weight: 700;
    color: white;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 6px;
}

header p {
    color: rgba(255,255,255,0.9);
    font-size: 1.1rem;
}

/* Search */
.search-box {
    position: relative;
    max-width: 540px;
    margin: -30px auto 48px;
}

.search-box input {
    width: 100%;
    padding: 16px 18px 16px 50px;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-size: 1rem;
    background: var(--card-bg);
    box-shadow: var(--shadow-lg);
    outline: none;
    transition: all 0.25s ease;
    color: var(--text);
}

.search-box input:hover {
    border-color: var(--primary-light);
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(37, 99, 235, 0.15);
}

[data-theme="dark"] .search-box input:focus {
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(96, 165, 250, 0.2);
}

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

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.2s;
}

.search-box input:focus + .search-icon,
.search-box:focus-within .search-icon {
    color: var(--primary);
}

.search-hint {
    position: absolute;
    bottom: -28px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.85rem;
    color: #475569;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.2s;
}

[data-theme="dark"] .search-hint {
    color: #94a3b8;
}

.search-hint strong {
    color: #1e40af;
    font-weight: 700;
}

[data-theme="dark"] .search-hint strong {
    color: #60a5fa;
}

.search-hint.visible {
    opacity: 1;
}

/* Search Highlight */
.highlight {
    background: rgba(37, 99, 235, 0.25);
    color: var(--primary);
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

[data-theme="dark"] .highlight {
    background: rgba(96, 165, 250, 0.3);
    color: #93c5fd;
}

/* Articles Grid - Side by Side */
.articles-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .articles-grid {
        grid-template-columns: 1fr;
    }
}

/* Article Card */
.article-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.article-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0;
    transition: opacity 0.25s;
}

.article-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
}

.article-card:hover::before {
    opacity: 1;
}

.article-card .card-icon {
    width: 42px;
    height: 42px;
    background: var(--icon-bg);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: 14px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Icon images */
.icon-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 4px;
}

.icon-img-lg {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 6px;
}

.article-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.4;
}

.article-card .excerpt {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-card .excerpt .read-more {
    color: var(--primary);
    font-weight: 500;
}

.match-score {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 20px;
    vertical-align: middle;
}

.article-card .meta {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.article-card .meta::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 50%;
}

/* Loading State */
.loading-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

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

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

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.empty-state p {
    font-size: 0.9rem;
}

.empty-state::before {
    content: '🔍';
    display: block;
    font-size: 2.5rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

.modal-overlay.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    max-width: 720px;
    width: 100%;
    margin: 40px 0;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

.modal-body {
    padding: 32px;
}

.modal-body .modal-icon {
    width: 60px;
    height: 60px;
    background: var(--icon-bg);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.modal-body .modal-icon .icon-img-lg {
    width: 40px;
    height: 40px;
}

.modal-body h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    padding-right: 40px;
    line-height: 1.3;
}

.modal-body .meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

/* Article Content */
.modal-body .content {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text);
}

.modal-body .content p {
    margin-bottom: 16px;
}

.modal-body .content h1,
.modal-body .content h2,
.modal-body .content h3 {
    margin-top: 28px;
    margin-bottom: 12px;
    color: var(--text);
    font-weight: 600;
}

.modal-body .content h1 { font-size: 1.4rem; }
.modal-body .content h2 { font-size: 1.2rem; }
.modal-body .content h3 { font-size: 1.1rem; }

.modal-body .content ul,
.modal-body .content ol {
    margin: 16px 0;
    padding-left: 24px;
}

.modal-body .content li {
    margin-bottom: 8px;
}

.modal-body .content a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.modal-body .content a:hover {
    text-decoration: underline;
}

.modal-body .content code {
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.85em;
    color: var(--primary-dark);
}

.modal-body .content pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 20px 0;
}

.modal-body .content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.modal-body .content blockquote {
    border-left: 4px solid var(--primary);
    padding: 12px 20px;
    margin: 20px 0;
    background: var(--bg);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.modal-body .content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 20px 0;
}

.modal-body .content figure {
    margin: 20px 0;
}

.modal-body .content hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 28px 0;
}

.modal-body .content .callout {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: var(--callout-bg);
    border-radius: var(--radius-sm);
    margin: 20px 0;
    border: 1px solid var(--callout-border);
}

.modal-body .content .callout span:first-child {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.modal-body .content details {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin: 16px 0;
    border: 1px solid var(--border);
}

.modal-body .content details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

/* Internal links (to other articles) */
.modal-body .content .internal-link {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--primary-light);
    cursor: pointer;
    transition: all 0.2s;
}

.modal-body .content .internal-link:hover {
    border-bottom-style: solid;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 2px;
}

.modal-body .content .loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Footer */
footer {
    margin-top: auto;
    padding: 24px 0;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

footer p {
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

footer p::before {
    content: '💡';
    font-size: 0.9rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 640px) {
    header {
        padding: 32px 0 60px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .search-box {
        margin-top: -32px;
    }
    
    .modal-body {
        padding: 24px;
    }
    
    .modal-body h2 {
        font-size: 1.25rem;
    }
}
