* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #0d0d0f;
  color: #e8e8ed;
  -webkit-font-smoothing: antialiased;
}

/* Landing */
#landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
  height: 100vh; height: 100dvh;
  text-align: center;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-icon { width: 40px; height: 40px; border-radius: 8px; }
.brand-name { font-size: 22px; font-weight: 700; color: #c285e4; }
.brand-sub { font-size: 13px; color: #6b5b7a; margin-bottom: 4px; }
.mobile-name-bar { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 14px; }
.mobile-name-value { color: #c285e4; font-weight: 600; }
.mobile-name-edit { background: transparent; border: none; cursor: pointer; color: #666; padding: 2px; display: flex; transition: color 0.2s; }
.mobile-name-edit:hover { color: #c285e4; }
.brand-hint { font-size: 11px; color: #4a3d54; margin-bottom: 24px; }
.code-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}
#roomCodeInput {
  width: 100%;
  padding: 14px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 8px;
  border: 2px solid #2e2638;
  border-radius: 12px;
  background: #151218;
  color: #e8e8ed;
  outline: none;
  font-family: inherit;
}
#roomCodeInput:focus { border-color: #7c3aed; }
#roomCodeInput::placeholder { letter-spacing: 1px; color: #4a3d52; font-size: 14px; }
.btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: #c285e4;
  color: #0d0d0f;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: #dbb5f0; }
.btn-secondary {
  width: 100%;
  max-width: 300px;
  padding: 14px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: 12px;
  background: #1a1520;
  color: #c285e4;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active { background: #252033; }
#installBtn {
  width: 100%;
  max-width: 300px;
  margin-top: 10px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
#installBtn:active { opacity: 0.8; }
#installBtn svg { flex-shrink: 0; }
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 300px;
  color: #4a3d52;
  font-size: 12px;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #2e2638; }
#error {
  color: #f87171;
  font-size: 14px;
  min-height: 20px;
  margin-top: 4px;
}

/* Room */
#room {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100vh; height: 100dvh;
  background: #0d0d0f;
}
#roomHeader {
  display: flex;
  flex-direction: column;
  padding: 6px 14px;
  background: #151218;
  border-bottom: 1px solid #2e2638;
  flex-shrink: 0;
  gap: 2px;
}
.header-row { display: flex; align-items: center; justify-content: space-between; }
.header-right { display: flex; align-items: center; gap: 8px; }
#roomName { font-size: 15px; font-weight: 700; color: #c285e4; }
#roomSuffix { font-size: 12px; color: #8a7a9a; }
.room-peers { font-size: 12px; color: #6b5b7a; }
#leaveBtn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #c285e4;
  border-radius: 8px;
  background: transparent;
  color: #c285e4;
  cursor: pointer;
}

/* Fullscreen mode */
#room.fullscreen { position: fixed; inset: 0; z-index: 9999; }
#room.fullscreen #roomHeader { display: none; }
#room.fullscreen #faces.screen-mode {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 0;
}
#room.fullscreen #faces.screen-mode #screenContainer {
  position: absolute;
  inset: 0;
  max-height: none;
  border-radius: 0;
  z-index: 1;
}
#room.fullscreen #faces.screen-mode #screenVideo {
  height: 100%;
  object-fit: contain;
  aspect-ratio: auto;
}
#room.fullscreen #faces.screen-mode #peerList {
  position: absolute;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: auto;
  max-width: 70vw;
  gap: 4px;
  flex-direction: row;
  align-items: center;
}
#room.fullscreen #faces.screen-mode #peerList #localVideo,
#room.fullscreen #faces.screen-mode #peerList .remote-peer {
  width: 72px; height: 72px;
  flex-shrink: 0;
  border-radius: 6px;
}
#room.fullscreen #faces.screen-mode #peerList #localVideo {
  order: 99;
  transform: scaleX(-1);
}

