:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dde0e6;
  --text: #1c1f24;
  --muted: #646b76;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d93a3a;
  --ok: #1f9d55;
  --stage: #111316;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2228;
    --border: #2e333b;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --accent: #5b8cff;
    --danger: #f06262;
    --ok: #3fc07a;
    --stage: #000000;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- 카드형 폼 ---------- */
.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card .sub { margin: 0 0 20px; color: var(--muted); }

label { display: block; font-weight: 600; margin: 14px 0 6px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}
button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.block { width: 100%; margin-top: 20px; padding: 11px; }
button.block.secondary { margin-top: 10px; }
button.small { padding: 4px 10px; font-size: 13px; }

.error { color: var(--danger); margin: 12px 0 0; min-height: 1.5em; }

/* ---------- 오너 대시보드 ---------- */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
}
@media (max-width: 860px) { .dashboard { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar .code { font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.topbar .spacer { flex: 1; }

.share-link { display: flex; gap: 8px; }
.share-link input { flex: 1; min-width: 0; }

.pw-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; font-weight: 600; }

/* 오너 화면 상단 줄: 스크롤해도 항상 보이게 */
.dashboard .topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0;
  margin: -10px 0 0;
}

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.controls .quality-note { font-size: 13px; color: var(--muted); }
.controls .check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }

.preview {
  margin-top: 16px;
  width: 100%;
  max-width: 360px; /* 강사 본인 화면은 확인용이라 작게 */
  aspect-ratio: 16 / 9;
  font-size: 13px;
  text-align: center;
  background: var(--stage);
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #9aa1ab;
}
.preview video { width: 100%; height: 100%; object-fit: contain; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}
.badge.live { color: var(--danger); }
.badge.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.people { list-style: none; margin: 0; padding: 0; }
.people li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.people li:last-child { border-bottom: none; }
.people .empty { color: var(--muted); justify-content: center; }
.people .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .actions { display: flex; gap: 6px; flex-shrink: 0; }

.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- 알림 ---------- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  max-width: min(320px, calc(100vw - 32px));
  box-shadow: 0 4px 12px #0003;
}

.badge.ok { color: var(--ok); }

/* ---------- 대화상자 ---------- */
dialog {
  width: min(400px, calc(100% - 32px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
dialog::backdrop { background: #0008; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog .sub { margin: 0 0 8px; color: var(--muted); }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- 시청자 화면 ---------- */
.viewer { height: 100%; display: flex; flex-direction: column; background: var(--stage); }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.viewer-bar .spacer { flex: 1; }
.stage { flex: 1; position: relative; min-height: 0; display: grid; place-items: center; }
.stage video { width: 100%; height: 100%; object-fit: contain; background: var(--stage); }
.stage .message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c7ccd3;
  text-align: center;
  padding: 16px;
}
.status-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #000c;
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
}

.badge.owner { color: var(--accent); }

/* ---------- 시청자 화면 공유 ---------- */
.remote-shares { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.remote-share { display: flex; flex-direction: column; gap: 6px; }
.remote-share video { width: 100%; aspect-ratio: 16 / 9; background: var(--stage); border-radius: 8px; object-fit: contain; cursor: zoom-in; }
.remote-share .head { display: flex; align-items: center; gap: 6px; }
.remote-share .head .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.share-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.share-tabs button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.people .sharing { font-size: 12px; color: var(--ok); margin-left: 6px; }
