/* ============ ESP32-S3 摄像头 · 云端观看页 ============ */

:root {
    --bg: #070b14;
    --bg-soft: #0d1424;
    --panel: rgba(18, 27, 45, 0.72);
    --panel-border: rgba(120, 160, 255, 0.14);
    --text: #e8eefc;
    --text-dim: #93a1bd;
    --accent: #5b8cff;
    --accent-2: #4fd1c5;
    --ok: #3ddc97;
    --danger: #ff6b6b;
    --radius: 16px;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background:
        radial-gradient(1200px 600px at 15% -10%, rgba(91, 140, 255, 0.18), transparent 60%),
        radial-gradient(900px 500px at 110% 10%, rgba(79, 209, 197, 0.12), transparent 55%),
        var(--bg);
    color: var(--text);
    font: 14px/1.55 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ---------------- 登录 ---------------- */

.login {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
    background: var(--bg);
}

.login[hidden] {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 28px;
    border-radius: var(--radius);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 20px;
    letter-spacing: 0.4px;
}

.login-sub {
    margin: 0 0 22px;
    color: var(--text-dim);
    font-size: 13px;
}

.field {
    display: block;
    margin-bottom: 14px;
}

.field span {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.field input {
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-size: 15px;
    outline: none;
}

.field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.login-err {
    min-height: 18px;
    margin: 12px 0 0;
    color: var(--danger);
    font-size: 12px;
}

/* ---------------- 布局 ---------------- */

.app {
    max-width: 1420px;
    margin: 0 auto;
    padding: 18px clamp(12px, 3vw, 28px) 40px;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.logo {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 22px rgba(91, 140, 255, 0.35);
}

.brand-text h1 {
    margin: 0;
    font-size: 17px;
    letter-spacing: 0.3px;
}

.brand-text p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--text-dim);
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.badge {
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid var(--panel-border);
    white-space: nowrap;
}

.badge.pill {
    color: #ffd4d4;
    border-color: rgba(255, 107, 107, 0.35);
    background: rgba(255, 107, 107, 0.12);
}

.badge.pill.online {
    color: #c9ffe6;
    border-color: rgba(61, 220, 151, 0.35);
    background: rgba(61, 220, 151, 0.14);
}

button.badge.ghost {
    cursor: pointer;
    font: inherit;
    font-size: 12px;
}

button.badge.ghost:hover {
    color: var(--text);
    border-color: var(--accent);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

@media (max-width: 1000px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------------- 画面区 ---------------- */

.stage {
    min-width: 0;
}

.viewport {
    position: relative;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius);
    overflow: hidden;
    background: #04060d;
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewport canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #04060d;
}

.overlay {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: rgba(232, 238, 252, 0.9);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

.placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: radial-gradient(circle at 50% 45%, rgba(91, 140, 255, 0.12), transparent 60%), #04060d;
    color: var(--text-dim);
    transition: opacity 0.25s ease;
}

.placeholder.hidden {
    opacity: 0;
    pointer-events: none;
    /* 光靠 opacity:0 只是视觉上消失，仍会留在无障碍树里，
     * 读屏软件会念出"正在拉流"这类过期提示。 */
    visibility: hidden;
}

.spinner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 3px solid rgba(120, 160, 255, 0.18);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.stage-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

.hint {
    font-size: 12px;
    color: var(--text-dim);
}

/* ---------------- 控件 ---------------- */

.btn {
    padding: 9px 16px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover {
    border-color: rgba(120, 160, 255, 0.42);
}

.btn:active {
    transform: translateY(1px);
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #04121a;
    font-weight: 600;
}

.btn.ghost {
    background: transparent;
}

.btn.block {
    width: 100%;
    padding: 11px;
    font-size: 14px;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.group {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(14px);
}

.group h2 {
    margin: 0 0 12px;
    font-size: 12px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 600;
}

.presets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.btn.preset {
    padding: 9px 0;
    font-size: 13px;
    border-radius: 10px;
}

.btn.preset.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #04121a;
    font-weight: 600;
}

.row {
    display: block;
    margin-bottom: 12px;
}

.row > span {
    display: block;
    margin-bottom: 7px;
    font-size: 12px;
    color: var(--text-dim);
}

.row b {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

select {
    width: 100%;
    padding: 9px 10px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: rgba(0, 0, 0, 0.32);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    outline: none;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #0b1220;
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 2px solid #0b1220;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.tip {
    margin: 4px 0 12px;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text-dim);
}

.switches {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
}

.switch input {
    display: none;
}

.switch .track {
    width: 38px;
    height: 21px;
    flex: 0 0 38px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    position: relative;
    transition: background 0.18s ease;
}

.switch .track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #dfe8ff;
    transition: transform 0.18s ease;
}

.switch input:checked + .track {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.switch input:checked + .track::after {
    transform: translateX(17px);
    background: #04121a;
}

.stats {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats > div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
    font-size: 12.5px;
}

.stats > div:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.stats dt {
    color: var(--text-dim);
}

.stats dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

/* ---------------- 全屏 ---------------- */

.viewport:fullscreen {
    border-radius: 0;
    aspect-ratio: auto;
    width: 100vw;
    height: 100vh;
    border: none;
}

.viewport:fullscreen canvas {
    object-fit: contain;
}
