:root {
  --bg: #212121;
  --bg-surface: #171717;
  --bg-hover: #2a2a2a;
  --bg-input: #2a2a2a;
  --border: #333;
  --border-focus: #6366f1;
  --text: #e5e5e5;
  --text-muted: #888;
  --text-dim: #555;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-bg: rgba(99,102,241,0.12);
  --user-msg: #2a2a2a;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Splash */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.4s;
}
.splash.hidden { opacity: 0; pointer-events: none; }
.splash-content { text-align: center; }
.splash-logo { margin-bottom: 20px; }
.splash-title {
  font-size: 28px; font-weight: 600;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin-bottom: 20px;
}
.status-bar {
  width: 220px; height: 3px; background: var(--bg-input);
  border-radius: 4px; overflow: hidden; margin: 0 auto 8px;
}
.status-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  transition: width 0.3s;
}
.status-text { font-size: 12px; color: var(--text-muted); }

/* App layout */
.app {
  display: flex; flex-direction: column;
  height: 100vh; max-width: 860px; margin: 0 auto;
}
.app.hidden { display: none; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-icon { flex-shrink: 0; }
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-badge {
  font-size: 11px; color: var(--text-muted);
  display: none;
}
@media (min-width: 640px) {
  .topbar-badge { display: inline; }
}
.topbar-right { display: flex; gap: 4px; }
.topbar-btn {
  background: none; border: none; color: var(--text-muted);
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Settings panel */
.settings-panel {
  position: absolute; top: 52px; right: max(calc((100% - 860px)/2 + 12px), 12px);
  width: 260px; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.settings-panel.hidden { display: none; }
.settings-section { margin-bottom: 14px; }
.settings-label {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 6px;
}
.settings-label span { float: right; color: var(--text); font-weight: 500; }
.settings-section select {
  width: 100%; padding: 8px 10px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; font-family: inherit; outline: none;
}
.settings-section select:focus { border-color: var(--accent); }
.settings-section input[type="range"] {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--border); border-radius: 2px; outline: none;
}
.settings-section input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
.checkbox-row {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  color: var(--text); font-size: 13px;
}
.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent);
}
.settings-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.settings-btn {
  width: 100%; padding: 8px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 12px; font-family: inherit; cursor: pointer;
  transition: all 0.15s;
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Chat messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.welcome-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  flex: 1; color: var(--text-dim);
}
.welcome-placeholder p { font-size: 18px; color: var(--text-muted); margin-bottom: 4px; }
.welcome-placeholder span { font-size: 13px; }

/* Messages */
.message {
  display: flex; gap: 10px;
  animation: msgIn 0.2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 13px; font-weight: 600;
  margin-top: 4px;
}
.message.ai .message-avatar { background: var(--accent-bg); color: var(--accent); }
.message.user .message-avatar { background: var(--accent-bg); color: var(--accent); }

.message-bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.65;
  white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: break-word;
}
.message.ai .message-bubble {
  background: transparent;
  color: var(--text);
}
.message.user .message-bubble {
  background: var(--user-msg);
  border: 1px solid var(--border);
}

/* Thinking toggle */
.thinking-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; margin-top: 6px;
  border: none; border-radius: 20px;
  background: var(--bg-hover);
  cursor: pointer; font-size: 11px; color: var(--text-muted);
  font-family: inherit; transition: all 0.15s;
}
.thinking-toggle:hover { background: var(--border); color: var(--text); }

.thinking-panel {
  margin-top: 8px;
  border-left: 2px solid var(--accent);
  padding-left: 12px;
}
.thinking-panel.hidden { display: none; }

.thinking-step {
  font-size: 12px; color: var(--text-muted);
  line-height: 1.5; margin-bottom: 6px;
  cursor: pointer;
}

.thinking-step-header {
  display: flex; align-items: flex-start; gap: 6px;
}

.step-phase {
  font-size: 9px; font-weight: 600; text-transform: uppercase;
  padding: 1px 5px; border-radius: 4px;
  flex-shrink: 0; margin-top: 2px;
}

.step-content { color: var(--text-muted); }

.thinking-step-detail {
  margin-top: 4px; padding: 6px 8px;
  background: var(--bg-surface); border-radius: var(--radius-sm);
  font-size: 11px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text-dim);
}
.thinking-step-detail.hidden { display: none; }

/* Input area */
.input-area {
  padding: 12px 20px 20px;
  flex-shrink: 0;
}

.typing {
  display: flex; align-items: center; gap: 4px;
  padding: 0 4px 8px;
}
.typing.hidden { display: none; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim);
  animation: typingB 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingB {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

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

.chat-input {
  flex: 1; padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit; font-size: 14px; line-height: 1.5;
  resize: none; outline: none;
  max-height: 150px; min-height: 48px;
  transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-dim); }
.chat-input:disabled { opacity: 0.4; }

.send-btn {
  width: 48px; height: 48px; border-radius: var(--radius);
  border: none; background: var(--accent);
  color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.3; cursor: default; }

/* Code blocks in messages */
.message-bubble code {
  background: var(--bg-hover);
  padding: 1px 5px; border-radius: 4px;
  font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
}

.message-bubble pre {
  background: var(--bg-surface);
  padding: 12px; border-radius: var(--radius-sm);
  overflow-x: auto; margin: 8px 0;
  font-size: 13px; line-height: 1.5;
}

/* Mobile */
@media (max-width: 600px) {
  .chat-messages { padding: 12px; }
  .input-area { padding: 8px 12px 16px; }
  .message-bubble { font-size: 14px; }
  .settings-panel { right: 8px; width: calc(100% - 16px); }
}
