* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: auto;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  font-size: 11px;
  background: #245edb;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px;
  user-select: none;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Desktop wallpaper (peak aesthetic) ── */
.xp-desktop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.xp-desktop-wallpaper {
  position: absolute;
  inset: -4%;
  /* Classic Windows XP Bliss (with silly fallback) */
  background:
    url("wallpaper-bliss.jpg") center center / cover no-repeat,
    url("wallpaper-silly.jpg") center 35% / cover no-repeat,
    #3a6ea5;
  transform: scale(1.02);
  filter: saturate(1.15) contrast(1.05);
}

.xp-desktop-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 25%, rgba(0, 0, 0, 0.35) 100%),
    linear-gradient(180deg, rgba(255, 200, 0, 0.04) 0%, transparent 40%, rgba(0, 0, 0, 0.12) 100%);
}

.xp-desktop-scanlines {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.35) 2px,
    rgba(0, 0, 0, 0.35) 3px
  );
}

.xp-screen {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  /* Vertically center when short; stick to top when tall (no clipping) */
  margin-top: auto;
  margin-bottom: auto;
}

/* ── Layout ── */
.app-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* Room screen: player on top, room panel below (all breakpoints) */
#room-screen {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.app-layout--room {
  flex-direction: column;
  align-items: stretch;
  width: min(920px, 100%);
  max-width: 100%;
  min-width: 0;
  gap: 12px;
}

/* Desktop: keep both windows fully visible (scroll page if needed) */
@media (min-width: 769px) {
  #room-screen .player-window,
  #room-screen .room-panel {
    overflow: visible;
  }

  #room-screen .player-window .xp-video-wrap {
    overflow: hidden;
  }

  #room-screen .xp-controls,
  #room-screen .xp-media-panel {
    min-width: 0;
  }
}

/* ── XP Window ── */
.xp-window {
  width: min(720px, 100%);
  max-width: 100%;
  min-width: 0;
  background: #ece9d8;
  border: 2px solid #0054e3;
  border-radius: 8px 8px 0 0;
  box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  flex-shrink: 0;
}

.xp-window.lobby {
  width: min(420px, 100%);
}

.xp-window.player-window {
  width: 100%;
  max-width: 920px;
}

.xp-window.room-panel {
  width: 100%;
  max-width: 920px;
  overflow: visible;
}

