:root {
  --radius-sm: 6px;
  --radius-md: 10px;
  --font: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Dark theme (default) */
html[data-theme="dark"] {
  --bg-0: #121216; --bg-1: #1a1a20; --bg-2: #24242c; --bg-3: #2e2e38; --line: #34343f;
  --text-hi: #f1f0f8; --text-mid: #b7b4cc; --text-low: #82809a;
  --accent: #8b7bf0; --accent-dim: #5d4fc4; --link: #a9c4ff; --url-color: #7fd9a8;
  --mark-bg: rgba(139, 123, 240, 0.28); --mark-text: #e4defc;
}

/* Light theme */
html[data-theme="light"] {
  --bg-0: #f7f7fa; --bg-1: #ffffff; --bg-2: #eeeef3; --bg-3: #e2e2ea; --line: #dcdce4;
  --text-hi: #17161f; --text-mid: #46435a; --text-low: #7a7791;
  --accent: #6d5be0; --accent-dim: #5343b8; --link: #2952b3; --url-color: #1c7a4d;
  --mark-bg: rgba(109, 91, 224, 0.16); --mark-text: #2b2350;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%; background: var(--bg-0); color: var(--text-hi);
  font-family: var(--font);
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.view[hidden] { display: none; }

.logo {
  font-weight: 700; letter-spacing: -0.02em; user-select: none;
  background: linear-gradient(135deg, #a9a0ff, #7fd9a8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Homepage ---------- */
.home-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 24px;
}
.home-wrap .logo { font-size: 42px; }
.home-wrap .tagline { color: var(--text-low); font-size: 13px; margin-top: -14px; text-align: center; }
.home-search-form { width: 100%; display: flex; justify-content: center; }
.home-search-wrap {
  width: 100%; max-width: 600px; display: flex; align-items: center; gap: 8px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 8px 4px 22px; transition: border-color 120ms ease, box-shadow 120ms ease;
}
.home-search-wrap:focus-within { border-color: var(--accent-dim); box-shadow: 0 0 0 4px rgba(139,123,240,0.16); }
.home-search-wrap input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-hi); font-size: 15px; height: 46px;
}
.home-search-wrap input::placeholder { color: var(--text-low); }
.ask-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--accent); flex-shrink: 0; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.ask-btn:hover { border-color: var(--accent-dim); }
.search-submit-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--accent); color: #100f1a; font-size: 15px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.search-submit-btn:hover { background: var(--accent-dim); color: #fff; }
.home-footnote { color: var(--text-low); font-size: 11.5px; text-align: center; max-width: 440px; }

