:root {
    --bg: #07111f;
    --panel: rgba(15, 23, 42, .88);
    --card: rgba(30, 41, 59, .78);
    --card-strong: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --brand: #38bdf8;
    --brand-2: #2563eb;
    --danger: #ef4444;
    --danger-2: #991b1b;
    --ok: #22c55e;
    --warn: #f59e0b;
    --line: rgba(148, 163, 184, .22);
    --shadow: 0 22px 80px rgba(0, 0, 0, .35);
    --joy-size: 120px;   /* 摇杆直径 */
    --joy-thumb: 52px;   /* 摇杆头直径 */
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(circle at 20% 0%, rgba(56, 189, 248, .22), transparent 32%),
        radial-gradient(circle at 90% 10%, rgba(99, 102, 241, .24), transparent 28%),
        linear-gradient(160deg, #020617, #0f172a 52%, #020617);
    color: var(--text);
    overflow-x: hidden;
}

button {
    font-family: inherit;
}

header {
    padding: 18px 6vw;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    background: rgba(2, 6, 23, .74);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(14px);
}

h1, h2, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: .02em; }

.nav a {
    color: var(--muted);
    text-decoration: none;
    margin-left: 18px;
}
.nav a:hover { color: var(--brand); }

main { padding: 28px 6vw; }

