:root {
  color-scheme: dark;

  --background: #1a1124;
  --foreground: #f0eaff;
  --card: #261833;
  --card-foreground: #f3e9ff;
  --primary: #a259ff;
  --primary-foreground: #ffffff;
  --muted-foreground: #bbaed1;
  --accent: #c084fc;
  --destructive: #ff5c8d;
  --border: #4c3663;
  --input: #3d2c4d;
  --ring: #a259ff;
  --radius: 10px;
  --sidebar-width: 280px;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: #000;
  background-image: linear-gradient(
    -70deg,
    rgba(33, 41, 107, 0.4) 0%,
    rgba(46, 12, 89, 0.4) 50%,
    rgba(71, 35, 117, 0.4) 100%
  );
  font-family: "Roboto", sans-serif;
  color: var(--foreground);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1rem;
  background: rgba(26, 17, 36, 0.96);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 0 0.25rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.1;
  font-weight: 700;
}

.participant-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  align-content: flex-start;
}

.participant-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  height: auto;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(1, 4, 9, 0.35);
  flex-shrink: 0;
}

.participant-item.is-self {
  border-color: rgba(162, 89, 255, 0.45);
  background: rgba(162, 89, 255, 0.08);
}

.participant-item.is-editing {
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.participant-main {
  min-width: 0;
}

.participant-name {
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.participant-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.participant-empty {
  color: var(--muted-foreground);
  font-size: 0.9rem;
  padding: 0.5rem 0.25rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-pill.sharing {
  background: rgba(63, 185, 80, 0.16);
  color: #aff3bb;
}

.name-input {
  width: 100%;
  height: 2rem;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--input);
  background: rgba(61, 44, 77, 0.45);
  color: var(--foreground);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
}

.name-input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(162, 89, 255, 0.25);
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
}

.sidebar-footer {
  display: grid;
  gap: 0.65rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 2.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(162, 89, 255, 0.35);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
  background: #9347ef;
}

.btn-outline {
  background: rgba(61, 44, 77, 0.3);
  color: var(--foreground);
  border-color: var(--input);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(192, 132, 252, 0.12);
  color: var(--accent);
}

.btn-destructive {
  background: rgba(255, 92, 141, 0.85);
  color: #fff;
}

.btn-destructive:hover:not(:disabled) {
  background: var(--destructive);
}

.btn-icon {
  width: auto;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.55rem;
  font-size: 0.82rem;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.22);
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-foreground);
  font-size: 1rem;
  pointer-events: none;
}

.stage-empty.hidden {
  display: none;
}

.stream-stage {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  height: calc(100vh - 2rem);
}

.stream-stage.is-single .stream-grid {
  flex: 1;
  min-height: 0;
  grid-template-columns: 1fr;
}

.stream-pinned {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
}

.stream-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  align-content: start;
}

.stream-stage.is-pinned .stream-grid {
  flex-shrink: 0;
  max-height: min(42vh, 360px);
  overflow-y: auto;
}

.stream-stage:not(.is-pinned):not(.is-single) .stream-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.video-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: calc(var(--radius) + 2px);
}

.video-tile.is-local {
  border-color: rgba(162, 89, 255, 0.55);
}

.video-tile.is-pinned-tile {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.video-tile.is-grid-tile {
  min-height: 220px;
}

.stream-stage.is-single .video-tile.is-grid-tile {
  height: 100%;
  min-height: 0;
}

.stream-stage.is-pinned .video-tile.is-grid-tile {
  min-height: 160px;
  max-height: 220px;
}

.tile-media {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
}

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

.video-tile.is-grid-tile video {
  object-fit: contain;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: rgba(26, 17, 36, 0.72);
  color: var(--foreground);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.tile-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: rgba(26, 17, 36, 0.92);
  border-top: 1px solid var(--border);
}

.thumb-label {
  display: none;
}

.tile-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mute-btn.is-muted {
  color: var(--destructive);
  border-color: rgba(255, 92, 141, 0.5);
  background: rgba(255, 92, 141, 0.14);
}

.mute-btn.is-muted:hover:not(:disabled) {
  color: #ff7aa3;
  border-color: rgba(255, 92, 141, 0.65);
  background: rgba(255, 92, 141, 0.22);
}

.volume-slider {
  --volume: 100%;
  width: 88px;
  height: 4px;
  appearance: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(
    to right,
    var(--primary) 0%,
    var(--primary) var(--volume),
    rgba(255, 255, 255, 0.16) var(--volume),
    rgba(255, 255, 255, 0.16) 100%
  );
}

.volume-slider.is-muted {
  --volume: 0%;
  background: rgba(255, 255, 255, 0.12);
  cursor: not-allowed;
  opacity: 0.72;
  pointer-events: none;
}

.volume-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: transparent;
}

.volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(162, 89, 255, 0.25);
}

.volume-slider.is-muted::-webkit-slider-thumb {
  background: #8b8199;
  box-shadow: none;
}

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

.volume-slider::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--primary);
}

.volume-slider.is-muted::-moz-range-progress {
  background: transparent;
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
}

.volume-slider.is-muted::-moz-range-thumb {
  background: #8b8199;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: rgba(61, 44, 77, 0.35);
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(192, 132, 252, 0.14);
  color: var(--accent);
  border-color: rgba(192, 132, 252, 0.35);
}

.icon-btn:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(162, 89, 255, 0.35);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pin-btn.is-active {
  color: var(--primary-foreground);
  border-color: rgba(162, 89, 255, 0.65);
  background: rgba(162, 89, 255, 0.85);
}

.pin-btn.is-active:hover:not(:disabled) {
  background: var(--primary);
  color: var(--primary-foreground);
}

.icon-btn svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: #2e1a44;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}

video:fullscreen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  object-fit: contain;
  background: #000;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 42vh;
  }

  .stage {
    min-height: 58vh;
    padding: 0.75rem;
  }

  .stream-stage {
    height: calc(100vh - 42vh - 1.5rem);
  }

  .stream-grid {
    grid-template-columns: 1fr;
  }

  .stream-stage.is-pinned .stream-grid {
    max-height: 34vh;
  }

  .volume-slider {
    width: 64px;
  }
}
