:root {
  --bg: #000000;
  --panel: #050507;
  --panel-2: #0a0a0d;
  --line: #16161a;
  --line-2: #22222a;
  --text: #ffffff;
  --muted: #7e7e86;
  --red: #ff3b30;
  --red-dim: rgba(255, 59, 48, 0.15);
  --green: #30d158;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: var(--sans);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 860px;
  margin: 0 auto;
}

button { font-family: var(--mono); }
button:focus { outline: none; }
button:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }

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

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  height: 60px;
  background: rgba(0,0,0,0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
  z-index: 10;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font: 800 16px var(--mono);
  flex: none;
}

.brand-text { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }

.brand-text strong {
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 700;
}

.subtitle { font-size: 10px; color: var(--muted); font-family: var(--mono); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.online { background: var(--green); box-shadow: 0 0 8px rgba(48, 209, 88, 0.5); }
.dot.busy { background: var(--red); box-shadow: 0 0 8px rgba(255, 59, 48, 0.5); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 12px;
  font: 700 10px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.pill:hover { background: #14141a; }
.pill:active { background: #16161a; }
.pill.off { color: var(--muted); }
.pill.primary { background: var(--text); color: #000; border-color: var(--text); }
.pill.primary:hover { background: #e8e8ea; }

.call-btn.active {
  background: var(--red); border-color: var(--red); color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5); }
  50% { box-shadow: 0 0 0 9px rgba(255, 59, 48, 0); }
}

.select {
  appearance: none; -webkit-appearance: none;
  background-color: var(--panel-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%2388888e'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 8px 28px 8px 12px;
  font: 700 11px var(--mono);
  letter-spacing: 0.04em;
  cursor: pointer;
  max-width: 190px;
  outline: none;
}
.select:focus { border-color: var(--text); }
.select option { background: var(--panel-2); color: var(--text); }

/* ---------- chat ---------- */

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 18px 12px;
  scroll-behavior: smooth;
}

#messages { display: flex; flex-direction: column; gap: 14px; }

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: fade 0.2s ease;
  max-width: 100%;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font: 700 11px var(--mono);
  flex: none;
}
.msg.user .msg-avatar { color: var(--text); }

.bubble {
  padding: 10px 15px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 76%;
  position: relative;
}
.msg.jef .bubble {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  color: var(--text);
}
.msg.user .bubble {
  background: var(--text);
  color: #000;
  border-bottom-right-radius: 6px;
}

.bubble .speak-replay {
  position: absolute; right: 8px; bottom: 6px;
  background: none; border: none; cursor: pointer;
  font: 700 9px var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); opacity: 0; transition: opacity 0.15s;
}
.msg.jef .bubble:hover .speak-replay { opacity: 1; }
.speak-replay:hover { color: var(--text); }

.caret {
  display: inline-block; width: 8px; height: 15px;
  background: var(--text);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 0.8s steps(2) infinite;
}

.typing .bubble {
  display: flex; gap: 5px; align-items: center;
  min-width: 54px; min-height: 30px;
}
.typing .tydot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing .tydot:nth-child(2) { animation-delay: 0.15s; }
.typing .tydot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.tool-chip {
  align-self: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line-2);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 80%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.sys-msg {
  align-self: center; text-align: center;
  color: var(--muted); font-size: 11px; font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.06em;
  max-width: 80%;
}

.greeting-card {
  align-self: center; text-align: center;
  margin-top: 30px; margin-bottom: 10px;
  animation: fade 0.35s ease;
}
.greeting-card .big-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font: 800 30px var(--mono);
  margin: 0 auto 18px;
}
.greeting-card h2 { font-size: 17px; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 8px; }
.greeting-card p { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.greeting-card .chips { display: flex; gap: 8px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

.chip {
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  transition: background 0.12s;
}
.chip:hover { background: #14141a; }

/* ---------- input bar ---------- */

#inputbar { padding: 10px 16px 14px; flex-shrink: 0; }

#inputWrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 24px;
  padding: 8px 8px 8px 18px;
  backdrop-filter: blur(14px);
  transition: border-color 0.15s;
}
#inputWrap:focus-within { border-color: var(--text); }

#textInput {
  flex: 1;
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 15px; font-family: var(--sans);
  resize: none; max-height: 140px; line-height: 1.45;
  padding: 8px 0;
}
#textInput::placeholder { color: var(--muted); }
#textInput:disabled { opacity: 0.45; }

.mic { font-size: 10px; }
.mic.recording {
  background: var(--red); border-color: var(--red); color: #fff;
  animation: pulse 1s infinite;
}

.send { flex: none; }

.hint { text-align: center; color: var(--muted); font-size: 10px; font-family: var(--mono); margin-top: 8px; letter-spacing: 0.04em; text-transform: uppercase; }

/* ---------- call overlay ---------- */

#callOverlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.96);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
#callOverlay.hidden { display: none; }

.call-card {
  text-align: center; padding: 30px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  width: min(420px, 92vw);
}

.call-ring { position: relative; width: 140px; height: 140px; }
.call-ring::before, .call-ring::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  animation: ring 2.4s ease-out infinite;
}
.call-ring::after { animation-delay: 1.2s; }
@keyframes ring {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}
.call-ring.listening::before, .call-ring.listening::after { border-color: rgba(255, 59, 48, 0.6); }
.call-ring.speaking::before, .call-ring.speaking::after { border-color: rgba(255, 255, 255, 0.7); }

.call-avatar {
  position: absolute; inset: 24px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font: 800 42px var(--mono);
}

.call-status {
  font-size: 16px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
}
.call-sub { color: var(--muted); font-size: 10px; font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; min-height: 14px; margin-top: -8px; }

.hold-btn {
  width: 150px; height: 150px; border-radius: 50%;
  border: 1px solid var(--text); cursor: pointer;
  background: var(--text);
  color: #000; font: 700 12px var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  transition: transform 0.12s, background 0.12s, color 0.12s, box-shadow 0.12s;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.hold-btn:active, .hold-btn.pressed {
  transform: scale(0.94);
  background: var(--red); border-color: var(--red); color: #fff;
  box-shadow: 0 0 0 8px var(--red-dim);
}

.end-btn { color: var(--muted); }
.end-btn:hover { color: var(--red); border-color: var(--red); }

/* ---------- memory panel ---------- */

#memOverlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.96);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.2s ease;
}
#memOverlay.hidden { display: none; }

