:root {
  --bg: #f2f2ef;
  --panel: #fff;
  --line: #e3e3df;
  --ink: #16161a;
  --muted: #74746e;
  --accent: #e8710a;
  --ok: #157f3d;
  --bad: #c02b2b;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 18px 24px 14px;
}
header h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.pill {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}
header #restart { margin-left: auto; }

main { padding: 0 24px 40px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
}
.ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
}

/* ------------------------------------------------------------------ connect */

#connect {
  max-width: 620px;
  margin: 8vh auto 0;
}
#connect h2 {
  margin: 0 0 10px;
  font-size: 27px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.lede { margin: 0 0 26px; color: var(--muted); }

#search {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
#search label {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
#search label + * { margin-bottom: 16px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
  background: #fbfbf9;
}
#bucket { font-family: var(--mono); font-size: 13px; }
textarea { resize: vertical; border-color: var(--accent); border-width: 2px; background: var(--panel); }
input:focus, textarea:focus { border-color: var(--accent); }

#go {
  width: 100%;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
}
#go:disabled { opacity: 0.45; cursor: default; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; text-align: center; }

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

#results { max-width: 860px; margin: 0 auto; }

#summary h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
#summary .query { margin: 0 0 22px; color: var(--muted); }
#summary .warn { color: var(--bad); font-size: 15px; font-weight: 400; }
.tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ece7fb;
  color: #5a4ac7;
}

.spinner {
  width: 15px;
  height: 15px;
  flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

#feed { display: grid; gap: 10px; margin-bottom: 26px; }

.moment {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  animation: rise 0.3s ease both;
}
.moment:hover { border-color: #cfcfc9; }
.moment:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.shot { position: relative; display: block; line-height: 0; }
.shot img {
  width: 160px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  background: #ddd;
  display: block;
}
.shot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-40%, -50%);
  border: 8px solid transparent;
  border-left: 13px solid rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.shot .at {
  position: absolute;
  right: 5px;
  bottom: 5px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
}

.moment .body { display: grid; gap: 4px; min-width: 0; }
.sev {
  justify-self: start;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: #efefeb;
  color: var(--muted);
}
.sev.critical { background: #fbe6e6; color: var(--bad); }
.sev.notable { background: #fdeddc; color: #a2560a; }
.what { overflow-wrap: anywhere; }
.evidence { color: var(--muted); font-size: 13px; font-style: italic; overflow-wrap: anywhere; }
.src { color: var(--muted); font-family: var(--mono); font-size: 11px; }

.none {
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 26px 20px;
  text-align: center;
  margin: 0;
}

/* ------------------------------------------------------------------ objects */

#objects {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}
#objects summary {
  cursor: pointer;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
#listing { margin-top: 10px; }

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 54px 96px;
  gap: 10px;
  align-items: center;
  padding: 6px 2px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}
.row:hover { background: #fafaf8; }
.row .key { overflow-wrap: anywhere; }
.row .size, .row .dur { color: var(--muted); text-align: right; }

.chip {
  justify-self: end;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e2f4e8;
  color: var(--ok);
  white-space: nowrap;
}
.chip.working { background: #efefeb; color: var(--muted); }
.chip.failed { background: #fbe6e6; color: var(--bad); }
.chip.working::after {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: 6px;
  vertical-align: -1px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .moment, .chip.working::after, .spinner { animation: none; }
}

/* ------------------------------------------------------------------ player */

/* padding and overflow stay at 0/hidden so only the true backdrop matches e.target === dialog */
#player {
  padding: 0;
  border: 0;
  overflow: hidden;
  width: min(92vw, 1100px);
  max-width: none;
  background: var(--panel);
  border-radius: 14px;
}
#player::backdrop { background: rgba(20, 20, 22, 0.68); }

.player-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
}
.player-head .ghost { margin-left: auto; font-size: 16px; line-height: 1; padding: 4px 11px; }

#player-video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 78vh;
  background: #000;
}

@media (max-width: 700px) {
  .moment { grid-template-columns: 1fr; }
  .shot img { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .row { grid-template-columns: minmax(0, 1fr) 96px; }
  .row .size, .row .dur { display: none; }
}
