/* ---------- 全局重置 ---------- */
* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #0a0c1a;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #eee;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    /* 安全区：四个方向都保护，适配刘海/挖孔/Home指示条 */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (max-width: 768px) {
    body { font-size: 12px; }
}

/* ========== 全屏横屏引导 ========== */

/* ---------- 全局按钮基础样式 ---------- */
#remainingTimeDisplay {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    color: #aaa;
    padding: 4px 14px;
    border-radius: 22px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}
#refreshDevicesBtn:hover { background: rgba(255,255,255,0.12); }
#remainingTimeDisplay { cursor: default; }

/* ---------- 视频容器 ---------- */
.video-container {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}
video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: black;
}

/* ---------- 登录面板 ---------- */
.login-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    flex-direction: column;
}
.login-card {
    background: #1e1f2c;
    border-radius: 24px;
    padding: 24px 20px;
    width: 90%;
    max-width: 340px;
    box-shadow: 0 20px 35px rgba(0,0,0,0.5);
    border: 1px solid #2f3545;
}
.login-card h2 {
    text-align: center;
    margin: 0 0 20px 0;
    color: #0af;
    font-size: 1.6rem;
}
.input-group {
    margin-bottom: 16px;
}
.input-group label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 6px;
    color: #aaa;
}
.input-group input {
    width: 100%;
    padding: 12px;
    background: #2a2c3a;
    border: 1px solid #3a3f50;
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: 0.2s;
}
.input-group input:focus {
    border-color: #0af;
    outline: none;
}
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
}
.checkbox-group input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.checkbox-group label {
    font-size: 0.85rem;
    color: #ccc;
    cursor: pointer;
}
.login-btn {
    width: 100%;
    background: rgba(0,160,255,0.2);
    border: 1px solid rgba(0,160,255,0.3);
    padding: 12px;
    border-radius: 40px;
    font-weight: bold;
    font-size: 1rem;
    color: #8cf;
    margin-top: 10px;
    cursor: pointer;
    transition: background 0.15s;
}
.login-btn:hover { background: rgba(0,160,255,0.3); }
.register-btn { background: #27ae60 !important; border-color: #2ecc71 !important; color: #fff !important; }
.register-btn:hover { background: #219653 !important; }

/* 邮箱分段输入 */
.email-split {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: nowrap;
}
.email-split input {
    flex: 1;
    min-width: 0;
}
.email-split .email-at {
    color: #aaa;
    font-size: 1rem;
    flex-shrink: 0;
}
.email-split select {
    flex-shrink: 0;
    width: auto;
    max-width: 100px;
    padding: 12px 8px;
    background: #2a2c3a;
    border: 1px solid #3a3f50;
    border-radius: 12px;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 1.2;
    height: auto;
    box-sizing: border-box;
}
.email-split select:focus {
    border-color: #0af;
    outline: none;
}

/* 验证码行 */
.code-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}
.code-row input {
    flex: 1;
    min-width: 0;
    font-family: monospace;
    letter-spacing: 4px;
    text-align: center;
    font-size: 1.1rem;
}
.code-row button {
    flex-shrink: 0;
    max-width: 90px;
    padding: 12px 14px;
    background: rgba(0,160,255,0.2);
    border: 1px solid rgba(0,160,255,0.3);
    border-radius: 12px;
    color: #8cf;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.2;
    box-sizing: border-box;
}
.code-row button:hover { background: rgba(0,160,255,0.3); }
.code-row button:disabled { opacity: 0.5; cursor: not-allowed; }

/* 登录/注册面板 移动端适配 */
@media (max-width: 480px) {
    .login-card {
        padding: 18px 14px;
        max-width: 100%;
        border-radius: 16px;
    }
    .login-card h2 { font-size: 1.3rem; margin-bottom: 14px; }
    .input-group input { padding: 14px; font-size: 1rem; min-height: 48px; }
    .email-split { gap: 2px; }
    .email-split .email-at { font-size: 0.85rem; }
    .email-split select { padding: 10px 4px; font-size: 0.78rem; max-width: 85px; }
    .code-row { gap: 6px; }
    .code-row input { font-size: 1rem; letter-spacing: 2px; }
    .code-row button { padding: 10px 8px; font-size: 0.75rem; max-width: 78px; }
    .login-btn { padding: 10px; font-size: 0.95rem; }
    .error-msg { font-size: 0.72rem; }
}
.error-msg {
    color: #f66;
    font-size: 0.75rem;
    margin-top: 10px;
    text-align: center;
}

/* ---------- 设备列表面板 ---------- */
.device-panel {
    display: none;
    background: #11131f;
    padding: 20px;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}
.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
    padding-right: 50px;
}
.device-header h3 {
    margin: 0;
    font-size: 1.2rem;
    margin-right: auto;
}
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}
.device-card {
    background: #1e1f2c;
    border-radius: 16px;
    padding: 14px 16px;
    border: 1px solid #2f3545;
    transition: 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.device-card:hover {
    border-color: #0af;
    background: #252a3a;
}
.device-card.selected {
    border: 2px solid #0af;
    background: #252a3a;
}
.device-name {
    font-size: 1rem;
    font-weight: bold;
    color: #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.device-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.device-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
}
.status-online { background: #2a6; color: white; }
.status-offline { background: #666; color: #ccc; }
.status-occupied { background: #f90; color: #000; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; }
.device-voltage {
    font-size: 0.8rem;
    color: #aaa;
}
.device-actions {
    margin-top: 4px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.device-actions button {
    padding: 5px 12px;
    border: none;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    flex: 1;
    min-width: 50px;
    text-align: center;
}
.btn-takeover { background: rgba(255,170,60,0.18); border: 1px solid rgba(255,170,60,0.3); color: #fba; }
.btn-takeover:hover { background: rgba(255,170,60,0.28); }
.btn-watch { background: rgba(80,160,255,0.15); border: 1px solid rgba(80,160,255,0.25); color: #acd; }
.btn-watch:hover { background: rgba(80,160,255,0.25); }
.btn-disabled { opacity: 0.4; cursor: not-allowed !important; pointer-events: none; }
.device-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 0.9rem;
}

/* ========== 移动端设备列表适配 ========== */
/* 手机竖屏：单列 + 紧凑间距 */
@media (max-width: 480px) and (orientation: portrait) {
    .device-panel { padding: 12px; }
    .device-header { padding-right: 0; gap: 6px; }
    .device-header h3 { font-size: 1rem; }
    .device-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .device-card { padding: 10px 12px; border-radius: 12px; }
    .device-name { font-size: 0.9rem; }
    .device-actions button { padding: 4px 8px; font-size: 0.7rem; }
}

/* 手机横屏 / 小平板：双列，充分利用宽度 */
@media (max-width: 950px) and (orientation: landscape) {
    .device-panel { padding: 10px 14px; }
    .device-header {
        padding-right: 0;
        margin-bottom: 10px;
        gap: 8px;
    }
    .device-header h3 { font-size: 1rem; }
    /* 横屏使用双列紧凑网格 */
    .device-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .device-card {
        padding: 10px 12px;
        border-radius: 12px;
        gap: 4px;
    }
    .device-name { font-size: 0.9rem; }
    .device-voltage { font-size: 0.7rem; color: #888; }
    .device-actions button { padding: 4px 8px; font-size: 0.68rem; min-width: 40px; }
    .device-status { font-size: 0.65rem; padding: 1px 6px; }
    .status-occupied { font-size: 0.65rem; padding: 1px 6px; }
}

/* 平板横屏：三列 */
@media (min-width: 951px) and (max-width: 1200px) {
    .device-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
}

/* PC 大屏：4-5 列 */
@media (min-width: 1201px) {
    .device-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 14px;
    }
}

/* ---------- 用户菜单（下拉） ---------- */
.user-menu {
    position: relative;
    display: inline-block;
}
.user-menu-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #ccc;
    padding: 5px 14px;
    border-radius: 22px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s;
}
.user-menu-btn:hover { background: rgba(255,255,255,0.14); }
.user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 30px;
    background: #1e1f2c;
    border: 1px solid #2f3545;
    border-radius: 12px;
    padding: 8px 0;
    min-width: 160px;
    z-index: 100;
    box-shadow: 0 8px 20px rgba(0,0,0,0.6);
}
.user-dropdown.show { display: block; }
.user-dropdown a {
    display: block;
    padding: 8px 16px;
    color: #ccc;
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
}
.user-dropdown a:hover {
    background: #2a2c3a;
    color: #fff;
}

/* ---------- 模态框（弹窗） ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    justify-content: center;
    align-items: center;
    z-index: 3000;
}
.modal-overlay.active { display: flex; }
.modal-box {
    background: #1e1f2c;
    border-radius: 24px;
    padding: 24px;
    width: 90%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid #2f3545;
}
.modal-overlay.usage-history-modal .modal-box {
    width: 96%;
    max-width: 860px;
}
.modal-overlay.usage-history-modal #modalBody {
    overflow-x: auto;
}
.modal-box h2 {
    margin-top: 0;
    color: #0af;
    font-size: 1.3rem;
}
.modal-box .form-group {
    margin-bottom: 14px;
}
.modal-box .form-group label {
    display: block;
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 4px;
}
.modal-box .form-group input,
.modal-box .form-group select {
    width: 100%;
    padding: 10px;
    background: #2a2c3a;
    border: 1px solid #3a3f50;
    border-radius: 10px;
    color: white;
    font-size: 0.95rem;
}
.modal-box .form-group input:focus {
    border-color: #0af;
    outline: none;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}
.modal-actions button {
    padding: 8px 20px;
    border: none;
    border-radius: 30px;
    font-size: 0.9rem;
    cursor: pointer;
}
.btn-primary { background: rgba(0,160,255,0.2); border: 1px solid rgba(0,160,255,0.3); color: #8cf; }
.btn-secondary { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); color: #ccc; }
.btn-danger { background: rgba(255,60,60,0.2); border: 1px solid rgba(255,60,60,0.3); color: #faa; }
.btn-success { background: rgba(40,170,100,0.2); border: 1px solid rgba(40,170,100,0.3); color: #aea; }

.record-table {
    width: 100%;
    min-width: 700px;
    border-collapse: collapse;
    font-size: 0.75rem;
    margin-top: 10px;
}
.record-table th, .record-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #2f3545;
    text-align: left;
}
.record-table th {
    color: #88a;
    font-weight: normal;
}
.record-table td {
    color: #ddd;
}

/* ---------- 控制界面 ---------- */
.control-panel {
    display: none;
    flex-direction: column;
    height: 100%;
}

/* 状态栏：透明毛玻璃风格，嵌入视频画面顶部，始终保持单行 */
/* 默认隐藏，仅控制界面显示 */
#status-container {
    display: none;
    position: fixed;
    top: max(2px, env(safe-area-inset-top, 2px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.22);
    color: rgba(255, 255, 255, 0.92);
    padding: 5px 16px;
    border-radius: 30px;
    z-index: 2147483647;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-size: 12px;
    line-height: 1.2;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 12px;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    border: none;
    box-shadow: none;
    width: fit-content;
    max-width: calc(100vw - 20px);
}
/* 状态栏条目：统一字号，紧凑间距，垂直居中对齐 */
.status-item {
    display: flex;
    gap: 3px;
    white-space: nowrap;
    align-items: center;
    font-size: inherit;          /* ⭐ 继承容器字号，不再单独定义 */
}
/* PC 大屏：整体放大，不拆散条目 */
@media (min-width: 1025px) {
    #status-container { font-size: 14px; padding: 6px 22px; gap: 18px; }
    .status-indicator { width: 11px; height: 11px; }
}
.status-label {
    color: rgba(255, 255, 255, 0.55);
}
.status-value {
    color: rgba(255, 255, 255, 0.95);
    font-weight: 600;
}
.status-indicator {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #f55;
    display: inline-block;
    margin-right: 4px;
    flex-shrink: 0;
}
.status-indicator.connected {
    background: #5f5;
    box-shadow: 0 0 8px #5f5;
}
.connection-pulse { animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }
.low-voltage { color: #f55; animation: blink 1s infinite; }
@keyframes blink { 0%{opacity:1;}50%{opacity:0.3;}100%{opacity:1;} }

/* 返回按钮（视频左上角，小巧不遮挡画面） */
.back-btn {
    position: absolute;
    top: 10px;
    left: max(6px, env(safe-area-inset-left, 6px));
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 3px 10px;
    font-size: 11px;
    z-index: 500;
    cursor: pointer;
    color: #bbb;
    min-width: 48px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: background 0.15s;
}
.back-btn:hover { background: rgba(255,255,255,0.14); }

/* ---------- 录制按钮（视频右上角，圆形图标按钮） ---------- */
#record-btn {
    position: absolute;
    top: 42px;
    right: 138px;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    line-height: 1;
    z-index: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    touch-action: manipulation;
    font-family: inherit;
}
#record-btn.record-btn-off {
    background: rgba(180, 40, 40, 0.5);
    color: rgba(255, 255, 255, 0.85);
}
#record-btn.record-btn-off:hover {
    background: rgba(200, 50, 50, 0.7);
}
#record-btn.record-btn-on {
    background: rgba(220, 20, 20, 0.85);
    color: white;
    border: 1px solid #f44;
    animation: recordPulse 1.5s infinite;
}
#record-btn.record-btn-on:hover {
    background: rgba(240, 30, 30, 0.95);
    transform: scale(1.05);
}
#record-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
/* 录制脉冲动画 */
@keyframes recordPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(255, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

/* 全屏模式下录制按钮 */
:fullscreen #record-btn,
:-webkit-full-screen #record-btn,
:-moz-full-screen #record-btn,
:-ms-fullscreen #record-btn {
    z-index: 2147483646 !important;
}