.mem-panel {
  width: min(600px, 94vw);
  max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 20px;
  overflow: hidden;
}

.mem-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.mem-head strong { font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; }
.mem-count { flex: 1; color: var(--muted); font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }

.mem-add {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.mem-input {
  flex: 1;
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); font-size: 13px; font-family: var(--sans);
  border-radius: 12px; padding: 9px 12px; outline: none;
}
.mem-input:focus { border-color: var(--text); }
.mem-input::placeholder { color: var(--muted); }
.mem-select { max-width: 150px; padding: 9px 28px 9px 12px; }

.mem-list {
  flex: 1; overflow-y: auto;
  padding: 12px 18px 18px;
}

.mem-group { margin-bottom: 16px; }
.mem-group:last-child { margin-bottom: 0; }

.mem-group-label {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--muted);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.mem-group-label .n { color: var(--muted); opacity: 0.6; }

.mem-fact {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  animation: fade 0.15s ease;
}
.mem-fact.pinned { border-color: var(--line-2); }
.mem-fact-text { flex: 1; font-size: 13px; line-height: 1.45; min-width: 0; }
.mem-fact .tag {
  flex: none; font-family: var(--mono); font-size: 8px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 2px 7px;
}
.mem-fact .src { flex: none; font-family: var(--mono); font-size: 9px; color: var(--muted); opacity: 0.5; }

.mem-btn {
  flex: none; background: none; border: none; cursor: pointer;
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding: 4px 6px; border-radius: 8px;
  transition: color 0.12s, background 0.12s;
}
.mem-btn:hover { background: #14141a; color: var(--text); }
.mem-btn.pin.on { color: var(--text); }
.mem-btn.del:hover { color: var(--red); }

.mem-empty { text-align: center; color: var(--muted); font-size: 11px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em; padding: 30px 0; }

/* ---------- login ---------- */

#loginWrap {
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.login-card {
  width: min(360px, 94vw);
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 24px;
  padding: 40px 30px 26px;
  animation: fade 0.3s ease;
}
.login-card .big-avatar {
  width: 68px; height: 68px; border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font: 800 28px var(--mono);
  margin-bottom: 16px;
}
.login-card h2 { font-size: 15px; letter-spacing: 0.2em; text-transform: uppercase; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 10px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 22px; }

.login-tabs {
  display: flex; gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 22px;
  width: 100%;
}
.login-tabs .tab {
  flex: 1;
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  font: 700 10px var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  padding: 9px 0; border-radius: 9px;
  transition: background 0.12s, color 0.12s;
}
.login-tabs .tab.active { background: var(--text); color: #000; }
.login-tabs .tab:not(.active):hover { color: var(--text); }

.login-label {
  align-self: flex-start;
  color: var(--muted); font-size: 10px; font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.login-card .login-label:not(:first-of-type) { margin-top: 14px; }

.login-input {
  width: 100%;
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); font-size: 15px; font-family: var(--sans);
  border-radius: 12px; padding: 11px 14px; outline: none;
}
.login-input:focus { border-color: var(--text); }

.login-error {
  margin-top: 14px; color: #ffb3ba; font-size: 11px; font-family: var(--mono);
  letter-spacing: 0.04em; text-transform: uppercase; text-align: center;
}
.login-error.hidden { display: none; }

.login-btn { margin-top: 22px; width: 100%; justify-content: center; padding: 11px; font-size: 11px; }
.login-btn:disabled { opacity: 0.5; cursor: default; }

.login-hint { color: var(--muted); font-size: 10px; font-family: var(--mono); letter-spacing: 0.04em; margin-top: 16px; text-align: center; }

/* ---------- misc ---------- */

#toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100;
  align-items: center;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); padding: 10px 18px; border-radius: 12px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  animation: fade 0.2s ease;
}
.toast.error { border-color: var(--red); color: #ffb3ba; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #22222a; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #33333d; }

@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .controls { width: 100%; }
  .bubble { max-width: 84%; }
  .subtitle { display: none; }
}
