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

:root {
  /* Discord's actual dark-theme palette */
  --bg-0: #1e1f22;
  --bg-1: #2b2d31;
  --bg-2: #313338;
  --bg-3: #383a40;
  --bg-hover: #2e3035;
  --text: #dbdee1;
  --text-bright: #f2f3f5;
  --text-dim: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --red: #da373c;
  --gold: #f0b232;
}

html, body { height: 100%; }

body {
  font-family: "gg sans", "Noto Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  line-height: 1.35;
}

.hidden { display: none !important; }

.screen { height: 100vh; height: 100dvh; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg-0); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Lobby ---------- */
#lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #5865f2 0%, #404eed 60%, #3442d9 100%);
}

.lobby-card {
  background: var(--bg-2);
  border-radius: 8px;
  padding: 32px;
  width: min(440px, 92vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.lobby-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin-bottom: 14px;
}

.lobby-card h1 {
  margin-bottom: 4px;
  color: var(--text-bright);
  font-size: 24px;
}
.tagline { color: var(--text-dim); margin-bottom: 20px; font-size: 14px; }

.lobby-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: none;
  border-radius: 4px;
  background: var(--bg-0);
  color: var(--text);
  font-size: 16px; /* ≥16px stops iOS Safari zooming in on focus */
  outline: none;
}
.lobby-card input:focus { outline: 2px solid var(--accent); }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; margin-bottom: 0; }

button {
  border: none;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }

.error { color: var(--red); margin-top: 10px; font-size: 14px; }

.lobby-card h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 22px 0 8px;
  letter-spacing: 0.04em;
}

#room-list { list-style: none; max-height: 300px; overflow-y: auto; }

.room-item {
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
}
.room-item:hover { background: var(--bg-3); }
.room-item:hover .room-name { color: var(--text-bright); }

.room-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-icon { display: flex; flex-shrink: 0; }
.room-icon svg { width: 18px; height: 18px; }
.room-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-row .count, #sidebar-rooms .count {
  color: var(--text-dim);
  font-size: 12px;
  flex-shrink: 0;
}
.room-members {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 3px 0 0 26px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* In-room quick-hop room list */
#sidebar-rooms {
  list-style: none;
  max-height: 35%;
  overflow-y: auto;
  flex-shrink: 0;
}
#sidebar-rooms li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 14.5px;
  color: var(--text-dim);
  cursor: pointer;
}
#sidebar-rooms li:hover { background: var(--bg-3); color: var(--text); }
#sidebar-rooms li.active { background: var(--bg-3); color: var(--text-bright); }
#sidebar-rooms li .room-name { font-size: 14.5px; color: inherit; }
#sidebar-rooms li .room-icon svg { width: 16px; height: 16px; }

/* ---------- Room layout ---------- */
#room { display: flex; }

#sidebar {
  width: 240px;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 8px;
}

#room-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-bright);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--bg-0);
  overflow: hidden;
  white-space: nowrap;
}
.title-logo { width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0; }
#room-title-text { overflow: hidden; text-overflow: ellipsis; }

#sidebar h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  padding: 4px 8px 0;
}

.add-btn {
  background: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.add-btn:hover { background: none; color: var(--text-bright); }

/* Text channel list in the sidebar */
#text-list {
  list-style: none;
  max-height: 30%;
  overflow-y: auto;
  flex-shrink: 0;
}
#text-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 14.5px;
  color: var(--text-dim);
  cursor: pointer;
}
#text-list li:hover { background: var(--bg-3); color: var(--text); }
#text-list li.active { background: var(--bg-3); color: var(--text-bright); }
#text-list .hash { font-weight: 600; width: 16px; text-align: center; flex-shrink: 0; }
#text-list li .room-name { font-size: 14.5px; color: inherit; }
.side-dot { position: static; margin-left: auto; flex-shrink: 0; }

#member-list { list-style: none; flex: 1; overflow-y: auto; }
#member-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 15px;
  color: var(--text-dim);
}
#member-list li:hover { background: var(--bg-3); color: var(--text-bright); }

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#member-list .badges { margin-left: auto; display: flex; gap: 4px; font-size: 13px; }
#member-list .host-crown { color: var(--gold); }
#member-list .host-actions { display: none; gap: 4px; }
#member-list li:hover .host-actions { display: flex; }
#member-list .host-actions button {
  padding: 3px 8px;
  font-size: 11px;
  background: var(--bg-0);
}
#member-list .host-actions button:hover { background: var(--red); }