/* 移动端适配 */
@media (max-width: 768px) and (orientation: landscape) {
    #record-btn { top: 34px; right: 118px; width: 30px; height: 30px; font-size: 14px; }
    #audio-btn  { top: 34px; right: 78px;  width: 30px; height: 30px; font-size: 14px; }
    #settings-menu-btn { top: 34px; right: 42px; width: 30px; height: 30px; font-size: 14px; }
}
@media (max-width: 480px) and (orientation: portrait) {
    #record-btn { top: 30px; right: 104px; width: 28px; height: 28px; font-size: 13px; }
    #audio-btn  { top: 30px; right: 68px;  width: 28px; height: 28px; font-size: 13px; }
    #settings-menu-btn { top: 30px; right: 34px; width: 28px; height: 28px; font-size: 13px; }
}

/* 全屏按钮 — 全局固定圆形图标（所有页面可见） */
#fullscreen-btn {
    position: fixed;
    top: max(8px, env(safe-area-inset-top, 8px));
    right: max(10px, env(safe-area-inset-right, 10px));
    width: 34px;
    height: 34px;
    padding: 0;
    background: rgba(255,255,255,0.08);
    color: #bbb;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    line-height: 1;
    z-index: 2001;
    cursor: pointer;
    transition: background 0.15s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    touch-action: manipulation;
}
#fullscreen-btn:hover { background: rgba(255,255,255,0.14); }

