:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c1d26;
  --muted: #6b6f80;
  --border: #e2e4ec;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1016;
    --card: #1a1b24;
    --text: #e8e9f0;
    --muted: #9095a8;
    --border: #2c2e3b;
    --accent: #818cf8;
    --accent-text: #0f1016;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h2 { font-size: 15px; margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.status { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
.composer .row { flex-wrap: nowrap; }
@media (max-width: 520px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .status { gap: 6px; width: 100%; flex-wrap: wrap; }
  .status .btn { padding: 6px 10px; }
  .status .room-label { margin-right: auto; }
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.dot.on { background: var(--ok); }
.room-label { font-family: ui-monospace, monospace; color: var(--muted); white-space: nowrap; }
.lock { position: relative; cursor: help; font-family: system-ui, sans-serif; outline: none; }
.lock::after {
  content: attr(data-hint);
  position: absolute; top: calc(100% + 10px); right: -60px; z-index: 5;
  width: min(300px, calc(100vw - 32px));
  padding: 10px 12px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font: 13px/1.45 system-ui, sans-serif; white-space: normal; text-align: left;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.lock:hover::after, .lock:focus-visible::after, .lock.show::after {
  opacity: 1; visibility: visible; transform: none;
}
@media (max-width: 520px) {
  /* Pin the hint to the viewport edges so it is always fully on screen; with
     top: auto it stays just below the lock's line. */
  .lock::after { position: fixed; top: auto; left: 12px; right: 12px; width: auto; margin-top: 30px; }
}

main { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

textarea, input, select {
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; margin-bottom: 10px; min-height: 90px; }

.btn {
  white-space: nowrap;
  font: inherit; cursor: pointer;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.chips li.self { cursor: pointer; }
.chips li.self:hover { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.chips li.self:has(.name-edit) { padding: 0; border-color: var(--accent); }
.name-edit {
  font: inherit; font-size: 13px; padding: 2px 10px; border: 0; border-radius: 999px;
  background: transparent; outline: none; max-width: 60vw;
}
.chips { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li {
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); font-size: 13px;
}
.chips li.self { border-color: var(--accent); }

.clips { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.clips:first-child { margin-top: 0; }
.clips:empty { display: none; }
.clip { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.clip.new { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 18%, transparent); } to { background: transparent; } }
.clip pre {
  margin: 0 0 8px; white-space: pre-wrap; word-break: break-word;
  font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  max-height: 240px; overflow: auto;
}
.clip.pinned { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.clip { position: relative; }
.clip.latest {
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
}
.clip .pin { font-size: 15px; padding: 2px 8px; }
.clip.pinned .pin { color: var(--accent); }
.preview { margin-bottom: 8px; }
.preview img {
  display: block; max-width: 100%; max-height: 320px; border-radius: 8px; cursor: zoom-in;
  background: repeating-conic-gradient(var(--border) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}
.file-line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-width: 0; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; min-width: 0; }
.xfer { color: var(--accent); white-space: nowrap; }
.uploads { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.uploads:not(:empty) { margin-top: 10px; }
.uploads li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.uploads .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads progress { width: 40%; accent-color: var(--accent); }
.drop-overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.drop-overlay div {
  padding: 24px 36px; border-radius: var(--radius);
  border: 2px dashed var(--accent); background: var(--card);
  font-size: 18px; font-weight: 600;
}
.clip .meta { font-size: 12px; color: var(--muted); }
.clip a { color: var(--accent); }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text);
  padding: 0; max-width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
.pair { position: relative; }
.dialog-close {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer;
}
.pair h2:focus { outline: none; } /* initial focus target, so the X doesn't open with a focus ring */
.dialog-close:hover { background: var(--bg); color: var(--text); }
.pair { padding: 18px; display: grid; gap: 10px; justify-items: center; text-align: center; }
.qr { background: #fff; border-radius: 8px; padding: 8px; line-height: 0; }
.qr svg { width: 240px; height: 240px; }
.scan-video { width: 100%; max-width: 360px; border-radius: 8px; background: #000; }
label.btn { display: inline-block; }
.pair select { width: 100%; }
.url-row { display: flex; gap: 8px; align-items: center; width: 100%; }
.url-row code { flex: 1; word-break: break-all; font-size: 13px; text-align: left; }
.pair hr { width: 100%; border: 0; border-top: 1px solid var(--border); }
.room-controls { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; justify-content: center; }
.room-controls label { display: grid; gap: 4px; text-align: left; font-size: 13px; }
.room-controls input { width: 140px; font-family: ui-monospace, monospace; }

.center { text-align: center; }
.chips li .st { color: var(--muted); }
.chips li .st.direct { color: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
#empty { margin: 0; }