/* ---------- Results view topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--bg-1);
}
.topbar .logo { font-size: 19px; flex-shrink: 0; }
.results-search-form { flex: 1; display: flex; max-width: 620px; }
.results-search-wrap {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 8px 0 16px; height: 40px;
}
.results-search-wrap:focus-within { border-color: var(--accent-dim); }
.results-search-wrap input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-hi); font-size: 14px; height: 100%;
}
.results-search-wrap button:not(.ask-btn) {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: var(--bg-3); color: var(--text-mid); flex-shrink: 0; font-size: 13px;
}
.results-search-wrap button:not(.ask-btn):hover { background: var(--accent); color: #100f1a; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text-mid); font-size: 15px; flex-shrink: 0;
  margin-left: auto;
}
.icon-btn:hover { color: var(--text-hi); border-color: var(--accent-dim); }

/* ---------- Category tabs ---------- */
.category-tabs {
  display: flex; gap: 4px; padding: 10px 28px; background: var(--bg-1);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
.tab-btn {
  border: none; background: transparent; color: var(--text-mid);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.tab-btn:hover { background: var(--bg-2); color: var(--text-hi); }
.tab-btn.active { background: var(--accent); color: #100f1a; font-weight: 600; }

/* ---------- Results layout ---------- */
.page-body { display: flex; gap: 32px; max-width: 900px; margin: 0 auto; padding: 0 28px; }
.results-col { flex: 1; min-width: 0; max-width: 700px; }
.knowledge-col { width: 280px; flex-shrink: 0; padding-top: 20px; }

.meta { padding: 14px 0 0; color: var(--text-low); font-size: 12.5px; }
.results { padding: 10px 0 40px; }

.fallback-banner {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; margin: 8px 0 16px; color: var(--text-mid); font-size: 12.5px;
}
.fallback-banner strong { color: var(--text-hi); }

.result { padding: 16px 0; border-bottom: 1px solid var(--bg-2); }
.result:last-child { border-bottom: none; }
.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.result-favicon-box {
  width: 18px; height: 18px; border-radius: 5px; flex-shrink: 0;
  background: var(--bg-2); overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.result-favicon-box img { width: 100%; height: 100%; object-fit: cover; }
.result-sitename { font-size: 12.5px; color: var(--text-hi); font-weight: 600; }
.result-domain { font-size: 12px; color: var(--url-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result a.title {
  display: block; font-size: 17px; font-weight: 700; color: var(--link);
  margin: 4px 0 6px; line-height: 1.35;
}
.result a.title:hover { text-decoration: underline; }
.result .snippet { color: var(--text-mid); font-size: 13.5px; line-height: 1.55; }
.result .snippet mark { background: var(--mark-bg); color: var(--mark-text); border-radius: 2px; padding: 0 1px; }

.empty { color: var(--text-low); padding: 50px 0; text-align: center; }
.empty-icon { font-size: 32px; margin-bottom: 10px; opacity: 0.6; }
.empty-sub { font-size: 12.5px; margin-top: 8px; max-width: 380px; margin-left: auto; margin-right: auto; }

.pager { display: flex; justify-content: center; gap: 10px; padding: 20px 0; }
.pager button {
  padding: 8px 18px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--text-mid); background: transparent; font-size: 13px;
}
.pager button:hover { border-color: var(--accent-dim); color: var(--text-hi); }
.pager button:disabled { opacity: 0.35; cursor: default; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(6,6,12,0.55);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 400px; max-height: 85vh; overflow-y: auto; background: var(--bg-1);
  border: 1px solid var(--line); border-radius: var(--radius-md); padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.settings-modal { width: 440px; }
.modal h2 { margin: 0 0 4px 0; font-size: 17px; }
.modal p.sub { margin: 0 0 16px 0; color: var(--text-low); font-size: 12px; }
.modal-footer-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.ghost-btn {
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: transparent; color: var(--text-mid); font-size: 12.5px;
}
.ghost-btn:hover { color: var(--text-hi); border-color: var(--accent-dim); }

.settings-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.settings-section:last-of-type { border-bottom: none; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0;
}
.settings-row-label { font-size: 13px; }
.settings-row-desc { font-size: 11px; color: var(--text-low); margin-top: 2px; }
.settings-modal select {
  background: var(--bg-2); color: var(--text-hi); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12.5px; outline: none;
}

.pill-toggle-group { display: flex; gap: 6px; margin-top: 8px; }
.pill-toggle-btn {
  flex: 1; border: 1px solid var(--line); background: var(--bg-2); color: var(--text-mid);
  padding: 7px 0; border-radius: 999px; font-size: 12.5px;
}
.pill-toggle-btn.active { background: var(--accent); color: #100f1a; border-color: var(--accent); font-weight: 600; }

.radio-group { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--text-mid); }
.radio-group label { display: flex; align-items: center; gap: 6px; }

.switch {
  width: 32px; height: 18px; border-radius: 999px; background: var(--bg-3);
  position: relative; border: none; flex-shrink: 0;
}
.switch.on { background: var(--accent); }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--text-hi); transition: transform 120ms ease;
}
html[data-theme="light"] .switch::after { background: #fff; }
.switch.on::after { transform: translateX(14px); }

@media (max-width: 720px) {
  .page-body { flex-direction: column; }
  .knowledge-col { display: none; }
}
