:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #17202a;
  --muted: #5d6b7a;
  --border: #d9dee5;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26b00;
  --bad: #c0392b;
  --focus: #2f6fed55;
  --radius: 10px;
  --shadow: 0 1px 2px #0000000f, 0 4px 16px #0000000a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171d24;
    --surface-2: #1f2730;
    --text: #e6ebf0;
    --muted: #96a3b1;
    --border: #2c3641;
    --accent: #5b8ff9;
    --accent-text: #0b1220;
    --ok: #4cc283;
    --warn: #e0a344;
    --bad: #ef6b5b;
    --focus: #5b8ff966;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; }
code { font-size: 0.9em; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 650; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #8f5cf7);
}

.token { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }


.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 1rem 16px; }
}

.side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.75rem 0 0.25rem; }
label.check { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0 1rem 0 0; color: var(--text); }

input[type="text"], input[type="url"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

fieldset { border: 0; padding: 0; margin: 0.75rem 0 0; }
legend { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }

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

.row { display: flex; gap: 0.5rem; }
.row input { flex: 1; min-width: 0; }

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); width: 100%; margin-top: 1rem; font-weight: 600; }
.btn-quiet { background: transparent; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.tabs button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.open { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.error { color: var(--bad); }
.note { background: var(--surface-2); border-radius: 8px; padding: 0.5rem 0.75rem; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.job-head p { margin: 0; word-break: break-all; }

.pill {
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  text-transform: capitalize;
}
.pill.succeeded { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.failed { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.pill.running { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 0.75rem 0 0.25rem; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.4s ease; }

.version-row { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.75rem 0; }
.versions { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.player-wrap { margin-top: 0.5rem; }
.player {
  background: #000;
  border-radius: var(--radius);
  display: flex;
  justify-content: center;
  overflow: hidden;
}
.player video { max-width: 100%; max-height: 70vh; display: block; }
.downloads { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.downloads a { font-size: 0.85rem; color: var(--accent); }

.section-title { margin: 1.25rem 0 0.5rem; }

.scenes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
}
.scene {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.scene.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus); }
.scene img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); display: block; }
.scene .body { padding: 0.5rem 0.65rem 0.65rem; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.scene .text { font-size: 0.9rem; }
.scene .meta { font-size: 0.75rem; color: var(--muted); }
.scene .meta a { color: inherit; }
.scene .actions { display: flex; gap: 0.4rem; margin-top: auto; padding-top: 0.25rem; }
.badges { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.badge { font-size: 0.7rem; border-radius: 4px; padding: 0.05rem 0.35rem; background: var(--surface-2); color: var(--muted); }
.badge.good { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }

.jobs-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.jobs-head h2 { margin: 0; }
.jobs { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-direction: column; gap: 0.4rem; max-height: 60vh; overflow-y: auto; }
.job-row { display: flex; align-items: center; gap: 0.5rem; border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.5rem; }
.job-row.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus); }
.job-link { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; padding: 0; }
.job-link .job-label { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.job-link .job-meta { font-size: 0.72rem; color: var(--muted); }
#jobs-more { margin-top: 0.5rem; }

.cost-total { margin: 0 0 0.4rem; font-weight: 600; }
.cost-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.cost-table td { padding: 0.3rem 0.4rem; border-top: 1px solid var(--border); vertical-align: top; }
.cost-table td.usage { color: var(--muted); }
.cost-table td.usd { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.rating { margin-top: 1.25rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.rating-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.rating-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.75rem; }
.rate-item { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.rate-item.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.rate-item img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); display: block; }
.rate-item .body { padding: 0.5rem 0.65rem 0.65rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.rate-item .meta { font-size: 0.75rem; color: var(--muted); }
.rate-item .text { font-size: 0.85rem; }
.rate-item .actions { display: flex; gap: 0.5rem; align-items: center; font-size: 0.8rem; }
.rate-item .actions a { color: var(--accent); }
.scores { display: flex; gap: 0.25rem; margin-top: auto; }
.scores .btn { flex: 1; }
.scores .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.rating-summary h4 { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
.rating-summary table { border-collapse: collapse; font-size: 0.85rem; }
.rating-summary th, .rating-summary td { padding: 0.3rem 0.5rem; border-top: 1px solid var(--border); text-align: left; }
.rating-summary .agreement th { font-weight: normal; color: var(--muted); }
.confusion th, .confusion td { text-align: center; min-width: 2.2rem; }
.confusion td.same { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); font-weight: 600; }
.confusion td.zero { color: var(--muted); }
.disagreements { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; }
.blind .vision-badge { display: none; }

.warnings { margin-top: 1rem; }
.warnings li { font-size: 0.85rem; margin: 0.2rem 0; }

dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1rem;
}
dialog::backdrop { background: #0008; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; }

.alts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.6rem; }
.alt { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.alt img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.alt .body { padding: 0.4rem 0.5rem; font-size: 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.alt .btn { margin-top: auto; }
.swap-other { margin-top: 1rem; }
.swap-generate { margin-top: 1rem; display: grid; gap: 0.5rem; }

/* Placed after the generic input rules so they win. */
.token input[type="password"] { width: 16rem; max-width: 60vw; }
.versions .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