#leave-btn { background: var(--red); }
#leave-btn:hover { background: #a12d31; }

/* ---------- Main / video ---------- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  min-width: 0;
}

#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--text-dim);
  text-align: center;
  font-size: 15px;
  line-height: 1.6;
}
.welcome-logo { width: 96px; height: 96px; border-radius: 24px; opacity: 0.85; }

#video-grid {
  flex: 1;
  display: grid;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-content: center;
}

.tile {
  position: relative;
  background: var(--bg-0);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile.speaking { outline: 3px solid var(--green); }

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tile.cam-off video { display: none; }

.tile .avatar {
  display: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 30px;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.tile.cam-off .avatar { display: flex; }

.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 13px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.tile .label .muted { color: var(--red); }
.tile .label .label-icon { display: flex; }
.tile .label .label-icon svg { width: 13px; height: 13px; }

.tile { cursor: pointer; }

/* Screen shares: never crop the content */
.screen-tile video { object-fit: contain; background: #000; display: block; }

/* ---- Spotlight: click a tile to make it the main view ---- */
#video-grid.has-focus {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: flex-start;
}
#video-grid.has-focus .tile.focused {
  order: -1;
  flex: 1 1 100%;
  aspect-ratio: unset;
  height: min(64vh, 70%);
}
#video-grid.has-focus .tile.focused video { object-fit: contain; background: #000; }
#video-grid.has-focus .tile:not(.focused) {
  flex: 0 0 200px;
  aspect-ratio: 16 / 9;
}

/* Picture-in-picture button (top-left of remote tiles) */
.pip-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: var(--text);
}
.pip-btn svg { width: 16px; height: 16px; }
.tile:hover .pip-btn { display: flex; }
.pip-btn:hover { background: var(--accent); color: white; }
@media (hover: none) {
  .tile .pip-btn { display: flex; }
}

/* Per-person volume slider (top-right of each remote tile) */
.tile .vol {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 6px;
  padding: 5px 9px;
}
.tile:hover .vol { display: flex; }
@media (hover: none) {
  .tile .vol { display: flex; }
}
.vol-icon { display: flex; color: var(--text); }
.vol-icon svg { width: 15px; height: 15px; }
.tile .vol input[type="range"] {
  width: 88px;
  accent-color: var(--accent);
  cursor: pointer;
}
.vol-pct {
  font-size: 11.5px;
  color: var(--text);
  min-width: 34px;
  text-align: right;
}

#controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px;
}

.ctrl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 21px;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctrl:hover { background: var(--bg-1); }
.ctrl.off { background: var(--red); }
.ctrl.active { background: var(--green); }

/* ---------- SVG icons ---------- */
.icon { display: flex; align-items: center; justify-content: center; }
.ctrl .icon svg { width: 24px; height: 24px; }
#mobile-bar .icon svg { width: 21px; height: 21px; }
.host-crown svg { width: 16px; height: 16px; display: block; }
.tile .label .muted svg { width: 14px; height: 14px; display: block; }

/* ---------- Chat ---------- */
#chat {
  width: 340px;
  background: var(--bg-2);
  border-left: 1px solid var(--bg-0);
  display: flex;
  flex-direction: column;
}

/* ---------- Channel tabs ---------- */
#channel-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--bg-0);
  flex-shrink: 0;
  scrollbar-width: none;
}
#channel-tabs::-webkit-scrollbar { display: none; }

.channel-tab {
  background: none;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  position: relative;
  flex-shrink: 0;
}
.channel-tab:hover { background: var(--bg-3); color: var(--text); }
.channel-tab.active { background: var(--bg-3); color: var(--text-bright); }
.channel-tab.add { font-size: 16px; padding: 5px 10px; }

.unread-dot {
  position: absolute;
  top: 3px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
}

.msg {
  display: flex;
  gap: 12px;
  padding: 6px 14px;
  position: relative;
}
.msg:hover { background: var(--bg-hover); }

