html,
body {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  font-size: 16px;
  color: #ccc;
  background-color: #333;
}

.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  overflow: hidden;
  line-height: 1em;
}

/* Video grid */

.grid {
  flex: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-template-rows: repeat(var(--rows, 1), 1fr);
  gap: 0.25em;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0.5em;
  align-items: stretch;
  justify-items: stretch;
  overflow: hidden;
}

.grid:empty {
  background: repeating-linear-gradient(
      45deg,
      #222 0,
      #222 1em,
      transparent 0,
      transparent 2em
    );
  border: 0.5em solid #333;
}

.grid > div {
  display: flex;
  gap: 0.25em;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background-color: #222;
  border-radius: 0.25em;
  border: 2px solid #444;
  box-sizing: border-box;
}

.grid video {
  flex-grow: 1;
  display: block;
  height: 100%;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  overflow: hidden;
  cursor: pointer;
  background-color: #222;
}

.grid video[data-mirror] {
  transform: rotateY(180deg);
}

.grid video:not([data-video="true"]) {
  display: none;
}

.grid video[data-expanded="true"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.grid > div::before {
  content: attr(data-name);
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  max-width: 50%;
  padding: 0.5em;
  font-size: 1em;
  line-height: 1em;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background-color: #222;
  z-index: 2;
}

.grid > div:not(:has(video))::before {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 3em;
}

.grid > div > div {
  display: none;
}

.grid > div:has(video[data-audio="true"]):not(:has(video[data-video="true"]))::after {
  content: '🔊';
  position: absolute;
  display: block;
  font-size: 3em;
  line-height: 1em;
  width: 1em;
  height: 1em;
  left: calc(50% - 0.5em);
  top: calc(50% - 0.5em);
  z-index: 1;
}

.grid > div:has(video[data-video="true"]):not(:has(video[data-audio="true"]))::after {
  content: '🔇';
  position: absolute;
  display: block;
  font-size: 1em;
  line-height: 1em;
  background-color: #222;
  padding: 0.5em;
  right: 0;
  top: 0;
  z-index: 1;
}

/* Chat */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  max-width: 300px;
  border-radius: 0.25em;
  border: 2px solid #444;
  margin: 0.5em 0.5em 0.5em 0;
  overflow: hidden;
}

.chat > header {
  display: flex;
  padding: 0.5em;
  border-bottom: 2px solid #444;
  background-color: #222;
}

.chat > header > div {
  flex: 1;
  font-weight: bold;
}

.chat > header > button {
  background: none;
  border: none;
  color: inherit;
  font-size: 1em;
  line-height: 1em;
  cursor: pointer;
  width: 1em;
  height: 1em;
  padding: 0;
  border-radius: 50%;
}

.chat > header > button:hover {
  background-color: #222;
}

.chat > main {
  flex: 1;
  overflow-y: auto;
  padding: 0.5em;
  background-color: #222;
  scroll-behavior: smooth;
}

.chat > main .message {
  border: 2px solid #444;
  margin-bottom: 0.5em;
  padding: 0.5em;
  border-radius: 0.25em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  position: relative;
  box-shadow: 0 0 2px 0px #bb00ff;
}

.chat > main .message[data-name]::before {
  content: attr(data-name);
  position: absolute;
  display: block;
  color: #888;
  font-size: 0.5em;
  left: 0.5em;
  top: -1em;
  background-color: #222;
  padding: 0 0.25em;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat > main .message[data-time]::after {
  content: attr(data-time);
  position: absolute;
  display: block;
  color: #888;
  font-size: 0.5em;
  right: 0.5em;
  top: -1em;
  background-color: #222;
  padding: 0 0.25em;
  overflow: hidden;
}

.chat > footer {
  display: flex;
  padding: 2px;
}

.chat > footer textarea {
  flex-grow: 1;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  display: block;
  box-sizing: border-box;
  padding: 0.5em;
  border: none;
  border-top: 2px solid #444;
  border-radius: 0 0 0.25em 0.25em;
  resize: none;
  background-color: #222;
}

.chat > footer textarea:focus {
  outline: 1px solid #bb00ff;
}

/* Toolbar */

.toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: fit-content;
  margin: 0.5em auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.5em;
  border-radius: 2em;
  overflow: hidden;
  background-color: rgba(127, 127, 127, 0.5);
  border: 2px solid #444;
  z-index: 2;
}

