:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-floating: #111214;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --text-normal: #f2f3f5;
  --text-muted: #949ba4;
  --text-faint: #6d6f78;
  --danger: #da373c;
  --danger-hover: #a12d2f;
  --online: #23a55a;
  --avatar-colors: #5865f2, #eb459e, #57f287, #fee75c, #ed4245, #f0b232, #3ba55c, #faa61a;
  --overlay-btn-bg: rgba(97, 100, 107, 0.85);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "gg sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-normal);
  height: 100vh;
}

/* ---- Auth pages ---- */
body:not(.room) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: var(--bg-secondary);
  padding: 32px;
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.auth-card h1 {
  text-align: center;
  margin-top: 0;
  font-size: 24px;
}

.auth-card p.subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: 20px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-normal);
  margin-bottom: 16px;
  font-size: 15px;
}

button {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.auth-card button[type="submit"] {
  width: 100%;
  padding: 11px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 15px;
}

.auth-card button[type="submit"]:hover { background: var(--accent-hover); }

.error {
  background: rgba(218,55,60,0.15);
  color: #ff8085;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 16px;
  font-size: 14px;
  display: none;
}

/* ================= Discord-style call room ================= */
body.room {
  overflow: hidden;
  height: 100vh;
}

.discord-app {
  display: flex;
  height: 100vh;
}

/* Channel sidebar */
.channel-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
}

.server-header {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.channel-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8px 8px;
}

.voice-channel-header {
  padding: 6px 8px;
  color: var(--text-faint);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.participant-list {
  padding: 2px 8px 2px 28px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.participant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
}

.participant.clickable {
  cursor: pointer;
}

.participant.clickable:hover {
  background: var(--bg-primary);
}

.participant .avatar {
  width: 24px;
  height: 24px;
  font-size: 11px;
}

.participant-name {
  font-size: 14px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sharing-badge {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  border-radius: 999px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  color: white;
  background: var(--accent);
}

.avatar.emoji-avatar {
  font-size: 18px;
}

.participant .avatar.emoji-avatar {
  font-size: 14px;
}

.user-panel {
  height: 52px;
  flex-shrink: 0;
  padding: 0 8px;
  background: #232428;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-meta { flex: 1; min-width: 0; }
.user-meta .name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta .status {
  font-size: 11px;
  color: var(--online);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-primary); color: var(--text-normal); }

/* Main call area */
.call-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.call-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  gap: 12px;
  min-height: 0;
}

.call-stage:fullscreen,
.call-stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  background: #000;
}

/* Grid mode: all tiles flow centered, sized precisely by JS so the
   whole set always fits without scrolling. */
.call-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
}

/* Focus mode: only the selected tile is shown, filling the whole stage. */
.focus-main {
  display: none;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}

.call-stage.focus-mode .focus-main { display: flex; }
.call-stage.focus-mode .call-grid { display: none; }

.focus-main > .call-tile {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.call-stage:not(:fullscreen):not(:-webkit-full-screen) .focus-main > .call-tile {
  border-radius: 8px;
}

.call-tile {
  background: var(--bg-tertiary);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color 0.1s;
}

.call-stage:not(:fullscreen):not(:-webkit-full-screen) .call-tile:hover {
  outline-color: var(--accent);
}

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

.call-tile .avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-tile.has-video .avatar-fallback { display: none; }

.call-tile .avatar-fallback .avatar {
  width: 35%;
  height: auto;
  aspect-ratio: 1;
  max-width: 96px;
  max-height: 96px;
  min-width: 28px;
  min-height: 28px;
}

.call-tile .avatar-fallback .avatar svg {
  width: 55%;
  height: 55%;
  color: rgba(255, 255, 255, 0.9);
}

.call-tile .avatar-fallback .avatar.emoji-avatar {
  font-size: 32px;
}

.call-tile .tile-label {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100% - 12px);
}

.call-tile .tile-label .text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-tile .tile-label .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  flex-shrink: 0;
}

/* Blurred preview shown to viewers who haven't clicked "watch" yet */
.thumbnail-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(16px) brightness(0.55);
  transform: scale(1.12);
}

.watch-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
}

.watch-play-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  max-width: 85%;
  border-radius: 999px;
  background: var(--overlay-btn-bg);
  color: white;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.1s, transform 0.1s;
}

.watch-play-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.watch-play-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.watch-play-btn:hover {
  background: var(--accent);
  transform: scale(1.04);
}

.watch-play-btn.stop-variant:hover {
  background: var(--danger);
}

/* Shown over an already-playing stream; stays hidden until the mouse
   enters/moves inside the tile, then fades out again after a moment of
   stillness — like video-player controls. */
