:root {
  --bg-primary: #0d0d14;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252542;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --accent: #ff6b35;
  --accent-glow: rgba(255, 107, 53, 0.3);
  --user-bubble: #2d2d4a;
  --assistant-bubble: #1e1e36;
  --error: #ff4757;
  --success: #2ed573;
  --border-radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-content {
  text-align: center;
  padding: 2rem;
}

.logo {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: flicker 2s infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 1; filter: brightness(1); }
  50% { opacity: 0.8; filter: brightness(1.2); }
}

.overlay h1 {
  font-size: 2rem;
  font-weight: 300;
  letter-spacing: 0.2em;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, var(--accent), #ffa07a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#connect-status {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.error {
  color: var(--error);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--accent);
}

.btn.primary {
  background: var(--accent);
}

.btn.primary:hover {
  background: #ff8555;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-small {
  font-size: 1.5rem;
}

.title {
  font-size: 1.1rem;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
}

.dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* Chat container */
#chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Messages */
main#messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}

.message.assistant.streaming {
  border-left: 2px solid var(--accent);
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 0.5rem;
}

.message pre {
  background: var(--bg-primary);
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

.message code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
}

.message p {
  margin: 0.5rem 0;
}

.message p:first-child {
  margin-top: 0;
}

.message p:last-child {
  margin-bottom: 0;
}

/* Footer / Input */
footer {
  background: var(--bg-secondary);
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + var(--safe-bottom));
  border-top: 1px solid var(--bg-tertiary);
}

#input-container {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

#message-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 20px;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 1rem;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

#message-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#message-input::placeholder {
  color: var(--text-secondary);
}

/* Voice button states */
#voice-btn {
  position: relative;
}

#voice-btn .mic-icon,
#voice-btn .ear-icon {
  transition: opacity 0.2s, transform 0.2s;
}

#voice-btn .ear-icon {
  position: absolute;
  opacity: 0;
  transform: scale(0.8);
}

#voice-btn.listening .mic-icon {
  opacity: 0;
  transform: scale(0.8);
}

#voice-btn.listening .ear-icon {
  position: static;
  opacity: 1;
  transform: scale(1);
}

#voice-btn.listening {
  color: var(--accent);
  animation: ear-pulse 1.2s ease-in-out infinite;
  background: var(--accent-glow);
}

@keyframes ear-pulse {
  0%, 100% { 
    transform: scale(1); 
    box-shadow: 0 0 0 0 var(--accent-glow);
  }
  50% { 
    transform: scale(1.15); 
    box-shadow: 0 0 20px 4px var(--accent-glow);
  }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 400px;
}

.modal h2 {
  margin-bottom: 1rem;
  font-weight: 500;
}

.setting {
  margin-bottom: 1rem;
}

.setting label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.setting input[type="text"],
.setting input[type="password"],
.setting select {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1rem;
}

.setting input[type="checkbox"] {
  margin-right: 0.5rem;
}

.modal .buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.modal .buttons .btn {
  flex: 1;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

/* Mobile optimizations */
@media (max-width: 480px) {
  .message {
    max-width: 90%;
  }
  
  #message-input {
    font-size: 16px; /* Prevents iOS zoom */
  }
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}
