:root {
  --bg: #0d0d0c;
  --panel: #151513;
  --card: #1a1a18;
  --line: #2a2a27;
  --text: #f2efe8;
  --muted: #8f8b82;
  --dim: #5f5c55;
  --accent: #f2efe8;
  --fred: #ffcf4a;
  --used: #7fd3a8;
  --hit: rgba(255, 207, 74, .22);
  --radius: 10px;
  --sans: "Inter Tight", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f2ed; --panel: #ebe8e1; --card: #fff; --line: #dcd8cf; --text: #141412;
  --muted: #6d6a62; --dim: #9a968c; --accent: #141412; --fred: #b07d00; --used: #237a52;
  --hit: rgba(255, 196, 0, .3); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 24px; padding: 14px 28px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; letter-spacing: -.01em; }
.mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.stats { display: flex; gap: 20px; color: var(--muted); font: 12px var(--mono); flex: 1; overflow-x: auto; white-space: nowrap; }
.stats b { color: var(--text); font-weight: 500; }
.user { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* search */
.searchbar { padding: 26px 28px 8px; max-width: 1600px; margin: 0 auto; }
#searchForm { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 0 16px; transition: border-color .15s; }
#searchForm:focus-within { border-color: var(--muted); }
#searchForm .icon { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; flex: none; }
#q { flex: 1; background: none; border: 0; outline: 0; padding: 16px 0; font-size: 18px; min-width: 0; }
#q::-webkit-search-cancel-button { filter: invert(.6); }
kbd { font: 12px var(--mono); color: var(--dim); border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
select.chip { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.chip.toggle[aria-pressed="true"] { background: var(--fred); border-color: var(--fred); color: #111; font-weight: 600; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg button { background: none; border: 0; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.count { margin-left: auto; color: var(--muted); font: 12px var(--mono); }

/* grid */
main { padding: 16px 28px 80px; max-width: 1600px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.card { cursor: pointer; border-radius: var(--radius); outline: none; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--card); border: 1px solid var(--line); }
.card:hover .thumb, .card:focus-visible .thumb { border-color: var(--muted); }
.thumb img, .thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb.portrait img, .thumb.portrait video { object-fit: contain; background: #000; }
.badges { position: absolute; left: 8px; top: 8px; display: flex; gap: 5px; }
.badge { font: 600 10px var(--mono); letter-spacing: .04em; padding: 3px 6px; border-radius: 4px; background: rgba(0,0,0,.65); color: #fff; backdrop-filter: blur(4px); }
.badge.fred { background: var(--fred); color: #111; }
.badge.used { background: var(--used); color: #0b2018; }
.dur { position: absolute; right: 8px; bottom: 8px; font: 11px var(--mono); padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.7); color: #fff; }
.score { position: absolute; right: 8px; top: 8px; font: 11px var(--mono); padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.65); color: #fff; }
.meta { padding: 9px 2px 0; }
.name { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.snip { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.snip .t { font: 11px var(--mono); color: var(--fred); margin-right: 4px; }
mark { background: var(--hit); color: var(--text); border-radius: 2px; padding: 0 1px; }
.empty { text-align: center; color: var(--muted); padding: 80px 20px; }
.more { display: block; margin: 32px auto 0; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 10px 26px; cursor: pointer; }
.skeleton .thumb { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--panel); border-left: 1px solid var(--line); transform: translateX(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); z-index: 10; overflow-y: auto; }
body.open .drawer { transform: none; }
body.open .scrim { opacity: 1; pointer-events: auto; }
.drawer-inner { padding: 18px 22px 60px; }
.dhead { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.dhead h2 { font-size: 18px; margin: 0; flex: 1; word-break: break-all; font-weight: 600; letter-spacing: -.01em; }
.close { background: none; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; flex: none; }
.player { width: 100%; border-radius: var(--radius); background: #000; aspect-ratio: 16 / 9; display: block; }
.player.portrait { aspect-ratio: 9 / 16; max-height: 70vh; margin: 0 auto; }
.fredbar { position: relative; height: 6px; background: var(--card); border-radius: 3px; margin: 10px 0 4px; overflow: hidden; }
.fredbar i { position: absolute; top: 0; bottom: 0; background: var(--fred); border-radius: 2px; }
.fredlabel { font: 11px var(--mono); color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 13px; font-size: 13px; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 16px 0; }
.facts div { background: var(--panel); padding: 9px 12px; }
.facts dt { font: 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.facts dd { margin: 2px 0 0; font-size: 13px; }
h3 { font: 600 11px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin: 26px 0 10px; }
.desc { margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.tag:hover { color: var(--text); border-color: var(--muted); }
.usage { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; text-decoration: none; }
.usage img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: var(--card); }
.usage .ut { font-weight: 500; font-size: 13.5px; }
.usage .us { font: 11px var(--mono); color: var(--muted); margin-top: 3px; }
.transcript { max-height: 380px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.seg-line { display: flex; gap: 12px; padding: 7px 12px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.seg-line:last-child { border-bottom: 0; }
.seg-line:hover { background: var(--card); }
.seg-line.active { background: color-mix(in srgb, var(--fred) 12%, transparent); }
.seg-line .t { font: 11px var(--mono); color: var(--dim); padding-top: 2px; flex: none; width: 42px; }
.path { font: 11.5px var(--mono); color: var(--muted); word-break: break-all; margin: 4px 0; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 20; }

@media (max-width: 700px) {
  .top { padding: 12px 16px; gap: 12px; }
  .stats { display: none; }
  .searchbar { padding: 16px 16px 4px; }
  main { padding: 12px 16px 60px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .count { width: 100%; margin: 4px 0 0; }
  #q { font-size: 16px; padding: 13px 0; }
  kbd { display: none; }
}

/* account menu */
.user { position: relative; }
.who { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid transparent; border-radius: 999px; padding: 3px 10px 3px 3px; cursor: pointer; color: var(--muted); font-size: 13px; }
.who:hover, .who[aria-expanded="true"] { border-color: var(--line); color: var(--text); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--fred); color: #111; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 12px 40px rgba(0,0,0,.35); z-index: 20; }
.menu a, .menu button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; font-size: 13px; text-decoration: none; cursor: pointer; color: var(--text); }
.menu a:hover, .menu button:hover { background: var(--card); }
.menu-head { padding: 8px 10px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 10px; }
.role { font: 11px var(--mono); text-transform: uppercase; color: var(--fred); }

/* clip bank: kind tabs, category sidebar, select + delete */
.kinds { display: flex; gap: 4px; padding: 10px 28px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.kinds button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px 10px; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.kinds button:hover { color: var(--text); }
.kinds button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--fred); font-weight: 500; }
.kinds span { font: 11px var(--mono); color: var(--dim); margin-left: 4px; }
.bank-wrap { display: grid; grid-template-columns: 236px minmax(0, 1fr); max-width: 1840px; margin: 0 auto; }
.bank-main .searchbar, .bank-main main { max-width: none; }
.cats { border-right: 1px solid var(--line); padding: 18px 12px 60px 20px; position: sticky; top: 55px; align-self: start; max-height: calc(100dvh - 55px); overflow-y: auto; scrollbar-width: thin; }
.cats h4 { font: 500 10.5px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 18px 0 6px; display: flex; justify-content: space-between; }
.cats h4:first-child { margin-top: 0; }
.cats h4 button { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; text-transform: none; letter-spacing: 0; }
.cats .opt { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; border-radius: 7px; padding: 5px 8px; font-size: 13px; color: var(--muted); cursor: pointer; text-align: left; }
.cats .opt:hover { background: var(--card); color: var(--text); }
.cats .opt.on { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.cats .opt.on::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--fred); flex: none; }
.cats .opt b { flex: 1; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.cats .opt.keep b { text-transform: none; }
.cats .opt i { font: normal 11px var(--mono); color: var(--dim); }
.cats .none { font-size: 12px; color: var(--dim); padding: 2px 8px; }
.chips-on { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips-on:empty { display: none; }
.chips-on button { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text); cursor: pointer; }
.chips-on button::after { content: " ✕"; color: var(--muted); }
.bulk { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 8px 10px 8px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; position: sticky; top: 64px; z-index: 4; }
.card .tick { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid #fff9; background: #0006; display: none; z-index: 2; }
.selecting .card .tick { display: block; }
.card.sel .tick { background: var(--fred); border-color: var(--fred); }
.card.sel .tick::after { content: "✓"; color: #111; font: 700 14px/19px var(--sans); display: block; text-align: center; }
.card.sel .thumb { outline: 2px solid var(--fred); outline-offset: -2px; }
.selecting .card .score { display: none; }
.btn.danger { color: #ff8a7a; }
@media (max-width: 900px) {
  .bank-wrap { grid-template-columns: 1fr; }
  .cats { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 6px; overflow-x: auto; }
  .cats section { flex: none; }
  .cats h4 { margin: 0 0 4px; }
  .cats .opts { display: flex; gap: 4px; }
  .cats .opt { width: auto; white-space: nowrap; }
  .kinds { padding: 6px 16px 0; }
}
.snip .why { font: 600 9.5px var(--mono); letter-spacing: .05em; text-transform: uppercase; border-radius: 4px; padding: 1px 5px; margin-right: 6px; vertical-align: 1px; }
.snip .why.seen { background: #1e2536; color: #9db8ff; }
.snip .why.said { background: #1c3a2c; color: #7fd3a8; }
:root[data-theme="light"] .snip .why.seen { background: #e3eaff; color: #2f4fb0; }
:root[data-theme="light"] .snip .why.said { background: #dcf3e7; color: #1f6b47; }
