/* --- 基本样式 --- */
body {
    font-family: Arial, sans-serif;
    background-color: #f8f9fa;
    margin: 0;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 20px auto;
    background-color: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

h1 {
    text-align: center;
    color: #343a40;
    margin-bottom: 10px;
}

.description {
    text-align: center;
    color: #6c757d;
    margin-bottom: 30px;
    font-size: 1.1em;
}

/* --- 控制按钮 --- */
.simulation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 40px;
    gap: 15px;
    flex-wrap: wrap; /* 允许换行 */
}

.control-btn {
    padding: 10px 20px;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 15px;
    transition: background-color 0.3s, box-shadow 0.3s, transform 0.1s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.control-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.mode-btn { background-color: #17a2b8; } /* Info Blue */
.mode-btn:hover { background-color: #138496; }
.mode-btn.active { background-color: #117a8b; font-weight: bold; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }

#reset-btn { background-color: #6c757d; } /* Grey */
#reset-btn:hover { background-color: #5a6268; }

/* --- 模拟区域 --- */
.simulation-area {
    display: flex;
    justify-content: space-between;
    align-items: center; /* 垂直居中对齐 */
    padding: 30px 20px;
    background-color: #fdfdfd;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    min-height: 200px;
    position: relative;
}

.node {
    width: 130px;
    text-align: center;
    padding: 15px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.node-title {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: #495057;
}

.node-icon img {
    width: 50px;
    height: auto;
    margin-bottom: 10px;
}

.status {
    margin-top: 10px;
    font-size: 0.9em;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: #e9ecef;
    color: #495057;
    min-width: 50px; /* 避免文字换行时宽度变化 */
    transition: background-color 0.3s, color 0.3s;
}
.status.sending { background-color: #cce5ff; color: #004085; } /* Blue */
.status.receiving { background-color: #d4edda; color: #155724; } /* Green */

/* --- 通信通道和数据流 --- */
.communication-channel {
    flex-grow: 1;
    height: 100px; /* 通道高度 */
    margin: 0 30px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center; /* 垂直居中箭头 */
}

.data-flow {
    position: absolute;
    width: 100%;
    opacity: 0; /* 初始隐藏 */
    transition: opacity 0.5s ease-in-out;
}

.data-flow .arrow {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 3px; /* 箭头线粗细 */
    background-color: #adb5bd; /* 默认灰色 */
    transform: translateY(-50%);
    animation: none; /* 初始无动画 */
}

.data-flow .arrow::after { /* 箭头头部 */
    content: '';
    position: absolute;
    top: 50%;
    right: -1px;
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 12px solid #adb5bd; /* 默认灰色 */
    transform: translateY(-50%);
}

/* 数据流标签 */
.data-flow .label {
    position: absolute;
    top: -22px; /* 标签在箭头上 */
    left: 50%;
    transform: translateX(-50%);
    background-color: #fff;
    padding: 2px 6px;
    font-size: 0.8em;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    white-space: nowrap;
    color: #6c757d;
}

/* 不同模式和方向的样式 */
.data-flow.a-to-b { /* A -> B 方向 */ }
.data-flow.b-to-a .arrow { /* B -> A 方向 */
    left: auto;
    right: 0;
}
.data-flow.b-to-a .arrow::after {
    right: auto;
    left: -1px;
    border-left: none;
    border-right: 12px solid #adb5bd; /* 默认灰色 */
}

/* 模式特定颜色 */
.data-flow.simplex .arrow, .data-flow.simplex .arrow::after { background-color: #007bff; border-left-color: #007bff; } /* Blue */
.data-flow.half-duplex.a-to-b .arrow, .data-flow.half-duplex.a-to-b .arrow::after { background-color: #ffc107; border-left-color: #ffc107; } /* Yellow */
.data-flow.half-duplex.b-to-a .arrow { background-color: #fd7e14; } /* Orange */
.data-flow.half-duplex.b-to-a .arrow::after { border-right-color: #fd7e14; } /* Orange */
.data-flow.full-duplex.a-to-b .arrow, .data-flow.full-duplex.a-to-b .arrow::after { background-color: #28a745; border-left-color: #28a745; } /* Green */
.data-flow.full-duplex.b-to-a .arrow { background-color: #dc3545; } /* Red */
.data-flow.full-duplex.b-to-a .arrow::after { border-right-color: #dc3545; } /* Red */

/* 调整全双工箭头的垂直位置，避免重叠 */
.data-flow.full-duplex.a-to-b { top: 35%; }
.data-flow.full-duplex.b-to-a { top: 65%; }
/* 调整半双工箭头的垂直位置 */
.data-flow.half-duplex.a-to-b { top: 35%; }
.data-flow.half-duplex.b-to-a { top: 65%; }
/* 单工居中 */
.data-flow.simplex.a-to-b { top: 50%; transform: translateY(-50%); }


/* 数据流动动画 (简单示例：闪烁) */
@keyframes blink-flow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.data-flow.active .arrow {
    animation: blink-flow 1s infinite;
}

/* --- 信息面板和说明卡片 --- */
.info-panel, .explanation-card {
    margin-top: 30px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
}

.panel-title, .card-title {
    font-weight: bold;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
    font-size: 1.1em;
    color: #495057;
}

.panel-content, .card-content {
    color: #6c757d;
    font-size: 1em;
    min-height: 30px;
}

.panel-content p { margin: 0; }
.card-content ul { padding-left: 20px; margin: 0; }
.card-content li { margin-bottom: 10px; }
.card-content strong { color: #343a40; }

/* --- 响应式调整 --- */
@media (max-width: 768px) {
    .simulation-area {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    .node {
        width: 60%;
    }
    .communication-channel {
        width: 80%;
        margin: 10px 0;
        height: 120px; /* 增加高度以容纳箭头 */
    }
    .data-flow .label {
        font-size: 0.75em;
        top: -18px;
    }
}