:root {
  --bg-primary: #0a0c10;
  --bg-card: rgba(22, 27, 34, 0.85);
  --border-color: rgba(255, 255, 255, 0.1);
  --accent-cyan: #00f2fe;
  --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --danger-color: #ff4b4b;
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* Top Navigation */
.top-nav {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: rgba(10, 12, 16, 0.9);
  backdrop-filter: blur(10px);
  z-index: 10;
  flex-shrink: 0;
}

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

.logo-dot {
  width: 10px;
  height: 10px;
  background: var(--accent-cyan);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-cyan);
}

.logo-text {
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 1.1rem;
}

.security-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 242, 254, 0.1);
  border: 1px solid rgba(0, 242, 254, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--accent-cyan);
}

/* Screens */
.screen {
  display: none;
  flex: 1;
  position: relative;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* Lobby */
#lobbyScreen {
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow-y: auto;
}

.lobby-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 28px 20px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.lobby-card h1 {
  font-size: 1.7rem;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
  margin-bottom: 20px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input[type="text"] {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
  padding: 13px 16px;
  border-radius: 10px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  text-align: center;
}

input[type="text"]:focus {
  border-color: var(--accent-cyan);
}

#roomInput {
  letter-spacing: 2px;
  text-transform: uppercase;
}

.btn {
  padding: 13px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #000;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid var(--border-color);
  width: 100%;
}

.divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}

.divider span {
  padding: 0 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.privacy-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}

.feature-tag {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
}

/* Call Screen */
#callScreen {
  flex-direction: column;
}

.call-header {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0,0,0,0.4);
  z-index: 5;
  flex-shrink: 0;
}

.room-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
}

.room-pill strong {
  color: var(--accent-cyan);
  letter-spacing: 1px;
}

.room-pill button {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: 1rem;
}

.chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: var(--accent-cyan);
  border-radius: 50%;
}

.chat-badge.hidden {
  display: none;
}

/* Dynamic Video Grid */
.video-grid {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  overflow: hidden;
}

.video-wrapper {
  position: relative;
  background: #111;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

.video-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #fff;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Solo layout */
.video-grid.alone .remote-wrapper {
  display: none;
}

.video-grid.alone .local-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
  border: none;
  border-radius: 0;
}

/* Peer connected: PIP layout */
.video-grid.connected .remote-wrapper {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
}

.video-grid.connected .local-wrapper {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 110px;
  height: 155px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  z-index: 10;
}

.local-wrapper video {
  object-fit: cover;
}

/* Mirror self-camera only (when not sharing screen) */
.local-wrapper video.mirror {
  transform: scaleX(-1);
}

/* Bottom Controls with Mobile Safe-Area padding */
.controls-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  background: rgba(10, 12, 16, 0.95);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 15;
}

.control-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  font-size: 1.15rem;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.control-btn.active-off {
  background: rgba(255, 75, 75, 0.2);
  border-color: var(--danger-color);
}

.btn-danger {
  background: var(--danger-color);
}

/* Ephemeral Chat Drawer */
.chat-drawer {
  position: absolute;
  top: 52px;
  right: -100%;
  width: 100%;
  max-width: 340px;
  bottom: 0;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 25;
}

.chat-drawer.open {
  right: 0;
}

.chat-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.tag-ephemeral {
  font-size: 0.65rem;
  color: var(--accent-cyan);
}

.btn-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.system-message {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px;
  border-radius: 8px;
  line-height: 1.4;
}

.msg {
  max-width: 80%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  word-break: break-word;
}

.msg.sent {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: #000;
  border-bottom-right-radius: 2px;
}

.msg.received {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-bottom-left-radius: 2px;
}

.chat-input-bar {
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border-color);
}

.chat-input-bar input {
  flex: 1;
  padding: 10px;
  font-size: 0.85rem;
  text-align: left;
}

.btn-send {
  background: var(--accent-cyan);
  border: none;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: bold;
}

/* Avatar placeholder when camera is off */
.avatar-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  border: 3px solid rgba(0, 242, 254, 0.4);
  box-shadow: 0 0 25px rgba(0, 242, 254, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  background-size: cover;
  background-position: center;
  transition: all 0.3s ease;
}

.avatar-circle.hidden {
  display: none !important;
}

.avatar-initial {
  font-size: 2.8rem;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  user-select: none;
}

/* Picture-in-picture avatar */
.local-wrapper .avatar-circle {
  width: 60px;
  height: 60px;
}

.local-wrapper .avatar-initial {
  font-size: 1.6rem;
}