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

:root {
  --bg: #faf9f7;
  --card: #ffffff;
  --border: #f0eeeb;
  --text: #2c2c2c;
  --text-light: #999;
  --accent: #c4956a;
  --accent-light: #f5ede4;
  --bubble-user: #f0ebe3;
  --bubble-ai: #ffffff;
  --thinking-bg: #f8f6f3;
  --tool-bg: #f5f3ef;
  --radius: 18px;
  --radius-sm: 12px;
}

html, body {
  height: 100%; width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

.header-center { display: flex; align-items: center; gap: 8px; }
.header-title { font-size: 16px; font-weight: 600; }
.model-badge {
  font-size: 11px; padding: 2px 8px;
  background: var(--accent-light); color: var(--accent);
  border-radius: 10px; font-weight: 500;
}
.back-btn { text-decoration: none; color: var(--text); font-size: 20px; }
.icon-btn {
  background: none; border: none; font-size: 18px;
  color: var(--text-light); cursor: pointer; padding: 4px 8px;
}

#tokenBar {
  height: 3px; background: var(--border); position: relative;
}
#tokenFill {
  height: 100%; width: 0%; background: var(--accent);
  transition: width 0.3s ease;
}
#tokenText {
  display: none; position: absolute; right: 8px; top: 4px;
  font-size: 10px; color: var(--text-light);
}

#messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.msg {
  max-width: 85%; display: flex; flex-direction: column; gap: 4px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }

.msg-bubble {
  padding: 10px 14px; border-radius: var(--radius);
  line-height: 1.6; word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .msg-bubble {
  background: var(--bubble-user); border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  background: var(--bubble-ai); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 11px; color: var(--text-light); padding: 0 4px;
}
.msg.user .msg-time { text-align: right; }

.thinking-block {
  background: var(--thinking-bg); border-radius: var(--radius-sm);
  margin-bottom: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.thinking-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  color: var(--text-light); user-select: none;
}
.thinking-header .arrow { transition: transform 0.2s; font-size: 10px; }
.thinking-header.open .arrow { transform: rotate(90deg); }
.thinking-verb { font-style: italic; }
.thinking-content {
  display: none; padding: 8px 12px; font-size: 13px;
  color: var(--text-light); line-height: 1.5;
  border-top: 1px solid var(--border);
  max-height: 300px; overflow-y: auto;
  white-space: pre-wrap;
}
.thinking-content.open { display: block; }

.tool-block {
  background: var(--tool-bg); border-radius: var(--radius-sm);
  margin-bottom: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.tool-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  color: var(--text-light); user-select: none;
}
.tool-header .arrow { transition: transform 0.2s; font-size: 10px; }
.tool-header.open .arrow { transform: rotate(90deg); }
.tool-icon { font-size: 14px; }
.tool-content {
  display: none; padding: 8px 12px; font-size: 12px;
  color: var(--text-light); line-height: 1.4;
  border-top: 1px solid var(--border);
  max-height: 200px; overflow-y: auto;
  white-space: pre-wrap; font-family: monospace;
}
.tool-content.open { display: block; }

.session-divider {
  text-align: center; padding: 16px 0; font-size: 12px;
  color: var(--text-light);
}

#input-area {
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
}
.input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg); border-radius: 22px;
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--border);
}
#userInput {
  flex: 1; border: none; outline: none; background: none;
  font-size: 15px; font-family: inherit; color: var(--text);
  resize: none; max-height: 120px; line-height: 1.5;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: white; border: none;
  font-size: 14px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }

.typing-indicator {
  display: flex; gap: 4px; padding: 8px 0;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-light);
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}