.toolbar button {
  padding: 0.5em;
  font-size: 1em;
  border: 2px solid #333;
  border-radius: 50%;
  background-color: #888;
  color: inherit;
  cursor: pointer;
  width: 2.75em;
  height: 2.75em;
}

.toolbar button:hover {
  filter: brightness(80%);
}

.toolbar button:focus {
  outline: 1px solid #bb00ff;
}

.toolbar button[data-enabled="true"] {
  background-color: #bb00ff;
}

.toolbar .microphone_btn::after {
  content: '🎤';
}

.toolbar .camera_btn::after {
  content: '📹';
}

.toolbar .screen_btn::after {
  content: '🖥️';
}

.toolbar .chat_btn::after {
  content: '💬';
}

/* Dialog */
.dialog {
  display: flex;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: #222;
  align-items: center;
  justify-content: center;
}

.dialog > div:first-child {
  padding: 1em;
  border: 2px solid #444;
  border-radius: 0.25em;
  width: 250px;
  height: fit-content;
  background-color: #333;
  margin-bottom: 0.5em;  
}

.dialog label {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5em;
}

.dialog input, .dialog select {
  display: block;
  padding: 0.5em;
  border: 2px solid #444;
  border-radius: 0.25em;
  background-color: #222;
  margin-top: 0.5em;
  font-size: 1em;
  color: inherit;
}

.dialog button {
  display: block;
  background-color: #222;
  border: 2px solid #444;
  border-radius: 0.25em;
  padding: 0.5em;
  width: 100%;
  color: inherit;
  margin-top: 1em;
  font-weight: bold;
  font-size: 1em;
  cursor: pointer
}

.dialog button:hover {
  background-color: #333;
}

.dialog input:focus,
.dialog select:focus,
.dialog button:focus {
  outline: 1px solid #bb00ff;
}

/* Error */
.error {
  position: fixed;
  top: 1em;
  right: 1em;
  min-width: 100px;
  max-width: 50vw;
  background-color: rgba(255, 0, 0, 0.8);
  color: white;
  padding: 0.5em 1em;
  border-radius: 0.25em;
  border: 2px solid #880000;
  font-weight: bold;
  font-size: small;
  z-index: 1000;
}

/* Fork me on GitHub */
.github-forkme {
  width: 12em;
  height: 12em;
  position: fixed;
  overflow: hidden;
  right: auto;
  left: 0;
  bottom: 0;
  z-index: 999;
  pointer-events: none;
  font-size: 12px;
  text-decoration: none;
  text-indent: -999999px;
}

.github-forkme::after {
  content: attr(data-text);
  display: block;
  position: absolute;
  width: 14em;
  color: #fff;
  font-weight: bold;
  line-height: 1.5em;
  text-decoration: none;
  text-shadow: 0 -1px rgba(0, 0, 0, .5);
  text-align: center;
  text-indent: 0;
  padding: .15em;
  top: 7em;
  left: -3em;
  border: 2px dashed #aaa;
  outline: 2px solid #a00;
  transform: rotate(45deg);
  background-image: linear-gradient(to bottom, #a00, #c00, #a00);
  box-shadow: 0 4px 4px 0 rgba(0, 0, 0, .5);
  pointer-events: auto;
}

/* Common */

[hidden] {
  display: none;
}

@media (orientation: portrait) {
  .container:has(.chat:not([hidden])) :is(.grid, .toolbar) {
    display: none;
  }

  .chat {
    max-width: none;
    margin: 0.5em;
  }
}