.card, .video-card, .controls-card, .status-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 18px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.video {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: 18px;
    object-fit: cover;
    border: 1px solid rgba(148, 163, 184, .32);
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.btn {
    border: 0;
    border-radius: 14px;
    padding: 14px 16px;
    font-weight: 800;
    color: #00111a;
    background: var(--brand);
    cursor: pointer;
    transition: .2s;
}

.btn:hover,
.mode-btn:hover,
.mini-btn:hover {
    filter: brightness(1.08);
}

.btn.stop {
    background: var(--danger);
    color: #fff;
}

.btn.mode {
    background: #a78bfa;
    color: #fff;
}

.status {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 14px;
}

.metric {
    padding: 15px;
    background: rgba(15, 23, 42, .86);
    border-radius: 16px;
    border: 1px solid var(--line);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.metric strong {
    font-size: 24px;
    word-break: break-all;
}

.muted, .small-muted {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.alarm { color: var(--danger) !important; }
.ok    { color: var(--ok) !important; }
.warn  { color: var(--warn) !important; }

table { width: 100%; border-collapse: collapse; }
td, th { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; }

input {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #020617;
    color: var(--text);
    margin: 8px 0 16px;
}

/* ====== 页面布局 ====== */

.remote-page {
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: none;
}

.mobile-header {
    padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
}

.eyebrow {
    color: var(--brand);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.compact-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compact-nav a {
    margin-left: 0;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(15, 23, 42, .64);
    font-size: 13px;
}

.remote-shell {
    width: min(1200px, 100%);
    margin: 0 auto;
    padding: 14px 14px calc(22px + env(safe-area-inset-bottom));
    display: grid;
    gap: 14px;
    align-items: start;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.section-title strong { font-size: 16px; }

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--warn);
    box-shadow: 0 0 18px rgba(245, 158, 11, .75);
}

.dot.online {
    background: var(--ok);
    box-shadow: 0 0 18px rgba(34, 197, 94, .8);
}

.dot.offline {
    background: var(--danger);
    box-shadow: 0 0 18px rgba(239, 68, 68, .8);
}

.cloud-video {
    aspect-ratio: 16 / 10;
    max-height: 42vh;
    transform: rotate(180deg);
}

.video-stage {
    position: relative;
    width: 100%;
}

.video-stage .video { display: block; }

.video-placeholder {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, .22);
    background:
        radial-gradient(circle at 50% 20%, rgba(56, 189, 248, .12), transparent 30%),
        linear-gradient(180deg, rgba(2, 6, 23, .92), rgba(15, 23, 42, .96));
    color: var(--text);
    text-align: center;
    padding: 20px;
}

.video-placeholder.active { display: flex; }
.video-placeholder strong { font-size: 20px; }
.video-placeholder span { color: var(--muted); font-size: 14px; }

.spinner {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 4px solid rgba(148, 163, 184, .2);
    border-top-color: var(--brand);
    border-right-color: rgba(96, 165, 250, .8);
    animation: spin 1s linear infinite;
    box-shadow: 0 0 24px rgba(56, 189, 248, .18);
}

@keyframes spin { to { transform: rotate(360deg); } }

.camera-strip {
    display: grid;
    gap: 4px;
    margin-top: 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(2, 6, 23, .46);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.mini-btn {
    border: 1px solid rgba(56, 189, 248, .42);
    border-radius: 999px;
    padding: 9px 14px;
    color: #dff7ff;
    background: rgba(14, 165, 233, .18);
    font-weight: 800;
    cursor: pointer;
    transition: .2s;
}

.badge {
    padding: 7px 11px;
    border-radius: 999px;
    color: #dbeafe;
    background: rgba(37, 99, 235, .32);
    border: 1px solid rgba(96, 165, 250, .38);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .06em;
}

/* ====== 急停按钮 ====== */

.estop-btn {
    display: block;
    width: 100%;
    border: none;
    border-radius: 20px;
    padding: 18px;
    font-size: 24px;
    font-weight: 900;
    color: #fff;
    letter-spacing: .12em;
    cursor: pointer;
    background: radial-gradient(circle at 40% 30%, #fb7185, #ef4444 55%, #b91c1c);
    box-shadow:
        0 4px 20px rgba(239, 68, 68, .45),
        0 0 0 4px rgba(239, 68, 68, .18),
        inset 0 2px 0 rgba(255, 255, 255, .25);
    transition: transform .06s ease, box-shadow .2s ease;
    text-shadow: 0 2px 6px rgba(0, 0, 0, .3);
    margin-bottom: 18px;
}

.estop-btn:active {
    transform: scale(.96);
    box-shadow:
        0 2px 10px rgba(239, 68, 68, .5),
        0 0 0 6px rgba(239, 68, 68, .25),
        inset 0 2px 0 rgba(255, 255, 255, .2);
}

/* ====== 摇杆 ====== */

.joystick-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.joystick-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.joystick-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.joystick-wrapper {
    position: relative;
    width: var(--joy-size);
    height: var(--joy-size);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(15, 23, 42, .9), rgba(2, 6, 23, .95));
    border: 2px solid rgba(148, 163, 184, .25);
    box-shadow: 0 6px 24px rgba(0, 0, 0, .4), inset 0 0 12px rgba(56, 189, 248, .08);
    cursor: pointer;
    touch-action: none;
}

.joystick-base {
    position: absolute;
    inset: 12px;
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, .12);
    pointer-events: none;
}

.joystick-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--joy-thumb);
    height: var(--joy-thumb);
    margin: calc(var(--joy-thumb) / -2) 0 0 calc(var(--joy-thumb) / -2);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 32%, #60a5fa, #2563eb 55%, #1e40af);
    box-shadow: 0 4px 16px rgba(37, 99, 235, .5), inset 0 2px 0 rgba(255, 255, 255, .3);
    pointer-events: none;
    transition: transform .03s ease;
    will-change: transform;
}

/* ====== 模式按钮 ====== */

.mode-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.mode-btn {
    border: 0;
    color: white;
    font-weight: 900;
    cursor: pointer;
    user-select: none;
    min-height: 52px;
    border-radius: 16px;
    padding: 10px 8px;
    font-size: 15px;
    background: rgba(99, 102, 241, .78);
    border: 1px solid rgba(199, 210, 254, .25);
    transition: transform .06s ease, filter .15s ease, box-shadow .2s ease;
}

.mode-btn:active { transform: scale(.96); }

.mode-btn.active {
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .22), 0 10px 28px rgba(56, 189, 248, .25);
    background: rgba(37, 99, 235, .88);
}

