:root {
  --user-hue: 220; /* Default: Altrusian Blue / Nilam Sapphire */
  --bg-space: #070a11;
  --bg-surface: rgba(14, 20, 32, 0.75);
  --bg-card: rgba(20, 28, 46, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: hsl(var(--user-hue), 85%, 65%);
  --accent-color: hsl(var(--user-hue), 85%, 65%);
  --accent-glow: hsla(var(--user-hue), 90%, 65%, 0.4);
  --text-main: #f0f4fc;
  --text-muted: #8b99b5;
  --text-dim: #55627d;
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

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

body {
  background-color: var(--bg-space);
  color: var(--text-main);
  font-family: var(--font-stack);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image: 
    radial-gradient(circle at 50% 20%, hsla(var(--user-hue), 70%, 25%, 0.15) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(20, 24, 38, 0.5) 0%, transparent 50%);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

/* Ambient Presence Stage */
.presence-stage {
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.halo-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s ease, box-shadow 0.4s ease;
  cursor: pointer;
}

.halo-core {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 20px var(--accent-glow);
  transition: all 0.3s ease;
}

.halo-aura {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid var(--accent-glow);
  opacity: 0.6;
}

/* Halo States */
.halo-ring.idle .halo-core {
  animation: pulse-idle 4s ease-in-out infinite;
}

.halo-ring.listening {
  transform: scale(1.12);
}

.halo-ring.listening .halo-core {
  box-shadow: 0 0 35px var(--accent-color);
  animation: pulse-listen 1.2s ease-in-out infinite;
}

.halo-ring.speaking {
  transform: scale(1.08);
}

.halo-ring.speaking .halo-core {
  animation: pulse-speak 1.6s ease-in-out infinite;
  box-shadow: 0 0 40px var(--accent-color);
}

.halo-ring.thinking .halo-core {
  opacity: 0.5;
  animation: pulse-think 0.8s ease-in-out infinite alternate;
}

@keyframes pulse-idle {
  0%, 100% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.05); opacity: 1; }
}

@keyframes pulse-listen {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

@keyframes pulse-speak {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.15); filter: brightness(1.3); }
}

@keyframes pulse-think {
  from { transform: scale(0.85); }
  to { transform: scale(1.15); }
}

.companion-title {
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-top: 10px;
  color: var(--text-main);
}

.companion-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Conversation Viewport */
.conversation-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: auto;
}

.message-item {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fade-in 0.3s ease forwards;
}

.message-item.user {
  align-self: flex-end;
}

.message-item.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.55;
  word-break: break-word;
}

.message-item.user .bubble {
  background: hsl(var(--user-hue), 35%, 20%);
  color: #ffffff;
  border: 1px solid hsla(var(--user-hue), 50%, 40%, 0.3);
  border-bottom-right-radius: 4px;
}

.message-item.assistant .bubble {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.bubble-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 4px;
  padding: 0 4px;
}

.message-item.user .bubble-meta {
  text-align: right;
}

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

/* Bottom Control Dock */
.control-dock {
  padding: 14px 20px 20px;
  background: linear-gradient(to top, var(--bg-space) 80%, transparent);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.input-shell {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 30px;
  padding: 6px 10px;
  backdrop-filter: blur(16px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-shell:focus-within {
  border-color: var(--border-active);
  box-shadow: 0 0 16px var(--accent-glow);
}

.input-shell input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 0.95rem;
  padding: 8px 12px;
}

.input-shell input::placeholder {
  color: var(--text-dim);
}

.btn-voice {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-voice:hover, .btn-voice.active {
  background: var(--accent-color);
  color: #05070c;
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-send:hover {
  background: var(--accent-color);
  color: #05070c;
}

.identity-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
  font-size: 0.78rem;
}

.badge-identity {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 12px;
  transition: color 0.2s ease;
}

.badge-identity:hover {
  color: var(--text-main);
}

.badge-identity .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
}

.btn-sound-toggle {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.78rem;
  transition: color 0.2s ease;
}

.btn-sound-toggle:hover {
  color: var(--text-main);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-box {
  background: #0f1523;
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-box h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 18px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.input-field label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.input-field input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
}

.input-field input:focus {
  border-color: var(--accent-color);
}

.modal-preview {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.preview-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-item strong {
  color: var(--accent-color);
}

.color-chip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 8px var(--accent-glow);
}

.preview-item code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.btn-save {
  background: var(--accent-color);
  color: #05070c;
  border: none;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.btn-save:hover {
  opacity: 0.9;
}
