:root {
    --accent-color: #00f2ff;
    --glass-bg: rgba(20, 20, 20, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
}

body {
    background: #141414;
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    margin: 0;
    overflow: hidden;
    color: var(--text-primary);
}

/* 搜索栏布局调整 - 采用稳健的 margin 居中，避免 transform 导致的半像素偏移 */
.search-container {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 1000;
    width: 90%;
    max-width: 600px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

/* 搜索输入框一体化包装器 - 弃用 border 改用 shadow 确保像素对齐 */
.search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    background: var(--glass-bg);
    /* 使用 spread radius 模拟 1px 边框，解决物理对齐偏差 */
    box-shadow: 0 0 0 1px var(--glass-border);
    border-radius: 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(15px);
    box-sizing: border-box;
}

/* 激活状态：向上生长感，底边圆角消失 */
.search-container.suggestions-active .search-input-wrapper {
    border-radius: 24px 24px 0 0;
    background: rgba(30, 30, 30, 0.95);
    /* 激活时，底部不显示模拟边条，由建议列表接管 */
    box-shadow:
        -1px 0 0 var(--glass-border),
        1px 0 0 var(--glass-border),
        0 -1px 0 var(--glass-border),
        0 10px 30px rgba(0, 0, 0, 0.6);
}

.search-input-wrapper input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    padding: 14px 24px;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    box-shadow: none !important;
}

/* 联想词面板样式 - 极致对齐方案 (Shadow-Border 渲染) */
#search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: rgba(30, 30, 30, 0.95);
    border: none;
    /* 移除 border 以防浏览器渲染偏移 */
    border-radius: 0 0 24px 24px;
    backdrop-filter: blur(20px);
    max-height: 380px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
    /* 使用多重阴影模拟外部边框，实现物理对齐 */
    box-shadow:
        -1px 0 0 var(--glass-border),
        /* 左侧模拟线 */
        1px 0 0 var(--glass-border),
        /* 右侧模拟线 */
        0 1px 0 var(--glass-border),
        /* 底部模拟线 */
        0 15px 30px rgba(0, 0, 0, 0.5);
    /* 整体投影 */
    box-sizing: border-box;
    background-clip: padding-box;
    transform: translateZ(0);
    /* 强制开启硬件加速，提高边框渲染精度 */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* 隐藏滚动条 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#search-suggestions::-webkit-scrollbar {
    display: none;
}

/* 建议列表内部的分割线 */
#search-suggestions::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
}

/* 联想项基础样式 - 紧凑单行版 */
.suggestion-item {
    padding: 10px 20px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
    background: rgba(255, 255, 255, 0.08);
    padding-left: 28px;
    /* 轻微位移反馈 */
}

.suggestion-item.active {
    box-shadow: inset 4px 0 0 var(--accent-color);
}

.suggestion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.suggestion-name {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 15px;
}

/* 中文名后的英文名括号提示 */
.suggestion-en-name {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-left: 2px;
}

.suggestion-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.suggestion-item:hover .suggestion-meta,
.suggestion-item.active .suggestion-meta {
    opacity: 0.8;
}

.meta-tag {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
}

/* 状态与加载提示 */
.suggestion-status {
    padding: 20px;
    text-align: center;
    color: var(--accent-color);
    font-size: 14px;
    opacity: 0.7;
}

@keyframes pulse {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

.loading-pulse {
    animation: pulse 1.5s infinite;
}

/* 悬停与聚焦状态：触发高亮阴影 */
.search-input-wrapper:hover,
.search-input-wrapper:focus-within {
    box-shadow: 0 0 0 1px var(--accent-color), 0 0 18px rgba(0, 242, 255, 0.15);
    background: rgba(35, 35, 35, 0.85);
}

/* 当联想框激活时，强制同步高亮阴影边框 */
.suggestions-active .search-input-wrapper {
    box-shadow:
        -1px 0 0 var(--accent-color),
        1px 0 0 var(--accent-color),
        0 -1px 0 var(--accent-color),
        0 10px 30px rgba(0, 0, 0, 0.2) !important;
}

.suggestions-active #search-suggestions {
    box-shadow:
        -1px 0 0 var(--accent-color),
        1px 0 0 var(--accent-color),
        0 1px 0 var(--accent-color),
        0 15px 30px rgba(0, 0, 0, 0.5) !important;
}

/* 搜索按钮 - 内嵌于搜索框右侧 (Google 风格) */
.search-container button#search-btn {
    background: transparent;
    color: var(--accent-color);
    border: 1px solid rgba(0, 242, 255, 0.3);
    border-radius: 18px;
    padding: 0 16px;
    margin: 6px;
    height: 36px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.search-container button#search-btn:hover {
    background: var(--accent-color);
    color: #1a1a2e;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
    transform: scale(1.05);
}

.search-container button#search-btn:active {
    transform: scale(0.95);
}

/* 结果信息卡片 */
#molecule-info {
    position: absolute;
    top: 100px;
    left: 30px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 24px;
    border-radius: 20px;
    backdrop-filter: blur(15px);
    max-width: 320px;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}

#molecule-info.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.molecule-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 8px;
}