/* 音频按钮（视频右上角，圆形图标按钮） */
#audio-btn {
    position: absolute;
    top: 42px;
    right: 94px;
    width: 34px;
    height: 34px;
    padding: 0;
    background: rgba(255,255,255,0.08);
    color: #bbb;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    line-height: 1;
    z-index: 500;
    cursor: pointer;
    transition: background 0.15s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    touch-action: manipulation;
}
#audio-btn.audio-on { background: rgba(80,200,80,0.25); border-color: rgba(80,200,80,0.3); color: #aea; }
#audio-btn.audio-off { background: rgba(200,80,80,0.25); border-color: rgba(200,80,80,0.3); color: #eaa; }

/* 摇杆区域（仅移动端显示）— 浮动摇杆版 */
.joystick-area {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 500;
    pointer-events: none;
    display: none;
}
/* 触屏设备显示摇杆 */
@media (hover: none) and (pointer: coarse) {
    .joystick-area { display: block; }
}
/* 备用规则：小屏幕竖屏或横屏也显示摇杆 */
@media (pointer: coarse) {
    .joystick-area { display: block; }
}
.stick-container {
    position: absolute;
    /* aspect-ratio 强制正方形，避免 42vw≠38vh 导致扁椭圆 */
    width: min(40vw, 40vh, 220px);
    aspect-ratio: 1;
    min-width: 130px;
    pointer-events: auto;
}
/* 底部安全区：iPhone X+ 的 Home Indicator 区域 */
#leftStickArea {
    left: max(15px, env(safe-area-inset-left, 15px));
    bottom: max(15px, env(safe-area-inset-bottom, 15px));
}
#rightStickArea {
    right: max(15px, env(safe-area-inset-right, 15px));
    bottom: max(15px, env(safe-area-inset-bottom, 15px));
}
/* 浮动摇杆的视觉环：只有边框可见，内部透明用于触摸检测 */
.stick {
    width: 100%;
    height: 100%;
    background: transparent;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    position: relative;
    touch-action: none;
    box-shadow: none;
    transition: border-color 0.15s ease;
}
.stick:active {
    border-color: rgba(100, 200, 255, 0.7);
    box-shadow: inset 0 0 12px rgba(100, 200, 255, 0.2);
    transition: none;
}
/* 摇杆环位置过渡动画（回中） */
.stick {
    transition: left 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), top 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), right 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), bottom 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.15s ease;
}
/* 旋钮：使用百分比尺寸，随摇杆环等比缩放 */
.knob {
    width: 36%;
    height: 36%;
    max-width: 55px;
    max-height: 55px;
    min-width: 30px;
    min-height: 30px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 6px 18px rgba(0,0,0,0.6);
    transition: transform 0.1s ease, background 0.1s ease;
}
/* 旋钮被拖动时的视觉反馈 */
.stick:active .knob {
    background: rgba(100, 200, 255, 0.9);
    box-shadow: 0 6px 24px rgba(100, 200, 255, 0.4), 0 0 12px rgba(100, 200, 255, 0.3);
}
/* 标签放在容器上方，避免被安全区裁切 */
.stick-label {
    position: absolute;
    top: -22px;
    width: 100%;
    text-align: center;
    color: white;
    font-size: clamp(10px, 2.5vw, 14px);
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    font-weight: bold;
    pointer-events: none;
}
.gear-1 { background: linear-gradient(135deg, #2a6, #1a4) !important; }
.gear-2 { background: linear-gradient(135deg, #fc0, #ea0) !important; color: black !important; }
.gear-3 { background: linear-gradient(135deg, #f60, #d40) !important; }
.gear-4 { background: linear-gradient(135deg, #f33, #c00) !important; }

/* ========== 全屏模式覆盖样式：确保所有控制UI可见 ========== */
:fullscreen #settings-menu-btn,
:-webkit-full-screen #settings-menu-btn,
:-moz-full-screen #settings-menu-btn,
:-ms-fullscreen #settings-menu-btn {
    z-index: 2147483646 !important;
    display: flex !important;
}
:fullscreen #status-container,
:-webkit-full-screen #status-container,
:-moz-full-screen #status-container,
:-ms-fullscreen #status-container {
    z-index: 2147483647 !important;
    display: flex !important;
}
:fullscreen .joystick-area,
:-webkit-full-screen .joystick-area,
:-moz-full-screen .joystick-area,
:-ms-fullscreen .joystick-area {
    display: block !important;
    z-index: 1000 !important;
}
:fullscreen #speed-controls,
:-webkit-full-screen #speed-controls,
:-moz-full-screen #speed-controls,
:-ms-fullscreen #speed-controls {
    z-index: 1000 !important;
    display: flex !important;
}
:fullscreen #speed-btn,
:-webkit-full-screen #speed-btn,
:-moz-full-screen #speed-btn,
:-ms-fullscreen #speed-btn {
    z-index: 1000 !important;
    display: flex !important;
}
:fullscreen #fullscreen-btn,
:-webkit-full-screen #fullscreen-btn,
:-moz-full-screen #fullscreen-btn,
:-ms-fullscreen #fullscreen-btn {
    z-index: 2147483646 !important;
}
:fullscreen #audio-btn,
:-webkit-full-screen #audio-btn,
:-moz-full-screen #audio-btn,
:-ms-fullscreen #audio-btn {
    z-index: 2147483646 !important;
}
:fullscreen .back-btn,
:-webkit-full-screen .back-btn,
:-moz-full-screen .back-btn,
:-ms-fullscreen .back-btn {
    z-index: 2147483646 !important;
}
:fullscreen .settings-panel-overlay,
:-webkit-full-screen .settings-panel-overlay,
:-moz-full-screen .settings-panel-overlay,
:-ms-fullscreen .settings-panel-overlay {
    z-index: 2147483647 !important;
}

/* 移动端隐藏键盘提示 */
@media (hover: none) and (pointer: coarse) {
    .keyboard-hint { display: none !important; }
}

/* 移动端横屏适配 */
@media (max-width: 768px) and (orientation: landscape) {
    .stick-container { width: min(35vw, 35vh, 150px); min-width: 100px; }
    .knob { max-width: 42px; max-height: 42px; min-width: 26px; min-height: 26px; }
    #speed-btn { width: 55px; height: 32px; font-size: 0.8rem; min-width: 50px; min-height: 28px; }
    #speed-controls { top: 68px; }
    .back-btn { top: 8px; left: 6px; width: 28px; height: 28px; font-size: 14px; padding: 0; border-radius: 50%; min-width: 28px; min-height: 28px; }
    #audio-btn { top: 8px; right: 70px; width: 28px; height: 28px; font-size: 14px; }
    #settings-menu-btn { top: 8px; right: 36px; width: 28px; height: 28px; font-size: 14px; }
    #record-btn { top: 8px; right: 106px; width: 28px; height: 28px; font-size: 14px; }
    #status-container { font-size: 10px; gap: 6px; padding: 3px 10px; }
    .device-header { padding-right: 46px; }
    .user-menu-btn { padding: 5px 10px; font-size: 0.75rem; }
}
@media (max-width: 480px) and (orientation: portrait) {
    .stick-container { width: min(38vw, 38vh, 130px); min-width: 85px; }
    .knob { max-width: 38px; max-height: 38px; min-width: 22px; min-height: 22px; }
    #speed-btn { width: 48px; height: 28px; font-size: 0.65rem; min-width: 44px; min-height: 24px; }
    #speed-controls { top: 60px; }
    .back-btn { top: 6px; left: 4px; width: 26px; height: 26px; font-size: 13px; padding: 0; border-radius: 50%; min-width: 26px; min-height: 26px; }
    #audio-btn { top: 6px; right: 60px; width: 26px; height: 26px; font-size: 13px; }
    #settings-menu-btn { top: 6px; right: 28px; width: 26px; height: 26px; font-size: 13px; }
    #record-btn { top: 6px; right: 92px; width: 26px; height: 26px; font-size: 13px; }
    #status-container { font-size: 9px; gap: 5px; padding: 2px 8px; }
    .device-header { padding-right: 44px; }
    .user-menu-btn { padding: 4px 8px; font-size: 0.7rem; }
}

/* 档位按钮：放在全屏按钮下方，移动端进一步下移 */
#speed-controls {
    position: absolute;
    top: 80px;
    right: 10px;
    bottom: auto;
    display: flex;
    flex-direction: row;
    gap: 6px;
    pointer-events: auto;
    z-index: 2200;
}
#speed-btn {
    width: 65px;
    height: 36px;
    background: rgba(255,255,255,0.08);
    color: #bbb;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 13px;
    font-weight: bold;
    user-select: none;
    pointer-events: auto;
    transition: background 0.15s;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(10px);
    min-width: 60px;
    min-height: 32px;
    touch-action: manipulation;
}
#speed-btn:active {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.5);
}

