/* 全局和基础样式 */
:root {
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --accent-color: #4895ef;
    --border-color: #e9ecef;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --hover-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* 登录页面 */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #1e1e3f, #3c3c8a);
    animation: background-pan 15s ease-in-out infinite;
}

@keyframes background-pan {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#login-container form {
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

#login-container h1 {
    margin-bottom: 25px;
    font-size: 28px;
    color: #ffffff;
    font-weight: 600;
}

#login-container input {
    width: 100%;
    padding: 15px;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transition: all 0.3s ease;
}
#login-container input::placeholder { color: rgba(255, 255, 255, 0.7); }
#login-container input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 4px rgba(128, 118, 234, 0.5);
}

#login-container button {
    width: 100%;
    padding: 15px;
    background: linear-gradient(45deg, #8076ea, #621f84);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#login-container button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#login-container button.loading {
    pointer-events: none;
    color: transparent;
}

#login-container button.loading::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -12px;
    margin-left: -12px;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#login-container.fade-out {
    opacity: 0;
    transition: opacity 0.5s ease-out;
}

.error {
    color: #ffcdd2;
    margin-top: 15px;
    background: rgba(255, 82, 82, 0.2);
    padding: 10px;
    border-radius: 8px;
}


/* 主容器和导航 */
#main-container { padding: 40px 20px; max-width: 1200px; margin: 0 auto; opacity: 1; transition: opacity 0.5s ease, transform 0.5s ease; }
#header { margin-bottom: 50px; display: flex; justify-content: center; }
.search-bar {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 8px 12px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 680px;
    border: 1px solid transparent;
    transition: var(--transition);
}
.search-bar:focus-within {
    box-shadow: var(--hover-shadow);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}
