:root {
  --bg: #ffffff;
  --bg2: #f2f2f3;
  --bg3: #e5e5e7;
  --fg: #0f0f10;
  --fg2: #5f6066;
  --accent: #3b5bdb;
  --accent-fg: #ffffff;
  --border: #e3e3e6;
  --neurips: #7048e8;
  --icml: #0c8599;
  --iclr: #e8590c;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f10; --bg2: #1c1c1f; --bg3: #2a2a2e; --fg: #f1f1f2; --fg2: #a3a4ab;
    --accent: #748ffc; --accent-fg: #0f0f10; --border: #2a2a2e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f10; --bg2: #1c1c1f; --bg3: #2a2a2e; --fg: #f1f1f2; --fg2: #a3a4ab;
  --accent: #748ffc; --accent-fg: #0f0f10; --border: #2a2a2e; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; flex: none; }
.logo img { width: 28px; height: 28px; }
.search { flex: 1; min-width: 0; }
.search input {
  width: 100%; height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--border);
  background: var(--bg2); outline: none; font-size: 16px; /* 16px stops iOS zoom */
}
.search input:focus { border-color: var(--accent); }
.iconbtn {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--bg2);
  display: grid; place-items: center; cursor: pointer;
}
.iconbtn.on { color: var(--accent); }
@media (max-width: 480px) { .logo span { display: none; } }