.xp-window.chat-window {
  width: min(380px, 100%);
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.xp-window.participants-panel {
  width: 220px;
}

/* ── Chat window body ── */
.xp-body--chat {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  background: #ece9d8;
}

.xp-chat-messages {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fff;
  border: 2px inset #aca899;
  margin: 8px 8px 0;
  padding: 6px 8px;
  font-size: 12px;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  -webkit-overflow-scrolling: touch;
}

.xp-chat-msg {
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dotted #d4d0c8;
}

.xp-chat-msg:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.xp-chat-msg-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.xp-chat-msg-name {
  font-weight: bold;
  color: #000080;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-chat-msg--me .xp-chat-msg-name {
  color: #008000;
}

.xp-chat-msg-time {
  font-size: 10px;
  color: #666;
  font-family: "Lucida Console", "Courier New", monospace;
  flex-shrink: 0;
}

.xp-chat-msg-text {
  color: #000;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.35;
}

/* ── Voice controls inside chat window ── */
.xp-chat-voice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 6px 8px;
  background: linear-gradient(180deg, #f5f4ec 0%, #e8e4d8 50%, #d4d0c8 100%);
  border-top: 1px solid #fff;
  border-bottom: 1px solid #aca899;
  flex-shrink: 0;
  min-height: 36px;
}

.xp-voice-mic {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  min-width: 56px;
  padding: 0 8px;
  font-weight: bold;
  flex-shrink: 0;
}

.xp-voice-mic.is-muted {
  color: #800000;
  background: linear-gradient(180deg, #fff0f0 0%, #e8c0c0 45%, #d0a0a0 100%);
}

.xp-voice-mic.is-live:not(.is-muted) {
  color: #004000;
  background: linear-gradient(180deg, #f0fff0 0%, #c8e8c8 45%, #a0d0a0 100%);
}

.xp-voice-mic.is-speaking {
  outline: 2px solid #ffcc00;
  box-shadow: 0 0 0 1px #c90;
}

.xp-voice-mic-icon {
  font-size: 13px;
  line-height: 1;
}

.xp-voice-mic-label {
  font-size: 11px;
}

.xp-voice-vol-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 1 130px;
  min-width: 100px;
  max-width: 160px;
  height: 28px;
  padding: 0 5px 0 4px;
  /* XP sunken panel (like WMP volume tray) */
  background: linear-gradient(180deg, #d4d0c8 0%, #ece9d8 40%, #f5f4ec 100%);
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  box-shadow: inset 1px 1px 0 #404040;
  box-sizing: border-box;
}

.xp-voice-vol-icon {
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  color: #000;
  filter: grayscale(0.2);
}

/* Classic XP / WMP silver range — same language as .xp-volume-slider / .xp-seekbar */
.xp-voice-vol {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.xp-voice-vol:focus {
  outline: none;
}

.xp-voice-vol:focus-visible {
  outline: 1px dotted #000;
  outline-offset: 1px;
}

.xp-voice-vol::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(
    180deg,
    #808080 0%,
    #c0c0c0 28%,
    #e8e8e8 50%,
    #c0c0c0 72%,
    #808080 100%
  );
  border: 1px solid #404040;
  border-radius: 0;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.45);
}

.xp-voice-vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 18px;
  margin-top: -7px;
  background: linear-gradient(180deg, #ffffff 0%, #ece9d8 38%, #c0c0c0 70%, #a0a0a0 100%);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow:
    1px 1px 1px rgba(0, 0, 0, 0.35),
    inset 1px 1px 0 rgba(255, 255, 255, 0.85);
  border-radius: 0;
  cursor: pointer;
}

.xp-voice-vol::-webkit-slider-thumb:active {
  background: linear-gradient(180deg, #e0e0e0 0%, #c8c4bc 50%, #a8a8a8 100%);
  border-color: #606060 #fff #fff #606060;
}

.xp-voice-vol::-moz-range-track {
  height: 6px;
  background: linear-gradient(
    180deg,
    #808080 0%,
    #c0c0c0 28%,
    #e8e8e8 50%,
    #c0c0c0 72%,
    #808080 100%
  );
  border: 1px solid #404040;
  border-radius: 0;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.45);
}

.xp-voice-vol::-moz-range-thumb {
  width: 11px;
  height: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #ece9d8 38%, #c0c0c0 70%, #a0a0a0 100%);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.35);
  border-radius: 0;
  cursor: pointer;
}

.xp-voice-vol::-moz-range-progress {
  height: 6px;
  background: linear-gradient(180deg, #0a246a 0%, #3a6ea5 50%, #0a246a 100%);
  border: 1px solid #003c74;
  border-radius: 0;
}

.xp-voice-speakers {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 22px;
}

.xp-voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 110px;
  height: 20px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: bold;
  color: #000080;
  background: linear-gradient(180deg, #fff 0%, #d0e4ff 100%);
  border: 1px solid #6080c0;
  border-radius: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: xp-voice-pulse 0.9s ease-in-out infinite;
}

.xp-voice-chip::before {
  content: "🎙";
  font-size: 9px;
}

.xp-voice-chip.is-self {
  color: #006000;
  background: linear-gradient(180deg, #fff 0%, #d0f0d0 100%);
  border-color: #60a060;
}

@keyframes xp-voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

.xp-voice-status {
  flex: 0 0 auto;
  font-size: 10px;
  color: #555;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xp-voice-status.is-error {
  color: #800000;
  font-weight: bold;
}

.xp-chat-compose {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(180deg, #ece9d8 0%, #d4d0c8 100%);
  border-top: 1px solid #fff;
  flex-shrink: 0;
}

.xp-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
}

.xp-chat-compose .xp-btn {
  flex-shrink: 0;
  height: 28px;
  padding: 0 12px;
}

.xp-chat-mobile-toggle {
  display: none;
}

/* FAB to reopen closed chat */
.xp-chat-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2500;
  height: 36px;
  padding: 0 14px;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  font-size: 12px;
  font-weight: bold;
  color: #000;
  cursor: pointer;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 40%, #c0c0c0 100%);
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.4);
}

.xp-chat-fab:active {
  border-color: #404040 #fff #fff #404040;
  padding-top: 1px;
  padding-left: 1px;
}

.xp-chat-fab.xp-chat-fab--pulse {
  outline: 2px solid #ffcc00;
  box-shadow: 0 0 0 3px rgba(255, 200, 0, 0.45);
}

.xp-window.chat-window.xp-window--closed {
  display: none !important;
}

.xp-body--player {
  display: flex;
  flex-direction: column;
}

.xp-body--room {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.xp-titlebar {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 4px 0 6px;
  background: linear-gradient(180deg, #0997ff 0%, #0053ee 8%, #0050ee 40%, #06f 88%, #06f 93%, #005bff 95%, #003dd7 96%, #003dd7 100%);
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  letter-spacing: 0.2px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.xp-titlebar.viewer {
  background: linear-gradient(180deg, #6a9fd8 0%, #4a7fc8 50%, #3a6fb8 100%);
}

.xp-titlebar.inactive {
  background: linear-gradient(180deg, #7a96df 0%, #5a7fd4 50%, #4a6fc9 100%);
}

.xp-titlebar-icon {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  background: linear-gradient(135deg, #ff6b00, #ff0000 50%, #cc0000);
  border: 1px solid #800000;
  border-radius: 2px;
  flex-shrink: 0;
  position: relative;
}

.xp-titlebar-icon::after {
  content: "▶";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: #fff;
}

.xp-titlebar-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.xp-media-title {
  flex: 1;
  font-size: 10px;
  font-weight: normal;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 8px;
  text-shadow: none;
}

.xp-titlebar-buttons {
  display: flex;
  gap: 2px;
  margin-left: 8px;
}

.xp-sysbtn {
  width: 21px;
  height: 21px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
  background: linear-gradient(180deg, #3c8cff 0%, #2563d4 50%, #1a4db0 100%);
  border: 1px solid #0039a6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.xp-sysbtn:hover {
  background: linear-gradient(180deg, #5aa0ff 0%, #3a7ae0 50%, #2a60c0 100%);
}

.xp-sysbtn:active {
  background: linear-gradient(180deg, #1a4db0 0%, #2563d4 50%, #3c8cff 100%);
}

.xp-sysbtn.close:hover {
  background: linear-gradient(180deg, #e88080 0%, #d43030 50%, #b01010 100%);
  border-color: #800000;
}

.xp-sysbtn.close:active {
  background: linear-gradient(180deg, #b01010 0%, #d43030 50%, #e88080 100%);
}

/* ── Lobby ── */
.lobby-content {
  padding: 20px 16px 16px;
  text-align: center;
}

.lobby-content h2 {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #000;
}

.lobby-content p {
  font-size: 11px;
  color: #444;
  margin-bottom: 16px;
  line-height: 1.4;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  color: #808080;
  font-size: 10px;
}

.lobby-divider::before,
.lobby-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #aca899;
}

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

.lobby-join-row .xp-input {
  flex: 1;
}

.lobby-join-status {
  font-size: 11px;
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px inset #aca899;
  background: #fff;
}

.lobby-join-status.error {
  color: #cc0000;
  background: #fff0f0;
}

.lobby-join-status.info {
  color: #003399;
}

.lobby-hint {
  font-size: 10px;
  color: #808080;
  margin-top: 12px;
}

/* ── Supabase config panel (lobby) ── */
.xp-config-panel {
  margin-top: 14px;
  text-align: left;
  border: 1px solid #aca899;
  background: #f0f0ea;
  font-size: 11px;
}

.xp-config-panel summary {
  padding: 6px 10px;
  cursor: pointer;
  font-weight: bold;
  background: linear-gradient(180deg, #f5f4f0 0%, #e4e2db 100%);
  border-bottom: 1px solid #aca899;
  user-select: none;
}

.xp-config-panel:not([open]) summary {
  border-bottom: none;
}

.xp-config-body {
  padding: 10px;
}

.xp-config-status {
  font-family: "Lucida Console", Monaco, monospace;
  font-size: 10px;
  line-height: 1.5;
  background: #fff;
  border: 1px inset #aca899;
  padding: 6px 8px;
  margin-bottom: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

.xp-config-note {
  font-size: 10px;
  color: #666;
  margin: 0 0 8px;
}

.xp-config-label {
  display: block;
  font-size: 10px;
  margin: 6px 0 2px;
}

.xp-config-input {
  width: 100%;
  margin-bottom: 4px;
}

.xp-config-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.xp-config-badge {
  font-size: 10px;
  color: #003399;
  cursor: help;
}

.xp-realtime-status {
  font-size: 10px;
  font-weight: bold;
  cursor: help;
}

.xp-realtime-status.connected {
  color: #006600;
}

.xp-realtime-status.reconnecting {
  color: #cc6600;
}

.xp-realtime-status.disconnected {
  color: #cc0000;
}

.xp-config-badge.local-mode {
  color: #808080;
}

.xp-config-badge.configured {
  color: #006600;
}

/* ── XP fieldset / media panel ── */
.xp-fieldset {
  border: 1px solid #aca899;
  margin: 0;
  padding: 8px 10px 10px;
  background: linear-gradient(180deg, #f5f4f0 0%, #ece9d8 100%);
  border-bottom: 1px solid #aca899;
}

.xp-fieldset legend {
  padding: 0 6px;
  font-size: 11px;
  font-weight: bold;
  color: #000;
}

.xp-media-panel {
  box-shadow: inset 0 1px 0 #fff;
}

.xp-current-video {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 10px;
  padding: 6px 8px;
  background: #fff;
  border: 1px inset #aca899;
  font-size: 11px;
  line-height: 1.35;
}

.xp-current-video-label {
  color: #444;
  flex-shrink: 0;
  font-weight: bold;
}

.xp-current-video-name {
  color: #000;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-current-video-name.is-idle {
  color: #808080;
  font-style: italic;
}

/* ── XP confirm dialog ── */
.xp-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px))
           max(16px, env(safe-area-inset-right, 0px))
           max(16px, env(safe-area-inset-bottom, 0px))
           max(16px, env(safe-area-inset-left, 0px));
  background: rgba(0, 0, 0, 0.45);
}

.xp-confirm-overlay[hidden] {
  display: none !important;
}

.xp-confirm-window {
  width: 100%;
  max-width: 360px;
  flex-shrink: 1;
}

.xp-confirm-body {
  padding: 16px 14px 14px;
  background: #ece9d8;
}

.xp-confirm-body p {
  font-size: 12px;
  line-height: 1.45;
  color: #000;
  margin-bottom: 14px;
}

.xp-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.xp-confirm-actions .xp-btn {
  min-width: 100px;
}

.xp-toolbar-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.xp-toolbar-group label {
  display: block;
  color: #000;
  font-weight: normal;
  margin-bottom: 4px;
  font-size: 11px;
}

.xp-toolbar-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
  flex-wrap: wrap;
}

.xp-toolbar-input-row .xp-input {
  flex: 1;
  min-width: 0;
}

.xp-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.xp-toolbar-actions .xp-btn {
  flex: 1;
  min-width: 120px;
}

#btn-reset-video {
  color: #800000;
}

.xp-input {
  flex: 1;
  height: 22px;
  padding: 2px 6px;
  font-family: Tahoma, sans-serif;
  font-size: 11px;
  border: 2px inset #fff;
  background: #fff;
  outline: none;
}

.xp-input:focus {
  background: #ffffe1;
}

.xp-input:disabled {
  background: #ece9d8;
  color: #808080;
}

.xp-btn,
.xp-transport-btn,
.xp-sysbtn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.xp-btn {
  height: 24px;
  padding: 0 12px;
  font-family: Tahoma, sans-serif;
  font-size: 11px;
  cursor: pointer;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 45%, #d4d0c8 100%);
  border: 1px solid;
  border-color: #fff #808080 #808080 #fff;
  box-shadow: 1px 1px 0 #000;
  white-space: nowrap;
}

.xp-btn:hover {
  background: linear-gradient(180deg, #fff 0%, #f0ede5 45%, #e0dcd4 100%);
}

.xp-btn:active {
  border-color: #808080 #fff #fff #808080;
  background: linear-gradient(180deg, #d4d0c8 0%, #ece9d8 55%, #fff 100%);
  box-shadow: none;
  padding-top: 1px;
  padding-left: 13px;
}

.xp-btn:disabled {
  color: #808080;
  cursor: default;
  background: #ece9d8;
}

.xp-btn-primary {
  font-weight: bold;
  padding: 0 20px;
  height: 28px;
}

.xp-btn-small {
  height: 20px;
  padding: 0 6px;
  font-size: 10px;
  margin-left: auto;
}

/* ── Video area ── */
.xp-video-wrap {
  background: #000;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 240px;
  /* Clip any residual YouTube chrome that paints at iframe edges */
  overflow: hidden;
}

/* Media tools sit under transport — still near the player */
.xp-body--player .xp-media-panel {
  border-left: none;
  border-right: none;
  border-radius: 0;
  margin: 0;
}

.xp-fullscreen-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 6;
  width: 36px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: #000;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 40%, #c0c0c0 100%);
  border: 2px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.xp-fullscreen-btn:active {
  border-color: #606060 #fff #fff #606060;
  padding-top: 1px;
  padding-left: 1px;
}

.xp-video-wrap:fullscreen,
.xp-video-wrap:-webkit-full-screen {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  max-height: none;
  background: #000;
}

.xp-video-wrap:fullscreen #yt-player,
.xp-video-wrap:fullscreen #local-player-wrap,
.xp-video-wrap:fullscreen #local-player,
.xp-video-wrap:-webkit-full-screen #yt-player,
.xp-video-wrap:-webkit-full-screen #local-player-wrap,
.xp-video-wrap:-webkit-full-screen #local-player {
  width: 100%;
  height: 100%;
}

#yt-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  z-index: 1;
  background: #000;
  /* Native YT UI must never receive taps — only XP transport controls */
  pointer-events: none;
}

/* YT replaces the div with an iframe keeping the same id */
iframe#yt-player,
#video-wrap > iframe {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  max-width: 100% !important;
  max-height: 100% !important;
  z-index: 1;
  background: #000;
  /*
   * controls:0 still leaves a tappable surface that can flash the bottom bar
   * on mobile. Disable hit-testing so only our XP seek/play/volume work.
   */
  pointer-events: none !important;
}

/*
 * Transparent shield over the YT surface (below unlock / fullscreen / badge).
 * Extra insurance if a browser ignores pointer-events on cross-origin iframes.
 */
.xp-yt-hitshield {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: transparent;
  pointer-events: auto;
  /* Let scroll pass through on mobile when user drags over video area */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: default;
}

.xp-video-wrap.mode-local .xp-yt-hitshield {
  display: none;
}

/* Our overlays above the shield stay clickable */
.xp-video-wrap .xp-source-badge,
.xp-video-wrap .xp-fullscreen-btn,
.xp-video-wrap .xp-media-unlock,
.xp-video-wrap .xp-video-placeholder {
  pointer-events: auto;
}

#local-player-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#local-player {
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
  z-index: 1;
}

/* Tap-to-enable sound/video (iOS / mobile autoplay policy) */
.xp-media-unlock {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 16px;
  border: none;
  cursor: pointer;
  color: #fff;
  background: rgba(0, 0, 0, 0.62);
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.xp-media-unlock[hidden] {
  display: none !important;
}

.xp-media-unlock-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  font-size: 28px;
  line-height: 1;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 40%, #c0c0c0 100%);
  color: #000;
  border: 2px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.xp-media-unlock-text {
  font-size: 14px;
  font-weight: bold;
  text-shadow: 0 1px 2px #000;
  text-align: center;
  max-width: 240px;
}

.xp-video-wrap.needs-media-unlock .xp-source-badge {
  z-index: 16;
}

.xp-source-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 5;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: bold;
  border: 1px solid;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.xp-source-badge.youtube {
  background: linear-gradient(180deg, #fff 0%, #ffe0e0 100%);
  border-color: #c00 #800 #800 #faa;
  color: #800;
}

.xp-source-badge.rutube {
  background: linear-gradient(180deg, #fff 0%, #e8ffe8 100%);
  border-color: #0a0 #060 #060 #8f8;
  color: #060;
}

.xp-source-badge.vk {
  background: linear-gradient(180deg, #fff 0%, #e0ecff 100%);
  border-color: #4a76a8 #2a4a78 #2a4a78 #9cb4d8;
  color: #2a4a78;
}

.xp-source-badge.local {
  background: linear-gradient(180deg, #fff 0%, #e0f0ff 100%);
  border-color: #06c #048 #048 #8cf;
  color: #048;
}

.xp-source-badge.idle {
  background: linear-gradient(180deg, #fff 0%, #f0f0ea 100%);
  border-color: #808080 #404040 #404040 #c0c0c0;
  color: #404040;
}

.xp-video-wrap.mode-local {
  background: #111;
}

.xp-video-wrap.mode-external {
  background: #000;
}

/* RuTube / VK iframe fill */
.xp-iframe-player-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: #000;
}

.xp-iframe-player-wrap iframe,
#iframe-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ── Source picker dialog (Windows XP) ── */
.xp-source-window {
  width: min(440px, calc(100vw - 24px));
  max-width: 440px;
  box-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.25),
    0 8px 24px rgba(0, 0, 0, 0.35);
}

.xp-source-body {
  padding: 12px 14px 14px;
  background: #ece9d8;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  font-size: 12px;
  color: #000;
}

.xp-source-hint {
  margin: 0 0 10px;
  color: #222;
  line-height: 1.35;
}

.xp-source-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
  padding: 4px;
  background: #fff;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  box-shadow: inset 1px 1px 0 #404040;
  max-height: 260px;
  overflow-y: auto;
}

.xp-source-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  background: #fff;
  border: 1px solid transparent;
  color: #000;
  border-radius: 0;
}

.xp-source-option:hover {
  background: #e8f0fc;
  border-color: #7da2ce;
}

.xp-source-option:focus-visible {
  outline: 1px dotted #000;
  outline-offset: -3px;
}

.xp-source-option.is-selected {
  background: #316ac5;
  border-color: #0a246a;
  color: #fff;
}

.xp-source-option.is-selected:hover {
  background: #3a76d4;
}

.xp-source-option.is-selected small {
  color: #d0e0ff;
}

.xp-source-option.is-selected .xp-source-option-icon {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.xp-source-option-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid;
  border-radius: 2px;
}

.xp-source-option-icon.youtube {
  background: #c00;
  border-color: #800;
  color: #fff;
}

.xp-source-option-icon.rutube {
  background: #00a651;
  border-color: #060;
  color: #fff;
}

.xp-source-option-icon.vk {
  background: #4a76a8;
  border-color: #2a4a78;
  color: #fff;
}

.xp-source-option-icon.local {
  background: linear-gradient(180deg, #fff 0%, #d4d0c8 100%);
  border-color: #808080;
  color: #000;
  font-size: 16px;
}

.xp-source-option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.xp-source-option-text strong {
  font-size: 12px;
}

.xp-source-option-text small {
  font-size: 10px;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-source-input-block {
  margin-bottom: 12px;
}

.xp-source-input-block label {
  display: block;
  margin-bottom: 4px;
  font-weight: bold;
}

.xp-source-input-block .xp-input {
  width: 100%;
  box-sizing: border-box;
  height: 28px;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  box-shadow: inset 1px 1px 0 #404040;
  background: #fff;
  font-family: Tahoma, "MS Sans Serif", sans-serif;
  font-size: 12px;
  padding: 2px 6px;
}

.xp-source-input-block .xp-input:focus {
  outline: 1px dotted #000;
  outline-offset: -4px;
}

.xp-source-field-hint {
  margin: 5px 0 0;
  font-size: 10px;
  color: #555;
  line-height: 1.3;
}

.xp-source-error {
  margin: 6px 0 0;
  padding: 4px 6px;
  color: #800000;
  font-weight: bold;
  font-size: 11px;
  background: #fff8f0;
  border: 1px solid #c0a0a0;
}

.xp-toolbar-actions--primary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.xp-toolbar-actions--primary .xp-btn-primary {
  flex: 1 1 auto;
  min-width: 180px;
}

.xp-upload-progress {
  padding: 4px 8px 6px;
  background: linear-gradient(180deg, #ece9d8 0%, #d8d6cf 100%);
  border-bottom: 1px solid #aca899;
}

.xp-upload-progress-track {
  height: 14px;
  background: #fff;
  border: 2px inset #aca899;
  margin-bottom: 2px;
  overflow: hidden;
}

.xp-upload-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(180deg, #6c6 0%, #393 50%, #282 100%);
  transition: width 0.2s ease;
}

.xp-upload-progress-label {
  font-size: 10px;
  color: #444;
}

.xp-video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #c0c0c0;
  font-size: 13px;
  background: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%);
  pointer-events: none;
  text-align: center;
  padding: 16px;
  z-index: 4;
}

.xp-video-placeholder::before {
  content: "▶";
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  font-size: 20px;
  color: #808080;
  background: linear-gradient(180deg, #404040 0%, #202020 100%);
  border: 2px solid;
  border-color: #606060 #101010 #101010 #606060;
  border-radius: 4px;
}

.xp-video-placeholder.hidden { display: none; }

.xp-video-wrap.has-video .xp-video-placeholder {
  display: none;
}

/* Embed blocked: keep overlay visible above player, allow link clicks */
.xp-video-placeholder.xp-embed-blocked {
  display: flex !important;
  pointer-events: auto;
  z-index: 12;
  gap: 12px;
  color: #f0e8c8;
  background: rgba(10, 10, 10, 0.92);
}

.xp-video-placeholder.xp-embed-blocked::before {
  content: "⚠";
  color: #ffcc00;
  font-size: 22px;
  border-color: #c4a000 #604000 #604000 #c4a000;
  background: linear-gradient(180deg, #3a3a20 0%, #1a1a10 100%);
}

.xp-video-placeholder.xp-embed-blocked .xp-embed-blocked-title {
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  max-width: 320px;
  line-height: 1.35;
}

.xp-video-placeholder.xp-embed-blocked .xp-embed-blocked-hint {
  font-size: 12px;
  color: #b0b0b0;
  max-width: 320px;
  line-height: 1.4;
}

.xp-video-placeholder.xp-embed-blocked .xp-embed-open-yt {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: bold;
  color: #000;
  text-decoration: none;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 45%, #d4d0c8 100%);
  border: 2px solid;
  border-color: #fff #808080 #808080 #fff;
  cursor: pointer;
}

.xp-video-placeholder.xp-embed-blocked .xp-embed-open-yt:hover {
  background: linear-gradient(180deg, #fff 0%, #f5f3ec 50%, #e4e0d6 100%);
}

.xp-video-placeholder.xp-embed-blocked .xp-embed-open-yt:active {
  border-color: #808080 #fff #fff #808080;
}

/* ── Control panel (WMP style) ── */
.xp-controls {
  background: linear-gradient(180deg, #e8e6df 0%, #d4d0c8 30%, #c8c4bc 100%);
  border-top: 1px solid #fff;
  padding: 8px 10px 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.xp-controls.viewer-mode {
  opacity: 0.75;
}

.xp-controls.viewer-mode .xp-seekbar,
.xp-controls.viewer-mode .xp-transport-btn,
.xp-controls.viewer-mode .xp-select {
  cursor: not-allowed;
}

.xp-seek-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.xp-time {
  font-family: "Lucida Console", "Courier New", monospace;
  font-size: 11px;
  color: #000;
  min-width: 38px;
  text-align: center;
}

.xp-seekbar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
  cursor: pointer;
}

.xp-seekbar:disabled { cursor: not-allowed; opacity: 0.6; }

.xp-seekbar::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(180deg, #808080 0%, #c0c0c0 30%, #e0e0e0 50%, #c0c0c0 70%, #808080 100%);
  border: 1px solid #404040;
  border-radius: 0;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.xp-seekbar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 18px;
  margin-top: -7px;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 40%, #c0c0c0 100%);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.xp-seekbar::-moz-range-track {
  height: 6px;
  background: linear-gradient(180deg, #808080 0%, #c0c0c0 30%, #e0e0e0 50%, #c0c0c0 70%, #808080 100%);
  border: 1px solid #404040;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.xp-seekbar::-moz-range-thumb {
  width: 12px;
  height: 18px;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 40%, #c0c0c0 100%);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  border-radius: 0;
}

.xp-transport-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.xp-transport {
  display: flex;
  gap: 4px;
}

.xp-transport-btn {
  width: 36px;
  height: 32px;
  cursor: pointer;
  background: linear-gradient(180deg, #fff 0%, #ece9d8 30%, #d4d0c8 70%, #c0c0c0 100%);
  border: 2px solid;
  border-color: #fff #606060 #606060 #fff;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #000;
  padding: 0;
}

.xp-transport-btn:hover {
  background: linear-gradient(180deg, #fff 0%, #f5f3ec 30%, #e8e4dc 70%, #d8d4cc 100%);
}

.xp-transport-btn:active,
.xp-transport-btn.active {
  border-color: #606060 #fff #fff #606060;
  background: linear-gradient(180deg, #b8b4ac 0%, #d4d0c8 30%, #ece9d8 70%, #fff 100%);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.2);
  padding-top: 2px;
  padding-left: 2px;
}

.xp-transport-btn:disabled {
  color: #a0a0a0;
  cursor: default;
}

.xp-transport-btn .icon-play {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #1a5c1a;
  margin-left: 3px;
}

.xp-transport-btn .icon-pause {
  display: flex;
  gap: 3px;
}

.xp-transport-btn .icon-pause span {
  display: block;
  width: 4px;
  height: 14px;
  background: #1a5c1a;
}

.xp-transport-btn .icon-stop {
  width: 12px;
  height: 12px;
  background: #cc0000;
  border: 1px solid #800000;
}

.xp-spacer { flex: 1; }

.xp-volume-group,
.xp-speed-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.xp-volume-group label,
.xp-speed-group label {
  font-size: 11px;
  color: #000;
}

.xp-volume-slider {
  width: 80px;
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
  cursor: pointer;
}

.xp-volume-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(180deg, #707070, #b0b0b0, #707070);
  border: 1px solid #404040;
}

.xp-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 16px;
  margin-top: -7px;
  background: linear-gradient(180deg, #fff, #c0c0c0);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  cursor: pointer;
}

.xp-volume-slider::-moz-range-track {
  height: 4px;
  background: linear-gradient(180deg, #707070, #b0b0b0, #707070);
  border: 1px solid #404040;
}

.xp-volume-slider::-moz-range-thumb {
  width: 10px;
  height: 16px;
  background: linear-gradient(180deg, #fff, #c0c0c0);
  border: 1px solid;
  border-color: #fff #606060 #606060 #fff;
  cursor: pointer;
  border-radius: 0;
}

.xp-select {
  height: 22px;
  font-family: Tahoma, sans-serif;
  font-size: 11px;
  padding: 0 4px;
  background: #fff;
  border: 2px inset #fff;
  cursor: pointer;
}

.xp-select:disabled {
  background: #ece9d8;
  color: #808080;
  cursor: not-allowed;
}

.xp-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 3px 8px;
  background: #ece9d8;
  border-top: 1px solid #aca899;
  font-size: 11px;
  color: #000;
  min-width: 0;
}

.xp-statusbar #status-text {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-statusbar-secondary {
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-statusbar .sep {
  color: #808080;
  margin: 0 4px;
}

/* ── Participants (inside room panel) ── */
.participants-body {
  padding: 8px 10px 10px;
  min-height: 80px;
  max-height: 280px;
  overflow-y: auto;
}

.room-panel .participants-body {
  border-top: 1px solid #aca899;
  background: #f8f7f2;
}

.participants-body h3 {
  font-size: 11px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #000;
}

#participants-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.xp-participant {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: #fff;
  border: 1px solid #aca899;
  font-size: 11px;
}

.xp-participant .xp-btn-transfer-host {
  flex: 1 1 100%;
  width: 100%;
  margin-left: 0;
  height: 28px;
  font-size: 11px;
  cursor: pointer;
}

.xp-participant.is-host {
  background: #ffffe1;
  border-color: #c4a000;
}

.xp-participant.is-me {
  font-weight: bold;
}

.xp-avatar {
  width: 22px;
  height: 22px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: bold;
  font-size: 11px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.xp-participant-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xp-participant-badge {
  font-size: 9px;
  color: #666;
  white-space: nowrap;
}

.room-link-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #f5f4f0 0%, #e8e6df 100%);
  border-bottom: 1px solid #aca899;
  font-size: 12px;
  flex-wrap: wrap;
}

.room-link-bar > span:first-child {
  font-weight: bold;
  flex-shrink: 0;
}

.room-link-bar code {
  flex: 1 1 auto;
  min-width: 0;
  background: #fff;
  border: 1px inset #aca899;
  padding: 4px 8px;
  font-family: "Lucida Console", monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-panel .room-link-bar .xp-btn-small {
  margin-left: 0;
  height: 28px;
  padding: 0 12px;
  flex-shrink: 0;
}

/* Minimized / Maximized */
.xp-window.minimized .xp-body { display: none; }
.xp-window.minimized { width: 300px; }

.xp-window.maximized {
  position: fixed;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.xp-window.maximized .xp-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.xp-window.maximized .xp-video-wrap {
  flex: 1;
  aspect-ratio: unset;
}

.xp-window.xp-window--closed {
  display: none !important;
}

/* Resize handles — hidden by default (mobile + lobby); desktop enables below */
.xp-resize-handles {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.xp-resize-handle {
  position: absolute;
  pointer-events: auto;
  background: transparent;
  box-sizing: border-box;
}

/* Edge strips */
.xp-resize-n  { top: 0; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.xp-resize-s  { bottom: 0; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.xp-resize-e  { top: 8px; right: 0; bottom: 8px; width: 6px; cursor: ew-resize; }
.xp-resize-w  { top: 8px; left: 0; bottom: 8px; width: 6px; cursor: ew-resize; }

/* Corners — XP-style grip squares */
.xp-resize-nw,
.xp-resize-ne,
.xp-resize-sw,
.xp-resize-se {
  width: 12px;
  height: 12px;
  z-index: 51;
}

.xp-resize-nw { top: 0; left: 0; cursor: nwse-resize; }
.xp-resize-ne { top: 0; right: 0; cursor: nesw-resize; }
.xp-resize-sw { bottom: 0; left: 0; cursor: nesw-resize; }
.xp-resize-se { bottom: 0; right: 0; cursor: nwse-resize; }

/* Classic XP corner grip (small beveled square) */
.xp-resize-nw::after,
.xp-resize-ne::after,
.xp-resize-sw::after,
.xp-resize-se::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: linear-gradient(135deg, #fff 0%, #d4d0c8 45%, #808080 100%);
  border: 1px solid;
  border-color: #fff #404040 #404040 #fff;
  box-shadow: 0 0 0 1px #0a246a;
  opacity: 0.85;
}

.xp-resize-nw::after { top: 1px; left: 1px; }
.xp-resize-ne::after { top: 1px; right: 1px; }
.xp-resize-sw::after { bottom: 1px; left: 1px; }
.xp-resize-se::after { bottom: 1px; right: 1px; }

/* ========== DESKTOP STYLES (min-width: 769px) ==========
   Pure CSS free-desktop for room mode when viewport ≥ 769px.
   Requires body.xp-in-room (set by app.js). Drag is JS-only.
   ======================================================= */
@media (min-width: 769px) {
  /* Full-bleed XP desktop surface while in a room */
  body.xp-in-room {
    padding: 0;
    margin: 0;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
    display: block;
    align-items: unset;
    justify-content: unset;
  }

  body.xp-in-room .xp-desktop {
    z-index: 0;
  }

  body.xp-in-room .xp-desktop-wallpaper {
    background:
      url("wallpaper-bliss.jpg") center center / cover no-repeat,
      #3a6ea5;
    transform: none;
    filter: saturate(1.1) contrast(1.05);
  }

  body.xp-in-room .xp-screen {
    margin: 0;
  }

  /* Room fills the entire desktop */
  body.xp-in-room #room-screen:not([hidden]) {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    display: block;
    overflow: hidden;
    z-index: 1;
  }

  /* Layout becomes a free positioning canvas */
  body.xp-in-room #room-screen .app-layout--room {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    min-width: 0;
    gap: 0;
    flex-direction: unset;
    align-items: unset;
  }

  /* Player window — floating XP window (default top-left) */
  body.xp-in-room #app-window,
  body.xp-in-room #room-screen .player-window {
    position: absolute;
    left: 40px;
    top: 36px;
    width: 720px;
    min-width: 400px;
    max-width: calc(100vw - 48px);
    margin: 0;
    z-index: 20;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 4px 4px 14px rgba(0, 0, 0, 0.5);
  }

  /* Room panel — floating, to the right of player when space allows */
  body.xp-in-room #room-panel,
  body.xp-in-room #room-screen .room-panel {
    position: absolute;
    left: 780px;
    top: 36px;
    width: 400px;
    min-width: 320px;
    max-width: calc(100vw - 48px);
    margin: 0;
    z-index: 21;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 4px 4px 14px rgba(0, 0, 0, 0.5);
  }

  /* Chat — floating XP window (default bottom-left; JS may override) */
  body.xp-in-room #chat-window,
  body.xp-in-room #room-screen .chat-window {
    position: absolute;
    left: 40px;
    top: 420px;
    width: 360px;
    height: 300px;
    min-width: 280px;
    min-height: 220px;
    max-width: calc(100vw - 48px);
    margin: 0;
    z-index: 22;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 4px 4px 14px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
  }

  body.xp-in-room #chat-window.xp-window--sized,
  body.xp-in-room #room-screen .chat-window.xp-window--sized {
    display: flex;
    flex-direction: column;
  }

  body.xp-in-room #chat-window .xp-body--chat {
    flex: 1 1 auto;
    min-height: 0;
  }

  body.xp-in-room #chat-window .xp-chat-messages {
    flex: 1 1 auto;
    min-height: 80px;
  }

  body.xp-in-room #btn-chat-mobile-toggle {
    display: none !important;
  }

  /* Narrower desktop: stack room panel under player (still floating / draggable) */
  body.xp-in-room #room-panel {
    /* fallback if left would overflow — JS may override with saved pos */
  }

  /* Title bar = drag handle (Windows XP) */
  body.xp-in-room #room-screen .xp-titlebar {
    cursor: move;
  }

  body.xp-in-room #room-screen .xp-titlebar .xp-sysbtn,
  body.xp-in-room #room-screen .xp-titlebar-buttons {
    cursor: default;
  }

  body.xp-in-room #room-screen .xp-titlebar .xp-titlebar-text,
  body.xp-in-room #room-screen .xp-titlebar .xp-titlebar-icon,
  body.xp-in-room #room-screen .xp-titlebar .xp-media-title {
    pointer-events: none; /* drag starts from whole titlebar strip */
  }

  /* ── Resize handles (desktop room only) ── */
  body.xp-in-room #room-screen .xp-window .xp-resize-handles {
    display: block;
  }

  body.xp-in-room #room-screen .xp-window.maximized .xp-resize-handles,
  body.xp-in-room #room-screen .xp-window.minimized .xp-resize-handles {
    display: none !important;
  }

  /* Explicit size from drag/resize — body fills remaining height */
  body.xp-in-room #room-screen .xp-window.xp-window--sized {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.xp-in-room #room-screen .xp-window.xp-window--sized > .xp-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
  }

  body.xp-in-room #room-screen .player-window.xp-window--sized .xp-video-wrap {
    flex: 1 1 auto;
    min-height: 140px;
    height: auto;
    aspect-ratio: auto;
  }

  body.xp-in-room #room-screen .room-panel.xp-window--sized .xp-body--room,
  body.xp-in-room #room-screen .room-panel.xp-window--sized .participants-body {
    min-height: 0;
  }

  body.xp-in-room #room-screen .room-panel.xp-window--sized .participants-body {
    flex: 1 1 auto;
    overflow: auto;
  }

  body.xp-resizing {
    cursor: inherit;
    user-select: none;
  }

  body.xp-resizing iframe,
  body.xp-resizing video,
  body.xp-resizing #yt-player {
    pointer-events: none !important;
  }

  body.xp-in-room .xp-window--resizing {
    opacity: 0.97;
    box-shadow: 6px 6px 18px rgba(0, 0, 0, 0.55) !important;
  }

  body.xp-in-room #room-screen .xp-window.maximized {
    position: fixed !important;
    inset: 0 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    border-radius: 0;
    z-index: 2000 !important;
  }

  body.xp-in-room #room-screen .xp-window.minimized {
    width: 280px !important;
    height: auto !important;
  }

  body.xp-in-room #room-screen .xp-window.minimized .xp-body {
    display: none !important;
  }

  /* While dragging: capture cursor + ignore media under pointer */
  body.xp-dragging {
    cursor: move !important;
    user-select: none !important;
    -webkit-user-select: none !important;
  }

  body.xp-dragging iframe,
  body.xp-dragging video,
  body.xp-dragging #yt-player {
    pointer-events: none !important;
  }

  body.xp-in-room .xp-window--dragging {
    opacity: 0.97;
    box-shadow: 8px 8px 20px rgba(0, 0, 0, 0.55);
    z-index: 3000 !important;
  }

  body.xp-in-room #room-screen .xp-sysbtn {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
  }

  /* Desktop video: normal 16:9, not mobile dvh clamp */
  body.xp-in-room #room-screen .xp-video-wrap {
    height: auto;
    max-height: none;
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  body.xp-in-room #room-screen .xp-controls {
    padding: 8px 10px 10px;
  }

  body.xp-in-room #room-screen .xp-transport-btn {
    width: 36px;
    height: 32px;
    min-width: 36px;
    min-height: 32px;
  }
}

