:root {
  --bg: #0b1120;
  --bg-card: #151d31;
  --bg-inset: #0f1626;
  --line: #24304a;
  --text: #e6ecf8;
  --text-dim: #93a1bd;
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.05rem; font-weight: 650; margin: 0; letter-spacing: 0.2px; }

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background:
    linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 3h8v8H3V3zm2 2v4h4V5H5zm8-2h2v2h2V3h2v4h-4V5h-2V3zm6 0h2v8h-2v-2h-2V9h2V3zM3 13h2v2H3v-2zm4 0h2v2h2v-2h2v2h2v-2h2v2h-2v2h2v2h-2v-2h-2v2h-2v-2h2v-2H9v2H7v2H3v-4h2v-2H3v-2zm14 2h2v2h-2v-2zm-4 4h2v2h2v2h-4v-4z'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 3h8v8H3V3zm2 2v4h4V5H5zm8-2h2v2h2V3h2v4h-4V5h-2V3zm6 0h2v8h-2v-2h-2V9h2V3zM3 13h2v2H3v-2zm4 0h2v2h2v-2h2v2h2v-2h2v2h-2v2h2v2h-2v-2h-2v2h-2v-2h2v-2H9v2H7v2H3v-4h2v-2H3v-2zm14 2h2v2h-2v-2zm-4 4h2v2h2v2h-4v-4z'/%3E%3C/svg%3E");
}

main {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
}

.view.stack-gap { display: grid; gap: 14px; }

.tagline {
  color: var(--text-dim);
  text-align: center;
  margin: 8px auto 18px;
  line-height: 1.5;
}

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

.stack { display: grid; gap: 10px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 1rem;
  font-weight: 550;
  padding: 13px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: transparent;
  color: #04222a;
}
.btn-ghost { background: transparent; }
.btn-small { padding: 8px 12px; font-size: 0.85rem; border-radius: 9px; }

.join-form { display: grid; gap: 10px; }
.join-form label { color: var(--text-dim); font-size: 0.9rem; }
.join-form input {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 1.4rem;
  letter-spacing: 6px;
  text-transform: uppercase;
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  outline: none;
}
.join-form input:focus { border-color: var(--accent); }

.error { color: var(--err); text-align: center; }

.room-head .status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.status-row span:nth-child(2) { flex: 1; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-off { background: var(--warn); animation: pulse 1.4s infinite; }
.dot-on { background: var(--ok); animation: none; }

@keyframes pulse { 50% { opacity: 0.35; } }

.qr-wrap { text-align: center; transition: opacity 0.3s ease; }
.qr-wrap.minimized { display: none; }
#qrBox {
  display: inline-flex;
  background: #fff;
  padding: 12px;
  border-radius: 14px;
  margin: 14px 0 10px;
}
#qrBox svg { display: block; width: min(230px, 62vw); height: auto; }

.hint { color: var(--text-dim); font-size: 0.88rem; line-height: 1.5; margin: 8px 0 0; }

.dropzone {
  border-style: dashed;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-card));
}

.text-compose { display: grid; gap: 10px; }
.text-compose label { color: var(--text-dim); font-size: 0.9rem; }
.text-compose textarea {
  width: 100%;
  resize: vertical;
  min-height: 88px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  padding: 11px 12px;
  border-radius: 12px;
  outline: none;
}
.text-compose textarea:focus { border-color: var(--accent); }
.text-compose-footer { display: flex; align-items: center; gap: 10px; }
.text-compose-footer .hint { flex: 1; margin: 0; }

.messages h2 { font-size: 0.95rem; color: var(--text-dim); font-weight: 600; margin: 4px 4px 10px; }
#messageList { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.message {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.message-out { border-color: color-mix(in srgb, var(--accent) 38%, var(--line)); }
.message-meta { color: var(--text-dim); font-size: 0.78rem; margin-bottom: 5px; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }

.transfers h2 { font-size: 0.95rem; color: var(--text-dim); font-weight: 600; margin: 4px 4px 10px; }
#transferList { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.transfer {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}
.transfer .t-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.transfer .t-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}
.transfer .t-size { color: var(--text-dim); font-size: 0.85rem; white-space: nowrap; }
.transfer .t-state { color: var(--text-dim); font-size: 0.85rem; }
.transfer.done .t-state { color: var(--ok); }
.transfer.error .t-state { color: var(--err); }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}
.bar > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #3b82f6);
  transition: width 0.15s linear;
}

.t-actions { display: flex; gap: 8px; }
.t-actions .btn { padding: 9px 14px; font-size: 0.9rem; }

.banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--err) 14%, var(--bg-card));
  border: 1px solid color-mix(in srgb, var(--err) 40%, var(--line));
  color: var(--text);
}

.scan-card { display: grid; gap: 12px; justify-items: center; }
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
#scanVideo, #rxVideo {
  width: 100%;
  height: 100%;
  object-fit: contain; /* full sensor view — no crop that fakes zoom */
}

/* ---------- Camera controls ---------- */

.cam-controls {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.cam-controls.hidden { display: none !important; }

.cam-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cam-row label:first-child {
  font-size: 0.82rem;
  color: var(--text-dim);
  min-width: 130px;
}
.cam-row input[type="range"] { flex: 1; accent-color: var(--accent); }

.cam-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
}
.cam-check input { accent-color: var(--accent); }
.scan-frame {
  position: absolute;
  inset: 12%;
  border: 2px solid color-mix(in srgb, var(--accent) 80%, transparent);
  border-radius: 16px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.35);
}

.hidden { display: none !important; }

/* ---------- Direct QR transfer ---------- */

.card-title {
  font-size: 1rem;
  margin: 0 0 4px;
  font-weight: 650;
}

.hint.left { text-align: left; }

.qr-stage { text-align: center; }
#dsQrBox {
  display: inline-flex;
  background: #fff;
  padding: 10px;
  border-radius: 14px;
  margin-bottom: 12px;
}
#dsQrBox svg { width: min(78vw, 400px); height: auto; display: block; }
#dsQrBox:empty::after {
  content: "…";
  width: min(78vw, 400px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
}

.ds-status {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 12px;
}

.select {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.rx-progress { text-align: left; display: grid; gap: 8px; }

.live-line {
  color: var(--ok);
  font-size: 0.85rem;
  margin: 0;
}

.t-actions.error { color: var(--err); }
