* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1c1c1c;
  --border: #1f1f1f;
  --text: #e8e8e8;
  --text2: #777;
  --text3: #444;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

.app { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ===== Join ===== */
.screen.join {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

.join-card { width: 100%; max-width: 340px; }

.join-logo { width: 44px; height: 44px; margin-bottom: 20px; color: var(--accent); }
.join-logo svg { width: 100%; height: 100%; }

.join-card h1 { font-size: 24px; font-weight: 700; color: #fff; margin-bottom: 4px; letter-spacing: -0.3px; }
.join-card p { font-size: 14px; color: var(--text3); margin-bottom: 28px; }

.input-group { margin-bottom: 14px; }
.input-group label { display: block; font-size: 11px; font-weight: 600; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.input-group input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 16px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s; -webkit-appearance: none;
}
.input-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.08); }
.input-group input::placeholder { color: var(--text3); }

.join-btn {
  width: 100%; padding: 13px 16px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 10px; display: flex; align-items: center;
  justify-content: center; gap: 8px; transition: opacity 0.15s, transform 0.1s;
}
.join-btn:active { transform: scale(0.97); }
.join-btn:disabled { opacity: 0.5; pointer-events: none; }

/* ===== Chat ===== */
.screen.chat { flex: 1; display: flex; flex-direction: column; height: 100%; position: relative; }

.chat-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--bg); z-index: 5;
}

.room-info { display: flex; align-items: center; gap: 10px; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); position: relative; }
.pulse-dot::after { content: ''; position: absolute; inset: -3px; border-radius: 50%; background: var(--green); opacity: 0; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(0.8); opacity: 0; } 50% { transform: scale(1.3); opacity: 0.35; } }
.room-label { font-size: 15px; font-weight: 600; color: #fff; }
.user-count { font-size: 13px; color: var(--text3); }

.leave-btn {
  display: flex; align-items: center; gap: 5px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 7px; background: transparent;
  color: var(--text2); font-size: 13px; cursor: pointer; transition: all 0.15s;
}
.leave-btn:active { border-color: var(--red); color: var(--red); background: rgba(239,68,68,0.05); }

/* ===== Media Area (Video / Screen) ===== */
.media-area {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 4px;
  padding: 4px;
  max-height: 45vh;
  overflow-y: auto;
  background: #000;
  border-bottom: 1px solid var(--border);
}

.video-tile {
  position: relative;
  background: #111;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16/9;
  min-height: 120px;
}

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

.video-label {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  background: rgba(0,0,0,0.6);
  padding: 3px 8px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

.video-fullscreen {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  backdrop-filter: blur(4px);
}

.video-tile:hover .video-fullscreen { opacity: 1; }
@media (hover: none) { .video-fullscreen { opacity: 1; } }

/* ===== Users ===== */
.users-area {
  flex: 1; overflow-y: auto; padding: 6px 10px; -webkit-overflow-scrolling: touch; min-height: 0;
}

.user-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border-radius: var(--radius); margin-bottom: 2px; transition: background 0.1s;
}

.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface2);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  border: 2px solid transparent; transition: border-color 0.2s, box-shadow 0.25s;
}
.user-avatar span { font-size: 12px; font-weight: 700; color: var(--accent); }

.user-item.speaking .user-avatar { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,0.12); }
.user-item.speaking .user-avatar span { color: var(--green); }
.user-item.muted-user .user-avatar { opacity: 0.4; }
.user-item.muted-user .user-avatar span { color: var(--text3); }

.user-details { flex: 1; min-width: 0; }
.user-details .name { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-details .tag { font-size: 12px; color: var(--text3); margin-top: 1px; transition: color 0.2s; }
.user-item.speaking .tag { color: var(--green); }

/* ===== Controls ===== */
.controls-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 16px; padding-bottom: max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; z-index: 5;
}

.ctrl-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--surface2); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s; -webkit-appearance: none;
}
.ctrl-btn:active { transform: scale(0.9); }
.ctrl-btn .ctrl-icon { width: 20px; height: 20px; }
.ctrl-btn.active { background: var(--red); color: #fff; }
.ctrl-btn#denoise-btn.active { background: var(--green); color: #fff; }
.ctrl-btn#share-btn.active { background: var(--accent); color: #fff; }
.ctrl-btn#camera-btn.active { background: var(--accent); color: #fff; }

/* ===== Status ===== */
.status-text { text-align: center; font-size: 12px; color: var(--text3); padding: 2px 16px; min-height: 18px; }

/* ===== Toasts ===== */
.toast-container {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 1000; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  padding: 7px 14px; border-radius: 16px; font-size: 12px; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text2);
  opacity: 0; transform: translateY(-8px) scale(0.95);
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1); pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-error { border-color: rgba(239,68,68,0.3); color: var(--red); }

/* ===== Responsive ===== */
@media (max-width: 380px) {
  .controls-bar { gap: 8px; }
  .ctrl-btn { width: 44px; height: 44px; }
  .ctrl-btn .ctrl-icon { width: 18px; height: 18px; }
  .media-area { grid-template-columns: 1fr; }
}

@media (max-height: 500px) {
  .media-area { max-height: 35vh; }
  .users-area { padding: 2px 6px; }
  .user-item { padding: 5px 8px; }
  .user-avatar { width: 30px; height: 30px; }
  .controls-bar { padding: 8px; }
  .ctrl-btn { width: 40px; height: 40px; }
}

@media (hover: hover) {
  .leave-btn:hover { border-color: var(--red); color: var(--red); }
  .ctrl-btn:hover { background: #252525; }
  .ctrl-btn.active:hover { opacity: 0.9; }
  .user-item:hover { background: var(--surface); }
}

/* Single video fullscreen-like: when only one tile */
.media-area:has(.video-tile:only-child) {
  max-height: 55vh;
}
.media-area:has(.video-tile:only-child) .video-tile {
  aspect-ratio: auto;
  height: 100%;
}
