/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */

.hidden {
  display: none !important;
}

a {
  color: #4285F4;
  text-decoration: none;
}

a:hover {
  color: #3B78E7;
  text-decoration: underline;
}

#room-link a {
  white-space: nowrap;
}

:root {
  --bg-gradient: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #0d0d15 100%);
  --card-bg: rgba(22, 22, 37, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.5);
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.5);
  --accent-orange: #f59e0b;
  --accent-orange-glow: rgba(245, 158, 11, 0.5);
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.5);
  --accent-purple: #8b5cf6;
}

body {
  background: var(--bg-gradient);
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  height: 100%;
  margin: 0;
  padding: 0;
  width: 100%;
}

header {
  background: rgba(150, 16, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin: 0;
  padding: 1em 0;
  position: absolute;
  text-align: center;
  top: 0;
  width: 100%;
  z-index: 10;
}

#remote-canvas {
  display: none;
  height: 100%;
  margin: 0 auto;
  width: 100%;
}

div.warning {
  background-color: #a80202;
  color: black;
  font-weight: 400;
  opacity: .9;
}

#container {
  height: 100%;
  position: absolute;
}

#info-div {
  z-index: 3;
}

#room-link {
  margin: 0 0 29px 0;
}

#status {
  z-index: 4;
}

#videos {
  font-size: 0; /* to fix whitespace/scrollbars problem */
  height: 100%;
  pointer-events: none;
  position: absolute;
  transition: all 1s;
  width: 100%;
}

#videos.active {
  -moz-transform: rotateY(180deg);
  -ms-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

footer > div {
  background-color: black;
  bottom: 0;
  color: white;
  display: none;
  font-size: .9em;
  font-weight: 300;
  line-height: 2em;
  max-height: 80%;
  opacity: 0;
  overflow-y: auto;
  padding: 10px;
  position: absolute;
  transition: opacity 1s;
  width: calc(100% - 20px);
}

footer > div.active {
  display: block;
  opacity: .8;
}

div#privacy {
  bottom: 7px;
  color: gray;
  position: absolute;
  right: 10px;
}

div#privacy a {
  color: gray;
  font-size: 14px;
}

html {
  height: 100%;
  margin: 0;
  width: 100%;
}

label {
  margin: 0 10px 0 0;
}

#local-video {
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: cover;  /* no letterboxing */
  -moz-transform: scale(-1, 1);
  -ms-transform: scale(-1, 1);
  -o-transform: scale(-1, 1);
  -webkit-transform: scale(-1, 1);
  transform: scale(-1, 1);
  transition: opacity 1s;
  width: 100%;
}

#mini-video {
  border: 1px solid gray;
  bottom: 20px;
  left: 20px;
  /* video div is flipped horizontally when active*/
  max-height: 17%;
  max-width: 17%;
  opacity: 0;
  position: absolute;
  transition: opacity 1s;
}

#mini-video.active {
  opacity: 1;
  z-index: 2;
}

#remote-video {
  display: block;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: cover;  /* no letterboxing */
  opacity: 0;
  position: absolute;
  -moz-transform: rotateY(180deg);
  -ms-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  transition: opacity 1s;
  width: 100%;
}

#remote-video.active {
  opacity: 1;
  z-index: 1;
}

.sfu-grid {
  align-content: start;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  /* Anchor to #videos' top-left so the grid overlays the full window the way the P2P remote-video
     does. Without top/left an absolutely positioned box uses its static position, which sits below
     the full-height (opacity:0 but still in-flow) #local-video and pushes the grid off-screen. */
  top: 0;
  left: 0;
  height: 100%;
  overflow-y: auto;
  padding: 12px;
  position: absolute;
  width: 100%;
  box-sizing: border-box;
  z-index: 1;
}

.sfu-grid.hidden {
  display: none;
}

.sfu-tile {
  /* A fixed 16:9 aspect gives each tile a real height (its columns are width-driven), so the
     grid flows top-down as a responsive grid of cards instead of collapsing. */
  aspect-ratio: 16 / 9;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.sfu-tile video {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.sfu-caption {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  bottom: 6px;
  color: #fff;
  font-size: 12px;
  left: 6px;
  padding: 2px 6px;
  position: absolute;
  z-index: 2;
}

/* SFU mode only swaps the full-window peer video for the grid. #videos.active gives P2P its own
   stacking context (via its transform) so the grid — which lives inside #videos — cannot escape
   to cover the self-view or the control buttons (which sit outside #videos). SFU mode drops the
   .active transform, so re-establish that context here with isolation, leaving every other
   element (self-view, #icons) in its P2P position and stacking order. */
#videos.sfu-mode {
  isolation: isolate;
}

/* In P2P the .active transform both mirrors the self-view and (by flipping the whole container)
   makes #mini-video's `left: 20px` land on the right. SFU mode drops that container transform, so
   here we (a) mirror the self-view directly and (b) re-anchor it to the right so it keeps the exact
   P2P bottom-right position. */
#videos.sfu-mode #mini-video {
  transform: rotateY(180deg);
  left: auto;
  right: 20px;
}

#videos.sfu-mode #local-video,
#videos.sfu-mode #remote-video {
  opacity: 0;
  pointer-events: none;
}

#confirm-join-div {
  position: absolute;
  text-align: center;
  top: 80%;
  width: 100%;
  z-index: 5;
}

#confirm-join-div div {
  font-size: 1.5em;
  margin-bottom: 10px;
}

/*////// room selection start ///////////////////*/

/* Glow decoration */
.bg-glow,
.bg-glow-right {
  position: fixed;
  z-index: -1;
  pointer-events: none;
  filter: blur(80px);
}

