:root {
    /* Light Theme */
    --bg-color: #f8f9fa;
    --bg-card: #ffffff;
    --text-color: #202124;
    --text-secondary: #5f6368;
    --link-color: #1a0dab;
    --visited-color: #609;
    --url-color: #202124;
    --accent-color: #4285f4;
    --border-color: #dadce0;
    --hover-bg: #f1f3f4;
    --input-bg: #ffffff;
    --input-border: #dfe1e5;
    --input-hover-shadow: 0 1px 6px rgba(32,33,36,0.28);
    --card-bg: #ffffff;
    --card-shadow: 0 1px 2px rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    --card-shadow-hover: 0 2px 4px rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15);
    --header-bg: rgba(255, 255, 255, 1);
    --badge-bg: #f1f3f4;
    --badge-text: #5f6368;
    --official-bg: #4285f4;
    --official-text: #ffffff;
    
    /* Hot Ranks */
    --rank-1: #fe2d46;
    --rank-2: #ff6600;
    --rank-3: #faa90e;
    --rank-other: #9195a3;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Theme */
        --bg-color: #202124;
        --bg-card: #303134;
        --text-color: #e8eaed;
        --text-secondary: #9aa0a6;
        --link-color: #8ab4f8;
        --visited-color: #c58af9;
        --url-color: #e8eaed;
        --accent-color: #8ab4f8;
        --border-color: #3c4043;
        --hover-bg: #3c4043;
        --input-bg: #303134;
        --input-border: #5f6368;
        --input-hover-shadow: 0 1px 6px rgba(0,0,0,0.5);
        --card-bg: #303134;
        --card-shadow: 0 1px 2px rgba(0,0,0,0.5);
        --card-shadow-hover: 0 2px 4px rgba(0,0,0,0.5);
        --header-bg: #202124;
        --badge-bg: #3c4043;
        --badge-text: #bdc1c6;
        --official-bg: #8ab4f8;
        --official-text: #202124;
    }
}

* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    line-height: 1.58;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Prevent horizontal scroll on mobile */
}
a { text-decoration: none; color: inherit; transition: color 0.2s; }
.container {
    width: 100%;
    padding-right: 20px;
    padding-left: 20px;
    margin-right: auto;
    margin-left: auto;
}
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Search History Dropdown */
.search-history-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 24px 24px;
    box-shadow: 0 4px 6px rgba(32,33,36,0.28);
    z-index: 1000;
    overflow: hidden;
    display: none;
    padding-bottom: 8px;
    margin-top: -1px; /* Overlap border */
}

/* Adjust input border radius when dropdown is open */
.search-input-wrapper.has-dropdown .search-input {
    border-radius: 24px 24px 0 0;
    border-bottom: 1px solid transparent;
    box-shadow: var(--input-hover-shadow);
    z-index: 1001; /* Keep input above dropdown for clean border merge */
    position: relative;
}

.search-input-wrapper.has-dropdown .search-history-dropdown {
    display: block;
    border-top: none;
    border-radius: 0 0 24px 24px;
    box-shadow: var(--input-hover-shadow);
    margin-top: -1px;
    z-index: 1000;
}
.history-item {
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.history-item:hover { background-color: var(--hover-bg); }
.history-text { flex: 1; display: flex; align-items: center; }
.history-text::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239aa0a6'%3E%3Cpath d='M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 1 13 21a9 9 0 0 1 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.6;
}
.history-delete {
    color: var(--text-secondary);
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
    display: none;
    border-radius: 4px;
}
.history-item:hover .history-delete { display: block; }
.history-delete:hover { color: var(--text-color); background-color: rgba(0,0,0,0.1); }

/* Home Layout */
.home-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    padding: 20px;
}
.home-logo {
    font-size: 4rem;
    font-weight: 500;
    margin-bottom: 2rem;
    user-select: none;
    letter-spacing: -2px;
    color: var(--text-color);
}
.home-logo span { color: var(--accent-color); }
.home-search-container { width: 100%; max-width: 584px; position: relative; }
.search-input-wrapper { position: relative; width: 100%; }
.search-input {
    width: 100%;
    padding: 12px 44px;
    border-radius: 24px;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 16px;
    outline: none;
    transition: box-shadow 0.2s, background-color 0.2s, border-color 0.2s;
}
.search-input:hover, .search-input:focus {
    background-color: var(--input-bg);
    box-shadow: var(--input-hover-shadow);
    border-color: transparent;
}
.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    width: 20px;
    height: 20px;
}
.search-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent-color);
    padding: 0;
}
.search-btn svg { fill: currentColor; }

