* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: #111418;
  color: #e8eaed;
}
[hidden] { display: none !important; }
h2 { margin: 0; font-size: 20px; }
.muted { color: #9aa3ad; }
.small-text { font-size: 13px; }
.error { color: #ff6b6b; margin: 0; font-size: 14px; }

.screen { height: 100%; }

/* 버튼 */
button {
  padding: 10px 16px; border: 0; border-radius: 8px; cursor: pointer;
  background: #2d333b; color: #fff; font-size: 15px; font-family: inherit;
}
button:hover:not(:disabled) { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: default; }
button.primary, #login-btn { background: #4c8bf5; }
button.big { padding: 14px; font-size: 17px; font-weight: 600; }
button.danger { background: #e5484d; }
button.small { padding: 6px 10px; font-size: 13px; }
button.link { background: none; color: #9aa3ad; text-decoration: underline; padding: 4px; }
button.icon { background: none; font-size: 18px; padding: 4px 8px; }
button.toggle.off { background: #e5484d; }
button.active { background: #4c8bf5; }

/* 로그인 */
#login { display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
  width: 100%; max-width: 360px;
  background: #1d2127; border-radius: 12px; padding: 28px;
  display: flex; flex-direction: column; gap: 16px;
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #aab; }
input, select {
  padding: 10px 12px; border-radius: 8px; border: 1px solid #333a44;
  background: #111418; color: #fff; font-size: 15px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid #4c8bf5; border-color: transparent; }

/* 영상 타일 */
.tile { position: relative; background: #000; border-radius: 10px; overflow: hidden; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.self video { transform: scaleX(-1); }
.tile.self.screen video { transform: none; object-fit: contain; }
.tile.remote video { object-fit: contain; }
.tile .label {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.6); padding: 4px 8px; border-radius: 6px; font-size: 13px;
}
.tile .avatar {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 48px; background: #262b33;
}
.tile.no-video .avatar { display: flex; }
.tile-status {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.7); padding: 6px 12px; border-radius: 6px; font-size: 13px;
}

/* 대기실 */
#lobby { overflow: auto; }
.lobby {
  min-height: 100%;
  display: flex; gap: 24px; align-items: center; justify-content: center;
  padding: 24px; flex-wrap: wrap;
}
.lobby-preview { flex: 1 1 520px; max-width: 760px; display: flex; flex-direction: column; gap: 12px; }
#preview-tile { aspect-ratio: 16 / 9; width: 100%; }
.preview-controls { display: flex; gap: 8px; justify-content: center; }
.lobby-side {
  flex: 0 1 380px; background: #1d2127; border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.lobby-side p { margin: 0; }

/* 설정 패널 */
.settings { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 14px; color: #c4cad1; }
.row { display: flex; gap: 8px; align-items: center; }
.meter { height: 6px; background: #2d333b; border-radius: 3px; overflow: hidden; }
#mic-level { height: 100%; width: 0; background: #3ecf8e; transition: width .08s linear; }

.bg-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bg-option {
  position: relative; aspect-ratio: 16 / 9; padding: 0; border-radius: 6px; overflow: hidden;
  background: #2d333b center / cover no-repeat; border: 2px solid transparent;
  font-size: 11px; color: #fff;
}
.bg-option.selected { border-color: #4c8bf5; }
.bg-option span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px;
  background: rgba(0,0,0,.55); text-align: center;
}
.bg-option .icon-big { position: absolute; inset: 0 0 14px; display: flex; align-items: center; justify-content: center; font-size: 18px; }

/* 회의 */
#meeting { display: flex; flex-direction: column; }
#grid {
  flex: 1; display: grid; gap: 8px; padding: 8px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: minmax(180px, 1fr);
  overflow: auto;
}
#controls {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  padding: 12px; background: #1d2127;
}

/* 설정 창 */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal-box {
  background: #1d2127; border-radius: 12px; padding: 20px;
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

#toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #2d333b; padding: 8px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

@media (max-width: 600px) {
  #controls button span { display: none; }
  .lobby { padding: 12px; }
  .bg-grid { grid-template-columns: repeat(3, 1fr); }
}
