/**
 * 通用演示页面样式
 * 适用于: huffman.html, tree.html 等数据结构可视化页面
 */

/* ==================== CSS变量 ==================== */
:root {
    --primary-color: #8527d2b2;
    --secondary-color: #f5f5f5eb;
    --text-color: #333;
    --light-text: #fff;
    --transition: all 0.3s ease;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --node-root: #E91E63;
    --edge-color: #666;
    
    /* 霍夫曼页面特有变量 */
    --node-leaf: #4CAF50;
    --node-internal: #FF9800;
    
    /* 树转换页面特有变量 */
    --node-normal: #4CAF50;
    --node-binary: #2196F3;
    
    /* 主题色变量 - 可被页面覆盖 */
    --theme-primary: #667eea;
    --theme-secondary: #764ba2;
    --theme-gradient: linear-gradient(135deg, var(--theme-primary) 0%, var(--theme-secondary) 100%);
}

/* ==================== 基础重置 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--secondary-color);
    background-image: url('https://cdn.jsdelivr.net/gh/FunctionHookTJU/fxHook.io@master/assets/images/background4k.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(245, 245, 245, 0.29);
    z-index: -1;
}

/* ==================== 主容器 ==================== */
.main-container {
    max-width: 1600px;
    margin: 20px auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

/* ==================== 页面头部 ==================== */
.page-header {
    background: var(--theme-gradient);
    color: white;
    padding: 30px;
    text-align: center;
}

.page-header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

/* ==================== 内容布局 ==================== */
.content-wrapper {
    display: flex;
    gap: 20px;
    padding: 30px;
    flex-wrap: wrap;
}

.left-panel {
    flex: 1;
    min-width: 350px;
}

.right-panel {
    flex: 2;
    min-width: 600px;
}

/* ==================== 区块样式 ==================== */
.section {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
}

.section h2 {
    color: var(--theme-primary);
    margin-bottom: 15px;
    font-size: 1.3em;
    border-bottom: 2px solid var(--theme-primary);
    padding-bottom: 10px;
}

.section h3 {
    color: #555;
    margin: 15px 0 10px;
    font-size: 1.1em;
}

.section p {
    margin-bottom: 12px;
}

/* ==================== 输入区域 ==================== */
.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.input-group input,
.input-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--theme-primary);
}

.input-group textarea {
    min-height: 100px;
    resize: vertical;
    font-family: 'Courier New', monospace;
}

/* ==================== 按钮样式 ==================== */
.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--theme-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

.btn-step {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
}

.btn-step:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(17, 153, 142, 0.4);
}

.btn-convert {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-convert:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

/* ==================== 示例按钮 ==================== */
.examples {
    margin-top: 15px;
}

.examples span {
    font-weight: 600;
    margin-right: 10px;
}

.example-btn {
    padding: 6px 12px;
    margin: 3px;
    border: 1px solid var(--theme-primary);
    background: white;
    color: var(--theme-primary);
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.example-btn:hover {
    background: var(--theme-primary);
    color: white;
}

/* ==================== 模式切换 ==================== */
.mode-switch {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f4ff;
    border-radius: 8px;
    flex-wrap: wrap;
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 15px;
    border-radius: 6px;
    transition: all 0.3s;
}

.mode-option:hover {
    background: #e0e8ff;
}

.mode-option.active {
    border-color: var(--theme-primary);
    background: #e0e8ff;
}

.mode-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--theme-primary);
}

.mode-option input[type="radio"]:checked + .mode-label {
    color: var(--theme-primary);
    font-weight: 600;
}

.mode-label {
    font-size: 14px;
}

/* ==================== Canvas 容器 ==================== */
.canvas-container {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    min-height: 400px;
    overflow: auto;
    position: relative;
}

.canvas-container svg {
    display: block;
    margin: 0 auto;
}

/* ==================== 图例 ==================== */
.legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 15px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.legend-color.leaf {
    background: var(--node-leaf);
}

.legend-color.internal {
    background: var(--node-internal);
}

.legend-color.root {
    background: var(--node-root);
}

.legend-color.normal {
    background: var(--node-normal);
}

.legend-color.binary {
    background: var(--node-binary);
}

/* ==================== 通用表格 ==================== */
.freq-table,
.code-table,
.info-table,
.weight-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.freq-table th, .freq-table td,
.code-table th, .code-table td,
.info-table th, .info-table td,
.weight-table th, .weight-table td {
    padding: 10px 12px;
    border: 1px solid #ddd;
    text-align: center;
}

.freq-table th {
    background: var(--theme-primary);
    color: white;
}

.code-table th {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
}

.info-table th {
    background: var(--theme-primary);
    color: white;
}

.info-table th, .info-table td {
    text-align: left;
}

.weight-table th {
    background: var(--theme-gradient);
    color: white;
}

.freq-table tr:nth-child(even),
.info-table tr:nth-child(even),
.weight-table tr:nth-child(even) {
    background: #f8f9fa;
}

.code-table tr:nth-child(even) {
    background: #f0fff4;
}

.code-table .code {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #e91e63;
}

/* ==================== 错误提示 ==================== */
.error-msg {
    color: #dc3545;
    background: #f8d7da;
    padding: 10px 15px;
    border-radius: 8px;
    margin-top: 10px;
    display: none;
}

.error-msg.show {
    display: block;
}

/* ==================== 算法卡片/步骤卡片 ==================== */
.algo-card,
.step-card {
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    border-radius: 10px;
    padding: 15px;
    margin: 10px 0;
}

.algo-card h4,
.step-card h4 {
    color: #4a148c;
    margin-bottom: 8px;
}

.algo-card ol,
.step-card ol {
    padding-left: 20px;
}

.algo-card li {
    margin: 5px 0;
}

.step-card li {
    margin: 8px 0;
}

/* ==================== 代码块 ==================== */
.code-block {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    overflow-x: auto;
    white-space: pre;
    line-height: 1.5;
}

.code-keyword { color: #66d9ef; }
.code-type { color: #a6e22e; }
.code-comment { color: #75715e; }

/* ==================== 结果区域 ==================== */
.encoded-result,
.traversal-result {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.encoded-result h4,
.traversal-result h4 {
    color: #00695c;
    margin-bottom: 10px;
}

.encoded-string {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    word-break: break-all;
    background: white;
    padding: 10px;
    border-radius: 5px;
    margin-top: 10px;
}

.stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.stat-item {
    background: white;
    padding: 8px 15px;
    border-radius: 5px;
    font-size: 14px;
}

.stat-item strong {
    color: var(--theme-primary);
}

.traversal-item {
    background: white;
    padding: 8px 15px;
    border-radius: 5px;
    margin: 5px 0;
    font-family: 'Courier New', monospace;
}

.traversal-item strong {
    color: var(--theme-primary);
}

/* ==================== 动画 ==================== */
@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.node-animated {
    animation: nodeAppear 0.3s ease-out;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

/* ==================== 页脚 ==================== */
footer {
    background-color: var(--primary-color);
    color: var(--light-text);
    padding: 1rem 0;
    margin-top: auto;
}

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

footer .footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

footer .footer-links {
    display: flex;
    gap: 2rem;
}

footer .footer-links a {
    color: var(--light-text);
    text-decoration: none;
}

footer .copyright {
    font-size: 0.875rem;
    opacity: 0.8;
}

/* ==================== 响应式布局 ==================== */
@media (max-width: 1000px) {
    .content-wrapper {
        flex-direction: column;
    }

    .left-panel, .right-panel {
        min-width: 100%;
    }

    .page-header h1 {
        font-size: 1.8em;
    }
}
