:root {
  --bg: #f5f2ed;
  --surface: #ffffff;
  --surface-hover: #fafaf8;
  --border: rgba(0,0,0,0.06);
  --border-strong: rgba(0,0,0,0.1);
  --text: #1a1a1a;
  --text-secondary: #888;
  --text-muted: #bbb;
  --accent: #2dba5e;
  --accent-soft: rgba(45, 186, 94, 0.08);
  --accent-border: rgba(45, 186, 94, 0.2);
  --accent-hover: #24a14f;
  --danger: #e53935;
  --danger-soft: rgba(229, 57, 53, 0.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 8px;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  text-align: center;
  padding: 44px 0 32px;
}

.logo {
  font-family: 'DM Sans', sans-serif;
  font-size: 34px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.logo span {
  color: var(--accent);
}

.subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 400;
  margin-top: 4px;
}

/* ── Status indicator ── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.4s ease;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.card-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

/* ── Your Code ── */
.id-display {
  display: flex;
  align-items: center;
  gap: 12px;
}

.id-value {
  flex: 1;
  font-family: 'DM Mono', 'SF Mono', monospace;
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 6px;
  color: var(--text);
}

.id-value.loading {
  color: var(--text-muted);
  font-size: 15px;
  letter-spacing: 0;
  font-family: 'DM Sans', sans-serif;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── QR Code ── */
.qr-container {
  display: flex;
  justify-content: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.qr-container canvas,
.qr-container img {
  border-radius: var(--radius-xs);
}

/* ── Buttons ── */
.btn {
  background: var(--bg);
  border: none;
  color: var(--text-secondary);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--border-strong);
  color: var(--text);
}

.btn:active { transform: scale(0.97); }

.btn.copied {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 100%;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  text-align: center;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) { transform: scale(0.97); }

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Connect section ── */
.connect-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input {
  flex: 1;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 20px;
  letter-spacing: 3px;
  outline: none;
  transition: all 0.2s ease;
}

.input::placeholder {
  color: var(--text-muted);
  letter-spacing: 0;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
}

.input:focus {
  border-color: var(--accent);
  background: #fff;
}

/* ── Display name ── */
.name-row {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  min-height: 28px;
}

.name-set-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}
.name-set-btn:hover {
  color: var(--text-secondary);
}

.name-edit {
  display: none;
  align-items: center;
  gap: 8px;
}
.name-edit.visible { display: flex; }

.name-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.name-input:focus {
  border-color: var(--accent);
  background: #fff;
}
.name-input::placeholder {
  color: var(--text-muted);
}

.name-confirm-btn, .name-cancel-btn {
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
  white-space: nowrap;
  transition: color 0.15s;
}
.name-confirm-btn {
  color: var(--accent);
}
.name-confirm-btn:hover {
  color: var(--accent-hover);
}
.name-cancel-btn {
  color: var(--text-muted);
}
.name-cancel-btn:hover {
  color: var(--text-secondary);
}

.name-display {
  display: none;
  align-items: center;
  gap: 6px;
}
.name-display.visible { display: flex; }

.name-value {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.name-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.15s;
}
.name-edit-btn:hover {
  color: var(--text-secondary);
}

/* ── Connected peer badge ── */
.peer-badge {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--accent-hover);
  font-weight: 500;
}

.peer-badge.visible {
  display: flex;
  animation: slideUp 0.3s ease;
}

.peer-badge .mini-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.peer-badge .peer-text { flex: 1; }
.peer-badge .peer-text strong { font-weight: 600; }

.btn-disconnect {
  background: transparent;
  border: 1px solid var(--accent-border);
  color: var(--text-secondary);
  padding: 5px 14px;
  border-radius: 100px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: auto;
}

.btn-disconnect:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

/* ── Reconnect badge ── */
.reconnect-badge {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--danger-soft);
  border: 1px solid rgba(229, 57, 53, 0.2);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.reconnect-badge.visible {
  display: flex;
  animation: slideUp 0.3s ease;
}
.reconnect-text { flex: 1; color: var(--text-secondary); }
.btn-reconnect {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 6px 16px;
  border-radius: 100px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-reconnect:hover {
  background: var(--accent-hover);
}
.btn-dismiss-reconnect {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s;
}
.btn-dismiss-reconnect:hover {
  color: var(--text-secondary);
}

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

#sendSection {
  animation: slideUp 0.3s ease;
}

.drop-icon {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
  opacity: 0.7;
}

.drop-text {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.6;
}

.drop-text strong {
  color: var(--text);
  font-weight: 600;
}

.file-input { display: none; }

/* ── Transfer progress ── */
.transfer-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 14px;
  display: none;
}

.transfer-card.visible {
  display: block;
  animation: slideUp 0.3s ease;
}

