:root {
  --bg: #0a0b10;
  --panel: #12141c;
  --panel-2: #171a24;
  --line: #262a38;
  --ink: #ecedf4;
  --muted: #8b8f9e;
  --stable: #6c8cff;
  --amber: #e8a33d;
  --danger: #e2543a;
  --display: 'Fraunces', serif;
  --body: 'Inter', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.05;
  background-image: radial-gradient(circle at 1px 1px, #fff 1px, transparent 0);
  background-size: 3px 3px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1;
}

.mark {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  color: var(--stable);
}

.top-note {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 3rem;
  position: relative;
  z-index: 1;
}

.hero h1 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 1.1rem;
}

.hero h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--stable);
}

.lede {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--muted);
  max-width: 58ch;
  margin: 0 0 2.2rem;
}

#search {
  display: flex;
  gap: 0.6rem;
}

#q {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.15s ease;
}

#q:focus { border-color: var(--stable); }

#search button {
  background: var(--stable);
  color: #060714;
  border: none;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  padding: 0 1.4rem;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

#search button:hover { background: #93a8ff; }
#search button:active { transform: scale(0.97); }
#search button:focus-visible, #q:focus-visible, .chip:focus-visible { outline: 2px solid var(--stable); outline-offset: 2px; }

.hint {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chip:hover { border-color: var(--stable); color: var(--stable); }

.result, .empty, .loading {
  margin-top: 3rem;
  padding-top: 2.2rem;
  border-top: 1px solid var(--line);
  animation: rise 0.5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ch-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.ch-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ch-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  width: fit-content;
  margin-bottom: 0.3rem;
}
.ch-matched { background: color-mix(in srgb, var(--stable) 22%, transparent); color: var(--stable); }
.ch-nomatch { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--muted); }
.ch-error { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }

.ch-name {
  display: block;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.25rem;
}

.ch-meta {
  display: block;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.cases-panel {
  margin-top: 2rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--line);
}

.cases-panel h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.15rem;
  margin: 0 0 0.3rem;
}

.cases-sub {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.9rem;
}

.cases-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }

.case-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.case-title {
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}
.case-title:hover { color: var(--stable); text-decoration: underline; }

.case-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.cases-empty {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.provenance {
  margin-top: 2rem;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 1rem;
}
.provenance a { color: var(--stable); }

.empty p { margin: 0 0 0.5rem; }

.loading:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.9rem;
}

.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--stable);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.about {
  margin-top: 4.5rem;
  padding-top: 2.2rem;
  border-top: 1px solid var(--line);
}

.about h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.3rem;
  margin: 0 0 1rem;
}

.about p {
  color: var(--muted);
  line-height: 1.65;
  font-size: 0.94rem;
  max-width: 62ch;
}

.about .limits { color: var(--ink); }
.about .limits strong { color: var(--amber); }

footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .result, .empty, .loading, .pulse { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .top { padding: 1.2rem 1.2rem; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  main { padding: 3rem 1.2rem 2.5rem; }
}
