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

:root {
  --bg: #ffffff;
  --bg-surface: #f5f5f7;
  --bg-elevated: #eeeef0;
  --border: #d1d1d6;
  --text: #1c1c1e;
  --text-dim: #636366;
  --text-muted: #aeaeb2;
  --primary: #7c5cff;
  --primary-hover: #6a4de0;
  --primary-glow: rgba(124, 92, 255, 0.25);
  --danger: #e04060;
  --success: #34c759;
  --radius: 10px;
  --header-h: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Header ────────────────────────────────────────────────── */
header {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 14px; padding-right: 14px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}
.brand h1 span { color: var(--text-dim); font-weight: 300; }

.header-right {
  display: flex; align-items: center; gap: 10px;
}

.user-badge {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-elevated);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.mode-badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.mode-badge.ghost {
  background: rgba(128, 128, 128, 0.15);
  color: var(--text-dim);
}
.mode-badge.live {
  background: rgba(52, 199, 89, 0.15);
  color: var(--success);
}

.mode-btn {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.mode-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg-elevated); }

.badge {
  position: absolute; top: 0; right: 0;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  min-width: 14px; height: 14px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.badge.hidden { display: none; }

/* ─── Map ───────────────────────────────────────────────────── */
#map-container {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  left: 0; right: 0; bottom: 0;
}

#map {
  width: 100%; height: 100%;
}

/* MapLibre control overrides */
.maplibregl-ctrl-group {
  border-radius: var(--radius) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12) !important;
}

/* ─── Crosshair Target ──────────────────────────────────────── */
.crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.2s;
}
.crosshair svg {
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
}
.crosshair.panning svg circle {
  fill: rgba(124, 92, 255, 0.25);
}

/* Location coordinates pill (below crosshair) */
.crosshair-label {
  position: absolute;
  top: calc(50% + 30px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 0.7rem;
  color: var(--text-dim);
  z-index: 20;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  opacity: 0;
  transition: opacity 0.3s;
}
.crosshair-label.visible { opacity: 1; }

/* ─── Location Button ───────────────────────────────────────── */
.location-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.location-btn:hover { background: var(--primary-hover); }

/* ─── Location Denied Modal ─────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-card h3 {
  font-size: 1.1rem;
  margin-bottom: 10px;
  color: var(--text);
}
.modal-card p {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 8px;
}
.modal-section-label {
  margin-top: 14px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text) !important;
  font-weight: 600;
}
.modal-section-label.modal-alt {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-weight: 500;
  color: var(--text-dim) !important;
  font-size: 0.8rem;
}
.modal-steps {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.7;
  padding-left: 20px;
  margin-bottom: 8px;
}
.modal-steps li { margin-bottom: 2px; }
.modal-steps strong { color: var(--text); }
.modal-note {
  font-size: 0.75rem;
  color: var(--success);
  line-height: 1.4;
  margin-bottom: 8px;
}
.modal-note.modal-warning {
  color: #e88a00;
}
.share-icon {
  display: inline-block;
  font-size: 1rem;
  vertical-align: middle;
  line-height: 1;
}
.modal-actions {
  display: flex; flex-direction: column; gap: 8px;
}
.modal-actions .location-btn {
  width: 100%;
  padding: 10px;
  font-size: 0.9rem;
  border-radius: 10px;
}
.modal-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 6px;
}
.modal-skip:hover { color: var(--text-dim); }

/* ─── Neighborhood Label ────────────────────────────────────── */
.neighborhood-label {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.8rem;
  color: var(--text);
  z-index: 30;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: opacity 0.3s;
}
.neighborhood-label.hidden { opacity: 0; pointer-events: none; }

/* ─── PTT Button ────────────────────────────────────────────── */
.ptt-container {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 40;
}
.ptt-container.hidden { display: none; }

.ptt-btn {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: radial-gradient(circle at 40% 35%, #fff, var(--bg-surface));
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  touch-action: none;
  position: relative;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.ptt-btn:not(:disabled):hover {
  border-color: var(--text-muted);
}
.ptt-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.ptt-btn.active {
  background: radial-gradient(circle at 40% 35%, var(--primary), #3a2a8f);
  border-color: #9d80ff;
  color: #fff;
  box-shadow: 0 0 36px var(--primary-glow);
  transform: scale(1.08);
}

.ptt-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color 0.1s;
  z-index: 1;
}
.ptt-ring.hot {
  border-color: var(--primary);
}

/* ─── Room Info Pill ────────────────────────────────────────── */
.room-info {
  position: absolute;
  bottom: calc(110px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.75rem;
  color: var(--text-dim);
  z-index: 30;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.room-info.hidden { display: none; }

.leave-room-btn, .share-room-btn {
  background: none;
  border: none;
  padding: 2px 0 0 2px;
  cursor: pointer;
  color: var(--text-dim);
  opacity: 0.6;
  display: flex; align-items: center;
  transition: opacity 0.15s, color 0.15s;
}
.leave-room-btn:hover { opacity: 1; color: var(--danger, #e53935); }
.leave-room-btn.left { color: var(--primary); opacity: 0.9; }
.share-room-btn:hover { opacity: 1; color: var(--primary, #42a5f5); }

.participant-count {
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* ─── Chat Sidebar ──────────────────────────────────────────── */
.chat-sidebar {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  right: 0;
  width: 340px;
  max-width: 100vw;
  height: calc(100% - var(--header-h) - var(--safe-top));
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.chat-sidebar.open {
  transform: translateX(0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Message bubbles */
.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

.msg.theirs {
  align-self: flex-start;
  background: var(--bg-elevated);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg.theirs .msg-time { color: var(--text-muted); }

.msg .msg-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}
.msg.mine .msg-author { color: rgba(255,255,255,0.7); }

.msg .msg-time {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
  text-align: right;
}
.msg.theirs .msg-time { color: var(--text-muted); }

/* Deaf / blurred messages */
.msg.deaf {
  filter: blur(5px);
  opacity: 0.5;
  cursor: default;
  transition: filter 0.3s;
}
.msg.deaf:hover {
  filter: blur(3px);
  opacity: 0.65;
}

/* System messages */
.msg.system {
  align-self: center;
  background: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-style: italic;
  padding: 4px 0;
}

/* Chat input */
.chat-input-wrap {
  display: flex;
  padding: 10px 14px;
  padding-bottom: calc(10px + var(--safe-bottom));
  gap: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
  -webkit-user-select: text;
  user-select: text;
}
#chat-input:focus { border-color: var(--primary); }
#chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.send-btn:hover { background: var(--primary-hover); }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: opacity 0.3s, transform 0.3s;
}
.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* ─── Participant Markers (map) ─────────────────────────────── */
.participant-marker {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid rgba(255,255,255,0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.participant-marker.speaking {
  box-shadow: 0 0 14px var(--primary-glow);
  transform: scale(1.15);
  animation: pulse 1s ease infinite;
}
.participant-marker.me {
  background: var(--success);
}
.participant-marker.ghost-me {
  background: rgba(128, 128, 128, 0.6);
  border: 2px dashed rgba(128, 128, 128, 0.5);
  font-size: 1rem;
  cursor: grab;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 14px var(--primary-glow); }
  50% { box-shadow: 0 0 24px var(--primary-glow); }
}

/* ─── Mobile ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .chat-sidebar {
    width: 100vw;
  }
  .user-badge {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