.msg-delete {
  display: none;
  position: absolute;
  top: 4px;
  right: 10px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
}
.msg:hover .msg-delete { display: block; }
.msg-delete:hover { background: var(--red); color: white; }
@media (hover: none) {
  .msg .msg-delete { display: block; }
}

.channel-delete {
  margin-left: 6px;
  color: var(--text-dim);
  font-size: 14px;
}
.channel-delete:hover { color: var(--red); }

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg .content { min-width: 0; flex: 1; }
.msg .meta { font-size: 12px; color: var(--text-dim); margin-bottom: 1px; }
.msg .meta .author {
  color: var(--text-bright);
  font-weight: 600;
  font-size: 15px;
  margin-right: 6px;
}
.msg .body { font-size: 14.5px; word-wrap: break-word; color: var(--text); }
.msg.system {
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
  padding: 4px 14px;
}
.msg.system:hover { background: none; }

#typing-indicator {
  min-height: 18px;
  padding: 0 16px 2px;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* GIF messages */
.msg .gif {
  max-width: min(260px, 100%);
  border-radius: 8px;
  margin-top: 4px;
  display: block;
}

/* GIF picker */
#gif-picker {
  border-top: 1px solid var(--bg-0);
  padding: 10px 12px;
  background: var(--bg-1);
}
#gif-picker input {
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 6px;
  background: var(--bg-0);
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 8px;
}
#gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
#gif-results img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
}
#gif-results img:hover { outline: 2px solid var(--accent); }
.gif-note {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px 4px;
}

#gif-btn {
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
  border-radius: 8px;
}
#gif-btn:hover { background: var(--bg-1); color: var(--text-bright); }

#chat-form {
  display: flex;
  gap: 8px;
  padding: 0 12px 14px;
}
#chat-form input {
  flex: 1;
  padding: 11px 14px;
  border: none;
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text);
  font-size: 16px;
  outline: none;
  min-width: 0;
}
#chat-form input::placeholder { color: var(--text-dim); }
#chat-form button { border-radius: 8px; }

/* ---------- Reconnect toast ---------- */
#reconnect-toast {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--bg-0);
  color: var(--text-bright);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
}
#reconnect-toast.hidden { display: none; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile top bar & backdrop (hidden on desktop) ---------- */
#mobile-bar {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--bg-1);
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--bg-0);
}
#mobile-bar button {
  position: relative;
  background: var(--bg-3);
  width: 42px;
  height: 42px;
  border-radius: 8px;
  font-size: 19px;
  padding: 0;
  flex-shrink: 0;
}
#mobile-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red);
  color: white;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

#backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
}

/* Touch devices have no hover: always show the host's mute/kick buttons */
@media (hover: none) {
  #member-list .host-actions { display: flex; }
}

/* ---------- Phone layout ---------- */
@media (max-width: 768px) {
  #room { flex-direction: column; }
  #mobile-bar { display: flex; }

  /* Members & chat become slide-in drawers */
  #sidebar, #chat {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: min(80vw, 320px);
    transition: transform 0.25s ease;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
  }
  #sidebar { left: 0; transform: translateX(-105%); box-shadow: 4px 0 24px rgba(0,0,0,0.4); }
  #chat { right: 0; transform: translateX(105%); box-shadow: -4px 0 24px rgba(0,0,0,0.4); border-left: none; background: var(--bg-1); }
  #sidebar.open, #chat.open { transform: translateX(0); }

  #video-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px;
    padding: 8px;
  }
  .tile { aspect-ratio: 4 / 3; }
  .tile .avatar { width: 56px; height: 56px; font-size: 24px; }
  .tile .label { font-size: 12px; padding: 2px 7px; }

  #video-grid.has-focus .tile.focused { height: 42vh; }
  #video-grid.has-focus .tile:not(.focused) { flex: 0 0 130px; }

  /* Bigger touch targets, clear of the home indicator */
  #controls {
    gap: 16px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }
  .ctrl { width: 58px; height: 58px; font-size: 24px; }

  #chat-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .msg-avatar { width: 34px; height: 34px; font-size: 14px; }
}
