:root {
  --bg: #0e1014;
  --panel: #14171d;
  --raised: #1b1f27;
  --line: #262b36;
  --text: #e8eaf0;
  --muted: #8d93a3;
  --accent: #8b9dff;
  --accent-ink: #0e1014;
  --danger: #ff8a8a;
  --radius: 10px;
  --side: 264px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- shared bits ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand em { font-style: normal; font-weight: 400; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--raised); color: var(--text); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: #3a4152; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); }
.link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--raised); color: var(--text);
}
.icon-btn:hover { border-color: #3a4152; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 14px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.login-card .brand { margin-bottom: 6px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px;
}
.login-card .btn { height: 40px; margin-top: 2px; }
.login-error { min-height: 18px; margin: -4px 0 0; color: var(--danger); font-size: 13px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100%; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 18px 12px 14px; background: var(--panel); border-right: 1px solid var(--line);
}
.side .brand { padding: 0 8px 18px; }
.side-label { padding: 0 8px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tree { flex: 1; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.me {
  display: flex; justify-content: space-between; gap: 8px; padding: 12px 8px 0;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.me b { color: var(--text); font-weight: 600; }

/* folder tree */
.node { display: flex; align-items: center; gap: 2px; border-radius: 7px; }
.node:hover { background: var(--raised); }
.node.on { background: #232a44; }
.node.on .node-name { color: #fff; }
.twist {
  flex: none; width: 22px; height: 30px; display: grid; place-items: center;
  background: none; border: 0; color: var(--muted); padding: 0;
}
.twist svg { transition: transform .12s; }
.twist.open svg { transform: rotate(90deg); }
.twist.none { visibility: hidden; }
.node-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 30px;
  background: none; border: 0; padding: 0 8px 0 0; text-align: left;
}
.node-icon { flex: none; color: var(--muted); }
.node.on .node-icon { color: var(--accent); }
.node-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-count { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.kids { margin-left: 13px; padding-left: 5px; border-left: 1px solid var(--line); }

/* top bar */
.main { min-width: 0; padding: 0 22px 96px; }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 0 12px; background: linear-gradient(var(--bg) 82%, transparent);
}
.menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 16px; font-weight: 600; flex: 1 1 200px; flex-wrap: wrap; }
.crumbs button { background: none; border: 0; padding: 0; color: var(--muted); font-weight: 500; }
.crumbs button:hover { color: var(--text); }
.crumbs .sep { color: #4a5062; font-weight: 400; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tools input, .tools select {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}
.tools input { width: 240px; }
.sub { display: flex; align-items: center; gap: 14px; padding: 0 0 12px; color: var(--muted); font-size: 13px; }

/* clips */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.card { min-width: 0; }
.media {
  position: relative; aspect-ratio: 9 / 16; border-radius: var(--radius); overflow: hidden;
  background: var(--raised); cursor: pointer; outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color .1s;
}
.card.picked .media { outline-color: var(--accent); }
.media img, .media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media video { opacity: 0; transition: opacity .12s; }
.media video.live { opacity: 1; }
.media::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 34%; pointer-events: none;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.dur {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; padding: 1px 6px; border-radius: 5px;
  background: rgba(0, 0, 0, .6); font-size: 12px; font-variant-numeric: tabular-nums;
}
.tag {
  position: absolute; left: 8px; bottom: 8px; z-index: 2; padding: 1px 6px; border-radius: 5px;
  background: rgba(139, 157, 255, .92); color: var(--accent-ink); font-size: 11px; font-weight: 600;
}
.tag.warn { background: rgba(255, 196, 107, .95); }
.pick, .dl {
  position: absolute; top: 8px; z-index: 3; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center; background: rgba(14, 16, 20, .72); border: 1px solid rgba(255, 255, 255, .16);
  color: #fff; opacity: 0; transition: opacity .1s; backdrop-filter: blur(6px);
}
.pick { left: 8px; }
.dl { right: 8px; text-decoration: none; }
.media:hover .pick, .media:hover .dl, .card.picked .pick, .picking .pick { opacity: 1; }
.pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.pick svg { opacity: 0; }
.card.picked .pick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card.picked .pick svg { opacity: 1; }
.cap { display: flex; justify-content: space-between; gap: 8px; padding: 7px 2px 0; font-size: 13px; }
.cap .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.cap .what { flex: none; color: var(--muted); font-size: 12px; }
.empty { padding: 60px 0; text-align: center; color: var(--muted); }
.more { height: 1px; }

/* Soft fade at the bottom of the screen while there is more to scroll to. It is taller than the part you
   notice (the bottom ~5%) so that it can ease in from nothing instead of starting at a line. */
.fade {
  position: fixed; left: var(--side); right: 0; bottom: 0; height: 10vh; z-index: 4; pointer-events: none;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  background: rgba(14, 16, 20, .5);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,.015) 12%, rgba(0,0,0,.05) 24%, rgba(0,0,0,.12) 36%, rgba(0,0,0,.23) 48%, rgba(0,0,0,.38) 60%, rgba(0,0,0,.56) 72%, rgba(0,0,0,.76) 84%, rgba(0,0,0,.92) 94%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,.015) 12%, rgba(0,0,0,.05) 24%, rgba(0,0,0,.12) 36%, rgba(0,0,0,.23) 48%, rgba(0,0,0,.38) 60%, rgba(0,0,0,.56) 72%, rgba(0,0,0,.76) 84%, rgba(0,0,0,.92) 94%, #000 100%);
  transition: opacity .2s;
}
.fade.off { opacity: 0; }

/* selection bar */
.selbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 18px;
  background: var(--raised); border: 1px solid #3a4152; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  max-width: calc(100vw - 32px);
}
#sel-count { font-weight: 550; white-space: nowrap; }

/* one clip, full size */
.viewer {
  position: fixed; inset: 0; z-index: 30; background: rgba(6, 7, 10, .93);
  display: grid; place-items: center; padding: 20px 64px;
}
.v-body { display: flex; gap: 28px; align-items: center; max-width: 100%; max-height: 100%; }
#v-video { height: min(86vh, 900px); max-width: min(52vw, 520px); aspect-ratio: 9 / 16; border-radius: 12px; background: #000; }
.v-info { width: 280px; display: grid; gap: 12px; align-content: start; }
.v-info h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.v-name { margin: -6px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.v-info dl { margin: 4px 0 6px; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.v-info dt { color: var(--muted); }
.v-info dd { margin: 0; overflow-wrap: anywhere; }
.v-close { position: absolute; top: 16px; right: 16px; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%; }
.v-prev { left: 12px; }
.v-next { right: 12px; }

.scrim { display: none; }

/* ---------- narrow screens ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; z-index: 25; left: 0; top: 0; width: min(var(--side), 84vw);
    transform: translateX(-102%); transition: transform .18s;
  }
  .side.open { transform: none; }
  .side.open + .scrim { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(0, 0, 0, .55); }
  .menu { display: inline-grid; }
  .fade { left: 0; }
  .main { padding: 0 16px 96px; }
  .tools { width: 100%; }
  .tools input { flex: 1; width: auto; min-width: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
  .pick, .dl { opacity: 1; }
  .viewer { padding: 56px 12px 12px; }
  .v-body { flex-direction: column; gap: 14px; overflow: auto; }
  #v-video { height: min(56vh, 620px); width: auto; max-width: 100%; }
  .v-info { width: 100%; }
  .v-nav { top: auto; bottom: 14px; transform: none; }
}
