@font-face {
  font-family: "FiraCode-Regular";
  src: url("./FiraCode-Regular.ttf");
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #fafafa;
  --fg: #2a2a2a;
  --border: #d0d0d0;
  --muted: #757575;
  --lighter: #a0a0a0;
  --subtle: #e8e8e8;
  --hover-bg: #f0f0f0;
  --and-operator: #e57373;
  --or-operator: #63df56;
  --paren-operator: #64b5f6;
  --keyword: rgba(202, 202, 202, 0.18);
}

:root[data-theme="dark"] {
  --bg: #1a1a1a;
  --fg: #e0e0e0;
  --border: #404040;
  --muted: #909090;
  --lighter: #707070;
  --subtle: #2a2a2a;
  --hover-bg: #252525;
  --and-operator: #ef5350;
  --or-operator: #63df56;
  --paren-operator: #42a5f5;
  --keyword: rgba(194, 194, 194, 0.07);
}

#main {
  width: 100%;
  max-width: 1200px;
  height: 600px;
  border-radius: 8px;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  padding: 60px 20px;
  transition: background-color 0.3s, color 0.3s;
}

main {
  max-width: 720px;
  margin: 0 auto;
}

header {
  margin-bottom: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
}

#themeToggle {
  padding: 12px 12px;
  border: 1.5px solid var(--border);
  border-radius: 0px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  position: absolute;
  left: 2em;
  bottom: 2em;
}

#themeToggle:hover {
  background: var(--hover-bg);
  border-color: var(--fg);
  color: var(--fg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

#themeToggle:active {
  transform: scale(0.95);
}

#themeToggle::before {
  content: '⬛';
}

:root[data-theme="dark"] #themeToggle::before {
  content: '⬜';
}

.search {
  margin-bottom: 24px;
}

label {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

#query {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 0px;
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  outline: none;
  margin-bottom: 8px;
  transition: all 0.2s ease;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#query > span {
  margin: 4px 0;
}

#query:empty:before {
  content: attr(data-placeholder);
  color: var(--lighter);
  pointer-events: none;
}

#query:focus {
  border-color: var(--fg);
  box-shadow: 0 0 0 4px rgba(42, 42, 42, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] #query:focus {
  box-shadow: 0 0 0 4px rgba(224, 224, 224, 0.06), 0 1px 3px rgba(0, 0, 0, 0.3);
}

#query .error-highlight {
  animation: error-pulse 2.0s ease-in;
}

@keyframes error-pulse {
  0% {
    background-color: rgba(245, 61, 58, 0.8);
  }
  100% {
    background-color: rgba(245, 61, 58, 0.0);
  }
}

/* Syntax highlighting */
.and-operator {
  color: var(--and-operator);
}

.or-operator {
  color: var(--or-operator);
}

.paren-operator {
  color: var(--paren-operator);
  padding-left: 2px;
  padding-right: 4px;
}

#query .and-operator, .or-operator, .paren-operator {
  font-weight: 500;
  font-size: 18px;
  background-color: rgba(0, 0, 0, 0.0);
}

#query .keyword {
  color: var(--fg);
  padding: 6px 14px;
  display: inline-block;
  border: 1px solid rgba(128, 128, 128, 0.35);
  background-color: rgba(0, 0, 0, 0.0);
}

#query > .keyword:hover {
  background: rgba(202, 202, 202, 0.08);
}

#query:not(:focus) .keyword {
  cursor: pointer;
}

#query:focus .keyword {
  cursor: text;
}

:root[data-theme="dark"] #query .keyword {
  opacity: 0.85;
}

.syntax {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 16px;
  margin-top: 12px;
}

.sources {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.source-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
}

.source-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.source-item span {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  transition: all 0.2s ease;
}

.source-item:hover span {
  border-color: var(--fg);
  background: var(--hover-bg);
}

.source-item input[type="checkbox"]:checked ~ span {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  font-weight: 600;
}

.source-item:active span {
  transform: scale(0.95);
}

#searchBtn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 0px;
  background: var(--fg);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#searchBtn:active {
  transform: scale(0.985);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#searchBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#results {
  display: none;
}

#results.visible {
  display: block;
}

.results-header {
  margin-bottom: 32px;
  padding: 20px 24px;
  background: var(--hover-bg);
  border-radius: 0px;
  border: 1px solid var(--subtle);
}

.results-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.results-header p {
  font-size: 13px;
  color: var(--muted);
}

.article {
  margin-bottom: 40px;
  padding: 24px;
  border-radius: 0px;
  background: var(--bg);
  border: 1px solid var(--subtle);
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.article:hover {
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.article:last-child {
  margin-bottom: 0;
}

.article-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  margin-bottom: 14px;
  align-items: center;
}

.article-source {
  font-weight: 700;
  color: var(--fg);
  padding: 3px 10px;
  background: var(--hover-bg);
  border-radius: 0px;
  font-size: 11px;
  letter-spacing: 0.02em;
}

.article-date {
  color: var(--muted);
  font-weight: 500;
}

.article-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.article-title a {
  color: var(--fg);
  text-decoration: none;
  transition: color 0.2s ease;
}

.article-title a:hover {
  color: var(--and-operator);
}

.article-description {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 12px;
}

.article-categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.category {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 0px;
  background: var(--hover-bg);
  color: var(--muted);
  border: 1px solid var(--subtle);
  letter-spacing: 0.01em;
}

.loading {
  text-align: center;
  padding: 60px 0;
  font-size: 14px;
  color: var(--muted);
}

.no-results {
  padding: 60px 0;
  text-align: center;
}

.no-results h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--fg);
}

.no-results p {
  font-size: 14px;
  color: var(--muted);
}

.error {
  padding: 16px;
  border-radius: 0px;
  border: 1px solid #e57373;
  background: #ffebee;
  color: #c62828;
  margin-bottom: 32px;
  font-size: 14px;
}

:root[data-theme="dark"] .error {
  background: #3a1f1f;
  border-color: #6d3333;
  color: #ef9a9a;
}

.status-digging {
  animation: dig 0.635s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

@keyframes dig {
  0% {
    transform: translateY(0) scaleX(1) scaleY(1);
  }
  15% {
    transform: translateY(-2px) scaleX(0.95) scaleY(1.1);
  }
  45% {
    transform: translateY(10px) scaleX(1.25) scaleY(0.8);
    animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  55% {
    transform: translateY(6px) scaleX(1.15) scaleY(0.85);
  }
  70% {
    transform: translateY(2px) scaleX(0.9) scaleY(1.15);
  }
  85% {
    transform: translateY(-1px) scaleX(0.97) scaleY(1.05);
  }
  100% {
    transform: translateY(0) scaleX(1) scaleY(1);
  }
}
