/*
PANMOX Relay - Free Software Video Chat
Copyright (C) 2026 PANMOX
Licensed under GPL v3 - see LICENSE file
*/

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

:root {
  --bg: #000;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --text-secondary: rgba(255, 255, 255, 0.45);
  --accent: #0a84ff;
  --danger: #ff453a;
  --radius: 14px;
  --radius-lg: 20px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Lobby ─── */

#lobby {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem 1rem;
  background: linear-gradient(160deg, #0a0a0a 0%, #111 50%, #0a0a0a 100%);
}

.lobby-card {
  text-align: center;
  padding: 1.5rem 1.5rem 1.25rem;
  background: var(--surface);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  width: 340px;
  margin: auto;
}

.logo-mark {
  width: 40px;
  height: 40px;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5856d6);
  opacity: 0.9;
}

/* Device selects */

.device-selects {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  text-align: left;
}

.device-selects label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.select-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-left: 0.15rem;
}

.device-selects select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.device-selects select:focus {
  border-color: rgba(10, 132, 255, 0.5);
}

.device-selects select option {
  background: #1a1a1a;
  color: var(--text);
}

/* Camera preview */

#preview-area {
  width: 100%;
  height: 100px;
  border-radius: 10px;
  overflow: hidden;
  background: #111;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
}

#preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lobby-card h1 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 0.15rem;
  color: var(--text);
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 400;
  margin-bottom: 1rem;
}

/* Buttons */

.btn {
  display: block;
  width: 100%;
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: -0.1px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #3a9bff;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  flex-shrink: 0;
  width: auto;
  padding: 0.7rem 1.25rem;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Divider */

.divider {
  display: flex;
  align-items: center;
  margin: 0.75rem 0;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 400;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 0.75rem;
}

/* Join input group */

.join-group {
  display: flex;
  gap: 0.5rem;
}

.join-group input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.join-group input:focus {
  border-color: rgba(10, 132, 255, 0.5);
  background: rgba(255, 255, 255, 0.06);
}

.join-group input::placeholder {
  color: var(--text-secondary);
}

/* ─── Call Screen ─── */

#call {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #000;
}

#videos {
  flex: 1;
  position: relative;
}

/* Remote video (main) */

#remote-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
}

/* Pulsing ring animation while waiting */

.pulse-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(10, 132, 255, 0.3);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.15); opacity: 0.8; }
}

/* Local video (picture-in-picture) */

#local-container {
  position: absolute;
  bottom: 7rem;
  right: 1.25rem;
  width: 180px;
  height: 135px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #111;
  z-index: 10;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s ease;
}

#local-container:hover {
  transform: scale(1.03);
}

#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Fullscreen button ─── */

.btn-fullscreen {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  z-index: 15;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

#remote-container:hover .btn-fullscreen {
  opacity: 1;
}

.btn-fullscreen:hover {
  background: rgba(0, 0, 0, 0.7);
}

/* ─── Hand raised indicator ─── */

.hand-indicator {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.5rem;
  z-index: 15;
  animation: handBounce 0.6s ease infinite alternate;
  pointer-events: none;
}

@keyframes handBounce {
  from { transform: translateX(-50%) translateY(0); }
  to { transform: translateX(-50%) translateY(-8px); }
}

/* ─── Connection status ─── */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.good { background: #30d158; }
.status-dot.medium { background: #ffd60a; }
.status-dot.poor { background: var(--danger); }
.status-dot.connecting {
  background: #ffd60a;
  animation: pulse 1s ease-in-out infinite;
}

/* ─── Bandwidth display ─── */

.bandwidth {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.bandwidth:empty { display: none; }

/* ─── Recording state ─── */

.btn-control.recording {
  background: var(--danger);
  animation: recPulse 1.5s ease-in-out infinite;
}

.btn-control.recording:hover {
  background: #ff6961;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ─── Hand raised (active) ─── */

.btn-control.hand-active {
  background: #ffd60a;
  color: #000;
}

.btn-control.hand-active:hover {
  background: #ffe566;
}

/* ─── Room Info Bar ─── */

#room-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem;
  background: transparent;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

#room-code-display {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  letter-spacing: 2px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--surface);
}

/* ─── Controls Bar ─── */

#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1rem 1rem 1.5rem;
  background: transparent;
}

.btn-control {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-control:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(1.06);
}

.btn-control:active {
  transform: scale(0.95);
}

.btn-control .icon {
  width: 22px;
  height: 22px;
}

.btn-control .label {
  display: none;
}

/* Off state (muted / cam off) */

.btn-control.off {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.35);
}

.btn-control.off:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Danger (hang up) */

.btn-danger {
  background: var(--danger);
  width: 56px;
  height: 56px;
  margin: 0 0.5rem;
}

.btn-danger:hover {
  background: #ff6961;
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 40, 40, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  padding: 0.55rem 1.1rem;
  border-radius: 100px;
  font-size: 0.82rem;
  font-weight: 450;
  z-index: 100;
  border: 1px solid var(--border);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 1.8s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ─── Name input ─── */

.name-group {
  margin-bottom: 0.75rem;
}

.name-group input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  outline: none;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.name-group input:focus {
  border-color: rgba(10, 132, 255, 0.5);
  background: rgba(255, 255, 255, 0.06);
}

.name-group input::placeholder {
  color: var(--text-secondary);
}

/* ─── Video name labels ─── */

.video-name {
  position: absolute;
  bottom: 0.6rem;
  left: 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  z-index: 5;
  pointer-events: none;
}

.video-name:empty {
  display: none;
}

#local-container .video-name {
  font-size: 0.7rem;
  bottom: 0.4rem;
  left: 0.5rem;
}

/* ─── Leave modal ─── */

#leave-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  background: rgba(30, 30, 30, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  text-align: center;
  min-width: 260px;
  animation: toastIn 0.2s ease;
}

