/* ========================================
   三套主题：终端 / 可爱 / 现代
   ======================================== */

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

/* ========== 终端主题（默认） ========== */
:root,
[data-theme="terminal"] {
    --bg-color: #0a0a0a;
    --card-bg: #141414;
    --card-hover: #1f1f1f;
    --text-primary: #e5e5e5;
    --text-secondary: #737373;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --border: #2a2a2a;
    --border-strong: #404040;
    --radius: 0;
    --font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    --header-bg: var(--card-bg);
    --header-border: var(--border-strong);
}

/* 终端主题浅色模式 */
@media (prefers-color-scheme: light) {
    :root,
    [data-theme="terminal"] {
        --bg-color: #fafafa;
        --card-bg: #ffffff;
        --card-hover: #f5f5f5;
        --text-primary: #171717;
        --text-secondary: #525252;
        --accent: #059669;
        --accent-hover: #047857;
        --border: #e5e5e5;
        --border-strong: #a3a3a3;
    }
}

/* ========== 可爱主题 ========== */
[data-theme="cute"] {
    --bg-color: #fff5f5;
    --card-bg: #ffffff;
    --card-hover: #fef2f2;
    --text-primary: #831843;
    --text-secondary: #9d174d;
    --accent: #ec4899;
    --accent-hover: #db2777;
    --border: #fce7f3;
    --border-strong: #fbcfe8;
    --radius: 16px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --header-bg: linear-gradient(135deg, #fce7f3 0%, #fff1f2 100%);
    --header-border: var(--border-strong);
}

/* 可爱主题深色模式 */
@media (prefers-color-scheme: dark) {
    [data-theme="cute"] {
        --bg-color: #1a0a10;
        --card-bg: #2d1420;
        --card-hover: #3d1a28;
        --text-primary: #fce7f3;
        --text-secondary: #f9a8d4;
        --accent: #f472b6;
        --accent-hover: #ec4899;
        --border: #4d2030;
        --border-strong: #6d2848;
        --header-bg: linear-gradient(135deg, #2d1420 0%, #1a0a10 100%);
        --header-border: var(--border-strong);
    }
}

/* ========== 现代主题 ========== */
[data-theme="modern"] {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --card-hover: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --radius: 12px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --header-bg: var(--card-bg);
    --header-border: var(--border);
}

/* 现代主题深色模式 */
@media (prefers-color-scheme: dark) {
    [data-theme="modern"] {
        --bg-color: #0f172a;
        --card-bg: #1e293b;
        --card-hover: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --border: #334155;
        --border-strong: #475569;
        --header-bg: var(--card-bg);
        --header-border: var(--border);
    }
}

body {
    font-family: var(--font-family);
    background: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* 主题切换按钮 */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.theme-switcher {
    display: flex;
    gap: 0.25rem;
    background: var(--card-bg);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 2px;
}

.theme-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    font-family: var(--font-family);
}

.theme-btn:hover {
    color: var(--text-primary);
    background: var(--card-hover);
}

.theme-btn.active {
    background: var(--accent);
    color: white;
}

[data-theme="cute"] .theme-btn.active {
    color: white;
}

[data-theme="modern"] .theme-btn.active {
    color: white;
}

/* 搜索头部 */
.search-header {
    padding: 1.5rem 1rem;
    text-align: center;
    background: var(--header-bg);
    border-bottom: 3px solid var(--header-border);
}

.search-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

[data-theme="cute"] .search-header h1 {
    text-transform: none;
    letter-spacing: 0;
}

[data-theme="modern"] .search-header h1 {
    text-transform: none;
    letter-spacing: 0;
}

.search-box {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: row;
    gap: 1rem;
    justify-content: center;
}

/* 搜索组 */
.search-group {
    flex: 1;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 搜索引擎标签按钮 */
.engine-tabs {
    display: flex;
    gap: 0;
    background: var(--card-bg);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
}

.engine-tab {
    flex: 1;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 2px solid var(--border-strong);
    cursor: pointer;
    transition: all 0.15s ease;
    font-weight: 700;
    font-family: var(--font-family);
}

.engine-tab:last-child {
    border-right: none;
}

.engine-tab:hover {
    color: var(--text-primary);
    background: var(--card-hover);
}

.engine-tab.active {
    background: var(--accent);
    color: white;
}

/* 终端风格特有 */
[data-theme="terminal"] .engine-tab {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 可爱风格 */
[data-theme="cute"] .engine-tab {
    font-weight: 500;
}

/* 现代风格 */
[data-theme="modern"] .engine-tabs {
    border-radius: 999px;
    padding: 4px;
}

[data-theme="modern"] .search-label {
    border-radius: 999px;
    padding: 4px;
}

[data-theme="modern"] .engine-tab {
    border: none;
    border-radius: 999px;
    font-weight: 500;
}

/* 搜索标签 */
.search-label {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
}

.search-label span {
    flex: 1;
    text-align: center;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 700;
}

/* 搜索表单 */
.search-form {
    display: flex;
    gap: 0;
}

.search-form input {
    flex: 1;
    padding: 0.8rem 1rem;
    font-size: 0.95rem;
    border: 2px solid var(--border-strong);
    border-right: none;
    background: var(--bg-color);
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-family);
    border-radius: var(--radius) 0 0 var(--radius);
}

[data-theme="modern"] .search-form input {
    border-right: none;
}

.search-form input:focus {
    border-color: var(--accent);
}

.search-form input::placeholder {
    color: var(--text-secondary);
}

.search-form button {
    padding: 0.8rem 1.25rem;
    font-size: 0.85rem;
    background: var(--accent);
    color: white;
    border: 2px solid var(--accent);
    cursor: pointer;
    font-weight: 700;
    font-family: var(--font-family);
    transition: all 0.15s ease;
    white-space: nowrap;
    border-radius: 0 var(--radius) var(--radius) 0;
}

[data-theme="cute"] .search-form button,
[data-theme="modern"] .search-form button {
    font-weight: 600;
}

.search-form button:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* 链接搜索特殊样式 */
.link-search input {
    border-radius: var(--radius) 0 0 var(--radius);
}

.link-search button {
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-strong);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.link-search button:hover {
    background: var(--card-hover);
}

/* 主内容 */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

/* 分类卡片网格 - 瀑布流 */
.categories-grid {
    column-count: 3;
    column-gap: 1rem;
}

.link-section {
    background: var(--card-bg);
    border: 2px solid var(--border-strong);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    break-inside: avoid;
    margin-bottom: 1rem;
}

[data-theme="cute"] .link-section {
    border-left: 2px solid var(--border-strong);
    box-shadow: 0 4px 20px rgba(236, 72, 153, 0.1);
}

[data-theme="cute"] .link-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
}

[data-theme="modern"] .link-section {
    border-left: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.link-section h2 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0 1rem;
    background: var(--card-hover);
    border-bottom: 2px solid var(--border-strong);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.8rem;
    line-height: 1;
    min-width: 0;
}

.link-section h2 img {
    width: 1.2rem !important;
    height: 1.2rem !important;
    object-fit: contain;
    flex-shrink: 0;
}

.link-section h2 .title-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.link-section h2 img {
    width: 1.2rem !important;
    height: 1.2rem !important;
    object-fit: contain;
    flex-shrink: 0;
}

[data-theme="terminal"] .link-section h2 {
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

[data-theme="cute"] .link-section h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

/* 链接网格 */
.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1px;
    background: var(--border);
    padding: 1px;
}

[data-theme="cute"] .link-grid {
    gap: 0.5rem;
    background: transparent;
    padding: 0.75rem;
}

[data-theme="modern"] .link-grid {
    gap: 0.5rem;
    background: transparent;
    padding: 0.75rem;
}

/* 链接卡片 */
.link-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.5rem;
    background: var(--card-bg);
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.15s ease;
}

[data-theme="cute"] .link-card {
    border-radius: 12px;
    padding: 1rem;
}

[data-theme="modern"] .link-card {
    border-radius: 8px;
    padding: 1rem;
}

.link-card:hover {
    background: var(--card-hover);
}

[data-theme="cute"] .link-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.15);
}

