/* =============================================
   FILE SHARE — "Signal Dark" UI
   Fonts: Syne (display) + Outfit (body)
   Theme: Deep space comms aesthetic
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=Outfit:wght@300;400;500;600&display=swap');

/* ─── Design Tokens ─────────────────────────── */
:root {
  /* Backgrounds */
  --bg:          #07090f;
  --bg-raised:   rgba(255,255,255,0.025);
  --bg-card:     rgba(255,255,255,0.04);
  --bg-card-hov: rgba(255,255,255,0.07);
  --bg-input:    rgba(255,255,255,0.06);
  --bg-chat:     #090b12;

  /* Brand Colors */
  --primary:      #22d3ee;
  --primary-dim:  rgba(34,211,238,0.1);
  --primary-glow: rgba(34,211,238,0.2);
  --secondary:    #818cf8;
  --accent:       #34d399;
  --danger:       #f87171;
  --warning:      #fbbf24;
  --success:      #34d399;

  /* Text */
  --text:       #e2e8f0;
  --text-dim:   #94a3b8;
  --text-muted: #475569;

  /* Borders */
  --border:        rgba(255,255,255,0.07);
  --border-active: rgba(34,211,238,0.35);

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.5);
  --shadow:     0 4px 20px rgba(0,0,0,0.45);
  --shadow-lg:  0 12px 48px rgba(0,0,0,0.65);
  --shadow-glow: 0 0 24px rgba(34,211,238,0.15);

  /* Radius */
  --r-sm:   8px;
  --r:      14px;
  --r-lg:   20px;
  --r-xl:   28px;
  --r-pill: 9999px;

  /* Spacing */
  --sp-1: 4px;  --sp-2: 8px;   --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px;  --sp-6: 24px;
  --sp-8: 32px; --sp-10: 40px;

  /* Typography */
  --font-display: 'Syne', 'SF Pro Display', system-ui, sans-serif;
  --font-ui:      'Outfit', 'SF Pro Text', system-ui, sans-serif;

  /* Dimensions */
  --icon-size:          64px;
  --peer-width:         148px;
  --peer-width-mobile:  118px;
  --logo-size:          70px;

  /* Easing */
  --ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --t-fast: 150ms;
  --t:      250ms;
  --t-slow: 400ms;
}

/* ─── Reset ──────────────────────────────────── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html {
  font-size: 16px;
  color-scheme: dark;
}

/* ─── Body ───────────────────────────────────── */
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-4);
  position: relative;
  overflow-x: hidden;
}

/* ─── Animated Nebula Background ─────────────── */
#background-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 15% 30%, rgba(34,211,238,0.055) 0%, transparent 65%),
    radial-gradient(ellipse 70% 55% at 88% 75%, rgba(129,140,248,0.055) 0%, transparent 65%),
    radial-gradient(ellipse 60% 70% at 55% 2%,  rgba(52,211,153,0.03)  0%, transparent 65%),
    radial-gradient(ellipse 50% 40% at 50% 50%, rgba(34,211,238,0.015) 0%, transparent 80%);
  z-index: -1;
  pointer-events: none;
  animation: bgDrift 28s ease-in-out infinite alternate;
}

@keyframes bgDrift {
  0%   { transform: scale(1)    rotate(0deg);    opacity: 1; }
  50%  { transform: scale(1.05) rotate(1deg);    opacity: 0.85; }
  100% { transform: scale(1)    rotate(-0.5deg); opacity: 1; }
}

/* Subtle scanline texture */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.025) 2px,
    rgba(0,0,0,0.025) 4px
  );
  pointer-events: none;
  z-index: -1;
}

/* ─── Header (hidden) ────────────────────────── */
header        { display: none; }
x-about       { display: none !important; }

/* ─── Utility Classes ────────────────────────── */
.full   { width: 100%; height: 100%; }
.center { display: flex; align-items: center; justify-content: center; }
.grow   { flex: 1; }

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.row-reverse {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-5);
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* ─── Main Layout ────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ─── x-peers Grid ───────────────────────────── */
x-peers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-6);
  margin: var(--sp-8) 0;
  width: 100%;
  max-width: 800px;
}

x-peer {
  display: block;
  width: var(--peer-width);
}

