:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --tile: #242833;
  --accent: #4f8cff;
  --danger: #e5484d;
  --text: #e7e9ee;
  --muted: #9aa0ad;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* keeps layout correct under mobile browser chrome */
  overflow: hidden; /* the stage scrolls internally; toolbar stays pinned */
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

/* --- Join screen --- */
.join {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.join-card {
  background: var(--panel);
  padding: 40px;
  border-radius: 16px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.join-logo { width: 92px; height: 92px; border-radius: 22px; object-fit: cover; margin: 0 0 14px; }
.join-card h1 { margin: 0 0 6px; font-size: 28px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.join-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid #313643;
  background: #0e1014;
  color: var(--text);
  margin-bottom: 14px;
}
.join-card button,
.tool {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 15px;
}
.join-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  font-weight: 600;
}
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* --- Meeting screen --- */
.room {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  min-height: 0;
  overflow-y: auto; /* tiles scroll here; the toolbar below stays put */
}

/* Big presenter view */
.presentation {
  flex: 1;
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
}
.presentation video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.presentation-label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 13px;
}

/* Participant grid */
.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
}
.tile {
  position: relative;
  flex: 1 1 320px;     /* one tile fills the space; many tiles share + wrap */
  min-height: 180px;
  background: var(--tile);
  border-radius: 12px;
  overflow: hidden;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
/* When presenting, tiles collapse into a thin scrolling strip at the bottom. */
.stage.presenting .grid {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
}
.stage.presenting .tile {
  flex: 0 0 180px;
  min-height: 0;
  height: 120px;
}
.tile .name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 12px;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile .badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex: 0 0 auto; /* never shrink or scroll away — always visible */
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  padding: 18px;
  background: var(--panel);
}
.tool {
  padding: 14px 26px;
  font-size: 17px;
  font-weight: 600;
  background: var(--tile);
  color: var(--text);
}
.tool.primary { background: var(--accent); color: white; }
.tool.danger { background: var(--danger); color: white; }
.tool.active { outline: 2px solid var(--accent); }
.tool.off { opacity: 0.55; }

/* Second input on the join card */
.join-card input + input { margin-top: 0; }

/* Header bar */
.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #2a2e38;
}
.header-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; }
.header-logo { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; margin-right: 9px; }
.header-actions { display: flex; gap: 10px; }
.hbtn {
  cursor: pointer;
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  background: var(--tile);
  color: var(--text);
}
.hbtn.active { outline: 2px solid var(--accent); }

/* Side panels (participants + chat) */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(86vw, 320px);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid #2a2e38;
  z-index: 20;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.35);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-weight: 700;
  border-bottom: 1px solid #2a2e38;
}
.panel-close {
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}
.people-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.people-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: 9px;
  font-size: 15px;
}
.people-list li:hover { background: var(--tile); }
.people-list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-list .pstatus { font-size: 14px; opacity: 0.9; letter-spacing: 2px; }
.people-list .ptag { font-size: 11px; color: var(--muted); }

/* Status icons on tiles */
.tile .status {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
  font-size: 13px;
}
.tile .status span {
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  padding: 2px 5px;
}
.room { position: relative; }

/* Avatar shown on a tile when the camera is off */
.tile .avatar {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #1b1e26;
}
.tile.camoff .avatar { display: flex; }
.tile.camoff video { visibility: hidden; }
.tile .avatar span {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 700;
}

/* Connection status */
.conn { font-size: 12px; font-weight: 600; margin-left: 10px; color: var(--muted); }
.conn.ok { color: #3ecf8e; }
.conn.warn { color: #f5a623; }

/* Header button unread badge */
.hbtn { position: relative; }
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* Chat panel */
.chat-list { list-style: none; margin: 0; padding: 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.chat-list li { font-size: 14px; line-height: 1.35; }
.chat-list .who { font-weight: 700; font-size: 12px; color: var(--accent); display: block; }
.chat-list li.mine .who { color: #3ecf8e; }
.chat-list .body { white-space: pre-wrap; word-break: break-word; }
.chat-list .sys { color: var(--muted); font-style: italic; font-size: 12px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #2a2e38; }
.chat-form input {
  flex: 1; padding: 10px 12px; border-radius: 9px;
  border: 1px solid #313643; background: #0e1014; color: var(--text); font-size: 14px;
}
.chat-send { cursor: pointer; border: none; border-radius: 9px; padding: 0 16px; background: var(--accent); color: #fff; font-weight: 600; }

/* Raise-hand badge on tiles + roster */
.tile .hand-badge {
  position: absolute; top: 8px; right: 8px; font-size: 18px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
}

/* Fullscreen button on presentation */
.fs-btn {
  position: absolute; top: 12px; right: 12px;
  cursor: pointer; border: none; border-radius: 8px;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 18px; padding: 6px 10px;
}

/* Toasts */
.toasts {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: rgba(20,23,30,0.95); border: 1px solid #2a2e38; color: var(--text);
  padding: 8px 16px; border-radius: 999px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: toastfade 4s forwards;
}
@keyframes toastfade {
  0% { opacity: 0; transform: translateY(-6px); }
  10%, 80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-6px); }
}
