:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #4f9cf9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

header {
  margin-bottom: 20px;
}

h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

#role-label {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px;
  margin-bottom: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input {
  width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c0e12;
  color: var(--text);
  font-size: 14px;
}

button {
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#status {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.videos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

figure {
  margin: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.video-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  container-type: size;
}

video {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: cover;
}

/*
 * 摄像头画面逆时针偏转 90°：顺时针旋转回来。
 * 旋转后视频元素的宽高与容器互换（cqh/cqw），再绕中心转 90°，
 * 这样旋转后的画面正好铺满 16:9 容器，且不会被裁切。
 */
body[data-rotate="cw"] .video-box video,
body[data-rotate="ccw"] .video-box video {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100cqh;
  height: 100cqw;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(90deg);
}

/* 如需反向校正，把 index.html 里的 data-rotate 改成 "ccw" */
body[data-rotate="ccw"] .video-box video {
  transform: translate(-50%, -50%) rotate(-90deg);
}

figcaption {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.hint {
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
}

.hint a {
  color: var(--accent);
}