.molecule-formula {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 12px;
    color: var(--text-secondary);
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.download-container {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
    z-index: 100;
}

.download-container:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.download-btn-main {
    background: transparent;
    border: none;
    color: white;
    padding: 12px 16px 12px 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 50px 0 0 50px;
    font-size: 14px;
    font-family: inherit;
    transition: background 0.2s;
}

.download-btn-main:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

.download-separator {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
}

.download-btn-arrow {
    background: transparent;
    border: none;
    color: white;
    padding: 12px 16px;
    cursor: pointer;
    border-radius: 0 50px 50px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.download-btn-arrow:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

/* Dropdown Menu */
.download-menu {
    position: absolute;
    bottom: 120%;
    right: 0;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px 0;
    min-width: 140px;
    display: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease;
    flex-direction: column;
}

.download-menu.show {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.menu-item {
    padding: 10px 20px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    text-align: left;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding-left: 24px;
}

/* 全局居中加载动画 */
.loading-overlay {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.05);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin-simple 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    /* 增加科技感光晕 */
    box-shadow: 0 0 30px rgba(0, 242, 255, 0.15);
}

.loading-text {
    color: var(--accent-color);
    font-size: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 0 0 10px rgba(0, 242, 255, 0.5);
    font-weight: 500;
}

@keyframes spin-simple {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}


@keyframes center-spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* AI 助手按钮与面板 */
.ai-assistant {
    position: absolute;
    right: 30px;
    top: 100px;
    z-index: 1001;
}

#ai-trigger {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background: linear-gradient(135deg, #00f2ff 0%, #0072ff 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 242, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#ai-trigger:hover {
    transform: scale(1.1) rotate(15deg);
}

#ai-trigger svg {
    color: white;
    width: 28px;
    height: 28px;
}

#ai-panel {
    position: absolute;
    right: 0;
    top: 60px;
    width: 300px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(20px);
    opacity: 0;
    transform: scale(0.9) translateX(20px);
    transform-origin: top right;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    pointer-events: none;
    color: var(--text-primary);
}

#ai-panel.visible {
    opacity: 1;
    transform: scale(1) translateX(0);
    pointer-events: all;
}

.ai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 12px;
    font-size: 16px;
}

.ai-content {
    font-size: 14px;
    line-height: 1.6;
    opacity: 0.9;
    max-height: 300px;
    overflow-y: auto;
}

.ai-loading-dots {
    display: inline-block;
}

.ai-loading-dots::after {
    content: '...';
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60% {
        content: '...';
    }

    80%,
    100% {
        content: '';
    }
}

/* 隐藏滚动条 */
.ai-content::-webkit-scrollbar {
    width: 4px;
}

.ai-content::-webkit-scrollbar-track {
    background: transparent;
}

.ai-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

/* 本地专家库角标 */
.local-badge {
    background: linear-gradient(135deg, #00f2ff, #0072ff);
    color: white;
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.5px;
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.3);
    vertical-align: middle;
}

/* 旋转控制按钮 - 放在右上角，替代原来的 AI 助手位置 */
.rotation-btn {
    position: absolute;
    right: 30px;
    top: 100px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    cursor: pointer;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    z-index: 1001;
    font-size: 14px;
    outline: none;
}

.rotation-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--accent-color);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

.rotation-btn.active {
    background: rgba(20, 20, 20, 0.8);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
    color: var(--accent-color);
}

.rotation-btn svg {
    transition: transform 0.5s ease;
}

.rotation-btn:hover svg {
    transform: rotate(180deg);
}

.rotation-btn:active {
    transform: scale(0.95);
}

/* 数据来源提示 */
.data-source {
    position: absolute;
    bottom: 30px;
    left: 30px;
    font-size: 10px;
    color: var(--text-secondary);
    background: rgba(20, 20, 20, 0.4);
    padding: 4px 10px;
    border-radius: 4px;
    backdrop-filter: blur(5px);
    border-left: 2px solid var(--accent-color);
    z-index: 1000;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.data-source.visible {
    opacity: 0.8;
}

/* Materials Project 元数据样式 */
.mp-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 242, 255, 0.2);
}

.mp-metadata .meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    background: rgba(0, 242, 255, 0.08);
    padding: 4px 10px;
    border-radius: 12px;
    color: var(--text-secondary);
    border: 1px solid rgba(0, 242, 255, 0.15);
    transition: all 0.2s ease;
}

.mp-metadata .meta-item:hover {
    background: rgba(0, 242, 255, 0.15);
    border-color: rgba(0, 242, 255, 0.3);
    color: var(--accent-color);
}

.mp-metadata .meta-item.metal {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 165, 0, 0.1));
    border-color: rgba(255, 215, 0, 0.3);
    color: #ffd700;
}

/* MP 数据来源特殊标识 */
.data-source[data-source="mp"] {
    border-left-color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
}

/* 晶体控制按钮样式 */
.crystal-controls {
    position: absolute;
    right: 30px;
    top: 160px;
    /* 放在旋转按钮下方 */
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 12px;
    border-radius: 20px;
    backdrop-filter: blur(15px);
    display: none;
    /* 默认隐藏，仅在晶体模式下显示 */
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    transition: all 0.3s ease;
}

.crystal-controls.visible {
    display: flex;
}

.control-header {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    text-align: center;
    font-weight: 600;
}

.control-actions {
    display: flex;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover:not(:disabled) {
    background: var(--accent-color);
    color: #1a1a2e;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}