:root {
  --bg: #f6f7fb;
  --fg: #1f2330;
  --muted: #6b7280;
  --card: #ffffff;
  --accent: #4f46e5;
  --accent-2: #06b6d4;
  --border: #e5e7eb;
}
/* Dark colours: follow the device (Auto), unless the user picked Light or Dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --fg: #e8eaf0;
    --muted: #9aa1b2;
    --card: #1a1d27;
    --border: #2a2e3b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --fg: #e8eaf0;
  --muted: #9aa1b2;
  --card: #1a1d27;
  --border: #2a2e3b;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.25rem; display: flex; gap: 8px; align-items: center; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; position: relative; }
footer { text-align: center; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 4px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

button {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); }
button:active { transform: scale(.97); }

.peers {
  display: flex; flex-wrap: wrap; gap: 28px; justify-content: center; max-width: 720px;
}
.peer {
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: 120px;
  background: none; color: var(--fg); padding: 0; font-weight: 400; user-select: none;
}
.avatar {
  position: relative; width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.2rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(79, 70, 229, .3);
  transition: transform .15s;
}
.peer:hover .avatar { transform: translateY(-3px); }
.peer.dragover .avatar { transform: scale(1.1); outline: 3px dashed var(--accent-2); outline-offset: 4px; }
.ring { position: absolute; inset: -6px; width: 96px; height: 96px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke: var(--accent-2); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .2s; }
.peer-name { font-weight: 600; text-align: center; }
.peer-status { font-size: .8rem; color: var(--muted); min-height: 1em; text-align: center; }

.empty { text-align: center; max-width: 420px; }
.empty h2 { margin: 24px 0 8px; font-size: 1.2rem; }
.empty p { color: var(--muted); line-height: 1.5; margin: 0; }
.radar { position: relative; width: 140px; height: 140px; margin: 0 auto; }
.radar span {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent);
  opacity: 0; animation: pulse 3s infinite;
}
.radar span:nth-child(2) { animation-delay: 1s; }
.radar span:nth-child(3) { animation-delay: 2s; }
@keyframes pulse { from { transform: scale(.2); opacity: .8; } to { transform: scale(1); opacity: 0; } }
.hidden { display: none !important; }

dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--fg);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin: 0 0 12px; }
dialog ul { list-style: none; padding: 0; margin: 0 0 12px; max-height: 40vh; overflow: auto; }
dialog li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; align-items: center; word-break: break-all; }
dialog li a { color: var(--accent); font-weight: 600; white-space: nowrap; }
dialog li img { max-width: 64px; max-height: 64px; border-radius: 6px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; margin-top: 12px; }
input, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
}
.code { font-size: 2rem; font-weight: 800; letter-spacing: .3em; text-align: center; margin: 8px 0; }
.qr { display: grid; place-items: center; }
.qr img { background: #fff; padding: 8px; border-radius: 8px; }
.msg { white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 12px; border-radius: 10px; max-height: 40vh; overflow: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  transition: transform .25s; max-width: calc(100vw - 32px); z-index: 10;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.footer-controls { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.switch { display: inline-flex; gap: 6px; align-items: center; font-size: .9rem; cursor: pointer; }
.switch input { width: auto; accent-color: var(--accent); }
button.small { padding: 6px 12px; font-size: .85rem; }

.header-actions { display: flex; gap: 8px; }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: #ef4444; color: #fff; font-size: .75rem;
}

#lockBtn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.lock-state { text-align: center; font-weight: 600; color: var(--accent); margin: -4px 0 8px; }
.pair-lock { margin-top: 10px; }
.pair-lock .row, .join-code .row { margin-top: 6px; }
.row button { white-space: nowrap; }
.join-code { margin-top: 12px; }
.join-code summary { cursor: pointer; }
.join-code input { min-width: 0; }

.steps { margin: 0 0 12px; padding-left: 20px; line-height: 1.9; }
.share-glyph { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border); font-size: .8rem; }

.ext-link { color: var(--accent); font-weight: 600; text-decoration: none; }
@media (pointer: coarse) { .ext-link { display: none; } } /* phones can't use browser extensions */