/* ---------- 设定菜单按钮（视频区域内，圆形图标按钮） ---------- */
#settings-menu-btn {
    position: absolute;
    top: 42px;
    right: 50px;
    width: 34px;
    height: 34px;
    padding: 0;
    background: rgba(255,255,255,0.08);
    color: #bbb;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    line-height: 1;
    z-index: 500;
    cursor: pointer;
    transition: background 0.15s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    touch-action: manipulation;
}
#settings-menu-btn:hover { background: rgba(255,255,255,0.16); }

/* ---------- 设定菜单面板（遮罩 + 弹出面板） ---------- */
.settings-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 4000;
    justify-content: center;
    align-items: center;
}
/* 显示状态 */
.settings-panel-overlay.show {
    display: flex;
}

/* 面板本体 */
.settings-panel {
    background: #1e1f2c;
    border-radius: 20px;
    border: 1px solid #2f3545;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    width: 92%;
    max-width: 380px;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    animation: settingsSlideIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes settingsSlideIn {
    from { opacity: 0; transform: scale(0.9) translateY(-10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* 面板头部 */
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #2a2c3a;
    font-size: 1.1rem;
    font-weight: bold;
    color: #eee;
    flex-shrink: 0;
}
.settings-close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.15s;
    line-height: 1;
}
.settings-close-btn:hover {
    background: #2a2c3a;
    color: #fff;
}

/* 面板内容区域 */
.settings-body {
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* 每个设定分区 */
.settings-section {
    background: #252836;
    border-radius: 14px;
    padding: 14px 16px;
    border: 1px solid #2f3545;
}
.settings-section-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: #0af;
    margin-bottom: 4px;
}
.settings-section-desc {
    font-size: 0.7rem;
    color: #777;
    margin-bottom: 10px;
}

/* ---- 微调控制行 ---- */
.trim-control-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}
.trim-display {
    font-size: 0.9rem;
    color: #ccc;
    min-width: 80px;
    text-align: center;
}
.trim-display strong {
    color: #0af;
    font-size: 1.1rem;
}
.trim-adj-btn {
    background: #0af;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.15s;
    min-width: 44px;
    min-height: 34px;
    touch-action: manipulation;
}
.trim-adj-btn:hover {
    background: #3cf;
    transform: scale(1.05);
}
.trim-adj-btn:active {
    transform: scale(0.95);
    background: #08c;
}
.trim-reset-btn {
    display: block;
    width: 100%;
    background: #3a3f50;
    border: 1px solid #4a4f60;
    padding: 8px;
    border-radius: 20px;
    color: #ccc;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
    touch-action: manipulation;
}
.trim-reset-btn:hover {
    background: #f44;
    border-color: #f44;
    color: white;
}

/* ---- 开关式切换（方向反转等） ---- */
.settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 4px 0;
}
.settings-toggle-label {
    font-size: 0.9rem;
    color: #ccc;
}
/* 隐藏原生 checkbox，用自定义开关替代 */
.settings-toggle input[type="checkbox"] {
    display: none;
}
.settings-toggle-switch {
    position: relative;
    width: 46px;
    height: 26px;
    background: #3a3f50;
    border-radius: 13px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.settings-toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #ccc;
    border-radius: 50%;
    transition: all 0.2s;
}
/* 开启状态 */
.settings-toggle input:checked + .settings-toggle-switch {
    background: #0af;
}
.settings-toggle input:checked + .settings-toggle-switch::after {
    left: 23px;
    background: white;
}

