:root {
  --bg: #f7f5ff;
  --card: #ffffff;
  --primary: #7a5cff;
  --primary-dark: #5a3fe0;
  --text: #1a1a2e;
  --muted: #6b6b80;
  --error: #d33a3a;
  --border: #e6e3f5;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 20px;
  padding: 32px 24px;
  box-shadow: 0 8px 32px rgba(122, 92, 255, 0.08);
  text-align: center;
}

.screen.hidden {
  display: none;
}

.brand {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.brand.small {
  font-size: 18px;
  margin: 0;
}

.tagline {
  color: var(--muted);
  margin: 0 0 28px;
}

h2 {
  font-size: 20px;
  margin: 16px 0 12px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.small {
  font-size: 12px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

label {
  text-align: left;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--primary);
}

button {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover {
  background: var(--primary-dark);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.link-btn {
  background: transparent;
  color: var(--primary);
  padding: 12px;
  font-weight: 500;
  width: auto;
  margin-top: 16px;
}

.link-btn:hover {
  background: rgba(122, 92, 255, 0.06);
}

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

.error.hidden {
  display: none;
}

.pair-options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

.divider {
  position: relative;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0;
}

.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}

.divider::before { left: 0; }
.divider::after  { right: 0; }

.code-display {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--primary);
  margin: 24px 0;
  padding: 20px;
  background: rgba(122, 92, 255, 0.06);
  border-radius: 16px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.chat-placeholder {
  text-align: center;
  padding: 32px 0;
}

.big-emoji {
  font-size: 64px;
  margin-bottom: 16px;
}

code {
  background: rgba(122, 92, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  word-break: break-all;
}

.screen.chat-fullscreen {
  max-width: 480px;
  width: 100%;
  height: calc(100vh - 48px);
  max-height: 800px;
  padding: 0;
  display: flex;
  flex-direction: column;
  text-align: left;
  overflow: hidden;
  position: relative;
}

.chat-fullscreen .chat-header {
  padding: 16px 20px;
  margin: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(180deg, #fafaff 0%, #f4f1ff 100%);
}

.empty-state {
  text-align: center;
  margin: auto;
  font-size: 14px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.mine { justify-content: flex-end; }
.message-row.theirs { justify-content: flex-start; }

.message-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.message-bubble.mine {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-bubble.theirs {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-input-row {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
  margin: 0;
}

.message-input-row input {
  flex: 1;
  padding: 12px 16px;
}

.message-input-row button {
  width: auto;
  padding: 12px 20px;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent !important;
  color: var(--primary) !important;
  font-size: 22px !important;
  padding: 8px 12px !important;
  border: 1px solid var(--border) !important;
}

.icon-btn:hover {
  background: rgba(122, 92, 255, 0.06) !important;
}

.message-bubble.image-bubble {
  padding: 4px;
  background: var(--primary);
  max-width: 70%;
}

.message-bubble.image-bubble.theirs {
  background: white;
}

.message-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
  cursor: pointer;
}

.upload-progress {
  padding: 8px 16px;
  background: rgba(122, 92, 255, 0.08);
  color: var(--primary);
  font-size: 13px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.upload-progress.hidden {
  display: none;
}

.message-bubble.file-bubble {
  padding: 12px 14px;
  max-width: 80%;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-bubble.mine { color: white; }
.file-bubble.theirs { color: var(--text); }

.file-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.file-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.file-size {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 2px;
}

.message-bubble.location-bubble {
  padding: 4px;
  background: var(--primary);
  max-width: 70%;
}

.message-bubble.location-bubble.theirs {
  background: white;
}

.location-map {
  width: 240px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
}

.location-open-link {
  display: block;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.location-open-link.mine { color: white; }
.location-open-link.theirs { color: var(--primary); }

.message-bubble.contact-bubble {
  padding: 12px 14px;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.contact-bubble.theirs .contact-avatar {
  background: rgba(122, 92, 255, 0.12);
}

.contact-name {
  font-weight: 600;
  font-size: 15px;
}

.contact-line {
  display: block;
  font-size: 13px;
  opacity: 0.85;
  text-decoration: none;
  color: inherit;
  margin-top: 2px;
}

.contact-line:hover {
  text-decoration: underline;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: white;
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions button {
  width: auto;
  padding: 10px 18px;
}

.emoji-picker {
  position: absolute;
  bottom: 72px;
  left: 12px;
  right: 12px;
  max-width: 320px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
}

.emoji-picker.hidden {
  display: none;
}

.emoji-btn-cell {
  background: transparent !important;
  border: none !important;
  padding: 6px !important;
  font-size: 22px !important;
  cursor: pointer;
  border-radius: 8px !important;
  width: auto !important;
  color: initial !important;
}

.emoji-btn-cell:hover {
  background: rgba(122, 92, 255, 0.08) !important;
}

.action-menu {
  position: absolute;
  bottom: 72px;
  left: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.action-menu.hidden {
  display: none;
}

.action-menu-item {
  display: flex !important;
  align-items: center;
  gap: 12px;
  width: 100% !important;
  background: transparent !important;
  color: var(--text) !important;
  text-align: left !important;
  padding: 10px 12px !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  border-radius: 10px !important;
  border: none !important;
}

.action-menu-item:hover {
  background: rgba(122, 92, 255, 0.08) !important;
}

.action-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
}
