:root {
  --bg: #0b1220;
  --card: #151d2b;
  --card2: #1b2536;
  --line: #2a3446;
  --txt: #e6edf3;
  --dim: #8b95a5;
  --blue: #3b82f6;
  --cyan: #58c4dc;
  --green: #34d399;
  --amber: #f0b429;
  --red: #f87171;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  padding: 18px 16px 40px;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}
h1 { font-size: 20px; margin-bottom: 4px; }
h2 { font-size: 16px; margin: 22px 0 10px; color: var(--cyan); }
.sub { color: var(--dim); font-size: 13px; margin-bottom: 18px; }
a { color: var(--cyan); text-decoration: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.card.entry { display: block; transition: border-color .15s, transform .1s; }
.card.entry:active { transform: scale(.99); border-color: var(--blue); }
.card.entry b { display: block; font-size: 16px; margin-bottom: 4px; }
.card.entry span { color: var(--dim); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--dim); margin: 10px 0 5px; }
input[type="text"], input[type="password"], select {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); }

button {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: var(--blue);
  color: #fff;
  margin-top: 12px;
  cursor: pointer;
  transition: opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--card2); color: var(--txt); border: 1px solid var(--line); }
button.danger { background: #7f1d1d; }
button.small { width: auto; padding: 8px 14px; font-size: 13px; margin: 0; }

.status {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--card2);
  color: var(--dim);
  margin-top: 12px;
  word-break: break-all;
}
.status.ok { background: #0f2e22; color: var(--green); }
.status.warn { background: #33280a; color: var(--amber); }
.status.err { background: #3a1518; color: var(--red); }

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.result { font-size: 13px; }
.result .line {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.result .line:last-child { border-bottom: none; }
.result .k { color: var(--dim); flex-shrink: 0; }
.result .v { text-align: right; word-break: break-all; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: var(--card2); color: var(--dim); margin-left: 6px;
}
.tag.green { background: #0f2e22; color: var(--green); }
.tag.amber { background: #33280a; color: var(--amber); }
.tag.red { background: #3a1518; color: var(--red); }

video {
  width: 100%; background: #000; border-radius: 12px; display: block;
  aspect-ratio: 3 / 4; object-fit: cover;
}

/* 观看端全屏：CSS 铺满，App 内 WebView 同样生效（不依赖 Fullscreen API） */
#remoteVideo.fs {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  max-width: none; max-height: none; aspect-ratio: auto;
  object-fit: contain; border-radius: 0; z-index: 9000; background: #000;
}
#fsBar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9001;
  display: none; gap: 10px; align-items: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0,0,0,.9), rgba(0,0,0,0));
}
#fsBar.show { display: flex; }
#fsBar .grow {
  flex: 1; font-size: 12px; color: #cfd8e3; line-height: 1.5;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
#fsBar button { width: auto; margin: 0; padding: 9px 16px; font-size: 13px; }
#fsTip {
  position: fixed; top: 14px; left: 0; right: 0; text-align: center;
  z-index: 9001; font-size: 12px; color: #9fb0c4; pointer-events: none;
}
body.fs-on { overflow: hidden; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button {
  margin: 0; background: var(--card); color: var(--dim);
  border: 1px solid var(--line); font-weight: 500;
}
.tabs button.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.hint { font-size: 12px; color: var(--dim); margin-top: 8px; line-height: 1.7; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* 省电黑屏遮罩：盖住界面但页面继续运行（摄像头不中断） */
#dimOverlay {
  display: none;
  position: fixed; inset: 0; z-index: 99990;
  background: #000;
  align-items: center; justify-content: center;
}
#dimOverlay.on { display: flex; }

/* ============ 瓦片模式：被 multi.html 以 iframe 嵌入，只显示画面 ============ */
body.tile > a, body.tile > h1, body.tile > .sub, body.tile > .tabs,
body.tile #panelDevice, body.tile #dimOverlay, body.tile #fsBar { display: none !important; }
body.tile #panelViewer .card,
body.tile #panelViewer button,
body.tile #panelViewer .row,
body.tile #panelViewer .status { display: none !important; }
body.tile { margin: 0 !important; padding: 0 !important; background: #000 !important; }
body.tile #remoteVideo {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000; border-radius: 0; margin: 0; display: block;
}
#tilePill {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(20,20,20,.72); color: #fff; font-size: 12px; line-height: 1.4;
  padding: 4px 12px; border-radius: 14px; display: none; z-index: 80;
  max-width: 92%; text-align: center; pointer-events: none;
}
#tilePill.show { display: block; }
#tilePill.bad { background: rgba(176,42,42,.88); }

/* ============ 多画面墙 multi.html ============ */
#grid { display: grid; gap: 10px; margin-top: 12px; }
#grid.n1 { grid-template-columns: 1fr; }
#grid.n2, #grid.n3, #grid.n4 { grid-template-columns: repeat(2, 1fr); }
#grid:empty { display: none; }
.tile {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9; cursor: pointer;
}
.tile iframe { width: 100%; height: 100%; border: 0; display: block; }
.tile .tag {
  position: absolute; top: 6px; left: 6px; z-index: 5;
  background: rgba(0,0,0,.55); color: #fff; font-size: 11px;
  padding: 2px 8px; border-radius: 10px; pointer-events: none;
  font-family: monospace;
}
.tile .close { position: absolute; top: 4px; right: 4px; z-index: 6; padding: 2px 10px; }
.tile .close { width: auto; min-width: 0; margin: 0; }
