:root {
  --bg: #0f1720;
  --panel: #17212b;
  --card: #1c2733;
  --in: #1e2c3a;
  --out: #2f6ea5;
  --text: #e9eff5;
  --muted: #8396a8;
  --line: #22303d;
  --accent: #5fb0f4;
  --on: #3fbf7f;
  --warn: #e0775f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: #0a1017;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }

.app {
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.peer { display: flex; align-items: center; gap: 12px; min-width: 0; }
.peer-text { min-width: 0; }
.avatar {
  flex: none;
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, #e07aa6, #8f6bd8);
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px;
}
.name { font-weight: 650; font-size: 16px; }
.status {
  font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.online { color: var(--accent); }

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: var(--card);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn[aria-expanded="true"] { background: var(--out); }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px;
  background: var(--panel);
}
.chips:not(:empty) { padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(63, 191, 127, 0.14);
  color: #8fe0b5;
}
.chip.warn { background: rgba(224, 119, 95, 0.16); color: #f2a896; }

.panel {
  padding: 6px 14px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  max-height: 70vh;
  overflow-y: auto;
}
.panel-title {
  margin: 12px 4px 6px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.card { background: var(--card); border-radius: 14px; overflow: hidden; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.switch-row + .switch-row { border-top: 1px solid var(--line); }
.switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-name { font-size: 15px; }
.switch-hint { font-size: 12.5px; color: var(--muted); }

.switch {
  appearance: none; -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 46px; height: 28px;
  margin: 0;
  border-radius: 999px;
  background: #3a4755;
  transition: background 0.18s;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: white;
  transition: transform 0.18s;
}
.switch:checked { background: var(--on); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.5; }

.one-bar { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.one-row { display: flex; gap: 8px; }
.one-bar input, .one-bar select {
  margin: 0; border: 0; border-radius: 10px;
  background: var(--bg); color: var(--text);
  font-size: 15px; padding: 10px 12px;
}
.one-bar select { flex: 1; min-width: 0; }
.one-bar button {
  border: 0; border-radius: 10px;
  padding: 10px 16px;
  background: var(--out); color: white;
  font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.one-bar.on { box-shadow: inset 0 0 0 1px var(--warn); }
.one-bar.on button { background: var(--warn); }

.login, .chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.login { padding: 28px 20px; gap: 4px; overflow-y: auto; }
.login-title { margin: 0 0 6px; font-size: 24px; font-weight: 700; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.login input {
  width: 100%;
  margin: 6px 0;
  padding: 13px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text);
  font-size: 16px;
}
.login .primary {
  margin-top: 6px;
  border: 0; border-radius: 12px;
  padding: 13px 16px;
  background: var(--out); color: white;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.login .link {
  margin-top: 10px;
  border: 0; background: transparent;
  color: var(--accent);
  font-size: 15px; text-align: center; text-decoration: none;
  cursor: pointer;
}
.qr-extra { margin-top: 14px; color: var(--muted); font-size: 14px; }
.qr-extra summary { cursor: pointer; }
#login-qr { display: block; width: 240px; height: 240px; margin: 12px auto; background: white; border-radius: 12px; }
.err { margin: 8px 0 0; color: #f28b82; min-height: 1.2em; font-size: 13.5px; line-height: 1.4; }
.hidden { display: none !important; }

.log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 16px;
  line-height: 1.38;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}
.row.her .bubble { background: var(--in); border-bottom-left-radius: 5px; }
.row.me .bubble { background: var(--out); border-bottom-right-radius: 5px; }
.row.psych { justify-content: center; }
.row.psych .bubble {
  max-width: 92%;
  background: #241f16;
  color: #f6f0e4;
  border: 1px solid #c4a46a;
  border-left: 4px solid #e2c27a;
  border-radius: 14px;
}
.psych-title {
  margin-bottom: 6px;
  font-size: 11px; font-weight: 750;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: #e2c27a;
}
.psych-body { white-space: pre-wrap; }

.composer {
  display: flex; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1; min-width: 0;
  margin: 0; padding: 11px 14px;
  border: 0; border-radius: 20px;
  background: var(--bg); color: var(--text);
  font-size: 16px;
}
.composer button {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--out); color: white;
  display: grid; place-items: center;
  cursor: pointer;
}