.stop-watch-overlay {
  flex-direction: row;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.call-tile.show-hover-ui .stop-watch-overlay {
  opacity: 1;
  pointer-events: auto;
}

.mute-stream-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--overlay-btn-bg);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
}

.mute-stream-btn svg {
  width: 18px;
  height: 18px;
}

.mute-stream-btn:hover {
  background: var(--accent);
  transform: scale(1.08);
}

/* Fixed in the tile's bottom-right corner, independent of the centered
   stop-watching pill. Bottom-anchored so the button itself never moves —
   the slider grows upward above it instead of pushing it sideways. */
.audio-control {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.call-tile.show-hover-ui .audio-control {
  opacity: 1;
  pointer-events: auto;
}

/* The slider only appears while hovering the volume button itself. */
.volume-slider-wrap {
  width: 40px;
  height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  opacity: 0;
  transition: height 0.15s, opacity 0.15s;
}

.audio-control:hover .volume-slider-wrap,
.audio-control:focus-within .volume-slider-wrap {
  height: 90px;
  opacity: 1;
}

/* Mirrors .audio-control but in the opposite (bottom-left) corner: lets a
   viewer pick their own playback quality, independent of the sharer's
   controls and of the volume control on the other side. */
.tile-quality-control {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.call-tile.show-hover-ui .tile-quality-control {
  opacity: 1;
  pointer-events: auto;
}

.tile-quality-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: auto;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  margin: 0;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transform: rotate(-90deg);
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: white;
  cursor: pointer;
}

.volume-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
}

/* Custom tooltip (replaces the native title attribute) so it can share the
   same mouse-activity fade as the rest of the hover UI. */
.tile-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 1;
}

.call-tile.show-hover-ui .tile-hint {
  opacity: 1;
}

/* Voice-connected bar (sidebar, above the user panel) */
.voice-status-bar {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
}

/* Stop + quality controls only make sense while actively sharing */
.voice-status-bar #qualityBtn,
.voice-status-bar #stopShareBtn {
  display: none;
}

.voice-status-bar.sharing #qualityBtn,
.voice-status-bar.sharing #stopShareBtn {
  display: flex;
}

.voice-status-text {
  flex: 1;
  min-width: 0;
}

.voice-status-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.voice-status-channel {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}

.voice-icon-btn svg {
  width: 17px;
  height: 17px;
}

.voice-icon-btn:hover { background: var(--bg-primary); color: var(--text-normal); }

.voice-icon-btn.share-btn.active {
  background: var(--online);
  color: #06140c;
}

.voice-icon-btn.share-btn.active:hover { background: #1c8b4c; }

.voice-icon-btn.danger:hover { background: var(--danger); color: white; }


.quality-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  right: 10px;
  z-index: 10;
  background: var(--bg-floating);
  border-radius: 6px;
  padding: 4px;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.quality-menu.show { display: flex; }

.quality-menu-item {
  text-align: left;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.quality-menu-item:hover {
  background: var(--bg-primary);
  color: var(--text-normal);
}

.quality-menu-item.active {
  background: var(--accent);
  color: white;
}

/* Settings modal (nickname + avatar) */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.show { display: flex; }

.settings-modal {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.settings-modal h2 {
  margin: 0 0 20px;
  font-size: 18px;
}

.settings-modal label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.settings-modal input[type="text"] {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-normal);
  margin-bottom: 20px;
  font-size: 15px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.avatar-option {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.1s, background 0.1s;
}

.avatar-option.default-option {
  color: var(--text-muted);
}

.avatar-option.default-option svg {
  width: 55%;
  height: 55%;
}

.avatar-option:hover {
  background: var(--bg-primary);
}

.avatar-option.selected {
  outline-color: var(--accent);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.color-option {
  aspect-ratio: 1;
  border-radius: 50%;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.1s, transform 0.1s;
}

.color-option:hover {
  transform: scale(1.08);
}

.color-option.selected {
  outline-color: var(--text-normal);
}

.color-option.auto-color-option {
  background: var(--bg-tertiary);
  position: relative;
}

.color-option.auto-color-option::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 60%;
  height: 2px;
  background: var(--text-muted);
  transform: rotate(-45deg);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.settings-cancel,
.settings-save {
  padding: 10px 18px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 14px;
}

.settings-cancel {
  background: transparent;
  color: var(--text-muted);
}

.settings-cancel:hover { color: var(--text-normal); }

.settings-save {
  background: var(--accent);
  color: white;
}

.settings-save:hover { background: var(--accent-hover); }