/* ─── Peer Card ──────────────────────────────── */
x-peer label {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 28px var(--sp-5) var(--sp-5);
  background: var(--bg-card);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  transition:
    transform    var(--t-slow) var(--ease-spring),
    box-shadow   var(--t)      var(--ease),
    border-color var(--t)      var(--ease),
    background   var(--t)      var(--ease);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Top shimmer line */
x-peer label::before {
  content: '';
  position: absolute;
  top: 0; left: 10%; right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}

x-peer label:hover {
  background: var(--bg-card-hov);
  border-color: rgba(34,211,238,0.2);
  transform: translateY(-8px);
  box-shadow:
    0 0 0 1px rgba(34,211,238,0.08),
    0 24px 52px rgba(0,0,0,0.55),
    0 0 60px rgba(34,211,238,0.04);
}

x-peer label:hover::before { opacity: 1; }

/* Recording state */
x-peer label.recording {
  border-color: rgba(248,113,113,0.45);
  animation: recordPulse 0.9s ease-in-out infinite alternate;
}

@keyframes recordPulse {
  from { box-shadow: 0 0 0 0   rgba(248,113,113,0.25); }
  to   { box-shadow: 0 0 0 14px rgba(248,113,113,0); }
}

/* ─── x-icon (Peer Avatar) ───────────────────── */
x-icon {
  width: var(--icon-size);
  height: var(--icon-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(34,211,238,0.16) 0%,
    rgba(129,140,248,0.1) 100%
  );
  border: 1.5px solid rgba(34,211,238,0.32);
  color: var(--primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  position: relative;
  box-shadow:
    0 0 0 6px rgba(34,211,238,0.05),
    inset 0 1px 0 rgba(255,255,255,0.1);
  transition:
    transform   var(--t)      var(--ease),
    box-shadow  var(--t)      var(--ease);
}

/* Orbit ring removed */

x-peer label:hover x-icon {
  transform: scale(1.08);
  box-shadow:
    0 0 0 9px rgba(34,211,238,0.08),
    0 0 24px rgba(34,211,238,0.2);
}

/* SVG icons inside x-icon */
x-icon svg,
x-icon .icon {
  width: 28px;
  height: 28px;
  fill: currentColor;
}


/* ─── Ripple Effect ──────────────────────────── */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
  transform: scale(0);
  animation: rippleAnim 1.2s linear;
  opacity: 0.35;
  pointer-events: none;
}

@keyframes rippleAnim {
  to { transform: scale(3.5); opacity: 0; }
}

/* ─── Peer Info Text ─────────────────────────── */
.name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  margin: 14px 0 4px;
  color: var(--text);
  word-break: break-word;
  text-align: center;
  letter-spacing: -0.01em;
}

.device-name {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 2px;
}

.status {
  font-size: 0.6875rem;
  color: var(--primary);
  font-weight: 500;
  min-height: 16px;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ─── Transfer Progress ──────────────────────── */
.progress {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(7,9,15,0.88);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t) var(--ease);
  border-radius: inherit;
}

[transfer] .progress { opacity: 1; }

.progress-circle {
  width: 56px;
  height: 56px;
  position: relative;
  margin-bottom: var(--sp-3);
}

.progress-circle svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-circle circle { fill: none; stroke-width: 4; }

.progress-circle .background { stroke: rgba(255,255,255,0.07); }

.progress-circle .foreground {
  stroke: var(--primary);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
  filter: drop-shadow(0 0 5px var(--primary-glow));
}

.progress-text {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
}

/* ─── No Peers ───────────────────────────────── */
x-no-peers {
  display: block;
  padding: 64px var(--sp-8);
  text-align: center;
}

x-no-peers h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--text-muted);
  letter-spacing: -0.01em;
  line-height: 1.5;
}

/* ─── Instructions ───────────────────────────── */
x-instructions {
  position: absolute;
  top: 90px;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.025em;
}

/* ─── Footer ─────────────────────────────────── */
footer {
  margin-top: auto;
  padding: var(--sp-10) 0;
  text-align: center;
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}

#displayName {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  cursor: default;
}

#myLocationStatus {
  font-size: 0.75rem;
  color: var(--accent);
}

