:root {
  --bg: #0a0a0f;
  --bg2: #12121a;
  --bg3: #1a1a26;
  --surface: rgba(255,255,255,0.05);
  --surface2: rgba(255,255,255,0.09);
  --border: rgba(255,255,255,0.1);
  --text: #f0f0ff;
  --text2: #8888aa;
  --accent: #6c63ff;
  --green: #00d9a3;
  --red: #ff6584;
  --glow: rgba(108,99,255,0.3);
}

[data-theme="light"] {
  --bg: #f0f0f8;
  --bg2: #e4e4f0;
  --bg3: #d8d8ec;
  --surface: rgba(0,0,0,0.04);
  --surface2: rgba(0,0,0,0.08);
  --border: rgba(0,0,0,0.12);
  --text: #0a0a1a;
  --text2: #555577;
  --glow: rgba(108,99,255,0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  max-width: 680px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-family: monospace;
  font-size: 1.5rem;
  font-weight: 700;
}
.logo span:first-child { color: var(--accent); }
.logo-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  margin-left: 5px;
  animation: pulse 2s infinite;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  outline: none;
  font-family: inherit;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 20px var(--glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 25px var(--glow); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); }
.btn-success { background: var(--green); color: #000; font-weight: 600; }
.btn-danger { background: var(--red); color: #fff; }
.small-btn { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.full-btn { width: 100%; justify-content: center; }

.screen {
  display: none;
  width: 100%;
  max-width: 680px;
  padding: 0.5rem 1.5rem 4rem;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  animation: fadeUp 0.35s ease;
}
.screen.active { display: flex; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero-title {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-top: 1rem;
}
.hero-title .accent { color: var(--accent); }
.hero-sub {
  color: var(--text2);
  text-align: center;
  max-width: 420px;
  font-size: 0.95rem;
  line-height: 1.7;
}

.action-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
}
.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem 1.2rem;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  text-align: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  -webkit-tap-highlight-color: transparent;
}
.action-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 30px var(--glow);
}
.action-card:active { transform: scale(0.98); }
.card-icon { font-size: 2.5rem; }
.action-card h3 { font-size: 1.05rem; font-weight: 600; }
.action-card p { font-size: 0.8rem; color: var(--text2); }

.info-bar {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.info-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 3px; }
.info-sub { font-size: 0.75rem; color: var(--text2); }

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.card-sub { font-size: 0.83rem; color: var(--text2); text-align: center; }

#qr-container {
  padding: 1rem;
  background: #fff;
  border-radius: 14px;
  display: inline-block;
  line-height: 0;
}
#qr-container canvas, #qr-container img {
  display: block;
  border-radius: 4px;
}

.room-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
}
.room-code {
  font-family: monospace;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  word-break: break-all;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  width: 100%;
  user-select: all;
  cursor: pointer;
}

.status-bar {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.status-title { font-weight: 600; font-size: 0.95rem; }
.status-sub { font-size: 0.78rem; color: var(--text2); margin-top: 2px; }

.spinner {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.peer-id-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: monospace;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.peer-id-input:focus { border-color: var(--accent); }
.peer-id-input::placeholder { color: var(--text2); }

.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  width: 100%;
}
.tab-btn {
  flex: 1;
  padding: 0.55rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text2);
  transition: all 0.2s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { background: var(--accent); color: #fff; }

.tab-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ===== SCANNER ===== */
.scan-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--accent);
  background: #000;
  aspect-ratio: 1;
}
#scanner-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
}
.scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent), 0 0 4px #fff;
  animation: scanLine 2s ease-in-out infinite;
  z-index: 2;
}
@keyframes scanLine {
  0% { top: 8%; }
  50% { top: 92%; }
  100% { top: 8%; }
}

.scan-corner {
  position: absolute;
  width: 22px; height: 22px;
  border-color: var(--accent);
  border-style: solid;
  z-index: 3;
}
.scan-corner.tl { top: 8px; left: 8px; border-width: 3px 0 0 3px; border-radius: 3px 0 0 0; }
.scan-corner.tr { top: 8px; right: 8px; border-width: 3px 3px 0 0; border-radius: 0 3px 0 0; }
.scan-corner.bl { bottom: 8px; left: 8px; border-width: 0 0 3px 3px; border-radius: 0 0 0 3px; }
.scan-corner.br { bottom: 8px; right: 8px; border-width: 0 3px 3px 0; border-radius: 0 0 3px 0; }

.peer-bar {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.peer-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.peer-name { font-weight: 600; font-size: 0.95rem; }
.connected-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--green);
  margin-top: 3px;
}
.connected-dot {
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

#drop-zone {
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: 18px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  background: var(--surface);
  -webkit-tap-highlight-color: transparent;
}
#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,0.07);
  box-shadow: 0 0 25px var(--glow);
}
.drop-icon { font-size: 2.8rem; margin-bottom: 0.8rem; }

.file-item {
  width: 100%;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeUp 0.25s ease;
  transition: opacity 0.3s;
}
.file-icon { font-size: 1.7rem; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 0.87rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size { font-size: 0.73rem; color: var(--text2); margin-top: 2px; }

.progress-wrap {
  width: 100%;
  height: 5px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 99px;
  transition: width 0.15s linear;
  will-change: width;
}
.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text2);
  margin-top: 3px;
}

textarea#clipboard-text {
  width: 100%;
  min-height: 110px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
textarea#clipboard-text:focus { border-color: var(--accent); }

.received-box {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  min-height: 80px;
  font-size: 0.87rem;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-all;
}

.history-item {
  width: 100%;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.modal-box {
  max-width: 380px;
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  text-align: center;
}
.modal-icon { font-size: 3rem; margin-bottom: 1rem; }
.modal-box h3 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.5rem; }
.modal-box p { color: var(--text2); font-size: 0.88rem; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.name-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px 4px 8px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.name-chip:hover { border-color: var(--accent); }
.edit-icon { font-size: 0.7rem; color: var(--text2); }

.theme-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.theme-btn:hover { background: var(--surface2); }

.back-btn { align-self: flex-start; }
.screen-title { font-family: monospace; font-size: 1.35rem; font-weight: 700; }
.hidden { display: none !important; }
.hint { font-size: 0.8rem; color: var(--text2); text-align: center; }
.divider { width: 100%; height: 1px; background: var(--border); }
.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
  align-self: flex-start;
}

#toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2rem);
}
.toast {
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
  transition: opacity 0.3s, transform 0.3s;
}
@keyframes toastIn {
  from { opacity:0; transform:translateY(10px); }
  to   { opacity:1; transform:translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* Safari/iOS fixes */
@supports (-webkit-overflow-scrolling: touch) {
  body { -webkit-overflow-scrolling: touch; }
}

@media (max-width: 480px) {
  .action-cards { grid-template-columns: 1fr; }
  .room-code { font-size: 0.72rem; }
  .scan-wrap { max-width: 100%; }
  header { padding: 1rem; }
  .screen { padding: 0.5rem 1rem 4rem; }
  .modal-box { padding: 1.5rem; }
}

@media (hover: none) {
  .action-card:hover { transform: none; box-shadow: none; }
  .btn-primary:hover { transform: none; box-shadow: 0 0 20px var(--glow); }
}