* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    color: #fff;
    min-height: 100vh;
    padding: 20px;
}

.container {
    width: 95%;
    max-width: 1200px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 2.2rem;
    color: #fdbb2d;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.description {
    text-align: center;
    margin-bottom: 25px;
    line-height: 1.6;
    color: #ddd;
}

/* 第一个窗口：连接配置 */
.connection-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 25px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    align-items: center;
}

.connection-config {
    flex: 2;
    display: flex;
    gap: 15px;
    align-items: end;
}

.config-group {
    flex: 1;
    min-width: 150px;
}

.config-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #fdbb2d;
}

.config-group input {
    width: 100%;
    padding: 12px 15px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 1rem;
    border: 2px solid transparent;
}

.config-group input:focus {
    outline: none;
    border-color: #fdbb2d;
}

.config-group button {
    width: 100%;
    padding: 12px 15px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(to right, #1a2a6c, #004e92);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.config-group button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.config-group button.connected {
    background: linear-gradient(to right, #b21f1f, #8b0000);
}

.config-group button.connected:hover {
    background: linear-gradient(to right, #8b0000, #660000);
}

.connection-status {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
    min-width: 200px;
}

.connection-status .status-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    flex: 1;
}

.connection-status .status-label {
    font-size: 0.9rem;
    color: #aaa;
    margin-bottom: 5px;
}

.connection-status .status-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.status-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #b21f1f;
    box-shadow: 0 0 10px #b21f1f;
    transition: all 0.3s ease;
}

.status-indicator.connected {
    background: #00b09b;
    box-shadow: 0 0 10px #00b09b;
}

/* 第二个窗口：设备状态 */
.status-panel {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 25px;
}

.status-title {
    margin-bottom: 15px;
}

.status-title h2 {
    font-size: 1.4rem;
    color: #fdbb2d;
}

.status-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.status-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
}

.status-label {
    font-size: 0.9rem;
    color: #aaa;
}

.status-value {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 5px;
    color: #fff;
}

/* 第三个窗口：设备控制按钮 */
.control-panel {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 25px;
}

.control-panel .panel-title {
    margin-bottom: 20px;
}

.control-panel .panel-title h2 {
    font-size: 1.4rem;
    color: #fdbb2d;
}

.buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.device-btn {
    background: linear-gradient(to right, #1a2a6c, #004e92);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    border: 2px solid transparent;
}

.device-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.device-btn:active {
    transform: translateY(0);
}

/* 设备按钮状态颜色 */
.device-btn.on {
    background: linear-gradient(to right, #b21f1f, #8b0000);
    border-color: #ff6b6b;
    box-shadow: 0 0 15px rgba(178, 31, 31, 0.5);
}

.device-btn.off {
    background: linear-gradient(to right, #1a2a6c, #004e92);
    border-color: #4dabf7;
}

.device-btn.touch {
    background: linear-gradient(to right, #fdbb2d, #f46b45);
    border-color: #ffd43b;
}

.device-btn.touch.active {
    animation: pulse 0.3s ease-in-out;
    background: linear-gradient(to right, #b21f1f, #8b0000);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

/* 第四个窗口：通信面板 */
.communication-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.panel {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
}

.panel-title {
    font-size: 1.4rem;
    color: #fdbb2d;
    margin-bottom: 15px;
}

#sendData, #receiveData {
    width: 100%;
    height: 150px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 15px;
    color: #fff;
    font-family: monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    border: none;
    resize: none;
}

/* 第五个窗口：通信记录和状态 */
.history-panel {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 15px;
}

.history-title {
    font-size: 1.4rem;
    color: #fdbb2d;
    margin: 0;
}

.history-stats {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 0.9rem;
    color: #aaa;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 10px;
    border-radius: 5px;
    min-width: 80px;
    text-align: center;
}

.clear-btn {
    padding: 8px 16px;
    background: rgba(178, 31, 31, 0.7);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.clear-btn:hover {
    background: rgba(178, 31, 31, 0.9);
    transform: translateY(-1px);
}

#historyLog {
    height: 200px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 15px;
    font-family: monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#historyLog::-webkit-scrollbar {
    display: none;
}

.log-entry {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.log-time {
    color: #fdbb2d;
    font-weight: 600;
}

.log-data {
    color: #fff;
    word-break: break-all;
}

.log-sent {
    color: #96c93d;
}

.log-received {
    color: #1a2a6c;
}

.log-error {
    color: #b21f1f;
}

.error-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(178, 31, 31, 0.9);
    color: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 400px;
    display: none;
}

.success-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 176, 155, 0.9);
    color: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 400px;
    display: none;
}

.loading {
    opacity: 0.7;
    pointer-events: none;
}

@media (max-width: 768px) {
    .communication-panel {
        grid-template-columns: 1fr;
    }
    
    .buttons-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .connection-config {
        flex-direction: column;
    }
    
    .history-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .history-stats {
        width: 100%;
        justify-content: space-between;
    }
}