footer .font-body2 {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ─── Connection Indicator ───────────────────── */
.connection-indicator {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.connection-indicator.online,
.connection-indicator[class*="connected"] {
  background: var(--accent);
  position: relative;
}

.connection-indicator.online::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  animation: connPulse 2.2s ease-in-out infinite;
}

@keyframes connPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%       { opacity: 0;   transform: scale(2.2); }
}

/* ─── Dialogs ────────────────────────────────── */
x-dialog x-background {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t) var(--ease);
}

x-dialog[show] x-background {
  opacity: 1;
  pointer-events: all;
}

x-dialog x-paper {
  background: #0d1119;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.02);
  transform: scale(0.93) translateY(10px);
  transition: transform var(--t-slow) var(--ease-spring);
  position: relative;
  overflow: hidden;
}

/* Gradient top border */
x-dialog x-paper::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--primary) 50%, transparent 100%);
  opacity: 0.6;
}

x-dialog[show] x-paper {
  transform: scale(1) translateY(0);
}

x-dialog x-paper h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-5);
}

x-dialog x-paper .font-subheading {
  color: var(--text-dim);
  font-size: 0.9375rem;
  margin-bottom: var(--sp-3);
  word-break: break-all;
}

x-dialog x-paper .font-body2 {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-bottom: var(--sp-3);
}

/* ─── Checkbox ───────────────────────────────── */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-active);
  border-radius: 5px;
  cursor: pointer;
  background: transparent;
  transition: var(--t-fast) var(--ease);
  position: relative;
  flex-shrink: 0;
}

input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px; left: 5px;
  width: 5px; height: 9px;
  border: 2px solid #07090f;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ─── Text Area ──────────────────────────────── */
.textarea {
  width: 100%;
  min-height: 120px;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);
  margin: var(--sp-2) 0;
  outline: none;
  transition: border-color var(--t-fast);
}

.textarea:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(34,211,238,0.1);
}

.textarea::placeholder { color: var(--text-muted); }

/* ─── Buttons ────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(34,211,238,0.22);
  border-radius: var(--r-pill);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background    var(--t-fast) var(--ease),
    border-color  var(--t-fast) var(--ease),
    box-shadow    var(--t-fast) var(--ease),
    transform     var(--t-fast) var(--ease);
  text-decoration: none;
  min-width: 90px;
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}

.button:hover {
  background: rgba(34,211,238,0.18);
  border-color: rgba(34,211,238,0.45);
  box-shadow: 0 0 16px rgba(34,211,238,0.12);
  transform: translateY(-1px);
}

.button:active { transform: translateY(0); }

/* ─── Icon Button ────────────────────────────── */
.icon-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}

.icon-button:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text);
}

/* ─── SVG Icons ──────────────────────────────── */
.icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  display: block;
  flex-shrink: 0;
}

.icon-button .icon {
  width: 22px;
  height: 22px;
}

/* ─── Toast ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  /* The HTML has class="toast-container full center" — those utility
     classes would make this a full-viewport overlay; we override them
     here so only the toast itself is positioned, not the whole screen. */
  width: auto !important;
  height: auto !important;
  pointer-events: none;
}

x-toast {
  background: #0d1119;
  color: var(--text);
  padding: 13px 22px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 240px;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transition: all var(--t) var(--ease-spring);
  font-size: 0.875rem;
}

x-toast::before {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--accent);
}

x-toast[show] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ─── Image Preview ──────────────────────────── */
.preview {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: var(--sp-4) 0;
  min-height: 180px;
  max-height: 55vh;
  overflow: hidden;
  border-radius: var(--r);
  background: var(--bg-raised);
}

.preview[style*="visibility: inherit"] {
  display: flex !important;
}

#img-preview {
  max-width: 100%;
  max-height: 55vh;
  object-fit: contain;
  border-radius: var(--r);
  display: none;
}

#img-preview[src] { display: block; }

/* ─── Hidden ─────────────────────────────────── */
[hidden], input[type="file"] { display: none; }

/* ─── Chat Container ─────────────────────────── */
#chat-container {
  display: none; /* shown via JS (showChatForPeer) */
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg-chat);
}

