:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --text: #e6e9ef;
  --muted: #8a919f;
  --accent: #5b8cff;
  --accent-2: #3d6ae0;
  --danger: #e06060;
  --border: #262b36;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.tiny { font-size: 12px; margin: 6px 0 10px; }
.small { font-size: 13px; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.brand { font-weight: 700; letter-spacing: 0.5px; }
.brand .dot { color: var(--accent); margin: 0 2px; }
.head-right { display: flex; align-items: center; gap: 10px; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 14px;
  cursor: pointer;
}
button:hover { background: var(--accent-2); }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}
button.ghost:hover { color: var(--text); border-color: var(--muted); background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#key-panel {
  margin: 14px 18px 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#key-panel label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#key-panel .row { display: flex; gap: 8px; }
#key-panel input {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: ui-monospace, monospace;
}
#key-msg { margin: 8px 0 0; font-size: 13px; }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}

.msg { margin-bottom: 18px; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.bubble {
  white-space: normal;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-width: 100%;
}
.msg.assistant .bubble {
  background: transparent;
}
.bubble p { margin: 0.5em 0; }
.bubble pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
}
.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
.bubble :not(pre) > code {
  background: var(--panel);
  padding: 1px 5px;
  border-radius: 5px;
}
.bubble ul, .bubble ol { padding-left: 1.4em; }
.bubble table { border-collapse: collapse; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; }

details.thinking {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}
details.thinking summary { cursor: pointer; user-select: none; }
details.thinking pre {
  white-space: pre-wrap;
  color: #9aa3b2;
  max-height: 300px;
  overflow-y: auto;
}
.usage-line { font-size: 12px; color: var(--muted); margin-top: 6px; }

#empty { padding-top: 15vh; }

footer {
  border-top: 1px solid var(--border);
  padding: 12px 18px 10px;
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
#composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#composer textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 180px;
}
#composer textarea:focus { outline: 1px solid var(--accent); }

.ctx-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 2px 0;
}
#ctx-mode {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
#ctx-est.warn { color: var(--danger); font-weight: 600; }

/* about page */
.about { padding: 24px 18px 60px; max-width: 760px; margin: 0 auto; }
.about h1 { font-size: 22px; }
.about h2 { font-size: 17px; margin-top: 28px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.about pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
}
.about code { font-family: ui-monospace, monospace; font-size: 13px; }
.about :not(pre) > code { background: var(--panel); padding: 1px 5px; border-radius: 5px; }
