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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --user-bubble: #0f3460;
  --assistant-bubble: #252545;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #4a9eff;
  --border: #2a2a4a;
  --input-bg: #1e1e3a;
  --code-bg: #1a1a30;
  --voice-recording: #e53935;
  --voice-playing: #43a047;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  font-family: monospace;
}

#status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}

#status.connected {
  color: #4caf50;
  background: rgba(76, 175, 80, 0.15);
}

#status.disconnected {
  color: #f44336;
  background: rgba(244, 67, 54, 0.15);
}

#status.connecting {
  color: #ff9800;
  background: rgba(255, 152, 0, 0.15);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 15px;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

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

.msg.system {
  align-self: center;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
  background: none;
  padding: 4px 0;
}

/* Streaming cursor */
.msg.streaming::after {
  content: "\25AE";
  animation: blink 0.8s infinite;
  margin-left: 2px;
  opacity: 0.7;
}

@keyframes blink {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0; }
}

/* Typing indicator */
.typing-indicator {
  padding: 12px 18px;
}

.typing-indicator .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}

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

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

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

/* Voice message override: no streaming cursor on voice/loading placeholders */
.msg.voice-msg.streaming::after,
.msg.streaming:has(.vp-loading)::after {
  display: none;
}

/* Voice player */
.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vp-play-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.vp-play-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.vp-waveform {
  flex: 1;
  height: 32px;
  cursor: pointer;
  display: block;
  overflow: hidden;
}

.vp-duration {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 30px;
  text-align: right;
}

.vp-transcript-toggle {
  display: block;
  margin-top: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}

.vp-transcript-toggle:hover,
.vp-transcript-toggle.active {
  color: var(--accent);
}

.vp-transcript {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.vp-transcript-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}

/* Voice loading dots (reuses typing animation) */
.vp-loading {
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.vp-loading .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}

.vp-loading .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.vp-loading .dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Voice message bubbles — slightly wider for player */
.msg.voice-msg {
  min-width: 240px;
}

/* Markdown elements inside assistant messages */
.msg.assistant code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 13px;
}

.msg.assistant pre {
  background: var(--code-bg);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.msg.assistant pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

.msg.assistant strong {
  font-weight: 600;
  color: #f0f0f0;
}

.msg.assistant em {
  font-style: italic;
  color: #c8c8e8;
}

.msg.assistant ul {
  margin: 4px 0;
  padding-left: 18px;
}

.msg.assistant li {
  margin: 2px 0;
}

footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

#input-form {
  display: flex;
  gap: 8px;
}

/* Voice button */
.voice-btn {
  width: 42px;
  height: 42px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--input-bg);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.voice-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.voice-btn.recording {
  border-color: var(--voice-recording);
  color: var(--voice-recording);
  background: rgba(229, 57, 53, 0.15);
  animation: pulse-recording 1s infinite;
}

.voice-btn.playing {
  border-color: var(--voice-playing);
  color: var(--voice-playing);
  background: rgba(67, 160, 71, 0.1);
}

@keyframes pulse-recording {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(229, 57, 53, 0); }
}

#input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

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

#input-form button[type="submit"] {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

#input-form button[type="submit"]:hover {
  opacity: 0.85;
}

#input-form button[type="submit"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

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

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

/* History loading indicator */
.history-loader {
  text-align: center;
  padding: 10px;
  color: var(--text-dim);
  font-size: 13px;
}

/* Mobile */
@media (max-width: 600px) {
  #app {
    max-width: 100%;
  }

  .msg {
    max-width: 90%;
  }

  .voice-btn {
    width: 48px;
    height: 48px;
  }
}