/* ========== 全屏模式下设定面板层级 ========== */
:fullscreen .settings-panel-overlay,
:-webkit-full-screen .settings-panel-overlay,
:-moz-full-screen .settings-panel-overlay,
:-ms-fullscreen .settings-panel-overlay {
    z-index: 2147483647 !important;
}
:fullscreen #settings-menu-btn,
:-webkit-full-screen #settings-menu-btn,
:-moz-full-screen #settings-menu-btn,
:-ms-fullscreen #settings-menu-btn {
    z-index: 2147483646 !important;
}

/* ========== 移动端适配（设定面板） ========== */
/* 手机横屏 */
@media (max-width: 768px) and (orientation: landscape) {
    #settings-menu-btn {
        top: 34px;
        right: 42px;
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    .settings-panel {
        max-width: 340px;
        max-height: 90vh;
        border-radius: 16px;
    }
    .settings-header { padding: 10px 16px 8px; font-size: 1rem; }
    .settings-body { padding: 10px 14px 14px; gap: 12px; }
    .settings-section { padding: 10px 12px; }
    .trim-adj-btn { padding: 5px 12px; font-size: 0.8rem; min-width: 38px; min-height: 30px; }
}
/* 手机竖屏 */
@media (max-width: 480px) and (orientation: portrait) {
    #settings-menu-btn {
        top: 30px;
        right: 34px;
        width: 28px;
        height: 28px;
        font-size: 13px;
    }
    .settings-panel {
        max-width: 320px;
        max-height: 88vh;
        border-radius: 14px;
    }
    .settings-header { padding: 10px 14px 8px; font-size: 0.95rem; }
    .settings-body { padding: 8px 12px 12px; gap: 10px; }
    .settings-section { padding: 10px 12px; border-radius: 12px; }
    .settings-section-title { font-size: 0.85rem; }
    .trim-adj-btn { padding: 5px 10px; font-size: 0.75rem; min-width: 34px; min-height: 28px; }
    .trim-display { font-size: 0.8rem; }
}