/* Side-by-side only when wide enough; otherwise room panel under player */
@media (min-width: 769px) and (max-width: 1199px) {
  body.xp-in-room #room-panel,
  body.xp-in-room #room-screen .room-panel {
    left: 40px;
    top: 420px;
  }
}

/* ========== MOBILE ONLY (max-width: 768px) ==========
   Desktop (≥769px) is untouched above.
   Room stack (display:contents reorders DOM for one-hand UX):
     1) Large video (~55–65dvh, 16:9 letterbox)
     2) Transport controls (touch ≥48px)
     3) Compact source tools (host)
     4) Room invite + participants at bottom
   =================================================== */
@media (max-width: 768px) {
  html {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
  }

  body {
    padding: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    font-size: 12px;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 100dvh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Cancel desktop free-desktop (absolute windows / fixed room) */
  body.xp-in-room {
    padding: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100dvh !important;
    display: block !important;
  }

  body.xp-in-room #room-screen:not([hidden]) {
    position: static !important;
    inset: auto !important;
    height: auto !important;
    min-height: 100dvh !important;
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    margin: 0 !important;
  }

  .xp-desktop-vignette { opacity: 0.35; }
  .xp-desktop-scanlines { opacity: 0.02; }

  .xp-screen {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    margin: 0;
    justify-content: stretch;
    align-items: stretch;
  }

  #lobby-screen {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    align-items: flex-start;
  }

  #room-screen {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  /*
   * Flatten windows so flex order can place:
   * video → controls → source → room invite (bottom)
   * Only applies inside this max-width:768 block.
   */
  body.xp-in-room #room-screen .app-layout--room,
  #room-screen .app-layout--room {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    gap: 0 !important;
    position: static !important;
    overflow-x: hidden !important;
  }

  body.xp-in-room #room-screen #app-window,
  body.xp-in-room #room-screen #room-panel,
  #room-screen #app-window,
  #room-screen #room-panel,
  #room-screen .player-window,
  #room-screen .room-panel {
    display: contents !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    overflow: visible !important;
  }

  /* Chat stays a real box on mobile (not display:contents) */
  body.xp-in-room #room-screen #chat-window,
  #room-screen #chat-window,
  #room-screen .chat-window {
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    border: 2px solid #0054e3 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #ece9d8 !important;
    overflow: hidden !important;
    z-index: 5 !important;
    order: 9;
  }

  body.xp-in-room #room-screen #chat-window.xp-window--closed,
  #room-screen #chat-window.xp-window--closed {
    display: none !important;
  }

  #room-screen #app-window > .xp-body--player,
  #room-screen .xp-body--player,
  #room-screen #room-panel > .xp-body--room,
  #room-screen .xp-body--room {
    display: contents !important;
  }

  /* Hide chrome that wastes vertical space */
  #room-screen #app-window > .xp-titlebar,
  #room-screen #titlebar {
    display: none !important;
  }

  #room-screen .xp-media-title {
    display: none !important;
  }

  #room-screen #room-panel > .xp-titlebar .xp-titlebar-buttons,
  #room-screen .room-panel .xp-titlebar-buttons {
    display: none !important;
  }

  /* ── Flex order: primary stack ── */
  #room-screen .xp-video-wrap { order: 1; }
  #room-screen .xp-upload-progress { order: 2; }
  #room-screen .xp-controls { order: 3; }
  #room-screen .xp-media-panel { order: 4; }
  #room-screen .xp-statusbar { order: 5; }
  #room-screen #room-panel-titlebar,
  #room-screen #room-panel > .xp-titlebar { order: 6; }
  #room-screen .room-link-bar { order: 7; }
  #room-screen .participants-body { order: 8; }
  #room-screen #chat-window { order: 9; }

  /* Mobile chat: collapsible panel under participants */
  #room-screen #chat-window > .xp-titlebar {
    display: none !important;
  }

  #room-screen #btn-chat-mobile-toggle {
    display: flex !important;
    align-items: center;
    width: 100%;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    margin: 0;
    border: none;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #aca899;
    background: linear-gradient(180deg, #245edb 0%, #0c3d9e 100%);
    color: #fff;
    font-family: Tahoma, "MS Sans Serif", sans-serif;
    font-size: 13px;
    font-weight: bold;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #room-screen #chat-window.xp-chat--collapsed .xp-body--chat {
    display: none !important;
  }

  #room-screen #chat-window .xp-body--chat {
    display: flex !important;
    flex-direction: column;
    max-height: 42dvh;
  }

  #room-screen #chat-window .xp-chat-messages {
    min-height: 120px;
    max-height: 28dvh;
    margin: 6px 8px 0;
    font-size: 13px;
  }

  #room-screen #chat-window .xp-chat-compose {
    padding: 8px 10px 10px;
    gap: 8px;
  }

  #room-screen #chat-window .xp-chat-voice {
    padding: 8px 10px;
    gap: 8px;
  }

  #room-screen #chat-window .xp-voice-mic {
    height: 44px;
    min-height: 44px;
    min-width: 72px;
    padding: 0 12px;
    font-size: 13px;
  }

  #room-screen #chat-window .xp-voice-vol-wrap {
    height: 44px;
    min-height: 44px;
    flex: 1 1 160px;
    max-width: none;
    padding: 0 10px 0 8px;
  }

  #room-screen #chat-window .xp-voice-vol {
    height: 28px;
  }

  #room-screen #chat-window .xp-voice-vol::-webkit-slider-runnable-track {
    height: 8px;
  }

  #room-screen #chat-window .xp-voice-vol::-webkit-slider-thumb {
    width: 14px;
    height: 24px;
    margin-top: -9px;
  }

  #room-screen #chat-window .xp-voice-vol::-moz-range-track {
    height: 8px;
  }

  #room-screen #chat-window .xp-voice-vol::-moz-range-thumb {
    width: 14px;
    height: 24px;
  }

  #room-screen #chat-window .xp-voice-status {
    font-size: 11px;
    max-width: none;
    width: 100%;
  }

  #room-screen #chat-window .xp-chat-input {
    height: 44px;
    min-height: 44px;
    font-size: 16px; /* prevent iOS zoom */
  }

  #room-screen #chat-window .xp-chat-compose .xp-btn {
    height: 44px;
    min-height: 44px;
    padding: 0 14px;
    font-size: 13px;
  }

  #room-screen .xp-chat-fab {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    height: 48px;
    min-height: 48px;
    padding: 0 16px;
    font-size: 14px;
  }

  /* ── 1. VIDEO — top, ~55–65% viewport, 16:9 letterbox ── */
  #room-screen .xp-video-wrap {
    order: 1;
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    box-sizing: border-box;
    /* Large stage ~55–65% screen; 16:9 via letterbox (object-fit / YT) */
    height: clamp(220px, 60dvh, 65dvh);
    max-height: 65dvh;
    min-height: 200px;
    background: #000;
    position: relative;
    overflow: hidden;
  }

  #room-screen #yt-player,
  #room-screen iframe#yt-player,
  #room-screen #video-wrap > iframe,
  #room-screen #local-player-wrap,
  #room-screen #local-player,
  #room-screen #iframe-player-wrap,
  #room-screen #iframe-player {
    position: absolute !important;
    inset: 0;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: 0 !important;
    z-index: 1;
  }

  /* Keep native YT chrome non-interactive on mobile too */
  #room-screen #yt-player,
  #room-screen iframe#yt-player,
  #room-screen #video-wrap > iframe {
    pointer-events: none !important;
  }

  #room-screen .xp-yt-hitshield {
    z-index: 2;
  }

  #room-screen #local-player {
    object-fit: contain;
    background: #000;
  }

  #room-screen .xp-media-unlock {
    z-index: 20;
    padding: 20px;
  }

  #room-screen .xp-media-unlock-icon {
    width: 72px;
    height: 72px;
    font-size: 32px;
  }

  #room-screen .xp-media-unlock-text {
    font-size: 15px;
  }

  /* Keep transport controls clearly above page chrome */
  #room-screen .xp-controls {
    position: relative;
    z-index: 10;
  }

  #room-screen .xp-source-badge {
    font-size: 11px;
    padding: 5px 9px;
    top: 10px;
    left: 10px;
    z-index: 6;
  }

  #room-screen .xp-fullscreen-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    right: 10px;
    bottom: 10px;
    font-size: 20px;
    z-index: 8;
  }

  #room-screen .xp-video-placeholder {
    font-size: 14px;
    padding: 16px;
  }

  #room-screen .xp-upload-progress {
    order: 2;
    flex: 0 0 auto;
    width: 100%;
    padding: 6px 10px;
    background: #ece9d8;
  }

  /* ── 2. CONTROLS — immediately under video, finger-sized ── */
  #room-screen .xp-controls {
    order: 3;
    position: relative;
    z-index: 5;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 12px 12px;
    border: none;
    border-bottom: 1px solid #aca899;
    box-shadow: inset 0 1px 0 #fff;
    background: linear-gradient(180deg, #f5f3ec 0%, #e4e0d6 45%, #d4d0c8 100%);
  }

  #room-screen .xp-seek-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    min-width: 0;
  }

  #room-screen .xp-time {
    font-size: 12px;
    font-weight: bold;
    min-width: 40px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
  }

  #room-screen .xp-seekbar {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 48px;
    min-height: 48px;
    padding: 16px 0;
    touch-action: none;
    cursor: pointer;
  }

  #room-screen .xp-seekbar::-webkit-slider-runnable-track {
    height: 14px;
    border-radius: 2px;
  }

  #room-screen .xp-seekbar::-webkit-slider-thumb {
    width: 28px;
    height: 36px;
    margin-top: -11px;
  }

  #room-screen .xp-seekbar::-moz-range-track {
    height: 14px;
  }

  #room-screen .xp-seekbar::-moz-range-thumb {
    width: 28px;
    height: 36px;
  }

  #room-screen .xp-transport-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 12px;
    min-width: 0;
  }

  #room-screen .xp-transport {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex: 1 1 100%;
  }

  #room-screen .xp-transport-btn {
    width: 56px;
    height: 52px;
    min-width: 48px;
    min-height: 48px;
    font-size: 15px;
  }

  #room-screen .xp-transport-btn .icon-play {
    border-width: 10px 0 10px 16px;
    margin-left: 3px;
  }

  #room-screen .xp-transport-btn .icon-pause span {
    width: 6px;
    height: 18px;
  }

  #room-screen .xp-transport-btn .icon-stop {
    width: 16px;
    height: 16px;
  }

  #room-screen .xp-spacer {
    display: none;
  }

  #room-screen .xp-volume-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 55%;
    min-width: 0;
  }

  #room-screen .xp-speed-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
  }

  #room-screen .xp-volume-group label,
  #room-screen .xp-speed-group label {
    font-size: 11px;
    flex-shrink: 0;
  }

  #room-screen .xp-volume-slider {
    flex: 1 1 auto;
    width: auto;
    min-width: 72px;
    height: 48px;
    min-height: 48px;
    padding: 16px 0;
    touch-action: none;
    cursor: pointer;
  }

  #room-screen .xp-volume-slider::-webkit-slider-runnable-track {
    height: 12px;
  }

  #room-screen .xp-volume-slider::-webkit-slider-thumb {
    width: 26px;
    height: 32px;
    margin-top: -10px;
  }

  #room-screen .xp-volume-slider::-moz-range-track {
    height: 12px;
  }

  #room-screen .xp-volume-slider::-moz-range-thumb {
    width: 26px;
    height: 32px;
  }

  #room-screen .xp-select {
    height: 48px;
    min-height: 48px;
    font-size: 16px; /* avoids iOS zoom */
    padding: 0 10px;
    min-width: 78px;
  }

  #room-screen #volume-label {
    min-width: 34px;
    font-size: 11px;
    flex-shrink: 0;
  }

  /* ── 3. Source tools — XP blue title bar + body ── */
  #room-screen .xp-media-panel {
    order: 4;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0 0 6px;
    border: none;
    border-bottom: 1px solid #aca899;
    border-radius: 0;
    background: #ece9d8;
    box-shadow: none;
    overflow: hidden;
  }

  /* Full-width Windows XP title bar (replaces plain legend) */
  #room-screen .xp-media-panel legend {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    float: none;
    margin: 0;
    padding: 0 8px 0 6px;
    height: 28px;
    min-height: 28px;
    line-height: 28px;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.2px;
    color: #fff;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
    background: linear-gradient(
      180deg,
      #0997ff 0%,
      #0053ee 8%,
      #0050ee 40%,
      #06f 88%,
      #06f 93%,
      #005bff 95%,
      #003dd7 96%,
      #003dd7 100%
    );
    border: none;
    border-bottom: 1px solid #0039a6;
  }

  #room-screen .xp-media-panel legend::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 6px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #ff6b00, #ff0000 50%, #cc0000);
    border: 1px solid #800000;
    border-radius: 2px;
  }

  #room-screen .xp-media-panel > :not(legend) {
    margin-left: 10px;
    margin-right: 10px;
  }

  #room-screen .xp-media-panel > .xp-current-video {
    margin-top: 6px;
  }

  #room-screen .xp-current-video {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 4px 6px;
    margin-bottom: 4px;
  }

  #room-screen .xp-current-video-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #room-screen .xp-toolbar-grid {
    gap: 6px;
  }

  #room-screen .xp-toolbar-group > label {
    font-size: 11px;
  }

  #room-screen .xp-toolbar-input-row {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 6px;
  }

  #room-screen .xp-toolbar-input-row .xp-input {
    flex: 1 1 auto;
    min-width: 0;
  }

  #room-screen .xp-toolbar-input-row .xp-btn {
    flex: 0 0 auto;
    min-height: 48px;
    height: 48px;
    padding: 0 12px;
  }

  #room-screen .xp-toolbar-actions {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
  }

  #room-screen .xp-toolbar-actions .xp-btn {
    flex: 1 1 50%;
    min-width: 0;
    min-height: 48px;
    height: 48px;
    font-size: 12px;
    padding: 0 8px;
  }

  #room-screen .xp-input {
    height: 48px;
    min-height: 48px;
    font-size: 16px;
    padding: 4px 10px;
  }

  /* Status: single quiet line */
  #room-screen .xp-statusbar {
    order: 5;
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    padding: 4px 10px;
    font-size: 10px;
    border: none;
    border-bottom: 1px solid #aca899;
    background: #ece9d8;
  }

  #room-screen .xp-statusbar-secondary {
    display: none !important;
  }

  #room-screen #status-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }

  /* ── 4. ROOM PANEL — XP title bar + bottom invite ── */
  #room-screen #room-panel-titlebar,
  #room-screen #room-panel > .xp-titlebar {
    order: 6;
    display: flex !important;
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    height: 28px;
    min-height: 28px;
    padding: 0 8px 0 6px;
    font-size: 12px;
    border-radius: 0;
    /* Ensure classic blue XP bar is visible (not flattened away) */
    background: linear-gradient(
      180deg,
      #0997ff 0%,
      #0053ee 8%,
      #0050ee 40%,
      #06f 88%,
      #06f 93%,
      #005bff 95%,
      #003dd7 96%,
      #003dd7 100%
    ) !important;
    color: #fff;
  }

  #room-screen #room-panel-titlebar .xp-titlebar-text,
  #room-screen #room-panel > .xp-titlebar .xp-titlebar-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #room-screen .room-link-bar {
    order: 7;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    font-size: 13px;
    border: none;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #aca899;
    background: linear-gradient(180deg, #ffffe8 0%, #f0e8c8 100%);
    min-width: 0;
  }

  #room-screen .room-link-bar > span:first-child {
    flex-shrink: 0;
    font-weight: bold;
    font-size: 12px;
  }

  #room-screen .room-link-bar code {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #fff;
    border: 2px inset #aca899;
  }

  #room-screen .room-link-bar .xp-btn-small {
    flex: 0 0 auto;
    margin-left: 0;
    height: 48px;
    min-height: 48px;
    padding: 0 12px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
  }

  #room-screen .participants-body {
    order: 8;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    max-height: min(18dvh, 120px);
    min-height: 0;
    padding: 4px 10px max(10px, env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #ece9d8;
    border: none;
  }

  #room-screen .participants-body h3 {
    font-size: 11px;
    margin-bottom: 4px;
  }

  #room-screen .xp-participant {
    padding: 6px 6px;
    font-size: 12px;
    gap: 6px;
  }

  #room-screen .xp-avatar {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }

  #room-screen .xp-participant .xp-btn-transfer-host {
    height: 40px;
    min-height: 40px;
    font-size: 11px;
    padding: 0 8px;
  }

  /* Touch-friendly shared buttons (mobile only) */
  .xp-btn {
    height: 48px;
    min-height: 48px;
    font-size: 13px;
    padding: 0 14px;
  }

  .xp-btn-primary {
    height: 48px;
    min-height: 48px;
    font-size: 14px;
  }

  .xp-btn-small {
    height: 48px;
    min-height: 48px;
    font-size: 12px;
  }

  .xp-confirm-actions {
    flex-direction: column;
  }

  .xp-confirm-actions .xp-btn {
    width: 100%;
    min-width: 0;
    height: 48px;
  }

  .lobby-content {
    padding: 18px 14px 16px;
  }

  .lobby-content h2 { font-size: 16px; }
  .lobby-content p { font-size: 12px; }

  .lobby-actions .xp-btn-primary,
  .lobby-join-row .xp-btn {
    width: 100%;
  }

  .lobby-join-row {
    flex-direction: column;
    gap: 8px;
  }

  .xp-config-actions {
    flex-direction: column;
  }

  .xp-config-actions .xp-btn {
    width: 100%;
    height: 48px;
    margin-left: 0;
  }

  .xp-window {
    border-radius: 0;
    box-shadow: none;
  }
}

