/* 松鼠對話｜溫暖木質調主題 */

:root {
  --bg: #faf6f0;
  --bg-deep: #f1e9dd;
  --card: #ffffff;
  --ink: #2d2418;
  --ink-soft: #7a6a55;
  --accent: #c2571b;        /* 松鼠橘棕 */
  --accent-deep: #9a4413;
  --accent-soft: #fbe8db;
  --line: #e7dccb;
  --user-bubble: #3e5c43;   /* 苔綠 */
  --user-ink: #f6f4ee;
  --danger: #b3372f;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(74, 52, 24, 0.08), 0 8px 24px rgba(74, 52, 24, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ===== 頂欄 ===== */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(250, 246, 240, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-emoji { font-size: 28px; }
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-sub {
  font-size: 11px;
  color: var(--ink-soft);
  font-family: ui-monospace, monospace;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.model-switch {
  display: flex;
  background: var(--bg-deep);
  border-radius: 999px;
  padding: 3px;
}
.model-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.model-btn.active {
  background: var(--card);
  color: var(--accent-deep);
  box-shadow: 0 1px 3px rgba(74, 52, 24, 0.15);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent-deep); }

/* ===== 訊息區 ===== */
#chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.messages {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg .avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  margin-top: 2px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--user-bubble); }
.msg.assistant .avatar { background: var(--accent-soft); }

.bubble {
  max-width: min(82%, 640px);
  padding: 10px 15px;
  border-radius: var(--radius);
  line-height: 1.75;
  font-size: 15px;
  overflow-wrap: break-word;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-ink);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

/* Markdown 內容樣式 */
.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0.5em 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 0.9em 0 0.4em;
  line-height: 1.4;
}
.bubble h1 { font-size: 1.25em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1.05em; }
.bubble ul, .bubble ol { margin: 0.5em 0; padding-left: 1.4em; }
.bubble li { margin: 0.25em 0; }
.bubble code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--bg-deep);
  padding: 0.15em 0.4em;
  border-radius: 5px;
}
.bubble pre {
  background: #2b2118;
  color: #f0e6d8;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0.6em 0;
}
.bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
}
.bubble blockquote {
  margin: 0.6em 0;
  padding: 0.3em 0.9em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}
.bubble table {
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.92em;
  display: block;
  overflow-x: auto;
}
.bubble th, .bubble td {
  border: 1px solid var(--line);
  padding: 5px 10px;
}
.bubble th { background: var(--bg-deep); }
.bubble a { color: var(--accent-deep); }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }

/* 思考過程（深度模式） */
.thinking {
  margin-bottom: 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 13px;
}
.thinking summary {
  cursor: pointer;
  padding: 7px 12px;
  color: var(--ink-soft);
  font-weight: 600;
  user-select: none;
}
.thinking .thinking-body {
  padding: 0 12px 10px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}

/* 打字中光標 */
.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
  vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== 空狀態 ===== */
.empty-state {
  max-width: 620px;
  margin: 8vh auto 0;
  text-align: center;
  padding: 0 20px;
}
.empty-squirrel { font-size: 56px; }
.empty-state h2 { margin: 10px 0 6px; font-size: 22px; }
.empty-state p { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-soft);
}

/* ===== 輸入區 ===== */
.composer {
  flex: none;
  padding: 10px 18px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px 12px 8px;
}
.input-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 180px;
  background: transparent;
  color: var(--ink);
  padding: 6px 2px;
}
#input::placeholder { color: #b5a892; }

.send-btn, .stop-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.send-btn {
  background: var(--accent);
  color: #fff;
}
.send-btn:hover { background: var(--accent-deep); }
.send-btn:disabled { background: var(--line); cursor: default; }
.stop-btn {
  background: var(--danger);
  color: #fff;
  font-size: 13px;
}

.status-line {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 0 4px 6px;
}
.status-line.error { color: var(--danger); }

.composer-hint {
  margin: 6px 2px 0;
  font-size: 11px;
  color: #b5a892;
  text-align: right;
}

/* ===== 通行碼 ===== */
.gate {
  position: fixed;
  inset: 0;
  background: rgba(45, 36, 24, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.gate-card {
  background: var(--card);
  border-radius: 18px;
  padding: 32px 30px;
  width: min(92vw, 360px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.gate-icon { font-size: 40px; }
.gate-card h2 { margin: 8px 0 4px; font-size: 19px; }
.gate-card p { margin: 0 0 16px; color: var(--ink-soft); font-size: 14px; }
#gate-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
}
#gate-input:focus { border-color: var(--accent); }
#gate-submit {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
#gate-submit:hover { background: var(--accent-deep); }
.gate-error { color: var(--danger) !important; font-size: 13px !important; margin-top: 10px !important; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(110px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #3a2d1d;
  color: #fdf8f0;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 60;
  max-width: 86vw;
}

/* ===== 手機 ===== */
@media (max-width: 640px) {
  .brand-sub { display: none; }
  .model-btn { padding: 6px 10px; font-size: 12px; }
  .ghost-btn { padding: 7px 10px; font-size: 12px; }
  .bubble { max-width: 88%; }
  .messages { padding: 16px 12px 8px; }
}