.modal-card p {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}

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

.modal-actions .btn {
  flex: 1;
  padding: 0.6rem 1rem;
}

.btn-leave {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-leave:hover {
  background: #ff6961;
}

/* ─── Device Switcher ─── */

#device-switcher {
  position: fixed;
  bottom: 6.5rem;
  left: 50%;
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 320px;
  padding: 0.5rem;
  background: rgba(30, 30, 30, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid var(--border);
  z-index: 55;
  animation: toastIn 0.2s ease;
}

.switcher-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.3rem 0.6rem 0.4rem;
}

.switcher-options {
  display: flex;
  flex-direction: column;
}

.switcher-opt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.switcher-opt:hover {
  background: rgba(255, 255, 255, 0.08);
}

.switcher-opt.active {
  color: var(--accent);
}

.switcher-opt .check {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  font-size: 0.75rem;
}

/* ─── Emoji Picker ─── */

#emoji-picker {
  position: fixed;
  bottom: 6.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.6rem;
  background: rgba(30, 30, 30, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 100px;
  border: 1px solid var(--border);
  z-index: 50;
  animation: toastIn 0.2s ease;
}

.emoji-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.2);
}

.emoji-btn:active {
  transform: scale(0.9);
}

/* Floating emoji reaction */

.emoji-float {
  position: fixed;
  font-size: 2.5rem;
  z-index: 200;
  pointer-events: none;
  animation: emojiRise 2s ease-out forwards;
}

@keyframes emojiRise {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  50% { opacity: 1; transform: translateY(-120px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-220px) scale(0.8); }
}

/* ─── Chat Panel ─── */

#chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#chat-messages::-webkit-scrollbar {
  width: 4px;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.chat-msg {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chat-sender {
  font-size: 0.68rem;
  font-weight: 600;
  opacity: 0.7;
  letter-spacing: 0.2px;
}

.chat-msg.sent {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.received {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

#chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

#chat-input:focus {
  border-color: rgba(10, 132, 255, 0.5);
}

#chat-input::placeholder {
  color: var(--text-secondary);
}

#btn-send {
  color: var(--accent);
}

#btn-send:hover {
  color: #3a9bff;
  background: transparent;
}

/* ─── Mobile / Responsive ─── */

@media (max-width: 480px) {
  #lobby {
    padding: 1rem 0.75rem;
  }

  .lobby-card {
    width: 100%;
    max-width: 340px;
    padding: 1.25rem 1.25rem 1rem;
    border-radius: 16px;
  }

  .logo-mark {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
  }

  .lobby-card h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    margin-bottom: 0.75rem;
    font-size: 0.72rem;
  }

  .device-selects {
    gap: 0.3rem;
    margin-bottom: 0.5rem;
  }

  .device-selects select {
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
  }

  .select-label {
    font-size: 0.65rem;
  }

  #preview-area {
    height: 80px;
    margin-bottom: 0.5rem;
  }

  .name-group input,
  .join-group input,
  .btn {
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
  }

  .divider {
    margin: 0.5rem 0;
  }

  /* Call screen mobile */
  #local-container {
    width: 100px;
    height: 75px;
    bottom: 5.5rem;
    right: 0.5rem;
    border-radius: 10px;
  }

  #controls {
    gap: 0.35rem;
    padding: 0.5rem 0.5rem 0.75rem;
    flex-wrap: wrap;
  }

  .btn-control {
    width: 44px;
    height: 44px;
  }

  .btn-control .icon {
    width: 18px;
    height: 18px;
  }

  .btn-danger {
    width: 48px;
    height: 48px;
    margin: 0 0.25rem;
  }

  #room-info {
    font-size: 0.7rem;
    padding: 0.3rem;
  }

  #room-code-display {
    font-size: 0.7rem;
  }

  .bandwidth {
    font-size: 0.6rem;
  }

  /* Chat panel full width on mobile */
  #chat-panel {
    width: 100%;
  }

  /* Emoji picker wrap on small screens */
  #emoji-picker {
    border-radius: 16px;
    flex-wrap: wrap;
    max-width: 280px;
    justify-content: center;
  }

  .emoji-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  /* Device switcher */
  #device-switcher {
    max-width: calc(100vw - 2rem);
    min-width: 200px;
  }

  /* Fullscreen button always visible on mobile (no hover) */
  .btn-fullscreen {
    opacity: 0.7;
  }

  /* Modal */
  .modal-card {
    margin: 0 1rem;
    min-width: auto;
    width: calc(100vw - 2rem);
    max-width: 300px;
  }
}

/* Medium screens (tablets, 1080p with scaling) */
@media (max-height: 700px) {
  .lobby-card {
    padding: 1rem 1.25rem;
  }

  .logo-mark {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
  }

  .lobby-card h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    margin-bottom: 0.5rem;
  }

  .device-selects {
    gap: 0.25rem;
    margin-bottom: 0.5rem;
  }

  .device-selects select {
    padding: 0.4rem 0.6rem;
  }

  #preview-area {
    height: 70px;
    margin-bottom: 0.5rem;
  }

  .name-group {
    margin-bottom: 0.5rem;
  }

  .name-group input,
  .btn {
    padding: 0.5rem 0.9rem;
  }

  .divider {
    margin: 0.4rem 0;
  }
}

/* ─── Utility ─── */

.hidden {
  display: none !important;
}
