*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: #0d0d15;
  --surface2: #151520;
  --accent: #4f46e5;
  --accent-light: #818cf8;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --user-bubble: #3730a3;
  --bot-bubble: #1e1e2e;
  --danger: #ef4444;
  --cyan: #00d4ff;
  --radius: 18px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Login ─── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at 50% 38%, #001520 0%, var(--bg) 68%);
}

.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 320px;
  padding: 0 24px;
}

/* ─── HUD (Login) ─── */
.hud-wrap {
  width: 200px;
  height: 200px;
  filter: drop-shadow(0 0 10px rgba(0,212,255,0.45)) drop-shadow(0 0 28px rgba(0,212,255,0.2));
}
.hud-wrap svg { width: 100%; height: 100%; }

/* ─── HUD (Mic button) ─── */
.hud-mic-wrap {
  position: relative;
  width: 90px;
  height: 90px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(0,212,255,0.35));
  transition: filter 0.3s;
}

.hud-mic-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hud-mic-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,212,255,0.5);
  background: rgba(0,212,255,0.08);
  color: var(--cyan);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}
.hud-mic-btn svg { width: 14px; height: 14px; }
.hud-mic-btn:active { transform: translate(-50%,-50%) scale(0.9); }

.hud-mic-wrap.recording {
  filter: drop-shadow(0 0 12px rgba(239,68,68,0.55));
}
.hud-mic-wrap.recording .hud-mic-btn {
  border-color: rgba(239,68,68,0.75);
  background: rgba(239,68,68,0.14);
  color: var(--danger);
  animation: pulse-inner 1s infinite;
}
.hud-mic-wrap.recording .g-cw  { --dur: 2.5s; }
.hud-mic-wrap.recording .g-ccw { --dur: 1.8s; }

@keyframes pulse-inner {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ─── HUD ring animations ─── */
.g-cw, .g-ccw {
  transform-box: fill-box;
  transform-origin: center;
}
.g-cw  { animation: hud-cw  var(--dur, 20s) linear infinite; }
.g-ccw { animation: hud-ccw var(--dur, 20s) linear infinite; }

@keyframes hud-cw  { to { transform: rotate(360deg);  } }
@keyframes hud-ccw { to { transform: rotate(-360deg); } }

/* ─── PIN ─── */
.login-label {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.pin-dots { display: flex; gap: 16px; }

.pin-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.pin-dots span.filled {
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
.pin-dots.error span {
  border-color: var(--danger);
  background: var(--danger);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-6px); }
  60%     { transform: translateX(6px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 12px;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid rgba(0,212,255,0.12);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pin-key:active { background: rgba(0,212,255,0.18); transform: scale(0.94); }
.pin-clear  { font-size: 18px; }
.pin-empty  { opacity: 0; pointer-events: none; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

/* ─── Chat ─── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid #1a1a28;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0,212,255,0.4);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.4; }
}

#btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
#btn-logout:hover { color: var(--danger); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar       { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: #2a2a3a; border-radius: 2px; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  animation: pop-in 0.2s ease;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bubble.user {
  background: var(--user-bubble);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.bubble.bot {
  background: var(--bot-bubble);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid #2a2a3a;
}
.bubble.transcript {
  background: transparent;
  border: 1px dashed #2a2a3a;
  color: var(--text-muted);
  font-size: 13px;
  align-self: flex-end;
  border-radius: 10px;
}

/* Typing indicator */
#typing-indicator { padding: 0 16px 8px; }
#typing-indicator .bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  width: fit-content;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40%         { transform: translateY(-6px); opacity: 1; }
}

/* ─── Footer ─── */
footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid #1a1a28;
  flex-shrink: 0;
}

.footer-mic-row {
  display: flex;
  justify-content: center;
}

.footer-text-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#msg-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid #2a2a3a;
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
#msg-input:focus       { border-color: var(--cyan); }
#msg-input::placeholder { color: var(--text-muted); }

.footer-text-row button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.footer-text-row button svg { width: 18px; height: 18px; }
.footer-text-row button:active { transform: scale(0.92); }

#btn-send { background: var(--accent); color: #fff; }
#btn-send:hover { background: #4338ca; }
#btn-photo:hover { color: var(--cyan); }
