:root[data-theme="dark"] {
  --bg: #131314; --surface: #1e1f20; --surface2: #282a2c;
  --border: #3c4043; --hover: #2d2f31;
  --text: #e3e3e3; --text2: #c4c7c5; --muted: #9aa0a6;
  --user-bubble: #333537; --code-bg: #282a2c; --shadow: rgba(0,0,0,.4);
}
:root[data-theme="light"] {
  --bg: #ffffff; --surface: #f0f4f9; --surface2: #e9eef6;
  --border: #dadce0; --hover: #e2e8f1;
  --text: #1f1f1f; --text2: #444746; --muted: #5f6368;
  --user-bubble: #f0f4f9; --code-bg: #f1f3f4; --shadow: rgba(60,64,67,.15);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Google Sans", -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
#app { display: flex; height: 100dvh; }

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 264px; flex-shrink: 0; background: var(--surface);
  display: flex; flex-direction: column; padding: 12px;
  transition: margin-left .25s ease;
}
#sidebar.hidden { margin-left: -264px; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 20px; padding: 8px 8px 16px; color: var(--text2); }
.new-chat-btn {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2); color: var(--text);
  border: none; border-radius: 999px; padding: 11px 16px;
  font-size: 14px; cursor: pointer; width: 100%;
}
.new-chat-btn:hover { background: var(--hover); box-shadow: 0 1px 3px var(--shadow); }
.side-mid { flex: 1; overflow-y: auto; margin-top: 18px; }
.side-label { font-size: 12px; color: var(--muted); padding: 8px 12px; }
.hist-item {
  padding: 10px 12px; border-radius: 999px; font-size: 13.5px;
  color: var(--text2); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin: 1px 0;
}
.hist-item:hover, .hist-item.active { background: var(--hover); }
.hist-item .del {
  float: right; color: var(--muted); display: none; font-size: 12px; padding-left: 6px;
}
.hist-item:hover .del { display: inline; }
.side-bottom { padding: 10px 12px; font-size: 11.5px; color: var(--muted); }

/* ---------- 主区 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; flex-shrink: 0;
}
.icon-btn { background: none; border: none; color: var(--text2); cursor: pointer; padding: 8px; border-radius: 50%; }
.icon-btn:hover { background: var(--hover); }
.top-right { display: flex; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: 999px; padding: 7px 14px;
  font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--hover); }
.chip.active { background: var(--surface2); border-color: var(--text2); color: var(--text); }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: 110%; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 4px 16px var(--shadow);
  display: none; z-index: 30; overflow: hidden;
}
.dropdown.open .dropdown-menu { display: block; }
.dd-item { padding: 11px 16px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.dd-item:hover { background: var(--hover); }
.dd-item .sub { font-size: 11.5px; color: var(--muted); }
.dd-item.disabled { color: var(--muted); cursor: default; }

/* ---------- 视图 ---------- */
#view { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#welcome { text-align: center; padding-top: 14vh; }
#welcome h1 { font-size: 52px; font-weight: 600; color: var(--text2); letter-spacing: -1px; }
#welcome h2 { font-size: 52px; font-weight: 600; letter-spacing: -1px; }
.grad-text {
  background: linear-gradient(74deg, #4285f4 0%, #9b72cb 25%, #d96570 50%, #f2a60c 75%, #4285f4 100%);
  background-size: 300% 100%; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; animation: grad 8s linear infinite;
}
@keyframes grad { to { background-position: 300% 0; } }

#chat { max-width: 780px; margin: 0 auto; padding: 28px 20px 20px; }
.turn { margin-bottom: 28px; }
.turn.user { display: flex; justify-content: flex-end; }
.turn.user .bubble {
  background: var(--user-bubble); color: var(--text);
  border-radius: 22px; padding: 12px 18px; max-width: 85%;
  white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.6;
}
.turn.gemini { display: flex; gap: 14px; }
.turn.gemini .avatar { flex-shrink: 0; width: 28px; height: 28px; margin-top: 2px; }
.turn.gemini .content { min-width: 0; flex: 1; font-size: 15.5px; line-height: 1.75; color: var(--text); }
.thoughts {
  border-left: 3px solid var(--border); margin: 0 0 12px 0; padding: 4px 0 4px 14px;
  color: var(--muted); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap;
}
.caret { display: inline-block; width: 8px; height: 17px; background: var(--text2);
  vertical-align: text-bottom; animation: blink 1s steps(2) infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.thinking-note { color: var(--muted); font-size: 13px; }

/* markdown */
.content p { margin: 0 0 12px; }
.content p:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3 { margin: 18px 0 10px; line-height: 1.4; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 24px; }
.content li { margin: 4px 0; }
.content a { color: #8ab4f8; }
.content code {
  background: var(--code-bg); border-radius: 5px; padding: 2px 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px;
}
.content pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; overflow-x: auto; margin: 0 0 12px;
}
.content pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.content table { border-collapse: collapse; margin: 0 0 12px; width: 100%; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 12px; font-size: 13.5px; text-align: left; }
.content blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--text2); margin: 0 0 12px; }
.content img.gen { max-width: 70%; border-radius: 14px; margin: 6px 8px 6px 0; display: inline-block; }

/* ---------- 输入区 ---------- */
#input-area { flex-shrink: 0; padding: 8px 20px 14px; }
#input-pill {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 28px; padding: 10px 10px 10px 20px;
  transition: box-shadow .2s;
}
#input-pill:focus-within { box-shadow: 0 2px 10px var(--shadow); border-color: var(--text2); }
#prompt {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-size: 15.5px; line-height: 1.55;
  font-family: inherit; max-height: 200px; padding: 4px 0;
}
#prompt::placeholder { color: var(--muted); }
.send-btn {
  background: var(--surface2); border: none; color: var(--text2);
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  margin-left: 10px; transition: background .2s, color .2s;
}
.send-btn.ready { background: #1a73e8; color: #fff; }
.send-btn:disabled { opacity: .55; cursor: default; }
#disclaim { text-align: center; font-size: 11.5px; color: var(--muted); padding: 10px 0 2px; }

/* ---------- 访问门 ---------- */
#gate:not([hidden]) {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.gate-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 40px 44px; border-radius: 24px;
}
.gate-title { font-size: 26px; font-weight: 600; color: var(--text); }
.gate-sub { font-size: 13px; color: var(--muted); margin-top: -6px; }
#gate-code {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); padding: 11px 16px; font-size: 15px; width: 260px;
  text-align: center; outline: none;
}
#gate-code:focus { border-color: #1a73e8; }
#gate-btn {
  background: #1a73e8; color: #fff; border: none; border-radius: 999px;
  padding: 10px 34px; font-size: 14.5px; cursor: pointer;
}
#gate-err { color: #f2b8b5; font-size: 12.5px; min-height: 16px; }

/* ---------- 提示条 ---------- */
#banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  background: #3c1e1e; color: #f2b8b5; border: 1px solid #8c3b39;
  padding: 10px 20px; border-radius: 12px; font-size: 13.5px;
  z-index: 99; max-width: 90vw; box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
:root[data-theme="light"] #banner { background: #fdeded; color: #b3261e; border-color: #f2b8b5; }

/* ---------- 移动端 ---------- */
@media (max-width: 768px) {
  #sidebar { position: fixed; z-index: 50; height: 100dvh; box-shadow: 0 0 40px var(--shadow); }
  #sidebar.hidden { margin-left: -280px; }
  #welcome h1, #welcome h2 { font-size: 34px; }
  #chat { padding: 16px 14px; }
  .content img.gen { max-width: 100%; }
}
