:root {
  --bg: #282828;
  --bg-panel: #32302f;
  --bg-elevated: #3c3836;
  --border: #45403d;
  --fg: #d4be98;
  --fg-muted: #a89984;
  --fg-faint: #928374;
  --accent: #7daea3;
  --link: #89b482;
  --visited: #d3869b;
  --highlight: #d8a657;
  --error: #ea6962;
  --success: #a9b665;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  height: 100%;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }
#main { flex: 1; display: flex; flex-direction: column; }

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

button { font-family: inherit; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid transparent;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}
.home .topbar { border-bottom-color: transparent; }
#app:not(.home) .topbar { border-bottom-color: var(--border); background: var(--bg-panel); }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: var(--fg);
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.home .brand { display: none; }

.search-form { flex: 1; max-width: 640px; }
.home .search-form { max-width: 100%; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0 14px;
  height: 44px;
  box-shadow: 0 2px 8px #1d2021aa;
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { color: var(--fg-faint); flex-shrink: 0; }
.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-size: 16px;
  padding: 0 10px;
}
.search-box input::placeholder { color: var(--fg-faint); }
.clear-btn {
  background: none;
  border: none;
  color: var(--fg-faint);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  display: none;
}
.search-box.has-text .clear-btn { display: block; }
.clear-btn:hover { color: var(--fg); }

.suggest-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px #1d2021cc;
  overflow: hidden;
  z-index: 30;
}
.suggest-item {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 14px;
}
.suggest-item:hover, .suggest-item.active {
  background: var(--bg-elevated);
  color: var(--fg);
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--fg-muted);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--fg); }

/* ---------- tabs / filters ---------- */
.tabs {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 0 20px;
  overflow-x: auto;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fg-muted);
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--fg); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-select {
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 10px;
  font-size: 13px;
}
.result-meta { margin-left: auto; color: var(--fg-faint); font-size: 13px; }

/* ---------- home ---------- */
.home-hero {
  display: none;
  width: 100%;
}
.home .home-hero {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
}
/* .home-center holds only the search bar in normal flow, so centering it
   vertically centers the bar itself; the heading is pinned above it via
   absolute positioning so its height doesn't shift the bar off-center. */
.home-center {
  position: relative;
  width: 100%;
  max-width: 820px;
  padding: 0 20px;
}
.home-heading {
  position: absolute;
  bottom: 100%;
  left: 20px;
  right: 20px;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.home-logo { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.home-logo h1 { margin: 0; font-size: 40px; letter-spacing: 1px; color: var(--fg); }
.home-tagline { color: var(--fg-faint); margin-top: 10px; font-size: 14px; }
.home-search-slot { width: 100%; }
.home .search-form { max-width: none; width: 100%; margin: 0; padding: 0; }
.home .search-box { height: 52px; padding: 0 18px; }
.home .search-box input { font-size: 17px; }
.home .topbar { flex-direction: column; padding: 0; min-height: 0; }
.home #settings-btn { position: fixed; top: 14px; right: 20px; }

/* ---------- results ---------- */
.results-layout {
  display: flex;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  align-items: flex-start;
}
.results-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.side-col { flex: 0 0 320px; }

.result-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.result-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.result-main { flex: 1; min-width: 0; }
.result-thumb {
  width: 120px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.result-favicon { width: 16px; height: 16px; vertical-align: -3px; margin-right: 8px; border-radius: 3px; }
.result-breadcrumb { color: var(--fg-faint); font-size: 13px; margin-bottom: 4px; }
.result-title { font-size: 18px; margin: 2px 0 6px; }
.result-title a { color: var(--link); }
.result-desc { color: var(--fg-muted); font-size: 14px; line-height: 1.5; }
.result-desc mark { background: none; color: var(--highlight); font-weight: 600; }
.result-engines { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.engine-badge {
  font-size: 11px;
  color: var(--fg-faint);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
}

.answer-card, .infobox-card {
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.answer-card { font-size: 16px; color: var(--fg); }
.infobox-card h3 { margin: 0 0 8px; color: var(--fg); font-size: 16px; }
.infobox-card img { max-width: 100%; border-radius: 6px; margin-bottom: 8px; }
.infobox-card .infobox-content { color: var(--fg-muted); font-size: 14px; line-height: 1.5; }
.infobox-attrs { margin-top: 10px; font-size: 13px; }
.infobox-attrs div { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px solid var(--border); }
.infobox-attrs span:first-child { color: var(--fg-faint); }
.infobox-urls a { display: block; margin-top: 6px; font-size: 13px; }

/* image / video grids */
.grid-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.image-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.image-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.image-card img { width: 100%; height: 140px; object-fit: cover; background: var(--bg-elevated); }
.image-card .image-title { font-size: 12px; color: var(--fg-muted); padding: 6px 8px; }

.video-card { display: flex; flex-direction: column; }
.video-card img { width: 100%; border-radius: var(--radius) var(--radius) 0 0; object-fit: cover; height: 160px; background: var(--bg-elevated); }
.video-card .video-body { padding: 10px 12px; }

.news-card .result-desc { margin-top: 4px; }

/* ---------- loader / states ---------- */
.sentinel { height: 1px; }
.loader { display: flex; justify-content: center; padding: 24px; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; color: var(--fg-faint); padding: 60px 20px; }
.error-inline { color: var(--error); font-size: 13px; padding: 8px 20px; }

/* ---------- settings ---------- */
.settings-panel {
  position: fixed; inset: 0;
  background: #1d2021cc;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 50;
}
.settings-card {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  width: 320px;
  max-width: 90vw;
  height: 100%;
  padding: 20px;
  overflow-y: auto;
}
.settings-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.settings-head h2 { margin: 0; font-size: 18px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; gap: 12px; }
.settings-row select { background: var(--bg-elevated); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.settings-hint { color: var(--fg-faint); font-size: 12px; margin-top: 16px; line-height: 1.6; }
kbd { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 11px; }

/* ---------- responsive ---------- */
@media (max-width: 800px) {
  .results-layout { flex-direction: column; padding: 14px; }
  .side-col { flex: none; width: 100%; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .tabs, .filters { padding-left: 12px; padding-right: 12px; }
  .result-thumb { width: 76px; height: 60px; }
}