/* 键盘提示（保留原有样式） */
.keyboard-hint {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.5);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 10px;
    pointer-events: none;
    z-index: 300;
    color: #ccc;
}

/* ========== 录制模式：隐藏所有不需要录制的UI元素 ========== */
body.recording-mode .keyboard-hint,
body.recording-mode .stick-label,
body.recording-mode #settings-menu-btn,
body.recording-mode .settings-panel-overlay,
body.recording-mode #record-toast {
    display: none !important;
}

/* 录制模式下，摇杆标签始终隐藏，避免在视频中出现 */
/* 保留摇杆本身，但隐藏标签（已通过上面的 .stick-label 处理） */

/* ========== 网络中断重连覆盖层 ========== */
.reconnect-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    justify-content: center;
    align-items: center;
    z-index: 4000;
    flex-direction: column;
}
.reconnect-card {
    text-align: center;
    padding: 30px 24px;
    max-width: 340px;
    width: 90%;
}
.reconnect-card h2 {
    color: #fff;
    font-size: 1.3rem;
    margin: 16px 0 8px;
}
.reconnect-card p {
    color: #ccc;
    font-size: 0.9rem;
    margin: 4px 0;
}
.reconnect-spinner {
    width: 48px; height: 48px;
    margin: 0 auto 8px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: #0af;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.reconnect-timer {
    margin-top: 16px;
    color: #aaa;
    font-size: 0.85rem;
}
#reconnectCountdown {
    color: #0af;
    font-weight: bold;
    font-size: 1.1rem;
}
.reconnect-cancel-btn {
    margin-top: 20px;
    padding: 10px 28px;
    background: rgba(255,255,255,0.1);
    color: #ccc;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 30px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}
.reconnect-cancel-btn:hover {
    background: rgba(255,255,255,0.2);
}
/* 全屏下覆盖层也在最上层 */
:fullscreen .reconnect-overlay,
:-webkit-full-screen .reconnect-overlay {
    z-index: 2147483647 !important;
}

