/* ─── 기본 리셋 ─────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --accent: #00b4d8;
  --accent2: #0077b6;
  --purple: #7c3aed;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --text: #e6edf3;
  --text2: #8b949e;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ─── 공통 컴포넌트 ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s, background 0.15s;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.95); opacity: 0.85; }

.btn-primary   { background: var(--accent2); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--red); color: #fff; }
.btn-purple    { background: var(--purple); color: #fff; }
.btn-green     { background: var(--green); color: #000; }
.btn-icon      { background: var(--bg3); color: var(--text); border: 1px solid var(--border); min-width: 2.8rem; }
.btn.active    { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-icon.on   { background: var(--yellow); color: #000; border-color: var(--yellow); }
.btn-icon.red  { background: var(--red); color: #fff; border-color: var(--red); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-green  { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge-yellow { background: rgba(210, 153, 34, 0.15); color: var(--yellow); }
.badge-red    { background: rgba(248, 81, 73, 0.15);  color: var(--red); }
.badge-blue   { background: rgba(0, 180, 216, 0.15);  color: var(--accent); }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.8s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ─── 토스트 알림 ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 1.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  color: var(--text);
  padding: 0.75rem 1.4rem;
  border-radius: 24px;
  border: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 9999;
  white-space: nowrap;
  animation: toastIn 0.2s ease, toastOut 0.2s ease 2.6s forwards;
}
@keyframes toastIn  { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(-50%) translateY(12px); } }

/* ─── 랜딩 페이지 ───────────────────────────────────────────── */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 3rem;
}

.logo { text-align: center; }
.logo-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.logo h1  { font-size: 2.5rem; font-weight: 800; color: var(--accent); }
.logo p   { color: var(--text2); margin-top: 0.35rem; font-size: 1rem; }

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 400px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1.4rem 1.6rem;
  border-radius: 18px;
  text-decoration: none;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}
.mode-card:active { transform: scale(0.97); }
.mode-card.cam  { background: linear-gradient(135deg, var(--accent2), #023e8a); border-color: rgba(0,180,216,0.3); }
.mode-card.view { background: linear-gradient(135deg, #4c1d95, var(--purple)); border-color: rgba(124,58,237,0.3); }

.mode-icon  { font-size: 2.2rem; flex-shrink: 0; }
.mode-title { display: block; font-size: 1.15rem; font-weight: 700; color: #fff; }
.mode-desc  { display: block; font-size: 0.82rem; color: rgba(255,255,255,0.7); margin-top: 0.2rem; }

/* ─── 페이지 공통 레이아웃 ──────────────────────────────────── */
.page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── 상단 헤더 ─────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
  padding-top: calc(env(safe-area-inset-top) + 0.7rem);
}

.header-left  { display: flex; align-items: center; gap: 0.6rem; }
.header-title { font-weight: 700; font-size: 1rem; }
.back-btn     { font-size: 1.2rem; cursor: pointer; opacity: 0.8; padding: 0.2rem; }

.room-code {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 0.3rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}
.room-code-label { font-size: 0.65rem; color: var(--text2); }
.room-code-value { font-size: 1rem; font-weight: 800; letter-spacing: 0.12em; color: var(--accent); font-family: monospace; }
.copy-icon { font-size: 0.85rem; opacity: 0.6; }

/* ─── 비디오 영역 ───────────────────────────────────────────── */
.video-wrap {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform-origin: center;
  transition: filter 0.3s ease;
}

/* 뷰어 - 줌 가능하도록 */
.video-wrap.zoomable video {
  cursor: zoom-in;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text2);
  pointer-events: none;
}
.video-overlay.hidden { display: none; }
.overlay-icon { font-size: 3rem; opacity: 0.4; }
.overlay-text { font-size: 0.9rem; opacity: 0.6; }

/* 야간 모드 필터 */
.night-mode {
  filter: brightness(1.6) saturate(0.2) sepia(0.9) hue-rotate(82deg) contrast(1.1) !important;
}

/* ─── 하단 컨트롤 패널 ──────────────────────────────────────── */
.controls {
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.85rem 1rem;
  padding-bottom: calc(env(safe-area-inset-bottom) + 0.85rem);
  flex-shrink: 0;
  z-index: 10;
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ctrl-row + .ctrl-row { margin-top: 0.6rem; }

/* 줌 슬라이더 영역 */
.zoom-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 0.2rem;
}

.zoom-label {
  font-size: 0.75rem;
  color: var(--text2);
  min-width: 2.8rem;
  text-align: right;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg3);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(0,180,216,0.25);
}

/* ─── 입장 화면(뷰어) ───────────────────────────────────────── */
.join-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 2rem;
}

.join-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.join-title { font-size: 1.3rem; font-weight: 700; text-align: center; }
.join-sub   { font-size: 0.85rem; color: var(--text2); text-align: center; }

.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-label { font-size: 0.8rem; color: var(--text2); font-weight: 600; }

.room-input {
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  outline: none;
  width: 100%;
  font-family: monospace;
  transition: border-color 0.15s;
}
.room-input:focus { border-color: var(--accent); }
.room-input::placeholder { color: var(--text2); opacity: 0.5; font-size: 1rem; letter-spacing: 0.1em; }

.btn-join {
  width: 100%;
  padding: 0.9rem;
  font-size: 1rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent2), var(--purple));
  color: #fff;
  border: none;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s;
}
.btn-join:active { transform: scale(0.97); opacity: 0.9; }