/* ─── Chat Header ────────────────────────────── */
#chat-header {
  padding: 10px 16px;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  height: 60px;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  margin-left: var(--sp-3);
  flex: 1;
  min-width: 0;
}

#chat-peer-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#chat-peer-location-status {
  font-size: 0.6875rem;
  color: var(--accent);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#back-to-peers {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  flex-shrink: 0;
}

#back-to-peers:hover {
  background: var(--bg-card);
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}

#back-to-peers .icon { width: 18px; height: 18px; }

#video-call-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ─── Chat location header button ───────────── */
#chat-location-btn {
  color: var(--text-muted);
  transition: color var(--t-fast), background var(--t-fast);
}

#chat-location-btn.location-active {
  color: var(--accent);
  background: rgba(52,211,153,0.1);
  border-radius: 50%;
}

#chat-location-btn.location-active:hover {
  background: rgba(52,211,153,0.18);
}

/* ─── Header Actions ─────────────────────────── */
.header-actions { position: relative; }

/* ─── Dropdown Menu ──────────────────────────── */
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #0d1119;
  min-width: 210px;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-2);
  z-index: 1100;
  flex-direction: column;
  gap: 2px;
  animation: dropIn 0.2s var(--ease-spring);
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

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

.dropdown-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-1) 0;
}

.dropdown-menu button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  text-align: left;
  padding: 9px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  transition: background var(--t-fast), color var(--t-fast);
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.dropdown-menu button:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.dropdown-menu button.danger { color: var(--danger); }

.dropdown-menu button.danger:hover {
  background: rgba(248,113,113,0.1);
}

/* ─── Chat Messages ──────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: #080a12;
  scroll-behavior: smooth;
}

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

.chat-message {
  max-width: 78%;
  padding: 10px 16px;
  border-radius: var(--r-lg);
  word-wrap: break-word;
  animation: msgIn 0.25s var(--ease) both;
  line-height: 1.55;
  font-size: 0.9rem;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-message.sent {
  align-self: flex-end;
  background: rgba(34,211,238,0.1);
  color: var(--text);
  border: 1px solid rgba(34,211,238,0.18);
  border-bottom-right-radius: var(--r-sm);
}

.chat-message.received {
  align-self: flex-start;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-sm);
}

.message-content { margin-bottom: 4px; }

.message-time {
  font-size: 0.6875rem;
  opacity: 0.4;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Audio messages */
.audio-message {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.play-audio-btn {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(34,211,238,0.18);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.8125rem;
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  transition: background var(--t-fast), box-shadow var(--t-fast);
}

.play-audio-btn:hover {
  background: rgba(34,211,238,0.18);
  box-shadow: 0 0 10px rgba(34,211,238,0.1);
}

/* ─── Chat Input Area ────────────────────────── */
#chat-input-area {
  padding: 10px 14px;
  background: rgba(255,255,255,0.02);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

#chat-message-input {
  flex: 1;
  min-width: 0; /* Allow shrinking below content size */
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  outline: none;
  background: var(--bg-input);
  color: var(--text);
  transition:
    border-color var(--t-fast) var(--ease),
    box-shadow   var(--t-fast) var(--ease);
}

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

#chat-message-input:focus {
  border-color: rgba(34,211,238,0.35);
  box-shadow: 0 0 0 3px rgba(34,211,238,0.08);
}

#send-message-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(34,211,238,0.22);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  transition: background var(--t-fast), box-shadow var(--t-fast);
}

#send-message-btn:hover {
  background: rgba(34,211,238,0.2);
  box-shadow: 0 0 12px rgba(34,211,238,0.15);
}

/* ─── Chat-specific action buttons ──────────── */
#view-peer-location-btn {
  /* Displayed as a regular dropdown item - shown/hidden by JS when location available */
}

/* ─── Chat action panel (left of input) ─────── */
#chat-action-panel-wrap {
  position: relative;
  flex-shrink: 0;
}

#chat-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), transform 0.25s var(--ease);
}

#chat-action-btn:hover {
  background: var(--primary-dim);
  color: var(--primary);
  border-color: rgba(34,211,238,0.25);
}

/* Rotate + icon when panel is open */
#chat-action-btn.panel-open {
  transform: rotate(45deg);
  color: var(--primary);
  background: var(--primary-dim);
  border-color: rgba(34,211,238,0.3);
}

