:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel2: #171e2c;
  --line: #232c3d;
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent: #58e6a8;
  --accent-dim: #2a8f63;
  --warn: #f2c14e;
  --bad: #ff6b6b;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
.muted { color: var(--muted); }

header.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(11, 14, 20, .82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; font-size: 18px; white-space: nowrap; }
.brand b { color: var(--accent); }
.presence { display: flex; align-items: center; gap: 6px; font-size: 13px; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
.chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px;
  font-size: 12px; background: var(--panel);
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.me { color: var(--accent); border-color: var(--accent-dim); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.live-dot.ok { background: var(--accent); animation: pulse 2s infinite; }
.live-dot.bad { background: var(--bad); }
.live-dot.warn { background: var(--warn); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(88, 230, 168, .45); }
  70% { box-shadow: 0 0 0 7px rgba(88, 230, 168, 0); }
  100% { box-shadow: 0 0 0 0 rgba(88, 230, 168, 0); }
}

main {
  max-width: 720px; margin: 0 auto;
  padding: 14px 14px calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.identity { display: flex; flex-direction: column; gap: 6px; }
.you-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.name-chip {
  font: inherit; font-weight: 700; color: var(--accent);
  background: none; border: 1px dashed transparent; border-radius: 8px;
  padding: 2px 6px; cursor: pointer;
}
.name-chip:hover { border-color: var(--line); background: var(--panel2); }
.name-input {
  font: inherit; font-weight: 700; color: var(--text);
  background: var(--panel2); border: 1px solid var(--accent-dim); border-radius: 8px;
  padding: 4px 8px; width: 200px; max-width: 60vw; outline: none;
}
.stats { font-size: 12.5px; }

.actions { display: flex; align-items: center; gap: 10px; }
.primary {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px;
  font: inherit; font-size: 16px; font-weight: 700; color: #06281a;
  background: var(--accent); border: 0; border-radius: var(--radius);
  padding: 14px 18px; cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
  min-height: 48px;
}
.primary:active { transform: scale(.98); }
.primary:hover { filter: brightness(1.07); }
.badge {
  font-size: 12.5px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); white-space: nowrap;
}
.badge.ok { color: var(--accent); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.entry.mine { border-color: rgba(88, 230, 168, .35); }
.entry.pop { animation: pop .28s ease; }
@keyframes pop {
  from { opacity: 0; transform: translateY(-6px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.udot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.ebody { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.link { color: var(--accent); text-decoration: none; word-break: break-all; font-weight: 600; }
.link:hover { text-decoration: underline; }
.plain {
  color: var(--text); word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px;
}
.meta { font-size: 12.5px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }
.meta .seq { opacity: .7; }

.empty {
  display: flex; flex-direction: column; gap: 6px; text-align: center;
  color: var(--muted); border-style: dashed;
}
.empty b { color: var(--text); }
.foot { text-align: center; font-size: 12px; margin: 0; }

.overlay { position: fixed; inset: 0; z-index: 20; background: #000; }
.overlay video { width: 100%; height: 100%; object-fit: cover; }
.frame {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  width: min(72vmin, 420px); height: min(72vmin, 420px);
  border-radius: 22px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .25), 0 0 0 9999px rgba(0, 0, 0, .45);
  pointer-events: none; overflow: hidden;
  transition: box-shadow .2s ease;
}
.overlay.sent .frame { box-shadow: 0 0 0 4px var(--accent), 0 0 0 9999px rgba(0, 0, 0, .45); }
.laser {
  position: absolute; left: 6%; right: 6%; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 2.2s ease-in-out infinite; opacity: .8;
}
@keyframes sweep { 0%, 100% { top: 8%; } 50% { top: 90%; } }
.close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px;
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 18px;
}
.scanpanel {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85) 40%);
  color: #fff; text-align: center;
}
#scanStatus { font-weight: 600; }
#lastSeen { font-size: 12.5px; color: #b9c0cf; word-break: break-all; }

.cam-help {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(88vw, 430px);
  background: rgba(18, 23, 34, .97); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px; z-index: 25;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.cam-help b { font-size: 15.5px; }
.cam-help p { margin: 0; color: #c6ccd9; font-size: 13.5px; line-height: 1.55; }
.cam-help code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  color: var(--accent); background: rgba(88, 230, 168, .08);
  padding: 1px 5px; border-radius: 6px; word-break: break-all;
}
.cam-help-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.cam-help-btn {
  flex: 1; min-height: 42px; text-align: center; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #06281a; font: inherit; font-weight: 700; font-size: 14px;
  border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
}
.cam-help-btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.cam-help-btn:active { transform: scale(.98); }

#toasts {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 30; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 14px; font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4); animation: pop .25s ease;
  max-width: min(90vw, 480px);
}
.toast.gone { opacity: 0; transition: opacity .4s; }
.toast.warn { border-color: var(--warn); }
.toast.bad { border-color: var(--bad); }