/* filters */
.filters { padding: 8px 16px 4px; display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 8px; padding: 6px 12px; background: var(--bg2);
  cursor: pointer; white-space: nowrap; font-size: 14px;
}
.chip.on { background: var(--fg); color: var(--bg); }
select {
  flex: none; height: 32px; border-radius: 8px; border: 0; background: var(--bg2); padding: 0 8px; font-size: 14px;
}
.meta { justify-content: space-between; color: var(--fg2); font-size: 13px; }
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* grid */
main { padding: 8px 16px 24px; }
.grid { display: grid; gap: 20px 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; gap: 18px; } main { padding: 4px 0 24px; } .card .info { padding: 0 16px; } .card .thumb { border-radius: 0; } }
.card { text-decoration: none; display: block; min-width: 0; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--bg3);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 12px 14px; color: #fff;
}
.ph .pt { font-weight: 650; font-size: 16px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ph .pc { font-size: 12px; opacity: .85; letter-spacing: .04em; }
.ph.neurips { background: linear-gradient(135deg, #5f3dc4, #9775fa); }
.ph.icml { background: linear-gradient(135deg, #0b7285, #3bc9db); }
.ph.iclr { background: linear-gradient(135deg, #d9480f, #ffa94d); }
.ph.f-cv { background: linear-gradient(135deg, #2b8a3e, #69db7c); }
.ph.f-nlp { background: linear-gradient(135deg, #c2255c, #f783ac); }
.ph.cvpr { background: linear-gradient(135deg, #1864ab, #4dabf7); }
.ph.iccv { background: linear-gradient(135deg, #2b8a3e, #69db7c); }
.ph.eccv { background: linear-gradient(135deg, #5c940d, #a9e34b); }
.ph.acl { background: linear-gradient(135deg, #a61e4d, #f06595); }
.ph.emnlp { background: linear-gradient(135deg, #862e9c, #da77f2); }
.ph.naacl { background: linear-gradient(135deg, #c92a2a, #ff8787); }
.ph.eacl { background: linear-gradient(135deg, #e67700, #ffd43b); }
.ph.findings { background: linear-gradient(135deg, #495057, #adb5bd); }
.player video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; }
.badge {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.78); color: #fff;
  font-size: 12px; padding: 2px 6px; border-radius: 4px;
}
.badge.none { background: rgba(0,0,0,.5); }
.info { padding-top: 10px; }
.info h3 {
  margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sub { color: var(--fg2); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-weight: 600; }
.tag { color: var(--accent); }
.tag.neurips { color: var(--neurips); } .tag.icml { color: var(--icml); } .tag.iclr { color: var(--iclr); }
@media (prefers-color-scheme: dark) { .tag.neurips { color: #b197fc; } .tag.icml { color: #66d9e8; } .tag.iclr { color: #ffa94d; } }
.loading { height: 60px; display: grid; place-items: center; color: var(--fg2); font-size: 14px; }
.empty { color: var(--fg2); text-align: center; padding: 40px 16px; }

/* watch */
#watch { padding: 0; max-width: 1100px; margin: 0 auto; }
.player-wrap { position: sticky; top: calc(55px + env(safe-area-inset-top)); z-index: 10; background: #000; }
@media (min-width: 900px) { .player-wrap { position: static; margin: 16px 16px 0; border-radius: var(--radius); overflow: hidden; } }
.player { width: 100%; aspect-ratio: 16 / 9; position: relative; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .sl { position: absolute; inset: 0; overflow: auto; }
.player .out {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #fff; padding: 16px;
  background: linear-gradient(135deg, #343a40, #212529);
}
.player .out a { display: inline-block; margin-top: 12px; padding: 10px 18px; border-radius: 20px; background: #fff; color: #000; text-decoration: none; font-weight: 600; }
.handoff { position: absolute; inset: 0; overflow: hidden; color: #fff; }
.handoff.neurips, .handoff.f-ml { background: linear-gradient(135deg, #5f3dc4, #9775fa); }
.handoff.icml { background: linear-gradient(135deg, #0b7285, #3bc9db); }
.handoff.iclr { background: linear-gradient(135deg, #d9480f, #ffa94d); }
.handoff.f-cv { background: linear-gradient(135deg, #1864ab, #4dabf7); }
.handoff.f-nlp { background: linear-gradient(135deg, #a61e4d, #f06595); }
.handoff img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.handoff .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.hcontent { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; text-align: center; }
.playbig { width: 72px; height: 72px; border-radius: 50%; background: rgba(255,255,255,.95); color: #111; display: grid; place-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.playbig svg { margin-left: 4px; }
.hbtn { padding: 10px 20px; border-radius: 22px; background: #fff; color: #111; text-decoration: none; font-weight: 650; font-size: 15px; }
.hlink { color: #fff; font-size: 13px; opacity: .9; }
.hnote { font-size: 12px; opacity: .75; max-width: 320px; }
@media (max-width: 380px) { .playbig { width: 56px; height: 56px; } .hnote { display: none; } }
.watch-body { padding: 12px 16px 24px; }
.vidchips { margin-bottom: 8px; }
.vidchips:empty { display: none; }
#wTitle { font-size: 19px; line-height: 1.3; margin: 4px 0 6px; }
.wmeta { color: var(--fg2); font-size: 13px; }
.authors { margin: 8px 0; font-size: 14px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.links a, .links button {
  border: 0; border-radius: 18px; padding: 8px 14px; background: var(--bg2); text-decoration: none; font-size: 14px; cursor: pointer;
}
.links .primary { background: var(--fg); color: var(--bg); }
.abs { background: var(--bg2); border-radius: var(--radius); padding: 10px 14px; }
.abs summary { cursor: pointer; font-weight: 600; }
.abs p { margin: 8px 0 2px; white-space: pre-line; }
.more-h { font-size: 16px; margin: 22px 0 10px; }
.list { display: grid; gap: 12px; }
.li { display: grid; grid-template-columns: 168px 1fr; gap: 10px; text-decoration: none; }
.li .thumb { border-radius: 8px; }
.li .ph { padding: 6px 8px; } .li .ph .pt { font-size: 12px; -webkit-line-clamp: 3; } .li .ph .pc { font-size: 10px; }
.li h3 { margin: 0; font-size: 14px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 380px) { .li { grid-template-columns: 136px 1fr; } }

/* library sheet */
.libhead { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.libhead h2 { margin: 0; font-size: 18px; }

/* notes panel + library */
.watch-main, .li > div { min-width: 0; }
.watch-body { overflow-wrap: anywhere; }
.libhead .chip { text-decoration: none; }
.notes-panel {
  display: none; min-width: 0; padding: 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); flex-direction: column; gap: 12px; overflow: hidden; overflow-wrap: anywhere;
}
.notes-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notes-heading h2 { font-size: 18px; margin: 0; }
.notes-panes { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#notesAsk { display: flex; flex-direction: column; height: 100%; min-height: 300px; }
.notes-hint, .notes-status, .notes-time, .notes-source { color: var(--fg2); font-size: 13px; }
.notes-hint { margin: 0 0 8px; }
.notes-status { margin: 8px 0 0; white-space: pre-wrap; }
.notes-status:empty { display: none; }
.notes-chat { flex: 1; min-height: 70px; overflow-y: auto; overscroll-behavior: contain; }
.notes-message { padding: 10px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.notes-message.from-user { background: var(--bg2); }
.notes-message .notes-hint { margin-bottom: 4px; }
.notes-text, .notes-word p, .notes-plain { white-space: pre-wrap; }
.notes-form { padding-top: 8px; flex-shrink: 0; }
#notesHint { flex-shrink: 0; }
.notes-form label, .notes-connection label { display: block; font-size: 13px; color: var(--fg2); }
.notes-panel input, .notes-panel textarea, #vocabSearch {
  display: block; width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg2); color: var(--fg); font-size: 16px;
}
.notes-panel textarea { resize: vertical; min-height: 66px; max-height: 160px; }
.notes-panel :is(input, textarea, select, button):focus-visible, #vocabSearch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.notes-fields { display: flex; gap: 8px; margin: 8px 0; }
.notes-fields label { flex: 1; min-width: 0; }
.notes-fields select { display: block; width: 100%; height: 41px; font-size: 16px; }
.notes-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.notes-panel button:disabled { cursor: default; opacity: .5; }
.notes-connection { border-top: 1px solid var(--border); padding-top: 10px; max-height: 45%; overflow-y: auto; }
.notes-connection summary { cursor: pointer; font-size: 13px; }
.notes-connection label { margin: 8px 0; }
.notes-word { padding: 12px 0; border-bottom: 1px solid var(--border); }
.notes-word h3 { margin: 0; font-size: 15px; }
.notes-word .chip { margin: 4px 0; }
.notes-word p { margin: 6px 0; }
.notes-markdown { line-height: 1.6; }
.notes-markdown > :first-child { margin-top: 0; }
.notes-markdown :is(h1, h2, h3) { font-size: 18px; line-height: 1.35; }
.notes-markdown :is(img, video, audio, svg) { max-width: 100%; height: auto; }
.notes-markdown pre, .notes-markdown table { display: block; max-width: 100%; overflow-x: auto; }
.notes-markdown pre { padding: 10px; background: var(--bg2); border-radius: 8px; }
.notes-markdown :is(ul, ol) { padding-left: 22px; }
.notes-markdown blockquote { margin: 12px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--fg2); }
.notes-markdown a, .notes-source a { color: var(--accent); }
.notes-open { position: fixed; z-index: 21; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.notes-shade { display: none; }
body.notes-sheet-open { overflow: hidden; }
.notes-sheet-open .notes-shade { display: block; position: fixed; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0,0,0,.45); z-index: 30; }
.notes-sheet-open .notes-panel {
  display: flex; position: fixed; z-index: 31; inset: auto 0 0; height: 85vh; height: 85dvh;
  padding-bottom: calc(12px + env(safe-area-inset-bottom)); border-radius: var(--radius) var(--radius) 0 0;
}
#notesLibrary { max-width: 1000px; margin: 0 auto; padding: 16px; overflow-wrap: anywhere; }
#notesLibrary h1 { font-size: 22px; margin: 0; }
#notesLibrary h2 { font-size: 18px; margin-top: 24px; }
.notes-list { display: grid; gap: 12px; min-width: 0; }
.notes-entry { display: block; min-width: 0; padding: 12px; border-radius: var(--radius); background: var(--bg2); text-decoration: none; }
.notes-entry h3 { margin: 0 0 6px; font-size: 16px; }
.notes-entry .notes-hint { margin: 0; }
#vocabSearch { margin-bottom: 12px; }
@media (min-width: 1100px) {
  #watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; max-width: 1520px; padding-right: 16px; align-items: start; }
  .notes-panel { display: flex; position: sticky; top: calc(63px + env(safe-area-inset-top)); height: calc(100vh - 71px - env(safe-area-inset-top)); margin-top: 8px; }
  .notes-open, .notes-close, .notes-shade { display: none; }
}

.foot { color: var(--fg2); font-size: 12px; padding: 16px 16px 28px; border-top: 1px solid var(--border); text-align: center; }
.foot p { max-width: 720px; margin: 0 auto; }