.diagnostic-btn {
    background: rgba(245, 158, 11, .82);
    border-color: rgba(253, 230, 138, .34);
}

/* ====== 速度控制 ====== */

.speed-control {
    padding: 14px;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 18px;
    background: rgba(15, 23, 42, .42);
}

.compact-title { margin-bottom: 10px; }

.speed-slider {
    width: 100%;
    accent-color: #38bdf8;
    cursor: pointer;
    margin: 8px 0 12px;
}

.speed-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.preset-btn {
    border: 1px solid rgba(56, 189, 248, .32);
    border-radius: 12px;
    padding: 10px 14px;
    color: var(--brand);
    background: rgba(14, 165, 233, .12);
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: .15s;
}

.preset-btn:active {
    background: rgba(14, 165, 233, .28);
    transform: scale(.96);
}

/* ====== 键盘提示卡 ====== */

.keyboard-help-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 18px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.keyboard-help-card .section-title {
    margin-bottom: 12px;
}

.key-map {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.key-group {
    flex: 1;
    min-width: 180px;
    padding: 12px;
    background: rgba(15, 23, 42, .56);
    border-radius: 14px;
    border: 1px solid var(--line);
}

.key-group-title {
    display: block;
    color: var(--brand);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .1em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.key-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
}

.key-hint {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
}

.key-hint kbd {
    display: inline-block;
    min-width: 24px;
    text-align: center;
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(56, 189, 248, .15);
    border: 1px solid rgba(56, 189, 248, .25);
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
    font-family: inherit;
    line-height: 1.5;
}

.kbd-indicator {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(56, 189, 248, .12);
    color: var(--brand);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    border: 1px solid rgba(56, 189, 248, .2);
}

/* ====== 状态 ====== */

.quick-status {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
}

.quick-item {
    min-height: 72px;
    padding: 12px 10px;
    border-radius: 18px;
    background: rgba(15, 23, 42, .74);
    border: 1px solid var(--line);
}

.quick-item span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 7px;
}

.quick-item strong { font-size: 18px; }

.more-status { margin-top: 12px; }

.more-status summary {
    color: var(--brand);
    cursor: pointer;
    font-weight: 800;
    padding: 10px 0 2px;
}

/* ====== 响应式 ====== */

/* 大屏：视频左，控制+状态右 */
@media (min-width: 980px) {
    .remote-shell {
        grid-template-columns: minmax(400px, 1.3fr) minmax(380px, .9fr);
        align-items: start;
    }

    .video-card {
        grid-row: span 2;
        position: sticky;
        top: 96px;
    }

    .controls-card,
    .status-card {
        grid-column: 2;
    }

    .cloud-video { max-height: none; }

    .status {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* 中等屏幕 */
@media (min-width: 620px) and (max-width: 979px) {
    .remote-shell {
        width: min(860px, 100%);
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .video-card,
    .status-card { grid-column: span 2; }
}

/* 小屏幕 */
@media (max-width: 520px) {
    h1 { font-size: 19px; }

    .compact-nav a {
        padding: 8px 10px;
        font-size: 12px;
    }

    .remote-shell {
        padding-left: 10px;
        padding-right: 10px;
    }

    .video-card,
    .controls-card,
    .status-card {
        border-radius: 20px;
        padding: 14px;
    }

    :root {
        --joy-size: 100px;
        --joy-thumb: 44px;
    }

    .joystick-row { gap: 14px; }

    .estop-btn {
        padding: 14px;
        font-size: 20px;
        border-radius: 16px;
        margin-bottom: 14px;
    }

    .mode-btn { min-height: 46px; font-size: 14px; }

    .keyboard-help-card { display: none; }

    .quick-status,
    .status {
        grid-template-columns: repeat(2, 1fr);
    }

    .camera-strip #cameraInfo { display: none; }

    .cloud-video { max-height: 36vh; }
}
