:root{
  --bg:#f4f7fb;
  --card:#ffffff;
  --txt:#0f172a;
  --muted:#64748b;
  --blue:#2f80ed;
  --blue2:#1e63c6;
  --line:#e6edf5;
  --good:#16a34a;
  --warn:#ea580c;
  --bad:#dc2626;
  --radius:14px;
  --shadow:0 8px 24px rgba(15,23,42,.08);
  --sidebar:300px;
  --camSize:220px;
}

/* THEMES */
body.theme-ocean { --bg:#eef6ff; --blue:#0ea5e9; --blue2:#0369a1; }
body.theme-candy { --bg:#fff3fb; --blue:#ec4899; --blue2:#be185d; }
body.theme-ninja { --bg:#0b1220; --card:#0f172a; --txt:#e2e8f0; --muted:#94a3b8; --line:#1f2a44; --blue:#22c55e; --blue2:#16a34a; }
body.theme-sunset { --bg:#fff5f0; --blue:#ff6b35; --blue2:#e85d31; }
body.theme-forest { --bg:#f0f7f4; --blue:#10b981; --blue2:#059669; }
body.theme-royal { --bg:#f5f3ff; --blue:#7c3aed; --blue2:#6d28d9; }
body.theme-cyber { --bg:#0a0e1a; --card:#131825; --txt:#e0e7ff; --blue:#00fff9; --blue2:#00cccd; --line:#1e2436; }
body.theme-sakura { --bg:#fff0f6; --blue:#ff6b9d; --blue2:#e85d8a; }
body.theme-matrix { --bg:#000000; --card:#0d1117; --txt:#00ff41; --muted:#00cc33; --blue:#00ff41; --blue2:#00cc33; --line:#1a3a1a; }
body.theme-desert { --bg:#fef6e4; --blue:#f77f00; --blue2:#dc6e00; }
body.theme-arctic { --bg:#f0f9ff; --blue:#38bdf8; --blue2:#0ea5e9; }
body.theme-lavender { --bg:#faf5ff; --blue:#a855f7; --blue2:#9333ea; }
body.theme-midnight { --bg:#1e1b4b; --card:#312e81; --txt:#fef3c7; --muted:#fde68a; --blue:#fbbf24; --blue2:#f59e0b; --line:#4338ca; }
body.theme-mint { --bg:#f0fdf4; --blue:#34d399; --blue2:#10b981; }
body.theme-volcano { --bg:#1a0a0a; --card:#2d1515; --txt:#fecaca; --muted:#fca5a5; --blue:#ef4444; --blue2:#dc2626; --line:#3d1f1f; }

*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--txt);
}
a{color:inherit;text-decoration:none}
button{cursor:pointer;font-family:inherit}

.topbar{
  height:64px;
  background: linear-gradient(90deg,var(--blue),var(--blue2));
  color:white;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 16px;
  box-shadow:var(--shadow);
  position:sticky;top:0;z-index:10;
}
.topbar .logo{font-weight:800;font-size:22px;letter-spacing:.3px}
.topbar .right{display:flex;gap:8px;align-items:center}
.topbar .pill{
  background:rgba(255,255,255,.16);
  border:1px solid rgba(255,255,255,.25);
  padding:6px 10px;border-radius:999px;font-size:13px
}

.layout{
  display:grid;
  grid-template-columns: var(--sidebar) 1fr;
  gap:12px;
  padding:12px;
  height: calc(100% - 64px);
}

.sidebar{
  background:var(--card);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:10px;
  display:flex;flex-direction:column;
  min-height:0;
}
.search{
  display:flex;gap:6px;align-items:center;
  padding:8px;border:1px solid var(--line);
  border-radius:10px;background:#f8fafc;
}
.search input{
  border:none;outline:none;background:transparent;flex:1;font-size:14px;
  color:var(--txt);
}
.rooms{
  margin-top:8px;overflow:auto;min-height:0;padding-right:4px;
  display:flex;flex-direction:column;gap:6px;
}
.room{
  display:flex;align-items:center;justify-content:space-between;
  padding:10px;border:1px solid var(--line);
  border-radius:12px;background:#fff;
  transition:.12s transform ease,.12s background ease;
}
.room:hover{transform:translateY(-1px);background:#f8fbff}
.room .meta{display:flex;flex-direction:column}
.room .name{font-weight:700;color:var(--txt)}
.room .slug{font-size:12px;color:var(--muted)}
.room .count{
  font-size:12px;background:#eef2ff;color:#3730a3;
  padding:3px 8px;border-radius:999px;font-weight:700;
}

.sidebar .actions{
  margin-top:auto;display:flex;flex-direction:column;gap:8px;padding-top:8px;
}
.btn{
  border:none;
  border-radius:20px;
  padding:8px 16px;
  font-weight:600;
  font-size:13px;
  background:linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color:white;
  box-shadow:0 2px 8px rgba(102,126,234,0.3);
  transition: all 0.2s ease;
}
.btn:hover{
  transform: translateY(-2px);
  box-shadow:0 4px 12px rgba(102,126,234,0.4);
}
.btn:active{
  transform: translateY(0);
}
.btn.outline{
  background:#fff;color:var(--txt);border:1px solid var(--line);box-shadow:none;
}
.btn.small{padding:6px 8px;font-size:13px;border-radius:9px}
.btn.ghost{background:transparent;border:1px dashed var(--line);color:var(--muted);box-shadow:none}

.main{
  min-height:0;display:flex;flex-direction:column;gap:12px;
}

.card{
  background:var(--card);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:12px;
}

.hero{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
}
.hero .title{font-size:22px;font-weight:800;color:var(--txt)}
.hero .subtitle{font-size:13px;color:var(--muted)}
.hero .right{display:flex;gap:8px;flex-wrap:wrap}

.inline{
  display:flex;gap:6px;flex-wrap:wrap;
}
.inline input{
  border:1px solid var(--line);outline:none;border-radius:10px;
  padding:10px 12px;font-size:14px;background:#f8fafc;min-width:180px;
  color:var(--txt);
}

.room-layout{
  display:grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "users cams"
    "users chat"
    "users input";
  gap:10px;
  height:100%;
  min-height:0;
}
.users-card{grid-area:users;display:flex;flex-direction:column;min-height:0;}
.users-list{overflow:auto;min-height:0;display:flex;flex-direction:column;gap:6px;padding-right:4px}
.user{
  display:flex;align-items:center;gap:8px;padding:8px;border:1px solid var(--line);
  border-radius:10px;background:var(--card);
}
.user .avatar{
  width:34px;height:34px;border-radius:50%;
  background:#e2e8f0;display:grid;place-items:center;font-weight:800;color:#334155;
}
.user .pseudo{font-weight:700;color:var(--txt)}
.user .role{font-size:11px;color:var(--muted);margin-left:auto}

.cams-card{grid-area:cams;}
.cams-grid{
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  z-index: 1000;
  pointer-events: none;
}
.cam{
  background:#000;
  border-radius:16px;
  position:fixed;
  overflow:hidden;
  width: 240px;
  height: 150px;
  display:grid;
  place-items:center;
  color:#fff;
  font-weight:800;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  border: 3px solid rgba(255,255,255,0.2);
  pointer-events: auto;
  cursor: move;
  transition: all 0.3s ease;
  z-index: 9999;
}
.cam:hover{
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  transform: scale(1.05);
}
.cam .label{
  position:absolute;
  left:8px;
  top:8px;
  background:rgba(0,0,0,0.8);
  padding:6px 10px;
  border-radius:8px;
  font-size:12px;
  font-weight:600;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
}

.chat-card{grid-area:chat;display:flex;flex-direction:column;min-height:0;}
.messages{
  flex:1;overflow:auto;display:flex;flex-direction:column;gap:2px;padding-right:4px;
}
.msg{
  display:flex;gap:8px;align-items:flex-start;width:100%;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg .bubble{
  background:#f1f5f9;
  border:1px solid var(--line);
  padding:4px 10px;
  border-radius:8px;
  width:100%;
  white-space:pre-wrap;
  word-break:break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
  display:flex;
  align-items:baseline;
  gap:6px;
  flex-wrap:wrap;
}
.msg .bubble:hover{
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}
.msg.me .bubble{
  background:#f1f5f9;
  border-color:var(--line);
}
.msg .who{
  font-weight:600;
  font-size:11px;
  color:var(--txt);
  letter-spacing:0.1px;
}
.msg .time{
  font-size:9px;
  color:var(--muted);
  font-weight:400;
  opacity:0.5;
  margin-left:auto;
  white-space:nowrap;
}
.msg .msg-content{
  font-size:12px;
  color:var(--txt);
  line-height:1.25;
  flex:1;
  min-width:0;
}
.msg .text{font-size:14px;color:var(--txt);flex:1;min-width:0}

/* Messages système discrets */
.msg.system{
  min-height:auto;
  opacity:0.6;
}
.msg.system .bubble{
  background:transparent;
  border:none;
  padding:2px 0;
  font-size:11px;
  color:var(--muted);
  font-style:italic;
}
.msg.system .who{
  display:none;
}

.input-card{grid-area:input}
.input-row{
  display:flex;gap:6px;align-items:center;
}
.input-row textarea{
  flex:1;
  min-height:36px;
  max-height:80px;
  resize:vertical;
  border:2px solid var(--line);
  outline:none;
  border-radius:20px;
  padding:8px 16px;
  font-size:13px;
  background:#fff;
  color:var(--txt);
  transition: all 0.2s ease;
}
.input-row textarea:focus{
  border-color:#667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}
.toolbar{
  display:flex;gap:4px;flex-wrap:wrap;margin-bottom:4px;
}
.tool{
  font-size:11px;
  border:1px solid var(--line);
  background:#fff;
  border-radius:6px;
  padding:3px 6px;
  color:var(--txt);
  cursor:pointer;
  transition: all 0.15s ease;
}
.tool:hover{
  background:var(--line);
  transform: translateY(-1px);
}
.tool.color{font-weight:900}
.tool[data-color="red"]{color:#dc2626}
.tool[data-color="blue"]{color:#2563eb}
.tool[data-color="green"]{color:#16a34a}
.tool[data-color="pink"]{color:#db2777}

.modal{
  position:fixed;inset:0;background:rgba(2,6,23,.5);display:none;place-items:center;z-index:50;
}
.modal.open{display:grid}
.modal .box{
  width:min(480px,92vw);background:var(--card);border-radius:16px;box-shadow:var(--shadow);
  padding:14px;
}
.modal h3{margin:0 0 8px 0;color:var(--txt)}
.modal .row{display:flex;flex-direction:column;gap:6px;margin:8px 0}
.modal input{
  border:1px solid var(--line);outline:none;border-radius:10px;padding:10px 12px;font-size:14px;background:#fff;
  color:var(--txt);
}
.modal .tabs{display:flex;gap:6px;margin-bottom:8px}
.modal .tab{flex:1;text-align:center;padding:8px;border-radius:10px;border:1px solid var(--line);font-weight:800;background:#fff;color:var(--txt)}
.modal .tab.active{background:#eef2ff;border-color:#c7d2fe;color:#3730a3}
.modal .hint{font-size:12px;color:var(--muted)}
.modal .actions{display:flex;gap:8px;justify-content:flex-end;margin-top:8px}

.theme-panel{
  display:flex;gap:8px;flex-wrap:wrap;align-items:center;
  max-height:300px;overflow-y:auto;
}
.theme-chip{
  padding:6px 10px;border-radius:999px;border:1px solid var(--line);background:#fff;font-weight:800;font-size:11px;
  color:var(--txt);display:flex;align-items:center;gap:4px;
}
.theme-chip.active{background:#e0f2fe;border-color:#7dd3fc}
.theme-chip .dot{width:8px;height:8px;border-radius:50%;display:inline-block}
.theme-panel input{
  border:1px solid var(--line);outline:none;border-radius:10px;padding:8px 10px;font-size:13px;background:#fff;min-width:220px;
  color:var(--txt);
}

@media (max-width: 1000px){
  .layout{grid-template-columns: 1fr; height:auto;}
  .sidebar{order:2}
  .room-layout{
    grid-template-columns: 1fr;
    grid-template-areas:
      "players"
      "chat"
      "input"
      "users";
    height:auto;
  }
}

/* Webcam Module Styles */
.webcam-control-btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.webcam-control-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.webcam-control-btn.active {
  background: rgba(34, 197, 94, 0.9);
}

.webcam-control-btn.active:hover {
  background: rgba(34, 197, 94, 1);
}

#webcam-cameras::-webkit-scrollbar {
  width: 8px;
}

#webcam-cameras::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
}

#webcam-cameras::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
}

#webcam-cameras::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.3);
}
