:root {
  --bg: #0f1115; --panel: #1a1d24; --text: #e8eaed; --muted: #9aa0a6;
  --ok: #34d399; --wait: #fbbf24; --bad: #f87171; --accent: #5170ff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; height: 100dvh;
  background: var(--bg); color: var(--text);
  word-break: keep-all; overflow-wrap: anywhere; /* 한글은 낱말 단위로 줄바꿈, 긴 영문·주소는 넘치지 않게 */
  font: 15px/1.4 system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}
.bar {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
}
#status { font-weight: 700; padding: 2px 10px; border-radius: 999px; background: #2a2e37; }
#status[data-kind="ok"] { color: var(--ok); }
#status[data-kind="wait"] { color: var(--wait); }
#status[data-kind="bad"] { color: var(--bad); }
.stat { color: var(--muted); font-variant-numeric: tabular-nums; }
.stat b { color: var(--text); }
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: contain; }
.stage.mirror { transform: scaleX(-1); }       /* 영상과 캔버스를 함께 뒤집는다 */
.stage.sync video { visibility: hidden; }      /* 동기 표시: 보낸 프레임을 캔버스에 그린다 */
.notice { margin: 8px 12px 0; min-height: 1.4em; color: var(--wait); }
.notice:empty { display: none; }
.legend { margin: 8px 12px 0; color: var(--muted); font-size: 13px; }
.legend b { font-weight: 700; }
.legend .pair { white-space: nowrap; } /* 색과 뜻이 다른 줄로 갈리지 않게 */
.lg-left { color: #38bdf8; }   /* lib.js COLORS와 같은 값 */
.lg-right { color: #fb923c; }
.lg-trunk { color: #facc15; }
.lg-face { color: #f472b6; }
.hint { margin: 6px 12px 0; color: var(--muted); font-size: 13px; }
.privacy { margin: 4px 12px 6px; color: var(--muted); font-size: 12px; }
.controls {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
}
button {
  word-break: keep-all; /* 한글 버튼 문구가 단어 중간에서 줄바꿈되지 않게 */
  font: inherit; color: var(--text); background: #2a2e37;
  border: 0; border-radius: 10px; padding: 12px 6px; min-height: 44px;
}
button.primary { background: var(--accent); color: #fff; font-weight: 700; }
dialog {
  width: min(92vw, 420px); border: 0; border-radius: 14px;
  background: var(--panel); color: var(--text); padding: 18px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: block; margin-bottom: 12px; color: var(--muted); }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px;
  font: inherit; font-size: 16px; /* 16px 미만이면 아이폰이 입력할 때 화면을 확대하고 되돌리지 않는다 */
  color: var(--text); background: var(--bg);
  border: 1px solid #3a3f4b; border-radius: 8px;
}
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 12px 0 0; }
dialog menu button { padding: 10px 18px; }
.small { font-size: 13px; color: var(--muted); margin: 0; }
dialog label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); }
dialog label.check input { display: inline-block; width: 20px; height: 20px; margin: 2px 0 0; flex: none; }
dialog label.check small { color: var(--muted); }
.error { color: var(--bad); margin: 6px 0 0; min-height: 1.2em; }
.token-row { display: flex; gap: 6px; align-items: stretch; margin-top: 4px; }
.token-row input { margin-top: 0; flex: 1; min-width: 0; }
.token-row button { padding: 0 12px; min-height: 0; }

/* 가로로 눕힌 폰: 영상 영역을 넓히려고 안내·범례를 숨기고 버튼을 한 줄로 낮춘다 */
@media (orientation: landscape) and (max-height: 500px) {
  .legend, .hint { display: none; }
  .bar { padding-top: 6px; padding-bottom: 6px; }
  .privacy { margin: 2px 12px; font-size: 11px; } /* 영상 전송 고지는 가로에서도 남긴다 */
  .controls { padding-top: 6px; padding-bottom: 6px; }
  button { min-height: 36px; padding: 6px; }
}
