:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #d9a300;
  --accent-ink: #2b2100;
  --ok: #128a4d;
  --err: #c0392b;
  --run: #1c6fd6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1c1f26;
    --ink: #e9eaee;
    --muted: #9aa0ac;
    --line: #2c3038;
    --accent: #e8bc2e;
    --accent-ink: #241c00;
    --ok: #37c07e;
    --err: #f0736a;
    --run: #62a6ff;
  }
}

* { box-sizing: border-box; }

/* Author `display` rules outrank the UA stylesheet's [hidden]{display:none}, so
   .auth-gate{display:flex} would keep the sign-in panel on screen after login.
   Make the attribute win everywhere. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.dot { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }
.topbar-actions { display: flex; gap: 8px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px;
}
.add-card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.hint code { background: rgba(127,127,127,.14); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

textarea, input[type=text], input[type=url], input[type=email], input[type=password], input[type=number] {
  width: 100%; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--muted); }
.check input { accent-color: var(--accent); }

.btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn.danger:hover { color: var(--err); border-color: var(--err); }
.btn[disabled] { opacity: .5; cursor: default; }

.auth-gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 26px 26px 20px;
}
.auth-card .brand { margin-bottom: 6px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.auth-card label input { margin-top: 4px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-switch { margin: 12px 0 0; text-align: center; }
.linkish {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--ink); text-decoration: underline; text-underline-offset: 2px;
}

.btn.warn { background: rgba(217,163,0,.16); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.btn.warn:hover { background: rgba(217,163,0,.28); }

.msg { font-size: 13px; margin-top: 8px; min-height: 18px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }
.msg.busy { color: var(--run); }

.debug-shot {
  display: block; width: 100%; height: auto; margin: 10px 0 4px;
  border: 1px solid var(--line); border-radius: 8px;
}
.account-row { margin-top: 0; margin-bottom: 4px; }
.account-row .hint { margin: 0; overflow-wrap: anywhere; }

.list-head { display: flex; align-items: baseline; gap: 10px; margin: 28px 2px 12px; }
.list-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
.count { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; font-size: 14px; }

.item {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
}
.thumb {
  aspect-ratio: 16 / 9; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--line); cursor: pointer; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.thumb .placeholder { color: var(--muted); font-size: 13px; text-align: center; padding: 12px; }
.thumb-duration {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0,0,0,.72); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 1;
  padding: 3px 6px; border-radius: 5px;
}

.item-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.item-title { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.item-title h3 { margin: 0; font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }
.src { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.src a { color: inherit; }

.badge {
  font-size: 11.5px; font-weight: 650; letter-spacing: .02em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  background: rgba(127,127,127,.16); color: var(--muted);
}
.badge.done { background: rgba(18,138,77,.15); color: var(--ok); }
.badge.error { background: rgba(192,57,43,.15); color: var(--err); }
.badge.running, .badge.queued { background: rgba(28,111,214,.15); color: var(--run); }

.link-row { display: flex; gap: 6px; align-items: center; }
.link-row input {
  flex: 1; font-size: 12px; padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.err-text { font-size: 12.5px; color: var(--err); overflow-wrap: anywhere; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

.dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px;
  background: var(--panel); color: var(--ink); max-width: 520px; width: calc(100% - 32px);
}
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog h2 { margin: 0 0 14px; font-size: 17px; }
.dialog fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0 0 14px; }
.dialog legend { padding: 0 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.dialog label input { margin-top: 4px; }
.dialog label.check { display: inline-flex; margin-bottom: 0; }
.dialog label.check input { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.spacer { flex: 1; }
.select {
  font: inherit; font-size: 13px; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}

.logs { display: flex; flex-direction: column; gap: 8px; }
.log {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--line); border-radius: 10px; padding: 10px 14px;
  display: flex; gap: 12px; align-items: flex-start;
}
.log.error { border-left-color: var(--err); }
.log.info { border-left-color: var(--ok); }
.log.warn { border-left-color: var(--accent); }

.log-shot {
  width: 116px; flex: 0 0 116px; aspect-ratio: 16/9; object-fit: cover; object-position: top center;
  border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: var(--bg);
}
.log-main { flex: 1; min-width: 0; }
.log-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.log-head .who { font-weight: 600; font-size: 13.5px; }
.log-head .when { font-size: 12px; color: var(--muted); }
.log-msg { font-size: 13.5px; margin-top: 3px; overflow-wrap: anywhere; }
.log-trail {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px; color: var(--muted); margin-top: 5px; overflow-wrap: anywhere;
}
.log-detail { margin-top: 6px; }
.log-detail summary { font-size: 12px; color: var(--muted); cursor: pointer; }
.log-detail pre {
  margin: 6px 0 0; padding: 8px 10px; background: var(--bg); border-radius: 6px;
  font-size: 11.5px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}

.viewer { max-width: min(1500px, 96vw); }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.viewer-head h2 { margin: 0; }
.viewer img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); display: block; }
