:root {
  --bg: #f2f2ef;
  --panel: #fff;
  --line: #e3e3df;
  --ink: #16161a;
  --muted: #74746e;
  --accent: #e8710a;
  --link: #2563eb;
  --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 #clear { margin-left: auto; }

main {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  padding: 0 24px 24px;
  height: calc(100vh - 62px);
}

aside {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 8px;
}
.label {
  font-family: var(--mono);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.label b { color: var(--bad); }
.count { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; }

.videos {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
}

.vcard {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  text-align: left;
  width: 100%;
  min-width: 0;
}
.vcard:hover { border-color: #cfcfc9; }
.vcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vcard img {
  width: 96px;
  height: 58px;
  object-fit: cover;
  border-radius: 6px;
  background: #ddd;
  display: block;
}
.thumb { position: relative; display: block; line-height: 0; }
.thumb::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-40%, -50%);
  border: 7px solid transparent;
  border-left: 12px solid rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.vcard .name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.vcard .meta { display: block; color: var(--muted); font-family: var(--mono); font-size: 11px; }

form { padding-top: 4px; }
textarea {
  width: 100%;
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  outline: none;
}
textarea::placeholder { color: #b3b3ad; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
}
#submit {
  width: 100%;
  margin-top: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
}
#submit:disabled { opacity: 0.45; cursor: default; }
.ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
}

#chat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
}

.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.empty .hint { font-size: 13px; }
#starter {
  margin-top: 16px;
  font-size: 12px;
  padding: 7px 14px;
  color: var(--ink);
  cursor: pointer;
}
#starter:hover { border-color: var(--accent); color: var(--accent); }
#starter:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#starter + .hint { margin-top: 8px; }

.run { margin-bottom: 28px; }
.bubble {
  background: var(--ink);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  margin-left: auto;
  width: fit-content;
  max-width: 70%;
}
.run-meta {
  text-align: right;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin: 6px 2px 14px;
}

.cards { display: grid; gap: 10px; }

.rcard {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.rcard-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.rcard-head .name { font-weight: 600; font-size: 14px; }
.rcard-head .elapsed {
  margin-left: auto;
  min-width: 34px;
  text-align: right;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #efefeb;
  color: var(--muted);
}
.chip.ready { background: #e2f4e8; color: var(--ok); }
.chip.cached { background: #ece7fb; color: #5a4ac7; }
.chip.failed, .chip.error { 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;
}
@keyframes spin { to { transform: rotate(1turn); } }

.rcard { animation: rise 0.28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

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

.rcard .text { white-space: pre-wrap; }
.rcard .text.err { color: var(--bad); font-family: var(--mono); font-size: 12px; }
.ts {
  color: var(--link);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

/* 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: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
}
