/* --- 基本样式 --- */
body {
    font-family: Arial, sans-serif;
    background-color: #f8f9fa;
    margin: 0;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1000px; /* 增加宽度以容纳并行通道 */
    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);
}
.control-btn:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
}

.mode-btn { background-color: #17a2b8; } /* Info Blue */
.mode-btn:hover:not(:disabled) { background-color: #138496; }
.mode-btn.active { background-color: #117a8b; font-weight: bold; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }

.action-btn { background-color: #28a745; } /* Green */
.action-btn:hover:not(:disabled) { background-color: #218838; }
#reset-btn { background-color: #dc3545; } /* Red */
#reset-btn:hover:not(:disabled) { background-color: #c82333; }

.data-input {
    display: flex;
    align-items: center;
    gap: 5px;
}
.data-input label {
    font-size: 0.9em;
    color: #495057;
}
.data-input input {
    padding: 5px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    width: 100px; /* 固定宽度 */
    text-align: center;
    font-family: monospace; /* 等宽字体 */
}

/* --- 模拟区域 --- */
.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: 250px;
    position: relative;
}

.node {
    width: 150px;
    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;
}

.data-buffer {
    margin-top: 10px;
    font-size: 1.1em;
    font-family: monospace; /* 等宽字体 */
    padding: 5px 10px;
    border-radius: 4px;
    background-color: #e9ecef;
    color: #495057;
    min-height: 1.5em; /* 保证高度 */
    word-break: break-all; /* 允许在字符间换行 */
    min-width: 120px; /* 最小宽度 */
    text-align: center;
}

/* --- 通信通道容器 --- */
.communication-channel-container {
    flex-grow: 1;
    height: 180px; /* 足够容纳并行通道 */
    margin: 0 20px;
    position: relative;
    display: flex; /* 使用flex布局来控制内部通道的显示 */
    justify-content: center;
    align-items: center;
}

.communication-channel {
    position: absolute; /* 让通道重叠，通过JS控制显示 */
    width: 100%;
    height: 100%;
    display: none; /* 初始隐藏 */
    flex-direction: column;
    justify-content: space-around; /* 分布并行线 */
    align-items: center;
}
.communication-channel.active {
    display: flex; /* 激活时显示 */
}

/* 单个通道线 */
.channel-line {
    width: 100%;
    height: 3px;
    background-color: #adb5bd;
    position: relative; /* 用于定位bit */
}

/* 串行通道只有一条线居中 */
.serial-channel .channel-line {
    height: 4px; /* 串行线稍粗 */
    background-color: #007bff;
}

/* 并行通道的多条线 */
.parallel-channel {
    padding: 10px 0; /* 上下留白 */
    gap: 8px; /* 线之间的间距 */
}
.parallel-channel .channel-line {
    background-color: #6c757d;
}

/* --- 数据位 (Bit) --- */
.bit {
    position: absolute;
    top: 50%;
    left: 0; /* 初始在最左边 */
    width: 18px;
    height: 18px;
    background-color: #ffc107; /* Yellow */
    border: 1px solid #e0a800;
    border-radius: 50%; /* 圆形 */
    color: #343a40;
    font-size: 0.8em;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transform: translateY(-50%);
    transition: left 1s linear; /* 移动动画 */
    z-index: 10;
}
.bit.bit-0 { background-color: #f8f9fa; border-color: #adb5bd; color: #6c757d;} /* '0' bit style */
.bit.bit-1 { background-color: #ffc107; border-color: #e0a800; color: #343a40;} /* '1' bit style */

/* --- 信息面板和说明卡片 --- */
.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 ul ul { margin-top: 5px; } /* 嵌套列表样式 */
.card-content li li { margin-bottom: 5px; font-size: 0.95em;}
.card-content strong { color: #343a40; }

/* --- 响应式调整 --- */
@media (max-width: 768px) {
    .simulation-area {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    .node {
        width: 60%;
    }
    .communication-channel-container {
        width: 90%;
        height: 200px; /* 增加高度 */
        margin: 10px 0;
    }
    .bit {
        width: 15px;
        height: 15px;
        font-size: 0.7em;
    }
}