/* ============================================================
   极简导航站 - 前台样式
   悬浮卡片风格，横竖屏背景切换，明暗双主题
   ============================================================ */

/* --- 动画关键帧 --- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes subtlePulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.02); }
}

@keyframes spinOnce {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@keyframes floatIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- CSS Variables --- */
:root {
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    --font-size-title: 1.5rem;
    --font-size-link: 0.95rem;
    --font-size-small: 0.8rem;
    --max-width: 1200px;
    --transition: 0.2s ease;
    --card-radius: 14px;
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
    --card-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* 浅色模式 */
[data-theme="light"] {
    --bg-color: #e8ecf1;
    --bg-card: rgba(255, 255, 255, 0.82);
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #999;
    --border-color: rgba(0, 0, 0, 0.06);
    --hover-bg: rgba(0, 0, 0, 0.03);
    --hover-border: rgba(0, 0, 0, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    --header-bg: rgba(255, 255, 255, 0.78);
    --input-bg: rgba(255, 255, 255, 0.90);
    --input-border: rgba(0, 0, 0, 0.08);
    --input-focus-border: rgba(0, 0, 0, 0.2);
    --btn-bg: #1a1a2e;
    --btn-text: #fff;
    --engine-active-bg: rgba(0, 0, 0, 0.06);
    --engine-hover-bg: rgba(0, 0, 0, 0.03);
    --dropdown-bg: #fff;
    --footer-bg: rgba(255, 255, 255, 0.7);
}

/* 深色模式 */
[data-theme="dark"] {
    --bg-color: #121216;
    --bg-card: rgba(30, 30, 38, 0.82);
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border-color: rgba(255, 255, 255, 0.06);
    --hover-bg: rgba(255, 255, 255, 0.04);
    --hover-border: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --header-bg: rgba(26, 26, 30, 0.82);
    --input-bg: rgba(40, 40, 48, 0.90);
    --input-border: rgba(255, 255, 255, 0.08);
    --input-focus-border: rgba(255, 255, 255, 0.2);
    --btn-bg: #e4e4e7;
    --btn-text: #1a1a1e;
    --engine-active-bg: rgba(255, 255, 255, 0.08);
    --engine-hover-bg: rgba(255, 255, 255, 0.04);
    --dropdown-bg: #1e1e22;
    --footer-bg: rgba(26, 26, 30, 0.7);
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-color);
    transition: background-color var(--transition), color var(--transition);
    scroll-behavior: smooth;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    html { scroll-behavior: auto; }
}

a {
    color: inherit;
    text-decoration: none;
}

/* --- 背景轮播层 --- */
.bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.bg-image {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
}

.bg-image.active {
    opacity: 1;
}

/* 横屏时隐藏竖屏背景 */
@media (orientation: landscape) {
    .bg-image[data-orientation="portrait"] { display: none !important; }
}

/* 竖屏时隐藏横屏背景 */
@media (orientation: portrait) {
    .bg-image[data-orientation="landscape"] { display: none !important; }
}

/* --- 顶部导航 - 悬浮卡片 --- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0.75rem 1rem 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
}

.site-header.header-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 1rem;
    background: var(--header-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
    animation: floatIn 0.5s ease both;
}

.site-title {
    font-size: var(--font-size-title);
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.header-admin-link {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.header-admin-link:hover {
    color: var(--text-secondary);
    border-color: var(--text-secondary);
    transform: scale(1.05);
}

.header-admin-link:hover svg {
    animation: spinOnce 0.6s ease;
}

.header-admin-link:active {
    transform: scale(0.92);
}

/* --- 主题切换按钮 --- */
.theme-btn {
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-primary);
    width: 34px;
    height: 34px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, transform 0.15s ease;
}

.theme-btn:hover {
    border-color: var(--text-secondary);
    transform: scale(1.05);
}

.theme-btn:active {
    transform: scale(0.92);
}

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

/* ============================================================
   Hero 中部搜索区 - 悬浮卡片
   ============================================================ */
