/* ============================================
RemUp 样式系统 v3.4 - 标签布局优化版
============================================ */

/* 基础变量定义 */
:root {
    /* 主色调 */
    --remup-primary: #3498db;
    --remup-secondary: #2ecc71;
    --remup-accent: #e74c3c;
    --remup-gray: #95a5a6;
    --remup-light-gray: #ecf0f1;
    
    /* 卡片颜色 */
    --card-bg: #ffffff;
    --card-shadow: rgba(0, 0, 0, 0.08);
    --card-border: #e0e0e0;
    
    /* 区域线颜色 */
    --region-line: #bdc3c7;
    --region-title: #7f8c8d;
    
    /* 字体 */
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Microsoft YaHei', sans-serif;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    
    /* 新增：阅读优化变量 */
    --font-size-base: 14px;
    --font-size-large: 1.3em;
    --font-size-small: 0.85em;
    --line-height-comfort: 1.5;
    --spacing-compact: 0.8rem;
}

/* 重置和基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    font-size: var(--font-size-base);
    line-height: var(--line-height-comfort);
    color: #2c3e50;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 15px;
    min-height: 100vh;
}

.container {
    max-width: none;
    width: 100%;
    margin: 0 auto;
    padding: 15px;
}

/* 页面标题样式 */
.page-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}

.page-header h1 {
    color: var(--remup-primary);
    margin-bottom: 8px;
    font-size: 2em;
}

/* ============================================
    主卡样式 - 重新设计标签布局
    ============================================ */
.card {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 3px 15px var(--card-shadow);
    border: 1px solid var(--card-border);
    padding: 20px;
    margin-bottom: 0;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    min-width: 0;
    font-size: var(--font-size-base);
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

/* 卡片标题区域 - 简化布局 */
.card-header {
    margin-bottom: 12px;
}

.card h2 {
    color: var(--remup-primary);
    border-bottom: 2px solid var(--remup-primary);
    padding-bottom: 8px;
    margin-bottom: 12px;
    font-size: 1.5em;
    position: relative;
    padding-left: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
    display: flex;
    align-items: center;
}

.card h2::before {
    content: '<+';
    color: var(--remup-gray);
    font-family: var(--font-mono);
    font-size: 0.7em;
    margin-right: 6px;
    opacity: 0.7;
    flex-shrink: 0;
}

.card h2::after {
    content: '/+>';
    color: var(--remup-gray);
    font-family: var(--font-mono);
    font-size: 0.7em;
    margin-left: 6px;
    opacity: 0.7;
    flex-shrink: 0;
}

/* 卡片标题文本容器 */
.card-title-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
    标签系统 - 重新设计为独立行布局
    ============================================ */
.labels-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    margin-bottom: 15px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    min-height: 32px;
    align-items: center;
}

/* 没有标签时的占位样式 */
.labels-container:empty {
    display: none;
}

.label {
    display: inline-flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 16px;
    padding: 6px 12px;
    text-decoration: none;
    color: #495057;
    font-size: 0.85em;
    transition: all 0.3s ease;
    max-width: 200px;
    overflow: hidden;
    border: 1px solid #dee2e6;
    position: relative;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1;
}

.label:hover {
    background: #e9ecef;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 3;
}

/* 可跳转标签的特殊样式 */
.label[href]:not(.label[href=""]) {
    border: 1.5px solid var(--remup-primary);
    background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);
    cursor: pointer;
}

.label[href]:not(.label[href=""]):hover {
    background: linear-gradient(135deg, #e6f3ff 0%, #d4eaff 100%);
    box-shadow: 0 3px 8px rgba(52, 152, 219, 0.2);
}

/* 可跳转标签的指示器 */
.label[href]:not(.label[href=""])::after {
    content: '↗';
    margin-left: 4px;
    font-size: 0.9em;
    color: var(--remup-primary);
    opacity: 0.8;
    flex-shrink: 0;
}

.label-symbol {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--remup-primary);
    margin-right: 6px;
    font-size: 0.8em;
    font-weight: bold;
    color: var(--remup-primary);
    flex-shrink: 0;
}

.label-content {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* 标签类型颜色映射 */
.label.default .label-symbol {
    border-color: var(--remup-primary);
    color: var(--remup-primary);
}
.label.important .label-symbol {
    border-color: var(--remup-accent);
    color: var(--remup-accent);
}
.label.reference .label-symbol {
    border-color: #3498db;
    color: #3498db;
}
.label.question .label-symbol {
    border-color: #f39c12;
    color: #f39c12;
}
.label.info .label-symbol {
    border-color: var(--remup-gray);
    color: var(--remup-gray);
}

/* 标签链接样式 */
.label-link {
    color: inherit;
    text-decoration: none;
    margin-right: 3px;
}

.label-link:hover {
    text-decoration: underline;
}

/* ============================================
    区域系统 - 紧凑布局
    ============================================ */
.region {
    margin-bottom: 2em;
    position: relative; /* 添加相对定位，让 region-title 绝对定位有参考 */
}

.region-line {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        var(--region-line) 20%, 
        var(--region-line) 80%, 
        transparent 100%);
    margin: 8px 0 15px 0;
    position: relative;
}

