:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a2130;
  --text-muted: #5b6472;
  --accent: #0f6e5e;
  --accent-soft: #e4f3ef;
  --accent-strong: #0a5245;
  --bar-track: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

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

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 64px 24px 48px;
}

.hero { text-align: center; }

.hero h1 {
  font-size: clamp(2.2rem, 5vw, 3rem);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 620px;
  margin: 0 auto 32px;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  resize: vertical;
  border: none;
  outline: none;
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: transparent;
  min-height: 64px;
}

textarea::placeholder { color: #9aa2ad; }

.search-form button#search-btn {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.search-form button#search-btn:hover { background: var(--accent-strong); }
.search-form button#search-btn:active { transform: scale(0.98); }
.search-form button#search-btn:disabled { opacity: 0.6; cursor: wait; }

.hint {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.8;
  text-align: left;
}

.examples {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.examples-label { color: var(--text-muted); font-size: 0.9rem; margin-right: 4px; }

.chip {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chip:hover { background: #d5ece5; }

.status {
  min-height: 1.4em;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 18px 0 0;
}

.status.error { color: #b3261e; }

.results {
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.low-signal-banner {
  background: #fff4e5;
  color: #7a4a00;
  border: 1px solid #f0c987;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.9rem;
}

.scope-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  opacity: 0.85;
}

/* An explicit `display` on these classes would otherwise beat the browser's
   default [hidden] rule (author styles win over the UA stylesheet even at
   equal specificity), so the `hidden` attribute silently stops hiding
   anything the moment a class sets display. */
.results[hidden],
.detail[hidden] {
  display: none;
}

.result-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
}

.clickable {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.clickable:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 2px 4px rgba(16, 24, 40, 0.06), 0 12px 28px rgba(16, 24, 40, 0.1);
}

/* Cards now contain a second, independently-clickable "Copy citation"
   button (stopPropagation'd from the card's own navigate-to-detail click),
   so hover-only affordance is no longer unambiguous on its own -- this
   chevron signals "the card itself goes somewhere" distinctly from the
   button's own action. Scoped to .result-card specifically, not the
   shared .clickable class, since lineage nodes/rows don't have a nested
   button and don't need it. */
.result-card.clickable::after {
  content: "→";
  position: absolute;
  right: 20px;
  bottom: 18px;
  color: var(--accent);
  font-size: 1.1rem;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.result-card.clickable:hover::after {
  opacity: 0.6;
  transform: translateX(0);
}

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

.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.result-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.rank {
  color: var(--text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.device-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}

.overall-score {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
}

.meta-line {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 4px 0 14px;
}

.meta-line .k-number {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bar-track);
  padding: 1px 6px;
  border-radius: 5px;
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent-strong);
  border-radius: 6px;
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.copy-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

.match-bullets {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.match-bullets li {
  font-size: 0.85rem;
  color: var(--text);
  padding-left: 20px;
  position: relative;
}

.match-bullets li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

.attr-pills {
  margin: 0 0 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.attr-pill {
  background: var(--bar-track);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
}

.facets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

@media (max-width: 560px) {
  .facets { grid-template-columns: 1fr; }
}

.facet-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.facet-bar-track {
  height: 6px;
  background: var(--bar-track);
  border-radius: 999px;
  overflow: hidden;
}

.facet-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.snippet {
  font-size: 0.92rem;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin: 0;
}

.snippet .label {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 6px;
}

.file-protocol-warning {
  background: #fff4e5;
  color: #7a4a00;
  border-bottom: 1px solid #f0c987;
  padding: 12px 20px;
  text-align: center;
  font-size: 0.9rem;
}

.file-protocol-warning code {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.detail {
  margin-top: 24px;
  animation: rise 0.2s ease both;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent-strong);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 16px;
}

.back-btn:hover { text-decoration: underline; }

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow);
}

.detail-card .device-name {
  font-size: 1.5rem;
  margin: 0 0 6px;
}

.detail-card h4 {
  margin: 20px 0 6px;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.full-text {
  white-space: pre-line;
  font-size: 0.95rem;
  margin: 0;
}

.detail-card a {
  color: var(--accent-strong);
}

.lineage-section {
  margin-top: 28px;
}

.lineage-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.lineage-section-head h3 { margin: 0; }

.lineage-view-btn {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.lineage-view-btn:hover { background: #d5ece5; }

.lineage-section h3 {
  font-size: 1rem;
  margin: 0 0 12px;
}

/* ---- predicate lineage diagram ---- */

.lineage-view {
  animation: rise 0.2s ease both;
}

.lineage-title {
  font-size: 1.4rem;
  margin: 0 0 6px;
}

.lineage-caption {
  color: var(--text-muted);
  font-size: 0.88rem;
  max-width: 760px;
  margin: 0 0 24px;
}

.lineage-scroll {
  overflow-x: auto;
  padding-bottom: 12px;
}

.lineage-canvas {
  position: relative;
}

.lineage-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.lineage-edge {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}

.lineage-node {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: block;
}

.lineage-node.clickable {
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.lineage-node.clickable:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.lineage-node.leaf-link {
  border-style: dashed;
  cursor: pointer;
}

.lineage-node.leaf-link:hover { border-color: var(--accent); }

.lineage-node.unresolved {
  border-style: dashed;
  border-color: #b3261e;
  opacity: 0.85;
}

.lineage-node-name {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.lineage-node-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.lineage-node-note {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.lineage-node.unresolved .lineage-node-note { color: #b3261e; }

.lineage-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 8px;
}

.lineage-row.clickable:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.lineage-row-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.in-sample-badge {
  font-size: 0.75rem;
  color: var(--accent-strong);
  font-weight: 600;
}

.flag {
  color: #b3261e;
}

.empty-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
}

.footer {
  margin-top: 56px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141a;
    --surface: #171c24;
    --border: #262d38;
    --text: #eef1f5;
    --text-muted: #97a1ae;
    --accent: #21a186;
    --accent-soft: #163229;
    --accent-strong: #35c4a5;
    --bar-track: #232a34;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  }
  .chip:hover { background: #1b3a30; }
}
