:root {
  --bg: #0b0d12;
  --bg-alt: #10131a;
  --card: #161a23;
  --card-2: #1c202b;
  --border: #262b38;
  --text: #eef0f4;
  --muted: #8b92a3;
  --accent: #5b7cfa;
  --accent-2: #8b6bff;
  --danger: #e5484d;
  --online: #3ecf8e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

button { font-family: inherit; }

/* ---------- Lobby ---------- */

#home {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.bg-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px circle at 20% 20%, rgba(91, 124, 250, 0.18), transparent 60%),
    radial-gradient(600px circle at 80% 80%, rgba(139, 107, 255, 0.14), transparent 60%);
  pointer-events: none;
}

.lobby {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.lobby h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 10px;
  letter-spacing: -0.3px;
}

.subtitle {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 28px;
}

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.field-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: -4px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

input::placeholder { color: #565d6e; }

input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}

button:hover { filter: brightness(1.12); }

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: white;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
}

.join-row button {
  flex-shrink: 0;
  width: auto;
  padding: 12px 18px;
}

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
  text-align: center;
}

/* ---------- Room ---------- */

#room {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-code {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.2);
}

.room-code span#room-code-label {
  color: var(--text);
  font-weight: 600;
  letter-spacing: 1.5px;
}

.room-code button {
  width: auto;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
}

.chat-toggle {
  width: auto;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
}

#participants-strip {
  display: flex;
  align-items: center;
  gap: -8px;
  flex: 1;
  overflow-x: auto;
  padding: 0 8px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  border: 2px solid var(--bg);
  margin-left: -8px;
  flex-shrink: 0;
}

.avatar:first-child { margin-left: 0; }

/* ---------- Stage ---------- */

#main-area {
  flex: 1;
  display: flex;
  min-height: 0;
}

#stage {
  position: relative;
  flex: 1;
  padding: 20px;
  display: flex;
  min-height: 0;
}

#screen-area {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  grid-auto-rows: 1fr;
  gap: 10px;
}

#screen-area:empty {
  display: block;
}

#screen-area:empty::before {
  content: "Ninguem compartilhando a tela ainda";
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 50vh;
  color: var(--muted);
  font-size: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.tile {
  position: relative;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}

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

.tile .label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.tile-screen {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.fullscreen-btn {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.tile:fullscreen {
  border-radius: 0;
}

.tile:fullscreen video {
  object-fit: contain;
}

.tile-audio {
  position: absolute;
  left: 10px;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  padding: 5px 8px;
  border-radius: 999px;
  z-index: 2;
}

.tile-audio .mute-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: white;
}

.tile-audio .icon-muted { display: none; }
.tile-audio.muted .icon-unmuted { display: none; }
.tile-audio.muted .icon-muted { display: block; }

.tile-audio .volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 70px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 100%, rgba(255, 255, 255, 0.25) 100%);
  outline: none;
  margin: 0;
}

.tile-audio .volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.tile-audio .volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.tile-audio .volume-slider::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: transparent;
}

#camera-strip {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 5;
}

.tile-camera {
  width: 170px;
  aspect-ratio: 16 / 9;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
}

/* ---------- Chat panel ---------- */

#chat-panel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-alt);
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.chat-header button {
  width: auto;
  padding: 4px;
  border: none;
  background: transparent;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.4;
}

.chat-msg .who {
  font-weight: 600;
  color: var(--accent);
  margin-right: 6px;
}

.chat-msg.own .who { color: var(--online); }

.chat-msg .body {
  color: var(--text);
  word-break: break-word;
}

.chat-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin-top: 20px;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#chat-form input {
  flex: 1;
}

#chat-form button {
  width: 40px;
  flex-shrink: 0;
  padding: 0;
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ---------- Bottom control bar ---------- */

.controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.ctrl {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.ctrl .icon-off { display: block; }
.ctrl .icon-on { display: none; }

.ctrl.on .icon-off { display: none; }
.ctrl.on .icon-on { display: block; }

.ctrl.on {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#quality-select {
  width: auto;
  height: 40px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--text);
  font-size: 12px;
  border: 1px solid var(--border);
}

.ctrl.hangup {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
  width: 60px;
  margin-left: 8px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  #chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 30;
  }

  #camera-strip {
    right: 12px;
    bottom: 12px;
  }

  .tile-camera {
    width: 110px;
  }
}
