*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a1a; color: #fff; min-height: 100vh; overflow: hidden;
}
button { cursor: pointer; border: none; font-family: inherit; font-size: 1rem; transition: all 0.15s; }
input { font-family: inherit; font-size: 1rem; border: none; outline: none; }
.hidden { display: none !important; }

/* LOBBY */
#lobby {
  background: #2a2a2a; border-radius: 24px; padding: 2.5rem 2.5rem 2rem;
  text-align: center; max-width: 420px; width: 92%; margin: 5vh auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.lobby-logo { margin-bottom: 0.5rem; }
#lobby h1 {
  font-size: 2.5rem; font-weight: 800;
  background: linear-gradient(135deg, #f97316, #fb923c);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.lobby-sub { color: #aaa; margin: 0.2rem 0 1.2rem; font-size: 0.95rem; }
.lobby-row { display: flex; gap: 0.5rem; margin-bottom: 0.8rem; }
.lobby-row input {
  flex: 1; background: #3a3a3a; color: #fff; padding: 0.85rem 1.2rem;
  border-radius: 12px; width: 100%;
}
.lobby-row input::placeholder { color: #666; }
.btn-primary {
  background: linear-gradient(135deg, #f97316, #fb923c);
  color: #fff; padding: 0.85rem 2rem; border-radius: 12px;
  font-weight: 700; width: 100%; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(249,115,22,0.4); }
.btn-secondary {
  background: #3a3a3a; color: #fff; padding: 0.85rem 1.5rem; border-radius: 12px;
  font-weight: 600; flex-shrink: 0;
}
.btn-secondary:hover { background: #4a4a4a; }
.btn-small {
  background: #374151; color: #fff; padding: 0.4rem 1rem; border-radius: 8px;
  font-size: 0.85rem;
}
.btn-small:hover { background: #4b5563; }
.btn-small.danger { background: #ef4444; }
.btn-small.danger:hover { background: #dc2626; }
.divider {
  display: flex; align-items: center; gap: 1rem; margin: 1rem 0;
  color: #555; font-size: 0.85rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #3a3a3a; }
#roomCode { margin-top: 1.2rem; padding: 1rem; background: #1f2937; border-radius: 12px; border: 1px solid #374151; }
#roomCode p { color: #9ca3af; font-size: 0.82rem; margin-bottom: 0.5rem; }
#roomCode .hint { font-size: 0.75rem; color: #6b7280; margin-top: 0.5rem; margin-bottom: 0; }
.code-display { display: flex; align-items: center; gap: 0.5rem; justify-content: center; }
.code-display span { font-size: 1.3rem; font-weight: 700; letter-spacing: 2px; background: #374151; padding: 0.35rem 1rem; border-radius: 8px; color: #fb923c; }

/* CALL */
#call { position: fixed; inset: 0; background: #111; display: none; flex-direction: column; overflow: hidden; }
#topBar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; gap: 0.8rem;
  padding: 0.5rem 1rem; background: rgba(0,0,0,0.6); font-size: 0.85rem;
}
#roomLabel { color: #fb923c; font-weight: 600; }
#participantCount { background: #374151; padding: 0.15rem 0.6rem; border-radius: 6px; font-size: 0.75rem; }

/* VIDEO GRID */
#videoGrid {
  flex: 1; min-height: 0; display: grid; gap: 2px; padding: 0; background: #111; position: relative;
}
.video-container {
  position: relative; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center; min-height: 0;
}
.video-container video { width: 100%; height: 100%; object-fit: cover; }
.video-container .mirror { transform: scaleX(-1); }
.video-label {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.6); padding: 0.15rem 0.5rem; border-radius: 5px;
  font-size: 0.7rem; color: #fff; pointer-events: none;
  display: flex; align-items: center; gap: 4px;
}
.video-label .hand-icon { font-size: 0.9rem; }
.video-muted-icon {
  position: absolute; top: 6px; left: 6px;
  background: rgba(239,68,68,0.8); padding: 2px 6px; border-radius: 4px;
  font-size: 0.7rem; display: none;
}

/* REACTIONS LAYER */
#reactions-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 15; overflow: hidden;
}
.reaction-fly {
  position: absolute; font-size: 2.5rem; pointer-events: none;
  animation: flyUp 2.5s ease-out forwards;
}
@keyframes flyUp {
  0% { opacity: 1; transform: translateY(0) scale(0.5); }
  50% { opacity: 1; transform: translateY(-30vh) scale(1.2); }
  100% { opacity: 0; transform: translateY(-60vh) scale(0.8); }
}

/* REACTION PICKER */
#reactionPicker {
  position: absolute; bottom: 75px; left: 50%; transform: translateX(-50%); z-index: 25;
  background: #2a2a2a; border-radius: 16px; padding: 0.5rem;
  display: flex; gap: 2px; box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#reactionPicker button {
  background: none; font-size: 1.5rem; padding: 0.3rem; border-radius: 8px;
  line-height: 1;
}
#reactionPicker button:hover { background: #3a3a3a; transform: scale(1.2); }

/* CHAT */
#chatPanel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 320px; z-index: 20;
  background: #1f1f1f; display: flex; flex-direction: column; border-left: 1px solid #333;
}
#chatHeader {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.8rem;
  background: #2a2a2a; font-weight: 600; font-size: 0.9rem;
}
#chatTabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.chat-tab {
  background: #3a3a3a; color: #aaa; padding: 0.2rem 0.6rem; border-radius: 6px;
  font-size: 0.75rem; white-space: nowrap;
}
.chat-tab.active { background: #f97316; color: #fff; }
.chat-tab .unread {
  background: #ef4444; color: #fff; border-radius: 50%; padding: 0 5px;
  margin-left: 4px; font-size: 0.7rem;
}
#chatClose { margin-left: auto; }
#chatMessages {
  flex: 1; overflow-y: auto; padding: 0.5rem 0.8rem; display: flex;
  flex-direction: column; gap: 0.4rem;
}
.chat-msg {
  padding: 0.4rem 0.7rem; border-radius: 10px; max-width: 85%;
  font-size: 0.85rem; line-height: 1.3;
}
.chat-msg.own { background: #f97316; align-self: flex-end; }
.chat-msg.other { background: #333; align-self: flex-start; }
.chat-msg.system { background: transparent; align-self: center; color: #666; font-size: 0.75rem; }
.chat-msg .sender { font-weight: 600; font-size: 0.75rem; color: #fb923c; display: block; }
.chat-msg .time { font-size: 0.65rem; color: #888; text-align: right; display: block; margin-top: 2px; }
.chat-file {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0;
}
.chat-file a { color: #60a5fa; text-decoration: underline; font-size: 0.8rem; }
.chat-file .file-size { color: #888; font-size: 0.7rem; }
#chatInputRow {
  display: flex; gap: 0.5rem; padding: 0.5rem 0.8rem; background: #2a2a2a;
}
#chatInput {
  flex: 1; background: #3a3a3a; color: #fff; padding: 0.6rem 0.8rem;
  border-radius: 10px; font-size: 0.85rem;
}
#chatInput::placeholder { color: #666; }

/* VU METER */
#vuMeter {
  display: flex; align-items: center; gap: 2px; height: 20px;
  margin-right: 2px;
}
.vu-bar {
  width: 3px; height: 100%; border-radius: 1px;
  background: #555; transition: background 0.1s;
}
.vu-bar.low { background: #22c55e; }
.vu-bar.mid { background: #eab308; }
.vu-bar.high { background: #ef4444; }

/* CONTROLS */
#controls {
  display: flex; align-items: center; justify-content: center;
  gap: 0.7rem; padding: 0.7rem 1rem 1rem; flex-shrink: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
}
.ctrl-btn {
  background: #3a3a3a; color: #fff; padding: 0; border-radius: 50%;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ctrl-btn:hover { background: #4a4a4a; }
.ctrl-btn.active { background: #f97316; }
.ctrl-btn.active:hover { background: #ea580c; }
.ctrl-btn.end { background: #ef4444; }
.ctrl-btn.end:hover { background: #dc2626; }
.ctrl-btn.recording { background: #ef4444; animation: pulse 1.5s infinite; }
.ctrl-btn.screen-active { background: #22c55e; }
.ctrl-btn.screen-active:hover { background: #16a34a; }
.ctrl-btn.wb-active { background: #a855f7; }
.ctrl-btn.wb-active:hover { background: #9333ea; }
.ctrl-btn.hand-active { background: #eab308; }
.ctrl-btn.hand-active:hover { background: #ca8a04; }
.ctrl-btn.bg-active { background: #3b82f6; }
.ctrl-btn.bg-active:hover { background: #2563eb; }
.ctrl-btn.hand-active .badge-dot, .ctrl-btn.recording .badge-dot { display: none; }
.badge-dot {
  position: absolute; top: -2px; right: -2px; width: 10px; height: 10px;
  background: #ef4444; border-radius: 50%; border: 2px solid #1a1a1a;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* WHITEBOARD */
#whiteboardOverlay {
  position: absolute; inset: 0; z-index: 30;
  background: #1a1a1a; display: flex; flex-direction: column;
}
#wbCanvas { flex: 1; cursor: crosshair; touch-action: none; }
#wbToolbar {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem; background: #2a2a2a; flex-wrap: wrap;
}
.wb-tools, .wb-colors { display: flex; gap: 4px; }
.wb-btn, .color-btn {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: #3a3a3a; color: #fff;
}
.wb-btn:hover, .color-btn:hover { background: #4a4a4a; }
.wb-btn.active, .color-btn.active { outline: 2px solid #fb923c; background: #4a4a4a; }
.color-btn { border-radius: 50%; width: 28px; height: 28px; }
.wb-size { display: flex; align-items: center; }
.wb-size input { width: 60px; accent-color: #f97316; }

/* TOAST */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #22c55e; color: #fff; padding: 0.7rem 1.5rem; border-radius: 10px;
  font-weight: 600; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  font-size: 0.9rem;
}
.toast.error { background: #ef4444; }
.toast.info { background: #3b82f6; }

/* GRID */
#videoGrid.count-1 { grid-template-columns: 1fr; }
#videoGrid.count-2 { grid-template-columns: 1fr 1fr; }
#videoGrid.count-3 { grid-template-columns: 1fr 1fr 1fr; }
#videoGrid.count-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.count-5 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.count-6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.count-7 { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.count-8 { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.count-9 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }

@media (max-width: 640px) {
  #videoGrid.count-2 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #videoGrid.count-3 { grid-template-columns: 1fr 1fr; }
  #videoGrid.count-4 { grid-template-columns: 1fr 1fr; }
  #chatPanel { width: 100%; }
  .ctrl-btn { width: 38px; height: 38px; }
  #controls { gap: 0.5rem; padding: 0.5rem 0.5rem 0.8rem; }
}