/* Small phones — still only ≤768 family */
@media (max-width: 480px) {
  #room-screen .xp-video-wrap {
    height: clamp(200px, 58dvh, 62dvh);
    max-height: 62dvh;
    min-height: 190px;
  }

  #room-screen .xp-controls {
    padding: 8px 10px 10px;
  }

  #room-screen .xp-transport-btn {
    width: 54px;
    height: 50px;
    min-width: 48px;
    min-height: 48px;
  }

  #room-screen .xp-speed-group label,
  #room-screen #volume-label {
    display: none;
  }

  #room-screen .room-link-bar {
    padding: 8px;
    gap: 6px;
  }

  #room-screen .room-link-bar .xp-btn-small {
    padding: 0 10px;
    font-size: 11px;
  }

  #room-screen .room-link-bar > span:first-child {
    display: none;
  }
}

@media (max-width: 360px) {
  #room-screen .xp-video-wrap {
    height: clamp(180px, 55dvh, 60dvh);
    min-height: 170px;
  }

  #room-screen .xp-transport-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }

  #room-screen .xp-volume-group label {
    display: none;
  }
}

/* Landscape phones only (narrow + short) — not desktop */
@media (max-width: 768px) and (max-height: 500px) and (orientation: landscape) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #room-screen .xp-video-wrap {
    height: clamp(140px, 52dvh, 58dvh);
    max-height: 58dvh;
    min-height: 120px;
  }

  #room-screen .xp-controls {
    padding: 6px 10px 8px;
  }

  #room-screen .participants-body {
    max-height: 80px;
  }
}

/* Touch devices in mobile width: reinforce 48px targets */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  #room-screen .xp-transport-btn {
    min-width: 48px;
    min-height: 48px;
  }

  #room-screen .xp-seekbar,
  #room-screen .xp-volume-slider {
    min-height: 48px;
    cursor: pointer;
  }

  #room-screen .xp-select {
    min-height: 48px;
  }

  #room-screen .xp-fullscreen-btn {
    min-width: 48px;
    min-height: 48px;
  }

  .xp-btn,
  .xp-btn-primary,
  .lobby-join-row .xp-btn {
    min-height: 48px;
  }
}