:root {
  --bg: #0b1020;
  --bg-2: #131a33;
  --surface: #161d38;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef2ff;
  --muted: #97a3c7;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2450 0%, var(--bg) 60%) fixed;
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  backdrop-filter: blur(10px);
  background: rgba(11, 16, 32, 0.6);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.2px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--primary-2); }
.ghost-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line); background: transparent;
  color: var(--text); font-size: 18px; cursor: pointer; text-decoration: none;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.06); }

.wrap { max-width: 640px; margin: 0 auto; padding: 22px 18px 60px; }

.screen { display: none; }
.screen.active { display: block; animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.hero { font-size: clamp(2.1rem, 8vw, 3rem); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; }
.hero span { background: linear-gradient(120deg, var(--primary-2), #22d3ee); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { color: var(--muted); margin-top: 14px; font-size: 1.02rem; max-width: 46ch; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 26px 0; }
.mode-card {
  text-align: left; cursor: pointer; border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--surface), var(--bg-2));
  border-radius: var(--radius); padding: 20px; color: var(--text);
  display: flex; flex-direction: column; gap: 6px; transition: transform 0.15s, border-color 0.15s;
}
.mode-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.mode-icon { font-size: 26px; }
.mode-card.send .mode-icon { color: var(--primary-2); }
.mode-card.receive .mode-icon { color: var(--green); }
.mode-title { font-weight: 700; font-size: 1.15rem; }
.mode-sub { color: var(--muted); font-size: 0.86rem; }

.facts { list-style: none; display: grid; gap: 10px; margin-top: 8px; }
.facts li { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.02); }
.facts strong { color: var(--text); min-width: 92px; }
.facts span { color: var(--muted); font-size: 0.9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }

.dropzone { text-align: center; border: 1.5px dashed var(--line); border-radius: 14px; padding: 26px 16px; transition: border-color 0.15s, background 0.15s; }
.dropzone.hover { border-color: var(--primary); background: rgba(99, 102, 241, 0.08); }
.dz-icon { font-size: 30px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.filelist { margin-top: 14px; display: grid; gap: 8px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.file-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.file-row .size { color: var(--muted); font-size: 0.82rem; }

.options { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 0.9rem; color: var(--muted); }
.field b { color: var(--text); }
select, input[type="range"] { width: 100%; }
select { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; font-size: 0.95rem; }
input[type="range"] { accent-color: var(--primary); }

.switch { display: flex; gap: 10px; align-items: flex-start; font-size: 0.88rem; color: var(--muted); }
.switch input { margin-top: 3px; accent-color: var(--primary); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stats div { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stats dt { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stats dd { font-weight: 700; margin-top: 2px; }

.btn { border: none; border-radius: 14px; padding: 13px 18px; font-size: 1rem; font-weight: 650; cursor: pointer; color: var(--text); background: rgba(255, 255, 255, 0.08); transition: transform 0.12s, opacity 0.2s; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--primary), #4f46e5); box-shadow: 0 10px 30px rgba(99, 102, 241, 0.35); }
.btn.danger { background: linear-gradient(135deg, var(--red), #b91c1c); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.wide { width: 100%; margin-top: 4px; }

.qr-stage { background: #fff; border-radius: var(--radius); padding: 14px; display: grid; place-items: center; box-shadow: var(--shadow); }
#qrCanvas { width: 100%; max-width: 420px; height: auto; image-rendering: pixelated; }

.progress { margin: 16px 0; }
.bar { height: 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #22d3ee); transition: width 0.25s; }
.progress-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 0.88rem; }

.camera { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3 / 4; box-shadow: var(--shadow); }
#video { width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; inset: 12%; border: 2px solid rgba(255, 255, 255, 0.6); border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); pointer-events: none; }

.results { display: grid; gap: 8px; margin: 14px 0; }
.result-row { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.02); }
.result-row a { color: var(--primary-2); text-decoration: none; font-weight: 600; }

.row { display: flex; gap: 10px; margin-top: 8px; }
.row .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--primary); padding: 13px 18px; border-radius: 12px; box-shadow: var(--shadow); transition: transform 0.3s; z-index: 60; max-width: 90vw; }
.toast.show { transform: translate(-50%, 0); }
.toast.ok { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--amber); }
.toast.err { border-left-color: var(--red); }

#focusCanvas { position: fixed; inset: 0; z-index: 50; display: none; }
#focusCanvas.active { display: block; }

@media (max-width: 420px) { .mode-grid { grid-template-columns: 1fr; } }
