:root {
  color-scheme: light dark;
  --bg: #f5f5f3; --surface: #ffffff; --surface2: #ecece8; --text: #1b1c1f; --muted: #62646b;
  --line: #d9d9d4; --accent: #2f5fd0; --on-accent: #ffffff; --danger: #c22f22; --warn: #fdf1d3; --warn-text: #5e4500;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417; --surface: #1d1f23; --surface2: #2a2c31; --text: #f0f0ee; --muted: #a4a6ad;
    --line: #363840; --accent: #8fb0ff; --on-accent: #10172b; --danger: #ff8a7e; --warn: #40330f; --warn-text: #ffe7ad;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { min-height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); font-weight: 600; }
.btn.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.big { min-height: 50px; padding: 0 24px; }
input, select, textarea { min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
textarea { width: 100%; min-height: 90px; resize: vertical; }

.login { min-height: 100dvh; padding: 24px 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.login img { border-radius: 16px; }
.login p { max-width: 340px; color: var(--muted); }
.err { color: var(--danger) !important; }

.top { position: sticky; top: 0; z-index: 5; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; max-width: 1240px; width: 100%; margin: 0 auto; }
.row h1 { flex: 1; min-width: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { flex-wrap: wrap; }
.tools input { flex: 1 1 200px; min-width: 0; }
.tools select { flex: 0 1 180px; min-width: 0; }
.bar { display: flex; align-items: center; gap: 8px; max-width: 1240px; width: 100%; margin: 0 auto; padding: 6px 10px; background: var(--surface2); border-radius: 8px; }
.bar > span { flex: 1; min-width: 0; }
.bar.warn { background: var(--warn); color: var(--warn-text); }

.content { max-width: 1240px; margin: 0 auto; padding: 14px 16px 60px; }
.content h2 { margin: 18px 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; }
.content h2:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.open { display: block; color: inherit; text-decoration: none; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--surface2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.count { position: absolute; right: 6px; bottom: 6px; padding: 1px 7px; border-radius: 5px; background: rgba(0, 0, 0, .78); color: #fff; font-size: 13px; }
.tick { position: absolute; left: 8px; top: 8px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .45); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.card.on .tick { background: var(--accent); color: var(--on-accent); }
.name { padding: 9px 11px 2px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.meta { padding: 0 11px; color: var(--muted); font-size: 13px; }
.acts { margin-top: auto; padding: 6px; display: flex; gap: 4px; }
.acts .btn { flex: 1; min-height: 40px; padding: 0 6px; font-size: 14px; border-color: transparent; background: transparent; }
.acts .btn:hover:not(:disabled) { background: var(--surface2); }
.btn.del, .acts .btn.del { color: var(--danger); }
.btn.push { margin-right: auto; }
.pick { all: unset; display: block; width: 100%; padding-bottom: 10px; cursor: pointer; }
.pick:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dlg.flat { padding: 0; }
.vsec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.ph { aspect-ratio: 16 / 12; background: var(--surface2); border-radius: 10px; }

dialog { width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog.small { width: min(460px, calc(100vw - 24px)); }
dialog select { max-width: 100%; }
.dlg { padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.dlg h2 { font-size: 18px; overflow-wrap: anywhere; }
.dlg-head { display: flex; align-items: center; gap: 8px; }
.dlg-head h2 { flex: 1; min-width: 0; }
.dlg-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.note { color: var(--muted); font-size: 14px; }
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label.field input, label.field select, label.field textarea { width: 100%; color: var(--text); font-size: 16px; }
.names { margin: 0; padding-left: 20px; max-height: 40dvh; overflow: auto; overflow-wrap: anywhere; }

.vbar { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; background: var(--surface); }
.vbar select { flex: 1 1 150px; min-width: 0; }
.vbar .grow { flex: 1 1 100%; color: var(--muted); font-size: 14px; }
.videos { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.video { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; }
.video:hover { background: var(--surface2); }
.video input { flex: none; width: 22px; height: 22px; min-height: 0; }
.video img { flex: none; width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 5px; background: var(--surface2); }
.video .txt { min-width: 0; flex: 1; }
.video a { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; font-size: 15px; text-decoration: none; }
.video a:hover { text-decoration: underline; }
.video small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 4px 18px rgba(0, 0, 0, .3); }

@media (max-width: 520px) {
  .top { position: static; }
  #selectBar { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 10; width: auto; box-shadow: 0 4px 18px rgba(0, 0, 0, .35); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tools input { flex-basis: 100%; }
  .tools select { flex: 1 1 100%; }
  .tools .btn { flex: 1; padding: 0 6px; }
  .acts .btn { font-size: 13px; }
  .video img { width: 72px; }
}
