:root {
  --bg: #0b0e13;
  --panel: rgba(18, 22, 30, 0.82);
  --panel-solid: #12161e;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8edf5;
  --muted: #8b96a8;
  --accent: #22d3a4;
  --danger: #f2585b;
  --warn: #f5b83d;
  --radius: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ------------------------------- 顶部状态栏 ------------------------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(48px + var(--safe-t));
  padding: var(--safe-t) calc(14px + var(--safe-r)) 0 calc(14px + var(--safe-l));
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line);
  z-index: 20;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(34, 211, 164, 0.5);
  transition: background 0.2s;
}
.dot.live { background: var(--accent); animation: pulse 2s infinite; }
.dot.offline { background: var(--danger); }
.dot.warn { background: var(--warn); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 164, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(34, 211, 164, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 164, 0); }
}

.state-text {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* --------------------------------- 画面区 -------------------------------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.stage::before {
  /* 无信号时的暗格背景 */
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.65;
  pointer-events: none;
}

#screen {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  z-index: 1;
}

#screen.hidden { visibility: hidden; }

/* 覆盖层 */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 45%, rgba(11, 14, 19, 0.55), rgba(11, 14, 19, 0.92));
  transition: opacity 0.25s ease;
}
.overlay[hidden] { display: none; }
.overlay .title { font-size: 15px; font-weight: 600; }
.overlay .desc { font-size: 12.5px; color: var(--muted); max-width: 28em; line-height: 1.7; }

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------- 数据条 -------------------------------- */
.statbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: calc(40px + var(--safe-b));
  padding: 0 calc(14px + var(--safe-r)) var(--safe-b) calc(14px + var(--safe-l));
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 20;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.statbar::-webkit-scrollbar { display: none; }

.stat { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.stat b { color: var(--text); font-weight: 600; }
.stat .unit { opacity: 0.6; }

/* ------------------------------- 沉浸模式 -------------------------------- */
body.immersive .topbar { transform: translateY(-100%); opacity: 0; pointer-events: none; }
body.immersive .statbar { transform: translateY(100%); opacity: 0; pointer-events: none; }
body.immersive .stage { position: fixed; inset: 0; z-index: 10; }

/* --------------------------------- 令牌页 -------------------------------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #161c26, #080a0e 70%);
}
.gate[hidden] { display: none; }

.card {
  width: min(380px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.card h1 { margin: 0 0 6px; font-size: 17px; letter-spacing: 0.02em; }
.card p { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); line-height: 1.65; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 11.5px; color: var(--muted); letter-spacing: 0.04em; }

input[type="text"],
input[type="password"],
input[type="url"],
select {
  appearance: none;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
input:focus, select:focus { border-color: rgba(34, 211, 164, 0.55); background: rgba(255, 255, 255, 0.07); }

select option { background: #12161e; }

button.primary {
  appearance: none;
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #04231b;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: scale(0.985); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.hint { margin-top: 14px; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.error { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 4px; }

/* 竖屏提示 */
.rotate-hint {
  position: fixed;
  left: 50%;
  bottom: calc(58px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  font-size: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: hintIn 0.28s ease;
  pointer-events: none;
}
.rotate-hint[hidden] { display: none; }

@keyframes hintIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ------------------------------- 采集页样式 ------------------------------- */
.page {
  height: 100%;
  overflow-y: auto;
  display: block;
  padding: 20px calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l));
}
.page .card { width: min(620px, 100%); margin: 0 auto 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }

#preview {
  width: 100%;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  display: block;
  margin-bottom: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
}
.pill.live { color: var(--accent); border-color: rgba(34, 211, 164, 0.35); background: rgba(34, 211, 164, 0.09); }
.pill.err { color: var(--danger); border-color: rgba(242, 88, 91, 0.35); background: rgba(242, 88, 91, 0.09); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 10px; margin-top: 14px; }
.kv div { background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.kv span { display: block; font-size: 10.5px; color: var(--muted); margin-bottom: 3px; letter-spacing: 0.04em; }
.kv b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

@media (max-width: 480px) {
  .brand { font-size: 13px; }
  .statbar { gap: 11px; font-size: 11px; }
  .card { padding: 20px 16px; }
}

/* 窄屏：数据条改为可换行，避免最后一列被裁掉 */
@media (max-width: 560px) {
  .statbar {
    height: auto;
    min-height: 40px;
    flex-wrap: wrap;
    align-content: center;
    row-gap: 3px;
    column-gap: 13px;
    padding-top: 7px;
    padding-bottom: calc(7px + var(--safe-b));
    overflow-x: visible;
  }
}
