/* --- 基本样式 (与 tcp_handshake.css 类似) --- */
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;
}

/* --- 控制按钮 (与 tcp_handshake.css 相同) --- */
.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: #6c757d; /* 灰色 */
    box-shadow: 0 2px 5px rgba(108, 117, 125, 0.3);
}

#reset-btn:hover {
    background-color: #5a6268;
    box-shadow: 0 4px 10px rgba(108, 117, 125, 0.4);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- 模拟区域 (与 tcp_handshake.css 类似) --- */
.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: 300px; /* 可能需要更高的高度容纳4条消息 */
    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;
}

/* --- 消息区域 (与 tcp_handshake.css 类似，但有4条消息) --- */
.message-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around; /* 分散对齐 */
    align-items: center;
    padding: 0 30px;
    min-height: 250px; /* 调整高度 */
    position: relative;
}

.message {
    position: relative;
    width: 100%;
    opacity: 0; /* 初始隐藏 */
    transition: opacity 0.5s ease-in-out;
    margin: 10px 0; /* 调整消息间距 */
    height: 40px; /* 给消息留出空间 */
}

.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.fin .arrow { background-color: #dc3545; } /* 红色 FIN */
.message.fin .arrow::after { border-left-color: #dc3545; }
.message.ack .arrow { background-color: #28a745; } /* 绿色 ACK */
.message.ack .arrow::after { border-left-color: #28a745; }

/* 反向箭头 (服务器到客户端 - msg2, msg3) */
.message#msg2 .arrow, .message#msg3 .arrow {
    left: auto;
    right: 0;
}
.message#msg2 .arrow::after, .message#msg3 .arrow::after {
    right: auto;
    left: -1px;
    border-left: none;
}
/* 反向箭头颜色 */
.message#msg2.ack .arrow { background-color: #28a745; }
.message#msg2.ack .arrow::after { border-right: 10px solid #28a745; }
.message#msg3.fin .arrow { background-color: #dc3545; }
.message#msg3.fin .arrow::after { border-right: 10px solid #dc3545; }


.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.fin .label { color: #dc3545; border-color: #f5c6cb;}
.message.ack .label { color: #28a745; border-color: #c3e6cb;}

/* --- 状态高亮 (需要定义四次挥手的状态) --- */
.state-established { background-color: #d1e7dd; color: #0f5132; } /* Green */
.state-fin-wait-1 { background-color: #fff3cd; color: #664d03; } /* Yellow */
.state-fin-wait-2 { background-color: #cfe2ff; color: #084298; } /* Blue */
.state-close-wait { background-color: #f8d7da; color: #58151c; } /* Red */
.state-last-ack { background-color: #ffc107; color: #664d03; } /* Orange */
.state-time-wait { background-color: #adb5bd; color: #343a40; } /* Grey */
.state-closed { background-color: #e2e3e5; color: #41464b; } /* Light Grey */


/* --- 信息面板和说明卡片 (与 tcp_handshake.css 相同) --- */
.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;
}

/* --- 响应式调整 (与 tcp_handshake.css 类似) --- */
@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;
    }
}