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

:root {
  --bg:        #0d0f1a;
  --surface:   #161826;
  --surface2:  #1f2235;
  --border:    rgba(255,255,255,.08);
  --accent:    #4f6ef7;
  --accent2:   #9b59f5;
  --red:       #e94560;
  --green:     #22c997;
  --yellow:    #f0c040;
  --text:      #e8eaf6;
  --muted:     #7b84a3;
  --radius:    12px;
  --ctrl-size: 68px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

/* ─── Join Screen ─────────────────────────────────────── */
#join-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #1a1f40, var(--bg));
}

.join-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  width: min(440px, 96vw);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: 0 32px 80px rgba(0,0,0,.6);
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin-top: -.75rem;
  font-size: .9rem;
}

.preview-wrap {
  position: relative;
  border-radius: 32px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16/9;
}

.preview-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.cam-off-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9rem;
  background: #000;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

input[type="text"] {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: .75rem 1rem;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--muted); }

.join-controls {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.icon-btn {
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  padding: .65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn.off { background: rgba(233,69,96,.2); border-color: rgba(233,69,96,.4); color: var(--red); }

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: .75rem 1.5rem;
  transition: opacity .2s, transform .1s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:active { transform: scale(.97); }

/* ─── Conference Screen ───────────────────────────────── */
.conf-header {
  background: rgba(0,0,0,.35);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .65rem 1.25rem;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.participant-count {
  color: var(--muted);
  font-size: .85rem;
  margin-left: auto;
}

/* Status pill */
.status {
  font-size: .75rem;
  font-weight: 600;
  padding: .2rem .7rem;
  border-radius: 999px;
}
.status.connecting  { background: rgba(240,192,64,.15); color: var(--yellow); }
.status.connected   { background: rgba(34,201,151,.15); color: var(--green); }
.status.disconnected,
.status.error       { background: rgba(233,69,96,.15);  color: var(--red); }

/* ─── Stage ───────────────────────────────────────────── */
.stage-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
}

.stage {
  position: relative;
  width: 600px;
  height: 400px;
  border-radius: 24px;
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
}

/* All tiles are freely positioned on the stage */
.video-tile {
  position: absolute;
  width: 160px;
  height: 120px;
  border-radius: 32px;
  overflow: hidden;
  background: #000;
  border: 2px solid rgba(255,255,255,.12);
  user-select: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.video-tile.local {
  border-color: rgba(79,110,247,.6);
  cursor: grab;
}
.video-tile.local:active { cursor: grabbing; }
.video-tile video { display: none; }   /* hidden source; canvas renders frames */
.video-tile canvas { width: 100%; height: 100%; display: block; }

.tile-name {
  position: absolute;
  bottom: .5rem;
  left: .5rem;
  background: rgba(0,0,0,.65);
  border-radius: 6px;
  font-size: .78rem;
  padding: .2rem .55rem;
  pointer-events: none;
  backdrop-filter: blur(3px);
}

.tile-muted {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: rgba(233,69,96,.8);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  display: none;
  align-items: center;
  justify-content: center;
}
.tile-muted svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }

/* cam-off placeholder — always a flex circle, toggled via visibility */
.tile-avatar {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  visibility: hidden;
  z-index: 1;
}

/* ─── Controls ────────────────────────────────────────── */
.controls {
  background: rgba(0,0,0,.5);
  border-top: 1px solid var(--border);
  display: flex;
  gap: .5rem;
  justify-content: center;
  padding: .75rem 1rem;
  flex-shrink: 0;
  backdrop-filter: blur(6px);
}

.ctrl-btn {
  align-items: center;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: var(--ctrl-size);
  padding: .6rem .8rem;
  transition: background .2s, border-color .2s, color .2s;
}
.ctrl-btn:hover { background: rgba(255,255,255,.12); }
.ctrl-btn.off {
  background: rgba(233,69,96,.15);
  border-color: rgba(233,69,96,.4);
  color: var(--red);
}
.ctrl-btn.on {
  background: rgba(79,110,247,.18);
  border-color: rgba(79,110,247,.4);
  color: #a0b4ff;
}
.ctrl-btn.danger { background: rgba(233,69,96,.15); border-color: rgba(233,69,96,.3); }
.ctrl-btn.danger:hover { background: var(--red); color: #fff; }

.ctrl-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctrl-label { font-size: .68rem; color: var(--muted); white-space: nowrap; }

/* ─── Pagination ──────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: .4rem 1rem;
  background: rgba(0,0,0,.3);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.page-btn {
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .35rem .6rem;
  transition: background .2s;
}
.page-btn:hover:not(:disabled) { background: rgba(255,255,255,.14); }
.page-btn:disabled { opacity: .3; cursor: default; }
.page-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

.page-info { font-size: .85rem; color: var(--muted); min-width: 90px; text-align: center; }

/* ─── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem 1.2rem;
  font-size: .85rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 100;
}
.toast.visible { opacity: 1; }
