:root {
  --bg: #0f1115;
  --card: #1a1e26;
  --card2: #232936;
  --fg: #e8eaf0;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --accent2: #34c98e;
  --danger: #e05661;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #262c39;
}
header h1 { font-size: 1.1rem; margin: 0; letter-spacing: 0.5px; }
header h1 span { color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 10px; }
.me-name { color: var(--muted); font-weight: 600; font-size: 0.9rem; }

main { flex: 1; overflow: hidden; display: flex; }

.view {
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  overflow-y: auto;
}
.view.active { display: flex; }

button {
  font: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
  background: var(--card2);
  color: var(--fg);
}
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--fg); }
button.big { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 10px; }

.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }

.qr-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#qr {
  width: min(320px, 80vw);
  height: auto;
  border-radius: 8px;
  image-rendering: pixelated;
}

h2 { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 22px 0 8px; }

#peer-list { list-style: none; margin: 0; padding: 0; }
#peer-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
#peer-list li:hover { background: var(--card2); }
.peer-name { flex: 1; font-weight: 600; }
.peer-transport { color: var(--muted); font-size: 0.8rem; }
.peer-del { background: transparent; color: var(--muted); padding: 4px 8px; }
.peer-del:hover { color: var(--danger); }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #555d70;
  display: inline-block;
  flex-shrink: 0;
}
.dot.ok { background: var(--accent2); }
.dot.bad { background: var(--danger); }

/* scanner — square preview so 90° rotation steps still fill the frame */
.cam-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 1 / 1; max-height: 60vh; margin: 0 auto; width: min(100%, 60vh); }
#cam { width: 100%; height: 100%; display: block; object-fit: cover; }
#cam.r90 { transform: rotate(90deg); }
#cam.r180 { transform: rotate(180deg); }
#cam.r270 { transform: rotate(270deg); }
.cam-frame {
  position: absolute;
  inset: 12%;
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  pointer-events: none;
}

/* chat */
#view-chat { padding: 0; max-width: 680px; height: 100%; overflow: hidden; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #262c39;
}
.chat-title { flex: 1; display: flex; flex-direction: column; }
.transport { font-size: 0.75rem; }
.transport.p2p { color: var(--accent2); }
.transport.relay { color: var(--accent); }
.transport.offline { color: var(--muted); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.in { background: var(--card2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg img { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 6px; }
.file-label { display: block; font-size: 0.9rem; }
a.file-label { color: inherit; text-decoration: underline; }
.progress {
  height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  margin-top: 7px;
  overflow: hidden;
}
.progress div { height: 100%; background: #fff; border-radius: 3px; transition: width 0.15s; }
.msg.in .progress { background: #39404f; }
.msg.in .progress div { background: var(--accent2); }
.delivered { display: block; font-size: 0.72rem; opacity: 0.8; margin-top: 4px; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #262c39;
}
#chat-input {
  flex: 1;
  font: inherit;
  background: var(--card);
  border: 1px solid #2c3342;
  border-radius: var(--radius);
  color: var(--fg);
  padding: 10px 14px;
  outline: none;
}
#chat-input:focus { border-color: var(--accent); }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 20px;
  z-index: 20;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 380px;
}
.modal-card h3 { margin: 0 0 8px; }

/* E2EE verification */
.verify-phrase {
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  background: var(--card2);
  border-radius: var(--radius);
  padding: 16px 12px;
  line-height: 1.6;
}
.verify-code {
  text-align: center;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  letter-spacing: 3px;
  margin-top: -6px;
}

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: #2b3140;
  color: var(--fg);
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  z-index: 30;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