[data-theme="modern"] .link-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.link-card.hidden {
    display: none;
}

.link-card.highlight {
    background: var(--accent);
    color: white;
}

.link-icon {
    font-size: 1.5rem;
    margin-bottom: 0.3rem;
}

[data-theme="cute"] .link-icon {
    font-size: 1.75rem;
}

.link-card span {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    word-break: break-word;
    font-weight: 500;
}

[data-theme="terminal"] .link-card span {
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

[data-theme="cute"] .link-card span {
    font-size: 0.8rem;
}

.link-card:hover span {
    color: var(--text-primary);
}

.link-card.highlight span {
    color: white;
}

/* 常用网站 - 跨所有列 */
.link-section.common-section {
    column-span: all;
}
.link-section.common-section .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

.link-section.common-section .link-card {
    padding: 1.1rem 0.6rem;
}

.link-section.common-section .link-icon {
    font-size: 1.65rem;
}

/* 空状态 */
.empty-section {
    opacity: 0.4;
}

/* 无搜索结果提示 */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

[data-theme="terminal"] .no-results {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 页脚 */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    border-top: 2px solid var(--border-strong);
}

[data-theme="terminal"] .footer {
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

[data-theme="cute"] .footer {
    font-size: 0.85rem;
}

/* 响应式 */
@media (max-width: 1100px) {
    .categories-grid {
        column-count: 2;
    }
}

@media (max-width: 900px) {
    .search-box {
        flex-direction: column;
        max-width: 650px;
    }
    
    .search-group {
        max-width: none;
    }
    
    .categories-grid {
        column-count: 1;
    }
    
    .header-top {
        justify-content: center;
    }
}

@media (max-width: 600px) {
    .search-header {
        padding: 1rem 0.5rem;
    }
    
    .search-header h1 {
        font-size: 1rem;
    }

    .search-box {
        gap: 0.5rem;
    }
    
    .search-group {
        min-width: 0;
    }

    .engine-tabs {
        gap: 0;
    }

    .engine-tab {
        padding: 0.5rem 0.25rem;
        font-size: 0.6rem;
    }

    .search-form input {
        padding: 0.6rem 0.5rem;
        font-size: 0.8rem;
    }

    .search-form button {
        padding: 0.6rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .search-label span {
        font-size: 0.65rem;
    }
    
    .theme-btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.65rem;
    }

    .link-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .link-card {
        padding: 0.7rem 0.3rem;
    }

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

    .link-card span {
        font-size: 0.6rem;
    }
}

@media (max-width: 400px) {
    .link-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