/* Landscape fullscreen: screen left, cameras stacked right */
@media (orientation: landscape) {
  #room.fullscreen #faces.screen-mode #screenContainer {
    right: 110px;
  }
  #room.fullscreen #faces.screen-mode #peerList {
    left: auto;
    right: 4px;
    top: 4px;
    bottom: 60px;
    width: 100px;
    max-width: none;
    transform: none;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
    align-items: center;
  }
  #room.fullscreen #faces.screen-mode #peerList #localVideo,
  #room.fullscreen #faces.screen-mode #peerList .remote-peer {
    width: 76px; height: 76px;
  }
}

/* Controls overlay in fullscreen */
#room.fullscreen #controls.overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 110;
  background: rgba(21,18,24,0.5);
  backdrop-filter: blur(8px);
  border-top: none;
  transition: opacity 0.3s;
}
#room.fullscreen #controls.overlay.auto-hide {
  opacity: 0;
  pointer-events: none;
}

/* Video grid */
#faces {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  padding: 4px;
  gap: 4px;
  overflow-y: auto;
  position: relative;
}
#localVideo {
  width: calc(50% - 2px);
  aspect-ratio: 1/1;
  border-radius: 10px;
  background: #000;
  transform: scaleX(-1);
  object-fit: cover;
  order: -1;
}
#peerList {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}
.remote-peer {
  width: calc(50% - 2px);
  aspect-ratio: 1/1;
  position: relative;
  background: #151218;
  border-radius: 10px;
  overflow: hidden;
}
.remote-peer video {
  width: 100%; height: 100%;
  display: block;
  object-fit: cover;
  background: #000;
}

@media (orientation: landscape) {
  #localVideo, .remote-peer { width: calc(33% - 4px); }
}

/* Screen share */
#screenContainer {
  display: none;
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
#screenVideo {
  width: 100%;
  display: block;
  background: #000;
  aspect-ratio: 16/9;
}
.screen-only { display: none !important; }

/* Screen mode: screen on top, cameras at bottom */
#faces.screen-mode {
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: stretch;
}
#faces.screen-mode #screenContainer {
  flex: 1;
  width: 100%;
  max-height: 60vh;
  display: block;
  border-radius: 8px;
  order: 0;
}
#faces.screen-mode #screenVideo {
  height: 100%;
  aspect-ratio: auto;
  object-fit: contain;
}
#faces.screen-mode #peerList {
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: center;
  gap: 4px;
  padding: 2px 4px;
  order: 1;
  scrollbar-width: none;
  align-items: center;
}
#faces.screen-mode #peerList::-webkit-scrollbar { display: none; }
#faces.screen-mode #peerList #localVideo,
#faces.screen-mode #peerList .remote-peer {
  width: 68px; height: 68px;
  flex-shrink: 0;
  border-radius: 6px;
}
#faces.screen-mode #peerList .remote-peer video { border-radius: 6px; }
#faces.screen-mode #peerList #localVideo { order: 99; transform: scaleX(-1); }

/* Controls bar — logo-purple icons on dark background */
#controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #151218;
  border-top: 1px solid #2e2638;
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ctrl-btn {
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: #2e2638;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s, opacity 0.15s;
  color: #c285e4;
}
.ctrl-btn:active { opacity: 0.7; }
.ctrl-btn.on { box-shadow: inset 0 0 0 2px #7c3aed; }
.ctrl-btn.off { box-shadow: inset 0 0 0 2px #666; color: #999; }
.ctrl-btn.ptt-mode { opacity: 0.5; box-shadow: inset 0 0 0 2px #666; color: #888; }
.ctrl-btn.ptt-active { box-shadow: 0 0 16px rgba(34,197,94,0.6), inset 0 0 0 2px #22c55e; color: #22c55e; }
.ctrl-btn svg { display: block; width: 20px; height: 20px; }
.ctrl-btn-sm { width: 42px; height: 42px; flex-shrink: 0; }
.ctrl-btn-sm svg { width: 20px; height: 20px; }

/* Connection status toast */
#statusToast {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #e8e8ed;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 200;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  border: 1px solid #2e2638;
  pointer-events: none;
}

/* Landing bottom links */
.landing-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  margin-top: 12px;
}
.landing-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: 10px;
  background: #1a1520;
  border: 1px solid #2e2638;
  cursor: pointer;
  font-size: 12px;
  color: #c6c0cc;
  transition: border-color 0.2s, background 0.2s;
}
.landing-card:active {
  border-color: #7c3aed;
  background: rgba(124,58,237,0.08);
}
.landing-card-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(124,58,237,0.15);
  color: #c285e4;
  flex-shrink: 0;
}
.landing-card-text {
  white-space: nowrap;
}