.results-header {
    display: flex;
    align-items: center;
    padding: 16px 30px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 40px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.header-logo {
    font-size: 24px;
    font-weight: 500;
    letter-spacing: -1px;
    color: var(--text-color);
    flex-shrink: 0;
    margin-bottom: 0;
    text-decoration: none;
    margin-right: 0;
}

.header-search-form {
    flex: 1;
    max-width: 690px;
}
.header-logo span { color: var(--accent-color); }

/* Results Layout */
.results-input {
    padding: 10px 44px;
    box-shadow: none;
    border: 1px solid transparent;
    background-color: var(--hover-bg);
}

.results-input:hover,
.results-input:focus {
    background-color: var(--input-bg);
    box-shadow: 0 1px 6px rgba(32,33,36,0.28);
    border-color: transparent;
}

.results-main {
    display: flex;
    padding: 20px 30px;
    padding-left: 160px; /* Restored indentation to align with search bar */
    max-width: 1500px; /* Increased max-width to allow wider results */
    margin: 0;
}
.results-grid { display: flex; gap: 60px; flex-wrap: wrap; width: 100%; }
.results-list { flex: 1; max-width: 650px; /* Adjusted to 650px based on user feedback (too wide at 750px) */ }
.results-sidebar { width: 368px; flex-shrink: 0; }
.result-stats {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    display: flex;
    align-items: center;
    opacity: 0.8;
}

.result-stats span {
    display: inline-flex;
    align-items: center;
}
.result-stats svg { margin-right: 4px; color: var(--text-secondary); }

/* Result Item */
.result-item {
    width: 100%;
    margin-bottom: 20px;
    padding: 20px;
    border-radius: 12px;
    background-color: var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.result-item:hover { box-shadow: var(--card-shadow); }
.result-meta { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; font-size: 14px; color: var(--text-color); }
.result-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--hover-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: var(--text-secondary);
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.result-icon img { width: 100%; height: 100%; object-fit: cover; }
.result-site-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.result-site-name { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-url { color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-title {
    display: block;
    font-size: 20px;
    color: var(--link-color);
    font-weight: 400;
    line-height: 1.3;
    margin-bottom: 8px;
    word-break: break-word; 
    text-decoration: none;
}
.result-title:hover { text-decoration: underline; }
.result-snippet { font-size: 14px; color: var(--text-secondary); line-height: 1.6; word-break: break-word; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 8px;
    vertical-align: middle;
}
.badge-official { background-color: var(--official-bg); color: var(--official-text); }
.badge-ad { border: 1px solid var(--text-secondary); color: var(--text-secondary); border-radius: 2px; font-weight: bold; }

/* Sidebar Widgets */
.hot-search-card {
    border: none;
    border-radius: 16px;
    padding: 0;
    background-color: var(--bg-card);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    margin-bottom: 24px;
}
.hot-search-header {
    font-size: 16px;
    font-weight: 600;
    padding: 16px 20px;
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}
.hot-search-list { list-style: none; padding: 8px 0; margin: 0; }
.hot-search-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: none;
    transition: background-color 0.2s;
}
.hot-search-item:hover { background-color: var(--hover-bg); }
.hot-search-rank {
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    font-weight: 700;
    margin-right: 12px;
    font-size: 14px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-style: normal;
    background-color: var(--hover-bg);
}
.hot-search-item:nth-child(1) .hot-search-rank { background-color: var(--rank-1); color: #fff; }
.hot-search-item:nth-child(2) .hot-search-rank { background-color: var(--rank-2); color: #fff; }
.hot-search-item:nth-child(3) .hot-search-rank { background-color: var(--rank-3); color: #fff; }
.hot-search-link {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    color: var(--text-color);
    line-height: 1.4;
    font-weight: 500;
}
.hot-search-link:hover { text-decoration: none; color: var(--link-color); }

/* Pagination */
.pagination {
    margin-top: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
.page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border-radius: 4px;
    color: var(--text-color);
    font-size: 14px;
    cursor: pointer;
}
.page-link:hover { background-color: var(--hover-bg); text-decoration: none; }
.page-link.active { background-color: var(--hover-bg); font-weight: bold; color: var(--text-color); }

/* Footer */
.footer {
    background-color: var(--bg-card);
    color: var(--text-secondary);
    padding: 20px;
    font-size: 14px;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

.footer-content {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 24px;
}

.footer a {
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--text-color);
    text-decoration: underline;
}

/* Card Group Styles */
.card-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-section-title::before {
    content: '';
    display: block;
    width: 4px;
    height: 14px;
    background-color: var(--accent-color);
    margin-right: 8px;
    border-radius: 2px;
}

.card-group-wrapper {
    position: relative;
    margin: 0 -20px 30px -20px; 
    padding: 0 20px;
}

.card-container {
    display: grid;
    grid-template-rows: repeat(2, auto);
    grid-auto-flow: column;
    grid-auto-columns: 260px;
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    padding: 10px 20px 10px 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-right: -20px;
    margin-left: -4px;
}

.card-container.single-row {
    grid-template-rows: 1fr;
}

.card-container::-webkit-scrollbar { 
    display: none;
}

.card-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    color: var(--text-secondary);
    transition: all 0.2s;
    opacity: 0;
    pointer-events: none;
}

.card-group-wrapper:hover .card-nav-btn {
    opacity: 1;
    pointer-events: auto;
}

.card-nav-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-color);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transform: translateY(-50%) scale(1.1);
}

.card-nav-btn.prev {
    left: -15px;
}

.card-nav-btn.next {
    right: -15px;
}

.card-item {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background-color: var(--bg-card);
    box-shadow: none;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
    border-color: var(--accent-color);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.card-header .site-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
    font-size: 12px;
}

.card-header .site-info {
    flex: 1;
    overflow: hidden;
}

.card-header .title {
    display: block;
    font-size: 15px;
    color: var(--link-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.card-header .url-line {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-item .result-snippet {
    font-size: 13px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {
    .results-main { padding-left: 20px; }
    .results-grid { flex-direction: column !important; }
    .results-list { max-width: 100% !important; width: 100% !important; flex: none !important; }
    .results-sidebar { width: 100% !important; max-width: 600px; margin-top: 20px; }
}
@media (min-width: 769px) {
    .mobile-only { display: none !important; }
}
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    
    /* Header & General Layout */
    .results-header { padding: 12px 16px; flex-direction: column; align-items: flex-start; gap: 16px; height: auto; }
    .header-logo { margin-right: 0; margin-bottom: 0; font-size: 1.5rem; width: 100%; text-align: center; }
    .header-search-form { width: 100%; max-width: 100%; margin-left: 0; }
    .search-input-wrapper { width: 100%; max-width: 100%; }
    
    /* Center home logo on mobile */
    .home-logo {
        text-align: center;
        font-size: 3rem; /* Slightly smaller on mobile */
        margin-bottom: 1.5rem;
    }
    
    /* Ensure search icon is visible */
    .search-icon {
        display: block !important;
        left: 14px !important;
        z-index: 10;
    }
    
    .search-input {
        padding-left: 44px !important; /* Ensure padding for icon */
    }

    /* Results Layout Fixes */
    .results-main { padding: 16px; width: 100%; overflow-x: hidden; }
    .results-grid { gap: 20px; flex-direction: column !important; width: 100%; }
    .results-list { width: 100% !important; max-width: 100% !important; flex: none !important; min-width: 0; }
    .results-sidebar { width: 100% !important; max-width: 100% !important; margin-top: 20px; }
    
    /* Card Group Fixes */
    .card-group-wrapper { margin: 0 -16px 30px -16px; padding: 0 16px; }
    .card-container { margin-right: -16px; }
    .card-nav-btn { display: none; }
}

/* Skeleton Loading (New) */
.skeleton-item {
    pointer-events: none;
    user-select: none;
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    width: 100%;
}
.skeleton-line, .skeleton-circle {
    background: #e0e0e0;
    border-radius: 4px;
    animation: skeleton-pulse 1.5s infinite ease-in-out;
}
@media (prefers-color-scheme: dark) {
    .skeleton-line, .skeleton-circle { background: #3c4043; }
}
@keyframes skeleton-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}
.skeleton-line { height: 14px; margin-bottom: 8px; }

/* Theme Overrides */
[data-theme="dark"] {
    --bg-color: #202124;
    --bg-card: #303134;
    --text-color: #e8eaed;
    --text-secondary: #9aa0a6;
    --link-color: #8ab4f8;
    --visited-color: #c58af9;
    --url-color: #e8eaed;
    --accent-color: #8ab4f8;
    --border-color: #3c4043;
    --hover-bg: #3c4043;
    --input-bg: #303134;
    --input-border: #5f6368;
    --input-hover-shadow: 0 1px 6px rgba(0,0,0,0.5);
    --card-bg: #303134;
    --card-shadow: 0 1px 2px rgba(0,0,0,0.5);
    --card-shadow-hover: 0 2px 4px rgba(0,0,0,0.5);
    --header-bg: #202124;
    --badge-bg: #3c4043;
    --badge-text: #bdc1c6;
    --official-bg: #8ab4f8;
    --official-text: #202124;
}

/* Force Light Theme Override (re-declaring light vars to override system dark preference) */
[data-theme="light"] {
    --bg-color: #f8f9fa;
    --bg-card: #ffffff;
    --text-color: #202124;
    --text-secondary: #5f6368;
    --link-color: #1a0dab;
    --visited-color: #609;
    --url-color: #202124;
    --accent-color: #4285f4;
    --border-color: #dadce0;
    --hover-bg: #f1f3f4;
    --input-bg: #ffffff;
    --input-border: #dfe1e5;
    --input-hover-shadow: 0 1px 6px rgba(32,33,36,0.28);
    --card-bg: #ffffff;
    --card-shadow: 0 1px 2px rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    --card-shadow-hover: 0 2px 4px rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15);
    --header-bg: rgba(255, 255, 255, 1);
    --badge-bg: #f1f3f4;
    --badge-text: #5f6368;
    --official-bg: #4285f4;
    --official-text: #ffffff;
}

/* Pull String Styles */
.theme-pull-string {
    position: fixed;
    top: 0;
    right: 40px;
    width: 20px;
    height: 100px; /* Initial length */
    cursor: pointer;
    z-index: 10000;
    transition: height 0.3s ease;
    transform-origin: top center;
    touch-action: none;
}

.pull-cord {
    width: 2px;
    height: 100%;
    background-color: var(--text-secondary);
    margin: 0 auto;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.pull-handle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--accent-color);
    position: absolute;
    bottom: -8px; /* Center handle on end of cord */
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: background-color 0.2s;
}

.theme-pull-string:hover .pull-handle {
    background-color: var(--link-color);
}

/* Animation class for bounce effect */
.theme-pull-string.pull-animate {
    animation: pull-bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pull-bounce {
    0% { height: 100px; }
    50% { height: 160px; } /* Stretch down */
    70% { height: 90px; }  /* Snap back up */
    100% { height: 100px; } /* Settle */
}

@media (max-width: 768px) {
    /* Hide Pull String on Mobile */
    .theme-pull-string {
        display: none !important;
    }
    
    /* Show Toggle Button on Mobile */
    .theme-toggle-mobile {
        display: flex !important;
        position: fixed;
        top: 12px;
        right: 16px;
        background: none;
        border: none;
        padding: 8px;
        color: var(--text-secondary);
        cursor: pointer;
        z-index: 10000;
        border-radius: 50%;
        transition: background-color 0.2s, color 0.2s;
    }
    
    .theme-toggle-mobile:hover {
        background-color: var(--hover-bg);
        color: var(--text-color);
    }
}

/* Mobile Toggle Button (Default Hidden) */
.theme-toggle-mobile {
    display: none;
}