/* ─── 연결 상태 오버레이 ────────────────────────────────────── */
.connecting-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 5;
}
.connecting-overlay.hidden { display: none; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.connecting-text { font-size: 0.9rem; color: var(--text2); }

/* ─── 시청자 수 뱃지 ────────────────────────────────────────── */
.viewer-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
}
.viewer-pill span { font-weight: 700; color: var(--text); }

/* ─── 대화하기 버튼 (push-to-talk) ─────────────────────────── */
.talk-btn {
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 3.5rem; height: 3.5rem;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  touch-action: none;
  flex-shrink: 0;
}
.talk-btn.active {
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(248,81,73,0.3);
  animation: talkPulse 0.6s ease infinite alternate;
}
@keyframes talkPulse {
  from { box-shadow: 0 0 0 4px rgba(248,81,73,0.3); }
  to   { box-shadow: 0 0 0 8px rgba(248,81,73,0.15); }
}
.talk-btn:active { transform: scale(0.92); }

/* ─── 카메라 모드 - 대기 화면 ──────────────────────────────── */
.waiting-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 2rem;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
  pointer-events: none;
}
.waiting-screen.hidden { display: none; }

.share-card {
  background: rgba(13,17,23,0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  pointer-events: all;
}

.share-card h3      { font-size: 1rem; font-weight: 700; margin-bottom: 0.3rem; }
.share-card p       { font-size: 0.8rem; color: var(--text2); margin-bottom: 1.2rem; }
.share-code         { font-size: 2.5rem; font-weight: 900; letter-spacing: 0.25em; color: var(--accent); font-family: monospace; }
.share-code-wrap    { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem; margin-bottom: 1rem; }
.share-url          { font-size: 0.7rem; color: var(--text2); word-break: break-all; margin-bottom: 1rem; }
.share-actions      { display: flex; gap: 0.6rem; }
.share-actions .btn { flex: 1; font-size: 0.8rem; }

/* ─── 로그인/회원가입 ────────────────────────────────────────── */
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 0.75rem;
  color: var(--text2);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.auth-input {
  width: 100%;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text2); opacity: 0.6; }

.auth-error {
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 0.6rem;
  min-height: 1.1rem;
  font-weight: 500;
}

/* 절전 모드 블랙 오버레이 */
.power-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.power-overlay.hidden { display: none; }

.power-wake-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
  transition: opacity 0.8s ease;
  user-select: none;
  -webkit-user-select: none;
}

/* 로그아웃 버튼 */
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.7rem;
  color: var(--text2);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

/* ─── 로그인 - 인풋 힌트 & 상태 ──────────────────────────── */
.req { color: var(--red); font-size: 0.75rem; }

.input-hint {
  font-size: 0.75rem;
  margin-top: 0.3rem;
  min-height: 1rem;
}
.input-hint.ok  { color: var(--green); }
.input-hint.err { color: var(--red); }

.auth-input.input-ok  { border-color: var(--green); }
.auth-input.input-err { border-color: var(--red); }

/* 성공 메시지 */
.auth-success {
  color: var(--green);
  font-size: 0.82rem;
  margin-top: 0.6rem;
  min-height: 1.1rem;
  font-weight: 500;
}

/* 비밀번호 입력 래퍼 (눈 아이콘 포함) */
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap .auth-input { padding-right: 2.8rem; }
.pw-eye {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text2);
  padding: 0.25rem;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── 비밀번호 강도 바 ──────────────────────────────────── */
.pw-strength {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.pw-strength-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--bg3);
  overflow: hidden;
}
.pw-strength-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.35s ease, background 0.35s ease;
  width: 0;
}
.pw-strength-text {
  font-size: 0.75rem;
  font-weight: 600;
}

/* ─── 유저 칩 (메인 페이지) ──────────────────────────────── */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3rem 0.75rem 0.3rem 0.4rem;
  text-decoration: none;
  color: var(--text2);
  font-size: 0.85rem;
  transition: border-color 0.15s;
}
.user-chip:hover { border-color: var(--accent); }
.user-chip-avatar {
  width: 1.8rem; height: 1.8rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* ─── 계정 설정 페이지 ──────────────────────────────────── */
.acct-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
}

.acct-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.acct-avatar {
  width: 5rem; height: 5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: #fff;
  margin: 0 auto;
  border: 3px solid var(--border);
}

.acct-nickname {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}
.acct-username {
  font-size: 0.85rem;
  color: var(--text2);
  margin-top: 0.2rem;
}
.acct-email {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 0.2rem;
}

/* ─── 앱 설치 버튼 ──────────────────────────────────────── */
.btn-install {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--green), #2ea043);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0.85rem 1.6rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(63, 185, 80, 0.3);
  transition: transform 0.12s, box-shadow 0.15s;
  animation: installPulse 2s ease-in-out infinite;
}
.btn-install:active { transform: scale(0.96); }
@keyframes installPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(63, 185, 80, 0.3); }
  50%       { box-shadow: 0 4px 24px rgba(63, 185, 80, 0.55); }
}

/* ─── 반응형 ────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .mode-grid    { flex-direction: row; max-width: 600px; }
  .mode-card    { flex: 1; flex-direction: column; text-align: center; }
  .ctrl-row     { flex-wrap: nowrap; }
}
