:root {
  --bg: #0b1020;
  --bg-soft: #131a30;
  --panel: rgba(255, 255, 255, 0.035);
  --border: rgba(255, 255, 255, 0.11);
  --text: #eaeefb;
  --muted: #9aa6c8;
  --accent: #5b8cff;
  --accent-2: #a06bff;
  --good: #35d39a;
  --warn: #ffc35b;
  --bad: #ff6b81;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fc;
    --bg-soft: #ffffff;
    --panel: rgba(15, 25, 60, 0.03);
    --border: rgba(15, 25, 60, 0.13);
    --text: #141a2e;
    --muted: #5b6584;
    --shadow: 0 12px 32px rgba(20, 30, 70, 0.12);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 560px at 12% -12%, rgba(91, 140, 255, 0.22), transparent 62%),
    radial-gradient(950px 520px at 92% 4%, rgba(160, 107, 255, 0.19), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1060px, 100% - 2.5rem); margin-inline: auto; }

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

/* ---------- hero ---------- */

.hero { padding: 3.2rem 0 1.6rem; }
.hero h1 { margin: 0 0 .55rem; font-size: clamp(1.7rem, 4.2vw, 2.6rem); letter-spacing: -.02em; line-height: 1.15; }
.hero .emoji { filter: drop-shadow(0 4px 12px rgba(91, 140, 255, .55)); }
.hero .sub { margin: 0; max-width: 68ch; color: var(--muted); }

.badges { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.15rem; }
.badge {
  font-size: .76rem; font-weight: 600; letter-spacing: .02em;
  padding: .3rem .68rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
}
.badge.live { color: var(--good); border-color: rgba(53, 211, 154, .4); }

/* ---------- controls / tabs ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 1.1rem; }
.ctl { display: flex; align-items: center; gap: .6rem; font-size: .86rem; color: var(--muted); }
.ctl select {
  font: inherit; font-size: .84rem; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 9px; padding: .4rem .6rem;
}
.ctl.checkbox { gap: .5rem; }
.ctl.checkbox input { accent-color: var(--accent); width: 15px; height: 15px; }

.tabs { display: flex; flex-wrap: wrap; gap: .35rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; }
.tab {
  font: inherit; font-size: .92rem; font-weight: 600; cursor: pointer;
  color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent;
  padding: .65rem .95rem; margin-bottom: -1px; border-radius: 8px 8px 0 0; transition: color .15s, background .15s;
}
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- panels ---------- */

.panel { display: none; padding-bottom: 3rem; }
.panel.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.lead { color: var(--muted); margin-top: 0; max-width: 72ch; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
.field small { font-weight: 400; opacity: .8; }

textarea, input[type="text"] {
  width: 100%; font: inherit; font-size: .95rem; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem .9rem; resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus, input[type="text"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, .18);
}

.row { display: flex; flex-wrap: wrap; gap: .55rem; margin: .4rem 0 1.4rem; }

.btn {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  padding: .58rem 1.05rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); transition: transform .12s, filter .15s, background .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(91, 140, 255, .3);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { color: var(--muted); font-weight: 500; }

/* ---------- similarity result ---------- */

.result {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--shadow);
}
.score-line { display: flex; align-items: baseline; gap: .85rem; flex-wrap: wrap; }
.score {
  font-size: 2.6rem; font-weight: 700; letter-spacing: -.03em; line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.verdict { font-size: 1rem; font-weight: 600; color: var(--muted); }

.meter { height: 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); overflow: hidden; margin: .95rem 0 .7rem; }
.meter-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .45s cubic-bezier(.22,1,.36,1); }
.meta { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- search results ---------- */

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.results li {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem;
  animation: fade .3s ease backwards;
}
.results .doc { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.results .rank {
  flex: 0 0 auto; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .76rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.results .text { flex: 1; }
.results .pct { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); font-size: .88rem; }
.results .bar { height: 5px; border-radius: 999px; background: var(--panel); overflow: hidden; margin-top: .6rem; }
.results .bar > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- embeddings ---------- */

.heatmap {
  display: grid; grid-template-columns: repeat(48, 1fr); gap: 2px;
  padding: .75rem; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border);
}
@media (max-width: 720px) { .heatmap { grid-template-columns: repeat(24, 1fr); } }
.heatmap i { display: block; aspect-ratio: 1; border-radius: 2px; }

.legend { display: flex; align-items: center; gap: .55rem; font-size: .74rem; color: var(--muted); margin: .7rem 0 1rem; }
.legend-bar { width: 130px; height: 8px; border-radius: 999px; background: linear-gradient(90deg, #3b6fe0, #1b2340, #ff6b81); }

.stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.stat {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 10px; padding: .5rem .8rem; font-size: .8rem; color: var(--muted);
}
.stat b { display: block; font-size: 1rem; color: var(--text); font-variant-numeric: tabular-nums; }

.raw summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.raw pre { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .8rem; overflow-x: auto; font-size: .78rem; }

/* ---------- misc ---------- */

.foot { padding: 1.5rem 0 3rem; color: var(--muted); font-size: .84rem; border-top: 1px solid var(--border); }

.loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(6, 9, 20, .74); backdrop-filter: blur(6px);
}
.loader-card {
  width: min(430px, calc(100% - 2.5rem)); text-align: center;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 18px; padding: 1.9rem 1.6rem; box-shadow: var(--shadow);
}
.loader-card h2 { margin: 0 0 .35rem; font-size: 1.1rem; }
.loader-file { margin: 0 0 1rem; color: var(--muted); font-size: .84rem; word-break: break-all; }
.progress { height: 7px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s ease; }
.hint { margin: .95rem 0 0; color: var(--muted); font-size: .76rem; }

.spinner {
  width: 34px; height: 34px; margin: 0 auto 1rem;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 1.6rem; transform: translateX(-50%);
  z-index: 60; max-width: min(560px, calc(100% - 2rem));
  background: var(--bg-soft); border: 1px solid var(--bad);
  color: var(--text); border-radius: 12px; padding: .8rem 1.1rem;
  box-shadow: var(--shadow); font-size: .88rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