.transfer-card.is-receive {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 0;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.transfer-card.is-receive .card-label { margin-bottom: 12px; }

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

.transfer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.transfer-filename {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.transfer-size {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  width: 0%;
  transition: width 0.15s linear;
}

.progress-fill.complete {
  background: var(--accent);
}

.transfer-status {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  font-family: 'DM Mono', monospace;
}

.btn-cancel-transfer {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 0 0;
  transition: color 0.15s;
  display: block;
  width: 100%;
  text-align: center;
}
.btn-cancel-transfer:hover {
  color: var(--danger);
}

/* ── File queue ── */
.file-queue {
  display: none;
  margin-top: 14px;
}

.queue-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.queue-item:last-child {
  border-bottom: none;
}

.queue-item-name {
  flex: 1;
  min-width: 0;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item-active {
  opacity: 0.5;
}

.queue-item-size {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.queue-item-status {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  flex-shrink: 0;
}

.btn-queue-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-queue-remove:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.btn-queue-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 0 0;
  display: block;
  width: 100%;
  text-align: center;
  transition: color 0.15s;
}
.btn-queue-clear:hover {
  color: var(--danger);
}

/* ── Incoming file prompt ── */
.incoming {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 12px;
  display: none;
  box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-soft);
  animation: slideUp 0.3s ease;
}

.incoming.visible { display: block; }

.incoming-title {
  font-weight: 600;
  font-size: 17px;
  margin-bottom: 6px;
  color: var(--text);
}

.incoming-info {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 18px;
  font-family: 'DM Mono', monospace;
  word-break: break-all;
  line-height: 1.5;
}

.incoming-file-list {
  max-height: 140px;
  overflow-y: auto;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 0;
}

.incoming-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px;
  gap: 10px;
}

.incoming-file-name {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.incoming-file-size {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.incoming-actions { display: flex; gap: 10px; }

.btn-accept {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  transition: all 0.2s ease;
}

.btn-accept:hover { background: var(--accent-hover); }
.btn-accept:active { transform: scale(0.97); }

.btn-decline {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-decline:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

/* ── Event log ── */
.log {
  max-height: 160px;
  overflow-y: auto;
  mask-image: linear-gradient(transparent, black 16px, black);
  -webkit-mask-image: linear-gradient(transparent, black 16px, black);
}

.log.hidden { display: none; }

.log::-webkit-scrollbar { width: 3px; }
.log::-webkit-scrollbar-track { background: transparent; }
.log::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 100px;
}

.log-entry {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 3px 0;
  opacity: 0;
  animation: fadeIn 0.3s forwards;
  display: flex;
  gap: 8px;
  line-height: 1.5;
}

.log-entry .time {
  color: var(--text-muted);
  flex-shrink: 0;
}

.log-entry.success { color: var(--accent-hover); }
.log-entry.error { color: var(--danger); }

@keyframes fadeIn { to { opacity: 1; } }

/* ── Log footer ── */
.log-footer {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 12px 0;
  margin-top: auto;
}

.log-footer .btn {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 100px;
  color: var(--text-muted);
  background: transparent;
}

.log-footer .btn:hover {
  color: var(--text-secondary);
  background: var(--border);
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 16px 0 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── QR Scanner Modal ── */
.scan-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}

.scan-modal.visible { display: flex; }

.scan-modal video {
  width: 100%;
  max-width: 360px;
  border-radius: var(--radius);
  border: 3px solid var(--accent);
}

.scan-modal .btn {
  font-size: 15px;
  padding: 12px 32px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 100px;
}

/* ── Connect button loading ── */
.btn-primary.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn-primary.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Connect error ── */
.connect-error {
  font-size: 13px;
  color: var(--danger);
  margin-top: 8px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.connect-error.visible {
  opacity: 1;
  animation: slideUp 0.2s ease;
}

/* ── Saved devices ── */
#savedDevices {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.saved-devices-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.saved-device {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.saved-device:last-child {
  border-bottom: none;
}

.saved-device-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.saved-device-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-device-id {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.btn-saved-connect {
  background: var(--accent-soft);
  border: none;
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 100px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-saved-connect:hover {
  background: var(--accent);
  color: #fff;
}

.btn-saved-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-saved-remove:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ── Setup section collapse ── */
.setup-section.collapsed { display: none; }

.setup-toggle {
  display: none;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 0;
  cursor: pointer;
  text-align: center;
  transition: color 0.2s ease;
}

.setup-toggle:hover { color: var(--text-secondary); }
.setup-toggle.visible { display: block; }

/* ── Responsive ── */
@media (max-width: 540px) {
  .container { padding: 16px; }
  .header { padding: 32px 0 24px; }
  .logo { font-size: 30px; }
  .id-value { font-size: 26px; letter-spacing: 4px; }
  .dropzone { padding: 36px 20px; }
}
