:root {
  --bg: #f6f7f9; --card: #fff; --text: #1b1e23; --muted: #667085; --border: #d9dde3;
  --accent: #d6332a; --accent-text: #fff; --hl: #ffe58a; --hover: #eef1f5; --err: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --card: #1a1d22; --text: #e6e8eb; --muted: #959ba5; --border: #2c3138;
    --accent: #e5483f; --accent-text: #fff; --hl: #6b5a12; --hover: #232830; --err: #f97066;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; margin: .4em 0; }

.top { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--card); }
.brand { font-weight: 700; font-size: 18px; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 6px; }
.who { display: flex; gap: 10px; align-items: center; font-size: 14px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
input[type=text], input[type=email], input[type=password], input[type=search] {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button.primary { padding: 10px 16px; font: inherit; font-weight: 600; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); cursor: pointer; white-space: nowrap; }
button.primary:disabled { opacity: .6; cursor: progress; }

.login { display: flex; justify-content: center; padding-top: 8vh; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }

.urlbar { display: flex; gap: 8px; position: relative; }   /* drop-down spans box + button */
.urlwrap { flex: 1; min-width: 0; }
.suggest { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  list-style: none; margin: 0; padding: 4px 0; max-height: min(60vh, 520px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .18); }
.suggest li { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.suggest .status { width: 1.2em; flex: none; text-align: center; }
.suggest li.ok .status { color: #12a150; }
.suggest li.failed .status { color: var(--err); }
.suggest .s-body { min-width: 0; flex: 1; }
.suggest li.s-close { justify-content: center; color: var(--muted); font-size: 14px;
  border-top: 1px solid var(--border); margin-top: 4px; padding: 10px 12px; }
.suggest .s-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-meta { display: block; color: var(--muted); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; margin-top: 8px; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.left { min-width: 0; }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.player iframe, .player #player { position: absolute; inset: 0; width: 100%; height: 100%; }
.meta h2 { font-size: 18px; margin: 12px 0 4px; }
.downloads { margin-top: 8px; font-size: 14px; }
.downloads a { margin-left: 8px; }

.right { min-width: 0; display: flex; flex-direction: column; }
.opt { font-size: 13px; color: var(--muted); margin: 6px 0; display: flex; gap: 6px; align-items: center; }
.count { font-size: 13px; margin: 4px 0 6px; }
.hits, .lines { list-style: none; margin: 0; padding: 0; }
.hits { max-height: 60vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--card); }
.hits:empty { display: none; }
.hits li, .lines li { display: flex; gap: 10px; padding: 7px 10px; align-items: baseline; }
.hits li + li { border-top: 1px solid var(--border); }
.hits li:hover, .lines li:hover { background: var(--hover); }
a.ts { font-variant-numeric: tabular-nums; font-weight: 600; text-decoration: none; white-space: nowrap; }
a.ts:hover { text-decoration: underline; }
mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 2px; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--muted); }
.lines { max-height: 50vh; overflow-y: auto; margin-top: 6px; }

/* ── Video tab panels (clip, channel) ── */
.downloads .small { margin-left: 8px; }
.panel { margin-top: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.panel > summary { padding: 10px 12px; font-weight: 600; color: var(--text); }
.panel-body { padding: 0 12px 12px; }
.clip-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.clip-label { width: 3em; font-size: 14px; color: var(--muted); }
input.time { width: 6.2em; padding: 6px 8px; text-align: center; font-variant-numeric: tabular-nums; }
.clip-len { font-size: 13px; margin: 6px 0; min-height: 1.2em; }
.clip-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 4px; }
.clip-actions .primary { padding: 8px 14px; }
.hits li > span { flex: 1; min-width: 0; }
button.clip-here { flex: none; padding: 2px 8px; align-self: center; }
.ch-list { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; }
.ch-item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; }
.ch-item + .ch-item { border-top: 1px solid var(--border); }
.ch-item.contains { background: color-mix(in srgb, #12a150 10%, transparent); }
.ch-item .s-body { flex: 1; min-width: 0; }
.ch-item .s-title { display: block; overflow-wrap: anywhere; }
.ch-item .s-meta { display: block; color: var(--muted); font-size: 12.5px; }
.ch-item.contains .s-meta { color: #12a150; }
.ch-list > li.muted { padding: 8px 10px; }

/* ── Clips tab ── */
.clip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.clip-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.clip-card .pl-card-title { display: block; overflow-wrap: anywhere; }
.clip-video { display: block; width: 100%; max-height: 60vh; margin-top: 10px; border-radius: 8px; background: #000; }
.clip-card .pl-actions { margin: 10px 0 0; }
a.button-link { display: inline-block; text-decoration: none; font-size: 13px; padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--text); background: var(--card); }
button.ready { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── Clip editor ── */
.ed-stage { position: relative; width: 100%; max-height: 62vh; margin: 10px auto 0; aspect-ratio: 16 / 9;
  background: #000; border-radius: 10px; overflow: hidden; touch-action: none; }
.ed-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.ed-crop { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgb(0 0 0 / .55);
  cursor: move; touch-action: none; box-sizing: border-box;
  background-image: linear-gradient(rgb(255 255 255 / .35) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / .35) 1px, transparent 1px);
  background-size: 33.333% 33.333%; background-position: -1px -1px; }
.ed-corner { position: absolute; width: 30px; height: 30px; touch-action: none; }
.ed-corner::after { content: ''; position: absolute; width: 16px; height: 16px; border: 4px solid #fff; }
.ed-corner.tl { left: -8px; top: -8px; cursor: nwse-resize; }      .ed-corner.tl::after { left: 4px; top: 4px; border-right: 0; border-bottom: 0; }
.ed-corner.tr { right: -8px; top: -8px; cursor: nesw-resize; }     .ed-corner.tr::after { right: 4px; top: 4px; border-left: 0; border-bottom: 0; }
.ed-corner.bl { left: -8px; bottom: -8px; cursor: nesw-resize; }   .ed-corner.bl::after { left: 4px; bottom: 4px; border-right: 0; border-top: 0; }
.ed-corner.br { right: -8px; bottom: -8px; cursor: nwse-resize; }  .ed-corner.br::after { right: 4px; bottom: 4px; border-left: 0; border-top: 0; }

/* trim bar, iPhone-style: filmstrip with a yellow frame between two grips */
.ed-trim { position: relative; height: 56px; margin: 16px 14px 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.ed-strip { position: absolute; inset: 0; border-radius: 6px; background: #222 center / 100% 100% no-repeat; }
.ed-shade { position: absolute; top: 0; bottom: 0; background: rgb(0 0 0 / .6); }
.ed-sel { position: absolute; top: -3px; bottom: -3px; border-top: 3px solid #f5c400; border-bottom: 3px solid #f5c400; pointer-events: none; }
.ed-grip { position: absolute; top: -3px; bottom: -3px; width: 28px; margin-left: -14px; cursor: ew-resize; touch-action: none; z-index: 2; }
.ed-grip span { position: absolute; top: 0; bottom: 0; left: 6px; width: 16px; background: #f5c400; border-radius: 5px; }
.ed-grip span::after { content: ''; position: absolute; left: 6px; top: 35%; height: 30%; width: 4px; border-radius: 2px; background: rgb(0 0 0 / .55); }
#edGripS span { border-top-right-radius: 0; border-bottom-right-radius: 0; left: 0; }
#edGripE span { border-top-left-radius: 0; border-bottom-left-radius: 0; left: 12px; }
.ed-head { position: absolute; top: -6px; bottom: -6px; width: 3px; margin-left: -1px; background: #fff;
  border-radius: 2px; box-shadow: 0 0 3px rgb(0 0 0 / .6); pointer-events: none; z-index: 1; }
.ed-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin: 4px 2px; }
.ed-times b { color: var(--text); font-variant-numeric: tabular-nums; }
.ed-fine { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 8px 0; font-size: 13px; color: var(--muted); }
.ed-fine-group { display: inline-flex; align-items: center; gap: 6px; }
.ed-crop-bar { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; padding: 4px; margin: 4px 0 14px; background: var(--hover);
  border-radius: 10px; }
.tabs [role=tab] { flex: 1; font: inherit; font-weight: 600; font-size: 14px; padding: 8px 6px; border: 0;
  border-radius: 7px; background: none; color: var(--muted); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tabs [role=tab][aria-selected=true] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.tab-badge { display: inline-block; min-width: 1.6em; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: 11.5px; line-height: 1.6em; }
.empty { margin: 24px 4px; }
.hint { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.small-text { font-size: 13px; }

/* ── Playlists ── */
.worker { font-size: 13px; margin: 4px 0; min-height: 1em; }
.progress { height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; margin: 8px 0 4px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .4s; }
.pl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.pl-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.pl-card:hover { border-color: var(--accent); }
.pl-card-title { font-weight: 600; }
.back { margin-bottom: 8px; font-size: 15px; }
.pl-title { font-size: 19px; margin: 0 0 2px; }
.pl-counts { font-size: 13px; }
.pl-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
#plResults { display: flex; flex-direction: column; gap: 12px; }
.pl-group { background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.pl-group-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  padding: 9px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
.pl-group-head a { overflow-wrap: anywhere; }
.pl-group .hits { border: 0; border-radius: 0; max-height: none; }
.pl-group .more { margin: 6px 12px 10px; }
.pl-videos { list-style: none; margin: 8px 0 0; padding: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; }
.pl-video { display: flex; gap: 10px; align-items: baseline; padding: 7px 12px; font-size: 14px; }
.pl-video + .pl-video { border-top: 1px solid var(--border); }
.pl-video .status { width: 1.2em; flex: none; text-align: center; }
.pl-video.ok .status { color: #12a150; }
.pl-video.failed .status { color: var(--err); }
.pl-video .s-body { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.pl-video .s-meta { display: block; color: var(--muted); font-size: 12.5px; }
.pl-video.nocaps, .pl-video.unavailable { color: var(--muted); }

.history { list-style: none; padding: 0; margin: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; }
.history li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; }
.history li + li { border-top: 1px solid var(--border); }
.history .status { width: 1.2em; text-align: center; flex: none; }
.history li.ok .status { color: #12a150; }
.history li.failed .status { color: var(--err); }
.history .body { flex: 1; min-width: 0; }
.history .body a { overflow-wrap: anywhere; }
.history .meta-line { color: var(--muted); font-size: 13px; }
.history .err { color: var(--err); font-size: 13px; overflow-wrap: anywhere; }
.history .actions { display: flex; gap: 6px; flex: none; }
button.small { font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
  background: var(--card); color: var(--text); border: 1px solid var(--border); }
button.small:hover { border-color: var(--accent); color: var(--accent); }
button.small.del { color: var(--muted); padding: 4px 8px; }
body { padding-bottom: 56px; }   /* room for the bottom-right corner buttons */

.corner { position: fixed; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 2px; padding: 2px 4px; z-index: 10;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; box-shadow: 0 1px 4px rgb(0 0 0 / .12); }
.corner button { background: none; border: 0; cursor: pointer; color: var(--muted); font: inherit;
  -webkit-tap-highlight-color: transparent; }
.corner button:hover { color: var(--accent); }
.corner button:focus:not(:focus-visible) { outline: none; }
.version { font-size: 13px; font-weight: 600; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.refresh { font-size: 18px; width: 32px; height: 32px; line-height: 1; }
.refresh.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.update-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: 64px; z-index: 11;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer; box-shadow: 0 2px 10px rgb(0 0 0 / .25); }

.modal { width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 720px); padding: 0;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px; }
.modal::backdrop { background: rgb(0 0 0 / .45); }
.modal-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; background: var(--card); border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
#changelogList { padding: 4px 18px 16px; }
.cl-entry { padding: 12px 0; }
.cl-entry + .cl-entry { border-top: 1px solid var(--border); }
.cl-entry h3 { margin: 0; font-size: 15px; }
.cl-entry .date { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.cl-entry ul { margin: 6px 0 0; padding-left: 20px; }
.cl-entry li { margin: 3px 0; font-size: 14px; }
.cl-entry code { font-size: 12.5px; background: var(--hover); padding: 0 4px; border-radius: 4px; }
