/* ═══════════════════════════════════════════════════════════
   CALLER — Dark theme, responsive, touch-ready
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #238636;
  --accent-h:    #2ea043;
  --danger:      #da3633;
  --danger-h:    #f85149;
  --warn:        #d29922;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 8px 32px rgba(0,0,0,.5);
  --transition:  .2s ease;
  --vad-glow:    0 0 0 3px #2ea043, 0 0 16px #2ea04388;
}

*, *::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', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ── Screens ──────────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform .1s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-primary:hover { background: var(--accent-h); }

.btn-ghost     { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger-ghost:hover { background: var(--danger); color: #fff; }

/* ── Fields ───────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.field input {
  height: 44px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #23863633;
}

/* ── Error message ────────────────────────────────────────── */
.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  background: #da363322;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger-h);
  font-size: 14px;
  text-align: center;
}
.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════
   LOBBY
   ════════════════════════════════════════════════════════════ */
.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -.5px;
}
.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 4px 0 24px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tab-panel .btn-primary { width: 100%; margin-top: 4px; }

/* ════════════════════════════════════════════════════════════
   WAITING
   ════════════════════════════════════════════════════════════ */
.waiting-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.waiting-card h2 { font-size: 20px; font-weight: 500; color: var(--text); }

/* Dots animation */
.waiting-anim {
  display: flex;
  gap: 8px;
  align-items: center;
}
.waiting-anim span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.waiting-anim span:nth-child(1) { animation-delay: 0s; }
.waiting-anim span:nth-child(2) { animation-delay: .2s; }
.waiting-anim span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40%           { transform: scale(1);  opacity: 1; }
}

.room-info {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.room-info p { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.room-info code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  text-align: center;
}

/* ════════════════════════════════════════════════════════════
   CALL SCREEN
   ════════════════════════════════════════════════════════════ */
#screen-call {
  flex-direction: column;
  background: #000;
  align-items: stretch;
  justify-content: stretch;
}

.videos {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Remote video: full screen */
#video-remote-wrap {
  position: absolute;
  inset: 0;
}
#video-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}

/* Self video: PiP corner */
#video-self-wrap {
  position: absolute;
  bottom: 80px;
  right: 16px;
  width: 120px;
  height: 90px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
  cursor: grab;
  transition: box-shadow var(--transition);
}
#video-self-wrap.vad-active { box-shadow: var(--vad-glow); border-color: var(--accent); }
#video-remote-wrap.vad-active { box-shadow: var(--vad-glow); }

#video-self {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #222;
}

/* Name labels */
.peer-name {
  position: absolute;
  bottom: 8px;
  left: 10px;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  pointer-events: none;
}
#video-self-wrap .peer-name { font-size: 11px; bottom: 4px; left: 6px; }

/* Connection status badge */
.conn-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(0,0,0,.6);
  color: var(--text-muted);
  backdrop-filter: blur(4px);
  transition: opacity .3s;
}
.conn-status.connected   { color: var(--accent);  }
.conn-status.reconnecting{ color: var(--warn);    }
.conn-status.disconnected{ color: var(--danger);  }

/* Call controls bar */
.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(255,255,255,.15);
  color: #fff;
  transition: background var(--transition), transform .1s, box-shadow var(--transition);
  backdrop-filter: blur(6px);
  flex-shrink: 0;
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn:active { transform: scale(.93); }
.ctrl-btn:hover  { background: rgba(255,255,255,.25); }

.ctrl-btn.off    { background: var(--surface-2); color: var(--text-muted); }
.ctrl-btn.hangup { background: var(--danger); width: 64px; height: 64px; }
.ctrl-btn.hangup:hover { background: var(--danger-h); }
.ctrl-btn.active-share { background: var(--accent); }

/* Hide screen share on mobile */
@media (max-width: 600px) {
  #btn-screenshare { display: none; }
  #video-self-wrap { width: 90px; height: 68px; }
}

/* ════════════════════════════════════════════════════════════
   ENDED SCREEN
   ════════════════════════════════════════════════════════════ */
.ended-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.ended-icon { font-size: 56px; }
.ended-card h2 { font-size: 22px; font-weight: 600; }
.ended-card p  { color: var(--text-muted); font-size: 15px; }

/* ════════════════════════════════════════════════════════════
   RECONNECT OVERLAY
   ════════════════════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.overlay-card p { color: var(--text-muted); font-size: 15px; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE: mobile 320–428px
   ════════════════════════════════════════════════════════════ */
@media (max-width: 440px) {
  .lobby-card { padding: 24px 18px; border-radius: 0; border-left: none; border-right: none; max-width: 100%; }
  .screen { align-items: flex-start; }
  #screen-lobby { align-items: center; }
}

/* ── Drag PiP animation ───────────────────────────────────── */
#video-self-wrap.dragging { cursor: grabbing; transition: none; }

/* ── Entry animation ──────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lobby-card, .waiting-card, .ended-card {
  animation: fadeUp .35s ease both;
}
