/* --- 字体定义 --- */
@font-face {
    font-family: 'MapleMono';
    src: url('assets/MapleMono-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
}

/* --- 动画定义 --- */
@keyframes loading-gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* --- 全局样式与重置 --- */
:root {
    /* Shared */
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --transition-speed: 0.25s;
    --dark-text-color: #2c3e50;

    /* Light Mode */
    --bg-color: #f4f4f5;
    --card-bg-color: #ffffff;
    --highlight-color: rgba(255, 255, 255, 0.2);
    --border-color: rgba(255, 255, 255, 0.5);
    --text-color: #f0f0f0;
    --gradient-1: #e0c3fc;
    --gradient-2: #8ec5fc;
    --gradient-3: #f0f2f0;
    --gradient-4: #a8edea;
    --gradient-5: #fed6e3;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Mode */
        --bg-color: #121212;
        --card-bg-color: #1e1e1e;
        --text-color: #e0e0e0;
        --border-color: #2a2a2a;
        --highlight-color: rgba(255, 255, 255, 0.2);
        --gradient-1: #0f0c29;
        --gradient-2: #302b63;
        --gradient-3: #24243e;
        --gradient-4: #537895;
        --gradient-5: #0f0c29;
    }
}

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

body {
    font-family: 'MapleMono', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-color);
    /* background-color is removed as it's covered by ::before */
    overflow-y: scroll;
    position: relative;
}

/* 加载动画层 (底层) */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    /* 动态渐变背景 */
    background: linear-gradient(-45deg, var(--gradient-1), var(--gradient-2), var(--gradient-3), var(--gradient-4), var(--gradient-5));
    background-size: 400% 400%;
    animation: loading-gradient 15s ease infinite;
    z-index: -2;
}

/* 最终图片层 (上层) */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: var(--bg-image); /* 由 JS 注入 */
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    z-index: -1;
    opacity: 0; /* 初始透明 */
    transition: opacity 0.8s ease-in-out; /* 平滑过渡 */
}

/* 加载完成后的状态 */
body.background-loaded::before {
    /* 停止动画 */
    animation: none;
}

body.background-loaded::after {
    /* 淡入图片 */
    opacity: 1;
}

body.background-fade-out::before {
    opacity: 0;
}

.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: -1;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* --- 搜索区域 --- */
.search-section {
    position: relative;
    z-index: 100;
    margin-bottom: 3rem;
    text-align: center;
}

.search-bar-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#search-input {
    width: 50vw;
    max-width: 600px;
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
    font-family: inherit;
    color: var(--text-color);
    background-color: rgba(0, 0, 0, 0.4);
    border: 2px solid var(--border-color);
    border-radius: 30px;
    outline: none;
    transition: all var(--transition-speed) ease-in-out;
    backdrop-filter: blur(5px);
}

#search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#search-input:focus {
    border-color: white;
    background-color: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.engine-selector {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 0.4rem;
    border-radius: 999px;
    backdrop-filter: blur(5px);
}

.engine-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    background-color: transparent;
    color: var(--border-color);
    border: none;
    transition: all var(--transition-speed) ease-in-out;
    position: relative;
}

.engine-option img {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.engine-option:hover:not(.active) {
    filter: brightness(1.2);
    transform: scale(1.05);
}

.engine-option.active {
    background-color: white;
    color: var(--dark-text-color);
    transform: scale(1.05);
}

.engine-option.parent-active {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.engine-option .dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) scaleY(0.95);
    opacity: 0;
    visibility: hidden;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 0.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10;
    transform-origin: top center;
    transition: transform var(--transition-speed) ease-in-out, opacity var(--transition-speed) ease-in-out, visibility 0s var(--transition-speed);
    backdrop-filter: blur(10px);
    min-width: 220px; /* 设置一个合适的最小宽度 */
    max-width: 350px; /* 设置一个最大宽度，防止无限延伸 */
}

.engine-option:hover .dropdown {
    transform: translateX(-50%) scaleY(1);
    opacity: 1;
    visibility: visible;
    /* 为 opacity 和 visibility 添加 150ms 的延迟，防止鼠标快速划过时闪现 */
    transition-delay: 0s, 150ms, 150ms;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    color: var(--dark-text-color);
    border-radius: 6px;
    text-align: left;
    white-space: normal; /* 允许文字在达到max-width后换行 */
    line-height: 1.4;
    overflow-wrap: break-word; /* 处理超长单词或链接 */
}

.dropdown-item img {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.dropdown-item:hover {
    background-color: var(--highlight-color);
}

.dropdown-item.active {
    background-color: var(--highlight-color);
    font-weight: bold;
}

/* --- 内容区域 --- */
.content-section {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 2rem;
    align-items: flex-start;
}

.folder-tree {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 12px;
    backdrop-filter: blur(5px);
    max-height: 70vh;
    overflow-y: auto;
}

.folder-tree ul {
    list-style: none;
    padding-left: 1rem;
}

.folder-item {
    padding: 0.6rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color var(--transition-speed) ease-in-out;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-item:hover {
    background-color: var(--highlight-color);
}

.folder-item.active {
    background-color: var(--highlight-color);
    font-weight: bold;
}

.bookmark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.bookmark-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* justify-content: center; */ /* Replaced by margin-top: auto on path */
    gap: 0.8rem;
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-color);
    transition: all var(--transition-speed) ease-in-out;
    backdrop-filter: blur(5px);
    min-height: 120px; /* Use min-height to allow expansion */
    position: relative;
}

.bookmark-item:hover {
    background-color: rgba(0, 0, 0, 0.4);
    transform: translateY(-4px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.bookmark-item img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.bookmark-item span {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bookmark-path {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: auto; /* Pushes the path to the bottom */
    padding-top: 0.5rem; /* Add some space above the path */
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #323232;
  color: #f1f1f1;
  padding: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  transition: transform 0.5s ease, opacity 0.5s ease;
  opacity: 0;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.hidden {
  display: none;
}

.toast-icon {
  margin-right: 12px;
  display: flex;
  align-items: center;
}

.toast-icon svg {
  fill: #ffcc00;
}

.toast-message {
  font-size: 14px;
}

/* 离线状态下的占位符图标 */
.bookmark-item img.is-placeholder-offline {
  opacity: 0.4;
  filter: grayscale(80%);
}