.bg-glow {
  width: 600px;
  height: 600px;
  top: -100px;
  left: -100px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 50%, transparent 100%);
}

.bg-glow-right {
  width: 500px;
  height: 500px;
  bottom: -100px;
  right: -100px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.1) 0%, rgba(59, 130, 246, 0.05) 60%, transparent 100%);
}

/* Glassy card styling */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s ease, border-color 0.3s ease;
  margin-bottom: 2rem;
}

.card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.15);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.75rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-orange);
  box-shadow: 0 0 10px var(--accent-orange-glow);
  display: inline-block;
  flex-shrink: 0;
}

.card-title.states .card-icon {
  background-color: var(--accent-purple);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

.log-container {
  flex-grow: 1;
  overflow-y: auto;
  max-height: 280px;
}

.controls-row {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

input[type="text"] {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 0.6rem;
  padding: 0.6rem 0.9rem;
  width: 100%;
  box-sizing: border-box;
  display: block;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input[type="text"].invalid {
  border-color: var(--accent-red);
}

/* The V2 room link stands in for the room-id field: same box, but a real anchor so it can
   be clicked, hovered to reveal the URL, and opened in a new tab. */
.room-selection-link {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  color: var(--accent-blue);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 0.6rem;
  padding: 0.6rem 0.9rem;
  width: 100%;
  box-sizing: border-box;
  display: block;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.room-selection-link:hover,
.room-selection-link:focus {
  text-decoration: underline;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  outline: none;
}

label.error-label {
  color: var(--accent-red);
  font-size: 0.85rem;
  font-weight: 400;
  margin-top: 0.5rem;
  display: block;
}

#room-id-input-div {
  margin: 0;
}

.protocol-option {
  align-items: center;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  font-size: 0.9rem;
  gap: 0.65rem;
  margin-left: auto;
  width: fit-content;
}

.protocol-option input {
  accent-color: var(--accent-blue);
  height: 1rem;
  margin: 0;
  width: 1rem;
}

.protocol-badge {
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(59, 130, 246, 0.32);
  border-radius: 999px;
  color: #93c5fd;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
}

#room-id-input-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-start;
  margin: 0;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent-blue);
  border: none;
  border-radius: 0.6rem;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, opacity 0.2s ease;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

button:hover:not(:disabled) {
  background: #2563eb;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: none;
  cursor: not-allowed;
}

h1 {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.03em;
  margin: 0 0 0.5rem 0;
  text-align: center;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
  font-weight: 300;
  text-align: center;
  margin: 0 0 2rem 0;
  display: block;
}

div#room-selection {
  margin: 6vh auto 0 auto;
  width: 100%;
  /* Wide enough for a V2 room link to fit on one line. The longest realistic form,
     https://host:port/v2/r/ plus the 22-character token, is ~50 monospace characters
     (~537px including the field and card padding); 45rem leaves room for longer hosts,
     and 92vw keeps the card inside narrow viewports. The link still ellipsizes rather
     than overflowing if a host is longer still.
     min(92vw, 45rem)*/
  max-width: 540px;
  z-index: 1;
}

p {
  color: var(--text-secondary);
  font-weight: 300;
  line-height: 1.6em;
}

#recent-rooms-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#recent-rooms-list li {
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid var(--accent-blue);
  padding: 0.6rem 0.9rem;
  border-radius: 0 0.6rem 0.6rem 0;
  transition: background 0.2s ease, border-left-color 0.2s ease, transform 0.2s ease;
}

#recent-rooms-list li:hover {
  background: rgba(59, 130, 246, 0.08);
  border-left-color: var(--accent-green);
  transform: translateX(4px);
}

#recent-rooms-list li a {
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  text-decoration: none;
  display: block;
}

#recent-rooms-list li a:hover {
  color: #fff;
  text-decoration: none;
}

/*////// room selection end /////////////////////*/

/*////// icons CSS start ////////////////////////*/

#icons {
  bottom: 77px;
  left: 6vw;
  position: absolute;
}

circle {
  fill: #666;
  fill-opacity: 0.6;
}

svg.on circle {
  fill-opacity: 0;
}

/* on icons are hidden by default */
path.on {
  display: none;
}

/* off icons are displayed by default */
path.off {
  display: block;
}

/* on icons are displayed when parent svg has class 'on' */
svg.on path.on {
  display: block;
}

/* off icons are hidden when parent svg has class 'on' */
svg.on path.off {
  display: none;
}

svg {
  border-radius: 48px;
  box-shadow: 2px 2px 24px #444;
  display: block;
  margin: 0 0 3vh 0;
  transform: translateX(calc(-6vw - 96px));
  transition: all .1s;
  transition-timing-function: ease-in-out;
}

svg:hover {
  box-shadow: 4px 4px 48px #666;
}

#icons.active svg {
  transform: translateX(0);
}

#mute-audio {
  transition: 40ms;
}

#mute-audio:hover,
#mute-audio.on {
  background: #407cf7;
}

#mute-audio:hover circle {
  fill: #407cf7;
}

#mute-video {
  transition: 120ms;
}

#mute-video:hover,
#mute-video.on {
  background: #407cf7;
}

#mute-video:hover circle {
  fill: #407cf7;
}

#switch-video {
  transition: 200ms;
}

#switch-video:hover {
  background: #407cf7;
}

#switch-video:hover circle {
  fill: #407cf7;
}

#fullscreen {
  transition: 280ms;
}

#fullscreen:hover,
#fullscreen.on {
  background: #407cf7;
}

#fullscreen:hover circle {
  fill: #407cf7;
}

#hangup {
  transition: 360ms;
}

#hangup:hover {
  background: #dd2c00;
}
#hangup:hover circle {
  fill: #dd2c00;
}

/*////// icons CSS end /////////////////////////*/