/* Help modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,8,12,0.8);
  backdrop-filter: blur(6px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-content {
  background: #151218;
  border: 1px solid #2e2638;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 16px 64px rgba(0,0,0,0.6);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #6b5b7a;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}
.modal-close:active { color: #c285e4; }
.modal-content h2 {
  font-size: 20px;
  color: #c285e4;
  margin-bottom: 16px;
}
.modal-content h3 {
  font-size: 14px;
  color: #e8e8ed;
  margin-top: 20px;
  margin-bottom: 10px;
  font-weight: 600;
}
.help-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.help-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.4;
  color: #c6c0cc;
}
.help-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.help-item-icon.c-purple {
  background: rgba(124,58,237,0.15);
  color: #c285e4;
}
.help-item-icon.c-green {
  background: rgba(34,197,94,0.15);
  color: #22c55e;
}
.help-donate {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.donate-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: #1a1520;
  border: 1px solid #2e2638;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.donate-card:active {
  border-color: #7c3aed;
  background: rgba(124,58,237,0.08);
}
.donate-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(124,58,237,0.15);
  color: #c285e4;
  flex-shrink: 0;
}
.donate-card-text {
  display: flex;
  flex-direction: column;
}
.donate-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #e8e8ed;
}
.donate-card-sub {
  font-size: 11px;
  color: #6b5b7a;
  margin-top: 2px;
}

/* Chat */
.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,13,15,0.07);
  flex-direction: column;
  justify-content: flex-end;
  z-index: 10000;
}
.chat-panel {
  background: rgba(26,21,32,0.17);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  max-height: 50vh;
  display: flex;
  flex-direction: column;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #c285e4;
  flex-shrink: 0;
}
.chat-close {
  background: none;
  border: none;
  color: #6b5b7a;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px;
  max-height: 35vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-msg {
  background: rgba(46,38,56,0.15);
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 80%;
  align-self: flex-start;
  font-size: 13px;
  line-height: 1.4;
}
.chat-msg-self {
  background: rgba(59,47,74,0.15);
  align-self: flex-end;
}
.chat-msg-author {
  font-size: 11px;
  color: #c285e4;
  display: block;
  margin-bottom: 2px;
  font-weight: 600;
}
.chat-msg-text {
  color: #e8e8ed;
  word-break: break-word;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1;
  background: rgba(13,13,15,0.15);
  border: 1px solid rgba(46,38,56,0.1);
  border-radius: 8px;
  padding: 10px 12px;
  color: #e8e8ed;
  font-size: 14px;
  outline: none;
}
.chat-input-row input:focus {
  border-color: #7c3aed;
}
.chat-send {
  background: #7c3aed;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:active {
  background: #6d28d9;
}

/* Reaction Picker */
.reaction-picker {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,21,32,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(46,38,56,0.5);
  border-radius: 24px;
  padding: 8px 14px;
  display: flex;
  gap: 6px;
  z-index: 10000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.reaction-emoji {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 50%;
  transition: transform 0.15s;
}
.reaction-emoji:active {
  transform: scale(1.3);
}

/* Floating Reactions */
.reaction-float {
  position: absolute;
  bottom: 30%;
  font-size: 40px;
  pointer-events: none;
  z-index: 98;
  will-change: transform, opacity;
}

.lang-switch {
  position: fixed;
  bottom: 12px;
  right: 12px;
  background: rgba(30,25,38,0.7);
  border: 1px solid rgba(124,58,237,0.25);
  border-radius: 10px;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #c285e4;
  cursor: pointer;
  z-index: 50;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.2s;
}
.lang-switch:active { background: rgba(124,58,237,0.2); }
