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

:root {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text: #eee;
  --text-muted: #888;
  --user-bubble: #0f3460;
  --ai-bubble: #252545;
  --danger: #e94560;
  --success: #2ecc71;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.token-display {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.token-display.warning {
  color: var(--danger);
  font-weight: 600;
}

/* Action Buttons */
.actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}

.actions button {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.actions button:active {
  transform: scale(0.96);
}

.actions button:hover {
  background: rgba(255,255,255,0.05);
}

.actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.actions button.primary:hover {
  background: var(--accent-hover);
}

/* Chat Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-break: 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(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 4px;
}

.message pre {
  background: rgba(0,0,0,0.3);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
  margin: 6px 0;
}

/* Loading indicator */
.loading {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}

.loading span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Mic Button Area */
.mic-area {
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mic-btn:active {
  transform: scale(0.92);
}

.mic-btn.recording {
  animation: pulse 1.5s infinite;
  background: var(--danger);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(233,69,96,0.6); }
  70% { box-shadow: 0 0 0 20px rgba(233,69,96,0); }
  100% { box-shadow: 0 0 0 0 rgba(233,69,96,0); }
}

.mic-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  animation: none;
}

/* Settings Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

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

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.modal input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

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

.modal-buttons {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.modal-buttons button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.modal-buttons .btn-cancel {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.modal-buttons .btn-save {
  background: var(--accent);
  color: #fff;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar {
  width: 4px;
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}