#chat-action-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: rgba(10,13,25,0.92);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

#chat-action-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.action-panel-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

.action-panel-btn .icon {
  width: 20px;
  height: 20px;
}

.action-panel-btn:hover {
  background: var(--primary-dim);
  color: var(--primary);
  border-color: rgba(34,211,238,0.3);
}

/* Start video call button styling in action panel */
#start-video-call.action-panel-btn:hover {
  background: rgba(129,140,248,0.15);
  color: var(--secondary);
  border-color: rgba(129,140,248,0.3);
}

/* ─── Voice record button (right of send) ───── */
#voice-record-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(248,113,113,0.08);
  color: var(--danger);
  border: 1px solid rgba(248,113,113,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--t-fast), box-shadow var(--t-fast), transform 0.15s;
}

#voice-record-btn:hover {
  background: rgba(248,113,113,0.18);
}

#voice-record-btn.recording {
  background: rgba(248,113,113,0.25);
  box-shadow: 0 0 0 4px rgba(248,113,113,0.15);
  animation: recordPulse 1s ease-in-out infinite;
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(248,113,113,0.15); }
  50%       { box-shadow: 0 0 0 8px rgba(248,113,113,0.05); }
}

/* ─── Settings Dialog Items ──────────────────── */
.setting-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  text-align: left;
}

.setting-item label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

#customNameInput,
x-dialog input[type="text"] {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}

#customNameInput:focus,
x-dialog input[type="text"]:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(34,211,238,0.1);
}

/* ─── Footer Buttons ─────────────────────────── */
.btn-footer {
  padding: 8px 16px;
  border: none;
  border-radius: var(--r-pill);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast);
}

.btn-footer-teal {
  background: rgba(34,211,238,0.1);
  color: var(--primary);
  border: 1px solid rgba(34,211,238,0.2);
}
.btn-footer-teal:hover { background: rgba(34,211,238,0.18); }

.btn-footer-slate {
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-footer-slate:hover { background: rgba(255,255,255,0.1); }

.btn-footer-dark {
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  border: 1px solid var(--border);
  display: none;
}
.btn-footer-dark:hover { background: rgba(255,255,255,0.08); }

/* ─── Logo ───────────────────────────────────── */
.logo {
  width: var(--logo-size);
  height: var(--logo-size);
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(34,211,238,0.18), rgba(129,140,248,0.12));
  border: 1.5px solid rgba(34,211,238,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--sp-5);
  transition: transform var(--t) var(--ease-spring), box-shadow var(--t) var(--ease);
}

.logo:hover {
  transform: scale(1.08) rotate(12deg);
  box-shadow: var(--shadow-glow);
}

/* ─── Video Call Container ───────────────────── */
#video-call-container {
  display: none;
  position: fixed;
  inset: 0;
  background: #03040a;
  z-index: 2000;
  flex-direction: column;
  animation: videoFadeIn 0.35s var(--ease);
}

@keyframes videoFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

#remote-video {
  width: 100%;
  flex: 1;
  object-fit: cover;
  background: #030509;
  min-height: 0;
}

#local-video {
  position: absolute;
  width: min(160px, 28vw);
  height: min(120px, 21vw);
  right: 16px;
  top: 16px;
  object-fit: cover;
  border: 2px solid rgba(34,211,238,0.3);
  border-radius: var(--r);
  background: #09111f;
  z-index: 1;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
}

#local-video:hover {
  transform: scale(1.04);
  border-color: rgba(34,211,238,0.6);
}

/* ─── Video call overlay controls ───────────── */
#video-call-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 32px 0 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: linear-gradient(to top, rgba(3,4,10,0.92) 0%, transparent 100%);
  z-index: 2;
}

.video-ctrl-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.video-ctrl-btn .icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.video-ctrl-btn:hover {
  background: rgba(255,255,255,0.22);
  transform: scale(1.08);
}

.video-ctrl-btn.active {
  background: rgba(248,113,113,0.25);
  color: var(--danger);
}

.video-ctrl-hangup {
  width: 62px;
  height: 62px;
  background: var(--danger);
  color: #fff;
}