#search-engine {
    border: none;
    background: #f8f9fa;
    padding: 8px 12px;
    border-radius: 8px;
    color: #495057;
    font-weight: 500;
    cursor: pointer;
    margin-right: 10px;
    transition: var(--transition);
}
#search-engine:hover { background: #e9ecef; }
#search-input { flex-grow: 1; border: none; background: transparent; padding: 12px; font-size: 16px; color: var(--text-color); }
#search-input:focus { outline: none; }
.search-bar button {
    border: none;
    background: none;
    padding: 10px;
    margin: 0 4px;
    cursor: pointer;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.search-bar button:hover { background-color: #f1f3f5; transform: scale(1.05); }
.search-bar button svg { color: #6c757d; width: 20px; height: 20px; }
#search-btn { background-color: var(--primary-color); padding: 10px 20px; border-radius: 12px; }
#search-btn:hover { background-color: var(--secondary-color); box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3); }
#search-btn svg { color: white; }

/* 导航卡片 */
.category { margin-bottom: 50px; }
.category h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 25px;
    padding-left: 15px;
    border-left: 4px solid var(--primary-color);
    color: var(--text-color);
    display: flex;
    align-items: center;
}
.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 25px; }
.link-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 16px;
    text-decoration: none;
    color: var(--text-color);
    box-shadow: var(--shadow);
    transition: var(--transition);
    border: 1px solid rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.link-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    opacity: 0;
    transition: var(--transition);
}
.link-card:hover::before { opacity: 1; }
.link-card[role="button"] { cursor: pointer; }
.link-card:hover { transform: translateY(-8px); box-shadow: var(--hover-shadow); }
.link-card h3 { margin: 0 0 8px 0; color: var(--text-color); font-size: 18px; font-weight: 600; }
.link-card:hover h3 { color: var(--primary-color); }
.link-card p { margin: 0; font-size: 14px; color: #868e96; line-height: 1.5; }

/* 下载弹窗样式 */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 0; transition: opacity 0.3s; }
.modal-overlay.visible { opacity: 1; }
.modal-content { background: white; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); width: 90%; max-width: 500px; transform: scale(0.95); transition: transform 0.3s; }
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { margin: 0; font-size: 20px; }
.modal-close-btn { background: none; border: none; font-size: 24px; cursor: pointer; color: #6c757d; }
.modal-links a { display: block; padding: 12px 15px; margin-bottom: 10px; background: #f1f3f5; color: var(--text-color); text-decoration: none; border-radius: 8px; transition: background 0.2s, color 0.2s; }
.modal-links a:hover { background: var(--primary-color); color: white; }
.modal-links a:last-child { margin-bottom: 0; }

/* AI 聊天界面 - 全新设计 */
#ai-chat-container {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--card-bg);
    display: flex; flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}
#ai-chat-container.visible { transform: translateY(0); }

.chat-header {
    flex-shrink: 0; display: flex; justify-content: space-between; align-items: center;
    padding: 10px 20px; border-bottom: 1px solid var(--border-color);
}
.chat-header button { background: none; border: none; cursor: pointer; padding: 5px; display: flex; }
.chat-header button svg { color: #495057; }
#model-selector { border-radius: 8px; border: 1px solid var(--border-color); padding: 8px 12px; font-size: 14px; background: #fff; }

.chat-view { flex-grow: 1; overflow-y: auto; padding: 20px 0; }
#chat-messages { max-width: 800px; margin: 0 auto; padding: 0 20px; }

.message { display: flex; gap: 15px; margin-bottom: 25px; }
.message.user { justify-content: flex-end; }
.message .avatar { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background-color: #e9ecef; display: flex; align-items: center; justify-content: center; }
.message.user .avatar { background-color: var(--primary-color); color: white; font-weight: bold; }
.message.assistant .avatar svg { color: #0b5ed7; width: 20px; height: 20px; }
.message .content { max-width: 100%; line-height: 1.7; font-size: 16px; word-wrap: break-word; }

/* 修复列表样式 */
.message .content ul, .message .content ol { padding-left: 25px; }
.message .content p:first-child { margin-top: 0; }
.message .content p:last-child { margin-bottom: 0; }
.message .content pre { background-color: #282c34; color: #abb2bf; padding: 16px; border-radius: 8px; overflow-x: auto; margin: 12px 0; }
.message .content code:not(pre code) { background-color: #e9ecef; padding: .2em .4em; margin: 0; font-size: 85%; border-radius: 3px; }

/* <think> 标签样式 */
details.thinking-process { border: 1px dashed #ced4da; border-radius: 8px; padding: 8px 12px; margin: 12px 0; background: #f8f9fa; }
details.thinking-process summary { cursor: pointer; font-weight: 600; color: #6c757d; user-select: none; list-style-type: '🤔 '; }
details.thinking-process summary:focus { outline: none; }
.thinking-content { padding-top: 8px; color: #495057; font-style: italic; white-space: pre-wrap; }

#chat-input-area { flex-shrink: 0; padding: 15px 10px; background: var(--card-bg); }
.chat-input-wrapper { max-width: 820px; margin: 0 auto; position: relative; }
#chat-form { display: flex; align-items: flex-end; gap: 10px; padding: 8px; background: #f1f3f5; border-radius: 28px; border: 1px solid #dee2e6; }
#chat-input { flex-grow: 1; border: none; background: transparent; resize: none; font-size: 16px; max-height: 120px; line-height: 1.5; padding: 8px 0; }
#chat-input:focus { outline: none; }
#chat-form button { background: none; border: none; cursor: pointer; padding: 8px; color: #495057; display: flex; align-items: center; justify-content: center; }
#chat-form button:disabled { color: #adb5bd; cursor: not-allowed; }
#send-btn { background-color: var(--primary-color); border-radius: 50%; }
#send-btn svg { color: white; }
#send-btn:disabled { background-color: #adb5bd; }

#preview-container { display: flex; gap: 10px; padding: 0 10px 10px; overflow-x: auto; }
.file-preview { position: relative; }
.file-preview img { max-height: 50px; border-radius: 8px; border: 1px solid var(--border-color); }
.remove-file { position: absolute; top: -5px; right: -5px; background: rgba(0,0,0,0.7); color: white; border-radius: 50%; width: 18px; height: 18px; border: none; font-size: 12px; line-height: 18px; text-align: center; cursor: pointer; }

.thinking-cursor::after { content: '▋'; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 768px) {
    #main-container { padding: 15px; }
    .search-bar { max-width: 100%; }
    .links-grid { grid-template-columns: 1fr; }
    #chat-messages { padding: 0 15px; }
}
/* --- 新增：C语言代码练习弹窗样式 --- */
.modal-content.code-modal {
    max-width: 800px; /* 为代码弹窗设置更宽的尺寸 */
}

.modal-content.code-modal .modal-body {
    padding-top: 0;
    max-height: 70vh; /* 限制内容区域高度，使其可滚动 */
    overflow-y: auto;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    /* 为滚动条美化 */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}
.modal-tabs::-webkit-scrollbar { height: 4px; }
.modal-tabs::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 2px; }

.modal-tab-btn {
    padding: 12px 18px;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 15px;
    color: #6c757d;
    transition: color 0.2s, border-bottom 0.2s;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
}
.modal-tab-btn:hover { color: var(--primary-color); }
.modal-tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.modal-tab-content {
    display: none; /* 默认隐藏 */
    padding: 25px 5px 10px;
    animation: fadeIn 0.4s;
}
.modal-tab-content.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.code-explanation h4 {
    font-size: 18px;
    margin-top: 25px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
    color: #343a40;
}
.code-explanation p, .code-explanation ul, .code-explanation ol {
    font-size: 15px;
    line-height: 1.8;
    color: #495057;
}
.code-explanation ul, .code-explanation ol {
    padding-left: 25px;
    margin-top: 10px;
}
.code-explanation code {
    background-color: #e9ecef;
    padding: .2em .4em;
    margin: 0;
    font-size: 85%;
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

/* 针对代码块的增强样式 */
.modal-tab-content pre {
    position: relative; /* 用于定位按钮 */
    background: #282c34;
    border-radius: 8px;
    margin: 15px 0;
}

.code-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.modal-tab-content pre:hover .code-actions { opacity: 1; }

.copy-code-btn, .download-code-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #abb2bf;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.copy-code-btn:hover, .download-code-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
}

.copy-code-btn.copied {
    background-color: rgba(40, 167, 69, 0.2);
    color: #4cd964;
    border-color: #4cd964;
}