/* 没有标题的区域，横线使用实线，方便查看 */
.region-no-title .region-line {
    background: var(--region-line);
    margin: 10px 0 15px 0;
}

.region-title {
    position: absolute;
    top: -8px;
    left: 0; /* 调整为 0，与正文内容左对齐 */
    background: var(--card-bg);
    padding: 0 4px; /* 稍微减少 padding */
    font-size: 0.8em;
    font-weight: bold;
    color: var(--region-title);
    opacity: 0.8;
    letter-spacing: 0.5px;
    z-index: 1; /* 确保标题在线上方 */
}

.region-content {
    margin-top: 12px;
    position: relative;
}

/* ============================================
    列表样式 - 紧凑布局
    ============================================ */
.region-content ul,
.region-content ol {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.region-content li {
    position: relative;
    padding-left: 1.2em;
    margin-bottom: 0.4em;
    font-size: 0.95em;
}

.region-content ul li::before {
    content: '';
    position: absolute;
    left: 0.2em;
    top: 0.5em;
    width: 0.35em;
    height: 0.35em;
    border-radius: 50%;
    background-color: var(--remup-primary);
}

.region-content ol {
    counter-reset: li-counter;
}

.region-content ol li::before {
    content: counter(li-counter) ".";
    counter-increment: li-counter;
    position: absolute;
    left: 0;
    color: var(--remup-primary);
    font-weight: bold;
    font-size: 0.9em;
}

/* ============================================
    内容样式 - 阅读优化
    ============================================ */
.content {
    line-height: var(--line-height-comfort);
    font-size: var(--font-size-base);
    position: relative;
}

.content p {
    margin-bottom: 12px;
    font-size: 0.95em;
}

/* ============================================
    代码块样式
    ============================================ */
.code-block {
    background: #2d3748;
    color: #e2e8f0;
    padding: 15px;
    border-radius: 6px;
    margin: 15px 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.85em;
    line-height: 1.4;
    position: relative;
    z-index: 1;
}

.code-block pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* 代码高亮样式 */
.keyword { color: #c678dd; font-weight: bold; }
.number { color: #d19a66; }
.string { color: #98c379; }
.comment { color: #5c6370; font-style: italic; }

/* ============================================
    行内解释 (>>语法) - 解决与注卡重叠问题
    ============================================ */
.inline-explanation {
    display: block;
    color: #7f8c8d;
    opacity: 0.7;
    font-size: 0.85em;
    font-style: italic;
    margin-top: 8px; /* 增加上边距，避免与注卡重叠 */
    margin-bottom: 12px;
    padding-left: 16px;
    position: relative;
    white-space: normal;
    word-wrap: break-word;
    z-index: 1; /* 确保在注卡下方 */
}

.inline-explanation::before {
    content: '>>';
    position: absolute;
    left: 0;
    color: var(--remup-gray);
    font-family: var(--font-mono);
    font-size: 0.8em;
}

/* ============================================
    注卡系统 (`内容`[批注]) - 优化定位避免重叠
    ============================================ */
.annotation-container {
    position: relative;
    display: inline;
    z-index: 10; /* 提高层级 */
}

.annotation {
    position: relative;
    display: inline;
    cursor: pointer;
    color: #2980b9;
    border-bottom: 1px dashed #2980b9;
    transition: all 0.2s ease;
    padding: 1px 3px;
    border-radius: 2px;
    background: rgba(52, 152, 219, 0.08);
    z-index: 10;
}

.annotation:hover {
    background: rgba(52, 152, 219, 0.15);
    border-bottom-style: solid;
}

/* 注卡激活状态（点击后） */
.annotation.active {
    background: rgba(52, 152, 219, 0.2);
    border-bottom: 2px solid #2980b9;
    border-bottom-style: solid;
    z-index: 10001;
}

/* 注卡弹出框 - 优化定位逻辑 */
.annotation-popup {
    position: absolute;
    z-index: 10000;
    background: white;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    padding: 10px;
    width: 220px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 0.85em;
    line-height: 1.4;
    color: #2c3e50;
    display: none;
    animation: fadeIn 0.2s ease;
    pointer-events: none;
    /* 智能定位：优先向上弹出，空间不足时向下 */
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
}

/* 如果上方空间不足，改为向下弹出 */
.annotation-container:has(.annotation.active):not(:first-child) .annotation-popup {
    bottom: auto;
    top: calc(100% + 8px);
}

/* 悬停时显示 */
.annotation-container:hover .annotation-popup {
    display: block;
    pointer-events: auto;
}

/* 激活状态时显示（点击后保持显示） */
.annotation.active + .annotation-popup,
.annotation-container:focus-within .annotation-popup {
    display: block;
    pointer-events: auto;
    z-index: 10002;
}

/* 跳回原文链接 */
.back-to-source {
    display: block;
    margin-top: 6px;
    font-size: 0.75em;
    color: var(--remup-primary);
    text-decoration: none;
}

.back-to-source:hover {
    text-decoration: underline;
}

/* 动画效果 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(3px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
    归档系统 - 按钮样式优化
    ============================================ */
.archive-section {
    width: 100%;
    margin-bottom: 25px;
}

.archive-title {
    font-size: 1.7em;
    margin-bottom: 15px;
    color: #2c3e50;
    border-bottom: 2px solid var(--remup-primary);
    padding-bottom: 8px;
    position: relative;
}

.archive-title::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--remup-primary);
}

.archive-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px; /* 减少间距 */
    width: 100%;
}

/* 归档卡片容器 */
.archive-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #e8e8e8;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.archive-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
    border-color: var(--remup-primary);
}

/* 归档卡片标题 */
.archive-card-title {
    font-size: 1.3em;
    color: var(--remup-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 600;
}

/* 归档卡片内容 */
.archive-card-content {
    flex: 1;
    margin-bottom: 15px;
    color: #5a6c7d;
    font-size: 0.95em;
    line-height: 1.5;
}

/* 归档卡片链接按钮 - 优化样式 */
.archive-card-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-size: 0.9em;
    font-weight: 500;
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    margin-top: auto; /* 确保按钮在底部 */
}

.archive-card-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.archive-card-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
    background: linear-gradient(135deg, #2980b9 0%, #2471a3 100%);
}

.archive-card-link:hover::before {
    left: 100%;
}

.archive-card-link:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

/* 按钮图标 */
.archive-card-link::after {
    content: '→';
    margin-left: 8px;
    font-weight: bold;
    transition: transform 0.3s ease;
}

.archive-card-link:hover::after {
    transform: translateX(3px);
}

/* ============================================
    注点归档样式优化
    ============================================ */
.vibe-archive {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid var(--remup-primary);
}

.vibe-archive-title {
    color: #2c3e50;
    font-size: 1.4em;
    margin-bottom: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
}

.vibe-archive-title::before {
    content: '📚';
    margin-right: 10px;
    font-size: 1.2em;
}

.vibe-archive-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.vibe-archive-card {
    background: white;
    padding: 15px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border-left: 3px solid #3498db;
    transition: all 0.2s ease;
}

.vibe-archive-card:hover {
    transform: translateX(3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.vibe-archive-item {
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}

.vibe-archive-item:last-child {
    border-bottom: none;
}

.vibe-archive-item::before {
    content: '•';
    color: var(--remup-primary);
    margin-right: 8px;
    font-weight: bold;
}

/* 注点归档跳转链接优化 */
.vibe-link {
    color: var(--remup-primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
}

.vibe-link:hover {
    color: #2980b9;
    text-decoration: underline;
    transform: translateX(2px);
}

.vibe-link::after {
    content: '↗';
    margin-left: 4px;
    font-size: 0.9em;
}

/* ============================================
    导航链接样式
    ============================================ */
.archive-card-link {
    display: block;
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-align: center;
    font-size: 0.9em;
}

.archive-card-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

/* ============================================
    响应式设计 - 优化布局
    ============================================ */
/* ============================================
    响应式设计 - 归档部分优化
    ============================================ */
@media (max-width: 768px) {
    .archive-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .archive-card {
        padding: 15px;
    }
    
    .archive-card-title {
        font-size: 1.2em;
    }
    
    .vibe-archive-cards {
        grid-template-columns: 1fr;
    }
    
    .vibe-archive {
        padding: 15px;
        margin: 15px 0;
    }
}

@media (min-width: 1024px) {
    .archive-cards {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 18px;
    }
    
    .vibe-archive-cards {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 15px;
    }
}

/* 小屏幕优化 */
@media (max-width: 480px) {
    .archive-card-link {
        padding: 8px 16px;
        font-size: 0.85em;
    }
    
    .vibe-archive-item {
        font-size: 0.85em;
    }
}

@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
        margin: 0 auto;
    }
    
    .archive-cards {
        grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    }
}

/* ============================================
    工具类
    ============================================ */
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mb-1 { margin-bottom: 8px; }

/* 滚动锚点偏移 */
:target {
    scroll-margin-top: 15px;
    background-color: rgba(255, 255, 0, 0.15);
    transition: background-color 0.3s ease;
}

/* 焦点样式 */
.card:focus {
    outline: 2px solid var(--remup-primary);
    outline-offset: 1px;
}

/* 打印优化 */
@media print {
    body {
        background: white;
        padding: 0;
        font-size: 12pt;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
    
    .labels-container {
        border-bottom: 1px solid #ddd;
    }
    
    .annotation-popup {
        display: block !important;
        position: relative;
        width: 100%;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}