:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1c1f2a;
  --muted: #6b7280;
  --border: #e3e5ee;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --mine: #e9e8ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --panel: #1c1e27;
    --text: #e8e9ef;
    --muted: #9aa0ae;
    --border: #2c2f3b;
    --accent: #7c74ff;
    --accent-soft: #262649;
    --mine: #2a2852;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

button, input, textarea { font: inherit; color: inherit; }
code, kbd, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace; }
kbd {
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 4px; font-size: .85em; background: var(--panel);
}
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.big { padding: 11px 18px; font-size: 1.05em; width: 100%; }
.btn.small { padding: 4px 10px; font-size: .88em; }
.icon-btn {
  border: none; background: transparent; cursor: pointer; font-size: 20px; line-height: 1;
  width: 36px; height: 36px; border-radius: 8px; color: var(--text); flex: none;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.small { width: 26px; height: 26px; font-size: 14px; }

/* ---------- lobby ---------- */
.screen { min-height: 100%; }
#lobby { display: flex; justify-content: center; padding: 40px 16px; }
.lobby-inner { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon { width: 56px; height: 56px; border-radius: 14px; }
.brand h1 { margin: 0; font-size: 28px; }
.tagline { margin: 2px 0 0; color: var(--muted); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.card h2 { margin: 0; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }
.card .btn.big { margin-top: auto; }
.card.warning { border-color: var(--warn); }
.card.warning p { color: var(--text); }
.code-input {
  width: 100%; padding: 10px 12px; font-size: 22px; letter-spacing: .12em; text-align: center;
  text-transform: uppercase; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.code-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.error { color: var(--danger) !important; margin: 0; font-size: .92em; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.recent-list li { display: flex; align-items: center; gap: 10px; }
.recent-list .code { font-family: ui-monospace, Consolas, monospace; font-size: 16px; letter-spacing: .06em; }
.recent-list .when { color: var(--muted); font-size: .88em; flex: 1; }
.lobby-footer { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.fineprint { color: var(--muted); font-size: .88em; margin: 0; }

/* ---------- room ---------- */
#room { height: 100vh; height: 100dvh; display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.spacer { flex: 1; }
.room-code {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 5px 10px;
  cursor: pointer; display: inline-flex; gap: 8px; align-items: baseline;
}
.room-code:hover { border-color: var(--accent); }
.room-code .label { color: var(--muted); font-size: .85em; }
#room-code { font-family: ui-monospace, Consolas, monospace; font-size: 17px; letter-spacing: .08em; font-weight: 600; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .9em; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.status[data-state="polling"] .dot { background: var(--warn); }
.status[data-state="offline"] .dot { background: var(--danger); }

.peers {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: .85em; padding: 3px 10px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--bg);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.chip.self { color: var(--muted); }
.chip.waiting::before, .chip.unknown::before { background: var(--muted); }
.chip.waiting, .chip.unknown { color: var(--muted); border-style: dashed; }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
.banner > span { flex: 1; }
.error-banner { background: #fdecec; color: #7f1d1d; }
@media (prefers-color-scheme: dark) { .error-banner { background: #3b1717; color: #fecaca; } }

.feed { flex: 1; overflow-y: auto; padding: 16px 12px 24px; }
.items { display: flex; flex-direction: column; gap: 12px; max-width: 860px; margin: 0 auto; }
#uploads:not(:empty) { margin-top: 12px; }

.empty { max-width: 560px; margin: 24px auto; text-align: center; }
.empty-code-label { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: .8em; }
.empty-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 40px; font-weight: 700;
  letter-spacing: .1em; margin: 4px 0 10px; user-select: all;
}
.empty-actions { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.qr-figure { margin: 18px auto 6px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-figure figcaption { color: var(--muted); font-size: .9em; }
/* QR codes stay black on white (see qr.js) in dark mode too; cameras need the contrast. */
.qr svg { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }
.ico { width: 18px; height: 18px; flex: none; }

.item { display: flex; flex-direction: column; gap: 4px; max-width: 80%; align-self: flex-start; }
.item.mine { align-self: flex-end; align-items: flex-end; }
.item .meta { font-size: .8em; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item .meta .tag {
  border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: .92em;
}
.bubble {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); max-width: 100%; overflow: hidden; position: relative;
}
.item.mine .bubble { background: var(--mine); }
.item.flash .bubble { outline: 2px solid var(--ok); }
.bubble pre.text {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; max-height: 420px; overflow: auto;
}
.bubble a { color: var(--accent); word-break: break-all; }
.bubble .more { margin-top: 6px; }
.bubble img.preview {
  display: block; max-width: 100%; max-height: 360px; border-radius: 6px; cursor: zoom-in; background: var(--bg);
}
.bubble img.preview.zoom { max-height: none; cursor: zoom-out; }
.file { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.file .icon { font-size: 30px; line-height: 1; }
.file .name { font-weight: 600; word-break: break-all; }
.file .size { color: var(--muted); font-size: .88em; }
.placeholder { color: var(--muted); font-size: .9em; }
.item .actions { display: flex; gap: 6px; opacity: .85; }
.item:hover .actions { opacity: 1; }
.item .actions .btn { padding: 2px 10px; font-size: .82em; }
.progress { height: 4px; background: var(--border); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.item.failed .bubble { border-color: var(--danger); }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 200px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); line-height: 1.4;
}
.composer textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.composer .btn { height: 40px; }
@media (max-width: 560px) {
  #clip-btn { display: none; }
  #invite-btn .btn-label, .room-code .label { display: none; }
  /* Keep the top bar on one line: the status takes the space left and truncates long states. */
  .topbar { gap: 6px; padding: 8px; }
  .topbar .spacer { display: none; }
  .status { flex: 1 1 0; min-width: 0; justify-content: flex-end; }
  .status .dot { flex: none; }
  #status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 340px) { #room-code { font-size: 15px; letter-spacing: .04em; } }

.drop-overlay {
  position: absolute; inset: 8px; border: 3px dashed var(--accent); border-radius: 16px;
  background: rgba(79, 70, 229, .08); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 600; color: var(--accent); pointer-events: none; z-index: 5;
}

/* ---------- dialog / toasts ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text);
  padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.settings { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.settings h2 { margin: 0 0 4px; }
.settings hr { border: none; border-top: 1px solid var(--border); width: 100%; margin: 4px 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .92em; color: var(--muted); }
.field input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.toggle { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.toggle input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--accent); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.invite { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.invite h2, .invite p { margin: 0; }
.invite .qr { display: flex; justify-content: center; }
.invite-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 30px; font-weight: 700;
  letter-spacing: .1em; user-select: all;
}

.toasts {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: #1f2330; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: .92em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: min(560px, 92vw); pointer-events: auto;
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); }
.toast.ok { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
