:root {
  --bg: #f6f5f2; --panel: #ffffff; --panel2: #efeee9; --line: #e2e0d9; --text: #1d1f24; --muted: #6b6e76;
  --accent: #6d5ce8; --accent-2: #eceafd; --teal: #0f9f86; --amber: #d97a2b; --rose: #d9466f; --blue: #2f7fd6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --r: 12px; --side: 248px; --detail: 520px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --panel: #1b1e26; --panel2: #232733; --line: #2d3240; --text: #e8e9ee; --muted: #959aa8;
    --accent: #8b7cf6; --accent-2: #2a2645; --teal: #22c3a6; --amber: #f59e5b; --rose: #f06b92; --blue: #5aa2f0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161c; --panel: #1b1e26; --panel2: #232733; --line: #2d3240; --text: #e8e9ee; --muted: #959aa8;
  --accent: #8b7cf6; --accent-2: #2a2645; --teal: #22c3a6; --amber: #f59e5b; --rose: #f06b92; --blue: #5aa2f0;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }
textarea { width: 100%; resize: vertical; }
.muted { color: var(--muted); }
.err { color: var(--rose); min-height: 1.2em; }
.small { font-size: 12px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 9px; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--rose); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.icon-btn { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 8px; font-size: 17px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.chip-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.logo { width: 22px; height: 22px; border-radius: 7px; background: conic-gradient(from 200deg, var(--accent), var(--teal), var(--amber), var(--accent)); display: inline-block; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; font-size: 15px; }
.brand.big { font-size: 22px; }
.brand.big .logo { width: 30px; height: 30px; border-radius: 9px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 5px; font-weight: 550; font-size: 13px; }

/* layout */
.app { display: grid; height: 100dvh; grid-template: "top top top" 56px "side main detail" 1fr / var(--side) 1fr auto; }
.top { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top .brand { width: calc(var(--side) - 28px); }
.search { flex: 1; display: flex; gap: 6px; align-items: center; max-width: 640px; }
.search input { flex: 1; border-radius: 10px; background: var(--bg); }
.views { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.views button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13px; }
.views button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.only-mobile { display: none !important; }

.side { grid-area: side; overflow: auto; border-right: 1px solid var(--line); padding: 12px 10px 40px; background: var(--panel); }
.side h4 { margin: 18px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.side h4 button { border: 0; background: none; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 4px; }
.side h4 button:hover { color: var(--accent); }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 5px 8px; border-radius: 7px; color: var(--text); font-size: 13.5px; }
.nav-item:hover { background: var(--panel2); }
.nav-item.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.nav-item .n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.nav-item .ic { width: 16px; text-align: center; opacity: .8; flex: none; }
.nav-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.drop { outline: 2px dashed var(--accent); }
.folder-row { position: relative; }
.folder-row .more { position: absolute; right: 4px; top: 3px; opacity: 0; border: 0; background: var(--panel2); border-radius: 6px; padding: 0 6px; color: var(--muted); }
.folder-row:hover .more { opacity: 1; }
.folder-row:hover .n { visibility: hidden; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 6px; }

.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; min-height: 50px; }
.bar .count { font-weight: 650; }
.bar .spacer { flex: 1; }
.bar select { padding: 4px 8px; font-size: 13px; }
.content { flex: 1; overflow: auto; position: relative; min-height: 0; }

.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel2); border: 1px solid transparent; border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--text); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
button.chip:hover { border-color: var(--accent); }
.chip.concept { background: var(--accent-2); color: var(--accent); }
.chip.tag { background: color-mix(in srgb, var(--teal) 14%, transparent); color: var(--teal); }
.chip.tag::before { content: "#"; opacity: .6; }
.chip.person::before { content: "👤"; font-size: 10px; }
.chip.active { border-color: currentColor; }
.chip .x { border: 0; background: none; padding: 0 0 0 2px; color: inherit; opacity: .6; font-size: 13px; }
.chip .x:hover { opacity: 1; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; position: relative; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card.sel { outline: 2px solid var(--accent); }
.thumb { aspect-ratio: 16/9; background: var(--panel2) center/cover no-repeat; position: relative; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.thumb .dur { position: absolute; right: 7px; bottom: 7px; background: rgba(0,0,0,.78); color: #fff; font-size: 11.5px; font-weight: 600; padding: 1px 6px; border-radius: 5px; }
.thumb .badges { position: absolute; left: 7px; top: 7px; display: flex; gap: 4px; }
.thumb .badge { background: rgba(0,0,0,.7); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 5px; }
.thumb .badge.proc { background: var(--accent); }
.thumb .badge.error { background: var(--rose); }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 620; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; }
.card .sum { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 4px; }
.card .check { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff; background: rgba(0,0,0,.35); opacity: 0; display: grid; place-items: center; color: #fff; font-size: 13px; }
.card:hover .check, .card.sel .check, .selecting .card .check { opacity: 1; }
.card.sel .check { background: var(--accent); border-color: var(--accent); }
.fav-star { color: #f5b301; }

/* table */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
.tbl th.sorted { color: var(--text); }
.tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.tbl tr:hover td { background: var(--panel); }
.tbl tr.sel td { background: var(--accent-2); }
.tbl tr { cursor: pointer; }
.tbl .t-thumb { width: 72px; height: 40px; border-radius: 5px; background: var(--panel2) center/cover; }
.tbl .t-title { font-weight: 580; white-space: normal; min-width: 240px; }
.tbl .t-chips { display: flex; gap: 3px; flex-wrap: nowrap; overflow: hidden; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* graph */
.graph-wrap { position: absolute; inset: 0; }
.graph-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.graph-ctl { position: absolute; left: 12px; top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); display: grid; gap: 6px; font-size: 12.5px; max-width: 250px; z-index: 2; }
.graph-ctl label { display: flex; align-items: center; gap: 7px; }
.graph-ctl .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.graph-ctl input[type=range] { width: 100%; padding: 0; }
.graph-ctl summary { cursor: pointer; font-weight: 650; }
.graph-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12.5px; box-shadow: var(--shadow); max-width: 300px; z-index: 3; }
.graph-legend { position: absolute; right: 12px; bottom: 12px; color: var(--muted); font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; }

/* concepts / ideas */
.split { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; height: 100%; }
.split > div { overflow: auto; }
.split .list { border-right: 1px solid var(--line); padding: 8px; }
.concept-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.concept-row:hover { background: var(--panel); }
.concept-row.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.concept-row .bar-in { height: 4px; background: var(--accent); border-radius: 2px; opacity: .45; }
.concept-row .kind { font-size: 11px; color: var(--muted); }
.pane { padding: 20px 24px 60px; max-width: 900px; }
.pane h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.pane h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mini-items { display: grid; gap: 8px; }
.mini { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px; cursor: pointer; }
.mini:hover { border-color: var(--accent); }
.mini .thumb { width: 96px; flex: none; border-radius: 6px; font-size: 18px; }
.mini .t { font-weight: 580; line-height: 1.3; }
.idea { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.idea .i { font-weight: 620; }
.idea .d { color: var(--muted); margin-top: 3px; }
.idea .src { margin-top: 6px; font-size: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ideas-list { padding: 16px 20px 60px; max-width: 980px; columns: 2 380px; column-gap: 14px; }
.ideas-list .idea { break-inside: avoid; }

/* detail */
.detail { grid-area: detail; width: var(--detail); border-left: 1px solid var(--line); background: var(--panel); overflow: auto; }
.detail .d-head { position: sticky; top: 0; background: var(--panel); z-index: 2; display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.detail .d-body { padding: 14px 18px 60px; display: grid; gap: 14px; }
.player { aspect-ratio: 16/9; background: #000; border-radius: 10px; overflow: hidden; }
.player iframe { width: 100%; height: 100%; border: 0; display: block; }
.d-title { font-size: 19px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; outline: none; border-radius: 6px; }
.d-title:focus { box-shadow: 0 0 0 2px var(--accent-2); }
.d-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.sec h5 { margin: 0 0 7px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.sec h5 .grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips-edit { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chips-edit input { border: 1px dashed var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; width: 120px; background: transparent; }
.stars button { border: 0; background: none; padding: 0 1px; font-size: 17px; color: var(--line); }
.stars button.on { color: #f5b301; }
.summary { line-height: 1.55; }
.ideas-d { display: grid; gap: 8px; }
.ideas-d .idea { margin: 0; }
.chap { display: flex; gap: 10px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.chap:hover { background: var(--panel2); }
.ts { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; cursor: pointer; }
.transcript { max-height: 420px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.55; }
.transcript p { margin: 0 0 8px; }
.transcript mark { background: color-mix(in srgb, var(--amber) 40%, transparent); color: inherit; border-radius: 3px; }
.link-row { display: flex; gap: 8px; align-items: flex-start; padding: 7px 8px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px; background: var(--bg); }
.link-row .thumb { width: 64px; flex: none; border-radius: 5px; font-size: 14px; }
.link-row .lt { font-weight: 580; cursor: pointer; line-height: 1.3; }
.link-row .lt:hover { color: var(--accent); }
.link-row .why { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.link-row .kind { font-size: 11px; background: var(--panel2); border-radius: 5px; padding: 0 6px; color: var(--muted); }
.link-row .acts { margin-left: auto; display: flex; gap: 2px; flex: none; }
.link-row.auto { border-style: dashed; }
.log { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; color: var(--muted); white-space: pre-wrap; }
details > summary { cursor: pointer; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--panel); color: var(--text); width: min(620px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,10,20,.45); backdrop-filter: blur(2px); }
.dlg { padding: 20px 22px; display: grid; gap: 12px; }
.dlg h3 { margin: 0; font-size: 18px; }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dlg label { display: grid; gap: 5px; font-weight: 550; font-size: 13px; }
.bm { display: inline-block; background: var(--accent); color: #fff !important; padding: 7px 14px; border-radius: 9px; font-weight: 650; text-decoration: none !important; cursor: grab; }
.picker-list { max-height: 300px; overflow: auto; display: grid; gap: 6px; }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 550; animation: tin .2s ease-out; max-width: calc(100vw - 32px); }
.toast.err { background: var(--rose); color: #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); max-width: 520px; margin: 0 auto; }
.empty h3 { color: var(--text); font-size: 18px; }
.bulk { display: flex; gap: 6px; align-items: center; background: var(--accent-2); border-radius: 9px; padding: 3px 6px 3px 12px; }

@media (max-width: 1250px) { :root { --detail: 440px; } }
@media (max-width: 1050px) {
  .app { grid-template: "top top" 56px "side main" 1fr / var(--side) 1fr; }
  .detail { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; width: min(var(--detail), 100vw); box-shadow: -10px 0 40px rgba(0,0,0,.25); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 19; }
  .views span { display: none; }
}
@media (max-width: 760px) {
  :root { --side: 270px; }
  .app { grid-template: "top" auto "main" 1fr / 1fr; }
  .top { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .top .brand { width: auto; }
  .brand-name { display: none; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .views { margin-left: auto; }
  .only-mobile { display: inline-grid !important; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: var(--side); z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 10px 0 40px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
  .card .sum { display: none; }
  .split { grid-template-columns: 1fr; grid-template-rows: 40% 60%; }
  .split .list { border-right: 0; border-bottom: 1px solid var(--line); }
  .bar { padding: 8px 12px; }
  #qDeep { display: none; }
  .add-lbl { display: none; }
  .views button { padding: 5px 8px; }
  .top .icon-btn { width: 30px; }
}
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } }
