:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #15803d;
  --green-soft: #f0fdf4;
  --red: #dc2626;
  --radius: 18px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
textarea { resize: vertical; }

button:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.site-header {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 72px;
  display: flex;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .02em; }

.page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 16px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, .035);
}

.intro h1 {
  margin: 0 0 7px;
  font-size: 29px;
  line-height: 1.12;
  letter-spacing: -.035em;
}
.intro p { margin: 0; color: var(--muted); font-size: 13.5px; }

.meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.status {
  display: inline-block;
  margin: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 11.5px;
}
.status.err { background: #fef2f2; color: var(--red); }

.role {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
}
.role.host { background: var(--blue-soft); color: #1d4ed8; }
.role.guest { background: var(--green-soft); color: var(--green); }

.pair-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 24px;
  margin-top: 22px;
  align-items: stretch;
}

.qr-panel, .scan-panel { min-width: 0; }
.scan-panel { display: flex; flex-direction: column; }

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.step > span {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}
.step h2 {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  font-weight: 650;
}

.qr-frame {
  display: grid;
  place-items: center;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 15px;
  background: #fff;
}
.qr-frame.host { border-color: #bfdbfe; background: #f8fbff; }
.qr-frame.guest { border-color: #bbf7d0; background: #f7fffa; }
.qr-frame canvas {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  image-rendering: pixelated;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.65;
}

.scan-box {
  flex: 1;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 20px;
  border: 1px dashed #cbd5e1;
  border-radius: 15px;
  background: #f8fafc;
  text-align: center;
}
.scan-box p { margin: 0; font-size: 12.5px; line-height: 1.7; }
.scan-box .hint { max-width: 270px; }
.scan-box.guest {
  border-style: solid;
  border-color: #bbf7d0;
  background: var(--green-soft);
}
.scan-box .primary { margin-top: 5px; }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  transition: background .15s;
}
.primary:hover { background: #1d4ed8; }
.primary:disabled { opacity: .45; cursor: not-allowed; }

.ghost {
  flex: 0 0 auto;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 12.5px;
  font-weight: 550;
}
.ghost:hover { border-color: #cbd5e1; background: #f8fafc; }

.text-button {
  width: fit-content;
  padding: 3px 0;
  color: var(--muted);
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-button:hover { color: var(--blue); }
.scan-box .text-button { margin-top: 2px; }

.banner {
  margin-bottom: 14px;
  padding: 11px 14px;
  border: 1px solid #fde68a;
  border-radius: 11px;
  background: #fffbeb;
  color: #92400e;
  font-size: 12.5px;
}
.banner.err { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

.utility {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.manual-panel {
  margin-bottom: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.panel-title {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 650;
}
.field + .field { margin-top: 14px; }
.field label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11.5px;
}
.field-row { display: flex; align-items: flex-start; gap: 8px; }
.field-row textarea {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  word-break: break-all;
}
.field-row textarea::placeholder { color: #94a3b8; }
.manual-panel .text-button { margin-top: 14px; }

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.bottom-actions.single { grid-template-columns: 1fr; }

.action {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: border-color .15s, color .15s, background .15s;
}
.action:hover { border-color: #bfdbfe; color: var(--blue); background: #f8fbff; }
.action[aria-expanded="true"] {
  border-color: #bfdbfe;
  color: var(--blue);
  background: var(--blue-soft);
}

.connected {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.connected strong { font-size: 13px; }
.connected span:last-child { color: var(--muted); font-size: 11.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #16a34a; }

.drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 18px 0;
  padding: 22px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}
.drop.over { border-color: var(--blue); background: var(--blue-soft); }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.item {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}
.item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}
.item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}
.item-size { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.item progress {
  width: 100%;
  height: 5px;
  margin: 8px 0 5px;
  accent-color: var(--blue);
}
.item-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}
.item.done .item-bottom { color: var(--green); }
.item.fail .item-bottom { color: var(--red); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
#scanVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-target {
  position: relative;
  width: min(68vmin, 520px);
  height: min(68vmin, 520px);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
.scan-tip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 36px;
  margin: 0;
  color: #fff;
  font-size: 13px;
  text-align: center;
  text-shadow: 0 1px 8px #000;
}
.close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}
.close:hover { background: rgba(255, 255, 255, .25); }

@media (max-width: 640px) {
  .site-header, .page { width: calc(100% - 24px); }
  .site-header { min-height: 62px; }
  .card { padding: 19px; border-radius: 15px; }
  .intro h1 { font-size: 24px; }
  .pair-layout { grid-template-columns: 1fr; gap: 20px; margin-top: 18px; }
  .scan-box { min-height: 160px; padding: 16px; }
  .qr-frame canvas { max-width: 300px; }
  .manual-panel { padding: 16px; }
  .field-row { flex-wrap: wrap; }
  .field-row .ghost, .field-row .primary { width: 100%; }
  .drop { flex-direction: column; gap: 9px; padding: 18px; }
}

/* Language switcher */
.site-header { justify-content: space-between; }
.lang-picker { flex: 0 0 auto; }
.lang-picker select {
  max-width: 130px;
  padding: 6px 28px 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 11.5px;
  font-weight: 550;
  cursor: pointer;
}
.lang-picker select:hover { border-color: #cbd5e1; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Arabic / RTL */
html[dir="rtl"] .field-row textarea {
  direction: ltr;
  text-align: left;
}
html[dir="rtl"] .close {
  right: auto;
  left: 16px;
}
html[dir="rtl"] .brand-name { letter-spacing: 0; }

@media (max-width: 640px) {
  .lang-picker select { max-width: 105px; padding-inline: 7px 24px; font-size: 11px; }
}

/* GitHub entry */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.github-link {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: #0f172a;
  transition: color .15s, border-color .15s, background .15s, transform .15s;
}
.github-link:hover {
  color: #2563eb;
  border-color: #cbd5e1;
  background: #f8fafc;
  transform: translateY(-1px);
}
.github-link svg { width: 17px; height: 17px; display: block; }
.github-link:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

@media (max-width: 640px) {
  .header-actions { gap: 8px; }
  .github-link { width: 30px; height: 30px; }
  .github-link svg { width: 16px; height: 16px; }
}