.video-ctrl-hangup:hover {
  background: #ef4444;
  transform: scale(1.1);
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 600px) {
  body { padding: var(--sp-3); }
  x-peers { gap: var(--sp-4); }
  x-peer { width: var(--peer-width-mobile); }
  x-dialog x-paper { padding: var(--sp-6); }
}

/* ─── PWA Install Banner ─────────────────────── */
#pwa-install-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(10, 14, 28, 0.92);
  border: 1px solid rgba(34,211,238,0.2);
  border-radius: var(--r-xl);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(34,211,238,0.06);
  max-width: min(420px, calc(100vw - 32px));
  width: max-content;
  animation: bannerUp 0.4s var(--ease-spring);
}

#pwa-install-banner[hidden] { display: none; }

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

#pwa-install-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  background: rgba(34,211,238,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

#pwa-install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#pwa-install-text strong {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

#pwa-install-text span {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--text-muted);
}

#pwa-install-btn {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: var(--r-pill);
  background: var(--primary);
  color: #07090f;
  border: none;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

#pwa-install-btn:hover { opacity: 0.85; }

#pwa-install-dismiss {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

#pwa-install-dismiss:hover { background: rgba(255,255,255,0.12); }

/* iOS hint bar */
#pwa-ios-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(10, 14, 28, 0.92);
  border: 1px solid rgba(34,211,238,0.2);
  border-radius: var(--r-xl);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  max-width: min(360px, calc(100vw - 32px));
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-dim);
  animation: bannerUp 0.4s var(--ease-spring);
}

#pwa-ios-hint[hidden] { display: none; }

#pwa-ios-hint strong { color: var(--primary); }

#pwa-ios-dismiss {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Light theme */
html[data-theme="light"] #pwa-install-banner,
html[data-theme="light"] #pwa-ios-hint {
  background: rgba(255,255,255,0.95);
  border-color: rgba(8,145,178,0.2);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

html[data-theme="light"] #pwa-install-btn {
  color: #fff;
}

/* ─── Noscript ───────────────────────────────── */
x-noscript {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: var(--sp-4);
  font-family: var(--font-display);
  text-align: center;
}

x-noscript h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.03em;
}

x-noscript h3 {
  color: var(--text-muted);
  font-weight: 400;
}

/* =============================================
   LIGHT THEME OVERRIDES
   Applied when <html data-theme="light">
   ============================================= */

html[data-theme="light"] {
  /* Backgrounds */
  --bg:          #f2f5fc;
  --bg-raised:   rgba(0,0,0,0.02);
  --bg-card:     rgba(255,255,255,0.82);
  --bg-card-hov: rgba(255,255,255,0.96);
  --bg-input:    rgba(0,0,0,0.05);
  --bg-chat:     #eef2f9;

  /* Brand — darker for light-bg contrast */
  --primary:      #0891b2;
  --primary-dim:  rgba(8,145,178,0.1);
  --primary-glow: rgba(8,145,178,0.2);
  --secondary:    #6366f1;
  --accent:       #059669;
  --danger:       #dc2626;
  --warning:      #d97706;
  --success:      #059669;

  /* Text */
  --text:       #1e2433;
  --text-dim:   #374151;
  --text-muted: #6b7280;

  /* Borders */
  --border:        rgba(0,0,0,0.09);
  --border-active: rgba(8,145,178,0.45);

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.1);
  --shadow:     0 4px 20px rgba(0,0,0,0.09);
  --shadow-lg:  0 12px 48px rgba(0,0,0,0.16);
  --shadow-glow: 0 0 24px rgba(8,145,178,0.18);
}


/* ─── Light: background nebula ─────────────── */
html[data-theme="light"] #background-overlay {
  background:
    radial-gradient(ellipse 90% 60% at 15% 30%, rgba(8,145,178,0.08)  0%, transparent 65%),
    radial-gradient(ellipse 70% 55% at 88% 75%, rgba(99,102,241,0.06) 0%, transparent 65%),
    radial-gradient(ellipse 60% 70% at 55% 2%,  rgba(5,150,105,0.04)  0%, transparent 65%);
}

/* Remove scanlines in light mode */
html[data-theme="light"] body::after { display: none; }

