:root {
  --bg: #fff8ef;
  --surface: #ffffff;
  --ink: #2b2340;
  --muted: #6f6787;
  --line: #eadfce;
  --accent: #ff7a59;
  --accent-ink: #ffffff;
  --chip: #f3ead9;
  --chip-on: #2b2340;
  --chip-on-ink: #ffffff;
  --done: #2fa36b;
  --shadow: 0 2px 10px rgba(43, 35, 64, .08);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141f;
    --surface: #221e2d;
    --ink: #f3eefc;
    --muted: #a69fba;
    --line: #342f42;
    --accent: #ff8a6b;
    --accent-ink: #1b1424;
    --chip: #2c2739;
    --chip-on: #f3eefc;
    --chip-on-ink: #17141f;
    --done: #4cc38a;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn:disabled { opacity: .6; cursor: progress; }
h1 { font-size: clamp(1.3rem, 4vw, 1.8rem); margin: 0; letter-spacing: -.01em; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-accent:hover { filter: brightness(1.05); border-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--ink);
  background: var(--chip); border: 0; border-radius: 999px; padding: 6px 14px 6px 6px; min-height: 44px;
}
.chip.all { padding-left: 14px; }
.chip img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.chip small { color: var(--muted); font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); }
.chip[aria-pressed="true"] small { color: inherit; opacity: .75; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.search {
  flex: 1 1 240px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; min-height: 44px;
}
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; min-width: 0; }
select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; min-height: 44px;
}
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.status { color: var(--muted); margin: 4px 0 16px; min-height: 1.45em; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }

.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:hover { transform: translateY(-3px); }
.card-hit { all: unset; cursor: pointer; display: flex; flex-direction: column; flex: 1; }
.card-hit:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: var(--radius); }
.thumb { position: relative; aspect-ratio: 9 / 14; background: var(--chip); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play {
  position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; font-size: 22px; padding-left: 4px;
}
.badge {
  position: absolute; top: 8px; right: 8px; background: var(--done); color: #fff; border: 0; cursor: pointer;
  font: inherit; font-size: .8rem; font-weight: 700; border-radius: 999px; padding: 4px 10px; min-height: 28px;
}
.badge:hover::after, .badge:focus-visible::after { content: ' ✕'; }
.card.watched .thumb img { opacity: .7; }
.meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.meta strong {
  font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta span { color: var(--muted); font-size: .85rem; }

#more { height: 1px; }
.foot { color: var(--muted); font-size: .85rem; padding-top: 32px; padding-bottom: 32px; }

dialog {
  border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--ink);
  width: min(440px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto;
}
dialog::backdrop { background: rgba(15, 10, 25, .75); }
.player-bar { display: flex; align-items: center; gap: 8px; padding: 10px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.player-bar #counter { flex: 1; text-align: center; color: var(--muted); font-size: .9rem; }
.player-bar .close { margin-left: 4px; }
.frame-box { padding: 0 10px; }
#frame { display: block; width: 100%; height: 640px; border: 0; border-radius: 12px; background: #fff; }
.unwatch-row { margin: 0; padding: 0 16px 16px; font-size: .9rem; }
.unwatch-row .linkish:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.caption { white-space: pre-line; padding: 4px 16px 16px; margin: 0; font-size: 1.05rem; }

.foot a { color: inherit; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--chip-on); color: var(--chip-on-ink); padding: 12px 20px; border-radius: 999px;
  font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center;
}
@media (max-width: 480px) {
  .top-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .top-actions .btn { padding: 8px 12px; }
}

/* ---- admin page ---- */
.admin-main { padding-top: 20px; padding-bottom: 48px; display: grid; gap: 16px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel.narrow { max-width: 420px; }
.panel h2 { margin: 0 0 10px; font-size: 1.25rem; }
.panel h3 { margin: 20px 0 8px; font-size: 1.05rem; }
.panel p { margin: 0 0 12px; }
.hint { color: var(--muted); font-size: .92rem; }
.err { color: #d64545; margin: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 4px; font-weight: 600; }
.stack label.toggle { display: inline-flex; font-weight: 400; }
.admin input:not([type=checkbox]), .admin textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.row input:not([type=checkbox]) { width: auto; flex: 1 1 180px; }
.admin textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
.admin a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.admin form { margin: 0; }
.progress { font-weight: 600; min-height: 1.45em; margin: 12px 0 4px !important; }
.linkish { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; }
.acc-list { display: grid; gap: 8px; }
.acc { display: grid; grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1fr) 110px; gap: 10px; align-items: center; }
.acc img, .acc .plus { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.acc .plus { display: grid; place-items: center; background: var(--chip); color: var(--muted); font-size: 1.4rem; }
.acc .btn { width: 100%; }
.acc .who { display: grid; }
.acc .who a { color: var(--ink); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.acc .who small { color: var(--muted); }
.acc-add { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
@media (max-width: 560px) {
  .acc { grid-template-columns: 40px minmax(0, 1fr) 96px; }
  .acc > input:last-of-type { grid-column: 2 / 3; grid-row: 2; }
}
.steps { padding-left: 20px; display: grid; gap: 8px; margin: 0 0 16px; }
.bookmarklet { cursor: grab; }
.log { white-space: pre-wrap; font-size: .82rem; color: var(--muted); max-height: 300px; overflow: auto; }
code { background: var(--chip); padding: 1px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.api-lines { margin: 0 0 8px; padding-left: 20px; display: grid; gap: 4px; }
.admin summary { cursor: pointer; font-weight: 600; }
details.sub { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
details.sub[open] > summary { margin-bottom: 8px; }
details.more > summary { font-size: 1.25rem; font-weight: 700; }
details.more .tool { border-top: 1px solid var(--line); margin-top: 20px; }
details.more .tool:first-of-type { border-top: 0; margin-top: 4px; }
details.more .tool h3 { margin-top: 16px; }
.token-form { margin-top: 12px; }
