:root {
  --bg: #0d1116;
  --surface: #151b22;
  --surface-2: #1d252e;
  --surface-3: #27313c;
  --line: #2a343f;
  --text: #e7ebf0;
  --muted: #8c98a6;
  --accent: #5aa9ff;
  --accent-ink: #07213d;
  --speaking: #3fd08a;
  --danger: #ea5a5f;
  --danger-ink: #fff;
  --host: #e3ab45;
  --radius: 12px;
  --font: "Pretendard", "Pretendard Variable", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.muted { color: var(--muted); font-weight: 400; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #7bbcff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn-danger:hover:not(:disabled) { background: #f27479; }
.btn-ghost { background: transparent; }

.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; font-size: 22px; line-height: 1; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- 로비 ---------- */
.lobby {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(90,169,255,.10), transparent 60%),
    radial-gradient(700px 480px at 100% 110%, rgba(63,208,138,.06), transparent 60%),
    var(--bg);
}
.lobby-card {
  width: 100%; max-width: 420px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.lobby-title { margin: 0 0 6px; font-size: 26px; letter-spacing: -.02em; }
.lobby-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.notice {
  margin: 0 0 18px; padding: 11px 14px;
  border-radius: 10px;
  background: rgba(90,169,255,.10);
  border: 1px solid rgba(90,169,255,.35);
  font-size: 14px;
}
.notice.warn { background: rgba(234,90,95,.10); border-color: rgba(234,90,95,.45); }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  width: 100%; padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.field input::placeholder { color: #55616e; }
.field input:focus-visible { outline-offset: 0; border-color: var(--accent); }
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.form-error { margin: 0 0 12px; color: #ff8d91; font-size: 13px; }

/* ---------- 회의 레이아웃 ---------- */
.meeting {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
}

.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { flex-wrap: wrap; justify-content: flex-end; }
.room-title { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.count-label { color: var(--muted); font-size: 13px; }
.host-tools { display: flex; gap: 8px; padding-left: 12px; border-left: 1px solid var(--line); }

.rec {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(234,90,95,.16); color: #ff8d91;
  font-size: 12px; font-weight: 800; letter-spacing: .08em;
}
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }

.main { flex: 1; min-height: 0; display: flex; }
.video-area {
  position: relative;
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  padding: 12px; gap: 12px;
}

.audio-banner {
  position: absolute; z-index: 5; top: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 16px;
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  font-size: 14px;
}
.audio-sink { position: absolute; width: 0; height: 0; overflow: hidden; }

/* 격자 */
.grid {
  flex: 1; min-height: 0;
  display: grid; gap: 12px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr));
}

/* 화면 공유 모드: 큰 무대 + 가로 스트립 */
.stage {
  flex: 1; min-height: 0;
  display: flex;
}
.stage .tile { flex: 1; background: #05080b; }
.stage .tile video { object-fit: contain; }
.grid.strip {
  flex: none; height: 128px;
  display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 2px;
}
.grid.strip .tile { flex: none; width: 200px; height: 100%; }
.grid.strip .tile-name { font-size: 12px; }
.grid.strip .avatar { width: 44px; height: 44px; font-size: 18px; }

/* 타일 */
.tile {
  position: relative; overflow: hidden;
  min-width: 0; min-height: 0;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 2px solid transparent;
  transition: border-color .15s, box-shadow .15s;
}
.tile video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #05080b;
}
.tile.mirror video { transform: scaleX(-1); }
.tile.no-video video { visibility: hidden; }
.tile.speaking { border-color: var(--speaking); box-shadow: 0 0 0 3px rgba(63,208,138,.22); }

.avatar {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 76px; height: 76px; border-radius: 50%;
  display: none; place-items: center;
  background: var(--surface-3); color: var(--accent);
  font-size: 30px; font-weight: 700;
}
.tile.no-video .avatar { display: grid; }

.tile-meta {
  position: absolute; left: 8px; bottom: 8px; right: 8px;
  display: flex; align-items: center; gap: 6px;
  pointer-events: none;
}
.tile-name {
  max-width: 100%;
  padding: 3px 9px; border-radius: 7px;
  background: rgba(8,11,15,.66);
  backdrop-filter: blur(6px);
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-mic {
  flex: none;
  width: 26px; height: 26px; border-radius: 7px;
  display: none; place-items: center;
  background: rgba(234,90,95,.9);
}
.tile.mic-off .tile-mic { display: grid; }
.tile-mic svg { width: 15px; height: 15px; }

.badge {
  flex: none;
  padding: 2px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700;
  background: rgba(227,171,69,.18); color: var(--host);
  border: 1px solid rgba(227,171,69,.4);
}

/* ---------- 사이드 패널 ---------- */
.panel {
  flex: none; width: 340px;
  display: flex; flex-direction: column; min-height: 0;
  margin: 12px 12px 12px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 15px; }

.chat-list {
  flex: 1; min-height: 0; overflow-y: auto;
  margin: 0; padding: 14px; list-style: none;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 3px; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-head { font-size: 12px; color: var(--muted); }
.msg-head b { color: var(--text); font-weight: 600; margin-right: 6px; }
.msg-body {
  padding: 8px 12px; border-radius: 12px 12px 12px 4px;
  background: var(--surface-3);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.mine .msg-body { background: var(--accent); color: var(--accent-ink); border-radius: 12px 12px 4px 12px; }
.msg.system { align-self: center; max-width: 100%; font-size: 12px; color: var(--muted); }
.chat-empty { margin: auto; color: var(--muted); font-size: 13px; text-align: center; }

.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea {
  flex: 1; resize: none; max-height: 110px;
  padding: 9px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  field-sizing: content;
}
.chat-form textarea:focus-visible { outline-offset: 0; border-color: var(--accent); }

.people-actions { padding: 12px 12px 4px; }
.people-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 8px 8px 12px; list-style: none; }
.person {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 8px; border-radius: 10px;
  flex-wrap: wrap;
}
.person:hover { background: var(--surface-2); }
.person.speaking .person-name { color: var(--speaking); }
.person-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-mic { flex: none; width: 18px; height: 18px; color: var(--muted); }
.person-mic.off { color: var(--danger); }
.person-actions { flex-basis: 100%; display: flex; gap: 6px; padding-left: 0; }

/* ---------- 컨트롤 바 ---------- */
.controls {
  flex: none;
  display: flex; justify-content: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.ctl {
  position: relative;
  width: 78px; padding: 8px 0 7px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px;
  transition: background .15s, border-color .15s;
}
.ctl:hover { background: var(--surface-3); }
.ctl svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ctl .slash { display: none; stroke: var(--danger); stroke-width: 2.2; }
.ctl.off { background: rgba(234,90,95,.14); border-color: rgba(234,90,95,.5); }
.ctl.off .slash { display: block; }
.ctl.off svg { color: #ff8d91; }
.ctl.on-accent { background: rgba(90,169,255,.16); border-color: var(--accent); color: var(--accent); }
.ctl-label { font-size: 11.5px; font-weight: 600; }
.ctl-leave { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl-leave:hover { background: #f27479; }
.ctl-leave svg { fill: currentColor; stroke: none; }
.ctl:disabled { opacity: .5; }

.badge-count {
  position: absolute; top: -6px; right: -6px;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800;
  border: 2px solid var(--surface);
}

/* ---------- 다이얼로그 ---------- */
.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
.dialog::backdrop { background: rgba(3,6,9,.65); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 16px; }
.dialog-body { padding: 8px 12px; max-height: 50vh; overflow-y: auto; }
.dialog-foot { padding: 10px 14px 14px; display: flex; justify-content: flex-end; }
.rec-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.rec-row:last-child { border-bottom: 0; }
.rec-info { flex: 1; min-width: 0; }
.rec-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-sub { color: var(--muted); font-size: 12px; }
.rec-group { padding: 12px 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.rec-status { margin-left: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }
.rec-status.rec-recording, .rec-status.rec-failed { color: var(--danger); }
.rec-error { color: var(--danger); word-break: break-word; }
a.btn { text-decoration: none; color: var(--text); }
.empty { padding: 24px 8px; text-align: center; color: var(--muted); }

/* ---------- 토스트 ---------- */
.toasts {
  position: fixed; z-index: 50; left: 50%; bottom: 96px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  font-size: 14px; text-align: center;
  animation: toast-in .2s ease-out;
}
.toast.error { background: #3a1d20; border-color: rgba(234,90,95,.6); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 반응형 ---------- */
@media (max-width: 900px) {
  .panel {
    position: fixed; z-index: 20; top: 56px; right: 8px; bottom: 92px;
    width: min(360px, calc(100vw - 16px)); margin: 0;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
  }
  .host-tools { border-left: 0; padding-left: 0; }
  .room-title { max-width: 30vw; }
}
@media (max-width: 640px) {
  .ctl { width: 56px; }
  .ctl-label { font-size: 10px; }
  .controls { gap: 6px; }
  .grid.strip { height: 104px; }
  .grid.strip .tile { width: 160px; }
  .count-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.stage-note {
  position: absolute; inset: 0; display: none; place-items: center;
  color: var(--muted); font-size: 16px; font-weight: 600;
}
.stage .tile.no-video .stage-note { display: grid; }