/* ─── Light: peer cards ─────────────────────── */
html[data-theme="light"] x-peer label {
  background: rgba(255,255,255,0.75);
  border-color: rgba(0,0,0,0.07);
  box-shadow: 0 2px 14px rgba(0,0,0,0.07), inset 0 1px 0 rgba(255,255,255,0.9);
}

html[data-theme="light"] x-peer label:hover {
  background: rgba(255,255,255,0.96);
  border-color: rgba(8,145,178,0.25);
  box-shadow:
    0 0 0 1px rgba(8,145,178,0.1),
    0 12px 32px rgba(0,0,0,0.12),
    0 0 40px rgba(8,145,178,0.06);
}

/* ─── Light: peer avatar ────────────────────── */
html[data-theme="light"] x-icon {
  background: linear-gradient(135deg, rgba(8,145,178,0.12) 0%, rgba(99,102,241,0.08) 100%);
  border-color: rgba(8,145,178,0.3);
  box-shadow: 0 0 0 6px rgba(8,145,178,0.06), inset 0 1px 0 rgba(255,255,255,0.7);
}

html[data-theme="light"] x-icon::after {
  border-top-color: rgba(8,145,178,0.5);
}

/* ─── Light: dialogs ────────────────────────── */
html[data-theme="light"] x-dialog x-paper {
  background: #ffffff;
  border-color: rgba(0,0,0,0.09);
  box-shadow: 0 12px 48px rgba(0,0,0,0.14);
}

/* ─── Light: chat container ─────────────────── */
html[data-theme="light"] #chat-header {
  background: rgba(255,255,255,0.6);
  border-color: rgba(0,0,0,0.07);
}

html[data-theme="light"] #chat-messages {
  background: #e2eaf5;
}

html[data-theme="light"] .chat-message.received {
  background: rgba(255,255,255,0.88);
  border-color: rgba(0,0,0,0.07);
  color: var(--text);
}

html[data-theme="light"] .chat-message.sent {
  color: #0c4a6e;
}

html[data-theme="light"] #chat-input-area {
  background: rgba(255,255,255,0.5);
  border-color: rgba(0,0,0,0.07);
}

html[data-theme="light"] #chat-message-input {
  background: rgba(255,255,255,0.9);
  border-color: rgba(0,0,0,0.12);
  color: var(--text);
}

html[data-theme="light"] #back-to-peers {
  border-color: rgba(0,0,0,0.12);
  color: var(--text-muted);
}

/* ─── Light: toast ──────────────────────────── */
html[data-theme="light"] x-toast {
  background: #ffffff;
  border-color: rgba(0,0,0,0.1);
  color: var(--text);
}

/* ─── Light: dropdown ───────────────────────── */
html[data-theme="light"] .dropdown-menu {
  background: #ffffff;
  border-color: rgba(0,0,0,0.1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
}

html[data-theme="light"] .dropdown-menu button {
  color: var(--text-dim);
}

html[data-theme="light"] .dropdown-menu button:hover {
  background: rgba(0,0,0,0.04);
  color: var(--text);
}

/* ─── Light: settings inputs ────────────────── */
html[data-theme="light"] #customNameInput,
html[data-theme="light"] x-dialog input[type="text"] {
  background: #f8fafc;
  color: var(--text);
  border-color: rgba(0,0,0,0.12);
}

/* ─── Light: progress overlay ───────────────── */
html[data-theme="light"] .progress {
  background: rgba(242,245,252,0.92);
}

/* ─── Theme toggle icon swap ────────────────── */
/* In dark mode: show sun (click → light).
   In light mode: show moon (click → dark).  */
#themeToggleBtn .icon-moon { display: none; }
#themeToggleBtn .icon-sun  { display: block; }

html[data-theme="light"] #themeToggleBtn .icon-sun  { display: none; }
html[data-theme="light"] #themeToggleBtn .icon-moon { display: block; }

/* ─── Light: action panel ───────────────────── */
html[data-theme="light"] #chat-action-panel {
  background: rgba(255,255,255,0.96);
  border-color: rgba(0,0,0,0.1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
}

html[data-theme="light"] .action-panel-btn {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.1);
  color: var(--text-dim);
}