.hero-section {
    position: relative;
    z-index: 10;
    padding: 3rem 1rem 2.5rem;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.hero-inner {
    width: 100%;
    max-width: 560px;
    position: relative;
    z-index: 50;
    animation: floatIn 0.5s ease 0.1s both;
}

.search-box-center {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 搜索引擎下拉 */
.engine-dropdown {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.engine-trigger {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 0 6px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.2s ease, background 0.2s ease;
    font-family: var(--font-family);
}

.engine-trigger:hover {
    color: var(--text-secondary);
    background: var(--engine-hover-bg);
}

.engine-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.engine-caret {
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.engine-dropdown.open .engine-caret {
    transform: rotate(180deg);
}

.engine-dropdown.open .engine-trigger {
    color: var(--text-primary);
    background: var(--engine-active-bg);
}

/* 下拉菜单 */
.engine-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 9999;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    isolation: isolate;
}

[data-theme="dark"] .engine-menu {
    background: #1e1e22;
    border-color: rgba(255, 255, 255, 0.12);
}

.engine-dropdown.open .engine-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.engine-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease;
    user-select: none;
}

.engine-menu-item:hover {
    background: var(--engine-hover-bg);
}

.engine-menu-item.active {
    background: var(--engine-active-bg);
    font-weight: 500;
}

.engine-menu-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* 搜索输入行 */
.search-input-row {
    display: flex;
    width: 100%;
    background: var(--input-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    overflow: visible;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.15s ease;
}

.search-input-row:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.search-input-center {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 0.75rem 1rem;
    outline: none;
    font-family: var(--font-family);
}

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

.search-btn-center {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 0 1rem;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.15s ease;
}

.search-btn-center:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.search-btn-center:active {
    transform: scale(0.92);
}

/* --- 主体内容 --- */
.site-main {
    position: relative;
    z-index: 1;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem 2rem;
    flex: 1;
}

/* --- 分类区域 - 悬浮卡片 --- */
.link-category {
    margin-bottom: 1.5rem;
    animation: floatIn 0.5s ease both;
}

.link-category:nth-child(1) { animation-delay: 0.15s; }
.link-category:nth-child(2) { animation-delay: 0.22s; }
.link-category:nth-child(3) { animation-delay: 0.29s; }
.link-category:nth-child(4) { animation-delay: 0.36s; }
.link-category:nth-child(5) { animation-delay: 0.43s; }
.link-category:nth-child(6) { animation-delay: 0.5s; }
.link-category:nth-child(n+7) { animation-delay: 0.55s; }

.category-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    letter-spacing: 0.02em;
}

/* --- 链接卡片网格 --- */
.link-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.link-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem 0.75rem;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
    animation: floatIn 0.4s ease both;
    text-decoration: none;
    color: inherit;
}

.link-grid .link-card:nth-child(1) { animation-delay: 0.05s; }
.link-grid .link-card:nth-child(2) { animation-delay: 0.1s; }
.link-grid .link-card:nth-child(3) { animation-delay: 0.15s; }
.link-grid .link-card:nth-child(4) { animation-delay: 0.2s; }
.link-grid .link-card:nth-child(5) { animation-delay: 0.25s; }
.link-grid .link-card:nth-child(6) { animation-delay: 0.3s; }
.link-grid .link-card:nth-child(7) { animation-delay: 0.35s; }
.link-grid .link-card:nth-child(8) { animation-delay: 0.4s; }
.link-grid .link-card:nth-child(n+9) { animation-delay: 0.45s; }

.link-card:hover {
    border-color: var(--hover-border);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

.link-card:active {
    transform: scale(0.975);
}

/* 卡片图标区 */
.link-card-image {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.link-card-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.link-card-emoji {
    font-size: 3rem;
    line-height: 1;
}

.link-card-fallback {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    background: var(--hover-bg);
    color: var(--text-secondary);
    font-size: 2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

/* 卡片主体 */
.link-body {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.link-name {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-all;
}

.link-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}

.link-url {
    font-size: 0.7rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- 空状态 --- */
.empty-hint {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 0;
    font-size: var(--font-size-link);
}

/* --- 页脚 - 固定在底部 --- */
.site-footer {
    position: relative;
    z-index: 5;
    text-align: center;
    padding: 0.75rem 1rem;
    margin-top: auto;
    font-size: var(--font-size-small);
    color: var(--text-muted);
    background: var(--footer-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 768px) {
    .hero-section {
        padding: 2rem 1rem 1.5rem;
    }
    .hero-inner {
        max-width: 100%;
    }
    .search-input-center {
        font-size: 0.9rem;
        padding: 0.65rem 0.75rem;
    }
    .site-title {
        font-size: 1.25rem;
    }
    .link-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .site-main {
        padding: 0 0.75rem 1.5rem;
    }
    .header-inner {
        border-radius: 10px;
    }
    .link-card-image {
        height: 100px;
    }
}

@media (max-width: 480px) {
    .hero-section {
        padding: 1.5rem 0.75rem 1rem;
    }
    .link-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .link-card-image {
        height: 150px;
    }
    .header-inner {
        border-radius: 8px;
        padding: 0 0.75rem;
    }
}