/* Transfers */
dialog.wide-dlg { width: min(94vw, 520px); }
.transfer-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; max-height: 60vh; overflow: auto; }
.transfer-list li { display: block; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.transfer-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.transfer-name { font-weight: 600; word-break: break-word; }
.transfer-meta { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.transfer-bar { height: 6px; border-radius: 99px; background: var(--border); margin-top: 8px; overflow: hidden; }
.transfer-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .2s; }
.transfer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.transfer-actions a, .transfer-actions button { font-size: .78rem; }
.transfer-actions a { color: var(--accent); font-weight: 600; }
.t-done { color: #16a34a; }
.t-failed, .t-cancelled, .t-declined { color: #ef4444; }

/* Recent rooms */
.recent { margin-top: 14px; }
.recent-title { margin-bottom: 6px; }
.recent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.recent-list li { display: flex; gap: 6px; align-items: stretch; padding: 0; border: 0; }
.recent-join {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); font-weight: 600; padding: 8px 12px;
}
.recent-join small { font-weight: 400; color: var(--muted); font-size: .75rem; }
.recent-join[disabled] { opacity: .65; cursor: default; }
.recent-remove { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 0 10px; }

/* Share-sheet banner */
.share-banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  margin: 0 16px; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.peers.picking .avatar { animation: pick 1.2s ease-in-out infinite; }
@keyframes pick { 50% { transform: scale(1.06); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent); } }

/* Device menu, trust, rename */
.link-btn { background: none; border: 0; padding: 0 4px; color: var(--accent); font-weight: 600; font-size: .85rem; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 14px; }
.trust-row { margin-top: 4px; }
.trust-badge {
  position: absolute; right: -2px; bottom: -2px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: .85rem; background: #f59e0b; color: #fff;
  border: 2px solid var(--bg);
}
dialog .switch { display: flex; margin: 6px 0; line-height: 1.4; }
dialog input#renameInput { margin-top: 4px; }

/* Chat room */
.menu-row .wide-btn { grid-column: 1 / -1; }
.chat-attach {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border);
}
.chat-attach img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.chat-attach span { flex: 1; }
.chat-img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; cursor: zoom-in; background: var(--bg); }
.chat-img-link { font-size: .75rem; color: var(--accent); font-weight: 600; }
.chat.dragover { outline: 3px dashed var(--accent-2); outline-offset: -8px; }
.chat-head-actions { display: flex; gap: 6px; }
.chat-divider { align-self: center; font-size: .72rem; color: var(--muted); margin: 4px 0; }
.chat {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 5;
  display: flex; flex-direction: column; background: var(--card); border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0,0,0,.12);
}
.chat-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.chat-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { text-align: center; margin: auto 0; line-height: 1.6; }
.chat-msg {
  align-self: flex-start; max-width: 88%; min-width: 0; padding: 8px 12px; border-radius: 14px;
  background: var(--bg); border: 1px solid var(--border);
}
.chat-msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--card)); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.chat-meta { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.chat-body { display: grid; gap: 8px; min-width: 0; }
.chat-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.chat-text a { color: var(--accent); }
.chat-foot { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 4px; font-size: .72rem; color: var(--muted); }
.copy-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 500;
}
.code-block { border-radius: 10px; overflow: hidden; background: #0d1117; border: 1px solid #30363d; min-width: 0; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; background: #161b22; color: #8b949e; font-size: .72rem; }
.code-bar .copy-btn { color: #c9d1d9; border-color: #30363d; }
.code-block pre {
  margin: 0; padding: 10px 12px; overflow-x: auto; color: #e6edf3; font-size: .82rem; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre;
}
.chat-form {
  display: flex; gap: 8px; align-items: flex-end; padding: 12px; border-top: 1px solid var(--border);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.chat-form textarea { resize: none; max-height: 200px; line-height: 1.4; }
.chat-form textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
#codeToggle { font-family: ui-monospace, monospace; }
#codeToggle.active { background: var(--accent); color: #fff; border-color: var(--accent); }
code { font-family: ui-monospace, monospace; }

header button { white-space: nowrap; }
@media (max-width: 440px) {
  header { padding: 12px 16px; }
  .header-actions { gap: 6px; }
  .header-actions button { padding: 8px 12px; }
  .wide { display: none; }
}
