/* localBuffer — one stylesheet, no build step, light + dark. */

:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eef0f4;
  --line: #e0e3ea;
  --line-strong: #c9cedb;
  --text: #1b1f27;
  --text-dim: #656d7e;
  --text-faint: #8b93a3;
  --accent: #5b5bd6;
  --accent-soft: #eeeeff;
  --accent-text: #ffffff;
  --danger: #d64545;
  --ok: #2f9e63;
  --warn: #c07d1a;
  --shadow: 0 1px 2px rgba(16, 20, 30, .05), 0 8px 24px -12px rgba(16, 20, 30, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-elev: #161b23;
    --bg-sunken: #10151c;
    --line: #262d38;
    --line-strong: #39424f;
    --text: #e6eaf1;
    --text-dim: #98a2b3;
    --text-faint: #6e7888;
    --accent: #7c7cf0;
    --accent-soft: #1c1f3a;
    --accent-text: #ffffff;
    --danger: #f2777a;
    --ok: #56c98a;
    --warn: #e0a53c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -16px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-elev: #161b23;
  --bg-sunken: #10151c;
  --line: #262d38;
  --line-strong: #39424f;
  --text: #e6eaf1;
  --text-dim: #98a2b3;
  --text-faint: #6e7888;
  --accent: #7c7cf0;
  --accent-soft: #1c1f3a;
  --accent-text: #ffffff;
  --danger: #f2777a;
  --ok: #56c98a;
  --warn: #e0a53c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -16px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }

.ic { width: 18px; height: 18px; flex: none; }
.ic-lg { width: 22px; height: 22px; }
.ic-xl { width: 44px; height: 44px; }

:root:not([data-theme="dark"]) .only-dark { display: none; }
:root[data-theme="dark"] .only-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-light { display: none; }
  :root:not([data-theme="light"]) .only-dark { display: inline-block; }
  :root[data-theme="light"] .only-dark { display: none; }
}

/* ---------- top bar ---------- */

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: -.01em;
}
.brand b { font-weight: 700; }
.brand svg { color: var(--accent); }

.spacer { flex: 1; }

.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.room-pill:hover { border-color: var(--accent); background: var(--accent-soft); }
.room-pill .hash { color: var(--text-faint); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  transition: background .2s;
}
.status.live .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.status.down .dot { background: var(--danger); }

.tools { display: flex; gap: 4px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); border-color: var(--line); }
.icon-btn:active { transform: translateY(1px); }

/* ---------- layout ---------- */

main {
  max-width: 940px;
  margin: 0 auto;
  padding: 22px max(14px, env(safe-area-inset-left)) 60px;
}

/* ---------- composer ---------- */

.composer {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); }

.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: vertical;
  min-height: 76px;
  padding: 6px 6px 10px;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
}
.composer textarea::placeholder { color: var(--text-faint); font-family: var(--sans); }

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.hints { flex: 1; min-width: 200px; font-size: 12px; color: var(--text-faint); }
.composer-actions { display: flex; gap: 8px; }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-sunken);
  color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:hover { background: var(--bg-sunken); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; margin-top: 4px; }

/* ---------- feed ---------- */

.feed-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 26px 4px 10px;
}
.feed-head h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .01em; }
.feed-meta { font-size: 12.5px; color: var(--text-faint); margin-left: auto; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop .22s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .item { animation: none; } }

.item.pinned { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.item.uploading { opacity: .75; }

.item-icon {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg-sunken);
  color: var(--text-dim);
  overflow: hidden;
}
.item-icon img { width: 100%; height: 100%; object-fit: cover; }

.item-main { min-width: 0; }

.item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}
.item-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-actions { margin-left: auto; display: flex; gap: 2px; opacity: .55; transition: opacity .15s; }
.item:hover .item-actions, .item:focus-within .item-actions { opacity: 1; }
@media (hover: none) { .item-actions { opacity: 1; } }
.item-actions .icon-btn { width: 30px; height: 30px; }
.item-actions .icon-btn.on { color: var(--warn); }
.item-actions .icon-btn.danger:hover { color: var(--danger); }
.item-actions .icon-btn.done { color: var(--ok); }

.item-meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 1px;
}
.item-meta .sep { opacity: .5; }

.item-text {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 260px;
  overflow: auto;
}
.item-text a { color: var(--accent); }

.item-preview {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-sunken);
  width: fit-content;
  max-width: min(100%, 420px);
}
.item-preview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  cursor: zoom-in;
}
.item-preview video, .item-preview audio { display: block; max-width: 100%; }
.item-preview audio { width: 100%; }

.progress {
  margin-top: 8px;
  height: 4px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .18s ease-out;
}

.empty {
  text-align: center;
  padding: 54px 20px;
  color: var(--text-dim);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty svg { color: var(--line-strong); margin-bottom: 8px; }
.empty p { margin: 4px 0; }
.empty .btn { margin-top: 14px; }

.foot {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--text-faint);
}
.foot span:last-child { margin-left: auto; }
.device-input {
  border: 0;
  border-bottom: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  width: 12ch;
  padding: 0 2px;
}
.device-input:focus { outline: none; border-color: var(--accent); color: var(--text); }

/* ---------- drop overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
}
.drop-overlay.on { display: grid; }
.drop-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 46px 62px;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
}
.drop-card svg { color: var(--accent); }
.drop-card span { color: var(--text-dim); font-size: 13px; }

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  padding: 20px;
  width: min(420px, calc(100vw - 28px));
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .55);
}
dialog::backdrop { background: rgba(8, 10, 14, .55); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
dialog p { margin: 4px 0 12px; }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dlg-head h2 { flex: 1; }
.dlg-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

dialog input[type="password"], dialog input:not([type]), .select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  margin-bottom: 10px;
}
dialog input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.error { color: var(--danger); font-size: 13px; }

#qr-img {
  display: block;
  width: 256px;
  height: 256px;
  margin: 6px auto 12px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  image-rendering: pixelated;
}
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.check input { margin-top: 3px; }

.room-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.room-list button {
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.room-list button:hover { border-color: var(--accent); color: var(--text); }

dialog.viewer {
  width: min(96vw, 1100px);
  padding: 10px;
  background: var(--bg-elev);
}
.viewer-close { position: absolute; top: 12px; right: 12px; background: var(--bg-elev); }
#viewer-body { display: grid; place-items: center; }
#viewer-body img, #viewer-body video { max-width: 100%; max-height: 82vh; border-radius: 8px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  z-index: 80;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: 16px;
  display: grid;
  gap: 8px;
  justify-items: end;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: slide-in .2s ease-out;
  max-width: min(90vw, 380px);
}
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast button {
  border: 0; background: transparent; color: var(--accent);
  font: inherit; font-weight: 600; cursor: pointer; padding: 0;
}
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- narrow screens ---------- */

@media (max-width: 620px) {
  .hints { display: none; }
  .status span { display: none; }
  main { padding-top: 14px; }
  .item { grid-template-columns: 32px 1fr; gap: 10px; padding: 11px; }
  .item-icon { width: 32px; height: 32px; }
  .composer-actions { flex: 1; }
  .composer-actions .btn { flex: 1; justify-content: center; }
  .toasts { left: 16px; justify-items: stretch; }
}
