/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg: #0a0a0f;
  --bg2: #0f0f18;
  --bg3: #141420;
  --border: rgba(99, 102, 241, 0.15);
  --accent: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.4);
  --accent-glow: rgba(99, 102, 241, 0.2);
  --text: #e2e8f0;
  --text-dim: #64748b;
  --text-muted: #334155;
  --danger: #ef4444;
  --success: #22c55e;
  --font: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 0 40px rgba(99, 102, 241, 0.08);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ─── Screens ────────────────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: none;
  &.active { display: flex; }
}

/* ─── Auth Screen ────────────────────────────────────────────────────────── */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(99,102,241,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 40% 60% at 80% 100%, rgba(99,102,241,0.06) 0%, transparent 70%);
}

.auth-container {
  width: 100%;
  max-width: 360px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;

  h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 4px;
    color: var(--text);
    font-family: var(--mono);
  }

  p {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
  }
}

.logo-face.mini {
  width: 80px;
  height: 80px;
  position: relative;

  svg { width: 100%; height: 100%; }
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;

  .field {
    position: relative;
    input {
      width: 100%;
      padding: 14px 16px;
      background: var(--bg3);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      color: var(--text);
      font-family: var(--font);
      font-size: 14px;
      outline: none;
      transition: border-color 0.2s;

      &:focus { border-color: var(--accent); }
      &::placeholder { color: var(--text-muted); }
    }
  }
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  letter-spacing: 0.5px;
  margin-top: 4px;

  &:hover { opacity: 0.9; }
  &:active { transform: scale(0.98); }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  padding: 4px 0;
  &.hidden { display: none; }
}

/* ─── App Screen ─────────────────────────────────────────────────────────── */
#app-screen {
  align-items: stretch;
}

.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

/* ─── Face Panel ─────────────────────────────────────────────────────────── */
.face-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  gap: 32px;
  position: relative;

  &::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
    opacity: 0.5;
  }
}

.face-container {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.face-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--border);

  &.outer { width: 220px; height: 220px; }
  &.inner { width: 180px; height: 180px; }
}

#nexus-face {
  width: 180px;
  height: 180px;
  position: relative;
  z-index: 1;
  transition: filter 0.3s;
}

.face-status {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-top: 8px;
}

/* Face state styles */
body.state-thinking #nexus-face { filter: drop-shadow(0 0 12px rgba(99,102,241,0.5)); }
body.state-speaking #nexus-face { filter: drop-shadow(0 0 16px rgba(99,102,241,0.7)); }
body.state-listening #nexus-face { filter: drop-shadow(0 0 12px rgba(34,197,94,0.5)); }

body.state-listening .eye { fill: var(--success) !important; }
body.state-listening .status-dot { fill: var(--success) !important; }
body.state-listening .face-status { color: var(--success); }

body.state-thinking .status-dot { animation: pulse-dot 1s ease-in-out infinite; }
body.state-speaking .mouth { animation: none; }

/* Scan line animation */
.scan-line {
  animation: scan 4s linear infinite;
  transform-origin: center;
}

@keyframes scan {
  0%, 100% { opacity: 0; transform: translateY(-60px); }
  10% { opacity: 0.2; }
  50% { opacity: 0.15; transform: translateY(60px); }
  90% { opacity: 0; }
}

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

@keyframes blink {
  0%, 94%, 100% { ry: 12; }
  96%, 98% { ry: 1; }
}

.left-eye { animation: blink 6s ease-in-out infinite; }
.right-eye { animation: blink 6s ease-in-out infinite 0.1s; }

/* Mouth animation for speaking */
@keyframes talk {
  0%, 100% { d: path("M 72 140 Q 100 152 128 140"); }
  25% { d: path("M 72 140 Q 100 156 128 140"); }
  50% { d: path("M 72 142 Q 100 148 128 142"); }
  75% { d: path("M 72 140 Q 100 154 128 140"); }
}

body.state-speaking .mouth { animation: talk 0.3s ease-in-out infinite; }

/* ─── Voice Controls ─────────────────────────────────────────────────────── */
.voice-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mic-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;

  svg { width: 22px; height: 22px; }

  &:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
  }

  &.listening {
    background: rgba(34,197,94,0.1);
    border-color: var(--success);
    color: var(--success);
    animation: mic-pulse 1.5s ease-in-out infinite;
  }
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(34,197,94,0); }
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;

  svg { width: 16px; height: 16px; }

  &:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
    background: var(--accent-glow);
  }

  &.active {
    border-color: var(--accent-dim);
    color: var(--accent);
  }

  &.muted {
    color: var(--text-muted);
    border-color: var(--text-muted);
    opacity: 0.5;
  }
}

/* ─── Chat Panel ─────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  flex-shrink: 0;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--text);
}

.dot-live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  50% { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

.chat-actions {
  display: flex;
  gap: 8px;
}

/* ─── Messages ───────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;

  &::-webkit-scrollbar { width: 4px; }
  &::-webkit-scrollbar-track { background: transparent; }
  &::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  gap: 4px;
  animation: msg-in 0.2s ease-out;

  &.user {
    align-self: flex-end;
    align-items: flex-end;

    .msg-content {
      background: var(--accent);
      color: white;
      border-radius: var(--radius) var(--radius) 4px var(--radius);
    }
  }

  &.assistant {
    align-self: flex-start;
    align-items: flex-start;

    .msg-content {
      background: var(--bg3);
      border: 1px solid var(--border);
      border-radius: var(--radius) var(--radius) var(--radius) 4px;
    }
  }

  &.thinking .msg-content {
    color: var(--text-dim);
    font-style: italic;
  }
}

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

.msg-content {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;

  span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-dim);
    animation: dot-bounce 1.2s ease-in-out infinite;

    &:nth-child(2) { animation-delay: 0.2s; }
    &:nth-child(3) { animation-delay: 0.4s; }
  }
}

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

/* ─── Chat Input ─────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.voice-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: var(--radius-sm);
  color: var(--success);
  font-size: 13px;

  &.hidden { display: none; }
}

.pulse-ring {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  animation: mic-pulse 1s ease-in-out infinite;
}

#transcript-preview {
  font-style: italic;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
  line-height: 1.5;

  &:focus { border-color: var(--accent-dim); }
  &::placeholder { color: var(--text-muted); }
  &::-webkit-scrollbar { width: 3px; }
  &::-webkit-scrollbar-thumb { background: var(--border); }
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.1s;

  svg { width: 18px; height: 18px; }

  &:hover { opacity: 0.85; }
  &:active { transform: scale(0.95); }
  &:disabled { opacity: 0.3; cursor: not-allowed; }
}

/* ─── Responsive (mobile) ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .face-panel {
    display: none;
  }

  .app-layout {
    flex-direction: column;
  }

  .chat-panel {
    height: 100%;
  }
}

@media (max-width: 900px) {
  .face-panel {
    width: 240px;
  }

  .face-container { width: 180px; height: 180px; }
  .face-ring.outer { width: 180px; height: 180px; }
  .face-ring.inner { width: 148px; height: 148px; }
  #nexus-face { width: 148px; height: 148px; }
}
