:root {
  --bg: #0e0f0a;            /* very dark olive — forests of Middle-earth */
  --bg-elev: #181a13;       /* warm dark — hobbit-hole wood */
  --bg-card: #232619;
  --fg: #e8e3d3;            /* parchment */
  --fg-dim: #a39c85;
  --accent: #d4af37;        /* The One Ring gold */
  --accent-2: #6b8e23;      /* olivedrab — Fangorn forest */
  --link: #c9a96e;          /* aged gold */
  --border: #2c2e22;
  --success: #8baf5a;
  --warn: #d4a347;
  --danger: #b54a3c;        /* mordor red, but muted */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
}

header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1f2117 0%, var(--bg) 100%);
}
header h1 {
  margin: 0 0 0.25rem;
  font-size: 2.4rem;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), #f4d878, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header .subtitle { color: var(--fg-dim); margin: 0; font-size: 1.05rem; }

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.ask form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.ask input[type="text"] {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.9rem 1rem;
  border-radius: 8px;
  font-size: 1.05rem;
  transition: border-color 0.15s;
}
.ask input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
}
.ask button {
  background: var(--accent);
  color: #1f1a08;
  border: none;
  padding: 0 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.ask button:hover:not(:disabled) { background: #e6c449; }
.ask button:active:not(:disabled) { transform: scale(0.97); }
.ask button:disabled { opacity: 0.5; cursor: not-allowed; }

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.9rem;
  color: var(--fg-dim);
}
.examples .ex {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.examples .ex:hover { border-color: var(--accent); background: var(--bg-card); }

.answer {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}
.answer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-bottom: 0.75rem;
}
.elapsed { font-variant-numeric: tabular-nums; }
.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.copy-btn:hover { color: var(--fg); border-color: var(--accent); }
.answer-text {
  font-size: 1.05rem;
  white-space: pre-wrap;
  line-height: 1.65;
}
.answer-text a { color: var(--link); }
.answer-text code { background: var(--bg-card); padding: 0.1em 0.3em; border-radius: 4px; font-size: 0.92em; }

.sources {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.sources h3 { margin: 0 0 0.5rem; font-size: 0.95rem; color: var(--fg-dim); font-weight: 600; }
.sources ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.sources li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.sources a { color: var(--link); text-decoration: none; }
.sources a:hover { text-decoration: underline; }
.sources .type {
  font-size: 0.7rem;
  background: var(--bg-card);
  color: var(--fg-dim);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sources .score { color: var(--fg-dim); font-variant-numeric: tabular-nums; font-size: 0.8rem; }

.results h2 { font-size: 1.3rem; margin: 2rem 0 0.5rem; }
.results .hint { color: var(--fg-dim); font-size: 0.9rem; margin: 0 0 1rem; }
.result {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.result:hover { border-color: var(--accent); transform: translateX(2px); }
.result-title { font-weight: 600; color: var(--fg); display: flex; align-items: center; gap: 0.5rem; }
.result-title .badge { font-size: 0.7rem; background: var(--bg-card); color: var(--fg-dim); padding: 0.1rem 0.5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.05em; }
.result-snippet { color: var(--fg-dim); font-size: 0.9rem; margin-top: 0.4rem; line-height: 1.5; }
.result-snippet mark { background: rgba(212, 175, 55, 0.28); color: var(--fg); padding: 0 0.1em; border-radius: 2px; }
.result-meta { font-size: 0.75rem; color: var(--fg-dim); margin-top: 0.35rem; }

.empty, .loading {
  color: var(--fg-dim);
  text-align: center;
  padding: 1.5rem;
  font-style: italic;
}
.loading::after {
  content: "▎";
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.error {
  background: rgba(181, 74, 60, 0.10);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 1rem;
  border-radius: 8px;
}

.hidden { display: none; }

footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--fg-dim);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
footer code { background: var(--bg-elev); padding: 0.1em 0.4em; border-radius: 4px; font-size: 0.85em; }
#health { margin-bottom: 0.5rem; }
#health.ok { color: var(--success); }
#health.err { color: var(--danger); }

@media (max-width: 600px) {
  .ask form { flex-direction: column; }
  .ask button { padding: 0.75rem; }
  header h1 { font-size: 1.7rem; }
  .answer { padding: 1rem; }
}
