/* =============================================
   Base
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* =============================================
   Nav
   ============================================= */
.topnav {
  height: 44px;
  background: #000;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  padding: 0 20px;
  flex-shrink: 0;
}

.topnav-brand {
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topnav-brand:hover {
  color: #aaa;
}

/* =============================================
   Buttons
   ============================================= */
button, .btn-primary, .btn-secondary, .btn-danger, .btn-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 16px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, opacity 0.15s;
}

.btn-primary {
  background: #fff;
  color: #000;
}

.btn-secondary {
  background: transparent;
  color: #fff;
  border: 1px solid #333;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
}

.btn-copy {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  font-size: 12px;
  height: 28px;
  padding: 0 12px;
}

button:hover:not(:disabled), .btn-copy:hover {
  filter: brightness(1.15);
}

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

/* =============================================
   Sender layout
   ============================================= */
body:has(.sender-controls) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sender-controls {
  height: 56px;
  background: #0d0d0d;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field label {
  color: #666;
  font-size: 12px;
  white-space: nowrap;
}

.field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: unset;
  accent-color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.field input, .field select {
  height: 32px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #fff;
  font-size: 13px;
  padding: 0 10px;
  outline: none;
  min-width: 90px;
}

.field select {
  min-width: 200px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.field input:focus, .field select:focus {
  border-color: #444;
}

/* =============================================
   Sender stage (video area)
   ============================================= */
.sender-stage {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
}

.sender-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* 시작 전 안내 */
.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-size: 15px;
  pointer-events: none;
}

/* LIVE 오버레이 */
.stage-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.overlay-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.overlay-right {
  display: flex;
  align-items: center;
}

.badge-live {
  background: #c0392b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 3px;
}

#viewerCount {
  color: #aaa;
  font-size: 13px;
}

/* =============================================
   Viewer (receiver) layout
   ============================================= */
body[data-state] {
  overflow: hidden;
}

#remoteVideo {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
  display: block;
}

.viewer-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #000;
  z-index: 10;
  transition: opacity 0.3s;
}

.overlay-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-title {
  font-size: 16px;
  color: #fff;
  font-weight: 500;
}

.overlay-sub {
  font-size: 13px;
  color: #555;
  min-height: 18px;
}

/* 상태별 오버레이 표시/숨김 */
body[data-state="live"] .viewer-overlay {
  opacity: 0;
  pointer-events: none;
}

/* =============================================
   CSS 스피너
   ============================================= */
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid #222;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.offline-icon {
  width: 32px;
  height: 32px;
  border: 2px solid #333;
  border-radius: 50%;
  position: relative;
}

.offline-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #555;
  transform: translateY(-50%);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============================================
   Responsive — 모바일 컨트롤바
   ============================================= */
@media (max-width: 600px) {
  .sender-controls {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
  }

  .controls-left {
    flex-wrap: wrap;
    gap: 8px;
  }

  .field select {
    min-width: 140px;
  }
}
