:root {
  --bg: #080b14;
  --bg-elevated: rgba(18, 24, 40, 0.78);
  --stroke: rgba(255, 255, 255, 0.08);
  --text: #eef3ff;
  --muted: #8b95b3;
  --accent: #5eead4;
  --accent-2: #67e8f9;
  --accent-dim: rgba(94, 234, 212, 0.14);
  --danger: #fb7185;
  --own: linear-gradient(135deg, #2dd4bf, #14b8a6);
  --theirs: #1a2236;
  --system: #8b95b3;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Noto Sans SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.bg-orb {
  position: fixed;
  width: 52vw;
  height: 52vw;
  max-width: 520px;
  max-height: 520px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}
.bg-orb-a { background: #164e63; top: -12%; left: -8%; }
.bg-orb-b { background: #4c1d95; bottom: -18%; right: -10%; }

#app, .view {
  position: relative;
  z-index: 1;
  height: 100%;
}
.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
}
.view[hidden] { display: none !important; }

.card {
  width: min(100%, 440px);
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 32px 28px 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.card-narrow { width: min(100%, 400px); }

.brand { text-align: center; margin-bottom: 28px; }
.logo {
  display: inline-flex;
  gap: 0;
  margin-bottom: 12px;
}
.logo-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px var(--accent);
}
.logo-dot + .logo-dot {
  margin-left: -6px;
  background: #f0abfc;
  box-shadow: 0 0 18px #f0abfc;
  opacity: 0.9;
}
h1 {
  font-family: Syne, "Noto Sans SC", sans-serif;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin: 0 0 8px;
  font-size: 28px;
}
h2 { margin: 0 0 8px; font-size: 22px; }
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

form label {
  display: block;
  margin-bottom: 14px;
}
form label span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: rgba(8, 11, 20, 0.55);
  border: 1px solid var(--stroke);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus {
  border-color: rgba(94, 234, 212, 0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  color: var(--text);
  background: transparent;
}
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #2dd4bf, #22d3ee);
  color: #042f2e;
  font-weight: 700;
  margin-top: 6px;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
.btn-ghost {
  color: var(--muted);
  background: transparent;
}
.btn-ghost:hover { color: var(--text); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; margin: 0; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn-primary { width: auto; flex: 1; }

.field-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 1.2em;
  margin: 0 0 8px;
}
.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 18px 0 0;
}

.topbar {
  position: absolute;
  top: var(--safe-t);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
}
.who-label { display: block; font-size: 11px; color: var(--muted); }
.pair-card { margin-top: 36px; }

.code-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 22px 0 14px;
}
.code-cell {
  width: 100%;
  aspect-ratio: 0.82;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
  padding: 0;
  border-radius: 14px;
  -webkit-text-security: disc;
  text-security: disc;
  user-select: none;
}
.pair-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 13px;
  margin: 0 0 12px;
}
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite;
}
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.view-chat {
  padding: 0;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  align-items: stretch;
  overflow: hidden;
}
.chat-top {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(8, 11, 20, 0.72);
  backdrop-filter: blur(16px);
}
.chat-peer { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700;
}
.online { display: block; font-size: 12px; color: var(--accent); }
.online.left { color: var(--danger); }
.chat-actions { display: flex; gap: 4px; }

.message-list {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.message-list::-webkit-scrollbar { display: none; }
.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 420px);
}
.bubble-wrap.own { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.theirs { align-self: flex-start; }
.bubble-wrap.system {
  align-self: center;
  max-width: 90%;
}
.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--theirs);
}
.own .bubble {
  background: var(--own);
  color: #042f2e;
}
.system .bubble {
  background: transparent;
  color: var(--system);
  font-size: 12px;
  padding: 4px 0;
  text-align: center;
}
.bubble img {
  display: block;
  max-width: 220px;
  max-height: 280px;
  border-radius: 12px;
  cursor: zoom-in;
}
.bubble img.sticker {
  width: 52px;
  height: 52px;
  cursor: default;
  background: transparent;
}
.meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.partner-left-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(251, 113, 133, 0.12);
  color: #fecdd3;
  font-size: 13px;
}

.composer {
  width: 100%;
  position: relative;
  padding: 8px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--stroke);
  background: rgba(8, 11, 20, 0.86);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
#text-input {
  flex: 1;
  resize: none;
  overflow-y: hidden;
  max-height: 120px;
  min-height: 40px;
  height: 40px;
  line-height: 20px;
  padding: 10px 12px;
  scrollbar-width: none;
}
#text-input::-webkit-scrollbar { display: none; }
.icon-btn {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  line-height: 1;
  display: grid;
  place-items: center;
  border: 0;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
}
.icon-btn.active { background: var(--accent-dim); color: var(--accent); }
.btn-send { width: auto; margin: 0; padding: 10px 16px; }

.panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(100% + 8px);
  background: #121826;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.panel[hidden] { display: none !important; }
emoji-picker {
  width: 100%;
  height: 260px;
  --background: #121826;
  --border-color: transparent;
  --border-size: 0;
  --border-radius: 16px;
  --button-hover-background: rgba(255, 255, 255, 0.08);
  --button-active-background: rgba(94, 234, 212, 0.18);
  --category-emoji-size: 1.05rem;
  --category-emoji-padding: 0.28rem 0;
  --emoji-size: 1.2rem;
  --emoji-padding: 0.22rem;
  --num-columns: 8;
  --indicator-color: #5eead4;
  --indicator-height: 2px;
  --input-border-color: rgba(255, 255, 255, 0.1);
  --input-border-radius: 10px;
  --input-border-size: 1px;
  --input-font-color: #eef3ff;
  --input-font-size: 13px;
  --input-line-height: 1.3;
  --input-padding: 0.4rem 0.65rem;
  --input-placeholder-color: #8b95b3;
  --outline-color: #5eead4;
  --outline-size: 2px;
}
.sticker-panel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: 8px;
  max-height: 168px;
  overflow-y: auto;
  scrollbar-width: none;
}
.sticker-panel::-webkit-scrollbar { display: none; }
.sticker-panel button {
  background: rgba(255,255,255,0.04);
  border: 0;
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
}
.sticker-panel img {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  display: block;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: calc(18px + var(--safe-t));
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0,0,0,0.82);
  display: grid;
  place-items: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

@media (max-width: 560px) {
  .chat-actions .btn { padding: 8px 10px; font-size: 13px; }
  .bubble img { max-width: 72vw; }
  .code-cell { font-size: 18px; }
}
