:root {
  --bg: #0d0f12;
  --bg2: #151920;
  --card: #1a1f28;
  --line: #2a3140;
  --text: #e8ecf2;
  --dim: #94a0b3;
  --accent: #ff4d7d;
  --accent2: #4dd4ff;
  --ok: #3ddc97;
  --warn: #ffb648;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

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

body { display: flex; flex-direction: column; }

.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }

/* ---------- 首页 ---------- */
.wrap {
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: 24px 18px calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 18px;
}

.hero { text-align: center; padding: 10px 0 4px; }
.hero-icon { font-size: 46px; line-height: 1; }
.hero h1 { margin: 10px 0 8px; font-size: 25px; letter-spacing: .5px; }
.sub { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.65; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px;
}
.field-label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 10px; }
.room-row { display: flex; gap: 10px; }
.room-input {
  flex: 1; background: #0f131a; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px 16px; font-size: 26px; letter-spacing: 8px;
  text-align: center; font-weight: 700; outline: none; min-width: 0;
}
.room-input:focus { border-color: var(--accent); }
.btn-ghost {
  background: #0f131a; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; width: 54px; font-size: 22px; cursor: pointer;
}
.btn-ghost:active { background: #1b212c; }
.hint { margin: 10px 2px 0; font-size: 12px; color: var(--dim); min-height: 16px; }

.roles { display: flex; flex-direction: column; gap: 12px; }
.role-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; color: var(--text); display: flex; align-items: center; gap: 14px;
  transition: transform .12s ease, border-color .12s ease;
}
.role-card:active { transform: scale(.985); }
.role-card.cam { border-left: 4px solid var(--accent); }
.role-card.view { border-left: 4px solid var(--accent2); }
.role-emoji { font-size: 30px; }
.role-title { font-size: 17px; font-weight: 700; }
.role-desc { font-size: 12.5px; color: var(--dim); margin-top: 3px; line-height: 1.5; }

.faq { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
.faq summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent2); }
.faq ol { margin: 12px 0 4px; padding-left: 20px; color: var(--dim); font-size: 13px; line-height: 1.8; }
.faq b { color: var(--text); }

/* ---------- 拍摄/观看舞台 ---------- */
.stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; background: #000; }

#cam-video, .frame-stack { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; }

#cam-video { width: 100%; height: 100%; object-fit: contain; display: block; }
#cam-video.mirror { transform: scaleX(-1); }

.frame-stack video, .frame-stack img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
.frame-stack img { display: none; }
.frame-stack img.show { display: block; }
.frame-stack video { display: none; }
.frame-stack video.show { display: block; }

.stage-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,.65), transparent);
  pointer-events: none;
}
.stage-top > * { pointer-events: auto; }
.chip {
  background: rgba(20,24,32,.78); border: 1px solid rgba(255,255,255,.14);
  color: var(--text); border-radius: 999px; padding: 7px 14px;
  font-size: 13px; cursor: pointer; backdrop-filter: blur(8px);
}
.chip-status { cursor: default; font-size: 12px; }
.chip-status.ok { color: var(--ok); border-color: rgba(61,220,151,.4); }
.chip-status.warn { color: var(--warn); border-color: rgba(255,182,72,.4); }

.placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; z-index: 2;
  color: var(--dim); font-size: 14px; background: #000;
}
.placeholder.hide { display: none; }
.spinner {
  width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.14);
  border-top-color: var(--accent2); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-bottom {
  position: relative; z-index: 5; padding: 12px 12px calc(12px + var(--safe-b));
  background: linear-gradient(to top, rgba(0,0,0,.92), rgba(0,0,0,.55));
  display: flex; flex-direction: column; gap: 10px;
}

.ctrl-row { display: flex; gap: 8px; }
.ctrl {
  flex: 1; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
  color: var(--text); border-radius: 14px; padding: 10px 4px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 20px;
  transition: background .12s;
}
.ctrl span { font-size: 11px; color: var(--dim); }
.ctrl:active { background: rgba(255,255,255,.18); }
.ctrl.on { background: rgba(255,77,125,.26); border-color: var(--accent); }
.ctrl.on span { color: #ffd7e2; }
.ctrl[disabled] { opacity: .38; }
.ctrl.unsupported { opacity: .5; border-style: dashed; }
.ctrl.wide { flex: 1; }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font-size: 11px; color: var(--dim); background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08); border-radius: 999px; padding: 4px 10px;
}

.zoom-row { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.zoom-label { font-size: 12px; color: var(--dim); }
.zoom-val { font-size: 12px; color: var(--accent2); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] {
  flex: 1; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px;
  background: rgba(255,255,255,.18); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent2); border: 2px solid #0d0f12;
}
input[type=range]:disabled { opacity: .4; }

.tip { margin: 4px 4px 0; font-size: 11.5px; color: var(--dim); line-height: 1.6; }
.tip b { color: var(--accent2); }

/* ---------- 系统相机拍照（主按钮）---------- */
.big-shot {
  width: 100%; background: linear-gradient(135deg, #ff4d7d, #ff7a4d);
  border: none; color: #fff; font-size: 16px; font-weight: 700;
  border-radius: 14px; padding: 14px; cursor: pointer; letter-spacing: .5px;
  box-shadow: 0 4px 16px rgba(255, 77, 125, .32);
}
.big-shot:active { transform: scale(.985); opacity: .92; }
.big-shot.flash { animation: pulse .5s ease 2; }
@keyframes pulse { 0%,100% { box-shadow: 0 4px 16px rgba(255,77,125,.32); } 50% { box-shadow: 0 0 0 8px rgba(255,77,125,.28); } }

/* ---------- 高清照片查看器 ---------- */
.photo-viewer {
  position: fixed; inset: 0; z-index: 200; background: #000;
  display: none; flex-direction: column;
}
.photo-viewer.show { display: flex; }
.photo-viewer img {
  flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000;
}
.photo-bar {
  display: flex; gap: 8px; padding: 12px 12px calc(12px + var(--safe-b));
  background: #0d0f12; border-top: 1px solid var(--line);
}
.photo-btn {
  flex: 1; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
  color: var(--text); border-radius: 12px; padding: 13px 6px; font-size: 14px; cursor: pointer;
}
.photo-btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 700; }
.photo-btn:active { opacity: .85; }

/* ---------- 远程请求拍照 ---------- */
.remote-shot {
  position: fixed; inset: 0; z-index: 300; display: none;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .82); padding: 24px;
}
.remote-shot.show { display: flex; }
.remote-shot-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px 20px; text-align: center; width: 100%; max-width: 340px;
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rs-title { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
.rs-sub { margin: 0 0 18px; font-size: 13px; color: var(--dim); line-height: 1.6; }
.rs-btn {
  width: 100%; background: linear-gradient(135deg, #ff4d7d, #ff7a4d); border: none;
  color: #fff; font-size: 18px; font-weight: 700; border-radius: 14px; padding: 17px;
  cursor: pointer; animation: pulse 1.1s ease infinite;
}
.rs-cancel {
  margin-top: 10px; width: 100%; background: transparent; border: 1px solid var(--line);
  color: var(--dim); border-radius: 12px; padding: 12px; font-size: 14px; cursor: pointer;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 12px);
  background: rgba(20,24,32,.95); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 99;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .stage-bottom { padding-left: 24px; padding-right: 24px; }
}
