:root {
  --bg: #0a0e17;
  --bg-soft: #0f1420;
  --panel: #121a2a;
  --panel-2: #162033;
  --border: #22304a;
  --text: #e6ecf7;
  --text-dim: #93a2bd;
  --text-faint: #5f6f8c;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --grad: linear-gradient(120deg, #818cf8 0%, #22d3ee 100%);
  --cita: #22d3ee;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #16203a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
  background: rgba(10, 14, 23, 0.75);
  border-bottom: 1px solid rgba(34, 48, 74, 0.5);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.3px;
}
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--grad);
  color: #06101f;
  font-size: 16px;
  box-shadow: 0 4px 18px -4px rgba(99, 102, 241, 0.7);
}
.brand-sub { color: var(--text-faint); font-weight: 500; font-size: 12px; letter-spacing: 1px; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Main / Hero ---------- */
main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 0 20px; }
.hero {
  position: relative;
  text-align: center;
  padding: 12vh 0 6vh;
}
.hero-glow {
  position: absolute;
  top: -60px; left: 50%; transform: translateX(-50%);
  width: 520px; height: 320px;
  background: radial-gradient(closest-side, rgba(99, 102, 241, 0.28), transparent 70%);
  filter: blur(20px);
  pointer-events: none;
  z-index: -1;
}
.hero-title { font-size: clamp(28px, 5vw, 44px); line-height: 1.2; margin: 0 0 14px; font-weight: 800; letter-spacing: -0.5px; }
.hero-title .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { color: var(--text-dim); font-size: 15px; margin: 0 0 34px; }

/* ---------- Search bar ---------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.searchbar:focus-within { border-color: rgba(99, 102, 241, 0.7); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12), var(--shadow); }
.searchbar.big { max-width: 640px; margin: 0 auto; }
.searchbar.compact { margin-bottom: 18px; }
.search-ico { color: var(--text-faint); font-size: 20px; }
.searchbar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  padding: 12px 4px;
}
.searchbar.big input { font-size: 17px; }
.search-btn {
  background: var(--grad);
  color: #06101f;
  border: none;
  border-radius: 11px;
  padding: 11px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}
.search-btn:hover { opacity: 0.92; }
.search-btn:active { transform: scale(0.97); }
.search-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 26px; }
.chips button {
  background: rgba(34, 48, 74, 0.4);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.chips button:hover { border-color: var(--accent); color: var(--text); background: rgba(99, 102, 241, 0.12); }

/* ---------- Results ---------- */
.results-wrap { padding: 22px 0 60px; animation: fade 0.3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.status-line { color: var(--text-faint); font-size: 13px; min-height: 18px; margin: 0 2px 12px; }
.status-line .spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent-2); border-radius: 50%; animation: spin 0.7s linear infinite; margin-right: 8px; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Answer card ---------- */
.answer-card {
  background: linear-gradient(180deg, rgba(34, 48, 74, 0.35), rgba(18, 26, 42, 0.85));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 26px;
  box-shadow: var(--shadow);
}
.answer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ai-badge {
  background: var(--grad);
  color: #06101f;
  font-weight: 800;
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 999px;
  letter-spacing: 0.4px;
}
.answer-model { color: var(--text-faint); font-size: 12px; }
.answer-body { font-size: 15px; line-height: 1.75; color: #dde5f3; word-break: break-word; }
.answer-body:empty::before { content: "…"; color: var(--text-faint); }
.answer-foot { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); color: var(--text-faint); font-size: 12.5px; }
.notice { color: var(--text-dim); font-size: 14px; background: rgba(99,102,241,0.08); border: 1px solid rgba(99,102,241,0.25); border-radius: 10px; padding: 12px 14px; }
.notice.warn { background: rgba(248,113,113,0.08); border-color: rgba(248,113,113,0.3); color: #fca5a5; }
.notice a { color: var(--accent-2); }

/* markdown */
.markdown p { margin: 0 0 12px; }
.markdown h1, .markdown h2, .markdown h3 { margin: 18px 0 8px; font-size: 16px; color: #fff; }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown code { background: rgba(99,102,241,0.14); padding: 1px 6px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; color: #c7d2fe; }
.markdown pre { background: #0b1220; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; color: #d7e0f0; }
.markdown a { color: var(--accent-2); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.markdown strong { color: #fff; }
.cite {
  display: inline-block;
  min-width: 16px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #06101f;
  background: var(--accent-2);
  border-radius: 5px;
  padding: 0 4px;
  margin: 0 1px;
  text-decoration: none;
  vertical-align: 1px;
  line-height: 16px;
}
.cite:hover { background: #67e8f9; }
.cursor { display: inline-block; width: 8px; height: 17px; background: var(--accent-2); border-radius: 2px; animation: blink 1s steps(2) infinite; vertical-align: -2px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Sources ---------- */
.sources-head { display: flex; align-items: center; gap: 10px; margin: 4px 2px 14px; color: var(--text-dim); font-size: 14px; font-weight: 600; }
.engine-tag { font-size: 11px; font-weight: 600; color: var(--text-faint); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.sources { display: flex; flex-direction: column; gap: 12px; }
.source-card {
  display: flex;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 14px 16px;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
  scroll-margin-top: 90px;
}
.source-card:hover { border-color: rgba(99,102,241,0.6); background: var(--panel-2); }
.source-card:target, .source-card.flash { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(34,211,238,0.15); }
.source-idx {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: rgba(99,102,241,0.16);
  color: #a5b4fc;
  font-size: 13px;
  font-weight: 700;
  display: grid; place-items: center;
}
.source-main { min-width: 0; flex: 1; }
.source-title { font-size: 15.5px; font-weight: 600; color: var(--text); text-decoration: none; display: block; margin-bottom: 4px; }
.source-title:hover { color: var(--accent-2); }
.source-url { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #7fd1e0; margin-bottom: 6px; }
.source-url img { width: 15px; height: 15px; border-radius: 3px; background: #fff; }
.source-url .u { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-snippet { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 22px 16px 26px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.footer .dot { opacity: 0.5; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(4, 7, 14, 0.7);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 60;
  padding: 20px;
  animation: fade 0.15s;
}
.modal {
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.8);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-soft); }
.modal-head h3 { margin: 0; font-size: 17px; }
.icon-btn { background: transparent; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.modal-body { padding: 18px 22px 22px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 7px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.hint code { background: rgba(99,102,241,0.14); padding: 1px 5px; border-radius: 4px; }
.hint.ok { color: #4ade80; }
.save-row { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 8px; }
.save-msg { font-size: 13px; }
.save-msg.ok { color: #4ade80; }
.save-msg.err { color: var(--danger); }
.primary-btn {
  background: var(--grad);
  color: #06101f;
  border: none;
  border-radius: 11px;
  padding: 11px 26px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:disabled { opacity: 0.5; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .brand-sub { display: none; }
  main { padding: 0 14px; }
  .hero { padding: 8vh 0 4vh; }
  .searchbar.compact { position: sticky; top: 60px; z-index: 5; }
}
