body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    margin: 0;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 10px;
}

.description {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
}

/* 控制按钮 */
.simulation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
}

.control-btn {
    padding: 10px 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.control-btn:hover {
    background-color: #45a049;
}

#reset-btn {
    background-color: #f44336;
}

#reset-btn:hover {
    background-color: #d32f2f;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 模拟容器 */
.simulation-container {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

/* 设备部分 */
.devices-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    position: relative; /* 添加相对定位 */
    overflow: visible; /* 确保溢出内容可见 */
}

.device {
    text-align: center;
    width: 120px; /* 减小设备宽度 */
    flex-shrink: 0; /* 防止设备被压缩 */
}

.device-title {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 14px;
}

.device-icon img {
    width: 60px; /* 调整图标大小 */
    height: auto;
}

.network-line {
    flex-grow: 1;
    height: 5px;
    background-color: #ddd;
    position: relative;
    margin: 0 20px;
    min-width: 300px; /* 确保网络线有足够的宽度 */
}

.data-packet {
    width: 25px; /* 调整数据包大小 */
    height: 25px;
    background-color: #2196F3; /* 更改颜色 */
    border: 2px solid #1976D2;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 0;
    transform: translate(-50%, -50%);
    z-index: 10; /* 确保数据包在最上层 */
    display: none; /* 初始隐藏 */
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.7);
}

/* OSI层部分 */
.osi-layers-container {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    width: 100%;
    overflow-x: auto; /* 如果内容过宽，允许水平滚动 */
}

.osi-column {
    width: 48%; /* 稍微减少宽度，留出间距 */
    display: flex;
    flex-direction: column;
}

.sender-column {
    align-items: flex-start; /* 左对齐 */
}

.receiver-column {
    align-items: flex-end; /* 右对齐 */
}

.layer-title {
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
    width: 100%;
    font-size: 16px;
    color: #555;
}

.osi-layer {
    display: flex;
    width: 100%;
    min-height: 50px; /* 调整最小高度 */
    margin-bottom: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    background-color: #fff;
    transition: background-color 0.5s; /* 添加背景色过渡 */
}

.sender-column .osi-layer {
    flex-direction: row;
}

.receiver-column .osi-layer {
    flex-direction: row-reverse;
}

.layer-name {
    width: 100px; /* 调整层名称宽度 */
    background-color: #e0e0e0; /* 调整背景色 */
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 13px; /* 调整字体大小 */
    color: #333;
    padding: 8px 5px; /* 调整内边距 */
    text-align: center;
    border-right: 1px solid #ccc; /* 调整边框 */
}

.receiver-column .layer-name {
    border-right: none;
    border-left: 1px solid #ccc; /* 调整边框 */
}

.layer-content {
    flex-grow: 1;
    padding: 8px 10px; /* 调整内边距 */
    position: relative;
    overflow: hidden;
    display: flex; /* 使用flex布局 */
    align-items: center; /* 垂直居中 */
    min-height: 30px; /* 确保有最小高度 */
}

/* 数据包表示 */
.data-unit {
    display: flex;
    align-items: center;
    font-family: monospace;
    font-size: 11px; /* 调整字体大小 */
    opacity: 0; /* 初始透明 */
    transition: opacity 0.5s ease-in-out;
    width: 100%; /* 占据全部宽度 */
    flex-wrap: wrap; /* 允许换行 */
    gap: 3px; /* 元素间距 */
}

.header, .trailer, .data-content {
    padding: 3px 5px; /* 调整内边距 */
    border-radius: 3px;
    white-space: nowrap;
    margin: 1px; /* 微调间距 */
}

.header {
    background-color: #ffebee; /* 浅红色 */
    border: 1px solid #ffcdd2;
    color: #c62828;
}

.data-content {
    background-color: #e3f2fd; /* 浅蓝色 */
    border: 1px solid #bbdefb;
    color: #1565c0;
    flex-shrink: 0; /* 防止数据内容被过度压缩 */
}

.trailer {
    background-color: #f1f8e9; /* 浅绿色 */
    border: 1px solid #dcedc8;
    color: #558b2f;
}

/* 信息面板 */
.info-panel {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
}

.panel-title {
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    font-size: 16px;
    color: #555;
}

.panel-content {
    color: #666;
    font-size: 14px;
    min-height: 40px; /* 确保有最小高度 */
}

.panel-content p {
    margin: 0;
}

.success-message {
    color: #4CAF50;
    font-weight: bold;
    margin-top: 5px;
}

/* 说明卡片 */
.explanation-card {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 20px;
}

.card-title {
    font-weight: bold;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    font-size: 16px;
    color: #555;
}

.card-content {
    color: #666;
    font-size: 14px;
}

.card-content h3 {
    margin: 15px 0 10px 0;
    color: #333;
    font-size: 15px;
}

.card-content ul {
    padding-left: 20px;
    margin: 0;
}

.card-content li {
    margin-bottom: 8px;
}

/* 高亮效果 */
.highlight {
    animation: highlight 1s ease-out;
}

@keyframes highlight {
    0% { background-color: rgba(76, 175, 80, 0.3); }
    50% { background-color: rgba(76, 175, 80, 0.1); }
    100% { background-color: #fff; } /* 恢复原始背景色 */
}

/* 响应式调整 */
@media (max-width: 992px) {
    .osi-layers-container {
        flex-direction: column;
        gap: 10px;
    }
    .osi-column {
        width: 100%;
    }
    .sender-column, .receiver-column {
        align-items: stretch; /* 在小屏幕上拉伸 */
    }
}

@media (max-width: 768px) {
    .devices-container {
        flex-direction: column;
        gap: 15px;
    }
    .network-line {
        width: 80%;
        margin: 10px 0;
    }
    .layer-name {
        width: 80px; /* 进一步缩小 */
        font-size: 12px;
    }
    .data-unit {
        font-size: 10px;
    }
    .control-btn {
        font-size: 14px;
        padding: 8px 15px;
    }
}