:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1c1f25;
  --border: #272b33;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #8ab4f8;
  --accent-ink: #0b1a33;
  --match: #fbbc04;
  --sound: #f0a868;
  --danger: #f28b82;
  --ok: #81c995;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  background: rgba(14, 15, 18, .9);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.brand .sub { color: var(--muted); font-weight: 400; font-size: 13px; }
.logo {
  width: 22px; height: 22px; border-radius: 6px; background: var(--panel-2); position: relative;
  box-shadow: inset 0 0 0 1px var(--border);
}
.logo::before { content: ""; position: absolute; left: 8px; top: 5px; border: 6px solid transparent; border-left: 8px solid var(--accent); border-right: 0; }
.logo::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: 3px; height: 2px; border-radius: 1px; background: var(--match); }
.status {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel);
  max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="busy"] .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.status[data-state="ready"] .dot { background: var(--ok); }
.status[data-state="warn"] .dot { background: var(--match); }
.status[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: clamp(14px, 3vw, 28px); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #3a404b; background: #22262d; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #a3c4fa; }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px 10px; font-size: 13px; }
.btn.icon.recording { border-color: var(--danger); color: var(--danger); animation: pulse 1.4s infinite; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: 13px; }
.link:hover, .link.active { color: var(--text); }
.link.active { text-decoration: underline; text-underline-offset: 3px; }

/* Empty state */
.empty { max-width: 760px; margin: clamp(8px, 6vh, 64px) auto 0; }
.drop {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  padding: clamp(28px, 6vw, 56px) clamp(18px, 4vw, 48px);
  border: 1.5px dashed #343a45; border-radius: 18px; background: var(--panel); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover { border-color: var(--accent); background: #171a20; }
.drop h1 { margin: 0; font-size: clamp(22px, 3.4vw, 30px); line-height: 1.2; letter-spacing: -.01em; }
.drop p { margin: 0; color: var(--muted); max-width: 580px; }
.drop .drop-sub { font-size: 14px; }
.drop em { color: var(--text); font-style: normal; background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.drop .hint { font-size: 13px; color: var(--muted); }
.drop-icon {
  width: 52px; height: 52px; border-radius: 14px; background: var(--panel-2); position: relative;
  box-shadow: inset 0 0 0 1px var(--border);
}
.drop-icon::before { content: ""; position: absolute; left: 20px; top: 14px; border: 10px solid transparent; border-left: 14px solid var(--accent); border-right: 0; }
.drop-icon::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 9px; height: 3px; border-radius: 2px; background: linear-gradient(90deg, #2a3445 0 30%, var(--match) 30% 48%, #2a3445 48% 70%, var(--match) 70% 78%, #2a3445 78%); }
.facts { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.facts li { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--muted); font-size: 14px; }
.facts b { color: var(--text); font-weight: 600; }
.warn { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius); background: #2a2210; border: 1px solid #5a4815; color: #fde293; font-size: 14px; }

/* Workspace */
.workspace { display: grid; gap: clamp(14px, 2vw, 24px); grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
@media (max-width: 1000px) { .workspace { grid-template-columns: 1fr; } }
.player-col { min-width: 0; }
.player-wrap { background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.player-wrap video { display: block; width: 100%; max-height: 62vh; background: #000; }

.timeline { position: relative; margin-top: 10px; height: 48px; border-radius: 8px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); cursor: pointer; touch-action: none; }
.timeline canvas { display: block; width: 100%; height: 100%; }
.tip {
  position: absolute; top: 4px; transform: translateX(-50%); pointer-events: none;
  background: rgba(0,0,0,.85); border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; padding: 2px 7px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.legend { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; align-items: center; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.heat { background: linear-gradient(90deg, #22314a, var(--accent)); }
.sw.heat-sound { background: linear-gradient(90deg, #4a2e22, var(--sound)); }
.sw.match { background: var(--match); }
.sw.pending { background: #1a1d23; box-shadow: inset 0 0 0 1px #2b3039; }
.legend-hint { margin-left: auto; }
.undercut { display: flex; gap: 8px; margin-top: 10px; }

.indexbar { margin-top: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.indexbar .bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.indexbar .fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.indexbar[data-state="done"] .fill { background: var(--ok); }
.indexbar[data-state="error"] .fill { background: var(--danger); }
.indexrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.indexrow .actions { display: flex; gap: 6px; }
.filemeta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.filemeta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Search column */
.search-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.search { display: flex; gap: 8px; }
.search input {
  flex: 1; min-width: 0; padding: 9px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); outline: none;
}
.search input:focus { border-color: var(--accent); }
.searchrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.scope { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.scope select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; }
.chip:hover { color: var(--text); border-color: #3a404b; }
.querybar { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.querybar img { height: 28px; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.querybar b { color: var(--text); font-weight: 500; }
.qicon { display: inline-block; color: var(--sound); margin-right: 5px; }

.controls { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 12px; }
#thresholds { display: grid; gap: 10px; }
.threshold { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.threshold > span { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.threshold b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.threshold input { width: 100%; accent-color: var(--match); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.toggle input { accent-color: var(--match); width: 16px; height: 16px; }
.nav { display: flex; gap: 6px; }

.summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.summary #summaryText { flex: 1; }
.summary .sort { display: flex; gap: 12px; white-space: nowrap; }
.results-host { display: grid; gap: 12px; max-height: 60vh; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 1000px) { .results-host { max-height: none; } }
.rgroup h3 {
  margin: 0 0 8px; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 6px; font-weight: 600;
}
.rgroup h3 .count { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; font-size: 11px; }
.dotmark { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.dotmark.frames { background: var(--accent); }
.dotmark.sound { background: var(--sound); }
.rgroup .results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.result {
  display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: center;
  padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.result:hover { border-color: #3a404b; background: #191c22; }
.result.current { border-color: var(--match); }
.result.weak { opacity: .72; }
.thumb { width: 112px; aspect-ratio: 16 / 9; border-radius: 6px; background: var(--panel-2) center / cover no-repeat; position: relative; overflow: hidden; }
.thumb .dur { position: absolute; right: 4px; bottom: 4px; font-size: 11px; background: rgba(0,0,0,.75); padding: 0 5px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.thumb .soundmark { position: absolute; left: 4px; bottom: 2px; font-size: 14px; color: var(--sound); text-shadow: 0 0 4px #000; }
.rinfo { min-width: 0; display: grid; gap: 4px; }
.rtime { font-weight: 600; font-variant-numeric: tabular-nums; }
.rscore { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rscore .meter { flex: 1; height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.rscore .meter i { display: block; height: 100%; background: var(--match); }
.result.weak .rscore .meter i { background: var(--muted); }
.ractions { display: flex; gap: 12px; }
.empty-results { color: var(--muted); font-size: 14px; padding: 6px 2px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px; }
.panel summary { padding: 11px 0; cursor: pointer; font-size: 14px; color: var(--muted); }
.panel[open] summary { color: var(--text); }
.panel[open] { padding-bottom: 14px; }
.panel .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.panel label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.panel select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }
.mem { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 10px; font-size: 13px; }
.mem dt { color: var(--muted); }
.mem dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.note { font-size: 12.5px; color: var(--muted); margin: 12px 0 12px; }

footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 18px 16px 28px; }

.dropveil { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(14, 15, 18, .82); border: 3px dashed var(--accent); }
.dropveil span { font-size: 22px; font-weight: 600; }
.offscreen { position: fixed; left: 0; top: 0; width: 2px; height: 2px; overflow: hidden; opacity: 0; pointer-events: none; }
.offscreen video { width: 2px; height: 2px; }

@media (max-width: 560px) {
  .brand .sub { display: none; }
  .result { grid-template-columns: 96px 1fr; }
  .thumb { width: 96px; }
  .panel .grid { grid-template-columns: 1fr; }
  .scope { margin-left: 0; width: 100%; }
}
