* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007AFF;
    --primary-dark: #0051D5;
    --success-color: #34C759;
    --warning-color: #FF9500;
    --error-color: #FF3B30;
    --bg-color: #f5f5f5;
    --text-color: #333;
    --text-light: #888;
    --border-color: #e0e0e0;
    --btn-color-triangle: #ff5252;
    --btn-color-circle: #ff5252;
    --btn-color-square: #4dd0e1;
    --btn-color-cross: #4dd0e1;
}

html, body {
    width: 100%;
    height: 100%;
    font-size: 18px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-color);
    overflow: hidden;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
}

.page {
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.page.active {
    display: flex;
}

/* ============ 连接设置页面 ============ */
.setup-container {
    height: 100%;
    padding: 28px 36px;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    display: grid;
    grid-template-columns: minmax(420px, 560px) minmax(420px, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    gap: 18px 28px;
    overflow: hidden;
}

.setup-container h1 {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 38px;
    margin-bottom: 2px;
    color: white;
    text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.settings-section,
.status-section,
.log-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 0;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.settings-section {
    grid-column: 1;
    grid-row: 2 / 5;
}

.status-section {
    grid-column: 2;
    grid-row: 2;
}

.btn-primary {
    grid-column: 2;
    grid-row: 3;
}

.log-section {
    grid-column: 2;
    grid-row: 4;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.settings-section h2,
.log-section h3 {
    font-size: 22px;
    margin-bottom: 18px;
    color: var(--text-color);
    font-weight: 600;
}

.input-group {
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 18px;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.input-group input,
.input-group select {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 18px;
    font-family: inherit;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(0, 122, 255, 0.2);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    font-weight: 400;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    cursor: pointer;
}

.status-section {
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.3);
    padding: 18px 24px;
}

.status-section p {
    font-size: 20px;
    font-weight: 600;
}

#statusText {
    color: var(--success-color);
    font-weight: 700;
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.log-container {
    flex: 1;
    min-height: 0;
    background: #f0f0f0;
    border-radius: 6px;
    padding: 14px;
    max-height: none;
    overflow: hidden;
    font-family: 'Courier New', monospace;
    font-size: 15px;
}

.log-item {
    padding: 5px 0;
    line-height: 1.55;
    word-break: break-all;
}

.log-item.info {
    color: #0066cc;
}

.log-item.error {
    color: #cc0000;
}

.log-item.success {
    color: #00aa00;
}

/* ============ 控制器页面 ============ */
#controlPage {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
}

.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.status-text {
    color: white;
    font-size: 20px;
    font-weight: 600;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 14px;
}

.status-text.connected {
    color: #7CFF9B;
}

.status-text.disconnected {
    color: #FFB3AC;
}

.status-text.connecting {
    color: #FFD37A;
}

.reconnect-btn {
    white-space: nowrap;
}

.menu-buttons {
    display: flex;
    gap: 16px;
}

.menu-btn {
    padding: 9px 18px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.menu-btn:active {
    background: rgba(255, 255, 255, 0.4);
}

.controller-wrapper {
    width: 100%;
    height: 100%;
    padding-top: 64px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    gap: 0;
    padding: 64px 32px 32px 32px;
}

/* 肩键区域 */
.shoulder-row {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 80px;
    margin-bottom: 28px;
    flex-shrink: 0;
}

.shoulder-left,
.shoulder-right {
    display: flex;
    gap: 22px;
}

.btn-shoulder {
    min-width: 86px;
    padding: 14px 28px;
    background: linear-gradient(145deg, #555, #333);
    color: white;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    border: 2px solid #666;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: all 0.1s;
}

.btn-shoulder:active {
    opacity: 0.7;
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* 主按钮区域 */
.main-controls {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 68px;
    margin: 22px 0;
    flex-shrink: 0;
}

/* 左侧摇杆 */
.left-section {
    flex: 0;
    width: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.joystick-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.joystick-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-dpad {
    width: 76px;
    height: 76px;
    background: linear-gradient(145deg, #555, #333);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: bold;
    border: 1px solid #666;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.1s;
}

.btn-dpad:active {
    opacity: 0.7;
    transform: scale(0.95);
}

.joystick-container {
    position: relative;
    width: 180px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.joystick-container:active {
    cursor: grabbing;
}

.joystick-base {
    position: absolute;
    width: 136px;
    height: 136px;
    border-radius: 50%;
    background: linear-gradient(145deg, #555, #333);
    border: 2px solid #666;
}

.joystick-stick {
    position: absolute;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: linear-gradient(145deg, #ff6b6b, #ee5a6f);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    transition: none;
    will-change: transform;
}

/* 中央区域 */
.center-section {
    flex: 0;
    width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.center-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.center-top-row {
    display: flex;
    gap: 22px;
}

.btn-small {
    min-width: 94px;
    padding: 14px 22px;
    background: rgba(50, 50, 50, 0.8);
    color: white;
    border-radius: 12px;
    font-size: 16px;
    border: 1px solid #666;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.1s;
}

.btn-small:active {
    opacity: 0.7;
    transform: scale(0.95);
}

.ps-logo {
    font-size: 20px;
    font-weight: bold;
    color: white;
    background: rgba(19, 146, 57, 0.6);
    padding: 12px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* 右侧动作按钮 */
.right-section {
    flex: 0;
    width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.buttons-row {
    display: flex;
    gap: 96px;
    align-items: center;
}

.btn-action {
    position: relative;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 52px;
    font-weight: bold;
    color: transparent;
    line-height: 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.1s;
}

.btn-action::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: block;
}

.btn-action:active {
    opacity: 0.7;
    transform: scale(0.92);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.btn-triangle {
    background: linear-gradient(145deg, #4ecdc4, #44a8a0);
}

.btn-triangle::before {
    width: 0;
    height: 0;
    border-left: 21px solid transparent;
    border-right: 21px solid transparent;
    border-bottom: 36px solid white;
}

.btn-circle {
    background: linear-gradient(145deg, #ff6b6b, #ee5a6f);
}

.btn-circle::before {
    width: 36px;
    height: 36px;
    border: 6px solid white;
    border-radius: 50%;
}

.btn-square {
    background: linear-gradient(145deg, #f38181, #e85d75);
}

.btn-square::before {
    width: 38px;
    height: 38px;
    background: white;
}

.btn-cross {
    background: linear-gradient(145deg, #a8e6cf, #7fcdbb);
}

.btn-cross::before,
.btn-cross::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 48px;
    height: 7px;
    background: white;
    border-radius: 999px;
    transform-origin: center;
}

.btn-cross::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.btn-cross::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* 底部按钮行 */
.bottom-row {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 80px;
    margin-top: 24px;
    flex-shrink: 0;
}

.bottom-left,
.bottom-right {
    display: flex;
    gap: 22px;
}

.btn-bottom {
    min-width: 86px;
    padding: 14px 28px;
    background: linear-gradient(145deg, #555, #333);
    color: white;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    border: 2px solid #666;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: all 0.1s;
}

.btn-bottom:active {
    opacity: 0.7;
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ============ 日志面板 ============ */
.log-panel {
    position: fixed;
    top: 64px;
    right: -460px;
    width: 420px;
    bottom: 0;
    background: rgba(20, 20, 20, 0.9);
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.5);
    transition: right 0.3s ease;
    z-index: 150;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

.log-panel.show {
    right: 0;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(40, 40, 40, 0.95);
    color: white;
    font-size: 18px;
    font-weight: bold;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.log-close {
    font-size: 22px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0 8px;
}

.log-close:hover {
    color: #ff6b6b;
}

.log-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 15px;
    line-height: 1.6;
}

.log-item {
    color: #0f0;
    margin-bottom: 6px;
    word-break: break-all;
}

.log-item.error {
    color: #ff6b6b;
}

.log-item.success {
    color: #52c41a;
}

.log-item.info {
    color: #1890ff;
}

/* ============ 对话框 ============ */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.dialog-overlay.show {
    display: flex;
}

.dialog-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 580px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dialog-header {
    padding: 26px;
    border-bottom: 1px solid #f0f0f0;
}

.dialog-header h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
}

.dialog-body {
    flex: 1;
    padding: 26px;
    overflow-y: auto;
}

.dialog-footer {
    padding: 20px 26px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 10px;
    color: var(--text-color);
}

.form-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 18px;
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(0, 122, 255, 0.2);
}

.btn-save,
.btn-cancel,
.btn-add {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-save {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-cancel {
    background: #f0f0f0;
    color: var(--text-color);
}

.btn-cancel:hover {
    background: #e0e0e0;
}

.btn-add {
    background: var(--primary-color);
    color: white;
    flex: 0.5;
}

.btn-add:hover {
    background: var(--primary-dark);
}

.subscribe-dialog {
    max-width: 640px;
}

.subscribe-list {
    background: #f9f9f9;
    border-radius: 6px;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid #f0f0f0;
}

.subscribe-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
}

.subscribe-item:last-child {
    border-bottom: none;
}

.subscribe-topic {
    flex: 1;
    word-break: break-all;
    color: var(--text-color);
}

.subscribe-delete {
    color: var(--error-color);
    cursor: pointer;
    margin-left: 14px;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 15px;
    transition: all 0.2s;
}

.subscribe-delete:hover {
    background: rgba(255, 59, 48, 0.1);
}

.settings-dialog {
    max-width: 640px;
}

.settings-list {
    max-height: 520px;
    overflow-y: auto;
}

.settings-item {
    padding: 16px;
    background: #f9f9f9;
    border-radius: 6px;
    margin-bottom: 10px;
    border: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-item:hover {
    background: #f0f0f0;
    border-color: var(--primary-color);
}

.settings-item-name {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 5px;
    font-size: 17px;
}

.settings-item-topic {
    font-size: 15px;
    color: var(--text-light);
}

/* 响应式设计 */
@media (max-width: 768px) {
    html, body {
        font-size: 16px;
    }

    .setup-container {
        padding: 20px;
        max-width: 600px;
    }

    .setup-container h1 {
        font-size: 28px;
        margin-bottom: 30px;
    }

    .settings-section,
    .status-section,
    .log-section {
        padding: 20px;
        margin-bottom: 15px;
    }

    .settings-section h2,
    .log-section h3 {
        font-size: 16px;
        margin-bottom: 15px;
    }

    .input-group label,
    .form-group label {
        font-size: 14px;
    }

    .input-group input,
    .input-group select,
    .form-input {
        min-height: auto;
        padding: 10px;
        font-size: 14px;
    }

    .btn-primary,
    .btn-save,
    .btn-cancel,
    .btn-add {
        font-size: 16px;
    }

    .status-bar {
        height: 50px;
        padding: 0 20px;
    }

    .status-text {
        font-size: 16px;
    }

    .connection-status {
        gap: 10px;
    }

    .menu-buttons {
        gap: 12px;
    }

    .menu-btn {
        padding: 6px 14px;
        font-size: 12px;
    }

    .controller-wrapper {
        padding: 50px 20px 20px 20px;
    }

    .main-controls {
        gap: 30px;
    }

    .shoulder-row,
    .bottom-row {
        gap: 40px;
    }

    .shoulder-left,
    .shoulder-right,
    .bottom-left,
    .bottom-right {
        gap: 15px;
    }

    .btn-shoulder,
    .btn-bottom {
        min-width: auto;
        padding: 10px 24px;
        font-size: 13px;
    }

    .btn-small {
        min-width: auto;
        padding: 10px 18px;
        font-size: 13px;
    }

    .ps-logo {
        font-size: 14px;
        padding: 8px 20px;
    }

    .joystick-area {
        gap: 6px;
    }

    .joystick-row {
        gap: 10px;
    }

    .buttons-row {
        gap: 20px;
    }

    .btn-action {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .btn-triangle::before {
        border-left-width: 12px;
        border-right-width: 12px;
        border-bottom-width: 20px;
    }

    .btn-circle::before {
        width: 20px;
        height: 20px;
        border-width: 4px;
    }

    .btn-square::before {
        width: 22px;
        height: 22px;
    }

    .btn-cross::before,
    .btn-cross::after {
        width: 28px;
        height: 5px;
    }

    .joystick-container {
        width: 100px;
        height: 100px;
    }

    .joystick-base {
        width: 75px;
        height: 75px;
    }

    .joystick-stick {
        width: 38px;
        height: 38px;
    }

    .log-panel {
        top: 50px;
        width: 280px;
        right: -280px;
    }

    .log-panel.show {
        right: 0;
    }

    .dialog-content,
    .subscribe-dialog,
    .settings-dialog {
        max-width: 500px;
    }
}
