:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --surface: #1e293b;
    --border: #334155;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.25);
    --glass-bg: rgba(30, 41, 59, 0.75);
    --glass-border: rgba(255, 255, 255, 0.12);
}

[data-theme="light"] {
    --bg-color: #f1f5f9;
    --text-color: #0f172a;
    --text-muted: #475569;
    --surface: #ffffff;
    --border: #cbd5e1;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.12);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.main-logo {
    width: 280px;
    height: auto;
    max-width: 85vw;
    margin: 0 auto -4.5rem auto;
    display: block;
    cursor: pointer;
    transition: transform 0.3s ease, filter 0.3s ease;
}

[data-theme="light"] .main-logo {
    filter: invert(1) hue-rotate(180deg);
}
.theme-toggle {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, background 0.3s;
    color: var(--text-color);
    z-index: 50;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}

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

.theme-toggle svg {
    width: 24px;
    height: 24px;
    transition: opacity 0.3s ease, transform 0.4s ease;
    pointer-events: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}

.theme-toggle .theme-icon-hidden {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
    position: absolute;
}

.theme-toggle .theme-icon-visible {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

#searchInput, .chip, .suggestion-item, .result-card {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 2rem 1.25rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Grid layout for search results page (Bing/Google style) */
body.searched .container {
    display: grid;
    max-width: 1100px;
    width: 100%;
    grid-template-columns: 140px minmax(auto, 680px);
    justify-content: center;
    gap: 1.5rem 2rem;
    align-items: start;
    padding-top: 1.5rem;
}

/* Header & Logo */
.header {
    text-align: center;
    margin-top: 14vh;
    margin-bottom: 0;
    transition: all 0.4s ease-in-out;
}

body.searched .header {
    grid-column: 1;
    grid-row: 1;
    margin-top: 0;
    margin-bottom: 0;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    align-self: center;
}

.main-logo:hover {
    transform: scale(1.03);
}

body.searched .main-logo {
    width: 130px;
    margin-bottom: 0;
}

/* Search Section */
.search-section {
    position: relative;
    width: 100%;
    margin-bottom: 2rem;
    transition: all 0.4s ease-in-out;
}

body.searched .search-section {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    max-width: 680px;
    margin-bottom: 0;
    align-self: center;
    justify-self: start;
}

body.searched .results-container {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 100%;
    max-width: 100%;
    justify-self: start;
}

body.searched #loader {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    justify-self: center;
    margin-top: 2rem;
}

.search-box {
    width: 100%;
    display: flex;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    padding: 0.5rem 0.5rem 0.5rem 1.25rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.search-box:focus-within {
    border-color: rgba(96, 165, 250, 0.6);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2), var(--shadow);
    transform: translateY(-2px);
}

.search-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

#searchInput {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.05rem;
    padding: 0.6rem 0.75rem;
    outline: none;
    font-family: inherit;
    min-width: 0;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    margin-right: 0.4rem;
    flex-shrink: 0;
}

.clear-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.1);
}

.search-button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.7rem 1.4rem;
    border-radius: 9999px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    flex-shrink: 0;
}

.search-button:hover {
    background: var(--primary-hover);
    transform: scale(1.04);
}

.search-button:active {
    transform: scale(0.96);
}

/* Quick Suggestion Chips */
.quick-chips {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
    transition: opacity 0.3s ease;
}

body.searched .quick-chips {
    display: none !important;
}

.chip {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0.4rem 0.9rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}

.chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Suggestions Box */
.suggestions-box {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    list-style: none;
    padding: 0.5rem 0;
    z-index: 500;
    max-height: 50vh;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.suggestions-box::-webkit-scrollbar {
    display: none;
}

.suggestions-box.hidden {
    display: none;
}

.suggestion-item {
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    color: var(--text-color);
    font-size: 0.95rem;
    transition: background 0.2s;
}

.suggestion-item:hover {
    background: rgba(100, 100, 100, 0.15);
}

.suggestion-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    color: var(--text-muted);
}

/* Loader */
.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 3rem 0;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s ease-in-out infinite;
    margin-bottom: 1rem;
}

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

.hidden {
    display: none !important;
}

/* Results Area */
.results-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-bottom: 3rem;
}

.results-stats {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    animation: fadeUp 0.35s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: rgba(96, 165, 250, 0.3);
}

.result-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
}

.result-favicon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    object-fit: contain;
    background: white;
    padding: 2px;
}

.result-url {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-title {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0.6rem;
}

.result-title a {
    color: #60a5fa;
    text-decoration: none;
}

.result-title a:hover {
    text-decoration: underline;
}

.result-snippet {
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--text-muted);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    padding: 1.25rem;
    border-radius: 12px;
    text-align: center;
}

/* Footer */
.footer {
    margin-top: auto;
    padding: 1.5rem 0 0.5rem 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

body.searched .footer {
    grid-column: 1 / 3;
    grid-row: 3;
}

/* ========== MOBILE BREAKPOINTS ========== */
@media (max-width: 768px) {
    .container {
        padding: 1.25rem 1rem;
    }
    
    .search-box {
        padding: 0.25rem 0.25rem 0.25rem 0.85rem;
    }
    
    #searchInput {
        font-size: 0.95rem;
        padding: 0.5rem 0.4rem;
    }
    
    .search-button {
        padding: 0.55rem 0.9rem;
        font-size: 0.88rem;
    }
    
    /* Home page mobile */
    .header {
        margin-top: 10vh;
        margin-bottom: 0;
    }
    
    .main-logo {
        width: 240px;
        max-width: 80vw;
        margin: 0 auto -3.2rem auto;
    }
    
    .quick-chips {
        gap: 0.4rem;
    }
    
    .chip {
        font-size: 0.8rem;
        padding: 0.35rem 0.75rem;
    }
    
    .suggestions-box {
        max-height: 40vh;
        border-radius: 16px;
        padding: 0.35rem 0;
    }
    
    .suggestion-item {
        padding: 0.55rem 0.9rem;
        font-size: 0.88rem;
    }
    
    .suggestion-icon {
        width: 14px;
        height: 14px;
        margin-right: 8px;
    }
    
    /* Searched layout mobile */
    body.searched .container {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 1rem;
    }
    
    body.searched .header {
        margin-top: 0;
        justify-content: center;
        text-align: center;
    }
    
    body.searched .main-logo {
        width: 110px;
        margin-bottom: 0;
    }
    
    body.searched .search-section {
        width: 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }
    
    body.searched .results-container {
        width: 100%;
        max-width: 100%;
    }
    
    body.searched #loader {
        align-self: center;
        margin-top: 2rem;
        width: 100%;
        text-align: center;
    }

    body.searched .footer {
        grid-column: auto;
        grid-row: auto;
    }
}
