body {
    font-family: Arial, sans-serif;
    background-color: #f4f7f6;
    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.1);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 10px;
}

.description {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

/* 控制按钮 */
.simulation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 40px;
    gap: 20px;
}

.control-btn {
    padding: 12px 25px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s, box-shadow 0.3s;
    box-shadow: 0 2px 5px rgba(0, 123, 255, 0.3);
}

.control-btn:hover {
    background-color: #0056b3;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.4);
}

#reset-btn {
    background-color: #dc3545;
    box-shadow: 0 2px 5px rgba(220, 53, 69, 0.3);
}

#reset-btn:hover {
    background-color: #c82333;
    box-shadow: 0 4px 10px rgba(220, 53, 69, 0.4);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 模拟区域 */
.simulation-area {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* 顶部对齐 */
    padding: 20px;
    background-color: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 8px;
    min-height: 250px; /* 保证足够高度 */
    position: relative;
}

.node {
    width: 150px;
    text-align: center;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.node-title {
    font-weight: bold;
    margin-bottom: 15px;
    font-size: 1.1em;
    color: #333;
}

.node-icon img {
    width: 60px;
    height: auto;
    margin-bottom: 15px;
}

.state {
    margin-top: 10px;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 4px;
    background-color: #e9ecef;
    color: #495057;
    font-size: 0.9em;
    transition: background-color 0.5s, color 0.5s;
}

.info {
    margin-top: 8px;
    font-size: 0.85em;
    color: #6c757d;
    word-wrap: break-word;
}

/* 消息区域 */
.message-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around; /* 分散对齐 */
    align-items: center;
    padding: 0 30px; /* 增加左右边距 */
    min-height: 200px; /* 确保消息区域高度 */
    position: relative; /* 用于绝对定位箭头 */
}

.message {
    position: relative;
    width: 100%;
    opacity: 0; /* 初始隐藏 */
    transition: opacity 0.5s ease-in-out;
    margin: 15px 0; /* 增加消息间距 */
}

.message .arrow {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #ccc;
    transform: translateY(-50%);
}

.message .arrow::after { /* 箭头 */
    content: '';
    position: absolute;
    top: 50%;
    right: -1px; /* 稍微调整位置 */
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid #ccc;
    transform: translateY(-50%);
}

.message.syn-ack .arrow {
    background-color: #ffc107; /* 黄色 */
}
.message.syn-ack .arrow::after {
    border-left-color: #ffc107;
}

.message.ack .arrow {
    background-color: #28a745; /* 绿色 */
}
.message.ack .arrow::after {
    border-left-color: #28a745;
}

/* 反向箭头 (服务器到客户端) */
.message.syn-ack .arrow {
    left: auto;
    right: 0;
}
.message.syn-ack .arrow::after {
    right: auto;
    left: -1px; /* 稍微调整位置 */
    border-left: none;
    border-right: 10px solid #ffc107;
}

.message .label {
    position: absolute;
    top: -20px; /* 标签在箭头上 */
    left: 50%;
    transform: translateX(-50%);
    background-color: #fff;
    padding: 3px 8px;
    font-size: 0.85em;
    border: 1px solid #eee;
    border-radius: 4px;
    white-space: nowrap;
    color: #555;
}

.message.syn .label { color: #007bff; border-color: #b8daff;}
.message.syn-ack .label { color: #b8860b; border-color: #ffeeba;}
.message.ack .label { color: #28a745; border-color: #c3e6cb;}

/* 状态高亮 */
.state-syn-sent { background-color: #cfe2ff; color: #084298; }
.state-listen { background-color: #e2e3e5; color: #41464b; }
.state-syn-rcvd { background-color: #fff3cd; color: #664d03; }
.state-established { background-color: #d1e7dd; color: #0f5132; }
.state-closed { background-color: #f8d7da; color: #58151c; }


/* 信息面板 */
.info-panel {
    margin-top: 30px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px 20px;
}

.panel-title {
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
    font-size: 1.1em;
    color: #495057;
}

.panel-content {
    color: #6c757d;
    font-size: 1em;
    min-height: 30px;
}

.panel-content p {
    margin: 0;
}

/* 说明卡片 */
.explanation-card {
    margin-top: 30px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
}

.card-title {
    font-weight: bold;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
    font-size: 1.1em;
    color: #495057;
}

.card-content {
    color: #6c757d;
    font-size: 1em;
}

.card-content ol, .card-content ul {
    padding-left: 20px;
}

.card-content li {
    margin-bottom: 10px;
}

.card-content strong {
    color: #343a40;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .simulation-area {
        flex-direction: column;
        align-items: center;
        gap: 30px;
    }
    .node {
        width: 80%;
    }
    .message-area {
        padding: 20px 0;
        width: 100%;
    }
    .message .label {
        font-size: 0.8em;
    }
}