:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1f2328; --muted: #6b6f76; --line: #e3dfd6;
  --accent: #2f5d8a; --accent-ink: #ffffff; --accent-soft: #e4edf6; --gold: #c8962a;
  --danger: #b3261e; --ok: #2e7d4f; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1f2226; --ink: #e8e6e1; --muted: #9a9ea5; --line: #30343a;
    --accent: #7fb0e0; --accent-ink: #0d1b29; --accent-soft: #22303e; --gold: #e0b857;
    --danger: #ff8a80; --ok: #7fd1a0; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --panel: #1f2226; --ink: #e8e6e1; --muted: #9a9ea5; --line: #30343a;
  --accent: #7fb0e0; --accent-ink: #0d1b29; --accent-soft: #22303e; --gold: #e0b857;
  --danger: #ff8a80; --ok: #7fd1a0; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0; }
.muted { color: var(--muted); font-weight: normal; }
.small-text { font-size: .85rem; }
.center { text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 1100px; margin: 0 auto; padding: 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.1rem; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }
main > section, #app > section { margin-top: 22px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.narrow { max-width: 420px; margin: 8vh auto 0; }

input, button { font: inherit; color: inherit; }
input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; font-size: .9rem; color: var(--muted); margin: 12px 0 6px; }

button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 10px 16px; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.ghost { background: transparent; border-color: var(--line); }
.small { padding: 6px 12px; font-size: .9rem; }
.wide { width: 100%; margin-top: 12px; }
details { margin-top: 16px; }
summary { cursor: pointer; color: var(--muted); }
.msg { min-height: 1.3em; margin: 10px 0 0; font-size: .92rem; }
.msg.err { color: var(--danger); }

.grab input { font-size: 1.05rem; padding: 14px 16px; }
.kinds { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.kinds button { flex: 1 1 160px; padding: 12px 16px; }

.jobs { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.job .t { font-weight: 600; overflow-wrap: anywhere; }
.job .s { color: var(--muted); font-size: .9rem; white-space: pre-line; overflow-wrap: anywhere; }
.job.error .s { color: var(--danger); }
.job.done .s { color: var(--ok); }
.bar { height: 6px; border-radius: 3px; background: var(--accent-soft); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
.bar.indeterminate > i { width: 30%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

.libhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; margin: 12px 0 14px; flex-wrap: wrap; }
.filters input { flex: 1 1 240px; }
.chips { display: flex; gap: 6px; }
.chip { background: var(--panel); border-color: var(--line); padding: 8px 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.items { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.item {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.thumb {
  position: relative; aspect-ratio: 16 / 9; background: var(--accent-soft); border: 0; padding: 0;
  border-radius: 0; display: block; width: 100%;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.2rem; color: var(--accent); }
.thumb .len {
  position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / .72); color: #fff;
  font-size: .78rem; padding: 2px 7px; border-radius: 6px;
}
.thumb .kind {
  position: absolute; left: 8px; top: 8px; background: var(--gold); color: #1b1400;
  font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase;
}
.item .body { padding: 12px 14px 4px; flex: 1; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.item .meta a { color: inherit; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 14px; }
.actions button, .actions a {
  font-size: .85rem; padding: 6px 10px; border-radius: 8px; background: var(--accent-soft);
  color: var(--ink); text-decoration: none; border: 0;
}
.actions .del { background: transparent; color: var(--danger); margin-left: auto; }

dialog {
  width: min(920px, 96vw); border: 0; border-radius: var(--radius); padding: 0;
  background: var(--panel); color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
.player-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 14px; }
#playerBody video { width: 100%; display: block; background: #000; max-height: 75vh; }
#playerBody audio { width: calc(100% - 28px); margin: 8px 14px 18px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .92rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25); overflow-wrap: anywhere; z-index: 10;
}

@media (max-width: 520px) {
  .items { grid-template-columns: 1fr; }
  .narrow { margin-top: 3vh; }
}
